function RedirectLink(lien_page)
{
	window.location = lien_page;
}

function ReloadPage()
{
	location.reload();
}

function createXhrObject()
{
    if (window.XMLHttpRequest)
        return new XMLHttpRequest();
 
    if (window.ActiveXObject)
    {
        var names = [
            "Msxml2.XMLHTTP.6.0",
            "Msxml2.XMLHTTP.3.0",
            "Msxml2.XMLHTTP",
            "Microsoft.XMLHTTP"
        ];
        for(var i in names)
        {
            try{ return new ActiveXObject(names[i]); }
            catch(e){}
        }
    }
    window.alert("Votre navigateur ne prend pas en charge l'objet XMLHTTPRequest.");
    return null; // non supporté
}

function AjaxRequest(url_traitement,param)
{
	var xhr=createXhrObject();
	xhr.open( "POST", url_traitement,  false); 
	xhr.setRequestHeader("Content-Type", "application/x-www-form-urlencoded"); 
	xhr.send(param); 

	if(xhr.readyState  == 4)
	{
		if(xhr.status  == 200) 
		{
    //alert('kikoo');
			response=xhr.responseText; 
			return response;
		}
		else
		{			  
			response=xhr.status;
			return response;
		}
	}
}

function returnAjaxResponse(path,data)
{
	window.open (path+'ajax_response.php?data='+data, 'reponse de ajax', config='height=500, width=400, toolbar=no, menubar=no, scrollbars=yes, resizable=yes, location=no, directories=no, status=no')
}

function ControlCase(id_box, id_box_verif, valeur_box, val_error,jquery_verif)
{
	if(document.getElementById(id_box_verif).value!=valeur_box || $('#'+id_box).val()=="")
	{
		document.getElementById(id_box).style.backgroundColor="#FFA0A0";
		document.getElementById(id_box).style.color="red";
		
		if($('#'+id_box).val()=="")
		{
			if(jquery_verif==false)
			{
				$('#'+id_box).hide();
				$('#'+id_box).fadeIn("slow");
				$('#'+id_box).val(val_error);
			}	
		}
	}
	else
	{	
		if(jquery_verif==true)
		{
			$('#'+id_box).hide();
			$('#'+id_box).fadeIn("slow");
			document.getElementById(id_box).style.backgroundColor="#D6ECA6";
			document.getElementById(id_box).style.color="#000000";
		}
		else
		{
			document.getElementById(id_box).style.backgroundColor="#FFFFFF";
			document.getElementById(id_box).style.color="#000000";
		}
	}
}

function VerifDataField(id_field,value_error,border)
{
	$('#'+id_field).hide();
	$('#'+id_field).fadeIn("slow");
	if(value_error==null)value_error='Veuillez remplir ce champ';
	if(document.getElementById(id_field)!=null)
	{
		if(document.getElementById(id_field).value=="")
		{	
			document.getElementById(id_field).style.backgroundColor="#FFA0A0";
			document.getElementById(id_field).style.color="red";
			document.getElementById(id_field).value=value_error;
		}
		else
		{	
			document.getElementById(id_field).style.border=border;
			document.getElementById(id_field).style.backgroundColor="#FFFFFF";
			document.getElementById(id_field).style.color="#000000";
		}
	}
	else
	{
		alert('Field inconnu');
	}
}

function VerifDataFieldOnKey(id_field)
{	
	if(document.getElementById(id_field)!=null)
	{
		if(document.getElementById(id_field).value!="")
		{
			document.getElementById(id_field).style.backgroundColor="#D6ECA6";
			document.getElementById(id_field).style.color="#000000";
		}
		else
		{
			document.getElementById(id_field).style.backgroundColor="#FFA0A0";
		}
	}
}

function VerifDataFieldFocus(id_field)
{	
	if(document.getElementById(id_field)!=null)
	{
		//if(document.getElementById(id_field).value!="")
		//{
			document.getElementById(id_field).style.backgroundColor="#D6ECA6";
			document.getElementById(id_field).style.color="#000000";
		//}
	}
}

