var ibLanguageClientID = "";
var bVatClientId = "";
/**********************************************************************/
/*   Used by CK. This used to prevent the user from changing the      */
/*   version by hiting the enter key when no control has the focus    */
/**********************************************************************/

function callStopEnterKeyFunction(){
    document.onkeydown = stopEnterKey;
}

function stopEnterKey(evt){

    // Here we get the target ie the name of the control 
    // that the onkeydown event was fired on
    var targ;
    
	if( !e )
	    var e = window.event;
	try{
	if( e.target )
	    targ = e.target;
	else
	    if( e.srcElement )
	        targ = e.srcElement;
	if( targ.nodeType == 3 )// defeat Safari bug
		targ = targ.parentNode;

    // if our target == bVatClientId, the enter key was pressed while the 'change version' ( bVAT )
    // button had the focus so we can process the client's request
    if( targ.id == bVatClientId ){
    
        evt = (evt) ? evt : event;

        var charCode = (evt.charCode) ? evt.charCode :
            ((evt.which) ? evt.which : evt.keyCode);
        if( charCode == 13 )
            return true;
    }
    else{
        // If no control has the focus we get one of these values as target id
        // in this case we return true if the charCode is anything else the the return key
        if( targ.id == "" || targ.id == "ctl00_body" ){
            
            evt = (evt) ? evt : event;

            var charCode = (evt.charCode) ? evt.charCode :
                ((evt.which) ? evt.which : evt.keyCode);

            if( charCode == 13 ) // charcode 13 is the return key
                return false;
            else
                return true;
         }
         // else we return true and the default button set for the current form will be used to fire the required event
         else
            return true;
        }
    }
    catch(error){
    }
}


function completeCardHolderName(tbFirstName,tbLastName,tbCardHolderName)
{
    var fn = document.getElementById( tbFirstName );
    var ln = document.getElementById( tbLastName );
    var ch = document.getElementById( tbCardHolderName );
    
    ch.value = fn.value + ' ' + ln.value;
}

    function SubmitLastMinuteProduct(frm){
        frm.action="../cart/cart_cart.asp";
    }
	function cartridgeUpdate(val)
    {   
        if(val != ''){            
            document.forms['search_form'].action  = val;
        }
        document.forms['search_form'].submit();
    }
        
    function cartridgeLink()
    {   
        document.forms['search_form'].action  = document.getElementById('cartridgeBrand').value;
        document.forms['search_form'].submit();
    }
        
    function LeftFormCheck(sURL)
    {
        document.forms.local_nav_form.action  = sURL;
        document.forms.local_nav_form.submit();
    }
        
    function LeftFormCheckForgottenPassword(sURL)
    {   var sUrl2;
        sUrl2 = ""
        if (document.getElementsByName("acct_login_txtEmail")[0]){
            sUrl2 = "?";
            if (sURL.indexOf("?") > 0){
                sUrl2 = "&";            
            }
            sUrl2 = sUrl2 + "passwordForgotten=true";           
        }
        sURL = sURL + sUrl2;
        LeftFormCheck(sURL);
    }
        
    function updateTextBox_onfocus(field,defaultValue)
    {
        if (field.value == defaultValue)
        {
            field.value="";
        }
    }

    function updateTextBox_onblur(field,defaultValue)
    {      
        if (field.value == '')
        {
            field.value=defaultValue;
        }
    }
    
    function enterPress(evt,element,action)
    { 
        flag=0;
        if (!evt) var evt = window.event; 

        if (evt.which){
            code = evt.which ;
            flag=1;
        }else{
            code = evt.keyCode;   
        }            				
				
		if (code == 13)
		{  		   
            if(action == 'focus') element.focus();
            if(action == 'click') element.click();
		    if(action == 'submit') element.submit();	  
		    
		    if (flag == 0){ 
		        evt.returnValue = false;  		       
            }
            else{      
                evt.preventDefault();    
            } 		      
		}		
	}
	


var spaceBorder = 13;
var heightPopup = 150;
var widthPopup = 313;
var topPopup = (screen.height-heightPopup)/2 - (heightPopup/2);
var leftPopup= (screen.width-widthPopup)/2;

var bgColor = "#FFFFFF";

