<!--

quotenbr = 0;
quoteadded = 'N';
var xmlHttp;
var resdiv = null;
var notfound;
var ziptype;
var citytype;

// Trim trailing blanks in a field
function trim(field)
{
	while(field.charAt(field.length-1)==' ')
	{
	 field=field.substring(0,field.length-1);
	}
	return field;
}

// Compare country codes to ensure they are different thus a cross border request
function checkCrossBorder(frCountry, toCountry)
{
		if (frCountry == toCountry)
		{
			document.getElementById("ToZip").focus();
			document.getElementById("ToZip").select();
			document.getElementById("ToCity").value = ' ';
			document.getElementById("ToState").selectedIndex = 0;
			document.getElementById("next").disabled = true;
			alert('Origin & Destination must cross Canada/US Border');
			return false;
		}
		else 
		{
			document.getElementById("next").disabled = false;
			return true;
		}
}

// Ajax request Wrapper
function getAjax(div, url)
{
  	xmlHttp = null;
  	if (div == 'none')
  	{
  		resdiv = 'none'
  	}
  	else
  	{
  		resdiv = document.getElementById(div);
  	}
	xmlHttp = GetXmlHttpObject();
  	xmlHttp.onreadystatechange = updatePage;
  	xmlHttp.open("GET", url, true);
  	xmlHttp.setRequestHeader("If-Modified-Since", "Sat, 1 Jan 2000 00:00:00 GMT");
  	xmlHttp.send(null);
  	
  
}
function GetXmlHttpObject() {

  	var objXMLHttp=null;
  	if (window.XMLHttpRequest) {
    	objXMLHttp=new XMLHttpRequest();
  	}
  	else if (window.ActiveXObject) {
   		objXMLHttp=new ActiveXObject("Microsoft.XMLHTTP");
  	}

return objXMLHttp;

}

function updatePage() 
{
  	if (xmlHttp.readyState == 4) 
  	{
    	if (xmlHttp.status == 200) 
    	{
    		var response = xmlHttp.responseText;
    		if (resdiv != null && resdiv != 'none' &&  resdiv.id != 'error')
    		{
      			resdiv.innerHTML = response;
      			resdiv.style.visibility = 'visible';
      			document.getElementById("resultdivwait").style.visibility = 'hidden';
      		}
      		else if (resdiv.id == 'error')
      		{
   				checkResponse(response);
      		}
    	}
  	}
}