function recherche(path)
{
	//var mot = document.getElementById('Mot').value;
	//RedirectLink(path+"moteur_recherche/result.php?Mot="+mot);
	$('#form_recherche').submit();
}

function verif() {
	var recherche = document.getElementById('Mot').value;
	var mot = recherche.split(' ');
	if(mot.length == 4){
		recherche = recherche.substring(0, (recherche.length-1));
		document.getElementById('Mot').value = recherche;
		alert("3 mots maximum !");
	}
	//var nbstore = reponse[1]; // nbstore
}

function ChangeClass(id,classname)
{
	$('#'+id).toggleClass(classname);
}

function AddClass(id,classname)
{
	$('#'+id).addClass(classname);
}

function RemoveClass(id,classname)
{
	$('#'+id).removeClass(classname);
}

function RollOver(id,src_image)
{
	$('#'+id).attr("src",src_image);
}

function ChangeBorderColor(id,color)
{
	$('#'+id).css("borderColor",color);
}

function ShowInfo(id)
{
	$('#'+id).fadeIn("fast");
	//$('#'+id).css("display","block");
}

function HiddenInfo(id)
{
	$('#'+id).fadeOut("fast");
	//('#'+id).css("display","none");
}

function BtnClick(id)
{
	$('#'+id).css('border-style','inset');
}

function BtnUnClick(id)
{
	$('#'+id).css('border-style','outset');
}

function autoRoll(image_id,src_image)
{
    old_image=$('#'+image_id).attr("src");
    $('#'+image_id).attr("src",src_image);
    $('#'+image_id).bind('mouseout',function(){
	$('#'+image_id).attr("src",old_image);
    });
}

function autoShow(id_over,id_show)
{
    $('#'+id_over).bind('mouseout',function(){
	$('#'+id_show).hide();
    });
    $('#'+id_show).show();

}

function SplitNumber(number)
{
	unit_number=parseInt(number);
	decimal_number=Math.round(((parseFloat(number)*100)-(unit_number*100)));
	if(decimal_number=='')decimal_number="00";
	else if(decimal_number.length==1)decimal_number+"0";
	else if(decimal_number.length<10)"0"+decimal_number;
	//decimal_number=Math.round(decimal_number);
	return new Array(unit_number, decimal_number);
}
//document.onkeypress = detect_key; 
var konami_code='122|115|113|100';
var tab_konami=konami_code.split('|');	
var code_stroke='';
function detect_key(event)
{	
	var keycode;
	var valid=true;
	if (window.event) keycode = window.event.keyCode;
	else keycode = event.which;
	
	//alert(keycode);
	code_stroke=code_stroke+keycode+"|";
	
	tab_stroke=code_stroke.split('|');
	for(id in tab_konami)
	{
		if(tab_stroke[id])
		{
			if(tab_stroke[id] != tab_konami[id])
			{
				valid=false;
				code_stroke='';
				return false;
				break;
			}
		}
		else
		{
			valid=false;
		}
	}
	
	if(valid==true)easter_egg();
	
	/*if(keycode==122)move_vaisseaux('up');
	else if(keycode==115)move_vaisseaux('down');*/
	/*if(keycode==113)move_vaisseaux('left');
	else if(keycode==100)move_vaisseaux('right');
	else if(keycode==32) Shot();*/
}

function animBackColor(id, color, time)
{
	$("#"+ id).animate({ backgroundColor : color}, time );
	//alert("id : "+id);
}


function easter_egg()
{
	code_stroke='';
	var monCalque=document.createElement('div');
	//alert('Test');
	/*monCalque.setAttribute("class","maclasse");
	monCalque.setAttribute("className","maclasse");*/
	
	monCalque.innerHTML='HAHA essaye de me cliquer dessus';
	//body=document.getElementsByTagName("div").appendChild(monCalque);
	document.write('Tu a reussi le super test du konami code t\'est trop baleze')
	//alert(body);
}

