// **************************************************************
// This page lives in two locations:
// - local webserver: /CommonWeb/JavaScript/InstPrice/
// - tiera.net webserver: /htdocs/JavaScript/InstaPrice/
// Please distribute in both locations.
// **************************************************************

var url = window.location.href.toUpperCase();
var lHost = window.location.host.toLowerCase();
var isChangeOrderPage = (url.indexOf("CHANGEORDERATTRIBUTES.ASP") != -1);

// Determine whether status is PUBLIC, INTERNAL, TRAINING, OR DEVELOPMENT
// DEFAULT IS PUBLIC !!!!!

//var DEV01 = url.indexOf("COURTNEY");
//var DEV02 = url.indexOf("LOCALHOST");
//var DEV03 = url.indexOf("EDWARD");
//var DEV04 = url.indexOf("DENIZ");
//var DEV05 = url.indexOf("KATHRYN"); //Kathryn
//var DEV06 = url.indexOf("MICHAEL"); //Michael
//var DEV07 = url.indexOf("LOGOWORKS.PFLNET.NET"); //LogoWorks Test
//var DEV08 = url.indexOf("GARY");
//var DEV09 = url.indexOf("DAVID");
//var DEV10 = url.indexOf("GRETEL");

//comment out by Vu
//Check for Internal framesets
//var TrainingFrame = 0;
//var OfflineFrame = 0;
//for (var i=0;i<parent.frames.length;i++) {
//     if (parent.frames[i].name == 'TrainingFrame') {
//	  TrainingFrame = 1;
//     }
//     if (parent.frames[i].name == 'OfflineFrame') {
//	  OfflineFrame = 1;
//     }
//     //alert(TrainingFrame);
//}
//var TrainingDB = url.indexOf("TRAININGDB.PFLNET.NET");
//var Internal = url.indexOf("DB.PFLNET.NET"); 
//
//if ((DEV01 > 0) || (DEV02 > 0) || (DEV03 > 0) || (DEV04 > 0) || (DEV05 > 0) || (DEV06 > 0) || (DEV07 > 0) || (DEV08 > 0) || (DEV09 > 0) || (DEV10 > 0)) {var weblocation = "DEVELOPMENT";}
//else if ((TrainingFrame > 0) || (TrainingDB > 0)) {var weblocation = "TRAINING";}
//else {var weblocation = "PUBLIC";}

var weblocation = "PUBLIC";

//determine site for OfficeMax and DO specific coding
//var site;
//if (url.indexOf('CHANNEL') != -1 || (isChangeOrderPage && document.price.channelID && document.price.channelID.value != '')) { site = "Channel"; }
//else if (url.indexOf('VERTICALLEND=TRUE') != -1) { site = "VL"; }
//else if (url.indexOf('DOBCARDS') != -1) { site = "DO"; }
//else if (url.indexOf('MATHNASIUM') != -1) { site = "MN"; }
//else if (url.indexOf('LOGOWORKS') != -1) { site = "LW"; }
//else if (url.indexOf('OFFICEMAX') != -1) { site = "OM"; }
//else if (url.indexOf('PDSPRINTINGCENTER') != -1) { site = "PC"; }
//else if (url.indexOf('MBA') != -1) { site = "MBA"; }
//else if (url.indexOf('PITNEYBOWES') != -1) { site = "PB"; }
//else if (url.indexOf('INSTAORDER') != -1) { site = "TO"; }
//else { site = "default"; }

var site = "default";

//if ((weblocation == "PUBLIC") && ((site == "default" || site == "MN" || site == "PB" || site == "MBA") && !isChangeOrderPage)) {
//	var protocol = window.location.protocol;
//	var preferedHost = (site == "MN") ? 'www.printingforless1.com' : 'www.printingforless.com';
//	if (protocol == "http:" || lHost != preferedHost) { 
//		var secureUrl = window.location.href.toLowerCase().replace('http:', 'https:');
//		secureUrl = secureUrl.replace(lHost, preferedHost);
//		secureUrl = secureUrl.replace('pitneybowes/', 'PitneyBowes/')
//		secureUrl = secureUrl.replace('mba/', 'MBA/')
//		location.replace(secureUrl); // replace current page in history and redirect
//	}
//}

function buildArray() {
	var a = buildArray.arguments;
	for (i=0; i<a.length; i++) {
    	this[i] = a[i];
	}
	this.length = a.length;
}

//comment out by Vu
//set prefix for absolute path to other ordering pages for Channel and DO sites
//if (site == "Channel") {
//	var prefix = "http://www.pdsprinting.com/";
//}
//else if (site == "DO" || site == "MN" || site == "LW") {
//	var prefix = "https://www.printingforless.com/";
//}
//else {
//	var prefix = "";
//}

//prefix added by Vu
var prefix = "";

var urls1 = new buildArray(
	"",
	prefix + "brochureseight.html",
	prefix + "brochuresfourteen.html",
	prefix + "brochureseleven.html",
	prefix + "brochurestwentyfive.html",
	prefix + "brochuresposters.html",
	prefix + "cardspostcards.html",
	prefix + "cardsrackcards.html",
	prefix + "cardsbusinesscards.html",
	prefix + "cardsgreetingcards.html",
	prefix + "cardsbookmarks.html",
	prefix + "cardsdoorhangers.html",

	prefix + "newsletterseight.html",
	prefix + "newsletterseleven.html",
	prefix + "newsletterstwentyfive.html",
	prefix + "stationeryletterhead.html",
	prefix + "stationeryletterheadonly.html",
	prefix + "stationeryenvelopesonly.html",
	prefix + "stationerylrgenvelopes.html",
	prefix + "catalogsfive.html",
	prefix + "catalogseight.html",
	prefix + "calendars.html",
	prefix + "presentationfolders.html",
	prefix + "filefolders.html",
	prefix + "custompieces.html",
	prefix + "statementstuffers.html",
	prefix + "cdcovers.html");