var fontFamily = "Arial";
var fontSize = "12";
var fontColor = "#000000";

var Ombre = 1;

var clic = false;
function clicDown(tab) {
	abscisse = abs-leftPopup;
	ordonne = ord-topPopup;
	clic=true;
}
function clicUp() {
		clic=false;
}
function closePopup(popupID) {
	document.getElementById(popupID).style.visibility="hidden";
}

function hidePopup(elementId)
{
	document.getElementById(elementId.id).style.display = 'none';
}

function showPopup(popupID,delayHidePopup) {
    var scrOfX = 0, scrOfY = 0;
    var scrOfW = 0, scrOfH = 0;
    if( typeof( window.pageYOffset ) == 'number' ) {
        //Netscape compliant
        scrOfY = window.pageYOffset;
        scrOfX = window.pageXOffset;
    } else if( document.body && ( document.body.scrollLeft || document.body.scrollTop ) ) {
        //DOM compliant
        scrOfY = document.body.scrollTop;
        scrOfX = document.body.scrollLeft;
    } else if( document.documentElement && ( document.documentElement.scrollLeft || document.documentElement.scrollTop ) ) {
        //IE6 standards compliant mode
        scrOfY = document.documentElement.scrollTop;
        scrOfX = document.documentElement.scrollLeft;
    }
        
    var oDiv = document.getElementById(popupID);
    scrOfW = oDiv.clientWidth;
    scrOfH = oDiv.clientHeight;
    oDiv.style.left = scrOfX + (screen.width-scrOfW)/2;
    oDiv.style.top = scrOfY + (screen.height-scrOfH)/2 - (scrOfH/2);
	oDiv.style.visibility="visible";
	oDiv.style.zIndex=100;
	setTimeout("hidePopup("+popupID+")",delayHidePopup);
	return false;
}

function displayPopup(popupID,url,delayHidePopup)
{
	document.location.href = url;
	return showPopup(popupID,delayHidePopup);
}

function submitWithPopup(popupID,myForm,delayHidePopup)
{
	//document.forms[myForm].submit();
	showPopup(popupID,delayHidePopup);
	return true;
}

function popup(popupID,myText,width,height){
    heightPopup = height+13;
    widthPopup = width;
    topPopup = (screen.height-heightPopup)/2 - (heightPopup/2);
    leftPopup= (screen.width-widthPopup)/2;

	if (document.getElementById) {
		document.write('<style type="text/css">')
		document.write('table.popup {')
		document.write('	border: 1px solid #000000;}')
		document.write('td.corps {')
		document.write('	font-family: '+fontFamily+';')
		document.write('	font-size: '+fontSize+'px;')
		document.write('	color: '+fontColor+';}')
		document.write('</style>')
		document.write('<DIV id='+ popupID +' STYLE="position:absolute; top:'+topPopup+'px; left:'+leftPopup+'px;visibility:hidden;">')
	
		if (Ombre == 1 ) {
			document.write('<table width="'+widthPopup+'" height="'+heightPopup+'" border="0" cellspacing="0" cellpadding="0">')
			document.write('<tr> ')
			widthPopup -= 5
			heightPopup -= 5
			document.write('<td width="'+widthPopup+'"  height="'+heightPopup+'" colspan="2" rowspan="2" align="left" valign="top">')
		}
        
		document.write('<table width="'+widthPopup+'"  height="'+heightPopup+'" border="0" cellspacing="0" cellpadding="0" class="popup">')
		widthPopup -= spaceBorder
		heightPopup -= spaceBorder
		document.write('<tr valign="top">') 
		document.write('<td bgcolor="'+bgColor+'" width="'+widthPopup+'" height="'+heightPopup+'" class="corps">'+myText+'</td>')
		document.write('</tr>')
		document.write('</table>')
	
		if (Ombre == 1 ) {
			document.write('</td>')
			document.write('<td width="5" height="5"></td>') 
			document.write('</tr>')
			document.write('<tr>')
			document.write('<td width="5" height="'+heightPopup+'"></td>')
			document.write('</tr>')
			document.write('<tr> ')
			document.write('<td height="5" width="5"></td>')
			document.write('<td height="5" width="'+widthPopup+'" ></td>')
			document.write('<td height="5" width="5" ></td>')
			document.write('</tr>')
  			document.write('</table>')
		}
		document.write('</div>')
	}
}

