function MM_reloadPage(init) {  //reloads the window if Nav4 resized
  if (init==true) with (navigator) {if ((appName=="Netscape")&&(parseInt(appVersion)==4)) {
    document.MM_pgW=innerWidth; document.MM_pgH=innerHeight; onresize=MM_reloadPage; }}
  else if (innerWidth!=document.MM_pgW || innerHeight!=document.MM_pgH) location.reload();
}
MM_reloadPage(true);

function MM_validateForm() { //v4.0
  var i,p,q,nm,test,num,min,max,errors='',args=MM_validateForm.arguments;
  for (i=0; i<(args.length-2); i+=3) { test=args[i+2]; val=MM_findObj(args[i]);
    if (val) { nm=val.name; if ((val=val.value)!="") {
      if (test.indexOf('isEmail')!=-1) { p=val.indexOf('@');
        if (p<1 || p==(val.length-1)) errors+='- '+nm+' doit contenir une adressee-mail.\n';
      } else if (test!='R') {
        if (isNaN(val)) errors+='- '+nm+' must contain a number.\n';
        if (test.indexOf('inRange') != -1) { p=test.indexOf(':');
          min=test.substring(8,p); max=test.substring(p+1);
          if (val<min || max<val) errors+='- '+nm+' must contain a number between '+min+' and '+max+'.\n';
    } } } else if (test.charAt(0) == 'R') errors += '- '+nm+' est obligatoire.\n'; }
  } if (errors) alert('Erreure:\n'+errors);
  document.MM_returnValue = (errors == '');
}

function MM_openBrWindow(theURL,winName,features) { //v2.0
  window.open(theURL,winName,features);
}


function MM_goToURL() { //v3.0
  var i, args=MM_goToURL.arguments; document.MM_returnValue = false;
  for (i=0; i<(args.length-1); i+=2) eval(args[i]+".location='"+args[i+1]+"'");
}
function MM_preloadImages() { //v3.0
  var d=document; if(d.images){ if(!d.MM_p) d.MM_p=new Array();
    var i,j=d.MM_p.length,a=MM_preloadImages.arguments; for(i=0; i<a.length; i++)
    if (a[i].indexOf("#")!=0){ d.MM_p[j]=new Image; d.MM_p[j++].src=a[i];}}
}

function MM_swapImgRestore() { //v3.0
  var i,x,a=document.MM_sr; for(i=0;a&&i<a.length&&(x=a[i])&&x.oSrc;i++) x.src=x.oSrc;
}

function MM_findObj(n, d) { //v4.01
  var p,i,x;  if(!d) d=document; if((p=n.indexOf("?"))>0&&parent.frames.length) {
    d=parent.frames[n.substring(p+1)].document; n=n.substring(0,p);}
  if(!(x=d[n])&&d.all) x=d.all[n]; for (i=0;!x&&i<d.forms.length;i++) x=d.forms[i][n];
  for(i=0;!x&&d.layers&&i<d.layers.length;i++) x=MM_findObj(n,d.layers[i].document);
  if(!x && d.getElementById) x=d.getElementById(n); return x;
}

function MM_swapImage() { //v3.0
  var i,j=0,x,a=MM_swapImage.arguments; document.MM_sr=new Array; for(i=0;i<(a.length-2);i+=3)
   if ((x=MM_findObj(a[i]))!=null){document.MM_sr[j++]=x; if(!x.oSrc) x.oSrc=x.src; x.src=a[i+2];}
}

function MM_showHideLayers() { //v3.0
  var i,p,v,obj,args=MM_showHideLayers.arguments;
  for (i=0; i<(args.length-2); i+=3) if ((obj=MM_findObj(args[i]))!=null) { v=args[i+2];
    if (obj.style) { obj=obj.style; v=(v=='show')?'visible':(v='hide')?'hidden':v; }
    obj.visibility=v; }
}


// project: client form validator
// version: 0.1