function go(which, num, win) {
	n = which.selectedIndex;
	if (n != 0) {
    	var url = eval("urls" + num + "[n]")
		if (win) {
			openWindow(url);
		} else {
			if (site == "Channel") {
				top.location.href = url;
			} else {
				location.href = url;
			}
		}
	}
}

//the expireCookie function needs to be placed in this location on this page.
//do not move it or remove it from StandardValidation.js
function expireCookie()
{
        if (document.cookie != "") {
            var Expire = new Date(97, 0, 1); //expires January 1, 1997
            document.cookie = "volumeDiscount=; expires=" + Expire.toGMTString();
        }
}

function hideLayer(layerid) {
  var layerElement = (document.layers) ? document.layers[layerid] : document.getElementById(layerid);
  layerElement.style.display = "none";
}

function showLayer(layerid) {
  var layerElement = (document.layers) ? document.layers[layerid] : document.getElementById(layerid);
  layerElement.style.display = "";
}

function CopyInfo() {
	document.price.SHIPPINGCOMPANYNAME.value = document.price.COMPANYNAME.value;
	document.price.SHIPPINGCUSTOMERFIRSTNAME.value = document.price.CUSTOMERFIRSTNAME.value;
	document.price.SHIPPINGCUSTOMERLASTNAME.value = document.price.CUSTOMERLASTNAME.value;
	document.price.SHIPPINGADDRESS.value = document.price.BILLINGADDRESS.value;
	document.price.SHIPPINGADDRESS2.value = document.price.BILLINGADDRESS2.value;
	document.price.SHIPPINGCITY.value = document.price.BILLINGCITY.value;
	document.price.SHIPPINGSTATE.selectedIndex = document.price.BILLINGSTATE.selectedIndex;
	document.price.SHIPPINGZIPCODE.value = document.price.BILLINGZIPCODE.value;
	document.price.SHIPPINGCOUNTRY.selectedIndex = document.price.BILLINGCOUNTRY.selectedIndex;
	document.price.SHIPPINGAREACODE.value = document.price.BILLINGAREACODE.value;
	document.price.SHIPPINGPHONENUMBER.value = document.price.BILLINGPHONENUMBER.value;
	if (document.price.SHIPPINGCOUNTRY.selectedIndex != 0) {
 		alert('Quoted Shipping prices are only valid for addresses in the USA.\n\nPlease contact customer service for shipping prices to other countries.');
	} 
}

function LWCopyInfo() {
	document.price.SHIPPINGCOMPANYNAME.value = document.price.ChannelCustomerCompany.value;
	document.price.SHIPPINGCUSTOMERFIRSTNAME.value = document.price.ChannelCustomerFirstName.value;
	document.price.SHIPPINGCUSTOMERLASTNAME.value = document.price.ChannelCustomerLastName.value;
	document.price.SHIPPINGAREACODE.value = document.price.ChannelCustomerAreaCode.value;
	document.price.SHIPPINGPHONENUMBER.value = document.price.ChannelCustomerPhone.value;
	if (document.price.SHIPPINGCOUNTRY.selectedIndex != 0) {
 		alert('Quoted Shipping prices are only valid for addresses in the USA.\n\nPlease contact customer service for shipping prices to other countries.');
	} 
}

var markupArray = new Array();
for (var i = 0; i < 51; i++) {
	markupArray[i] = new Array(0.3, 0.4, 0.5, 0, 0.1, 0.2);
}

//-----------------------------------------------------------------------------

function MakeCents(value) {
	var valueWithCorrectDecimalPosition = value / 100;
	return FormatFractionalNumber(valueWithCorrectDecimalPosition, 2);
}    

function FormatFractionalNumber(num, decimalPlaces) {
	var powerOfTen = Math.pow(10, decimalPlaces);
	var stringNum = (Math.round(num * powerOfTen) / powerOfTen).toString();
	var posDecimal = stringNum.indexOf(".");
	var zeroToAppendCnt = 0;
	if (posDecimal < 0) {
		stringNum += ".";
		zeroToAppendCnt = decimalPlaces;
	} else {
		zeroToAppendCnt = decimalPlaces - (stringNum.length - posDecimal - 1);
	}
	for (var i = 0; i < zeroToAppendCnt; i++) {
		stringNum += "0";
	}
	return stringNum;
}

//-----------------------------------------------------------------------------
// added 8/30/2002 cmb
function checkFileTransfer() {
	if (document.price.file1.value !="" || document.price.file2.value !="" || 
		   document.price.file3.value !="" || document.price.file4.value !="") {
		alert("You have selected a file to upload.  You must choose 'Select the File(s) to Upload from Your Computer' as your File Transfter Method");
		document.price.filetransfer[0].checked=true;
	}
}

//-----------------------------------------------------------------------------
// added 1/14/2004 mtm
// updated 7/8/2004 cmb
// updated and revised 4/29/2005 kar

