

function changeOrderBy(product_name, type, order,refinement, cat){
       
        product_name = product_name.replace("\"","");
        product_name = product_name.replace("'","");
        product_name = product_name.replace("&","");
        product_name = product_name.replace("'","");
        product_name = product_name.replace("*","");
        product_name = product_name.replace("|","");
        product_name = product_name.replace("/","");
        product_name = product_name.replace("\/","");
        product_name = product_name.replace("\\","");

	    if(order=="" && refinement=="")
        {
			if(cat==""){
				window.location="/"+type+ "/1/" + product_name +".html";   
			}else{
				window.location="/"+type+ "/1/" + cat + "/" +product_name +".html";   
			}
		}else if(order==""){
			if(cat==""){
				window.location="/"+type+ "/1/" + product_name +".html?reffinement="+refinement;
			}else{
				window.location="/"+type+ "/1/" + cat + "/" +product_name +".html?reffinement="+refinement;
			}
        }else if(refinement==""){
			if(cat==""){
				window.location="/"+type+ "/1/" + product_name +".html?orderBy="+order;
			}else{
				window.location="/"+type+ "/1/" + cat + "/" +product_name +".html?orderBy="+order;
			}
        }else{
			if(cat==""){
				window.location="/"+type+ "/1/" + product_name +".html?orderBy="+order+"&reffinement="+refinement;
			}else{
					window.location="/"+type+ "/1/" + cat + "/" +product_name +".html?orderBy="+order+"&reffinement="+refinement;   
			}
		}
    }
     function goToPageAuto(keyword){
                    
           keyword = keyword.replace("\"","");
           keyword = keyword.replace("&","");
           keyword = keyword.replace("'","");
           keyword = keyword.replace("*","");
	       keyword = keyword.replace("|","");
	       keyword = keyword.replace("/","");
	       keyword = keyword.replace("\/","");
	       keyword = keyword.replace("\\","");
	       keyword = keyword.replace(":","");	
    	   
	       window.location="/aramis.aspx?keyword=" + keyword;	   

        }  
   function goToPage(product_name, type, page, idcat, sortKey){
       product_name = product_name.replace("\"","");
       product_name = product_name.replace("&","");
       product_name = product_name.replace("'","");
       product_name = product_name.replace("*","");
	   product_name = product_name.replace("|","");
	   product_name = product_name.replace("/","");
	   product_name = product_name.replace("\/","");
	   product_name = product_name.replace("\\","");
	   product_name = product_name.replace(":","");	
	   
	   if(idcat=="")
	   {
	        window.location="/"+type+"/" + page + "/" + product_name +".html?orderBy="+sortKey;	   
	   }else{
	        window.location="/"+type+"/" + page + "/" + idcat + "/" + product_name +".html?orderBy="+sortKey;	   
	   }
	   
    }


    function favoris() {
        if ( navigator.appName != 'Microsoft Internet Explorer' )
        { 
            window.sidebar.addPanel("Votre Comparateur Wop-Shop.com","http://www.wop-shop.com/",""); 
        }
        else{ 
            window.external.AddFavorite("http://www.wop-shop.com/","Votre Comparateur Wop-Shop.com"); 
        }
    }


     function goToPageSimple(product_name, type, page, idcat, theme){
                    
           product_name = product_name.replace("\"","");
           product_name = product_name.replace("&","");
           product_name = product_name.replace("'","");
           product_name = product_name.replace("*","");
	       product_name = product_name.replace("|","");
	       product_name = product_name.replace("/","");
	       product_name = product_name.replace("\/","");
	       product_name = product_name.replace("\\","");
	       product_name = product_name.replace(":","");	
    	   
	       if(idcat=="")
	       {
	            window.location="" + theme + type+"/" + page + "/" + product_name +".html";	   
	       }else{
	            window.location="" + theme + type+"/" + page + "/" + idcat + "/" + product_name +".html";	   
	       }
        }  
    
    
    function checkEnter(e){ 
        var characterCode;
        if(e && e.which){ 
            e = e;
            characterCode = e.which ;
        }else{
            e = event;
            characterCode = e.keyCode ;
        }
        if(characterCode == 13){ 
            return true;
        }else{
            return false;
        }
    }
	
	function changeHover(elem){
	    //alert("fonction appl?");
	    for(i=0; i<4; i++){
	        if(i==elem){
	            document.getElementById("icone"+i).style.borderBottom="1px solid #ffffff";
	        }else{
                document.getElementById("icone"+i).style.borderBottom="1px solid #cccccc";
	        }
	    }
	}
	
	function checkDate(d1,d2){
	    if(d1>d2) alert("La date de d?part est apr?s la date d'arriv?e !")
	}

    
  function goToPageV3(base){
       var Marque;

       for(var i = 0; i < document.formsearch.Marque.length; i++) {
            if(document.formsearch.Marque[i].checked == true) {
            Marque = document.formsearch.Marque[i].value;
            }
       }
       
       var TypeVehicule;
       
       for(var i = 0; i < document.formsearch.TypeVehicule.length; i++) {
            if(document.formsearch.TypeVehicule[i].checked == true) {
            TypeVehicule = document.formsearch.TypeVehicule[i].value;
            }
       }
       
       var NbPorte;
       for(var i = 0; i < document.formsearch.NbPorte.length; i++) {
            if(document.formsearch.NbPorte[i].checked == true) {
            NbPorte = document.formsearch.NbPorte[i].value;
            }
       }
       
       var Carburant;
       for(var i = 0; i < document.formsearch.Carburant.length; i++) {
            if(document.formsearch.Carburant[i].checked == true) {
            Carburant = document.formsearch.Carburant[i].value;
            }
       }

        window.location=base + "auto/1/" + Marque +".html?filtre=_"+TypeVehicule+"_"+NbPorte+"_"+Carburant;
        //alert(base + "auto/1/" + Marque +".html?filtre=_"+TypeVehicule+"_"+NbPorte+"_"+Carburant);

    }

   function goToPageV2(base, Product){
       var Modele = document.getElementById("Modele").value;
       var TypeVehicule = document.getElementById("TypeVehicule").value;
       var NbPorte = document.getElementById("NbPorte").value;
       var Carburant = document.getElementById("Carburant").value;

        window.location=base + "auto/1/" + Product +".html?filtre="+Modele+"_"+TypeVehicule+"_"+NbPorte+"_"+Carburant;

    }

   function showFormulaire(base, Marque, productid, Modele, title, img){

        document.getElementById("FRMtitle").innerHTML = title;
        document.getElementById("FRMimgsite").innerHTML = "<img src='"+img+"'/>";
        document.frm.action.value = base + "devisauto/" + Marque + "/" + productid + "/" + Modele + ".html";
        document.getElementById("quickfrm").action = base + "devisauto/" + Marque + "/" + productid + "/" + Modele + ".html";
        document.getElementById("MainQuickForm").style.display = "inline";
        document.getElementById("SubMainQuickForm").style.display = "inline";
    }

    function CloseFormulaire(){
        document.getElementById("MainQuickForm").style.display = "none";
        document.getElementById("SubMainQuickForm").style.display = "none";
    }
       
    function goToPageAramis(base, Product, p, idProduct, name, type, filtre){

        Product = Product.replace("\"","");
        Product = Product.replace("&","");
        Product = Product.replace("'","");
        Product = Product.replace("*","");
        Product = Product.replace("|","");
        Product = Product.replace("/","");
        Product = Product.replace("\/","");
        Product = Product.replace("\\","");

        window.location=base+type+"/" +p+ "/" + Product +".html?filtre="+filtre;

    }

    function goToPageSearchAramis(base, Product, p, type){

        Product = Product.replace("\"","");
        Product = Product.replace("&","");
        Product = Product.replace("'","");
        Product = Product.replace("*","");
        Product = Product.replace("|","");
        Product = Product.replace("/","");
        Product = Product.replace("\/","");
        Product = Product.replace("\\","");

        window.location=base+type+"/" +p+ "/" + Product +".html";

    }


    function goToPageHomeDevis(base){
        window.location=base+"auto/default.html";
    }


    function isInt(x) {
        var y=parseInt(x);
        if (isNaN(y)) return false;
        return x==y && x.toString()==y.toString();
    } 

	