// This function checks the Ajax response and 
function checkResponse(response)
{
 
	if (document.getElementById)
	{
		var refresh = document.getElementById("refresh").value;
	}
	else if (document.all)
	{
		var refresh = document.all("refresh").value;
	}
			if (response.substring(0,9) == 'NOT FOUND')
			{
				
		    		if (ziptype == 'Origin')
					{
						alert ('From Zipcode not found on file');
						document.frmQuoteReq.FromZip.focus();
						document.frmQuoteReq.FromZip.select();
						notfound = 'N';
						document.getElementById("next").disabled = true;
						return false;
					}
					else if (ziptype == 'Dest')
					{
						alert ('To Zipcode not found on file');
						document.frmQuoteReq.ToZip.focus();
						document.frmQuoteReq.ToZip.select();
						document.getElementById("next").disabled = true;
						notfound = 'N';
						return false;
					}
					else if (citytype == 'Origin')
					{
						alert ('Origin City not found on file');
						document.frmQuoteReq.FromCity.focus();
						document.frmQuoteReq.FromCity.select();
						document.getElementById("next").disabled = true;
						notfound = 'N';
						return false;
					}
					//else if (citytype == 'Dest')
					else
					{
						alert ('To City not found on file');
						document.frmQuoteReq.ToCity.focus();
						document.frmQuoteReq.ToCity.select();
						document.getElementById("next").disabled = true;
						notfound = 'N';
						return false;
					}
			}
			else if (response.substring(0,11) == 'Not Entered')
			{
				if (refresh != 'Y')
				{
		    		if (ziptype == 'Origin')
					{
						alert ('Please enter a Postal Code or City/State.');
						document.frmQuoteReq.FromZip.focus();
						document.frmQuoteReq.FromZip.select();
						notfound = 'N';
						return false;
					}
					else if (ziptype == 'Dest')
					{
						alert ('Please enter a Postal Code or City/State.');
						document.frmQuoteReq.ToZip.focus();
						document.frmQuoteReq.ToZip.select();
						notfound = 'N';
						return false;
					}
					else if (citytype == 'Origin')
					{
						alert ('Please enter a Postal Code or City/State.');
						document.frmQuoteReq.ToCity.focus();
						document.frmQuoteReq.ToCity.select();
						notfound = 'N';
						return false;
					}
					else if (citytype == 'Dest')
					
					{
						alert ('Please enter a Postal Code or City/State.');
						document.frmQuoteReq.FromCity.focus();
						document.frmQuoteReq.FromCity.select();
						notfound = 'N';
						return false;
					}
				}
			}
			else
			{
					if (ziptype == 'Origin')
					{
						city = response.substring(8,28);
						city = trim(city);
						document.frmQuoteReq.FromCity.value = city;
						document.frmQuoteReq.FromCtry.value = response.substring(33,35);
						var state = response.substring(6,8);
						objSelect = document.getElementById("FromState");
						for (var i=0;i<objSelect.options.length;i++){
							if (objSelect.options[i].value==state)
							{
								objSelect.selectedIndex = i;
								break;
							}
						}
						fctry = response.substring(33,35);
						var toctry = document.getElementById("ToCtry").value;
						var xborder = checkCrossBorder(fctry, toctry);
						return xborder;
					}
					else if (ziptype == 'Dest')
					{
						city = response.substring(8,28);
						city = trim(city);
						document.frmQuoteReq.ToCity.value = city;
						document.frmQuoteReq.ToCtry.value = response.substring(33,35);
						state = response.substring(6,8);
						objSelect = document.getElementById("ToState");
						for (i=0;i<objSelect.options.length;i++){
							if (objSelect.options[i].value==state)
							{
								objSelect.selectedIndex = i;
								break;
							}
						}
						toctry = response.substring(33,35);
						var fctry = document.getElementById("FromCtry").value;
						var xborder = checkCrossBorder(fctry, toctry);
						return xborder;
					}
					else if (citytype == 'Origin')
					{
						document.frmQuoteReq.FromZip.value = response.substring(0,6);	
						document.frmQuoteReq.FromCtry.value = response.substring(33,35);
						fctry = response.substring(33,35);
						var toctry = document.getElementById("ToCtry").value;
						var xborder = checkCrossBorder(fctry, toctry);
						return xborder;
					}
					else if (citytype = 'Dest')
					{
						document.frmQuoteReq.ToZip.value = response.substring(0,6);
						document.frmQuoteReq.ToCtry.value = response.substring(33,35);
						toctry = response.substring(33,35);
						fctry = document.getElementById("FromCtry").value;
						xborder = checkCrossBorder(fctry, toctry);
						return xborder;
					}
			}
			return;
					
}

function crtStep1(refresh)
{
	if (document.getElementById)
	{
		var createQuote = document.getElementById("create").value;
		if (createQuote == 'Y')
		{
			//document.getElementById("create").value = 'N';
			var userid = document.getElementById("email").value;
			var orgcity = document.getElementById("FromCity").value;
			var orgste = document.getElementById("FromState").value;
			var orgzip = document.getElementById("FromZip").value;
			var destcity = document.getElementById("ToCity").value;
			var destste = document.getElementById("ToState").value;
			var destzip = document.getElementById("ToZip").value;
			var first = 'N';
		 
			var quote = document.getElementById("quotenbr").value;
				if (refresh != 'Y')
				{
					var action = 'Create';
				}
				else 
				{
					var action = 'UPDHDR';
				}
			var Url = "/webaccessp/Quotation1.pgm?Quote=" + encodeURIComponent(quote) + 
			'&Orgcity=' + encodeURIComponent(orgcity) +
			'&OrgState=' + encodeURIComponent(orgste) +
			'&Orgzip=' + encodeURIComponent(orgzip) +
			'&Descity=' + encodeURIComponent(destcity) +
			'&DesState=' + encodeURIComponent(destste) +
			'&Deszip=' + encodeURIComponent(destzip) +
			'&email=' + encodeURIComponent(userid) +
			'&first=' + encodeURIComponent(first) +
		 	'&action=' + encodeURIComponent(action);
			getAjax('none', Url); 
		}
	}
	else if (document.all)
	{
		var createQuote = document.all("create").value;
		if (createQuote == 'Y')
		{
			//document.all("create").value = 'N';
			var userid = document.all("email").value;
			var orgcity = document.all("FromCity").value;
			var orgste = document.all("lstFromState").value;
			var orgzip = document.all("FromZip").value;
			var destcity = document.all("ToCity").value;
			var destste = document.all("lstToState").value;
			var destzip = document.all("ToZip").value;
			var first = 'N';
			 
			var quote = document.all("quotenbr").value;
			if (refresh != 'Y')
				{
					var action = 'Create';
				}
				else 
				{
					var action = 'UPDHDR';
				}
			var Url = "/webaccessp/Quotation1.pgm?Quote=" + encodeURIComponent(quote) + 
			'&Orgcity=' + encodeURIComponent(orgcity) +
			'&OrgState=' + encodeURIComponent(orgste) +
			'&Orgzip=' + encodeURIComponent(orgzip) +
			'&Descity=' + encodeURIComponent(destcity) +
			'&DesState=' + encodeURIComponent(destste) +
			'&Deszip=' + encodeURIComponent(destzip) +
			'&email=' + encodeURIComponent(userid) +
			'&first=' + encodeURIComponent(first) +
			'&action=' + encodeURIComponent(action);
			getAjax('none', Url); 
		}
	}	
}

