var cornify_count = 0;
cornify_add = function() {
	cornify_count += 1;
	var cornify_url = 'http://bentobox.jp/images/konami/';
	var file = 'renardo';
	var count = 8;
	if (Math.random() > .8) {
		file = 'renardo';
	}
	file += Math.ceil(Math.random()*count) + '.gif';
	var div = document.createElement('div');
	div.style.position = 'fixed';
	
	 document.getElementById('divKonami').innerHTML = '<center><object type="application/x-shockwave-flash" data="http://petit-gion.com/oganku/dewplayer.swf?mp3=http://petit-gion.com/oganku/konami.mp3&volume=80&autostart=1" width="200" height="20"> <param name="movie" value="http://petit-gion.com/oganku/dewplayer.swf?mp3=http://petit-gion.com/oganku/12.mp3&volume=80" /> </object><br /<br /></center>';
	
	var numType = 'px';
	var heightRandom = Math.random()*.75;
	var windowHeight = 768;
	var windowWidth = 1024;
	var height = 0;
	var width = 0;
	var de = document.documentElement;
	if (typeof(window.innerHeight) == 'number') {
		windowHeight = window.innerHeight;
		windowWidth = window.innerWidth;
	} else if(de && de.clientHeight) {
		windowHeight = de.clientHeight;
		windowWidth = de.clientWidth;
	} else {
		numType = '%';
		height = Math.round( height*100 )+'%';
	}
	
	div.onclick = cornify_add;
	div.style.zIndex = 10;
	div.style.outline = 0;
	
	if( cornify_count==15 ) {
		file = 'renardo.gif';
		div.style.top = Math.max( 0, Math.round( (windowHeight-530)/2 ) )  + 'px';
		div.style.left = Math.round( (windowWidth-530)/2 ) + 'px';
		div.style.zIndex = 1000;
	} else {
		if( numType=='px' ) div.style.top = Math.round( windowHeight*heightRandom ) + numType;
		else div.style.top = height;
		div.style.left = Math.round( Math.random()*90 ) + '%';
	}
	
	var img = document.createElement('img');
	//img.setAttribute('src',cornify_url+'corns/'+file);
	img.setAttribute('src',cornify_url+file);
	var body = document.getElementsByTagName('body')[0];
	body.appendChild(div);
	div.appendChild(img);
	
	// Add stylesheet.
	
/*	if (cornify_count == 1) {
		var cssExisting = document.getElementById('__cornify_css');
		if (!cssExisting) {
			var head = document.getElementsByTagName("head")[0];
			var css = document.createElement('link');
			css.id = '__cornify_css';
			css.type = 'text/css';
			css.rel = 'stylesheet';
			css.href = 'http://www.cornify.com/css/cornify.css';
			css.media = 'screen';
			head.appendChild(css);
		}
		
	}	*/
}

cornify_replace = function() {
	// Replace text.
	var hc = 6;
	var hs;
	var h;
	var k;
	var words = ['RenardoVision','RenardoVision','RenardoVision','RenardoVision','RenardoVision','RenardoVision'];
	while(hc >= 1) {
		hs = document.getElementsByTagName('h' + hc);
		for (k = 0; k < hs.length; k++) {
			h = hs[k];
			h.innerHTML = words[Math.floor(Math.random()*words.length)] + ' ' + h.innerHTML;
		}
		hc-=1;
	}
}

/*
 * Adapted from http://www.snaptortoise.com/konami-js/
 */
var cornami = {
	input:"",
	pattern:"38384040373937396665",
	clear:setTimeout('cornami.clear_input()',5000),
	load: function() {
		window.document.onkeydown = function(e) {
			if (cornami.input == cornami.pattern) {
				cornify_add();
				clearTimeout(cornami.clear);
				return;
			}
			else {
				cornami.input += e ? e.keyCode : event.keyCode;
				if (cornami.input == cornami.pattern) cornify_add();
				clearTimeout(cornami.clear);
				cornami.clear = setTimeout("cornami.clear_input()", 5000);
			}
		}
	},
	clear_input: function() {
		cornami.input="";
		clearTimeout(cornami.clear);
	}
}
cornami.load();


    if ( window.addEventListener ) {
        var kkeys = [];
        var konami = "38,38,40,40,37,39,37,39,66,65";
        window.addEventListener("keydown", function(e){
                kkeys.push( e.keyCode );
                if ( kkeys.toString().indexOf( konami ) >= 0 )
                        cornify_add();
        }, true);
}

