function getSearchToken( name ){
	var query = unescape( location.search.substring(1) );
	var pairs = query.split("&"); 
	var names = new Array(pairs.lenth);
	var x = 0;
	while ( x < pairs.length ){
		names[x] = pairs[x].split("=");
		if (names[x][0] == name){
			var result =names[x][1];
			return result;
		}
		x += 1;
	}
}
function CheckSearchString(){
	var y = unescape( location.search.substring(1) );
	//alert(y);
	if ( y.length > 1 ){
		// get the shipping costs and update the page
		var strShipping = getSearchToken("Shipping");
		if ( strShipping != null ){
			var txtShip = document.signquoteform["txtShipping"];
			txtShip.value = strShipping.substring(0, strShipping.indexOf(".")+3)
		}
		// get the additional costs and update the page
		var strAddCost = getSearchToken("AddCost");
		if ( strAddCost != null ){
			var txtAdd = document.signquoteform["txtAddCost"];
			txtAdd.value = strAddCost.substring(0, strAddCost.indexOf(".")+3)
		}
		// get the name and update the page
		var strName = getSearchToken("Name");
		if ( strName != null ){
			var txtName = document.signquoteform["Name"];
			txtName.value = strName;
		}
		// get the email and update the page
		var strEmail = getSearchToken("Email");
		if ( strEmail != null ){
			var txtEmail = document.signquoteform["Email"];
			txtEmail.value = strEmail;
		}
		// get the zipcode and update the page
		var strZipCode = getSearchToken("ZipCode");
		if ( strZipCode != null ){
			var txtZipCode = document.signquoteform["ZipCode"];
			txtZipCode.value = strZipCode;
		}
		// search for up to five "Items" in the search string
		var strItem1 = getSearchToken("Item1");
		if ( strItem1 != null ){
			 refillDataItem( strItem1, 1 );
		}
		var strItem2 = getSearchToken("Item2");
		if ( strItem2 != null ){
			 refillDataItem( strItem2, 2 );
		}
		var strItem3 = getSearchToken("Item3");
		if ( strItem3 != null ){
			 refillDataItem( strItem3, 3 );
		}
		var strItem4 = getSearchToken("Item4");
		if ( strItem4 != null ){
			 refillDataItem( strItem4, 4 );
		}
		var strItem5 = getSearchToken("Item5");
		if ( strItem5 != null ){
			 refillDataItem( strItem5, 5 );
		}
	}
	else{
		var strname = GetCookie("RSName");
		if ( strname != null ){
			var nameobj = getObject("Name");
			nameobj.value = strname;
		}
		var stremail = GetCookie("RSEmail");
		if ( stremail != null ){
			var emailobj = getObject("Email");
			emailobj.value = stremail;
		}
		var strzip = GetCookie("RSZipcode");
		if ( strzip != null ){
			var zipobj = getObject("ZipCode");
			zipobj.value = strzip;
		}
		var strphonenumber = GetCookie("RSPhoneNumber");
		if ( strphonenumber != null ){
			var phonenumberobj = getObject("PhoneNumber");
			phonenumberobj.value = strphonenumber;
		}

	}
}

function getCost(strItem){
	return strItem.substring( strItem.lastindexof("~",1) );
}

function getPlasticColor(strItem){
	var start = strItem.indexOf("~") +1 ;
	var end = strItem.lastIndexOf("~") -1;
	var pn = strItem.substring(start,end+1);
	var c = "";
	if ( pn != "WS" ){
		if ( pn.length > 8 ){
			if ( pn.substring(0,1) == "W"  ){
				c = "White";
			}
			if ( pn.substring(0,1) == "Y" ){
				c = "Yellow";
			}
		}
	}
	return c;
}

function getPartNumber(strItem){
	var start = strItem.indexOf("~") +1 ;
	var end = strItem.lastIndexOf("~") -1;
	var pn = strItem.substring(start,end+1);
	if ( pn != "WS" ){
		if ( pn.length > 8 ){
			if ( pn.substring(0,1) == "W" | pn.substring(0,1) == "Y" ){
				pn = pn.substring(1,9);
			}
		}
	}
	return pn;
}

function getColorCount(partnumber){
	if ( partnumber.length >=7 ){
		//var cc = partnumber.substring(4,5);
		//if ( cc = "P" | cc = "p" ) {
		//	return "5";
		//}
		//return cc;
		return partnumber.substring(4,5);
	}
}

function getSidesCount(partnumber){
	if ( partnumber.length >=7 ){
		return partnumber.substring(6,7);
	}
}
function getItemQuantity(strItem){
	var start = strItem.indexOf("~") +1 ;
	var end = strItem.lastIndexOf("~") -1;
	return strItem.substring(0,start-1);
}

