﻿///////////////////////////////////////////
////   Quote Functions
/////////////////////////////////////////
function createCookie(name,value,days) {
	if (days) {
		var date = new Date();
		date.setTime(date.getTime()+(days*24*60*60*1000));
		var expires = "; expires="+date.toGMTString();
	}
	else var expires = "";
	document.cookie = name+"="+value+expires+"; path=/";
}
function readCookie(name) {
	var nameEQ = name + "=";
	var ca = document.cookie.split(';');
	for(var i=0;i < ca.length;i++) {
		var c = ca[i];
		while (c.charAt(0)==' ') c = c.substring(1,c.length);
		if (c.indexOf(nameEQ) == 0) return c.substring(nameEQ.length,c.length);
	}
	return null;
}
function eraseCookie(name) {
	createCookie(name,"",-1);
	setTimeout("location.reload(true);",0);
}
function removeItem(name) {
	alert(name);
}
function updateValues() {
	setTimeout("location.reload(true);",0);
}

function getQuoteTotal(name) {
	var cookieData = readCookie('quote');
  	if (cookieData) {	
		cookieData = cookieData.replace(/^\s+|\s+$/g, '') ;					
		// Split on | to get individual values into an array
		var items = cookieData.split('|');		
		// Get each array value (sku, description, qty, price)
		var total = 0;
		// Start from the second element ang get every fourth which is the qty of each SKU
		for(var i = 2; i < items.length; i += 4) {
			total += parseInt(items[i]);
		}
		
		if(total) {
			document.write('<h2>Items in Quote: ' + 
			'<span class="red">' + total + '</span>' +
			'</h2>');		
		}	
	}
}
function addQuote(sku, description, price, qty, refresh){
	strCookie = sku + "|" + description + "|" + qty + "|" + price;
  	var y = readCookie('quote');
	skuMatch = 0;
	if (y) { 
		y = y.replace(/^\s+|\s+$/g, '') ;	
		// Split on | to get individual values into an array
		var items = y.split('|');		
		// See if the sku already exists
		var i=0;
		while (i < items.length) {
			// If sku matches, update quantity 
			if (sku == items[i]){
				items[i+2]=qty;
				skuMatch = 1;
			}		
			i = i + 4;
		}		
		// Rewrite Cookie
		if (skuMatch == 1){
			var i=1;
			strCookie = items[0];
			while (i < items.length) {
			  strCookie = strCookie + "|" + items[i];
			  i = i + 1; 
			}
		}
		// Append Existing Cookie
		else {
			strCookie = y + "|" + strCookie;	
		}
		createCookie('quote',strCookie,0);
	} 
	else { 
		// Create New Cookie
		createCookie('quote',strCookie,0);
	}	
	// Refresh Quote Page
	if (refresh==1)
	{
			setTimeout("location.reload(true);",0);
	}
}
function addQuoteOption(sku, description, price, qty, refresh){
	QuantityValue= sku + "-Q";
	OptionValue=sku + "-O";
	strCookie = sku + "|" + description + " (Option: " + document.getElementById(OptionValue).value.toUpperCase() + ")" + "|" + document.getElementById(QuantityValue).value + "|" + price;
  	var y = readCookie('quote');
	skuMatch = 0;
	if (y) { 
		y = y.replace(/^\s+|\s+$/g, '') ;	
		// Split on | to get individual values into an array
		var items = y.split('|');		
		// See if the sku already exists
		var i=0;
		while (i < items.length) {
			// If sku matches, update quantity and description (includes option)
			if (sku == items[i]){
				items[i+2]=document.getElementById(QuantityValue).value;
				items[i+1]=description + " (Option: " + document.getElementById(OptionValue).value.toUpperCase() + ")";
				skuMatch = 1;
			}		
			i = i + 4;
		}		
		// Rewrite Cookie
		if (skuMatch == 1){
			var i=1;
			strCookie = items[0];
			while (i < items.length) {
			  strCookie = strCookie + "|" + items[i];
			  i = i + 1; 
			}
		}
		// Append Existing Cookie
		else {
			strCookie = y + "|" + strCookie;	
		}
		createCookie('quote',strCookie,0);
	} 
	else { 
		// Create New Cookie
		createCookie('quote',strCookie,0);
	}	
	// Refresh Quote Page
	if (refresh==1)
	{
			setTimeout("location.reload(true);",0);
	}
}
function addQuoteOptionENVIROMUXLDS(sku, description, price, qty, refresh){
	// document.tableform.watersensor.value) // x-value
	// document.tableform.wirecables.value) // y-value
	// document.tableform.ldsquantityQ.value) // quantity
	price = 51 + (9 * document.tableform.watersensor.value);
	strCookie = sku + "|" + description + ": " + document.tableform.watersensor.value + " Foot Water Sensor Cable (x-value) and " + document.tableform.wirecables.value + " Foot Wire Cable (y-value)" + "|" + document.tableform.ldsquantityQ.value + "|" + price;
  	var y = readCookie('quote');
	skuMatch = 0;
	if (y) { 
		y = y.replace(/^\s+|\s+$/g, '') ;	
		// Split on | to get individual values into an array
		var items = y.split('|');		
		// See if the sku already exists
		var i=0;
		while (i < items.length) {
			// If sku matches, update quantity, price and description (includes option)
			if (sku == items[i]){
				items[i+3]=price;
				items[i+2]=document.tableform.ldsquantityQ.value;
				items[i+1]=description + ": " + document.tableform.watersensor.value + " Foot Water Sensor Cable (x-value) and " + document.tableform.wirecables.value + " Foot Wire Cable (y-value)";
				skuMatch = 1;
			}		
			i = i + 4;
		}		
		// Rewrite Cookie
		if (skuMatch == 1){
			var i=1;
			strCookie = items[0];
			while (i < items.length) {
			  strCookie = strCookie + "|" + items[i];
			  i = i + 1; 
			}
		}
		// Append Existing Cookie
		else {
			strCookie = y + "|" + strCookie;	
		}
		createCookie('quote',strCookie,0);
	} 
	else { 
		// Create New Cookie
		createCookie('quote',strCookie,0);
	}	
	// Refresh Quote Page
	if (refresh==1)
	{
			setTimeout("location.reload(true);",0);
	}
}