function adfav(phrase,lien)
{
   if (window.sidebar)
   {
   window.sidebar.addPanel(phrase, lien,"");
   }
   else if( document.all )
   {
   window.external.AddFavorite(lien, phrase);
   }
   else
   {
   return true;
   }
}

function showDiv(identifiant) 
{
    document.getElementById(identifiant).className = "visible";
}
function hideDiv(identifiant) 
{
     document.getElementById(identifiant).className = "hidden";
}


var isMoving=false;
var oldx;
var oldy;
var oldAltx, oldAlty, isAltMoving, divAlt;

function moveMe(iframeName, clientX, clientY)
{

    if(isMoving) {
      x=(clientX)-oldx;
      y=(clientY)-oldy;
      iframeMoveRel(iframeName, y, x);
      oldx=clientX;
      oldy=clientY;
    }
    return false;
}


function iframeOpen(iframeUrl, iframeName, iframeWidth, iframeHeight, iframeTitle, iframeReloadOnClose, iframeParent, iframeButtonClose,iframeColor)
{
   	if(iframeColor+''=='undefined'|| iframeColor=='') 					iframeColor='#e83544';
    if(iframeReloadOnClose+''=='undefined'|| iframeReloadOnClose=='') 	iframeReloadOnClose=false;
    if(iframeButtonClose+''=='undefined'|| iframeButtonClose=='') 		iframeButtonClose=true;

    if(iframeParent+''=='undefined' || iframeParent=='') 
    {
        if(!document.getElementById('divGeneric')) {
           alert('Erreur, impossible d\'afficher la fenetre');
           return;
        }  

        topPos=(document.body.scrollTop+(((document.body.clientHeight)-iframeHeight)/2));
        if(topPos<20) topPos=20;
        leftPos=(((document.body.clientWidth)-iframeWidth)/2);
        if(leftPos<20) leftPos=20;
                   
        document.getElementById('divGeneric').innerHTML =
            '<div id="'+iframeName+'" style="position:absolute; background-color:'+iframeColor+'; z-index:0; top:'+topPos+'; left:'+leftPos+';">\
               <div id="'+iframeName+'-move" style=" padding-top:2px; padding-bottom:2px; width:'+iframeWidth+'; font-family: Geneva, Arial, Helvetica, sans-serif; font-size:14px; font-weight:bold; color:#FFFFFF; text-indent:5px;">'+iframeTitle+'<div id="'+iframeName+'-croix" style="position:absolute; top:4px; left:'+(iframeWidth-22)+'; font-family: Geneva, Arial, Helvetica, sans-serif; font-size:16px; font-weight:bold; color:#FFFFFF;">'+(iframeButtonClose==true?'<a style="cursor:hand;" onclick="iframeClose(\''+iframeName+'\'); '+(iframeReloadOnClose==true?'parent.frames[\'frame_page\'].location.reload();':'')+'"><img src="http://bentobox.jp/images/spacer/spacer9.gif" align="middle" border="0"></a>':'')+'</div></div>\
               <IFRAME id="'+iframeName+'-frame" style="z-index:10; width:'+iframeWidth+'; height:'+iframeHeight+'" src="'+iframeUrl+'"></IFRAME>\
            </div>';
        isMoving=false;
    
        /*document.getElementById(iframeName).onmousedown = function() {oldx=window.event.clientX; oldy=window.event.clientY; isMoving=true };
        document.onmouseup = function() {isMoving=false};
        document.getElementById(iframeName+'-frame').contentWindow.document.onmouseup = function() {isMoving=false};
        /*document.getElementById(iframeName+'-frame').contentWindow.document.onmousemove=function() { moveMe(iframeName, (window.event.clientX), (window.event.clientY)); };*/
        /*document.onmousemove = function() { moveMe(iframeName, (window.event.clientX), (window.event.clientY)); };*/
    }
    else
    {
        if(!iframeParent.getElementById('divGeneric')) {
           alert('Erreur, impossible d\'afficher la fenetre');
           return;
        }  

        topPos=(iframeParent.body.scrollTop+(((iframeParent.body.clientHeight)-iframeHeight)/2));
        if(topPos<20) topPos=20;
        leftPos=(((iframeParent.body.clientWidth)-iframeWidth)/2);
        if(leftPos<20) leftPos=20;
        
        iframeParent.getElementById('divGeneric').innerHTML =
            '<div id="'+iframeName+'" style="position:absolute; background-color:#336699; z-index:0; top:'+topPos+'; left:'+leftPos+';">\
               <div id="'+iframeName+'-move" style=" padding-top:2px; padding-bottom:2px; width:'+iframeWidth+'; font-family: Geneva, Arial, Helvetica, sans-serif; font-size:14px; font-weight:bold; color:#FFFFFF; text-indent:5px;">'+iframeTitle+'<div id="'+iframeName+'-croix" style="position:absolute; top:4px; left:'+(iframeWidth-22)+'; font-family: Geneva, Arial, Helvetica, sans-serif; font-size:16px; font-weight:bold; color:#FFFFFF;">'+(iframeButtonClose==true?'<a style="cursor:hand;" onclick="iframeClose(\''+iframeName+'\'); '+(iframeReloadOnClose==true?'parent.frames[\'frame_page\'].location.reload();':'')+'"><img src="http://bentobox.jp/images/spacer/spacer9.gif" align="middle" border="0"></a>':'')+'</div></div>\
               <IFRAME id="'+iframeName+'-frame" style="z-index:10; width:'+iframeWidth+'; height:'+iframeHeight+'" src="'+iframeUrl+'"></IFRAME>\
            </div>';
        isMoving=false;

    }
    
}




