// Fonction qui vérifie le format du mail (Présence du caractère "@", un "." après "@", au 
// moins deux lettres après le points et les textes à gauche et à droite du @ ne sont pas vides

//SHA 30/11/2007
function verifmail(unvalidated_mail,Ctrl)
{
	var x = Ctrl.value;
	var filter  = /^([a-zA-Z0-9_\.\-])+\@(([a-zA-Z0-9\-])+\.)+([a-zA-Z0-9]{2,4})+$/;
	if (filter.test(x))
	{
	     return true
	}
	else 
	{
	    //alert(unvalidated_mail);
	    //Ctrl.focus();
		return false;
	 }
}


function  checkNumeric( strValue ) {
/*****************************************************************
DESCRIPTION : Validates that a string contains only valid numbers.
PARAMETERS  :   strValue - String to be tested for validity
RETURNS     :   True if valid, otherwise false.
******************************************************************/
  var objRegExp  =  /(^-?\d\d*\.\d*$)|(^-?\d\d*$)|(^-?\.\d\d*$)/;
  //check for numeric characters
  return objRegExp.test(strValue);
}


function  checkInteger(strValue) 
{
/*****************************************************************
DESCRIPTION : Validates that a string is valid database Identifier (integer)
PARAMETERS  :   strValue - String to be tested for validity
RETURNS     :   True if valid, otherwise false.
******************************************************************/
  var objRegExp  = /(^\d\d*$)/;
  return objRegExp.test(strValue);
}

function checkZipCode( strValue ) {
/************************************************
DESCRIPTION: Validates that a string is Fr zip code in 5 digit 
  format. 99999 
PARAMETERS:  strValue - String to be tested for validity
RETURNS:   True if valid, otherwise false.
*************************************************/
var objRegExp  = /(^\d{5}$)/;
  //check for valid FR Zipcode
  return objRegExp.test(strValue);
}

/************************************************
DESCRIPTION: Vérifie qu'une date est valide (suivant le format jj/mm/aaaa) et qu'elle existe (ex : 12/13/2005 pas valide !) 
PARAMETERS:  strValue - String to be tested for validity
RETURNS:   True if valid, otherwise false.
*************************************************/
function checkFormatDate( strValue ) 
{
    var tabDate, newDate, year, returnValue;
    var objRegExp  = /^[0-9]{1,2}\/[0-9]{1,2}\/[0-9]{4}$/; 
    //expréssion régulière permettant de vérifier le format jj/mm/aaaa avec jj,mm et aaaa des nombres
    // On accepte que l'utilisateur ne rentre qu'un chiffre pour le jour et le mois.
    
    // 1) Vérif format
    if (objRegExp.test(strValue) == true)
    {
        // 2) Vérif validité date
        // 2.1) On récupère le jour, le mois et l'année sépremment dans un tableai
        tabDate = strValue.split("/");;

        // 2.2) Création d'une date avec l'objet javascript (new Date(année, mois, jour) avec mois valeur de 0 à 11 (d'ou le "-1")
        newDate = new Date(eval(tabDate[2]),eval(tabDate[1])-1,eval(tabDate[0]))
        
        // 2.3) Il se peut que le navigateur ne renvoit pas tjs 4 chiffres (pour les dates < 2000)
        year = newDate.getYear();
        if ((Math.abs(year)+"").length < 4) year = year + 1900

        // 2.3) Il ne reste plus qu'à vérifier si le jour, le mois et l'année obtenus sont les mêmes que ceux saisis par l'utilisateur.
        returnValue = ((newDate.getDate() == eval(tabDate[0])) && (newDate.getMonth() == eval(tabDate[1])-1) && (year == eval(tabDate[2])))
    }
    else
        returnValue = false;
        
    return returnValue;
}