function addQuoteOptionENVIROMUXLD(sku, description, price, qty, refresh){
	// document.tableform.watersensor.value) // x-value
	// document.tableform.wirecables.value) // y-value
	// document.tableform.ldquantityQ.value) // quantity
	price = 23 + (9 * document.tableform.watersensor.value);
	strCookie = sku + "|" + description + ": " + document.tableform.watersensor.value + " Foot Water Sensor Cable (x-value) and " + document.tableform.wirecables.value + " Foot Wire Cable (y-value)" + "|" + document.tableform.ldquantityQ.value + "|" + price;
  	var y = readCookie('quote');
	skuMatch = 0;
	if (y) { 
		y = y.replace(/^\s+|\s+$/g, '') ;	
		// Split on | to get individual values into an array
		var items = y.split('|');		
		// See if the sku already exists
		var i=0;
		while (i < items.length) {
			// If sku matches, update quantity, price and description (includes option)
			if (sku == items[i]){
				items[i+3]=price;
				items[i+2]=document.tableform.ldquantityQ.value;
				items[i+1]=description + ": " + document.tableform.watersensor.value + " Foot Water Sensor Cable (x-value) and " + document.tableform.wirecables.value + " Foot Wire Cable (y-value)";
				skuMatch = 1;
			}		
			i = i + 4;
		}		
		// Rewrite Cookie
		if (skuMatch == 1){
			var i=1;
			strCookie = items[0];
			while (i < items.length) {
			  strCookie = strCookie + "|" + items[i];
			  i = i + 1; 
			}
		}
		// Append Existing Cookie
		else {
			strCookie = y + "|" + strCookie;	
		}
		createCookie('quote',strCookie,0);
	} 
	else { 
		// Create New Cookie
		createCookie('quote',strCookie,0);
	}	
	// Refresh Quote Page
	if (refresh==1)
	{
			setTimeout("location.reload(true);",0);
	}
}