function iframeClose(iframeName)
{
    var monIframe=getIframe(iframeName);
    monIframe.innerHTML=' ';
}


function iframeResize(iframeName, iframeWidth, iframeHeight, iframeHideCroix)
{
    var monDocumentIframe=getDocumentIframe(iframeName);
    monDocumentIframe.getElementById(iframeName+'-frame').style.width = iframeWidth;
    monDocumentIframe.getElementById(iframeName+'-frame').style.height = iframeHeight;
    monDocumentIframe.getElementById(iframeName).style.top = (window.parent.document.body.scrollTop+(((window.parent.document.body.clientHeight)-iframeHeight)/2)); 
    
    monDocumentIframe.getElementById(iframeName).style.left = (((window.parent.document.body.clientWidth)-iframeWidth)/2);
    monDocumentIframe.getElementById(iframeName+'-croix').style.left = (iframeWidth-22);
    
    if(iframeHideCroix==true)
       monDocumentIframe.getElementById(iframeName+'-croix').style.visibility='hidden';

}

function iframeMoveRel(iframeName, iframeUp , iframeLeft )
{   
    var monIframe=getIframe(iframeName);
    monIframe.style.top= parseInt(monIframe.style.top) + parseInt(iframeUp) +'px';
    monIframe.style.left=parseInt(monIframe.style.left) + parseInt(iframeLeft) +'px';
}

function getIframe(iframeName)
{
    if(window.parent.document.getElementById(iframeName))
      return window.parent.document.getElementById(iframeName);
    else if(document.getElementById(iframeName))
      return document.getElementById(iframeName);
    else
      alert('Erreur getIframe. Prevenez le Service Informatique.');  
}

