
function getObj(objID)
{
    if (document.getElementById) {return document.getElementById(objID);}
    else if (document.all) {return document.all[objID];}
    else if (document.layers) {return document.layers[objID];}
}  
    
    
function getObjParent(objID)
{
    if (parent.document.getElementById) {return parent.document.getElementById(objID);}
    else if (parent.document.all) {return parent.document.all[objID];}
    else if (parent.document.layers) {return parent.document.layers[objID];}
}    
    
function newWin(url,width,height) {
    window.open(url,"remoteWin","width="+width+",height="+height+",resizable=1,menubar=0,status=0,scrollbars=1");
}

function isNull(val){return(val==null);}

function isNumeric(x) {
    // I use this function like this: if (isNumeric(myVar)) { }
    // regular expression that validates a value is numeric
    var RegExp = /^(-)?(\d*)(\.?)(\d*)$/; // Note: this WILL allow a number that ends in a decimal: -452.
    // compare the argument to the RegEx
    // the 'match' function returns 0 if the value didn't match
    var result = x.match(RegExp);
    return result;
}

function print_r(theObj){
  if(theObj.constructor == Array ||
     theObj.constructor == Object){
    document.write("<ul>")
    for(var p in theObj){
      if(theObj[p].constructor == Array||
        theObj[p].constructor == Object){
        document.write("<li>["+p+"] => "+typeof(theObj)+"</li>");
        document.write("<ul>")
        print_r(theObj[p]);
        document.write("</ul>")
      } else {
        document.write("<li>["+p+"] => "+theObj[p]+"</li>");
      }
    }
    document.write("</ul>")
  }
}

function toggleSearch(isOn, textAAjouter, ctrl) { 

	if (!isOn) {
		
		if(getObj(ctrl).value == ""){
		    getObj(ctrl).value = textAAjouter;
		}			
		getObj(ctrl).className = "search_inactive";
		
	} 
	
	if (isOn) {
	
		getObj(ctrl).className = "search_active";
		
		getObj(ctrl).value = "";
		
	}
}

function lancerRecherche(strKeyword){window.location = "http://" + location.host + "/" + GD_VERSION_NAME + "/produit/recherche.aspx?strS=" + strKeyword}

function fnct_onKeyDown(evenement)
{
    var touche = window.event ? evenement.keyCode : evenement.which;
    if (touche == 13)        
        return false;                 
 }        

function soumettreRecherche(formName,path,e){
    var formRecherche = getObj(formName);
    formRecherche.action = path + '?strS=' + getObj('strS').value;
    formRecherche.submit();
}	
	
function changeQty(path,formName){
    var formPanier = getObj(formName);
    formPanier.action = path;
    formPanier.submit();    
}

function supprimerAdresseShipping(path){
    if(confirm(MSGC00001)){
        window.location = path;
    }
}

function validationLogin(){

	var objForm = document.getElementById("form_connexion");
    
    if((objForm.login.value.length > 0) && (objForm.password.value.length > 0))
    {
        objForm.txtValide.value = '1';
        objForm.submit();  
             
    }
    else
    {   
        objForm.txtValide.value = '0';
    }
 
}

function enregistrerChoix(){

    getObj(document.forms[0].name).action= 'gestion.aspx?save=1';
    getObj(document.forms[0].name).submit();

}

function frmValidation_submit(formName){

    var formPanier = getObj(formName);
    formPanier.submit(); 

}

function forceMaxLength(objTxtArea, intMaxLen)
{
    if (objTxtArea.value.length > intMaxLen)
    {
        objTxtArea.value = objTxtArea.value.substring(0, intMaxLen);
    }
}

function trim(strValue)
{
    var objString = new String(strValue);
    return objString.replace(/(?:(?:^|\n)\s+|\s+(?:$|\n))/g,"");
}

function isValidEmail(strEmail)
{
    var regExpEmail = /^([a-zA-Z0-9_\.\-])+\@(([a-zA-Z0-9\-]{2,})+\.)+([a-zA-Z0-9]{2,4})+$/;	
    return regExpEmail.test(strEmail);
}

function setSelectInput(objSelect, val)
{
	for( var i=0, limit=objSelect.options.length; i < limit; ++i )
	{
		if( objSelect.options[i].value==val )
			objSelect.options[i].selected=true;
	}
}
