	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_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_nbGroup(event, grpName) { //v6.0
		var i,img,nbArr,args=MM_nbGroup.arguments;
		if (event == "init" && args.length > 2) {
			if ((img = MM_findObj(args[2])) != null && !img.MM_init) {
				img.MM_init = true; img.MM_up = args[3]; img.MM_dn = img.src;
				if ((nbArr = document[grpName]) == null) nbArr = document[grpName] = new Array();
				nbArr[nbArr.length] = img;
				for (i=4; i < args.length-1; i+=2) if ((img = MM_findObj(args[i])) != null) {
					if (!img.MM_up) img.MM_up = img.src;
					img.src = img.MM_dn = args[i+1];
					nbArr[nbArr.length] = img;
			} }
		} else if (event == "over") {
			document.MM_nbOver = nbArr = new Array();
			for (i=1; i < args.length-1; i+=3) if ((img = MM_findObj(args[i])) != null) {
				if (!img.MM_up) img.MM_up = img.src;
				img.src = (img.MM_dn && args[i+2]) ? args[i+2] : ((args[i+1])? args[i+1] : img.MM_up);
				nbArr[nbArr.length] = img;
			}
		} else if (event == "out" ) {
			for (i=0; i < document.MM_nbOver.length; i++) {
				img = document.MM_nbOver[i]; img.src = (img.MM_dn) ? img.MM_dn : img.MM_up; }
		} else if (event == "down") {
			nbArr = document[grpName];
			if (nbArr)
				for (i=0; i < nbArr.length; i++) { img=nbArr[i]; img.src = img.MM_up; img.MM_dn = 0; }
			document[grpName] = nbArr = new Array();
			for (i=2; i < args.length-1; i+=2) if ((img = MM_findObj(args[i])) != null) {
				if (!img.MM_up) img.MM_up = img.src;
				img.src = img.MM_dn = (args[i+1])? args[i+1] : img.MM_up;
				nbArr[nbArr.length] = img;
		} }
	}


	function validate(theform){
		var errors = '';
		
		// Check that the text had no spaces by making use
		// of regular expressions, \s means any 'space' character
	
		re = /\s/;
		 if ( re.test(theform.BillToName.value) ) {
		} else {
			errors = errors + '\nPlease enter your full name (first & last) in the Bill To Field';
			// alert("Please enter your full name (first & last) in the Bill To Field");
			// return false;
		}
		
		if ( re.test(theform.ShipToName.value) ) {
		} else {
			errors = errors + '\nPlease enter your full name (first & last) in the Ship To Field';
			// alert("Please enter your full name (first & last) in the Ship To Field");
			// return false;
		}  
		
		if(document.theform.ShipToCountry.value == "CA") {
		// check Canadian Postal Code
	
		// objRegExp_CA = "[A-Z]\d[A-Z]\s\d[A-Z]\d";
		objRegExp_CA  = /[A-Z]\d[A-Z]\s\d[A-Z]\d/;
		objRegExp_US  = /(^\d{5}$)|(^\d{5}-\d{4}$)/;
		
		strValue = document.theform.ShipToPostalCode.value;
		strValue = strValue.replace("-", " ");
		// alert(strValue);
		
		if(strValue.length == 6) {
			strValue = strValue.charAt(0)+strValue.charAt(1)+strValue.charAt(2)+" " +strValue.charAt(3)+strValue.charAt(4)+strValue.charAt(5);	
		}
		
		document.theform.ShipToPostalCode.value = strValue;
		
	
		
		if(objRegExp_CA.test(strValue)) {	
		} else {
			errors = errors + '\nPlease enter valid Postal Code';		
		}
		
		
		
		
		
		if(errors != '') {
			alert('Error: please correct the following\n'+errors);
			
			return false;
		} else { 
			return true;
		}
		
		
		}
		
		
	}


	function updateFields () {
	 if (document.theform.SoldIsShip.checked == 1){
		document.theform.ShipToName.value 				= document.theform.BillToName.value;
		document.theform.ShipToCompanyName.value 	= document.theform.BillToCompanyName.value;
		document.theform.ShipToAddress1.value 		= document.theform.BillToAddress1.value;
		document.theform.ShipToAddress2.value 		= document.theform.BillToAddress2.value;
		document.theform.ShipToCity.value 				= document.theform.BillToCity.value;
		if($('BillToProv')) { document.theform.ShipToProv.value = document.theform.BillToProv.value }
		document.theform.ShipToCountry2.value 		= document.theform.BillToCountry2.value;		
		document.theform.ShipToPostalCode.value	 	= document.theform.BillToPostalCode.value;
		
	} else {
		document.theform.ShipToName.value 				= "";
		document.theform.ShipToCompanyName.value 	= "";
		document.theform.ShipToAddress1.value 		= "";
		document.theform.ShipToAddress2.value 		= "";
		document.theform.ShipToCity.value 				= "";
		document.theform.ShipToProv.value 				= "";
		document.theform.ShipToPostalCode.value 	= "";
		document.theform.ShipToCountry2.value 		= "";
	}
		SetCountry();
	
	}


	function SetCountry () {
		document.theform.ShipToCountry.value = document.theform.BillToCountry.options[document.theform.BillToCountry.selectedIndex].value;
		
		if(document.theform.BillToCountry.options[document.theform.BillToCountry.selectedIndex].value == 'International' ) { 
			document.getElementById('div_BillToCountry2').style.display = 'block';
			document.getElementById('div_ShipToCountry2').style.display = 'block';
		} else { 
			document.getElementById('div_BillToCountry2').style.display = 'none'; 
			document.getElementById('div_ShipToCountry2').style.display = 'none';
			document.getElementById('BillToCountry2').value = '';
			document.getElementById('ShipToCountry2').value = '';
		}
		
		
		if(document.getElementById('BillToCountry2').value != '' && document.getElementById('BillToCountry').value == 'International') {
			document.theform.ShipToCountry.value = document.getElementById('BillToCountry').value +' / '+ document.getElementById('BillToCountry2').value;
			
		} else {
			document.theform.ShipToCountry.value = document.theform.BillToCountry.value ;			
		}
		
		
		if(document.getElementById('ShipToCountry2').value != '' && document.getElementById('BillToCountry').value == 'International') {
			document.theform.ShipToCountry.value = document.getElementById('BillToCountry').value +' / '+ document.getElementById('ShipToCountry2').value;
			
		} else {
			document.theform.ShipToCountry.value = document.theform.BillToCountry.value ;			
		}
	}

	
	function makeRemote(LOC) {
		remote = window.open("","remotewin","width=300,height=200,scrollbars=1");
		remote.location.href = LOC;
				if (remote.opener == null) remote.opener = window; 
		remote.opener.name = "opener";
	}
	
	
	function checkForm_Checkout() { // alert($('Comments').value);
		errorMessage = '';
		
		if($('CreditCard').value == '') { errorMessage = errorMessage + "\n - Missing Method of Payment"; } else {
			if($('CreditCard').value == 'PurchaseOrder' && $('PurchaseOrderNo').value == '') 		{ errorMessage = errorMessage + "\n - Missing Purchase Order Number"; }
			
			if($('CreditCard').value == 'Visa' || $('CreditCard').value == 'MasterCard') {
				if($('CreditCardNo').value == '') 			{ errorMessage = errorMessage + "\n - Missing Credit Card Number"; }
				if($('CreditCardNo').value.length < 16) { errorMessage = errorMessage + "\n - Invalid Credit Card Number"; }
			}
			
			if($('CreditCard').value == 'Request PayPal') {
				// if($('Comments').value == '') 			{ errorMessage = errorMessage + "\n - Missing Comments regarding this purchase"; }
			}
		}
		
		
		if(errorMessage != '') {
			alert("Please correct the following items\n"+errorMessage);
			
			return false;
		} else {
			// alert("no errors");
			return true;		
		}
		
	}