/* fonction pour recuperer les dimensions de la page*/
function getPageSize()
{
    var xScroll, yScroll;
    if (window.innerHeight && window.scrollMaxY)
    {
	xScroll = window.innerWidth + window.scrollMaxX;
	yScroll = window.innerHeight + window.scrollMaxY;
    }
    else if (document.body.scrollHeight > document.body.offsetHeight)
    {
	xScroll = document.body.scrollWidth;
	yScroll = document.body.scrollHeight;
    }
    else
    {
	xScroll = document.body.offsetWidth;
	yScroll = document.body.offsetHeight;
    }
    var windowWidth, windowHeight;
    if (self.innerHeight)
    {
	if(document.documentElement.clientWidth)
	{
	    windowWidth = document.documentElement.clientWidth;
	}
	else
	{
	    windowWidth = self.innerWidth;
	}
	windowHeight = self.innerHeight;
    }
    else if (document.documentElement && document.documentElement.clientHeight)
    {
	windowWidth = document.documentElement.clientWidth;
	windowHeight = document.documentElement.clientHeight;
    }
    else if (document.body)
    {
	windowWidth = document.body.clientWidth;
	windowHeight = document.body.clientHeight;
    }

    if(yScroll < windowHeight)
    {
	pageHeight = windowHeight;
    }
    else
    {
	pageHeight = yScroll;
    }

    if(xScroll < windowWidth)
    {
	pageWidth = xScroll;
    }
    else
    {
	pageWidth = windowWidth;
    }
    arrayPageSize = new Array(pageWidth,pageHeight,windowWidth,windowHeight)
    return arrayPageSize;
}

/* fonction qui retourne les valeur du scroll actuel de la page*/
function getPageScroll()
{
    var xScroll, yScroll;
    if (self.pageYOffset)
    {
	yScroll = self.pageYOffset;
	xScroll = self.pageXOffset;
    }
    else if (document.documentElement && document.documentElement.scrollTop)
    {
	yScroll = document.documentElement.scrollTop;
	xScroll = document.documentElement.scrollLeft;
    }
    else if (document.body)
    {
	yScroll = document.body.scrollTop;
	xScroll = document.body.scrollLeft;
    }
    arrayPageScroll = new Array(xScroll,yScroll)
    return arrayPageScroll;
}

function lightBox(texte,width_box,height_box)
{
    if(typeof(width_box)=='undefined')
    {
	   width_box='300';
    }
    if(typeof(height_box)=='undefined')
    {
	   height_box='300';
    }
    /*
     *  on créer  2 div. Une div qui sera en noir fond transparent pour centrer la lightbox
     *  puis une autre box qui contiendra les element html a afficher en lightbox
     */
    action_click='closeLightBox();';

    $('html').append('<div onclick="closeLightBox()" id="lightBoxShadow"></div>');
    $('html').append('<div onclick="'+ action_click +'" id="lightBox" style="height:'+ height_box +';width:'+ width_box +'px;">'+texte+'</div>');

    /*
     *on va récupérer les dimensions de la page chargé au moment de l'appel
     */

    var aPageSize=getPageSize();
    //on va récupérer les valeurs des ascenseurs
    var aScrollSize=getPageScroll();

    $('#lightBoxShadow').css({
				'background-color' : '#000000',
				'width' : aPageSize[2]+'px',
				'height' : aPageSize[1]+'px',
				'top' : '0px',
				'left' : '0px',
				'opacity' : '0.8',
				'position' : 'absolute'
    });

    posi_left_light=Math.floor((aPageSize[2]-width_box)/2)+aScrollSize[0];
    posi_top_light= Math.floor((aPageSize[3]-height_box)/2)+aScrollSize[1]-150;

    if(posi_left_light<0)posi_left_light=0;
    if(posi_top_light<0)posi_top_light=0;

    $('#lightBox').css({
			'height':height_box+'px',
			'width':width_box+'px',
			'background-color' : '#EEEEEE',
			'left' : posi_left_light+'px',
			'top' : posi_top_light+'px',
			'position' : 'absolute'
    });

   /* $('#lightBox').animate({'width' : width_box+'px'});
    $('#lightBox').animate({'height':height_box+'px'});*/
}

function closeLightBox()
{
    $('#lightBoxShadow').remove();
    $('#lightBox').remove();
}