function CheckCoupon() {

	var customerGroup = document.price.CUSTOMER;
	var theCoupon = document.price.COUPON.value.toUpperCase();

	//remove leading or trailing whitespace
	theCoupon.replace(/^\s*/, '').replace(/\s*$/, ''); 

	// NC coupons are only for new customers
	if (customerGroup[1].checked && theCoupon.substring(0,2)=="NC") { 
		alert('The coupon you have entered is only valid for new customers.');
		document.price.COUPON.value="";
		if (site == "PB" || site == "MBA") {
		    document.price.couponAmount.value="";
		    document.price.finalTotalPrice.value = document.price.totalPrice.value;
		}
	    return (false);
	} else if (site == "MBA") {
	   if (document.price.totalPrice.value > 250 && !customerGroup[1].checked)  {
		document.price.COUPON.value="NCMBA100";
		document.price.couponAmount.value="100.00";
	   }
	   if (theCoupon == "NCMBA100" && document.price.totalPrice.value < 250 ) {
		alert('The coupon discount is only valid on orders over $250. Please call if you have any questions.');
		document.price.COUPON.value="";
		document.price.couponAmount.value="";
		document.price.finalTotalPrice.value = document.price.totalPrice.value;
		return (false);
	   }
    } else if (site == "PB") { //PitneyBowes
	   if (gProduct == 7) { //offer only for business cards
		  if (!customerGroup[1].checked)  {
			 document.price.COUPON.value="NC50PP"; //50%
			 document.price.couponAmount.value=(MakeCents( Math.round(100*(document.price.totalPrice.value*.5))));
			 document.price.finalTotalPrice.value = (MakeCents( Math.round(100*(document.price.totalPrice.value - document.price.couponAmount.value))));
		  }
	   }
	} else if ((theCoupon == "CC10" || theCoupon == "NC15S") && site == "Channel") { //not valid for Channel orders
		alert('The coupon you have entered is not valid. Please call if you have any questions.');
		document.price.COUPON.value="";
		return (false);
	} else if (gProduct != 26 && theCoupon == "CC10") { // 26 = custom quote
		alert('The coupon you have entered is only valid for custom quote orders. Please call if you have any questions.');
		document.price.COUPON.value="";
		return (false);
	} else if (gProduct != 11 && theCoupon == "NC15S") { // 11 = letterhead/envelope
		alert('The coupon you have entered is only valid for letterhead/envelope orders. Please call if you have any questions.');
		document.price.COUPON.value="";
		return (false);
	} else if ((theCoupon.length!=0) && (theCoupon.indexOf("RP1") >= 0)) {
		alert('The coupon you entered in the Promotional Code field is a Referral Code. Please enter this code in the Referral Code field.');
		return (false);
	} else if (!(isValidCoupon(theCoupon))) {
		alert('The Promotional Code field contains an invalid character.');
		return (false);
	}
}

function CheckReferralCode() {

	var theRefCoupon = document.price.REFCOUPON.value.toUpperCase();
	var customerGroup = document.price.CUSTOMER;
	
	//remove leading or trailing whitespace
	theRefCoupon.replace(/^\s*/, '').replace(/\s*$/, ''); 
	
	if ((theRefCoupon.length!=0) && ((theRefCoupon.indexOf("RP1") < 0) && (theRefCoupon.indexOf("RP5") < 0))) {
		alert('The coupon you entered in the Referral Code field is a Promotional Code. Please enter this code in the Promotional Code field.');
		return (false);
	} else if ((theRefCoupon.length!=0) && (theRefCoupon.indexOf("RP1") < 0) && (customerGroup[1].checked)) {
		alert('The coupon you have entered is only valid for new customers.');
		return (false);
	} else if (theRefCoupon.length > 9) {
		alert('Only one coupon is allowed in the Referral Code field. Place all other referral code coupons in the Special instructions textbox.');
		return (false);
	} else if (!(isValidCoupon(theRefCoupon))) {
		alert('The Referral Code field contains an invalid character.');
		return (false);
	}
}

function ChangeMarkupCQ() { //Channel only
	var totalPrice;
	var wholesaleprice;
	var index;
	var markupInt, markup, markupPrice
	
    for (var i=0; i<document.price.ChannelMarkupPercent.length; i++) {
        if (document.price.ChannelMarkupPercent[i].checked) {
			index = i;
        }
     }
	markupInt = document.price.ChannelMarkupPercent[index].value;
	markup = (markupArray[gProduct][markupInt]);

	document.price.QUOTEPRICE.value = strip(',',document.price.QUOTEPRICE.value);
	wholesaleprice = document.price.QUOTEPRICE.value;
	
	if (((wholesaleprice / wholesaleprice) != 1) && (wholesaleprice != 0)) { 
		alert('Please enter currency only');
		document.price.QUOTEPRICE.focus();
		//exit;
	} else {
		if (wholesaleprice != "") {
				totalPrice = document.price.QUOTEPRICE.value * (markup + 1) * 100;
				markupPrice = document.price.QUOTEPRICE.value * markup * 100
				document.price.totalPrice.value = MakeCents( Math.round( totalPrice ) );
				document.price.markupPrice.value = MakeCents( Math.round( markupPrice ) );
		}
	}
}