function getSignSizeValue(partnumber){
		var h = partnumber.substring(0,2);
		var w = partnumber.substring(2,4);
		return h.toString() + w.toString();
}

function refillDataItem( strData, ctrlIndex ){
	var pn = getPartNumber(strData);
	//alert(pn);
	if ( pn.substring(0,2) != "WS" ){
		setSelectIndex(strData, "sProduct" + ctrlIndex, getSignSizeValue(pn) );	
		setSelectIndex(strData, "sSides" + ctrlIndex, getSidesCount(pn) );	
		setSelectIndex(strData, "sColors" + ctrlIndex, getColorCount(pn) );
		setSelectIndex(strData, "sPlastic" + ctrlIndex, getPlasticColor(strData) );
		var strText = getItemQuantity(strData);
		refillTextData(strText, "txtQuantity" + ctrlIndex );
		strText = getItemCost(strData);
		refillTextData(strText, "txtCostEach" + ctrlIndex );
		if ( isDirectional(strData) ){
			setDirectional( true, ctrlIndex );
		}
		
	}
	if ( pn.substring(0,2) == "WS" ){
		var strText = getItemQuantity(strData);
		refillTextData( strText, "standquantity" )
		strText = getItemCost(strData);
		refillTextData( strText, "standcost" )
	}
	if ( pn == "WS18" ) {
		setSelectIndex(strData, "sStandSize", "WS18");
	}
	total();
}

function setDirectional( boolChecked, ctrlIndex ){
	var chkDir = document.signquoteform["Directional" + ctrlIndex];
	if ( boolChecked ){
		chkDir.checked = true;
		return;
	}
	chkDir.checked = false;
}
function isDirectional(strItem){
	if ( strItem.indexOf("$D") != -1 ) { return true; }
	return false;
}

function getItemCost(strItem){
	var cost = strItem.substring(strItem.lastIndexOf("~")+1 )
	return cost.substring(0, cost.indexOf(".")+3 );
}

function setSelectIndex(strItem, ctrlName, strtofind){
	var pn = getPartNumber(strItem);
	if ( pn != "WS"){
		var x =0;	
		var selName = ctrlName;
		var sl = document.signquoteform[selName];
		while ( x < sl.options.length){
			if ( sl.options[x].value == strtofind ) {
				sl.selectedIndex = x;
				return x;
			}
			x += 1;
		}
	}
}

function refillTextData( strData, ctrlName ){
	var t = document.signquoteform[ctrlName];
	t.value = strData;
}

function total(){
	var x = 1;
	while ( x < 5 ){
		var unitcost = document.signquoteform["txtCostEach" + x].value;
		var unitTotal = document.signquoteform["txtExt" + x];
		var quantity = document.signquoteform["txtQuantity" + x].value;
		var t = parseFloat(unitcost) * parseFloat(quantity);
		unitTotal.value = t.toFixed(2);
		x += 1;
	}
	var unitcost = document.signquoteform["standcost"].value;
	var unitTotal = document.signquoteform["standsextended"];
	var quantity = document.signquoteform["standquantity"].value;
	var standcost = parseFloat(unitcost) * parseFloat(quantity);
	unitTotal.value = standcost.toFixed(2);
	
	var c1 = document.signquoteform["txtExt1"].value;
	var c2 = document.signquoteform["txtExt2"].value;
	var c3 = document.signquoteform["txtExt3"].value;
	var c4 = document.signquoteform["txtExt4"].value;
	var c5 = document.signquoteform["standsextended"].value;
	var c6 = document.signquoteform["txtShipping"].value;
	var c7 = document.signquoteform["txtAddCost"].value;
	var totalobj = document.signquoteform.txtTotal;
	var t = parseFloat(c1) + parseFloat(c2) + parseFloat(c3) + parseFloat(c4) + parseFloat(c5) + parseFloat(c6) + parseFloat(c7);
	totalobj.value = t.toFixed(2);
}

function getWidth(size){
	var firstspace = size.indexOf(" ");
	var w =  size.substring(0,firstspace-1);
	return w;
}

function getHeight(size){
	var firstspace = size.indexOf(" ");
	var h = size.substring((firstspace+3),size.length-1);
	return h;
}

function CanBeTwoSided(size){
	var w = getWidth(size);
	var h = getHeight(size);
	var ctrl = "sSides" + ctrlIndex;
	var sSideobj = document.getElementById(ctrl);
	if (((h > 48) || (w > 48)) || ( h == 48 && w == 48)){
		sSideobj.selectedIndex = 0
		if ( sSideobj.options.length >= 2 ){
			sSideobj.options.remove(1);
		}
	}else{
		if ( sSideobj.options.length < 2 ){
			newOpt  = document.createElement("OPTION");
			newOpt.text = "2 sides";
			sSideobj.options.add(newOpt);
		}
	}
} 

