function favoris(site) { 
if ( navigator.appName != 'Microsoft Internet Explorer' ) 
{ window.sidebar.addPanel('http://'+site,site,""); } 
else { window.external.AddFavorite('http://'+site,site); } } 


function verifMail(a){
testm = false ;
 for (var j=1 ; j<(a.length) ; j++) {
  if (a.charAt(j)=='@') {
   if (j<(a.length-4)){
    for (var k=j ; k<(a.length-2) ; k++) {
     if (a.charAt(k)=='.') testm = true;
    }
   }
  }
 }
return testm ;
}
function MM_openBrWindow(theURL,winName,features) { //v2.0
  window.open(theURL,winName,features);
}

function applyClass(oElement,sCSSClass)

{
     oElement.className = sCSSClass;
}


function ImageMax(chemin)
   {
   i1 = new Image;
   i1.src = chemin;
   html = '<html><head><title><?= $siteName; ?></title></head><body scroll="no" leftmargin="0" marginwidth="0" topmargin="0" marginheight="0" onBlur="top.close()"><a href="javascript:close()"><img src="'+chemin+'" border=0 name=ImageMax onLoad="window.resizeTo(document.ImageMax.width+10,document.ImageMax.height+60)"></a></body></html>';
   popupImage = window.open('','_blank','toolbar=0,location=0,directories=0,menuBar=0,scrollbars=0,resizable=1,left=200,top=200');
   popupImage.document.open();
   popupImage.document.write(html);
   popupImage.document.close()
   };

function MM_goToURL() { //v3.0
  var i, args=MM_goToURL.arguments; document.MM_returnValue = false;
  for (i=0; i<(args.length-1); i+=2) eval(args[i]+".location='"+args[i+1]+"'");
}

function setPointer(theRow, thePointerColor)
{
    if (typeof(theRow.style) == 'undefined' || typeof(theRow.cells) == 'undefined') {
        return false;
    }
 
    var row_cells_cnt = theRow.cells.length;
    
    for (var c = 0; c < row_cells_cnt; c++) {
        theRow.cells[c].bgColor = thePointerColor;        
    }
 
    return true;
}

function valid_search(form) {
  if (form.recherche.value == ""){
    alert("Veuillez saisir une recherche.")
	form.recherche.focus();
	return false }
	return true
}
function valid_mail(form) {
  if (form.email.value == ""){
    alert("Veuillez saisir une adresse mail.")
	form.email.focus();
	return false }
  if (verifMail(form.email.value)==false){
    alert("Le format de l'adresse mail n'est pas correct...")
	form.email.focus();
	return false }
	return true
}


//Gestion de Fondus	////////////////////////////////////////////////////////////////////////
function opacity(id, opacStart, opacEnd, millisec) { 
    //speed for each frame 
    var speed = Math.round(millisec / 100); 
    var timer = 0; 

    //determine the direction for the blending, if start and end are the same nothing happens 
    if(opacStart > opacEnd) { 
        for(i = opacStart; i >= opacEnd; i--) { 
            setTimeout("changeOpac(" + i + ",'" + id + "')",(timer * speed)); 
            timer++; 
        } 
    } else if(opacStart < opacEnd) { 
        for(i = opacStart; i <= opacEnd; i++) 
            { 
            setTimeout("changeOpac(" + i + ",'" + id + "')",(timer * speed)); 
            timer++; 
        } 
    } 
//	setTimeout("document.getElementById("+id+").style.display=\"none\";","3000");
} 

//change the opacity for different browsers 
function changeOpac(opacity, id) { 
    var object = document.getElementById(id).style; 
    object.opacity = (opacity / 100); 
    object.MozOpacity = (opacity / 100); 
    object.KhtmlOpacity = (opacity / 100); 
    object.filter = "alpha(opacity=" + opacity + ")"; 
	
} 
//Fin Gestion de Fondus	////////////////////////////////////////////////////////////////////////