function isCodePostal(str) {
  // are regular expressions supported?
  var supported = 0;
  if (window.RegExp) {
    var tempStr = "a";
    var tempReg = new RegExp(tempStr);
    if (tempReg.test(tempStr)) supported = 1;
  }
  if (!supported) 
    return (str.length() == 5);
  var r1 = new RegExp("[0-9]{5}");
  return (r1.test(str));
}


function isPhonNumber(str) {
    str = str.replace(/\./g, "");
    str = str.replace(/-/g, "");
    str = str.replace(/_/g, "");
    str = str.replace(/\//g, "");
  // are regular expressions supported?
  var supported = 0;
  if (window.RegExp) {
    var tempStr = "a";
    var tempReg = new RegExp(tempStr);
    if (tempReg.test(tempStr)) supported = 1;
  }
  if (!supported) 
    return (str.length() == 10);
  var r1 = new RegExp("[0-9]{10}");
  return (r1.test(str));
}


function isEmail(str) {
  // are regular expressions supported?
  var supported = 0;
  if (window.RegExp) {
    var tempStr = "a";
    var tempReg = new RegExp(tempStr);
    if (tempReg.test(tempStr)) supported = 1;
  }
  if (!supported) 
    return (str.indexOf(".") > 2) && (str.indexOf("@") > 0);
  var r1 = new RegExp("(@.*@)|(\\.\\.)|(@\\.)|(^\\.)");
  var r2 = new RegExp("^.+\\@(\\[?)[a-zA-Z0-9\\-\\.]+\\.([a-zA-Z]{2,3}|[0-9]{1,3})(\\]?)$");
  return (!r1.test(str) && r2.test(str));
}

//use a sign $(id) to get the html object
function $(id) 
{
	var obj =false;
	obj = document.getElementById(id);
	if(obj)  return obj;
}


function updateCookie(){
 document.frm.nom.value = "";

}


function email_validator()
{
	// checks email address
	var a = document.frm.email.value;
	testm = false;
	if(a != "")
	{
		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;
					}
				}
			}
		}//for
	}//if

	if (testm==false)
	{
		alert("Votre adresse e-mail est incorrecte, s?il vous plait.");
		document.frm.email.focus();
		return false;
	}//if

	return true;
}