function crtStep2(line, frtclss, qty, desc, createline, update)
{ 
	if (document.getElementById)
	{
		document.getElementById(createline);
		var create = createline.value;
		if (create == 'Y')
		{
			//document.getElementById(createline);
			//createline.value = 'N';
	  		var userid = document.getElementById("email").value;
	 		var first = 'N';
	 		if (update == 'N')
	 		{
	 			var action = 'Addlin';
	 		}
	 		else 
	 		{
	 			var action = 'Updlin';
	 		}
			var quote = document.getElementById("quotenbr").value;
			document.getElementById(line);
			var linenum = line.value;
			document.getElementById(frtclss);
			var frtClass = frtclss.value;
			document.getElementById(qty);
			var qty = qty.value;
			document.getElementById(desc);
			var desc = desc.value;
	    	var Url = "/webaccessp/Quotation1.pgm?quote=" + encodeURIComponent(quote) + '&linenum=' + encodeURIComponent(linenum) +
			'&frtclass=' + encodeURIComponent(frtClass) +
			'&qty=' + encodeURIComponent(qty) +
			'&desc=' + encodeURIComponent(desc) +
			'&action=' + encodeURIComponent(action) +
			'&first=' + encodeURIComponent(first) +
			'&email=' + encodeURIComponent(userid);
			getAjax('none', Url);
			
		}
	}
	else if (document.all)
	{
		document.all(createline);
		var create = createline.value;
		if (create == 'Y')
		{
			//document.all(createline).value = 'N';
	  		var userid = document.all("email").value;
	  		
	 		var first = 'N';
	 		if (update == 'N')
	 		{
	 			var action = 'Addlin';
	 		}
	 		else 
	 		{
	 			var action = 'Updlin';
	 		}
	 		
			var quote = document.all("quotenbr").value;
			document.all(line);
			var linenum = line.value;
			document.all(frtclss);
			var frtClass = frtclss.value;
			document.all(qty);
			var qty = qty.value;
			document.all(desc);
			var desc = desc.value;
	    	var Url = "/webaccessp/Quotation1.pgm?quote=" + encodeURIComponent(quote) + '&linenum=' + encodeURIComponent(linenum) +
			'&frtclass=' + encodeURIComponent(frtClass) +
			'&qty=' + encodeURIComponent(qty) +
			'&desc=' + encodeURIComponent(desc) +
			'&action=' + encodeURIComponent(action) +
			'&first=' + encodeURIComponent(first) +
			'&email=' + encodeURIComponent(userid);
			getAjax('none', Url);
		}
	}
		
}
function getQuote()
{
	if (document.getElementById)
	{
		var userid = document.getElementById("email").value;
		if (document.getElementById("PGP").checked)
		{ var pgp = document.getElementById("PGP").value;}
		else { var pgp = ' ' }
		if (document.getElementById("IND").checked)
		{ var ind = document.getElementById("IND").value;}
		else { var ind = ' ' }
		if (document.getElementById("RSD").checked)
		{ var rsd = document.getElementById("RSD").value;}
		else { var rsd = ' ' } 
		if (document.getElementById("RSP").checked)
		{ var rsp = document.getElementById("RSP").value;}
		else { var rsp = ' ' } 
		if (document.getElementById("PGD").checked)
		{ var pgd = document.getElementById("PGD").value;}
		else { var pgd = ' ' } 
		if (document.getElementById("APPT").checked)
		{ var appt = document.getElementById("APPT").value;}
		else { var appt = ' ' }  
		if (document.getElementById("HAZ").checked)
		{ var haz = document.getElementById("HAZ").value;}
		else { var haz = ' ' } 
		var quote = document.getElementById("quotenbr").value;
		document.getElementById("submit").value = 'Recalculate';
		document.getElementById("refresh").value = 'Y';
	}
	else if(document.all)
	{
		var userid = document.all("email").value;
		if (document.all("PGP").checked)
		{ var pgp = document.all("PGP").value;}
		else { var pgp = ' ' }
		if (document.all("IND").checked)
		{ var ind = document.all("IND").value;}
		else { var ind = ' ' }
		if (document.all("RSD").checked)
		{ var rsd = document.all("RSD").value;}
		else { var rsd = ' ' } 
		if (document.all("RSP").checked)
		{ var rsp = document.all("RSP").value;}
		else { var rsp = ' ' } 
		if (document.all("PGD").checked)
		{ var pgd = document.all("PGD").value;}
		else { var pgd = ' ' } 
		if (document.all("APPT").checked)
		{ var appt = document.all("APPT").value;}
		else { var appt = ' ' }  
		if (document.all("HAZ").checked)
		{ var haz = document.all("HAZ").value;}
		else { var haz = ' ' } 
		var quote = document.all("quotenbr").value;
		document.all("submit").value = 'Recalculate';
		document.all("refresh").value = 'Y';
	}
	 	var first = 'N';
	 	var action = 'Finish';
		
		var Url = "/webaccessp/Quotation1.pgm?quote=" + encodeURIComponent(quote) +
		'&action=' + encodeURIComponent(action) +
		'&first=' + encodeURIComponent(first) +
		'&pgp=' + encodeURIComponent(pgp) +
		'&ind=' + encodeURIComponent(ind) +
		'&rsd=' + encodeURIComponent(rsd) +
		'&rsp=' + encodeURIComponent(rsp) +
		'&pgd=' + encodeURIComponent(pgd) +
		'&appt=' + encodeURIComponent(appt) +
		'&haz=' + encodeURIComponent(haz) +
		
		'&email=' + encodeURIComponent(userid);
		getAjax('resultdiv', Url);
		
		
		//document.getElementById("submit").style.visibility = 'hidden';
}
function showField(el)
{
	if (document.getElementById)
	{
		document.getElementById(el);
		el.style.visibility = 'visible';
	}
	else if (document.all)
	{
		document.all(el);
		el.style.visibility = 'visible';
	}
}
function checkValid(fieldvalue)
{
	if (isNaN(fieldvalue))
	{
		return true;
	}			
	else {
		if (fieldvalue.indexOf(" ") >= 0)
		{
		return true;
		}
	}
}
function checkInput1()
	{
	 	if (document.getElementById)
		{
			email = document.getElementById("email").value;
		}
		else if (document.all)
		{
			email = document.all("email").value;
		}
		if (email.length > 0 && email == " " || email.length > 0 && email.indexOf('@') == -1 || email.length > 0 && email.indexOf('.') == -1 || email.length < 1)
		{
			alert ('Please enter a valid e-mail address');
			document.frmQuoteReq.email.focus();
			document.frmQuoteReq.email.select();
			
			return false;
		}
		
		showField(formdiv);
		document.frmQuoteReq.txtFromZip.focus();
		return true;
}
function checkInput2()
	{
	 	if (document.getElementById)
		{
			var orgcity = document.getElementById("FromCity").value;
			var orgzip = document.getElementById("FromZip").value;
			var orgstate = document.getElementById("FromState").value;
			var descity = document.getElementById("ToCity").value;
			var deszip = document.getElementById("ToZip").value;
			var desstate = document.getElementById("ToState").value;
			var refresh = document.getElementById("Refresh").value;
		}
		else if (document.all)
		{
			var orgcity = document.all("FromCity").value;
			var orgzip = document.all("FromZip").value;
			var orgstate = document.all("FromState").value;
			var descity = document.all("ToCity").value;
			var deszip = document.all("ToZip").value;
			var desstate = document.all("ToState").value;
			var refresh = document.all("Refresh").value;
		}
		foundspace = orgcity.lastIndexOf(" ");
		foundspace1 = orgzip.lastIndexOf(" ");
		foundspace2 = descity.lastIndexOf(" ");
		foundspace3 = deszip.lastIndexOf(" ");
		
		if (orgcity.length == 0 && orgzip.length == 0)
		{
			alert ('You must enter an origin City OR Zipcode!');
			document.frmQuoteReq.FromZip.focus();
			document.frmQuoteReq.FromZip.select();
			return false;
		}
		
		//if (orgcity.length > 0 && orgzip.length > 0)
		//{
		//	alert ('You can only enter a City OR Zipcode, not both!');
		//	document.frmQuoteReq.FromZip.focus();
		//	document.frmQuoteReq.FromZip.select();
		//	document.frmQuoteReq.FromCity.value = '';
		//	return false;
		//}
		
		if (orgcity.length > 0 && foundspace != -1 && foundspace <= 2) 
		{
			alert ('Please enter an valid origin city.');
			document.frmQuoteReq.FromCity.focus();
			document.frmQuoteReq.FromCity.select();
			return false;
		}
		if (orgzip.length > 0 && foundspace1 != -1 && foundspace1 <= 2) 
		{
			alert ('Please enter valid origin postal code.');
			document.frmQuoteReq.FromZip.focus();
			document.frmQuoteReq.FromZip.select();
			return false;
		}
		if (descity.length == 0 && deszip.length == 0)
		{
			alert ('You must enter a destination City OR Postal code!');
			document.frmQuoteReq.ToZip.focus();
			document.frmQuoteReq.ToZip.select();
			 
			return false;
		}
		
		//if (descity.length > 0 && deszip.length > 0)
		//{
		//	alert ('You can only enter a City OR Zipcode, not both!');
		//	document.frmQuoteReq.ToZip.focus();
		//	document.frmQuoteReq.ToZip.select();
		//	document.frmQuoteReq.ToCity.value = '';
		//	 
		//	return false;
		//}
		if (descity.length > 0 && foundspace2 != -1 && foundspace2 <= 2)
		{
			alert ('Destination city contains invalid data!');
			document.frmQuoteReq.ToCity.focus();
			document.frmQuoteReq.ToCity.select();
			return false;
		}
		if (deszip.length > 0 && foundspace3 != -1 && foundspace3 <= 2 || deszip.length > 0 && deszip < 3)
		{
			alert ('Please enter a valid destination zip code!');
			
			document.frmQuoteReq.ToZip.focus();
			document.frmQuoteReq.ToZip.select();
			return false;
		}
		if (orgzip.length > 0 && deszip.length > 0 && orgzip == deszip) 
		{
			alert ('Origin and Destination values must not be the same!');
			document.frmQuoteReq.FromZip.focus();
			document.frmQuoteReq.FromZip.select();
			document.frmQuoteReq.ToZip.value = '';
			return false;
		}
		if (orgcity.length > 0 && descity.length > 0 && orgcity == descity)
		{
			alert ('Origin and Destination values must not be the same!');
			document.frmQuoteReq.FromCity.focus();
			document.frmQuoteReq.FromCity.select();
			document.frmQuoteReq.ToCity.value = '';
			return false;
		}
		if (refresh != 'Y')
		{
			crtStep1('N');
			showField(lines);
			document.frmQuoteReq.clss1.focus();
			return true;
		}
		else
		{
			crtStep1('Y');
			showField(lines);
			document.frmQuoteReq.clss1.focus();
			return true;
		}
}