function shippingValidate() {

    //alert("shippingValidate");

    if(document.price.SHIPPINGCUSTOMERFIRSTNAME.value =="") {
        alert("Please type in your first name in Shipping Information");
        //document.price.SHIPPINGCUSTOMERFIRSTNAME.focus();
        return (false);
    } else if(document.price.SHIPPINGCUSTOMERLASTNAME.value =="") {
        alert("Please type in your last name in Shipping Information");
        //document.price.SHIPPINGCUSTOMERLASTNAME.focus();
        return (false);
    } else if(document.price.SHIPPINGADDRESS.value =="") {
        alert("Please type in your address in Shipping Information");
        //document.price.SHIPPINGADDRESS.focus();
        return (false);
    } else if(document.price.SHIPPINGCITY.value =="") {
        alert("Please type in your city in Shipping Information");
        //document.price.SHIPPINGCITY.focus();
        return (false);
    } else if(document.price.SHIPPINGSTATE.value =="") {
        alert("Please indicate in your state in Shipping Information");
        //document.price.SHIPPINGSTATE.focus();
        return (false);
    } else if(document.price.SHIPPINGZIPCODE.value =="") {
        alert("Please type in your zipcode in Shipping Information");
        //document.price.SHIPPINGZIPCODE.focus();
        return (false);
    } else if ((document.price.SHIPPINGCOUNTRY.selectedIndex != 0)&&(document.price.SHIPPINGCOUNTRY.selectedIndex != 1)) {
        alert('Quoted Shipping prices are only valid for addresses in the USA and Can.\n\nPlease contact customer service for shipping prices to other countries.');
    } else if(document.price.SHIPPINGAREACODE.value =="") {
        alert("Please type in your area code in Shipping Information");
        //document.price.SHIPPINGAREACODE.focus();
        return (false);
    } else if(document.price.SHIPPINGPHONENUMBER.value =="") {
        alert("Please type in your phone number in Shipping Information");
        //document.price.SHIPPINGPHONENUMBER.focus();
        return (false);
    } else if (site!= "VL" && document.price.shiptype && (document.price.shiptype[0].checked || document.price.shiptype[1].checked) &&
        (document.price.SHIPPINGSTATE.value == "HI" || document.price.SHIPPINGSTATE.value == "AK" ||
            document.price.SHIPPINGSTATE.value == "PR" || document.price.SHIPPINGSTATE.value == "VI")) {
        //document.price.shiptype[0] = Ground  document.price.shiptype[1] = 3-Day
        alert('Air Shipping is required for Alaska, Hawaii, Puerto Rico or the Virgin Islands');
        return (false);
    }  
    return (true);
}

function customOrderValidate() {

    //alert("customOrderValidate");

    if(document.price.QUOTENUMBER.value ==""){
	    alert("Please enter your quote number");
	    document.price.QUOTENUMBER.focus();
	    return (false);
    } else if (document.price.QUOTENUMBER.value != "") { 
        //quote number has been entered
	    //check for validity of quote number
	    var theString;
	    theString = document.price.QUOTENUMBER.value;

	    if (!(isNumberString(theString))) {
		    alert("Please enter Custom Quote Number with numbers only.");
		    document.price.QUOTENUMBER.focus();
		    return (false);
	    }
    }

    document.price.QQUANTITY.value = strip(',',document.price.QQUANTITY.value);
    var quotequantity = document.price.QQUANTITY.value;
    if(quotequantity ==""){
	    alert("Please enter a quantity");
	    document.price.QQUANTITY.focus();
	    return (false);
    } else if (!(isNumberString(quotequantity))) {
	    alert("Please enter an amount (no commas).");
	    document.price.QQUANTITY.focus();
	    return (false);
    }
    document.price.QUOTEPRICE.value = strip(',',document.price.QUOTEPRICE.value);
    var quoteprice = document.price.QUOTEPRICE.value;
    if(quoteprice ==""){
	    alert("Please type in your quoted price");
	    return (false);
    } else if (!(isCurrency(quoteprice))) {
	    alert("Please supply currency for the price");
	    return (false);
    } else if (site == "Channel") {
        var wholesaleprice = document.price.QUOTEPRICE.value;
        var markupButton = document.price.ChannelMarkupPercent;
        if (((wholesaleprice / wholesaleprice) != 1) && (wholesaleprice != 0)) {
	        alert('Please enter the price without a dollar sign.')
	        document.price.QUOTEPRICE.focus();
	        return (false);
         } else if (!(markupButton[0].checked || markupButton[1].checked || markupButton[2].checked)){
	        alert("Please choose a markup level.");
	        return (false);
        }
    }
    return (true);
}

function logoWorksCustomerValidate() {

    //alert("logoWorksCustomerValidate");

	if(document.price.CUSTOMERFIRSTNAME.options[document.price.CUSTOMERFIRSTNAME.selectedIndex].value =="") {
	    alert("Please select your first name");
	    document.price.CUSTOMERFIRSTNAME.focus();
	    return (false);
	} else if (document.price.ChannelOrderNumber.value == "") {
		alert("Please type in the LogoWorks Reference #");
		document.price.ChannelOrderNumber.focus();
		return (false);
    } else if (document.price.ChannelCustomerCompany.value == "") {
		alert("Please type in the LogoWorks Customer Company");
		document.price.ChannelCustomerCompany.focus();
		return (false);
	} else if (document.price.ChannelCustomerFirstName.value == "") {
		alert("Please type in the LogoWorks Customer First Name");
		document.price.ChannelCustomerFirstName.focus();
		return (false);
	} else if (document.price.ChannelCustomerLastName.value == "") {
		alert("Please type in the LogoWorks Customer Last Name");
		document.price.ChannelCustomerLastName.focus();
		return (false);
	} else if (document.price.ChannelCustomerEmail.value == "") {
		alert("Please type in the LogoWorks Customer Email");
		document.price.ChannelCustomerEmail.focus();
		return (false);
	} else if (document.price.ChannelCustomerAreaCode.value == "") {
		alert("Please type in the LogoWorks Customer Area Code");
		document.price.ChannelCustomerAreaCode.focus();
		return (false);
	} else if (document.price.ChannelCustomerPhone.value == "") {
		alert("Please type in the LogoWorks Customer Phone");
		document.price.ChannelCustomerPhone.focus();
		return (false);
	} else if(document.price.CUSTOMERFIRSTNAME.value == "") {
		alert("Please type in your first name in Contact Information");
		//document.price.CUSTOMERFIRSTNAME.focus();
		return (false);
	}
	return (true);
}