/*
function getElementsByClassBMK(tag, class){
	var elements = document.getElementsByTagName(tag);
	var results = new Array();
	for(var i=0; i<elements.length; i++){
		if(elements[i].className == class){
			elements[i].selected = true;
		}
	}
	return results;
}
*/

function inscription_newsletter(form) {
  if (form.newsletter_email.value == ""){
    alert("Veuillez saisir une adresse mail.")
	form.newsletter_email.focus();
	return false }
  if (verifMail(form.newsletter_email.value)==false){
    alert("Le format de l'adresse mail n'est pas correct...")
	form.newsletter_email.focus();
	return false }
	return true
}

function info_retour(txt,id,temps) { 

	document.getElementById(id).innerHTML ="<div id=\"retour_action\">"+txt+"</div>";
	timer=setTimeout("opacity('retour_action', 100, 0, 800)", temps);	
	setTimeout("document.getElementById('retour_action').style.display=\"none\";",2500);

}
	
function maj_quantite(pro_id, color, size, stock, attribut_id){
	if(attribut_id == '')
		attribut_id = 0;
	var qte = document.getElementById('qte_'+pro_id+color+size).value;
	window.location.href= 'panier_process.php?pro_id='+pro_id+'&maj=1&qte='+qte+'&color='+color+'&size='+size+'&stock='+stock+'&attribut_id='+attribut_id;	
}

function confirmation_deconnexion(){
if (window.confirm('Voulez vous réellement quitter votre compte ?')){
 	window.location.href="../user/kill_session.php";
	}
}
function change_quantite_detail(form){
	var attribut_id = form.options[form.selectedIndex].value;
	var first_id = document.getElementById("qte").options[0].value;
	var pro_id = document.getElementById("pro_id").value;
	
	var infos = file('inc/boutique.ajax.php?mode=selection&attribut_id='+attribut_id+'&first_id='+first_id+'&pro_id='+pro_id);
	document.getElementById("box_quantite").innerHTML = '<div>'+infos+'</div>';
	//alert(infos);
}

function change_quantite(current_select, pro_id){
	
	var attribut_id = current_select.options[current_select.selectedIndex].value;
	var form = document.forms['frm_add_'+pro_id];
	var first_id = form.elements["qte"].options[0].value;
		
	var infos = file('inc/boutique.ajax.php?mode=selection&attribut_id='+attribut_id+'&first_id='+first_id+'&pro_id='+pro_id);
	document.getElementById("box_quantite").innerHTML = '<div>'+infos+'</div>';
	//alert(infos);
}

function affiche_box_ajout_panier(pro_id){
	var infos = file('inc/boutique.ajax.php?mode=selection_produit&pro_id='+pro_id);
	document.getElementById("box_ajout_panier_detail").innerHTML = '<div>'+infos+'</div>';
	document.getElementById("box_ajout_panier").style.display = 'block';
}

function close_popup(pro_id){
	
	document.getElementById("box_ajout_panier").style.display = 'none';
}

	/****************************************** AJAX ************************************************/
	function file(fichier) {
		var xhr_object = false;
		
		try {
			xhr_object = new ActiveXObject("Msxml2.XMLHTTP");
		} catch (e) {
			try {
				xhr_object = new ActiveXObject("Microsoft.XMLHTTP");
			} catch (E) {
				xhr_object = false;
			}
		}
		//on essaie de créer l'objet si ce n'est pas déjà fait
		if (!xhr_object && typeof XMLHttpRequest != 'undefined') {
			try {
				xhr_object = new XMLHttpRequest();
			} catch (e) {
				xhr_object = false;
			}
		}
		
		if (xhr_object) {
			xhr_object.open("GET", fichier, false);
			xhr_object.send(null);
			if (xhr_object.readyState == 4) {
				return xhr_object.responseText;
			} else {
				return false;
			}
		} else {
			return false;	
		}
	}