function checkInput3(clsid, wghtid, descid, linenum, crtline, update, chkonly)
{
	 	if (document.getElementById)
		{
			document.getElementById(clsid);
			var cls = clsid.value;
			document.getElementById(wghtid);
			var weight = wghtid.value;
			document.getElementById(descid);
			var dname = descid.name;
			var desc = descid.value;
			var elemId = wghtid.name; 
		}
		else if (document.all)
		{
			document.all(clsid);
			var cls = clsid.value;
			document.all(wghtid);
			var weight = wghtid.value;
			document.all(descid);
			var dname = descid.name;
			var desc = descid.value;

		}
		foundspace = cls.lastIndexOf(" ");
		foundspace1 = desc.lastIndexOf(" ");
		
		if (cls == 'none')
		{
			alert ('Please select a class code.');
			return false;
		}
		
		if (weight.length > 0 && parseInt(weight) > 0)
		{
			if (isNaN(weight))
			{
				alert ('Weight entered must be numeric.');
				return false;
			}
			else
			{
				if (weight.indexOf(" ") >= 0)
			    {
				   alert ('Weight entered must be numeric.');
				   return false;
				}
			}
			if (chkonly == 'N')
			{
				crtStep2(linenum, clsid, wghtid, descid, crtline, update);
			}
		return true;
		}
		else 
		{
				alert ('A weight amount must be entered.');
				document.frmQuoteReq.elements[elemId].focus();
				document.frmQuoteReq.elements[elemId].select();
				return false;
		}
		document.frmQuoteReq.elements[dname].focus();
}