function verifmailOLD(unvalidated_mail,Ctrl)
//<!--- Verif @ si la valeur est nulle --->
{
	//alert(Ctrl.value.length);
	if (Ctrl.value.length != 0)
	{
		if (Ctrl.value.indexOf("@")==-1) 
		{
			alert(unvalidated_mail);
			Ctrl.focus();
			return false;
		}
		else
		{
            longueur = Ctrl.value.length;
            position = Ctrl.value.indexOf("@");
            left_str = Ctrl.value.substring(0,position);
            right_str = Ctrl.value.substring(position+1,longueur);
            left_len = left_str.length;
            right_len = right_str.length;

//<!--- si la valeur gauche ou droite du @ est vide --->
            if ((left_len==0) || (right_len==0))
            {
                alert(unvalidated_mail);
                Ctrl.focus();
                return false;
            }
            else
            {
//<!--- s'il n'y a pas de point --->
                if (right_str.indexOf(".")==-1)
                {
                    alert(unvalidated_mail);
                    Ctrl.focus();
                    return false;
                }
                else
                {
                    right_longueur = right_str.length;
                    right_position = right_str.lastIndexOf(".");
                    l_right_str = right_str.substring(0,right_position);
                    r_right_str = right_str.substring(right_position+1,right_longueur);
                    l_right_len = l_right_str.length;
                    r_right_len = r_right_str.length;

//<!--- s'il y a au moins 2 lettres après le point --->
                    if ((r_right_len < 2)||(r_right_len > 4))
                    {
                        alert(unvalidated_mail);
                        Ctrl.focus();
                        return false;
                    }
                    else
                    {
//<!--- s'il y a au moins 1 lettre après le point --->
                        if (l_right_len==0)
                        {
                            alert(unvalidated_mail);
                            Ctrl.focus();
                            return false;
                        }
                        else
						{return true}
                    }
                }
            }
		}
	}
	else
		{return true}
}

function ShowSpans(id)
{
    var SpanObj = (document.getElementById) ? document.getElementById(id) : eval("document.all['" + id + "']");
	if (SpanObj != null)
    	SpanObj.style.display="";
}

function HideSpans(id)
{
    var SpanObj = (document.getElementById) ? document.getElementById(id) : eval("document.all['" + id + "']");
	
	if (SpanObj != null)
	    SpanObj.style.display="none";
}

// Show or hide an object (fonction prise du site admin)
function ShowHideSpans(id)
{
    var SpanObj = (document.getElementById) ? document.getElementById(id) : eval("document.all['" + id + "']");

    if (SpanObj != null) 
    {
        if (SpanObj.style.display=="none")
		    SpanObj.style.display="";
	    else
		    SpanObj.style.display="none";
	}
}

function PopupImage(img, titre, auteur) { 
  // Compatible IE5+ / NN6+ / Mozilla
  oFenetre = window.open('/popup.asp?title='+titre+'&author='+auteur+'&image='+img,'Image','height=100,width=100,toolbar=no,scrollbars=no,resizable=no');
}

function getBrowserWidth()
{
	if (window.innerWidth)
	{
		return window.innerWidth;
	}
	else if (document.documentElement && document.documentElement.clientWidth != 0)
	{
		return document.documentElement.clientWidth;
	}
	else if (document.body)
	{
		return document.body.clientWidth;
	}
	
	return 0;
};

//fonction qui permet de lancer une popup alert pour signaler l'abscence de l'entrée d'un champ obligatoire 
// Entrée : 
// - intro : message d'introduction pour signaler qu'un ou plusieurs champ(s) obligatoire(s) ne sont pas renseigné
// - Ctrl : id du champ à tester
// - Nom_Champ : nom du champ (pour affichage à l'utilisateur) à tester
function alertFieldEmpty(intro,Ctrl,Nom_Champ)
{
    if (Ctrl.value == "")
	{
            alert (intro + " " + Nom_Champ);
            Ctrl.focus();
            return (false);
    } else
            return (true);
}

function correctPNG() // correctly handle PNG transparency in Win IE 5.5 & 6.
{
   var arVersion = navigator.appVersion.split("MSIE")
   var version = parseFloat(arVersion[1])
   if ((version >= 5.5) && (document.body.filters)) 
   {
      for(var i=0; i<document.images.length; i++)
      {
         var img = document.images[i]
         var imgName = img.src.toUpperCase()
         if (imgName.substring(imgName.length-3, imgName.length) == "PNG")
         {
            var imgID = (img.id) ? "id='" + img.id + "' " : ""
            var imgClass = (img.className) ? "class='" + img.className + "' " : ""
            var imgTitle = (img.title) ? "title='" + img.title + "' " : "title='" + img.alt + "' "
            var imgStyle = "display:inline-block;" + img.style.cssText 
            if (img.align == "left") imgStyle = "float:left;" + imgStyle
            if (img.align == "right") imgStyle = "float:right;" + imgStyle
            if (img.parentElement.href) imgStyle = "cursor:hand;" + imgStyle
            var strNewHTML = "<span " + imgID + imgClass + imgTitle
            + " style=\"" + "width:" + img.width + "px; height:" + img.height + "px;" + imgStyle + ";"
            + "filter:progid:DXImageTransform.Microsoft.AlphaImageLoader"
            + "(src=\'" + img.src + "\', sizingMethod='scale');\"></span>" 
            img.outerHTML = strNewHTML
            i = i-1
         }
      }
   }    
}