function getCtrlIndex(myCtrl){
	var nLen = myCtrl.id.length;
	ctrlIndex = myCtrl.id.substring(nLen-1,nLen);
	return ctrlIndex;
}


function chkDirectional_onclick(myCtrl) {
	getCtrlIndex(myCtrl);
	var hiddenboxobj = document.getElementById("Directional" + ctrlIndex);
	var chkDirectionalobj = document.getElementById("chkDirectional" + ctrlIndex);
	if ( chkDirectionalobj.checked )
	{
		hiddenboxobj.value = "1";
	}
	else
	{
		hiddenboxobj.value = "0";
	}
}

function txtQuantity_onChange(myCtrl){
	getCtrlIndex(myCtrl);
	var sQuantityobj = document.getElementById("txtQuantity" + ctrlIndex);
	if (isNaN(sQuantityobj.value)){	
		sQuantityobj.value = 0;
	}
	if ( sQuantityobj.value == null ) {sQuantityobj.value = 0;}
}

function sProduct_onclick(myCtrl) {
	getCtrlIndex(myCtrl);
	var size = myCtrl[myCtrl.selectedIndex].text.toLowerCase();

	if ( size.indexOf("select")== -1){
		CanBeTwoSided(size);
		CanBeProcess(size);
	}
}

function CanBeProcess(size){
	var w = getWidth(size);
	var h = getHeight(size);
	var ctrl = "sColors" + ctrlIndex ;
	var sColorobj = document.getElementById(ctrl);
	if (( h > 36) || (w > 36)){
		if( sColorobj.length >=4 ) {
			sColorobj.options.remove(4);
		}
	}else{
		if ( sColorobj.length < 5 ){
			newOpt  = document.createElement("OPTION");
			newOpt.text = "4 clr Process";
			sColorobj.options.add(newOpt);
		}
	}
}

function Validateform() {
var nameobj = getObject("Name");
var emailobj = getObject("Email");
var email = emailobj.value;
	if ( !validateEmail(emailobj.value) ){
		if ( getObject("imgEmailValid") != null ) {
			showImage("imgEmailValid", "images/Invalid.gif" );
			nameobj.focus();
			emailobj.focus();
			return false;
		}
		else{
			return true;  // no need to validate
		}
	}
	else {
		if ( getObject("imgEmailValid") != null ) {
			showImage("imgEmailValid", "images/BlankImage.gif");
 		}
		return true;
	}
}

function submitquote(){
	var nameobj = getObject("Name");
	if ( nameobj != null) {
		if (nameobj.value) { setNameCookie(nameobj.value) ; }
		var emailobj = getObject("Email");
		if (emailobj.value) { setEmailCookie(emailobj.value) ; }
		var zipobj = getObject("ZipCode");
		if (zipobj.value) { setZipcodeCookie(zipobj.value) ; }
		var phoneobj = getObject("PhoneNumber");
		if (phoneobj != null ){
			if (phoneobj.value) { setPhoneNumberCookie(phoneobj.value) ; }
		}
	}
	if ( Validateform() ){				
		if ( document.signquoteform.sSides1){
		document.signquoteform.sSides1.disabled = false;
		}
		if ( document.signquoteform.sSides2){
		document.signquoteform.sSides2.disabled = false;
		}
		if ( document.signquoteform.sSides3){
		document.signquoteform.sSides3.disabled = false;
		}
		if ( document.signquoteform.sSides4){
		document.signquoteform.sSides4.disabled = false;
		}
		document.signquoteform.submit();
	}
}

function setNameCookie(strname){
	if ( strname.length >= 1 ){
		//alert("strname = " + strname)
		//alert(getexpdate());
		var diedate = new Date();
		diedate = getexpdate();
		SetCookie("RSName", strname, diedate );
	}
}
function setZipcodeCookie(strzip){
	if ( strzip.length >= 1 ){
		SetCookie("RSZipcode", strzip, getexpdate() );
	}
}
function setEmailCookie(stremail){
	SetCookie("RSEmail", stremail, getexpdate() );
}
function setPhonenumberCookie(strphonenumber){
	if ( strzip.length >= 1 ){
		SetCookie("RSPhonenumber", strphonenumber, getexpdate() );
	}
}
function setPhoneNumberCookie(strphonenumber){
	SetCookie("RSPhoneNumber", strphonenumber, getexpdate() );
}



function getexpdate(){
	var expdate = new Date();
	expdate.setTime (expdate.getTime() + (30 * 24 * 60 * 60 * 1000 ));
	return expdate;
}

function setfirstfield(){
	sProduct_onclick(document.getElementById("sProduct1"));
	document.signquoteform.Name.focus();
}