function checkZip(zipcode, type)
{
		if (document.getElementById)
		{
		   	var dorefresh = document.getElementById("refresh").value;
			if (dorefresh == 'Y')
			{
				document.getElementById("lines").style.visibility = 'hidden';
			}
		}
		else if (document.all)
		{
			var dorefresh = document.all("refresh").value;
			if (dorefresh == 'Y')
			{
				document.all("lines").style.visibility = 'hidden';
			}
		}
			
		ziptype = type;
		citytype = ' ';
		var pcode = zipcode;
		var city = ' ';
		var source = 'zip';
		var action = 'VALIDT';
		var first = 'N';
		var Url = "/webaccessp/Quotation1.pgm?type=" +  encodeURIComponent(type) +
		'&zip=' + encodeURIComponent(pcode) +
		'&source=' + encodeURIComponent(source) +
		'&city=' + encodeURIComponent(city) +
		'&first=' + encodeURIComponent(first) +
		'&action=' + encodeURIComponent(action);
		getAjax('error', Url);
		if (type == 'Origin')
		{
			document.frmQuoteReq.txtToZip.focus();
		}
		else
		{
			var status = document.frmQuoteReq.btnNext.disabled;
			if (status == false)
			{
				document.frmQuoteReq.btnNext.focus();
			}
			else
			{
				document.frmQuoteReq.txtToCity.focus();
			}
		}
}	
function checkCity(loc)
{
		citytype = loc;
		var source = 'city';
		var zip = ' ';
		ziptype = ' ';
		if (loc == 'Origin')
		{
			if (document.getElementById)
			{
				var dorefresh = document.getElementById("refresh").value;
				if (dorefresh == 'Y')
				{
					document.getElementById("lines").style.visibility = 'hidden';
				}
				var state = document.getElementById("FromState").value;
				var city = document.getElementById("FromCity").value;
				//if (state = 'none')
				//{
				//	alert ('Please select a state.');
				//	return false;
				//}
			}
			else if (document.all)
			{
				var dorefresh = document.all("refresh").value;
				if (dorefresh == 'Y')
				{
					document.all("lines").style.visibility = 'hidden';
				}
				var city = document.all("FromCity").value;
				var state = document.all("FromState").value;
			}
		}
		else if (loc == 'Dest')
		{
			if (document.getElementById)
			{
				var dorefresh = document.getElementById("refresh").value;
				if (dorefresh == 'Y')
				{
					document.getElementById("lines").style.visibility = 'hidden';
				}
				var state = document.getElementById("ToState").value;
				var city = document.getElementById("ToCity").value;
			}
			else if (document.all)
			{
				var dorefresh = document.all("refresh").value;
				if (dorefresh == 'Y')
				{
					document.all("lines").style.visibility = 'hidden';
				}
				var city = document.all("ToState").value;
				var city = document.all("ToCity").value;
			}
			
		}
		var action = 'VALIDT';
		var first = 'N';
		var Url = "/webaccessp/Quotation1.pgm?type=" +  encodeURIComponent(citytype) +
		'&zip=' + encodeURIComponent(zip) +
		'&source=' + encodeURIComponent(source) +
		'&city=' + encodeURIComponent(city) +
		'&state=' + encodeURIComponent(state) +
		'&first=' + encodeURIComponent(first) +
		'&action=' + encodeURIComponent(action);
		getAjax('error', Url);
		
}	
function roundNumber(n)
{
// Format a number to 2 decimal places 
 x = n * 100;

 x = Math.round(x);

 strNumber = "" + x;
 len = strNumber.length;

 return strNumber.substring(0, len - 2) + "." + strNumber.substring(len - 2, len);
}