// DRO 29/11/2008 Ne pas charger correctPNG dans certaines pages
if(typeof(is_correctPNG)==undefined)
{
    //set page event handlers for onload
    if (window.attachEvent)
    {
     window.attachEvent("onload", correctPNG);
    }
    else
    {
     window.addEventListener("DOMContentLoaded", correctPNG, false);
    }
}

// ****************************************************************************************
// Autorise la saisie de chiffre uniquement dans les champs TEXTE
// ****************************************************************************************
// ************************************************************
// Autorise la saisie de chiffre uniquement dans un champ TEXTE
// ************************************************************
function onlyNumber(event) 
{
	try
	{
	 

	    // IE ou Firefox
	    if(!event&&window.event) 
	    {
		    event=window.event;
	        // IE : Autorise les caractères : "." et "," et "-"
            if (event.keyCode > 43 && event.keyCode < 47)
            {
    	        return true;
            }
            // IE : Autorise le backSpace
            if (event.keyCode == 8)
            {
    	        return true;
            }
            // IE : Autorise les numériques
	        if(event.keyCode < 48 || event.keyCode > 57) 
	        {
		        event.returnValue = false;
		        event.cancelBubble = true;
		        return false;
	        }
	    }
	    else if(event.which)
	    {
	        // Firefox : Autorise les caractères : "." et ",", backSpace
	        if (event.which > 43 && event.which < 47)
            {
    	        return true;
            }
            // Firefox : Autorise le backSpace            
            if (event.which == 8)
            {
    	        return true;
            }
            // Firefox : Autorise les numériques
	        if(event.which < 48 || event.which > 57) 
	        {
		        event.preventDefault();
		        event.stopPropagation();
		        return false;
	        }
	    }
	   } 
	   catch(e)
	   {
            alert('Erreur\t: ' + e.description+'\nPage\t: OscaroUtils.asp\nFonction\t: onlyNumber()');
            return false;
	   }
}

//Permet la saisie de numérique + l'Espace
// Saisie d'un n° de téléphone
function onlyPhoneNumber(e)
{
    var IE5 = false;
    if (!e) var e = window.event;
    if (e.keyCode) { IE5= true; code = e.keyCode;}
    else if (e.which) code = e.which ;

    //test du code
    if (code != 32  && code < 48 || code > 57)
    {
        if(IE5) e.returnValue = false;
        else e.preventDefault();
    } 

}

// ****************************************************************************************
// Autorise la saisie de chiffre uniquement dans un champ TEXTE
// -blnOnlyNumeric : Autorise la saisie des séparateur ".", "," et "-" pour champs "Montant"
// ****************************************************************************************
function onlyValidPostalCode(event) 
{
	try
	{
	    // IE ou Firefox
	    if(!event&&window.event) 
	    {
		    event=window.event;
	    }
	    // IE : Autorise les caractères : "a","A","b" et "B"
        if (event.keyCode == 65 || event.keyCode == 66 || event.keyCode == 97 || event.keyCode == 98)
        {
    	    return true;
        }
        // IE : Autorise les numériques
	    if(event.keyCode < 48 || event.keyCode > 57) 
	    {
		    event.returnValue = false;
		    event.cancelBubble = true;
		    return false;
	    }
	    
	    // Firefox :  Autorise les caractères : "a","A","b" et "B"
	    if (event.which == 65 || event.which == 66 || event.which == 97 || event.which == 98)
        {
    	    return true;
        }
        // Firefox : Autorise les numériques
	    if(event.which < 48 || event.which > 57) 
	    {
		    event.preventDefault();
		    event.stopPropagation();
		    return false;
	    }
	   } 
	   catch(e)
	   {
            alert('Erreur\t: ' + e.description);
            return false;
	   }
}