function Rule(poTarget, psRule, psConditions, psMessage) {
	this.oTarget = poTarget;
	this.sRule = psRule;
	this.sConditions = psConditions;
	this.sMessage = psMessage;
	this.checkRule = Rule_checkRule;
	this.checkRuleNOTNULL = Rule_checkRuleNOTNULL;
	this.checkRuleDIGITS = Rule_checkRuleDIGITS;
	this.checkRuleNUMERIC = Rule_checkRuleNUMERIC;
	this.checkRuleALPHA = Rule_checkRuleALPHA;
	this.checkRuleEMAIL = Rule_checkRuleEMAIL;
	this.checkRuleEQ = Rule_checkRuleEQ;
	this.checkRuleGT = Rule_checkRuleGT;
	this.checkRuleGTE = Rule_checkRuleGTE;
	this.checkRuleLT = Rule_checkRuleLT;
	this.checkRuleLTE = Rule_checkRuleLTE;
	this.checkRuleBETWEEN = Rule_checkRuleBETWEEN;
	this.checkRuleMINCHAR = Rule_checkRuleMINCHAR;
	this.checkRuleMAXCHAR = Rule_checkRuleMAXCHAR;
	this.checkRuleLIST = Rule_checkRuleLIST;
	this.checkRuleREGEXP = Rule_checkRuleREGEXP;
	this.checkRuleSELECTED = Rule_checkRuleSELECTED;
	this.checkRuleJS = Rule_checkRuleJS;
	this.getValue = Rule_getValue;
}

function Rule_getValue() {
	if( this.oTarget.type == "text" || this.oTarget.type == "textarea" || this.oTarget.type == "password" || this.oTarget.type == "hidden") {
		return this.oTarget.value;
	}
	if( this.oTarget.type == "select-one") {
		if(this.oTarget.options[this.oTarget.selectedIndex].value == "")
			return this.oTarget.options[this.oTarget.selectedIndex].text;
		else
			return this.oTarget.options[this.oTarget.selectedIndex].value;
	}
	if( this.oTarget.type == "select-multiple") {
		if(this.oTarget.length == 0)
			return "";
		else {
			if(this.oTarget.options[0].value == "")
				return this.oTarget.options[0].text;
			else
				return this.oTarget.options[0].value;
		}
	}
}

function Rule_checkRule(psColor) {
	if( !eval("this.checkRule" + this.sRule + "()") ) {
		if(this.oTarget != null) { 
			this.sOldBgColor = this.oTarget.style.backgroundColor;
			this.oTarget.style.backgroundColor = psColor;
		}
		return this.sMessage + "\n";
	} else {
		if(this.oTarget != null) { 
			this.oTarget.style.backgroundColor = "";
		}
		return "";
	}
}

function Rule_checkRuleNOTNULL() {
	var sValue = this.getValue();
	return (sValue.replace(/(\s)*/g, "") != "");
}

function Rule_checkRuleDIGITS() {
	var sValue = this.getValue();
	return (sValue.replace(/([0-9])*/g, "") == "");
}

function Rule_checkRuleNUMERIC() {
	var sValue = this.getValue();
	return (sValue.replace(/([0-9.])*/g, "") == "");
}

function Rule_checkRuleALPHA() {
	var sValue = this.getValue();
	return (sValue.replace(/([a-zA-Z])*/g, "") == "");
}

function Rule_checkRuleEMAIL() {
	var sValue = this.getValue();
	return (sValue.search(/^[a-zA-Z0-9]([a-zA-Z0-9\+\._-])*(@){1}([a-zA-Z0-9_-])+(\.){1}([a-zA-Z0-9\._-])+$/) != -1);
}

function Rule_checkRuleEQ() {
	var sValue = this.getValue();
	if( this.sConditions.substring(0, 2) == 'O:' ) {
		return ( sValue == eval(this.sConditions.substring(2)).value );
	} else {
		return ( sValue == this.sConditions );
	}
}

function Rule_checkRuleGT() {
	var sValue = this.getValue();
	if( this.sConditions.substring(0, 2) == 'O:' ) {
		return ( parseInt(sValue) > parseInt( eval(this.sConditions.substring(2)).value ) );
	} else {
		return (parseInt(sValue) > parseInt(this.sConditions));
	}
}

function Rule_checkRuleGTE() {
	var sValue = this.getValue();
	if( this.sConditions.substring(0, 2) == 'O:' ) {
		return ( parseInt(sValue) >= parseInt( eval(this.sConditions.substring(2)).value ) );
	} else {
		return (parseInt(sValue) >= parseInt(this.sConditions));
	}
}

function Rule_checkRuleLT() {
	var sValue = this.getValue();
	if( this.sConditions.substring(0, 2) == 'O:' ) {
		return ( parseInt(sValue) < parseInt( eval(this.sConditions.substring(2)).value ) );
	} else {
		return (parseInt(sValue) < parseInt(this.sConditions));
	}
}