function jvalider()
{
	var ok = false;
	
	if(document.frm.nom && document.frm.nom.value == "")
	{
		alert("Nom obligatoire, s?il vous plait.");
		document.frm.nom.focus();
		ok = false;	

	}else if(document.frm.prenom && document.frm.prenom.value == "")
	{
		alert("prenom obligatoire, s?il vous plait.");
		document.frm.prenom.focus();
		ok = false;

	} else if((document.frm.codepostal && document.frm.codepostal.value == "") || isCodePostal(document.frm.codepostal.value)==false)
	{
		alert("Code Postal en 5 chiffres obligatoire, s?il vous plait.");
		document.frm.codepostal.focus();
		ok = false;

	}else if(document.frm.email && document.frm.email.value == "")
	{
		alert("Email obligatoire, s?il vous plait.");
		document.frm.email.focus();
		ok = false;

	}else if((document.frm.telephone && document.frm.telephone.value == "") || isPhonNumber(document.frm.telephone.value)==false)
	{
		alert("Telephone obligatoire, s?il vous plait.");
		document.frm.telephone.focus();
		ok = false;
	} else if(email_validator())
	{
		ok = true;
		document.frm.submit();
	}
	
}

function getXhr(){
    var xhr = null;
    if(window.XMLHttpRequest) // Firefox et autres
       xhr = new XMLHttpRequest(); 
    else if(window.ActiveXObject){ // Internet Explorer 
       try {
            xhr = new ActiveXObject("Msxml2.XMLHTTP");
        } catch (e) {
            xhr = new ActiveXObject("Microsoft.XMLHTTP");
        }
    }
    else { // XMLHttpRequest non support? par le navigateur 
       alert("Votre navigateur ne supporte pas les objets XMLHTTPRequest..."); 
       xhr = false; 
    } 
    return xhr;
}
    
function checkEmailAjax(){
    var email = document.frm.email.value;

    document.getElementById("responseemail").innerHTML = "";                    
    if(emailcheck(email)) {
        xhr = new getXhr;
        // On d?fini ce qu'on va faire quand on aura la r?ponse
        
        xhr.onreadystatechange = function(){
            // On ne fait quelque chose que si on a tout re?u et que le serveur est ok
            if(xhr.readyState == 4 && xhr.status == 200){
                leselect = xhr.responseText;
                
                if(leselect == "true"){
                    document.getElementById("responseemail").innerHTML = "<img src='/images/tick.png'/>";                
                }else{
                    document.getElementById("responseemail").innerHTML = "<img src='/images/bullet_error.png'/>";
                }   
             }
        }
        xhr.open("GET","/verifemail.aspx?email="+email,true);
        xhr.send(null); 
    }
}


function emailcheck(str) {

	var at="@"
	var dot="."
	var lat=str.indexOf(at)
	var lstr=str.length
	var ldot=str.indexOf(dot)
	if (str.indexOf(at)==-1){
	   return false
	}

	if (str.indexOf(at)==-1 || str.indexOf(at)==0 || str.indexOf(at)==lstr){
	   return false
	}

	if (str.indexOf(dot)==-1 || str.indexOf(dot)==0 || str.indexOf(dot)==lstr){
	    return false
	}

	if (str.indexOf(at,(lat+1))!=-1){
	    return false
	}

	if (str.substring(lat-1,lat)==dot || str.substring(lat+1,lat+2)==dot){
	    return false
	}

	if (str.indexOf(dot,(lat+2))==-1){
	    return false
	}
	
	if (str.indexOf(" ")!=-1){
	    return false
	}

	return true					
}


function checkNom(nom){
    var len = nom.length
    if(len > 1){
        document.getElementById("responsenom").innerHTML = "<img src='/images/tick.png'/>";
    }else{
        document.getElementById("responsenom").innerHTML = "<img src='/images/bullet_error.png'/>";
    }
}

function checkPrenom(nom){
    var len = nom.length
    if(len > 1){
        document.getElementById("responseprenom").innerHTML = "<img src='/images/tick.png'/>";
    }else{
        document.getElementById("responseprenom").innerHTML = "<img src='/images/bullet_error.png'/>";
    }
}


function checkAge(age){
    var len = age.length
    if(len < 3){
    document.getElementById("responseage").innerHTML = "<img src='/images/tick.png'/>";
    }else{
    document.getElementById("responseage").innerHTML = "<img src='/images/bullet_error.png'/>";
    }
}

function checkTel(tel){
    if((isPhonNumber(tel)) && tel!="" ){
        document.getElementById("responsetel").innerHTML = "<img src='/images/tick.png'/>";
    }else{
        document.getElementById("responsetel").innerHTML = "<img src='/images/bullet_error.png'/>";
    }
}



