// <!--// Global Initializationvar validChars = "1234567890abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ";var msg = ""; // instantiate the msg variable, that will be used in the error dialog boxvar CurDoc ;var isSpecialMsg = false ;var msgErrorIntro = ""; //needed in case InitVal is called before the getScript finish// Get the Labels (using jQuery)...$.getScript( strCurProtocol+"//"+strCurServer+strCurDB+"0/999999990000000085257514007311D7?OpenDocument" );//var msgJS = makeHttpRequest( strCurProtocol+"//"+strCurServer+strCurDB+"0/999999990000000085257514007311D7?OpenDocument" , "", false );//eval( msgJS );function getFieldValue( field ) {	switch( field.type ) {	case "text" :	case "textarea" :	case "password" :	case "hidden" :		return field.value;	case "select-one" :		var i = field.selectedIndex;		if (i == -1)   return "";		else   return (field.options[i].value == "") ? field.options[i].text : field.options[i].value;	case "select-multiple" :		var allChecked = new Array();		for(i = 0; i < field.options.length; i++)		if(field.options[i].selected)			allChecked[allChecked.length] = (field.options[i].value == "") ? field.options[i].text : field.options[i].value;		return allChecked;	case "button" :	case "reset" :	case "submit" :		return "";	case "radio" :	case "checkbox" :		if (field.checked) { return field.value; } else { return ""; }	default :		if(field[0].type == "radio") {			for (i = 0; i < field.length; i++)				if (field[i].checked) return field[i].value;			return "";		} else if(field[0].type == "checkbox") {			var allChecked = new Array();           			for(i = 0; i < field.length; i++)              				if(field[i].checked) allChecked[allChecked.length] = field[i].value;			return allChecked;		} else			var str = "";			for (x in field) { str += x + "\n"; }			alert("Unknown field type...\n\n" + field.name + ": ???\n\n\n" + str + "\n\nlength = " + field.length);		break;	}	return "";}function isCreditCard(st) {	// Encoding only works on cards with less than 19 digits	if (st.length > 19) return (false);	sum = 0; mul = 1; l = st.length;	for (i = 0; i < l; i++) {		digit = st.substring(l-i-1,l-i);		tproduct = parseInt(digit ,10)*mul;		if (tproduct >= 10) { sum += (tproduct % 10) + 1; } else { sum += tproduct; }		if (mul == 1) { mul++; } else { mul--; }	}	if ((sum % 10) == 0) { return (true); } else { return (false); }}function isVisa(cc) {	if (((cc.length == 16) || (cc.length == 13)) && (cc.substring(0,1) == 4))	return isCreditCard(cc);	return false;}function isMasterCard(cc) {	firstdig = cc.substring(0,1);	seconddig = cc.substring(1,2);	if ((cc.length == 16) && (firstdig == 5) && ((seconddig >= 1) && (seconddig <= 5)))    	return isCreditCard(cc);	return false;}function isAmericanExpress(cc) {	firstdig = cc.substring(0,1);	seconddig = cc.substring(1,2);	if ((cc.length == 15) && (firstdig == 3) && ((seconddig == 4) || (seconddig == 7)))	return isCreditCard(cc);	return false;}function isDinersClub(cc) {	firstdig = cc.substring(0,1);	seconddig = cc.substring(1,2);	if ((cc.length == 14) && (firstdig == 3) && ((seconddig == 0) || (seconddig == 6) || (seconddig == 8)))	return isCreditCard(cc);	return false;}function isDiscover(cc) {	first4digs = cc.substring(0,4);	if ((cc.length == 16) && (first4digs == "6011"))	return isCreditCard(cc);	return false;}function isJCB(cc) {	first4digs = cc.substring(0,4);	if ((cc.length == 16) && ((first4digs == "3088") || (first4digs == "3096") || (first4digs == "3112") ||	(first4digs == "3158") || (first4digs == "3337") || (first4digs == "3528")))	return isCreditCard(cc);	return false;}function stripCharsInBag(s, bag) {	// Removes all characters which appear in string bag from string s.	var i;	var returnString = "";	// Search through string's characters one by one. If character is not in bag, append to returnString.	for (i = 0; i < s.length; i++) {   		// Check that current character isn't whitespace.		var c = s.charAt(i);		if (bag.indexOf(c) == -1) returnString += c;		// for not in bag : if (bag.indexOf(c) != -1) returnString += c;	}	return returnString;}function stripWhitespace(s) {	// Removes all whitespace characters from s.	return stripCharsInBag (s, whiteSpace);}function FieldNotValid(pField, pErrorMsg, pType, pMandatory ) {	// return true if something went wrong .... false if everything seems Ok here...	var vString = getFieldValue( pField ) ;	if ( pMandatory ) { // If it can not be empty...		if ( isWhitespace( vString ) ) {			if ( !isSpecialMsg ) { msg+="\r\n" + "- "+pErrorMsg + msgSep + msgNeedValue ; }			pField.focus() ;			return true ;		}	}	if ( pType=="" ) { return false ; } // No specific caracter to check : all is good....	if ( pType=="Full") {//		var NotValidChars = "&?#$/:";		var NotValidChars = "/\""; // We do a escape to all...		for ( var i = 0; i < NotValidChars.length; i++ ) {		  	if ( vString.indexOf( NotValidChars.substring(i,i+1) ) != -1 ) {				if ( !isSpecialMsg ) { msg+="\r\n" + "- "+pErrorMsg + msgSep + msgWrongChar ; }				pField.focus() ;				return true ;			}		}	} else  {		var ThisValidChars = validChars ;		if (pType=="Coupon") ThisValidChars = validChars + "@._";	// Coupon Code		if (pType=="Card") ThisValidChars = "0123456789";		// CreditCard & CVD Check		if (pType=="Phone") ThisValidChars = validChars + "@.()-_+ ";	// Phone Check		if (pType=="Login") ThisValidChars = validChars + "@_-.+= ";		// Login Check - we should have / and % too, for email, but kind of tricky when we set the userName in the URL...		if (pType=="Pass") ThisValidChars = validChars + "_-.+= ";		// Password Check		for ( var i = 0; i < vString.length; i++ ) {		  	if ( ThisValidChars.indexOf( vString.substring(i,i+1) ) == -1 ) {				if ( !isSpecialMsg ) { msg+="\r\n" + "- "+pErrorMsg + msgSep + msgWrongChar ; }				pField.focus() ;				return true ;			}		}	}	return false ;}function FieldSmallerThan( pField, pLen, pErrorMsg ) {	passStr = new String( getFieldValue( pField ) ); 	if ( passStr.length < pLen ) {		if ( !isSpecialMsg ) { msg+="\r\n" + "- "+pErrorMsg + msgSep + msgSmaller + pLen + msgSmallerBis ; }		pField.focus();		return true;	}	return false;}function FieldBiggerThan( pField, pLen, pErrorMsg ) {	passStr = new String( getFieldValue( pField ) ); 	if ( passStr.length > pLen ) {		if ( !isSpecialMsg ) { msg+="\r\n" + "- "+pErrorMsg + msgSep + msgBigger + pLen + msgBiggerBis ; }		pField.focus();		return true;	}	return false;}function FieldNotMatch( pField, pFieldBis, pErrorMsg ) {	var TheVal = getFieldValue( pField ) ;	if( isWhitespace( TheVal ) ) {		if ( !isSpecialMsg ) { msg+="\r\n" + "- "+pErrorMsg + msgSep + msgNeedValue ; }		pField.focus() ;		return true;	} else {		var TheValBis = getFieldValue( pFieldBis ) ;		if(  isWhitespace( TheValBis ) ) {			if ( !isSpecialMsg ) { msg+="\r\n" + "- "+pErrorMsg  + msgSep + msgNotMatch ; }			pField.focus() ;			return true;		} else {			if( TheValBis !=  TheVal ) {				if ( !isSpecialMsg ) { msg+="\r\n" + "- "+pErrorMsg  + msgSep + msgNotMatch ; }				pField.focus() ;				return true;			} else {				return false;			}			}	}}function emailCheck( pField, pErrorMsg ) {	var emailStr = getFieldValue( pField ) ;	var emailPat=/^(.+)@(.+)$/;	var specialChars="\\(\\)<>@,;:\\\\\\\"\\.\\[\\]";	var validChars="\[^\\s" + specialChars + "\]";	var quotedUser="(\"[^\"]*\")";	var ipDomainPat=/^\[(\d{1,3})\.(\d{1,3})\.(\d{1,3})\.(\d{1,3})\]$/;	var atom=validChars + '+';	var word="(" + atom + "|" + quotedUser + ")";	var userPat=new RegExp("^" + word + "(\\." + word + ")*$");	var domainPat=new RegExp("^" + atom + "(\\." + atom +")*$");	var matchArray=emailStr.match(emailPat);	if (matchArray==null) {		if ( !isSpecialMsg ) { msg+="\r\n" + "- "+pErrorMsg + msgSep + msgInvalidMail ; }		pField.focus() ;		return true;	}	var user=matchArray[1];	var domain=matchArray[2];	if (user.match(userPat)==null) {		if ( !isSpecialMsg ) { msg+="\r\n" + "- "+pErrorMsg + msgSep + msgInvalidMail ; }		pField.focus() ;		return true;	}	var IPArray=domain.match(ipDomainPat);	if (IPArray!=null) {		for (var i=1;i<=4;i++)  {			if (IPArray[i]>255) {				if ( !isSpecialMsg ) { msg+="\r\n" + "- "+pErrorMsg + msgSep + msgInvalidMail ; }				pField.focus() ;				return true;   			 }   		 }		return true;	}	var domainArray=domain.match(domainPat);	if (domainArray==null) {		if ( !isSpecialMsg ) { msg+="\r\n" + "- "+pErrorMsg + msgSep + msgInvalidMail ; }		pField.focus() ;		return true;	}	var atomPat=new RegExp(atom,"g");	var domArr=domain.match(atomPat);	var len=domArr.length;	if (domArr[domArr.length-1].length<2 || domArr[domArr.length-1].length>4) {		if ( !isSpecialMsg ) { msg+="\r\n" + "- "+pErrorMsg + msgSep + msgInvalidMail ; }		pField.focus() ;		return true;	}	if (len<2) {		if ( !isSpecialMsg ) { msg+="\r\n" + "- "+pErrorMsg + msgSep + msgInvalidMail ; }		pField.focus() ;		return true;	}	return false;}function FieldIsEqualTo( pField, pValue, pErrorMsg ) {	if ( getFieldValue( pField ) == pValue ) {		if ( !isSpecialMsg ) { msg+="\r\n" + "- "+pErrorMsg + msgSep + msgNeedValue ; }		pField.focus() ;		return true;	}	return false;}function FieldIsMember( pFieldMaster, pMasterValue, pFieldChild, pChildValue, pErrorMsg ) {	if ( getFieldValue( pFieldMaster ) == pMasterValue ) {		if( getFieldValue( pFieldChild ) == pChildValue  ) {			if ( !isSpecialMsg ) { msg+="\r\n" + "- "+pErrorMsg + msgSep + msgNeedValue ; }			pFieldChild.focus() ;			return true;		}		return false;	}	return false;}// ----------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------// FORM SPECIFIC VALIDATION// ----------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------function InitVal() {	CurDoc = document.forms[0] ;	msg=msgErrorIntro;}function CheckNav() {	document.cookie =  "check=checkV; path=/";	var strC = document.cookie;	var bPos = strC.indexOf("check=");	var ePos = strC.indexOf (";", bPos);	if (ePos == -1) { ePos = strC.length; }	var strV = strC.substring( bPos, ePos );	if ( unescape(strV) == "check=checkV" ) {		document.cookie =  "check=; expires=Thu, 01-Jan-70 00:00:01 GMT; path=/";		document.forms[0].jsCheck.value = "2";	} else {		document.forms[0].jsCheck.value = "1";	}}function noBackHere() {	var isNoBack = false;	if ( curReferrer==curPage ) { return; } // Reload of itself should be authorized, no matter what...	if ( curReferrer=="ec_register" ) { isNoBack = true; }	if ( curReferrer=="ec_infoinvoice" ) { isNoBack = true; }	if ( curReferrer=="ar_intro" )  { isNoBack = true; }	if ( curReferrer=="ec_creditcard" )  { isNoBack = true; }	if ( curReferrer=="er_displayinvoice" )  { isNoBack = true; }	if ( curReferrer.substring( 0, 25) =="webpagerequest/keysuccess" )  { isNoBack = true; } // Success page from Ec_Register	if( isNoBack ) { window.history.forward(1) ; } //This is to avoid any Back in this situation}var isCountryCA = false;function reloadInvoiceInfoCB( fullData ) {	InitVal() ;	var idx = fullData.indexOf("!!");	var newVal = fullData.substring(0, idx) ;	if ( idx == -1 ) { return; }	if ( getFieldValue( CurDoc.Form ) == "Ec_InfoInvoice" ) { CurDoc.GlobalValue.value = parseInt( newVal ) / 100 ; }	showElt( "divInvoiceReload", false );	var divElt = isW3C ? document.getElementById("divInfoInvoice") : document.all.divInfoInvoice ;	divElt.innerHTML = fullData.substr(idx+2) ;}function reloadInvoiceInfo() {	// Used in Ec_InfoInvoice and Ec_Register (on purchase), when the Province is changed	// This is to recompute the Taxes (TPS & GST when needed)	InitVal() ;	if ( getFieldValue( CurDoc.Form ) == "Ec_Register"  ) {  if ( getFieldValue( CurDoc.Type ) != "B" ) { return true; } ; }	showElt( "divInvoiceReload", true );	var CurC = getFieldValue( CurDoc.Country ) ;	var CurS = ( CurC == "CA" ) ? getFieldValue( CurDoc.StateCA ) : "[none]" ;	var url = strCurProtocol+"//"+strCurServer+strCurDB+"_Ajax_ReloadInfoInvoice?OpenAgent&";	url = url + getFieldValue( CurDoc.InfoInURL ) + "$" + getFieldValue( CurDoc.CouponCode ) +"!"+ CurS +"$"+ CurC;	makeHttpRequest( url, "reloadInvoiceInfoCB", false );}function updateCountryState() {	// must have in the TermHTML document: id="formInputState" style="display: none;"	InitVal() ;	var Origin = getFieldValue( CurDoc.Form ) ;	var CurC = ( Origin == "Ec_CreditCard" ) ? getFieldValue( CurDoc.CC_Country ) : getFieldValue( CurDoc.Country ) ;	if ( CurC == "CA" ) {		isCountryCA = true;		showElt( "formInputState", true );		showElt( "formListStateUS", false );		showElt( "formListStateCA", true );		var curS = ( Origin == "Ec_CreditCard" ) ? CurDoc.CC_StateUS : CurDoc.StateUS ;		curS.value = "[none]";	} else if ( CurC == "US" ) {		showElt( "formInputState", true );		showElt( "formListStateUS", true );		showElt( "formListStateCA", false );		var curS = ( Origin == "Ec_CreditCard" ) ? CurDoc.CC_StateCA : CurDoc.StateCA ;		curS.value = "[none]";		if ( isCountryCA ) { reloadInvoiceInfo(); }		isCountryCA = false;	} else {		showElt( "formInputState", false );		showElt( "formListStateUS", false );		showElt( "formListStateCA", false );		var curS = ( Origin == "Ec_CreditCard" ) ? CurDoc.CC_StateUS : CurDoc.StateUS ;		curS.value = "[none]";		curS = ( Origin == "Ec_CreditCard" ) ? CurDoc.CC_StateCA : CurDoc.StateCA ;		curS.value = "[none]";		if ( isCountryCA ) { reloadInvoiceInfo(); }		isCountryCA = false;	}	return true ;}// SPECIFIC Ec_Loginfunction submitLogin() {	var msgflag = false ;	InitVal() ;	if ( FieldNotValid( CurDoc.UserName, msgLogin, 'Login', true ) ) msgflag = true ;	if ( FieldNotValid( CurDoc.Password, msgPassword, 'Pass', true ) ) { msgflag = true ; } else {		if ( FieldSmallerThan( CurDoc.Password, 6, msgPassword ) ) msgflag = true ; }	if ( msgflag ) {		alert(msg) ;		return false ;	}	var theKey = getFieldValue( CurDoc.UserName ) ;	var expiry = new Date();	expiry.setMonth( expiry.getYear() + 15 ) ;	document.cookie =  "curUser="+ theKey +"; expires=" + expiry.toGMTString() + "; path=/ ";	return true;}// SPECIFIC Ec_Registerfunction goBackRegister() {	InitVal() ;	var curC = getFieldValue( CurDoc.CouponCode );	var curI = getFieldValue( CurDoc.InfoInURL );	var UrlRebuilt = "$Lang="+strCurLan ;	if ( curC != "" ) { UrlRebuilt = "$C=" + curC + UrlRebuilt ; }	UrlRebuilt = "I="+curI+UrlRebuilt ;		top.location.href = strCurProtocol+"//"+strCurServer+strCurDB+"Er_BuyTools?ReadForm&"+UrlRebuilt ;	return true;}function showHideRegister() {	InitVal() ;	if ( getFieldValue( CurDoc.LoginType ) == "2" ) {		curElt = isW3C ? document.getElementById("DivNewUser") : document.all.DivNewUser ;		curElt.style.display = "block" ;		curElt = isW3C ? document.getElementById("DivLogin") : document.all.DivLogin ;		curElt.style.display = "none" ;	} else {		curElt = isW3C ? document.getElementById("DivLogin") : document.all.DivLogin ;		curElt.style.display = "block" ;		curElt = isW3C ? document.getElementById("DivNewUser") : document.all.DivNewUser ;		curElt.style.display = "none" ;	}	return true ;}function submitRegister() {	var msgflag = false ;	InitVal() ;	if ( getFieldValue( CurDoc.LoginType ) == "2" ) {		if ( FieldNotValid( CurDoc.FirstName, msgFirstName, 'Full', true ) )  msgflag = true ;		if ( FieldNotValid( CurDoc.LastName, msgLastName, 'Full', true ) ) msgflag = true ;		if ( FieldNotValid( CurDoc.Title, msgTitle, 'Full', false ) ) msgflag = true ;		if ( FieldNotValid( CurDoc.eMail, msgEmail, '', true ) ) { msgflag = true ; } else {			if ( emailCheck(CurDoc.eMail, msgEmail ) ) msgflag = true ; }		if ( FieldNotValid( CurDoc.Phone, msgPhone, 'Phone', true ) ) msgflag = true ;		if ( FieldNotValid( CurDoc.CompanyName, msgCompName, 'Full', true ) ) msgflag = true ;		if ( FieldIsEqualTo( CurDoc.Country, '[none]', msgCountry ) ) { msgflag = true ; } else {			if ( FieldNotValid( CurDoc.Country, msgCountry, '', true ) )  { msgflag = true ; } else {				if ( FieldIsMember( CurDoc.Country, "CA", CurDoc.StateCA, "[none]", msgProvince ) ) msgflag = true ;				if ( FieldIsMember( CurDoc.Country, "US", CurDoc.StateUS, "[none]", msgState ) ) msgflag = true ;			}		}		if ( FieldNotValid( CurDoc.NewUserName, msgLogin, 'Login', true ) ) { msgflag = true ; } else {			if ( FieldSmallerThan( CurDoc.NewUserName, 6, msgLogin ) ) { msgflag = true ; } else {				if ( FieldBiggerThan( CurDoc.NewUserName, 64, msgLogin ) ) { msgflag = true ; } } }		if ( FieldNotValid( CurDoc.NewPassword, msgPassword, 'Pass', true ) ) { msgflag = true ; } else {			if ( FieldSmallerThan( CurDoc.NewPassword, 6, msgPassword ) ) { msgflag = true ; } else {				if ( FieldBiggerThan( CurDoc.NewPassword, 64, msgPassword ) ) { msgflag = true ; } else {					if ( FieldNotMatch( CurDoc.NewPassword, CurDoc.NewPasswordConfirm, msgPassword ) ) msgflag = true ; } } }	} else {		if ( FieldNotValid( CurDoc.UserName, msgLogin, 'Login', true ) ) msgflag = true ;		if ( FieldNotValid( CurDoc.Password, msgPassword, 'Pass', true ) ) { msgflag = true ; } else {			if ( FieldSmallerThan( CurDoc.Password, 6, msgPassword ) ) msgflag = true ; }	}	if ( msgflag ) {		alert(msg) ;		return false ;	}	var theKey = getFieldValue( CurDoc.UserName ) ;	var expiry = new Date();	expiry.setMonth( expiry.getYear() + 15 ) ;	document.cookie =  "curUser="+ theKey +"; expires=" + expiry.toGMTString() + "; path=/ ";	return true;}// SPECIFIC Ec_InfoInvoicefunction goBackInfoInvoice() {	InitVal() ;	var curC = getFieldValue( CurDoc.CouponCode );	var curI = getFieldValue( CurDoc.InfoInURL );	var UrlRebuilt = "$Lang="+strCurLan ;	if ( curC != "" ) { UrlRebuilt = "$C=" + curC + UrlRebuilt ; }	var bckStatus = getFieldValue( CurDoc.BackStatus );	if ( bckStatus == "P" ) { UrlRebuilt = "$B=X" + UrlRebuilt ; }	UrlRebuilt = "I="+curI+UrlRebuilt ;		top.location.href = strCurProtocol+"//"+strCurServer+strCurDB+"Er_BuyTools?ReadForm&"+UrlRebuilt ;	return true;}function submitInfoInvoice() {	var msgflag = false ;	InitVal() ;	if ( getFieldValue( CurDoc.GlobalValue ) == "-1" ) return false;	if ( FieldNotValid( CurDoc.FirstName, msgFirstName, 'Full', true ) )  msgflag = true ;	if ( FieldNotValid( CurDoc.LastName, msgLastName, 'Full', true ) ) msgflag = true ;	if ( FieldNotValid( CurDoc.CompanyName, msgCompName, 'Full', true ) ) msgflag = true ;	if ( FieldNotValid( CurDoc.Address1, msgStreet1, 'Full', true ) ) msgflag = true ;	if ( FieldNotValid( CurDoc.Address2, msgStreet2, 'Full', false ) ) msgflag = true ;	if ( FieldNotValid( CurDoc.ZipCode, msgZip, 'Full', true ) ) msgflag = true ;	if ( FieldNotValid( CurDoc.City, msgCity, 'Full', true ) ) msgflag = true ;	if ( FieldIsEqualTo( CurDoc.Country, '[none]', msgCountry ) ) { msgflag = true ; } else {		if ( FieldNotValid( CurDoc.Country, msgCountry, '', true ) )  { msgflag = true ; } else {			if ( FieldIsMember( CurDoc.Country, "CA", CurDoc.StateCA, "[none]", msgProvince ) ) msgflag = true ;			if ( FieldIsMember( CurDoc.Country, "US", CurDoc.StateUS, "[none]", msgState ) ) msgflag = true ;		}	}	if ( FieldNotValid( CurDoc.eMail, msgEmail, '', true ) ) { msgflag = true ; } else {		if ( emailCheck(CurDoc.eMail, msgEmail ) ) msgflag = true ; }	if ( msgflag ) {		alert(msg) ;		return false ;	}	return true;}// SPECIFIC Ec_NewPassWordfunction submitUserName() {	var msgflag = false ;	InitVal() ;	if ( FieldNotValid( CurDoc.UserName, msgLogin, 'Login', true ) ) msgflag = true;	if ( msgflag ) {		alert(msg) ;		return false ;	}	return true;}// SPECIFIC Ec_SendUserNamefunction submitEmail() {	var msgflag = false ;	InitVal() ;	if ( FieldNotValid( CurDoc.eMail, msgEmail, '', true ) ) { msgflag = true ; } else {		if ( emailCheck(CurDoc.eMail, msgEmail ) ) msgflag = true ; }	if ( msgflag ) {		alert(msg) ;		return false ;	}	return true;}// SPECIFIC Ec_Contactfunction submitContact() {	var msgflag = false;	InitVal();	if ( FieldNotValid( CurDoc.eMail, msgEmail, '', true ) ) { msgflag = true ; } else {		if ( emailCheck(CurDoc.eMail, msgEmail ) ) msgflag = true ; }	if ( FieldNotValid( CurDoc.Comments, msgComment, '', true ) ) { msgflag = true ; }	if ( msgflag ) {		msg+="\r\n\r\n" +msgContactEnd ;		if ( confirm(msg) ) { return true ; } else { return false ; }	}	return true ;}// SPECIFIC Ec_Supportfunction submitSupport() {	var msgflag = false;	InitVal();	if ( FieldNotValid( CurDoc.Ec_Email, msgEmail, '', true ) ) { msgflag = true ; } else {		if ( emailCheck(CurDoc.Ec_Email, msgEmail ) ) msgflag = true ; }	if ( FieldNotValid( CurDoc.Ec_Report, msgComment, '', true ) ) { msgflag = true ; }	if ( msgflag ) {		msg+="\r\n\r\n" +msgContactEnd ;		if ( confirm(msg) ) { return true ; } else { return false ; }	}	return true ;}// SPECIFIC Ec_CrediCardfunction goBackCreditCard() {	InitVal() ;	if ( getFieldValue( CurDoc.InvoiceUNID ) != "" ) { history.back() ; return true ; }	var curC = getFieldValue( CurDoc.CouponCode );	var UrlRebuilt = "$Lang="+strCurLan ;	UrlRebuilt = "$M1=" + escape( getFieldValue( CurDoc.UserEmail ) ) + UrlRebuilt ;	UrlRebuilt = "$K0=" + escape( getFieldValue( CurDoc.InvoiceComment ) ) + UrlRebuilt ;	UrlRebuilt = "$R0=" + escape( getFieldValue( CurDoc.InvoiceRef ) ) + UrlRebuilt ;	UrlRebuilt = "$M0=" + escape( getFieldValue( CurDoc.eMail ) ) + UrlRebuilt ;	UrlRebuilt = "$Y0=" + getFieldValue( CurDoc.Country ) + UrlRebuilt ;	UrlRebuilt = "$S0=" + getFieldValue( CurDoc.State ) + UrlRebuilt ;	UrlRebuilt = "$C0=" + escape( getFieldValue( CurDoc.City ) ) + UrlRebuilt ;	UrlRebuilt = "$Z0=" + escape( getFieldValue( CurDoc.ZipCode ) ) + UrlRebuilt ;	UrlRebuilt = "$A2=" + escape( getFieldValue( CurDoc.Address2 ) ) + UrlRebuilt ;	UrlRebuilt = "$A1=" + escape( getFieldValue( CurDoc.Address1 ) ) + UrlRebuilt ;	UrlRebuilt = "$N0=" + escape( getFieldValue( CurDoc.CompanyName ) ) + UrlRebuilt ;	UrlRebuilt = "$L0=" + escape( getFieldValue( CurDoc.LastName ) ) + UrlRebuilt ;	UrlRebuilt = "$F0=" + escape( getFieldValue( CurDoc.FirstName ) ) + UrlRebuilt ;	UrlRebuilt = "$G0=" + getFieldValue( CurDoc.Gender ) + UrlRebuilt ;	var bckStatus = getFieldValue( CurDoc.BackStatus );	if ( bckStatus == "P" ) { UrlRebuilt = "$B=X" + UrlRebuilt ; }	if ( curC != "" ) { UrlRebuilt = "$C=" + curC + UrlRebuilt ; }	UrlRebuilt = "I="+getFieldValue( CurDoc.InfoInURL ) + "$R=X" + UrlRebuilt ;	top.location.href = strCurProtocol+"//"+strCurServer+strCurDB+"Ec_InfoInvoice?OpenForm&"+UrlRebuilt ;	return true ;}function showHideCreditCardWarning() {	InitVal() ;	if ( getFieldValue( CurDoc.cardType ) != "AM" ) {		curElt = isW3C ? document.getElementById("DivWarning") : document.all.DivWarning ;		curElt.style.display = "none" ;	} else {		curElt = isW3C ? document.getElementById("DivWarning") : document.all.DivWarning ;		curElt.style.display = "block" ;	}	return true ;}function submitCreditCard() {	var msgflag = false ;	InitVal() ;	if ( FieldNotValid( CurDoc.cardNumber, msgCardNumber, 'Card', true ) )  { msgflag = true ; } else {		var cardNumber = stripWhitespace( getFieldValue( CurDoc.cardNumber ) );		if ( ( getFieldValue( CurDoc.cardType ) == "VI" && isVisa(cardNumber) ) ||		( getFieldValue( CurDoc.cardType ) == "MC" && isMasterCard(cardNumber) ) ||		( getFieldValue( CurDoc.cardType ) == "AM" && isAmericanExpress(cardNumber) ) ||		( getFieldValue( CurDoc.cardType ) == "DC" && isDinersClub(cardNumber) ) ||		( getFieldValue( CurDoc.cardType ) == "DI" && isDiscover(cardNumber) ) ) {			var today = new Date();			var expiry = new Date();			expiry.setYear( parseInt( "20"+getFieldValue( CurDoc.year ) ) ) ;			expiry.setMonth( parseInt( getFieldValue( CurDoc.month ) ) + 1 ) ;			expiry.setDate( 1 ) ;			expiry.setDate( expiry.getDate() - 1 ) ;			if ( today.getTime() > expiry.getTime() ) {				msg+="\r\n" + "- "+ msgCardNumber + msgSep + msgDateValid ;				CurDoc.year.focus();				msgflag = true ;			}		} else {			msg+="\r\n" + "- "+ msgCardNumber + msgSep + msgCardValid ;			CurDoc.cardNumber.focus() ;			msgflag = true ;		}	}	if ( FieldNotValid( CurDoc.CVD, msgCVD, 'Card', true ) )  msgflag = true ;	if ( FieldNotValid( CurDoc.CC_Name, msgName, 'Full', true ) )  msgflag = true ;	if ( FieldNotValid( CurDoc.CC_Address1, msgStreet1, 'Full', true ) ) msgflag = true ;	if ( FieldNotValid( CurDoc.CC_Address2, msgStreet2, 'Full', false ) ) msgflag = true ;	if ( FieldNotValid( CurDoc.CC_ZipCode, msgZip, 'Full', true ) ) msgflag = true ;	if ( FieldNotValid( CurDoc.CC_City, msgCity, 'Full', true ) ) msgflag = true ;	if ( FieldIsEqualTo( CurDoc.CC_Country, '[none]', msgCountry ) ) { msgflag = true ; } else {		if ( FieldNotValid( CurDoc.CC_Country, msgCountry, '', true ) )  { msgflag = true ; } else {			if ( FieldIsMember( CurDoc.CC_Country, "CA", CurDoc.CC_StateCA, "[none]", msgProvince ) ) msgflag = true ;			if ( FieldIsMember( CurDoc.CC_Country, "US", CurDoc.CC_StateUS, "[none]", msgState ) ) msgflag = true ;		}	}	if ( FieldNotValid( CurDoc.CC_Phone, msgPhone, 'Phone', true ) ) msgflag = true ;	if ( FieldNotValid( CurDoc.CC_Email, msgEmail, '', true ) ) { msgflag = true ; } else {		if ( emailCheck(CurDoc.CC_Email, msgEmail ) ) msgflag = true ; }	if ( msgflag ) {		alert(msg) ;		return false ;	}	curElt = isW3C ? document.getElementById("DivAllData") : document.all.DivAllData ;	curElt.style.display = "none" ;	curElt = isW3C ? document.getElementById("DivWait") : document.all.DivWait ;	curElt.style.display = "block" ;	return true;}// SPECIFIC FOR Ec_BuyTools// This is called just after the table has been built.function initTableBuyTools() {	$(document).ready(function() {		$('ul#ShopOption li').click(function(){			var curSel = $(this).attr('id');			if (curSel=="C") {curSel = curSel+$('input[name=maintenance]:checked').val();} 			if (curSel=="M") {$('input[name=YDS]').val(0).attr('disabled','disabled');} else {$('input[name=YDS]').removeAttr('disabled');}			loadTableDataBuyTools(curSel);			computeBuyTools();			$('ul#ShopOption li').removeClass('Active');			$(this).addClass('Active');		});		$(document).keydown( function(e){			if(checkEnterKeyPress(e)) {submitBuyTools();}		});		var initCode = initValueBuyTools();		loadTableDataBuyTools(initCode);		computeBuyTools();		if (initCode!="C2") {			$('ul#ShopOption li').removeClass('Active');			$('li#'+initCode.charAt(0)).addClass('Active');			if (initCode.charAt(0)=="C") {				$('input[name=maintenance][value='+initCode.charAt(1)+']').attr('checked',true); 			}		}	});}function loadTableDataBuyTools(initCode) {	$('tr.InvoiceListSubHeader').each( function() {		var nbLine = 0;		var curID = $(this).attr('id');		$('tr.'+curID).each( function(){			var sName = $(this).attr('id');			if (allPrice[sName][initCode]) {				$('input[name=Pri_'+sName+']').val(allPrice[sName][initCode].price);				$('input[name=Cod_'+sName+']').val(allPrice[sName][initCode].code);				$('#Desc_'+sName).html(allPrice[sName][initCode].desc);				thePrice = allPrice[sName][initCode].price;				if (thePrice-Math.floor(thePrice)!=0) {thePrice=thePrice.toFixed(2);}				$('#Price_'+sName).html(thePrice);				$('#'+sName).show();				nbLine++;			} else {				$('#'+sName).hide();				$('input[name=Pri_'+sName+']').val('0');				$('input[name=Cod_'+sName+']').val('');			}		});		if (nbLine == 0) {			$(this).hide();		} else {			$(this).show();		}	});}function initValueBuyTools() {	InitVal();	var strName = new String;	var retType = 'C1'; // Default when nothing is provided	var preSel = getFieldValue( CurDoc.PreSelect ) ;	var preSelRent = getFieldValue( CurDoc.PreSelectRent ) ;	var info = new String( getFieldValue( CurDoc.InfoInURL ) ) ;	if ( info == "" && preSel == "" && preSelRent == "" ) { return (retType);  }	if ( preSel != "" ) {		$('input[name=Qty_'+preSel.toUpperCase()+']').val(1);		retType = 'C2';	} else if ( preSelRent != "" ) {		$('input[name=Qty_'+preSelRent.toUpperCase()+']').val(1);		retType = 'R';	} else if ( info != "" ) {		var codeToProd = new Array() ;		for (var iProd in allPrice) {    		for (var iCode in allPrice[iProd]) {        		codeToProd[allPrice[iProd][iCode].code] = [iProd, iCode];    		}		}			var sPos = 0 ;		var nPos = 0 ;		var vPos = 0 ;		while ( sPos < info.length ) {			nPos = info.indexOf("@", sPos ) ;			if ( nPos != -1 ) {				strName = info.substring( sPos, nPos ) ;				sPos = nPos+1 ;			} else {				strName = info.substr( sPos, info.length - sPos ) ;				sPos = info.length ;			}			vPos = strName.indexOf("_") ;			if ( vPos != -1 ) {				sName = strName.substr( 0, vPos ) ;				sQty = strName.substr( vPos+1 ) ;			} else {				sName = strName ;				sQty = "0" ;			}			if ( sName.substr( 0, 2 )=="YD" ) {				$('input[name=YDS]').val(sQty);			} else {				if ( codeToProd[sName] ) {					// last one win (in case of mix selection)....					$('input[name=Qty_'+codeToProd[sName][0]+']').val(sQty);					retType = codeToProd[sName][1];				}			}		}	}	return(retType) ;}var sumBuyTools = 0;var sumRebateBuyTools = 0;function getTotalBuyTools() {	var sPos = 0 ;	sumBuyTools = 0;	sumRebateBuyTools = 0;	var strName = new String;	var aName = new Array() ;	var aQty = new Array() ;	var aSub = new Array() ;	var aPrice = new Array() ;	var sName = new String ;			for ( i=0; i < ( CurDoc.elements.length ); i++ ) {		strName = CurDoc.elements[i].name;		sPos = strName.indexOf("_", 0) ;		if ( sPos == 3 ) {			sName = strName.substr( 4, strName.length - 6 ) ;			if ( strName.substring( 0, 4 ) == "Qty_" ) {				aName[sName] = sName ;				aQty[sName] = CurDoc.elements[i] ;			} else if ( strName.substring( 0, 4 ) == "Sub_" ) {				aName[sName] = sName ;				aSub[sName] = CurDoc.elements[i] ;			} else if ( strName.substring( 0, 4 ) == "Pri_" ) {				aName[sName] = sName ;				aPrice[sName] = parseFloat( stripCharsInBag( CurDoc.elements[i].value, " ," ) ) ;			}		}	}	var Rebate = parseFloat( getFieldValue( CurDoc.Coupon_Rebate ) );	var aVal = 0;	var strVal = "";	for ( theName in aName ) {		aVal = Math.round( parseInt( aQty[theName].value ) * aPrice[theName] * 100 ) ;		strVal = aVal.toString() ;		if ( strVal == "0" ) { strVal = "0.00" ; } else { strVal = strVal.substr( 0, strVal.length - 2 ) + "." + strVal.substr( strVal.length - 2 , 2 ); }		aSub[theName].value = strVal ;		sumBuyTools = sumBuyTools + aVal;	}	var fullRebate = sumBuyTools * ( 100 - Rebate ) ;	sumRebateBuyTools = parseInt( fullRebate / 100 ) ;	if ( ( fullRebate - sumRebateBuyTools ) * 10 >= 5 ) { sumRebateBuyTools = sumRebateBuyTools + 1 ; } ;}function computeBuyTools() {	InitVal() ;	var sum = 0;	var sumRebate = 0;	getTotalBuyTools();	sum = parseInt( sumBuyTools ) ;	var strSum = sum.toString() ;	if ( strSum == "0" ) { strSum = "0.00"; } else { strSum = strSum.substr( 0, strSum.length - 2 ) + "." + strSum.substr( strSum.length - 2 , 2 ); }	CurDoc.SubTotal.value = strSum ;	sumRebate = sumRebateBuyTools;	sum = sum - sumRebate ;		var availYD = parseInt( getFieldValue( CurDoc.YDA ) );	if ( availYD > 0 ) {		var rateYD = parseInt( getFieldValue( CurDoc.YDR ) );		var qttyYD = parseInt( getFieldValue( CurDoc.YDS ) ) * 100 ;		var valuYD = 0;		var sumYD = sum; // fix + 1		if ( (sumYD % 100) > 0 ) { sumYD = sumYD - ( sumYD % 100 ) + 100; }		sumYD = parseInt( ( sumYD / rateYD ) * 100 );  // fix + 1 again		if ( (sumYD % 100) > 0 ) { sumYD = sumYD - ( sumYD % 100 ) + 100; }		if ( qttyYD > availYD ) { qttyYD = availYD; }		if ( qttyYD > sumYD ) { qttyYD = sumYD; }		valuYD = 	parseInt( ( qttyYD * rateYD ) / 100 ) ; // fix		if ( (valuYD % 100) > 0 ) { valuYD = valuYD - ( valuYD % 100 ); }		valuYD = 	- valuYD;		var strValuYD = valuYD.toString() ;		if ( strValuYD == "0" ) { CurDoc.YDV.value = "0.00" ; } else { CurDoc.YDV.value = strValuYD.substr( 0, strValuYD.length - 2 ) + "." + strValuYD.substr( strValuYD.length - 2 , 2 ); }		if ( qttyYD != parseInt( getFieldValue( CurDoc.YDS ) * 100 ) ) {			var strQttyYD = qttyYD.toString() ;			if ( strQttyYD == "0" ) { CurDoc.YDS.value = "0" ; } else { CurDoc.YDS.value = strQttyYD.substr( 0, strQttyYD.length - 2 ); }		}		sum = sum + valuYD;		if ( sum < 0 ) { sum = 0; }	}	var strSum = sum.toString() ;	if ( strSum == "0" ) { strSum = "0.00" ; } else { strSum = strSum.substr( 0, strSum.length - 2 ) + "." + strSum.substr( strSum.length - 2 , 2 ); }	var strRebate = sumRebate.toString() ;	if ( strRebate == "0" ) { strRebate = "0.00" ; } else { strRebate = strRebate.substr( 0, strRebate.length - 2 ) + "." + strRebate.substr( strRebate.length - 2 , 2 ); }	if ( CurDoc.Coupon_Rebate.value != "100" ) { CurDoc.TotalRebate.value = "-"+strRebate ; }	CurDoc.Total.value = strSum ;}function submitBuyTools(vType) {	InitVal() ;	var strQuery = new String;	var strName = new String;	var sValue = 0 ;	var curC = getFieldValue( CurDoc.Coupon_Code );	var curX = getFieldValue( CurDoc.PriceSelect );	var UrlRebuilt = "$Lang="+strCurLan ;	if ( curC != "" ) { UrlRebuilt = "$C=" + curC + UrlRebuilt ; }	computeBuyTools() ;	strQuery ="I=";	$('input[name^="Qty_"]').each( function() {		sValue = parseInt( $(this).val() );		if (sValue != 0 ) {			strName = $(this).attr('name');			strName = strName.substr( 4, strName.length - 4 );			strQuery = strQuery + $('input[name=Cod_'+strName+']').val() + "_" + sValue + "@";		}	});		var qttyYD = parseInt( getFieldValue( CurDoc.YDS ) );	if ( qttyYD != 0 ) {		strQuery = strQuery + getFieldValue( CurDoc.YDC )+"_" + getFieldValue( CurDoc.YDS ) +"@";	}	if ( strQuery == "I=" ) { strQuery =""; };	strQuery = strQuery.substr( 0, strQuery.length-1 ) ; // Get rid of the last @	if ( vType== "Reload" || vType=="Login" ) {		if ( curX != "" ) { UrlRebuilt = "$X=" + curX + UrlRebuilt ; }		if ( vType=="Login" ) { UrlRebuilt = "$Login" + UrlRebuilt ; }		top.location.href = strCurProtocol+"//"+strCurServer+strCurDB+"Er_BuyTools?ReadForm&"+strQuery+UrlRebuilt ;		return true;	}		if ( ( getFieldValue( CurDoc.Total ) == 0 ) && ( getFieldValue( CurDoc.YDV ) == 0 ) ) {		alert( msgNumber );		return false;	} else {		top.location.href = "https://"+strCurServer+strCurDB+"Ec_Register?OpenForm&T=B$"+strQuery+UrlRebuilt ;		return true;	}}function calcBuyTools( field ) {	var valid = '0123456789';	var QT= field.value ;	if ( QT == "" ) {		field.value = "0" ;	} else if ( isNaN(QT) ) {		field.value = "0" ;	} else {		for ( var i=0; i < QT.length; i++ ) {			if ( valid.indexOf( QT.charAt(i)) == -1) {				alert( msgNumber );				field.value = "0" ;			} else {				field.value = parseInt( field.value ) ;			}		}	}	computeBuyTools() ;}function setMaxYDBuyTools() {	InitVal() ;	var curSum = 0;	getTotalBuyTools();	curSum = sumBuyTools - sumRebateBuyTools ; // x 100 and fix + 1	if ( (curSum % 100) > 0 ) { curSum = curSum - ( curSum % 100 ) + 100; }	var availYD = parseInt( getFieldValue( CurDoc.YDA ) ); // x 100	if ( availYD == 0 ) { return; }	var rateYD = parseInt( getFieldValue( CurDoc.YDR ) );	availYD = parseInt( availYD * rateYD / 100 );	 // x100 and fix	if ( (availYD % 100) > 0 ) { availYD = availYD - ( availYD % 100 ); }	var sumYD = parseInt( ( curSum / rateYD ) * 100 ); // x100 and fix + 1	if ( (sumYD % 100) > 0 ) { sumYD = sumYD - ( sumYD % 100 ) + 100; }	var qttyYD = 0;	if ( curSum > availYD ) { qttyYD = parseInt( getFieldValue( CurDoc.YDA ) ); } else { qttyYD = parseInt( sumYD ); }	var strQttyYD = qttyYD.toString() ;	if ( strQttyYD == "0" ) { CurDoc.YDS.value = "0" ; } else { CurDoc.YDS.value = strQttyYD.substr( 0, strQttyYD.length - 2 ); }	computeBuyTools() ;}// SPECIFIC for Pollfunction submitPollData() {	var msgflag = false ;	isSpecialMsg = true ;	InitVal() ;	msg = getFieldValue( CurDoc.ErrorMsgIntro ) ;	var aQuestion = new Array(9) ;	var aErrorMsg = new Array(9) ;	var aType = new Array(9) ;	var aEnable = new Array(9) ;	for (i=0; i < ( CurDoc.elements.length ); i++ ) {		var strName = CurDoc.elements[i].name ;		if ( strName.indexOf("Type_")!=-1 ) {			var idx = strName.substring( strName.indexOf("_")+1, strName.length ) ;			aType[parseInt(idx)-1] = getFieldValue( CurDoc.elements[i] ) ;		}		else if ( strName.indexOf("Enabled_")!=-1 ) {			var idx = strName.substring( strName.indexOf("_")+1, strName.length ) ;			aEnable[parseInt(idx)-1] = getFieldValue( CurDoc.elements[i] ) ;		}		else if ( strName.indexOf("ErrorMsg")!=-1 && strName.indexOf("ErrorMsgIntro")==-1 ) {			var idx = strName.substring( strName.indexOf("g")+1, strName.length ) ;			aErrorMsg[parseInt(idx)-1] = getFieldValue( CurDoc.elements[i] ) ;		}	}	for (i=0; i < ( CurDoc.elements.length ); i++ ) {		var strName = CurDoc.elements[i].name ;		if ( strName.indexOf("Question")!=-1 ) {			var idx = strName.substring( strName.indexOf("n")+1, strName.indexOf("_") ) ;			if ( strName.indexOf( "_"+aType[parseInt(idx)-1] )!=-1 ) {				doIt = false ;				switch( CurDoc.elements[i].type ) {				case "radio" :				case "checkbox" :					doIt =  ( CurDoc.elements[i].checked ) ? true : false ;					break ;				default :					doIt = true ; 					break ;				}				if ( doIt ) { aQuestion[parseInt(idx)-1] = CurDoc.elements[i] ; }				if ( typeof aQuestion[parseInt(idx)-1] == 'undefined' ) { aQuestion[parseInt(idx)-1] = CurDoc.elements[i] ; }			}		}	}	for (i=0; i < 10; i++ ) {		var strName = aQuestion[i].name ;		if ( !isWhitespace( aErrorMsg[i] ) && !isWhitespace( aEnable[i] ) ) {			if ( FieldNotValid( aQuestion[i], '', '', true ) ) {				msg+="\r\n" + "- "+aErrorMsg[i] ;				msgflag = true ;			}		}	}	if ( msgflag ) {		alert(msg) ;		return false ;	} else {		var expiry = new Date();		expiry.setMonth( expiry.getMonth() + 12 ) ;		var theKey = getFieldValue( CurDoc.UniqueKey ) ;		theKey = ( theKey != "" ) ? theKey : "anonymous" ;		document.cookie =  getFieldValue( CurDoc.Reference ) + "="+ theKey +"; expires=" + expiry.toGMTString() + "; path=/ ";		return true;	}}// SPECIFIC Ac_Referralfunction setValueReferral() {	InitVal();	var lPer = parseInt( CurDoc.MinPer.value );	var mPer = parseInt( CurDoc.MaxPer.value );	var cPer = parseInt( CurDoc.RCustPer.value );	if ( (mPer - cPer) < lPer ) {		cPer = mPer - lPer;	} else if ( cPer > mPer ) { 		cPer = mPer;	}	CurDoc.RCustPer.value = cPer;	CurDoc.RPartPer.value = mPer - cPer;	CurDoc.RTotalPer.value = mPer;}function submitReferral() {	InitVal();	var msgflag = false ;	var isNew = getFieldValue( CurDoc.isNew ) ;	if ( isNew == "1" ) {		setValueReferral();		if ( FieldNotValid( CurDoc.RCode, msgCCode, 'Coupon', true ) ) { msgflag = true ; } else {			if ( FieldSmallerThan( CurDoc.RCode, 10, msgCCode ) ) msgflag=true ; }		if ( msgflag ) {			alert(msg) ;			return false ;		}	}	return true ;}function initValueReferral() {	// disable some fields - Won't be saved anyway...	InitVal();	var isNew = getFieldValue( CurDoc.isNew ) ;	if ( isNew != "1" ) {		CurDoc.RCode.readOnly = true;		CurDoc.RCustPer.readOnly = true;	}	CurDoc.RPartPer.readOnly = true;	CurDoc.RTotalPer.readOnly = true;}// -->