function Rule_checkRuleLTE() {
	var sValue = this.getValue();
	if( this.sConditions.substring(0, 2) == 'O:' ) {
		return ( parseInt(sValue) <= parseInt( eval(this.sConditions.substring(2)).value ) );
	} else {
		return (parseInt(sValue) <= parseInt(this.sConditions));
	}
}

function Rule_checkRuleBETWEEN() {
	var iMin, iMax, aTemp;
	var sValue = this.getValue();
	aTemp = this.sConditions.split(",");
	if( aTemp.length == 2) {
		if( aTemp[0].substring(0, 2) == 'O:' )
			iMin = parseInt( eval(aTemp[0].substring(2)).value );
		else
			iMin = parseInt(aTemp[0]);
		if( aTemp[1].substring(0, 2) == 'O:' )
			iMax = parseInt( eval(aTemp[1].substring(2)).value );
		else
			iMax = parseInt(aTemp[1]);
		return (parseInt(sValue) >= iMin && parseInt(sValue) <= iMax );
	} else
		return false;
}

function Rule_checkRuleMINCHAR() {
	var sValue = this.getValue();
	return ( sValue.length >= parseInt(this.sConditions) );
}

function Rule_checkRuleMAXCHAR() {
	var sValue = this.getValue();
	return ( sValue.length < parseInt(this.sConditions) );
}

function Rule_checkRuleLIST() {
	var i;
	var sValue = this.getValue();
	for(i=0;i<sValue.length;i++) {
		if( this.sConditions.indexOf(sValue.charAt(i)) == -1 )
			return false;
	}
	return true;
}

function Rule_checkRuleREGEXP() {
	var oRE = new RegExp(this.sConditions);
	return ( oRE.test(this.oTarget.value) );
}

function Rule_checkRuleSELECTED() {
	var i;
	if(this.oTarget.type == "select-multiple") {
		for(i=0;i<this.oTarget.length;i++)
			if(this.oTarget.options[i].selected)
				return true;
	}
	return false;
}

function Rule_checkRuleJS() {
	return(eval(this.sConditions));
}

/*

*/

function Validator() {
	this.aRules = new Array();
	this.sMessage = "";
	this.bGroupMessages = true;
	this.sErrorBgColor = "#FFCC66";
	this.addRule = Validator_addRule;
	this.checkForm = Validator_checkForm;
	this.groupMessages = Validator_groupMessages;
	this.setErrorBgColor = Validator_setErrorBgColor;
}

function Validator_groupMessages(pbValue) {
	this.bGroupMessages = pbValue;
}

function Validator_setErrorBgColor(psColor) {
	this.sErrorBgColor = psColor;
}

function Validator_addRule(poRule) {
	this.aRules[this.aRules.length] = poRule;
}

function Validator_checkForm(sHeader) {
	var i;
	if(this.bGroupMessages) {
		for(i=0;i<this.aRules.length;i++) {
			this.sMessage += this.aRules[i].checkRule(this.sErrorBgColor);
		}
		if( this.sMessage != "") {
            this.sMessage = sHeader + this.sMessage;
			alert(this.sMessage);
			this.sMessage = "";
			return false;
		}
	} else {
		for(i=0;i<this.aRules.length;i++) {
			this.sMessage = this.aRules[i].checkRule();
			if( this.sMessage != "") {
                this.sMessage = sHeader + this.sMessage;
				alert(this.sMessage);
				this.sMessage = "";
				return false;
			}
		}
	}
	this.sMessage = "";
	return true;
}

var oValidator1 = null;
function initValidator1() {
    oValidator1 = new Validator();
    oValidator1.setErrorBgColor("#ffdbdb");
    with (document.frmRequest) {
	oValidator1.addRule( new Rule(CompanyName, "NOTNULL", "", "Enter a Company Name") );
	oValidator1.addRule( new Rule(CustomerName, "NOTNULL", "", "Enter a Customer Name") );
	//oValidator1.addRule( new Rule(Address1, "NOTNULL", "", "Enter a Company Address") );
	oValidator1.addRule( new Rule(City, "NOTNULL", "", "Enter a City") );
	oValidator1.addRule( new Rule(ZipCode, "NOTNULL", "", "Enter a Postal/Zip Code") );
	oValidator1.addRule( new Rule(Country, "JS", "document.frmRequest.Country.selectedIndex > 0", "Choose a Country") );
	oValidator1.addRule( new Rule(Phone, "NOTNULL", "", "Enter a Phone") );
	oValidator1.addRule( new Rule(EmailAddress, "NOTNULL", "", "Enter an EmailAddress") );
	oValidator1.addRule( new Rule(EmailAddress, "EMAIL", "", "Enter a valid EmailAddress") );
	oValidator1.addRule( new Rule(CustomerPartNum, "NOTNULL", "", "Enter a Customer Drawing/Part #") );
	oValidator1.addRule( new Rule(EMCPartNum, "NOTNULL", "", "Enter an EMC Part#") );
	//oValidator1.addRule( new Rule(Est_Annual_Usage, "NOTNULL", "", "Enter an Estimated Annual Usage") );
	//oValidator1.addRule( new Rule(Shipment_Lots, "NOTNULL", "", "Enter a Shipment Lot Sizes") );
	//oValidator1.addRule( new Rule(Target_Price, "NOTNULL", "", "Enter a Target Price") );
    }
}