function channelCustomerValidate() {

    //alert("channelCustomerValidate");

	if(document.price.ChannelCustomer.value =="") {
		alert("Please type in the OfficeMax Customer Name");
		//document.price.ChannelCustomer.focus();
		return (false);
	} else if(document.price.PROJECTNAME.value =="") {
	    alert("Please type in the Name of the Project");
	    //document.price.PROJECTNAME.focus();
	    return (false);
    } else if(document.price.ChannelStore.value =="") {
		alert("Please type in your OfficeMax Store #");
		//document.price.ChannelStore.focus();
		return (false);
	} else if(document.price.channel.value == "false"){
		alert("Please enter a valid OfficeMax Store #");
		//document.price.ChannelStore.focus();
		return (false);
	} else if(document.price.CUSTOMERFIRSTNAME.value =="") {
	    alert("Please type in your first name in Contact Information");
	    //document.price.CUSTOMERFIRSTNAME.focus();
	    return (false);
    } else if(document.price.CUSTOMERLASTNAME.value =="") {
	    alert("Please type in your last name in Contact Information");
	    //document.price.CUSTOMERLASTNAME.focus();
	    return (false);
    }
    return (true);
}

function standardCustomerValidate(customerIDvalidate) {

    //alert("standardCustomerValidate");
    //this function is not called for LogoWorks
  
  //by Vu
//    if (!(customerIDvalidate)) { //there is a valid Customer Account Number
//        var customerGroup = document.price.CUSTOMER;
//        if (site != "MN" && site != "VL") //exclude Mathnasium and VerticalLend
//        { 
//	        if (!(customerGroup[0].checked || customerGroup[1].checked)) 
//	        {
//		        alert("Please indicate your customer status.");
//		        document.price.CUSTOMER[0].focus();
//		        return (false);
//	        }
//        }
//	} // end customerIDvalidate

    if(document.price.CUSTOMERFIRSTNAME.value =="") {
        alert("Please type in your first name in Contact Information");
        //document.price.CUSTOMERFIRSTNAME.focus();
        return (false);
    } else if(document.price.CUSTOMERLASTNAME.value =="") {
        alert("Please type in your last name in Contact Information");
        //document.price.CUSTOMERLASTNAME.focus();
        return (false);
    } 
    
    if (!(customerIDvalidate) || (site=="VL")) {
    //Issue #784: 09/07/2006 - KR
    //if customer account number is supplied - do not require billing phone
        if (document.price.BILLINGAREACODE.value =="") {
	        alert("Please type in your area code in Contact Information");
	        //document.price.BILLINGAREACODE.focus();
	        return (false);
        } else if (document.price.BILLINGPHONENUMBER.value =="") {
	        alert("Please type in your phone number In Contact Information");
	        //document.price.BILLINGPHONENUMBER.focus();
	        return (false);
        }
    } 
    
    var the_email = document.price.EMAIL.value;		
    var atindex = the_email.indexOf('@');
    if (document.price.EMAIL.value == "") {
	    alert("Please type in your email in Contact Information");
	    //document.price.EMAIL.focus();
	    return (false);
    } else if ((atindex == -1) || (atindex == 0) || (atindex == the_email.length-1)) {
	    alert("Your email is not formatted correctly.");
	    //document.price.EMAIL.focus();
	    return (false);
    }
	return (true);
}

function mailingValidate() {

    //alert("mailingValidate");

	if (document.price.MailingQuantity.value != "" && document.price.MailingQuantity.value != 0) {
		if (document.price.mailingtype && document.price.mailingtype.length > 0) {
			var mailingtypeChecked = false;
			for (var i = 0, lenIter = document.price.mailingtype.length; i < lenIter; i++) {
				if (document.price.mailingtype[i].checked) {
					mailingtypeChecked = true;
					break;
				}
			}
			if (!mailingtypeChecked) {
				alert("Please select mailing type");
				return (false);
			}
		}
	}
	return (true);
}

function billingValidate() {

    //alert("billingValidate");

	if(document.price.BILLINGADDRESS.value =="") {
		alert("Please type in your billing address");
		document.price.BILLINGADDRESS.focus();
		return (false);
	} else if(document.price.BILLINGCITY.value =="") {
		alert("Please type in your billing city");
		document.price.BILLINGCITY.focus();
		return (false);
	} else if(document.price.BILLINGSTATE.options[document.price.BILLINGSTATE.selectedIndex].value =="") {
		alert("Please indicate in your billing state");
		document.price.BILLINGSTATE.focus();
		return (false);
	} else if(document.price.BILLINGZIPCODE.value =="") {
		alert("Please type in your billing zipcode");
		document.price.BILLINGZIPCODE.focus();
		return (false);
	}
	return (true);
}