function addQuoteOptionENVIROMUXLDT(sku, description, price, qty, refresh){
	// document.tableform.watersensor.value) // x-value
	// document.tableform.wirecables.value) // y-value
	// document.tableform.ldtquantityQ.value) // quantity
	price = 23 + (9 * document.tableform.watersensor.value);
	strCookie = sku + "|" + description + ": " + document.tableform.watersensor.value + " Foot Water Sensor Cable (x-value) and " + document.tableform.wirecables.value + " Foot Wire Cable (y-value)" + "|" + document.tableform.ldtquantityQ.value + "|" + price;
  	var y = readCookie('quote');
	skuMatch = 0;
	if (y) { 
		y = y.replace(/^\s+|\s+$/g, '') ;	
		// Split on | to get individual values into an array
		var items = y.split('|');		
		// See if the sku already exists
		var i=0;
		while (i < items.length) {
			// If sku matches, update quantity, price and description (includes option)
			if (sku == items[i]){
				items[i+3]=price;
				items[i+2]=document.tableform.ldtquantityQ.value;
				items[i+1]=description + ": " + document.tableform.watersensor.value + " Foot Water Sensor Cable (x-value) and " + document.tableform.wirecables.value + " Foot Wire Cable (y-value)";
				skuMatch = 1;
			}		
			i = i + 4;
		}		
		// Rewrite Cookie
		if (skuMatch == 1){
			var i=1;
			strCookie = items[0];
			while (i < items.length) {
			  strCookie = strCookie + "|" + items[i];
			  i = i + 1; 
			}
		}
		// Append Existing Cookie
		else {
			strCookie = y + "|" + strCookie;	
		}
		createCookie('quote',strCookie,0);
	} 
	else { 
		// Create New Cookie
		createCookie('quote',strCookie,0);
	}	
	// Refresh Quote Page
	if (refresh==1)
	{
			setTimeout("location.reload(true);",0);
	}
}