function reCalc(quote)
{
	// alert ('Updating quote: ' + quote);
	var theForm = document.forms["results"] 
	var totcharges = 0;
	var charge = 0;
	var wrkfuel = 0;
	var wrkdisc = 0;
	var wrktotchg = 0;
	var minchg = 0;
	var minflg = 'N';
	var subtotal = 0;

		if (document.getElementById)
		{
			document.getElementById("showMin").style.visibility = 'hidden';
			var freight  = document.getElementById("frtchrg");
			var discount = document.getElementById("discamt");
			var fuel = document.getElementById("fuelsurch");
			var total = document.getElementById("total");
			var discp = document.getElementById("discpct").value + document.getElementById("discfrc").value;
			//var discp = document.getElementById("discpct");
			var fuelp = document.getElementById("fuelpct");
			var user = document.getElementById("email").value;
			var minchg = document.getElementById("minchg").value;
			for(i=0; i<theForm.elements.length; i++)
			{
				if (theForm.elements[i].type == "text")
				{
					var ele = theForm.elements[i].id;
					var type = ele.substring(0,6);
					if (type == 'charge')
					{
						charge = document.getElementById(ele).value;
						totcharges = totcharges + parseFloat(charge);
						
					}
				}
				  
			}
		}
		else if (document.all)
		{
			document.all("showMin").style.visibility = 'hidden';
			var freight  = document.all("frtchrg");
			var discount = document.all("discamt");
			var fuel = document.all("fuelsurch");
			var total = document.all("total");
			var discp = document.all("discpct").value + document.all("discfrc").value;
			//var discp = document.all("discpct");
			var fuelp = document.all("fuelpct");
			var minchg = document.all("minchg").value;
			var user = document.all("email").value;
			for(i=0; i<theForm.elements.length; i++)
			{
				if (theForm.elements[i].type == "text")
				{
					var ele = theForm.elements[i].id;
					var type = ele.substring(0,6);
					if (type == 'charge')
					{
						charge = document.all(ele).value;
						totcharges = totcharges + parseFloat(charge);
						
					}
				}
				  
			}
		}
			minchg = parseFloat(minchg); // Minimum Charge
			discount.value = freight.value * (discp / 100);
			//discount.value = freight.value * (discp.value / 100);
			wrkdisc = discount.value;
			discount.value = roundNumber(discount.value) * -1;
			subtotal = freight.value - wrkdisc;
			// If the discounted amount is below minimum then set it to the minimum
			if (subtotal < minchg) 
			{
				var minflg = 'Y';
				subtotal = minchg;
				discount.value = (freight.value - minchg) * -1;
				document.getElementById("showMin").style.visibility = 'visible';
			}
			wrkfuel = subtotal * fuelp.value;
			//fuel.value = (freight.value - discount.value) * fuelp.value;
			fuel.value = roundNumber(wrkfuel);
			total.value = subtotal + wrkfuel +  totcharges;
			total.value = roundNumber(total.value);
		var action = 'UPDAMT';
		var first = 'N';
		var netamt = total.value;
		var discreq = discp;
		//var discreq = discp.value;
		var discamt = discount.value;
		var Url = "/webaccessp/Quotation1.pgm?quote=" + encodeURIComponent(quote) +
		'&minflg=' + encodeURIComponent(minflg) +
		'&user=' + encodeURIComponent(user) + 
		'&discp=' + encodeURIComponent(discreq) +
		'&discamt=' + encodeURIComponent(discamt) +
		'&netamt=' + encodeURIComponent(netamt) +
		'&first=' + encodeURIComponent(first) +
		'&action=' + encodeURIComponent(action);
		getAjax('error', Url);
			
}
//-->