function switchAddress(typeAddress, divBill, divShip){

    if (typeAddress == 'ship'){
        document.getElementById(divBill).style.display = "none";
        document.getElementById(divShip).style.display = "block";
    }else{
        if (document.getElementById(divBill)!=null)
        {
            document.getElementById(divBill).style.display = "block";
        }
        if (document.getElementById(divShip)!=null)
        {
            document.getElementById(divShip).style.display = "none";
        }
    }	   
}

function popupWarranty(url,parameter){	
    window.open(url,'garantie_window',parameter); return false;
}

function checkCouponCodeEntered(fieldID){

    if (fieldID != undefined && document.getElementById(fieldID).value == '') {
        return false;
    }else{
        return true;
    }
}

function popupPrintOrder(url, parameter){
    window.open(url,'printOrder',parameter); return false;
}

function loadIFRAME() {
	if (document.getElementById) {  // DOM3 = IE5, NS6
	    document.getElementById('preloadIMG').style.visibility = 'hidden';
	}
}

function Reload () {
    var f = document.getElementById('framepsp');

}

function countChars( tbToValidate, nbChar )
{                      
    var s = "";
    s = tbToValidate.value;
    
    var len = s.length;

    if( len > nbChar )
    {
        s = s.substring( 0,nbChar );
        tbToValidate.value = s;
        return false;
    }         
}

function ReloadPage(){
    var hRefresh=document.getElementById("hRefresh");
    var allowed=CaptEvent(event);
    //Avoir Reload twice if user clicks on F5
    if (allowed) {
        if (hRefresh){   
            if(hRefresh.value=="no")
                hRefresh.value="yes";           
            else{
                hRefresh.value="no";
                location.reload();        
            }
        }
    }
}

function CaptEvent(event){
    switch (event.keyCode) {
    case 116: // Appui sur touche F5
        //alert('interdit');
        // Code de blocage ici, IE ne doit pas interpéter le F5 !!
        return false; // C'est la que l'on détermine si l'événement
        break;
    }
}


function evalQuantityKeyUp (sMultiple,tbQuantity,lErrorQuantity ){
     
    var mLErrorQuantity = document.getElementById(lErrorQuantity); 
    var mTbQuantity = document.getElementById(tbQuantity);  
    if (mLErrorQuantity != null && mTbQuantity != null ){
        var sQty=mTbQuantity.value;
        var val=Math.round(sQty/sMultiple);      
        
        if ((val != (sQty/sMultiple)) || (val ==0) ){   
            mLErrorQuantity.style.display="inline";         
        }else{
            mLErrorQuantity.style.display="none";  
        } 
    }                       
}

function evalQuantityBlur (sMultiple,tbQuantity,lErrorQuantity ){ 
    var mLErrorQuantity = document.getElementById(lErrorQuantity);     
    var mTbQuantity = document.getElementById(tbQuantity);  
    if (mLErrorQuantity != null && mTbQuantity != null){
        var sQty=mTbQuantity.value;
           
        var val=Math.round(sQty/sMultiple);

        if ((val != (sQty/sMultiple)) || (val ==0) ){  
            mLErrorQuantity.style.display="inline";
            if (val == 0){
                val=1;
            }
            val=val*sMultiple;  
             
            if (val < sQty) {
                val = val + sMultiple
            }
            
           mTbQuantity.value = val
                   
             mLErrorQuantity.style.display="none";      
        }else{
            mLErrorQuantity.style.display="none";  
        } 
    }                        
}

function countPasswordCharacters(tbToValidate, constant, counterTb) {

    var countTb = document.getElementById(counterTb);
    var tbToVal = document.getElementById(tbToValidate);

    if (tbToValidate === null) { }
    else {
        var s = "";
        s = tbToVal.value;
        
        var len = s.length;

        if (len > constant) {
            s = s.substring(0, constant);
            tbToVal.value = s;

            return false;

        }

        var remainingChars = constant - len;

        if (document.all) {
            countTb.innerText = remainingChars.toString();
        }
        else {// Firefox
            countTb.textContent = remainingChars.toString();
        }

        countTb.value = constant - len;
    }
}