var oValidator2 = null;
function initValidator2() {
    oValidator2 = new Validator();
    oValidator2.setErrorBgColor("#ffdbdb");
    with (document.frmSample) {
	oValidator2.addRule( new Rule(CompanyName, "NOTNULL", "", "Enter a Company Name") );
	oValidator2.addRule( new Rule(CustomerName, "NOTNULL", "", "Enter a Customer Name") );
	oValidator2.addRule( new Rule(Address1, "NOTNULL", "", "Enter a Company Address") );
	oValidator2.addRule( new Rule(City, "NOTNULL", "", "Enter a City") );
	oValidator2.addRule( new Rule(ZipCode, "NOTNULL", "", "Enter a Postal/Zip Code") );
	oValidator2.addRule( new Rule(Country, "JS", "document.frmSample.Country.selectedIndex > 0", "Choose a Country") );
	oValidator2.addRule( new Rule(Phone, "NOTNULL", "", "Enter a Phone") );
	oValidator2.addRule( new Rule(EmailAddress, "NOTNULL", "", "Enter an Email Address") );
	oValidator2.addRule( new Rule(EmailAddress, "EMAIL", "", "Enter a valid Email Address") );
    }
}
																			
var oValidator3 = null;
function initValidator3() {
    oValidator3 = new Validator();
    oValidator3.setErrorBgColor("#ffdbdb");
    with (document.frmSample) {
	oValidator3.addRule( new Rule(CompanyName, "NOTNULL", "", "Enter a Company Name") );
	oValidator3.addRule( new Rule(CustomerName, "NOTNULL", "", "Enter a Customer Name") );
	oValidator3.addRule( new Rule(Address1, "NOTNULL", "", "Enter a Company Address") );
	oValidator3.addRule( new Rule(City, "NOTNULL", "", "Enter a City") );
	oValidator3.addRule( new Rule(ZipCode, "NOTNULL", "", "Enter a Postal/Zip Code") );
	oValidator3.addRule( new Rule(Country, "JS", "document.frmSample.Country.selectedIndex > 0", "Choose a Country") );
	oValidator3.addRule( new Rule(Phone, "NOTNULL", "", "Enter a Phone") );
	oValidator3.addRule( new Rule(EmailAddress, "NOTNULL", "", "Enter an Email Address") );
	oValidator3.addRule( new Rule(EmailAddress, "EMAIL", "", "Enter a valid Email Address") );
    }
}

																	
var oValidator4 = null;
function initValidator4() {
    oValidator4 = new Validator();
    oValidator4.setErrorBgColor("#ffdbdb");
    with (document.frmSample) {
	oValidator4.addRule( new Rule(CompanyName, "NOTNULL", "", "Enter a Company Name") );
	oValidator4.addRule( new Rule(CustomerName, "NOTNULL", "", "Enter a Customer Name") );
	oValidator4.addRule( new Rule(Address1, "NOTNULL", "", "Enter a Company Address") );
	oValidator4.addRule( new Rule(City, "NOTNULL", "", "Enter a City") );
	oValidator4.addRule( new Rule(ZipCode, "NOTNULL", "", "Enter a Postal/Zip Code") );
	oValidator4.addRule( new Rule(Country, "JS", "document.frmSample.Country.selectedIndex > 0", "Choose a Country") );
	oValidator4.addRule( new Rule(Phone, "NOTNULL", "", "Enter a Phone") );
	oValidator4.addRule( new Rule(EmailAddress, "NOTNULL", "", "Enter an Email Address") );
	oValidator4.addRule( new Rule(EmailAddress, "EMAIL", "", "Enter a valid Email Address") );
    }
}
																																													    