function displayCookie(name){
	// Table Heading
	document.write('<table border="0"  align="center"><tr><td align="right">'); 
	document.write('<form name="formItems">');
	document.write('<table cellspacing="0" cellpadding="1" border="1" width="550">'); 
	document.write('<tr class="orange"><td colspan="5" align="center"><h2>Quote Request Contents</h2></td></tr>'); 
	document.write('<tr class="orange">'); 
	document.write('<td nowrap><b>Remove</b></td>'); 
	document.write('<td nowrap><b>NTI Part #</b></td>'); 
	document.write('<td nowrap><b>Description</b></td>'); 
	document.write('<td><b>Qty</b></td>'); 
	document.write('<td><b>List Price (Each)</b></td>'); 
	document.write('</tr>'); 
  	var y = readCookie(name);
  	if (y) {	
		y = y.replace(/^\s+|\s+$/g, '') ;					
		// Split on | to get individual values into an array
		var items = y.split('|');		
		// Get each array value (sku, description, qty, price) and display in table
		var i=0;
		var j=0;
		var itemno = 0;
		var itemsExist = 0;
		while (i < items.length) {
			var item = items[i];
			// Create New Record Cell?
			// Sku
			if (j==0) {
			  // Display if quantity is not equal to zero	
			  if (items[i+2]!=0){	
			  	document.write('<tr onMouseOver="this.bgColor=\'#ffffcc\';" onMouseOut="this.bgColor=\'\';">');
				document.write('<td>');
				document.write('<input type="checkbox" value="0" onClick="addQuote(\'' + items[i] +'\', \'' + items[i+1] + '\', \'' + items[i+2] + '\', \'0\', \'1\');">');
				document.write('</td><td nowrap align="left">');
			    document.write(item);
			    document.write('</td>');				
				itemsExist = 1;
			  }
			}
			// Description
			if (j==1) {
			  // Display if quantity is not equal to zero	
			  if (items[i+1]!=0){	
			    document.write('<td align="left">');
			    document.write(item);
			    document.write('</td>');
			  }
			}
			// Qty
			if (j==2) {
			  // Display if quantity is not equal to zero	
			  if (items[i]!=0){	
			  	document.write('<td align="left">');				  			 
			    document.write('<input name="item1" type="text" value="'+ items[i] +'" size="4" class="box-yellow" onChange="addQuote(\'' + items[i-2] +'\', \'' + items[i-1] + '\', \'' + items[i+1] + '\', this.value, \'0\');">');
			    document.write('</td>');
				itemno = itemno + 1;
			  }
			}	
			// Price	
			if (j==3) { 	
			  // Display if quantity is not equal to zero	
			  if (items[i-1]!=0){	
			    document.write('<td align="left">');
			    document.write(item);
			    document.write('</td>');
				document.write('</tr>');	
			  }					  		  
			}			
		j=j+1;
		// Reset j if end of record
		if (j==4) { 				
			  j=0;
		}
		i=i+1;
		}		
	}
	// Number of Items
	document.write('<input type="hidden" name="itemno" value="'+ itemno +'">');
	// Table Closing
	document.write('</table></form>');	
	if (itemsExist == 1){
		// Display Update and Clear Contents Button if Items exist
		document.write('<br><input type="button" name="update" value="Update Values" onClick="updateValues()">&nbsp;<input type="button" name="clear" value="Remove All" onClick="eraseCookie(\'quote\')">'); 
	}	
}
function formCookie(name){
	// Table Heading
  	var y = readCookie(name);
  	if (y) {	
		y = y.replace(/^\s+|\s+$/g, '') ;					
		// Split on | to get individual values into an array
		var items = y.split('|');		
		// Get each array value (sku, description, qty, price) and display in table
		var i=0;
		var j=0;
		var itemno = 0;
		var itemsExist = 0;
		while (i < items.length) {
			var item = items[i];
			// Create New Record Cell?
			// Sku
			if (j==0) {
			  // Add if quantity is not equal to zero	
			  if (items[i+2]!=0){	
			  	document.write('<input type="hidden" name="sku'+ itemno+'" value="'+ item +'">');	
				itemsExist = 1;
			  }
			}
			// Description
			if (j==1) {
			  // Add if quantity is not equal to zero	
			  if (items[i+1]!=0){	
			    document.write('<input type="hidden" name="description'+ itemno+'" value="'+ item +'">');			    
			  }
			}
			// Qty
			if (j==2) {
			  // Add if quantity is not equal to zero	
			  if (items[i]!=0){	
			    document.write('<input type="hidden" name="qty'+ itemno+'" value="'+ item +'">');				
			  }
			}	
			// Price	
			if (j==3) { 	
			  // Add if quantity is not equal to zero	
			  if (items[i-1]!=0){	
			    document.write('<input type="hidden" name="price'+ itemno+'" value="'+ item +'">');
				itemno = itemno + 1;
			  }					  		  
			}			
		j=j+1;
		// Reset j if end of record
		if (j==4) { 				
			  j=0;
		}
		i=i+1;
		}		
	}
	// Number of Items
	document.write('<input type="hidden" name="itemno" value="'+ itemno +'">');
}
///////////////////
/// Captcha Code
///////////////////
function ccode(){
wordid = "cword"; 
imagedir = "images/capform/";
wordfield = 15; 
randpic = (Math.floor(Math.random()*10))+1;
imageid = parseInt(randpic);
randomword = 
["alarm","mouse","share","guide","video","power","alert","ports","audio","cable"];
document.write("<table><tr><td><input type=\"text\" id=\"" + wordid + "\" name=\"" + wordid + "\" size=\"" +  wordfield + "\"></td>");
document.write("<td>&nbsp;<img src=\"" + decodeURIComponent(imagedir) + "cap-" + imageid + ".jpg\" width=\"100\" height=\"20\" alt=\"\"></td>");
document.write("<td>&nbsp;<a href=\"#\" onclick=\"playSound('images/capform/cap-"+imageid+".wav');\"><img src=\"images/audio.gif\" border=\"0\" alt=\"Play audio and enter the 5 letter word you hear.\" title=\"Play audio and enter the 5 letter word you hear.\"></a></td></tr></table>");
}
///////////////////
// Form Validation
///////////////////
function FormValidation (FormName, FormNameText) {
  ErrorString = "";
  // Check for Captcha Code 
  if (FormNameText == "formQuote") {
	  cwordentered = document.getElementById(wordid).value;
	  cword = cwordentered.toLowerCase();
	  if (cword==randomword[randpic-1]) {
	  }
	  else {
	  ErrorString = "Code incorrectly entered, please retry.";	
	  }
  }
  if (FormNameText == "formContact") {
	  cwordentered = document.getElementById(wordid).value;
	  cword = cwordentered.toLowerCase();
	  if (cword==randomword[randpic-1]) {
	  }
	  else {
	  ErrorString = "Code incorrectly entered, please retry.";	
	  }
  }
  if (FormNameText == "formFreecat") {
	  cwordentered = document.getElementById(wordid).value;
	  cword = cwordentered.toLowerCase();
	  if (cword==randomword[randpic-1]) {
	  }
	  else {
	  ErrorString = "Code incorrectly entered, please retry.";	
	  }
  }
  // Confirm valid email entered - formQuote
  if (FormNameText == "formQuote") {
	  AtPos = document.formQuote.email.value.indexOf("@")
	  StopPos = document.formQuote.email.value.lastIndexOf(".")
	  if (AtPos == -1 || StopPos == -1) {
	    ErrorString  = 'The email address entered is not a valid email address.'; 
	  }
	  if (StopPos < AtPos) {
	    ErrorString  = 'The email address entered is not a valid email address.'; 
	  }
	  if (StopPos - AtPos == 1) {
	    ErrorString  = 'The email address entered is not a valid email address.'; 
	  }
	  if (document.formQuote.email.value=="") {
	    ErrorString  = "";
	  }
	  // Check if email address was entered
	  if(document.formQuote.email.value=="") {
	    ErrorString = "Please Enter Your Email Address";
	  }
	  // Check that email address and confirmation email match
	  if(document.formQuote.email.value != document.formQuote.confirmemail.value) {
	    ErrorString = "Email Address and Confirmation Email Address Do Not Match";
	  }
  }
  // Confirm valid email entered - formContact
  if (FormNameText == "formContact") {
	  AtPos = document.formContact.email.value.indexOf("@")
	  StopPos = document.formContact.email.value.lastIndexOf(".")
	  if (AtPos == -1 || StopPos == -1) {
	    ErrorString  = 'The email address entered is not a valid email address.'; 
	  }
	  if (StopPos < AtPos) {
	    ErrorString  = 'The email address entered is not a valid email address.'; 
	  }
	  if (StopPos - AtPos == 1) {
	    ErrorString  = 'The email address entered is not a valid email address.'; 
	  }
	  if (document.formContact.email.value=="") {
	    ErrorString  = "";
	  }
	  // Check if email address was entered
	  if(document.formContact.email.value=="") {
	    ErrorString = "Please Enter Your Email Address";
	  }
  }
    // Confirm valid email entered - formFreecat
  if (FormNameText == "formFreecat") {
	  AtPos = document.formFreecat.email.value.indexOf("@")
	  StopPos = document.formFreecat.email.value.lastIndexOf(".")
	  if (AtPos == -1 || StopPos == -1) {
	    ErrorString  = 'The email address entered is not a valid email address.'; 
	  }
	  if (StopPos < AtPos) {
	    ErrorString  = 'The email address entered is not a valid email address.'; 
	  }
	  if (StopPos - AtPos == 1) {
	    ErrorString  = 'The email address entered is not a valid email address.'; 
	  }
	  if (document.formFreecat.email.value=="") {
	    ErrorString  = "";
	  }
	  // Check if email address was entered
	  if(document.formFreecat.email.value=="") {
	    ErrorString = "Please Enter Your Email Address";
	  }
  }
  // Confirm valid email entered - formEnvMgr
  if (FormNameText == "formEnvMgr") {
	  AtPos = document.formEnvMgr.email.value.indexOf("@")
	  StopPos = document.formEnvMgr.email.value.lastIndexOf(".")
	  if (AtPos == -1 || StopPos == -1) {
	    ErrorString  = 'The email address entered is not a valid email address.'; 
	  }
	  if (StopPos < AtPos) {
	    ErrorString  = 'The email address entered is not a valid email address.'; 
	  }
	  if (StopPos - AtPos == 1) {
	    ErrorString  = 'The email address entered is not a valid email address.'; 
	  }
	  if (document.formEnvMgr.email.value=="") {
	    ErrorString  = "";
	  }
	  // Check if email address was entered
	  if(document.formEnvMgr.email.value=="") {
	    ErrorString = "Please Enter Your Email Address";
	  }
	  // Check that email address and confirmation email match
	  if(document.formEnvMgr.email.value != document.formEnvMgr.confirmemail.value) {
	    ErrorString = "Email Address and Confirmation Email Address Do Not Match";
	  }
  }
  // Confirm valid email entered - formEnvEval
  if (FormNameText == "formEnvEval") {
	  AtPos = document.formEnvEval.email.value.indexOf("@")
	  StopPos = document.formEnvEval.email.value.lastIndexOf(".")
	  if (AtPos == -1 || StopPos == -1) {
	    ErrorString  = 'The email address entered is not a valid email address.'; 
	  }
	  if (StopPos < AtPos) {
	    ErrorString  = 'The email address entered is not a valid email address.'; 
	  }
	  if (StopPos - AtPos == 1) {
	    ErrorString  = 'The email address entered is not a valid email address.'; 
	  }
	  if (document.formEnvEval.email.value=="") {
	    ErrorString  = "";
	  }
	  // Check if email address was entered
	  if(document.formEnvEval.email.value=="") {
	    ErrorString = "Please Enter Your Email Address";
	  }
	  // Check that email address and confirmation email match
	  if(document.formEnvEval.email.value != document.formEnvEval.confirmemail.value) {
	    ErrorString = "Email Address and Confirmation Email Address Do Not Match";
	  }
  }
  // Confirm required fields entered - formEnvMgr
  if (FormNameText == "formEnvMgr" && ErrorString == "") {
	  if(document.formEnvMgr.fname.value=="") {
	    ErrorString = ErrorString + "First Name, ";
	  }
	  if(document.formEnvMgr.lname.value=="") {
	    ErrorString = ErrorString + "Last Name, ";
	  }
	  if(document.formEnvMgr.company.value=="") {
	    ErrorString = ErrorString + "Company, ";
	  }
	  if(document.formEnvMgr.company.value=="") {
	    ErrorString = ErrorString + "Address, ";
	  }
	  if(document.formEnvMgr.company.value=="") {
	    ErrorString = ErrorString + "City, ";
	  }
	  if(document.formEnvMgr.company.value=="") {
	    ErrorString = ErrorString + "Country, ";
	  }
	  if(document.formEnvMgr.serial.value=="") {
	    ErrorString = ErrorString + "ENVIROMUX Software Serial Number, ";
	  }
	  if(document.formEnvMgr.machineid.value=="") {
	    ErrorString = ErrorString + "Machine ID, ";
	  }
	  if(document.formEnvMgr.edition.value=="") {
	    ErrorString = ErrorString + "ENVIROMUX Software Edition, ";
	  }
	  if (ErrorString != "") {
	  	ErrorString = "Please enter values for: " + ErrorString;
		ErrorString = ErrorString.substring(0, ErrorString.length - 2);
	  }
  } 
  // Confirm required fields entered - formEnvEval
  if (FormNameText == "formEnvEval" && ErrorString == "") {
	  if(document.formEnvEval.fname.value=="") {
	    ErrorString = ErrorString + "First Name, ";
	  }
	  if(document.formEnvEval.lname.value=="") {
	    ErrorString = ErrorString + "Last Name, ";
	  }
	  if(document.formEnvEval.company.value=="") {
	    ErrorString = ErrorString + "Company, ";
	  }
	  if(document.formEnvEval.company.value=="") {
	    ErrorString = ErrorString + "Address, ";
	  }
	  if(document.formEnvEval.company.value=="") {
	    ErrorString = ErrorString + "City, ";
	  }
	  if(document.formEnvEval.company.value=="") {
	    ErrorString = ErrorString + "Country, ";
	  }
	  if(document.formEnvEval.phone.value=="") {
	    ErrorString = ErrorString + "Phone, ";
	  }
	  if(document.formEnvEval.howmany.value=="") {
	    ErrorString = ErrorString + "Number of ENVIROMUX-SEMS-16's to Manage, ";
	  }
	  if (ErrorString != "") {
	  	ErrorString = "Please enter values for: " + ErrorString;
		ErrorString = ErrorString.substring(0, ErrorString.length - 2);
	  }
  } 
  // Confirm user agreed to EULA - formEnvMgr
    if (FormNameText == "formEnvMgr") {
	  for (var i=0; i < document.formEnvMgr.eula.length; i++) { 
	  		if (document.formEnvMgr.eula[i].checked) { 
				var rad_val = document.formEnvMgr.eula[i].value; 
			} 
	   } 
	  if(rad_val=="no") {
	    ErrorString = "You Must Agree to the End User License Agreement to Submit your License Request";
	  }	   
  }
  // Confirm user agreed to EULA - formEnvMgr
    if (FormNameText == "formEnvEval") {
	  for (var i=0; i < document.formEnvEval.eula.length; i++) { 
	  		if (document.formEnvEval.eula[i].checked) { 
				var rad_val = document.formEnvEval.eula[i].value; 
			} 
	   } 
	  if(rad_val=="no") {
	    ErrorString = "You Must Agree to the End User License Agreement to Submit your Evaluation Request";
	  }	   
  }
  // Display error is there one, otherwise submit the form
  if (ErrorString != "") {
  	alert (ErrorString);
  }
  if (ErrorString == "") {
    FormName.submit();
  }
}
///////////////////////////////////////////
////   Help Functions
///////////////////////////////////////////
function writeHelp(layername){
// Get String to Write
if (layername == "serialhelp") { 
  msgstring="<br><table border=\"0\" width=\"500\" align=\"center\" cellspacing=\"2\" cellpadding=\"2\" bgcolor=\"#cccccc\"><tr bgcolor=\"#ffffff\"><td class=\"med-text\"><br>Your ENVIROMUX Management Software serial number is available in the order confirmation email.<br><br><div align=\"right\"><a href=\"javascript:writeHelp('serialhelp-close');\">Close</a>&nbsp;&nbsp;</td></tr></table></div><br>";	 
} 
if (layername == "serialhelp-close") { 
  msgstring=""; 
  layername="serialhelp"; 
} 
if (layername == "machineidhelp") { 
  msgstring="<br><table border=\"0\" width=\"500\" align=\"center\" cellspacing=\"2\" cellpadding=\"2\" bgcolor=\"#cccccc\"><tr bgcolor=\"#ffffff\"><td class=\"med-text\"><br>To obtain the Machine ID, open the Server software to the main menu, click on the “Help” link, then click on the “Install License” tab. The Machine ID is shown as the first item listed.<br><br><div align=\"center\"><img src=\"images/enviro-ms-menu.jpg\" alt=\"Main Menu Screen\"><br><br><img src=\"images/enviro-ms-activate.jpg\" alt=\"License Activation Screen\"></div><br><br><div align=\"right\"><a href=\"javascript:writeHelp('machineidhelp-close');\">Close</a>&nbsp;&nbsp;</td></tr></table></div><br>";	 
} 
if (layername == "machineidhelp-close") { 
  msgstring=""; 
  layername="machineidhelp"; 
} 
// Write to Layer
if(document.layers){
  //Browser="NN4";
  textlayer = document.layers[layername];
  textlayer.document.open();
  textlayer.document.write(msgstring);
  textlayer.document.close();  
}
if(document.all){
  //Browser="IE"
  textlayer = document.all[layername];
  textlayer.innerHTML=msgstring;  
}
if(document.getElementById){
  //Browser="NN6+";
  textlayer = document.getElementById(layername);
  textlayer.innerHTML =msgstring;
}     
} 
///////////////////////////////////////////
////   ENVIROMUX-LDSx-y Option Functions
//////////////////////////////////////////
function InitCable() {
  document.tableform.watersensor.value = '1';
  document.tableform.wirecables.value = '5';
}
function SaveFormData (Value) {
  SavedValue = Value;
}
function CableSelect (){ 
  // Write New Price
  write_layer('ldsprice');
  // Write New Options
  write_layer('ldsoptions');
}
function VerifyNumericRange (FieldName, EnteredValue) {
ErrorString = "";
// Check if numeric value has been entered
var NumericExpression = /^[0-9]+$/; 
if(EnteredValue.match(NumericExpression)){
  if (FieldName == "ldsquantity"){
      // Write New Options
	  write_layer('ldsoptions');
  }  
}
  else // Non-numeric values have been entered
  { 
  ErrorString = 'Only Numeric Values may be entered for this field.';
  }
// Replaced with original value if there is an error
if (ErrorString != "") {
  alert (ErrorString); 
  if (FieldName == "ldsquantity")
    document.tableform.ldsquantity.value = SavedValue;
  // Reset Error String
  ErrorString = "";
  }
}
function write_layer(layername){
// Write Price
if (layername == "ldsprice") { 
  // Get New Price
  Price = 51 + (9 * document.tableform.watersensor.value);
  msgstring=Price;		  
  // Write to Layer
    if(document.layers){
  	//Browser="NN4";
 	textlayer = document.layers[layername];
 	textlayer.document.open();
 	textlayer.document.write(msgstring);
 	textlayer.document.close();  
 	}
  	if(document.all){
 	//Browser="IE"
 	textlayer = document.all[layername];
 	textlayer.innerHTML=msgstring;  
 	}
 	if(document.getElementById){
 	//Browser="NN6+";
 	textlayer = document.getElementById(layername);
 	textlayer.innerHTML =msgstring;
 	}   
}   
// Write Option Values
if (layername == "ldsoptions") { 
  // Quantity
  document.tableform.ldsquantityweb.value = document.tableform.ldsquantity.value; 
  // Water Sensor Cable Option  
  document.tableform.watersensorweb.value = "watcble" + document.tableform.watersensor.value;
  // Wire Cable Option
  document.tableform.wirecablesweb.value = "wirecble" + document.tableform.wirecables.value;
}   
}  
///////////////////////////////////////////
////   ENVIROMUX-LDx-y Option Functions
//////////////////////////////////////////
function InitCableLD() {
  document.tableform.watersensor.value = '1';
  document.tableform.wirecables.value = '5';
}
function CableSelectLD (){ 
  // Write New Price
  write_layer2('ldprice');
  // Write New Options
  write_layer2('ldoptions');
}
function VerifyNumericRangeLD (FieldName, EnteredValue) {
ErrorString = "";
// Check if numeric value has been entered
var NumericExpression = /^[0-9]+$/; 
if(EnteredValue.match(NumericExpression)){
  if (FieldName == "ldquantity"){
      // Write New Options
	  write_layer2('ldoptions');
  }  
}
  else // Non-numeric values have been entered
  { 
  ErrorString = 'Only Numeric Values may be entered for this field.';
  }
// Replaced with original value if there is an error
if (ErrorString != "") {
  alert (ErrorString); 
  if (FieldName == "ldquantity")
    document.tableform.ldquantity.value = SavedValue;
  // Reset Error String
  ErrorString = "";
  }
}
function write_layer2(layername){
// Write Price
if (layername == "ldprice") { 
  // Get New Price
  Price = 23 + (9 * document.tableform.watersensor.value);
  msgstring=Price;		  
  // Write to Layer
    if(document.layers){
  	//Browser="NN4";
 	textlayer = document.layers[layername];
 	textlayer.document.open();
 	textlayer.document.write(msgstring);
 	textlayer.document.close();  
 	}
  	if(document.all){
 	//Browser="IE"
 	textlayer = document.all[layername];
 	textlayer.innerHTML=msgstring;  
 	}
 	if(document.getElementById){
 	//Browser="NN6+";
 	textlayer = document.getElementById(layername);
 	textlayer.innerHTML =msgstring;
 	}   
}   
// Write Option Values
if (layername == "ldoptions") { 
  // Quantity
  document.tableform.ldquantityweb.value = document.tableform.ldquantity.value; 
  // Water Sensor Cable Option  
  document.tableform.watersensorweb.value = "watcble" + document.tableform.watersensor.value;
  // Wire Cable Option
  document.tableform.wirecablesweb.value = "wirecble" + document.tableform.wirecables.value;
}   
}  