function validateEmail(email){
	var emailRegEx = /^\w+([\.-]?\w+)*@\w+([\.-]?\w+)*\.(\w{2}|(com|net|org|edu|int|mil|gov|arpa|biz|aero|name|coop|info|pro|museum))$/
	if ( email.match(emailRegEx) != null ){
		return true;
	} else {
		return false;
	}
}


function showImage(imagename, imageurl ) {
var thisimg = getObject(imagename);
thisimg.src = imageurl;
}

//var emailRegEx = /^\w+([\.-]?\w+)*@\w+([\.-]?\w+)*\.(\w{2}|(com|net|org|edu|int|mil|gov|arpa|biz|aero|name|coop|info|pro|museum))$/
//var phoneRegEx = /^((\+\d{1,3}(-| )?\(?\d\)?(-| )?\d{1,3})|(\(?\d{2,3}\)?))(-| )?(\d{3,4})(-| )?(\d{4})(( x| ext)\d{1,5}){0,1}$/

// convert object name string or object reference
// into a valid object reference ready for style change
function getObject(obj) {
	var theObj;
	if (document.layers) {
		if (typeof obj == "string") {
			return document.layers[obj];
		} else {
			return obj;
		}
	}
	if (document.getElementById) {
		if (typeof obj == "string") {
			return document.getElementById(obj);
		} else {
			return obj;
		}
	}
	if (document.all) {
		if (typeof obj == "string") {
			return document.all(obj);
		} else {
			return obj;
		}
	}
	return null
}

//
// "Internal" function to return the decoded value of a cookie
//
function getCookieVal (offset) {
  var endstr = document.cookie.indexOf (";", offset);
  if (endstr == -1)
    endstr = document.cookie.length;
  return unescape(document.cookie.substring(offset, endstr));
}
//  Function to correct for 2.x Mac date bug.  Call this function to
//  fix a date object prior to passing it to SetCookie.
//  IMPORTANT:  This function should only be called *once* for
//  any given date object!  See example at the end of this document.
//
function FixCookieDate (date) {
  var base = new Date(0);
  var skew = base.getTime(); // dawn of (Unix) time - should be 0
  if (skew > 0)  // Except on the Mac - ahead of its time
    date.setTime (date.getTime() - skew);
}
//
//  Function to return the value of the cookie specified by "name".
//    name - String object containing the cookie name.
//    returns - String object containing the cookie value, or null if
//      the cookie does not exist.
//
function GetCookie (name) {
  var arg = name + "=";
  var alen = arg.length;
  var clen = document.cookie.length;
  var i = 0;
  while (i < clen) {
    var j = i + alen;
    if (document.cookie.substring(i, j) == arg)
      return getCookieVal (j);
	i = document.cookie.indexOf(" ", i) + 1;
    if (i == 0) break; 
  }
return null;
}
//  Function to create or update a cookie.
//    name - String object containing the cookie name.
//    value - String object containing the cookie value.  May contain
//      any valid string characters.
//    [expires] - Date object containing the expiration data of the cookie.  If
//      omitted or null, expires the cookie at the end of the current session.
//    [path] - String object indicating the path for which the cookie is valid.
//      If omitted or null, uses the path of the calling document.
//    [domain] - String object indicating the domain for which the cookie is
//      valid. If omitted or null, uses the domain of the calling document.
//    [secure] - Boolean (true/false) value indicating whether cookie transmission
//      requires a secure channel (HTTPS).  
//
//  The first two parameters are required.  The others, if supplied, must
//  be passed in the order listed above.  To omit an unused optional field,
//  use null as a place holder.  For example, to call SetCookie using name,
//  value and path, you would code:
//
//      SetCookie ("myCookieName", "myCookieValue", null, "/");
//
//  Note that trailing omitted parameters do not require a placeholder.
//
//  To set a secure cookie for path "/myPath", that expires after the
//  current session, you might code:
//
//      SetCookie (myCookieVar, cookieValueVar, null, "/myPath", null, true);
//
function SetCookie (name,value,expires,path,domain,secure) {
  document.cookie = name + "=" + escape (value) +
    ((expires) ? "; expires=" + expires.toGMTString() : "") +
    ((path) ? "; path=" + path : "") +
    ((domain) ? "; domain=" + domain : "") +
    ((secure) ? "; secure" : "");
}

function DeleteCookie (name,path,domain) {
  if (GetCookie(name)) {
    document.cookie = name + "=" +
      ((path) ? "; path=" + path : "") +
      ((domain) ? "; domain=" + domain : "") +
      "; expires=Thu, 01-Jan-70 00:00:01 GMT";
  }
}
<center>
<b>
This web site hosted by Rapid Signs, Inc. on WebServer 1
</b>
</center>