function paymentValidate(customerIDvalidate) {

    //alert("paymentValidate");

    var creditcardGroup = document.price.CREDITCARD;
    var creditcardsChecked = (creditcardGroup[0].checked || creditcardGroup[1].checked || creditcardGroup[2].checked || creditcardGroup[3].checked );
    // note: card on file, will pay by check, will phone in credit card are not in Mathnasium

    var illegalChars = /[^a-zA-Z0-9 \-.]/;
    // allow only letters, numbers, and spaces, dashes and periods
    
    if ((document.price.LAST4DIGITS) && (!(creditcardGroup[4].checked))) document.price.LAST4DIGITS.value = '';
    
    if ((site == "MN" && (!creditcardsChecked)) //
        || (!(creditcardsChecked || creditcardGroup[4].checked || creditcardGroup[5].checked || creditcardGroup[6].checked))) {
	    alert("Please select your payment type.");
        document.price.CREDITCARD[0].focus();
        return (false);
    } else if ((site == "MN") || (!(creditcardGroup[4].checked || creditcardGroup[5].checked || creditcardGroup[6].checked))) {	
        // if not card on file, will pay by check, will phone in credit card
        if (document.price.NAMEONCARD.value =="") {
            alert("Please type in the name on card");
            document.price.NAMEONCARD.focus();
            return (false);
        } else if ((!(customerIDvalidate)) && (!(billingValidate()))) return false; 
        else if (document.price.CREDITCARDNUMBER.value =="") {
	        alert("Please type in your credit card number");
	        document.price.CREDITCARDNUMBER.focus();
	        return (false);
        } else if (document.price.CREDITCARDNUMBER.value.length >= 20) {
            alert("Your credit card number is too long");
            document.price.CREDITCARDNUMBER.focus();
            return (false);
        } else if (illegalChars.test(document.price.CREDITCARDNUMBER.value)) {
            alert("Your credit card number is incorrect");
            document.price.CREDITCARDNUMBER.focus();
            return (false);
        } else if(document.price.EXPIRESMONTH.options[document.price.EXPIRESMONTH.selectedIndex].value =="") {
            alert("Please select your expiration month");
            document.price.EXPIRESMONTH.focus();
            return (false);
        } else if(document.price.EXPIRESYEAR.options[document.price.EXPIRESYEAR.selectedIndex].value =="") {
            alert("Please select your expiration year");
            document.price.EXPIRESYEAR.focus();
            return (false);
        }
    } else if (creditcardGroup[4].checked) { // card on file
        if (document.price.CUSTOMER[0].checked) {
            alert("The 'card on file' payment option is only valid for returning customers.");
	        return (false);
        } else if (document.price.LAST4DIGITS.value == "") {
            alert("Please supply the last four digits of your credit card.");
            document.price.LAST4DIGITS.focus();
            return (false);
        } else if (!(isNumberString(document.price.LAST4DIGITS.value))) {
            alert("Please supply the last four digits of your credit card.");
            document.price.LAST4DIGITS.focus();
            return (false);   
        }
    }
    return (true);
}

function isValidAccount(){
    //check for validity of customer Account
    var InString;
    InString = document.price.account.value;
    if (InString.length != 9) { //string length = 9
        isInvalidAccountMessage();
        return (false);
    } else {
        var AlphaString;
        var NumericString;
        AlphaString = InString.substring(0,4);
        NumericString = InString.substring(4,9);
        if (!(isAlphabeticString(AlphaString))) 
        {
            isInvalidAccountMessage();
            return (false);
        }
        if (!(isNumberString(NumericString))) 
        {
            isInvalidAccountMessage();
            return (false);
        }
        // valid customer id has been identified
    } //end of string length = 9
    return (true);
}

function validatePresentationFolders() {
	//make sure a pocket is selected
	var pocketSelected = false;
	for (var i = 0; i < document.price.PocketType.length; i++) {
		if (document.price.PocketType[i].checked) {
			pocketSelected = true;
			break;
		}
	}
	if (!pocketSelected) {
		alert("Please select Pockets");
		document.price.PocketType[0].focus();
		return (false);
	}
	//make sure a slit is selected
	var slitsSelected = false;
	for (var i = 0; i < document.price.SlitType.length; i++) {
		if (document.price.SlitType[i].checked) {
			slitsSelected = true;
			break;
		}
	}
	if (!slitsSelected) {
		alert("Please select Card Slits");
		document.price.SlitType[0].focus();
		return (false);
	}
	return (true);
}

function validateDesignOnline() {
	// Check to see that quantities have been filled in for all cards
	for (var i = 1; i <= 12; i++)
	{
		var currentQtyBox = document.forms["price"].elements["name" + i + "qty"];
		if (currentQtyBox.type == "text" && currentQtyBox.value == "") { // if this is a text box rather than one of the hidden placeholder form elements, and no value has been entered
			alert("Please enter a quantity for each card,\nthen recalculate the price.");
			currentQtyBox.focus();
			return (false);
		}
		if (site == "VL" && currentQtyBox.value > 2) {
			alert("You are limited to two boxes.");
		     currentQtyBox.value = 2;
			ChangeNameQuantity();
			currentQtyBox.focus();
			return (false);	     
		}
	}

	// Determine whether any non-zero quantities have been entered
	var nonZeroQuantityEntered = false
	for (var i = 1; i <= 12; i++) {
		var currentQtyBox = document.forms["price"].elements["name" + i + "qty"];
		var currentNameElement = document.forms["price"].elements["name" + i];
		if (currentQtyBox.type == "text") { // if this is a text box rather than one of the hidden placeholder form elements
			if (currentQtyBox.value != "0" && currentQtyBox.value != "") { // if a value of zero has been entered
				nonZeroQuantityEntered = true
			}
		}
	}

	if (!nonZeroQuantityEntered) {
		alert("A quantity other than zero must be entered for at least one card.");
		return (false);
	}
	return (true);
}

//-----------------------------------------------------------------------------
function isValidCoupon (InString) {
	if(InString.length==0) 
	    return (true);
	var RefString = "ABCDEFGHIJKLMNOPQRSTUVWXYZ 0123456789%-";
	for (Count=0; Count < InString.length; Count++)  {
		TempChar= InString.substring(Count, Count+1);
		if (RefString.indexOf(TempChar, 0)==-1) 
			return (false);
	}
	return (true);
}