///////////////////////////////////////////
////   ENVIROMUX-LDTx-y Option Functions
//////////////////////////////////////////
function InitCableLDT() {
  document.tableform.watersensor.value = '1';
  document.tableform.wirecables.value = '5';
}
function CableSelectLDT (){ 
  // Write New Price
  write_layer3('ldtprice');
  // Write New Options
  write_layer3('ldtoptions');
}
function VerifyNumericRangeLDT (FieldName, EnteredValue) {
ErrorString = "";
// Check if numeric value has been entered
var NumericExpression = /^[0-9]+$/; 
if(EnteredValue.match(NumericExpression)){
  if (FieldName == "ldtquantity"){
      // Write New Options
	  write_layer3('ldtoptions');
  }  
}
  else // Non-numeric values have been entered
  { 
  ErrorString = 'Only Numeric Values may be entered for this field.';
  }
// Replaced with original value if there is an error
if (ErrorString != "") {
  alert (ErrorString); 
  if (FieldName == "ldtquantity")
    document.tableform.ldtquantity.value = SavedValue;
  // Reset Error String
  ErrorString = "";
  }
}
function write_layer3(layername){
// Write Price
if (layername == "ldtprice") { 
  // Get New Price
  Price = 23 + (9 * document.tableform.watersensor.value);
  msgstring=Price;		  
  // Write to Layer
    if(document.layers){
  	//Browser="NN4";
 	textlayer = document.layers[layername];
 	textlayer.document.open();
 	textlayer.document.write(msgstring);
 	textlayer.document.close();  
 	}
  	if(document.all){
 	//Browser="IE"
 	textlayer = document.all[layername];
 	textlayer.innerHTML=msgstring;  
 	}
 	if(document.getElementById){
 	//Browser="NN6+";
 	textlayer = document.getElementById(layername);
 	textlayer.innerHTML =msgstring;
 	}   
}   
// Write Option Values
if (layername == "ldtoptions") { 
  // Quantity
  document.tableform.ldtquantityweb.value = document.tableform.ldtquantity.value; 
  // Water Sensor Cable Option  
  document.tableform.watersensorweb.value = "watcble" + document.tableform.watersensor.value;
  // Wire Cable Option
  document.tableform.wirecablesweb.value = "wirecble" + document.tableform.wirecables.value;
}   
}  
///////////////////////////////////////////
////   Option Functions
//////////////////////////////////////////
function optionQty (option, qty)
{
	document.getElementById(option).value=qty;
}