// getPageSize()
// Retourne un tableau avec la largeur et la hauteur de la page page + la largeur et la hauteur de la fenêtre
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){ // Pour tout navigateur sauf Explorer pour Mac
		xScroll = document.body.scrollWidth;
		yScroll = document.body.scrollHeight;
	} else { // Explorer pour Mac...marche aussi pour Explorer 6, Mozilla and Safari
		xScroll = document.body.offsetWidth;
		yScroll = document.body.offsetHeight;
	}
	
	var windowWidth, windowHeight;
	
	if (self.innerHeight) {	// Tout navigateur sauf Explorer
		if(document.documentElement.clientWidth){
			windowWidth = document.documentElement.clientWidth; 
		} else {
			windowWidth = self.innerWidth;
		}
		windowHeight = self.innerHeight;
	} else if (document.documentElement && document.documentElement.clientHeight) { // Explorer 6
		windowWidth = document.documentElement.clientWidth;
		windowHeight = document.documentElement.clientHeight;
	} else if (document.body) { // Autres versions d'Explorer
		windowWidth = document.body.clientWidth;
		windowHeight = document.body.clientHeight;
	}	
	
	// Pour des pages plus petite que la résolution "Hauteur" de l'écran
	if(yScroll < windowHeight){
		pageHeight = windowHeight;
	} else { 
		pageHeight = yScroll;
	}

	// Pour des pages plus petite que la résolution "largeur" de l'écran
	if(xScroll < windowWidth){	
		pageWidth = xScroll;		
	} else {
		pageWidth = windowWidth;
	}

	arrayPageSize = new Array(pageWidth,pageHeight,windowWidth,windowHeight) 
	return arrayPageSize;
}

// Fonction permettant de faire une pause de "x" ms ...
function pause(ms){
	var date = new Date();
	curDate = null;
	do{var curDate = new Date();}
	while( curDate - date < ms);
}


function trim(str, chars) {
    return ltrim(rtrim(str, chars), chars);
}

function ltrim(str, chars) {
    chars = chars || "\\s";
    return str.replace(new RegExp("^[" + chars + "]+", "g"), "");
}

function rtrim(str, chars) {
    chars = chars || "\\s";
    return str.replace(new RegExp("[" + chars + "]+$", "g"), "");
}


//ouvrir un popup avec des args, un url, un target et des tailles
function JumpPopup(url, args, target, width, height) {
	if (args.length > 0)
		args = '?' + args
	else
		args = '';		
	//wtop = 20;
	//wleft = 20;	
	//param = "width=" + width + ",height=" + height + ",scrollbars=yes,status=yes,resizable=yes," + "left=" + wleft + ",top=" + wtop;
	
	leftVal= (screen.width  - (0.92 * screen.width)) / 2;
    topVal = (screen.height - (0.95 * screen.height)) / 2;
	param = "width="+(0.90 * screen.width)+",height="+(0.85 * screen.height)+",scrollbars=yes,status=yes,resizable=yes,left="+leftVal+",top="+topVal;
	
	new_win=open(url+args,target,param);
}


//--- Gestion de l'affichage des menus ---
function ShowHideMenu(IdMenu){
    var i;
    var nb_menu;
    
    nb_menu = 4;
    for(i=1;i<=nb_menu;i++){
        if(i!=IdMenu)
            document.getElementById('Menu'+i).style.visibility = 'hidden';
        else
            document.getElementById('Menu'+i).style.visibility = 'visible';
    }
}

function HideMenu(IdMenu){
    document.getElementById('Menu'+IdMenu).style.visibility = 'hidden';
}
//---------------------------------------

//--- Validation du finder par ref ---
function validRef()
{
    document.getElementById("WarningNbCar").style.display="none";
    if (document.getElementById("Find").value.length < 4)
        document.getElementById("WarningNbCar").style.display="";
    else
        document.getElementById("finder").submit();
}
//------------------------------------

//--- Ajout de parametre a une URL ---
function addParam(anchor, param)
{
    anchor.href += param;
}
//------------------------------------

//--- Validation des CGV sur panier_etape2.asp ---    
function checkCGV(ID_CLIENT_ORDERS, LAST_NAME){
    if(document.getElementById('acceptCGV').checked == false){
        alert(ALERT_ACCEPT_CGV);
        document.getElementById('trMissingCGVCheck').style.display = '';
        return false;
    }else{
        acceptCGV(ID_CLIENT_ORDERS,LAST_NAME);
        return true;
    }
}
//------------------------------------