function isAlphabeticString (InString) {
	if(InString.length==0)
		return (false);
	RefString="ABCDEFGHIJKLMNOPQRSTUVWXYZ";
	for (Count=0; Count < InString.length; Count++)  {
		TempChar= InString.substring(Count, Count+1);
		if (RefString.indexOf(TempChar, 0)==-1) 
			return (false);
	}
	return (true);
}

function isNumberString (InString) {
	if(InString.length==0) 
		return (false);
	RefString="1234567890";
	for (Count=0; Count < InString.length; Count++)  {
		TempChar= InString.substring (Count, Count+1);
		if (RefString.indexOf (TempChar, 0)==-1)  
			return (false);
	}
	return (true);
}

function isCurrency (InString) {
	if(InString.length==0) 
		return (false);
	RefString="0123456789.,$";
	for (Count=0; Count < InString.length; Count++)  {
		TempChar= InString.substring (Count, Count+1);
		if (RefString.indexOf (TempChar, 0)==-1)  
			return (false);
	}
	return (true);
}

function strip(filter,str){
    var i,curChar;
    var retStr = '';
    var len = str.length;
    for(i=0; i<len; i++){
        curChar = str.charAt(i);
        if(filter.indexOf(curChar)<0) 
        //not in filter, keep it
        retStr += curChar;
    }
    return retStr;
}

function isInvalidAccountMessage() {
	alert("The account number you entered is invalid. If you are entering a Promotional Code, please enter the code within the coupon field provided below. If you don't have an account number, please leave the account field blank.");
  	document.price.account.value="";
  	document.price.account.focus();
}

function macWindow(openWindow) {
	if (openWindow) {
    	windowHandle = window.open('macfile.html','window3','width=270,height=200');
        if (!windowHandle.opener) windowHandle.opener = self;
    }
	else
		windowHandle.close();
}

 // Call onclick function for the checked item of a collection
function Click(elem) {
	for (var i = 0; i < elem.length; i++) {
		if (elem[i].checked) {
			elem[i].click();
			break;
		}
	}
}

function newWindow(file,window) {
     msgWindow=open(file,window,'resizable=no,width=500,height=520');
     if (msgWindow.opener == null) msgWindow.opener = self;
 }
 
//by Vu 
//function itemType(itemID) {
//	var itemTxt;
//	if (itemID == "0") itemTxt= "Brochures 8 x 11";
//	else if (itemID == "1") itemTxt = "Brochures 11 x 17";
//	else if (itemID == "14") itemTxt = "Brochures 8-1/2 x 14";
//	else if (itemID == "53") itemTxt = "Brochures 11 x 25-1/2";
//	else if (itemID == "2") itemTxt = "Brochures Poster";
//	else itemTxt = "Unknown";
//	return itemTxt;
//}
 