function getDocumentIframe(iframeName)
{
    if(window.parent.document.getElementById(iframeName))
      return window.parent.document;
    else if(document.getElementById(iframeName))
      return document;
    else if(parent.frames['frame_page'].getElementById(iframeName))
      return parent.frames['frame_page'];
    else
      alert('Erreur getDocumentIframe. Prevenez le Service Informatique.');  
}


    //______________________________________________
    //     UTILISATION DE XmlHttpRequest
    //ŻŻŻŻŻŻŻŻŻŻŻŻŻŻŻŻŻŻŻŻŻŻŻŻŻŻŻŻŻŻŻŻŻŻŻŻŻŻŻŻŻŻŻŻŻŻ
    
    
    function xhrSendQuery(url, methode, data, fonctionRetour) 
    {
        try {
            xhr = new ActiveXObject("Msxml2.XMLHTTP");
        }
        catch(e) {
            try {
                xhr = new ActiveXObject("Microsoft.XMLHTTP");
            }
            catch(e2) {
               try {
                   xhr = new XMLHttpRequest();
               }
               catch(e3) {
                   xhr = false;
                   alert('XmlHttpRequest n\'est pas supporté sur votre ordinateur');
               }
            }
        }   

        if(url===undefined) {
            alert('Vous devez définir l\'adresse du script à appeler !');
            return;
        } 
        if(methode===undefined) {
           methode = "GET";
        }   
        if(methode!="GET" && methode!="POST") {
            alert('Vous ne pouvez utiliser que la methode GET ou POST');
            return;
        }      

        xhr.onreadystatechange = function()
        {
            //On ne peut pas utiliser "return" pour renvoyer la valeur. Il faut forcement appeler une fonction
            //Si elle a été passé en parametre on l'utilise, sinon on appele une fonction standard "xhrReponse(rep)"
            if (xhr.readyState == 4) 
            {    
                if(xhr.status=="200") 
                  ret = RTrim(xhr.responseText);
                  
                else
                  ret = false;
                if(fonctionRetour===undefined)
                  xhrReponse(ret);
                else  
                  //eval(fonctionRetour(ret));
                  eval(fonctionRetour + '(unescape(\'' + escape(ret) + '\'));' );
                                   
                //delete xhr;
            }      
        }

        xhr.open(methode, url);
        if(methode=="POST")  {
            xhr.setRequestHeader("Content-type", "application/x-www-form-urlencoded");
            xhr.send(data);
        }    
        else
            xhr.send('');

    }  
 
    
    
    
    //______________________________________________
    //     
    //ŻŻŻŻŻŻŻŻŻŻŻŻŻŻŻŻŻŻŻŻŻŻŻŻŻŻŻŻŻŻŻŻŻŻŻŻŻŻŻŻŻŻŻŻŻŻ
    
    function hideAllSelects()
    {
        for(index = 0 ; index < document.all.length; index++){
          monElement = document.all(index);
          if(monElement.type=='select-one') {
              monElement.style.visibility='hidden';
          }
        }
    }
    
    function RTrim(sString) 
    {
        while ( sString.substring(sString.length-1, sString.length)==' ' || sString.substring(sString.length-1, sString.length)=='\n' || sString.substring(sString.length-1, sString.length)=='\r' )
        {
            sString = sString.substring(0,sString.length-1);
        }
        return sString;
    }    
    
    
    function changeImages() {
    	if (document.images) {
    		for (var i=0; i<changeImages.arguments.length; i+=2) {
    			document[changeImages.arguments[i]].src = changeImages.arguments[i+1];
    		}
    	}
    }

	function ap_showWaitMessage(div,flag)  {
         if(document.getElementById(div)) {
           document.getElementById(div).visibility = ((flag) ? 'visible':'hidden');
         }
    }

    ap_showWaitMessage('waitDiv', 1);


    
function verifChamps()
{
    if(document.submitOnigiri.Nom.value=='')
    {
        alert('Nom manquant');  
        return false;
    }
    else if(document.submitOnigiri.Titre.value=='')
    {
        alert('Titre manquant');  
        return false;
    }
    else if(document.submitOnigiri.Commentaire.value=='')
    {
        alert('Commentaire manquant');
        return false;  
    }
    else if((document.submitOnigiri.Email.value=='') && (document.submitOnigiri.mailingYes.checked == true))
    {
        alert('Email manquant');  
        return false;
    }
    else
    {
       document.submitOnigiri.submit();
       return true;
    }
      
}