//-------------------------------------------------------------------------------
function CheckSubmit() {
//alert(site);
    if (site == "VL") { //set PROJECTNAME as LastName, FirstName for VerticalLend orders
	   document.price.PROJECTNAME.value = document.price.CUSTOMERLASTNAME.value + ', ' + document.price.CUSTOMERFIRSTNAME.value;
	   
	   if (document.price.ChannelOrderNumber.value == "") { //manager
		  alert("You must select a manager.");
		  document.price.ChannelOrderNumber.focus();
		  return false;
	   }
    }

    if (site != "DO" && site != "MN" && site != "VL" && site != "TO") {
	    var filetransferGroup = document.price.filetransfer;
		var uploading_files = filetransferGroup[0].checked;
	}
	
    var customerIDvalidate = false; //set to false for channel
    
    //gProduct variable is found in product js script within InstaPriceUtil folder
    if ((gProduct == 21) && (!(validatePresentationFolders()))) return false; //presentation folders
    else if ((gProduct == 26) && (!(customOrderValidate()))) return false; //custom quote
    else if ((site == "DO" || site == "VL") && (!(validateDesignOnline()))) return false; //design online
    
    if ((site != "Channel") && (site != "LW") && (document.price.MailingQuantity) && (!(mailingValidate()))) return false;

	if (uploading_files) {
		if(document.price.file1.value =="" && document.price.file2.value =="" && document.price.file3.value =="" &&  document.price.file4.value =="") {
			alert("Please select a file to upload or another file transfer option in Files Upload");
			
			// comment out jump back to error place by Vu
			//document.price.file1.focus();
			return false;
		}
	}
	
	if (site == "Channel") {
        if (!(channelCustomerValidate())) return false; //channel validation
        
    } else { // regular customer validation - non-channel
        if ((document.price.account.value != "") && (isValidAccount())) customerIDvalidate = true;
        
	    if (site != "LW") {
	        if (!(standardCustomerValidate(customerIDvalidate))) return false; 
		   //operating system and application hardcoded for DO & MN || do not require OS & app for exact reorders
	        // File transfer modified by Vu
			//if (site != "DO" && site != "MN" && site != "VL" && !document.price.filetransfer[4].checked) { 
			if (site != "DO" && site != "MN" && site != "VL") { 
		        var operatingsystemGroup = document.price.OPERATINGSYSTEM;
		        if (!(operatingsystemGroup[0].checked || operatingsystemGroup[1].checked || operatingsystemGroup[2].checked)) {
			        alert("Please select your operating system in Files Upload");
			        //document.price.OPERATINGSYSTEM[0].focus();
			        return false;
		        } else if (document.price.APPLICATION.options[document.price.APPLICATION.selectedIndex].value =="" &&  document.price.APPLICATIONOTHER.value =="") {
			        alert("Please indicate your application in Files Upload");
			        //document.price.APPLICATIONOTHER.focus();
			        return false;
		        }
		    }
		    if (site != "VL") { //no billing validation for Vertical Lend
			   // no billng validation modified by Vu
			   //if (!(paymentValidate(customerIDvalidate))) {return false;} 
		    }
	    } else { //logoworks validation
            if (!(logoWorksCustomerValidate())) return false; 
        }
    } 
    
    if ((!customerIDvalidate) 
        && ((site == "Channel" && document.price.ChannelShipTo[1].checked) || (site != "Channel"))
        && (!shippingValidate())) return false;
	
	if ((gProduct != 26) && (site == "LW")) updateGNTables();
	
	if (site != "DO" && site != "MN" && site != "VL") { //no upload progress window for DO orders & MN
	// Open upload progress window
	//by Vu
		//var w = window.open( "", "UPLOADWINDOW1", "width=380,height=320,resizable=no");
//		if (document.price.FBC) { //change page to files for Free Business Card ordering page
//			if (uploading_files) w.location.href = "../statusbarupload.html";
//	    	else                 w.location.href = "../statusbarorder.html";
//		}
//		else {
//			if (uploading_files) w.location.href = "statusbarupload.html";
//	    	else                 w.location.href = "statusbarorder.html";
//		}
	} else if (site == "DO") { //DO specific validation
		// Clear the name and quantity form elements if the quantity form element is zero
		for (var i = 1; i <= 12; i++) {
			var currentQtyBox = document.forms["price"].elements["name" + i + "qty"];
			var currentNameElement = document.forms["price"].elements["name" + i];
			if (currentQtyBox.type == "text" && currentQtyBox.value == "0") { // if this is a text box rather than one of the hidden placeholder form elements, and a value of zero has been entered
				currentQtyBox.value = ""
				currentNameElement.value = ""
			}
		}
		//found in UtilityFunctions.js include file
		DeleteCookie("SavedBCardsList")
	}
//	
//  	var producttype;
//	var companyname;
//	var customername;
//	var phone;
//	var email;
//	var cgiscriptaction;
//	var customertype;
//	
//	if (site == "default") { //failed Order only for PFL orders in 'default' sites
//		if (document.price.CUSTOMER[0].checked) customertype = "new";
//		else if (document.price.CUSTOMER[1].checked) customertype = "returning"; 
//		else customertype = "unknown";
//			
//		producttype = document.price.productTypeInt.value;
//		companyname = escape(document.price.COMPANYNAME.value);
//		customername = escape(document.price.CUSTOMERFIRSTNAME.value + "_" + document.price.CUSTOMERLASTNAME.value);
//		phone = escape(document.price.BILLINGAREACODE.value + "-" + document.price.BILLINGPHONENUMBER.value);
//		email = escape(document.price.EMAIL.value);
//	} //end default only
//
//	if (gProduct == 26) { //custom quote
//        cgiscriptaction = "https://www.printingforless.com/cgi-bin/";
//	    
//	    if (weblocation == "DEVELOPMENT") {
//		    cgiscriptaction += "processorderTestingCQ.cgi";
//	    } 
//	    else if (weblocation == "TRAINING") {
//		    cgiscriptaction += "processorderTrainingCQ.cgi";
//	    } 
//	    else { //if (weblocation == "PUBLIC") {
//		    cgiscriptaction += "processorderCQ.cgi";
//	    }
//	} else if (site == "MN") {
//		cgiscriptaction = document.price.action;
//	} else { //default, Channel, DO
//		cgiscriptaction = "https://www.printingforless.com/cgi-bin/";
//	     if (weblocation == "DEVELOPMENT") {
//			cgiscriptaction += "processorderTestingM.cgi";
//		} 
//		else if (weblocation == "TRAINING") {
//			cgiscriptaction += "processorderTrainingM.cgi";
//		} 
//		else { //if (weblocation == "PUBLIC") {
//			cgiscriptaction += "processorderM.cgi";
//		}
//	}
//	
//	if (site == "default") { //no failed Order for Channel and DO
//		document.price.action = cgiscriptaction + "?" + companyname + "--" + customername + "--" + customertype + "--" + phone + "--" + email + "--" + producttype
//	} // default
//	else { //not default
//		document.price.action = cgiscriptaction
//	}
//	
	// to stop duplicate orders - 9/8/2006 KR
	if (document.price.sendorder) {
		document.price.sendorder.disabled = true;
	    document.price.sendorder.value = "Sending Order..."
	}

	//document.price.orderNumber.value = (Math.round((Math.random()*999999999)+1))
	var now = Date.parse(new Date())+"";
	document.price.orderNumber.value = now.substr(0,10);
	//document.price.target="_self";
	document.price.submit();
	
//by Vu	
// Paypal Buy Now manipulating
//	document.paypal_form.action = "https://www.sandbox.paypal.com/us/cgi-bin/webscr";
//	document.paypal_form.business.value = "voodoo_1211318354_biz@hotmail.com";
//	document.paypal_form.item_number.value = document.price.orderNumber.value;
//	document.paypal_form.invoice.value = document.price.orderNumber.value;
//	document.paypal_form.item_name.value = "PrintFactoryDirect Printing Services";
//	document.paypal_form.amount.value = document.price.totalPrice.value;
////	document.paypal_form.handling.value = document.price.rushPrice.value;
////	document.paypal_form.shipping.value = document.price.shipPrice.value;
//
//	document.paypal_form.target="_blank";
//	document.paypal_form.submit();
	
//end of Paypal Buy Now button manupulating
	
}
