// shipping.js

var xmlHttp;

var theTable, theTableBody;

function initTable() {
    theTable = (document.all) ? document.all.myTABLE : 
        document.getElementById("estimateTable");
    theTable = document.getElementById("estimateTable");
    theTableBody = theTable.tBodies[0];
}
function appendRow(form) {
    insertTableRow(form, -1);
}

function addErrorRow(error, where) {
	var form = document.ShippingEstimate;

    var cell1;

    var row1 = theTableBody.insertRow(where);
    var row2 = theTableBody.insertRow(where + 1);
    
    row1.id = "error_row";
	row2.id = "estimate_detail";
	row1.style.backgroundColor = "#d5d1cf";	
    
    var str = "<font size=\"-1\" color=\"red\">" + error + "</font>";
    
    cell1 = row1.insertCell(0);
    cell1.innerHTML = str;
    cell1.colSpan ="2";
    cell1.align="left";    
}

function addLoadingGif() {
	var cell1, cell2;
	var where = 6;
	var row1 = theTableBody.insertRow(where);
	row1.id = "loading";
	row1.style.backgroundColor = "#d5d1cf";	

	var str = "<img src=\"../images/ajax-loader.gif\" alt=\"Loading, please wait!\" />";
    cell1 = row1.insertCell(0);
    cell1.innerHTML = str;
   	cell1.colSpan="2";
    cell1.align="center";    	
	
}
function addWeightLoadingGif() {
	var str = "<img id=\"loadingWeight\" src=\"../images/ajax-loader.gif\" alt=\"Loading, please wait!\" />";

	document.getElementById('weightLoading').innerHTML = str;
}	
function removeWeightLoadingGif() {
	var str = "";

	document.getElementById('weightLoading').innerHTML = str;
}	
function addEstimateRow(price, url, baseurl) {
	var form = document.ShippingEstimate;
	var where = 6;

    var cell1, cell2, cell3, cell4;

    var row1 = theTableBody.insertRow(where);
    var row2 = theTableBody.insertRow(where + 1);
    
    row1.id = "estimate_row";
	row1.style.backgroundColor = "#d5d1cf";	
    
    var str = "<span class=\"estimate_cost\">" + price + "</span> USD<br /><span class=\"estimate_details\">";
 	str = str + "<a href=\"javascript:getShippingLinkGFU('detail','" + baseurl + "')\">Estimate Details</a></span></td>";

    cell1 = row1.insertCell(0);
    cell1.innerHTML = "<span class=\"estimate_highlight\">Shipping estimate:</span> ";
    cell1.align="right";
        
    cell2 = row1.insertCell(1);
    cell2.innerHTML = str;    
}

function newZipLookUpWindow(location) {
    mywindow=open('../common_scripts/zippostalcodelookup.jsp',location,'resizable=no,width=300,height=200');
    mywindow.location.href = '../common_scripts/zippostalcodelookup.jsp';
    mywindow.moveTo(300,200);
    if (mywindow.opener == null) mywindow.opener = self;
    
}
function newPortLookUpWindow(location) {
    mywindow=open('../common_scripts/portlookup.jsp',location,'resizable=no,width=300,height=140');
    mywindow.location.href = '../common_scripts/portlookup.jsp';
    mywindow.moveTo(300,200);
    if (mywindow.opener == null) mywindow.opener = self;
}


function trim(s) 
{ 
    var l=0; var r=s.length -1; 
    while(l < s.length && s[l] == ' ') 
    {     l++; } 
    while(r > l && s[r] == ' ') 
    {     r-=1;     } 
    return s.substring(l, r+1); 
} 


function containsAmp(str) {
	var ampChar = /\&/;
	if (str.search(ampChar) == -1) { // does not contain amp character
		return false;
	} else { // contains amp character
		return true;
	}
}
function containsSpecialCharacter(string) {

	//var reg = /([!@#$%^&*]+)/
	string = string.replace(/\s/g, "");
	var reg = /\W/
	var results = string.match(reg);
	if (!results) { // no match			
		return false;									
	} else { 
		return true;
	}	
}
function getLotInfo(lotNo) {

	lotNo = trim(lotNo);
	
	removeEstimate();
	
	if (containsAmp(lotNo)) {
		document.getElementById('itemDesc').innerHTML = "Lot Number does not exist.";	
		document.ShippingEstimate.itemWeight.value = "";   	
		document.ShippingEstimate.length.value = "";   	
		document.ShippingEstimate.width.value = "";   	
		document.ShippingEstimate.height.value = "";
		document.ShippingEstimate.dimensionunit.value = "";		
		document.ShippingEstimate.unit_selection.selectedIndex = 0;	
		document.ShippingEstimate.numOfPics.value = "";	
		return;
	} 	
	
	var saleNo = document.ShippingEstimate.basic_auction_id.options[document.ShippingEstimate.basic_auction_id.selectedIndex].value;	
	var xmlHttp;
	
	xmlHttp=GetXmlHttpObject();
	if (xmlHttp==null) {
	  alert ("Your browser does not support AJAX!");
	  return;  
    } 

    if (lotNo != null && lotNo != "" && saleNo != null && saleNo != "All" && saleNo != "") {
		xmlHttp.onreadystatechange=lotInfoDetail;		
		xmlHttp.open("GET","../common_scripts/lotInfo.jsp?lotNo=" + lotNo + "&saleNo=" + saleNo,true);  
		xmlHttp.send(null); 
	} else {
	   	document.getElementById('itemDesc').innerHTML = "Lot Number does not exist.";	
		document.ShippingEstimate.itemWeight.value = "";   
		document.ShippingEstimate.length.value = "";   	
		document.ShippingEstimate.width.value = "";   	
		document.ShippingEstimate.height.value = "";   	
		document.ShippingEstimate.dimensionunit.value = "";
		document.ShippingEstimate.unit_selection.selectedIndex = 0;
		document.ShippingEstimate.numOfPics.value = "";

	}
	
	return; 
}

function weightInfo() {
	if(xmlHttp.readyState==4){ 	    
   		var weight = xmlHttp.responseText;	 
   		removeWeightLoadingGif();    
   		parseWeight(weight);
   	}	
}

function originZipCode() {
	if(xmlHttp.readyState==4){ 	    			  		
   		var xml = xmlHttp.responseText;	     
   		parseOriginXML(xml);   	
   	}
}

function removeEstimate() {
	
	initTable();
	if (document.getElementById("estimate_row") != null) {
		theTableBody.deleteRow(8);
	}
	
	if (document.getElementById("error_row") != null || document.getElementById("error") != null ) {
		theTableBody.deleteRow(8);
	}
}
function removeEstimateGFU() {
	initTable();
	
	if (document.getElementById("estimate_row") != null) {
		theTableBody.deleteRow(6);
		//theTableBody.deleteRow(4);

	}
	if (document.getElementById("error_row") != null) {
		theTableBody.deleteRow(6);
	}
	if (document.getElementById("loading") != null) {
		theTableBody.deleteRow(6);
	}
}
function getOrigin() {
	var saleNo = document.ShippingEstimate.basic_auction_id.options[document.ShippingEstimate.basic_auction_id.selectedIndex].value;			
	
	document.ShippingEstimate.lot.value = ""; 
	document.ShippingEstimate.equipid.value = "";
	document.ShippingEstimate.make.value = "";
	document.ShippingEstimate.model.value = "";
	document.ShippingEstimate.itemWeight.value = "";
	document.getElementById('itemDesc').innerHTML = "";
	document.ShippingEstimate.unit_selection.selectedIndex = 0;
	document.ShippingEstimate.numOfPics.value = "";

	
	removeEstimate();
	
   	xmlHttp=GetXmlHttpObject();
	if (xmlHttp==null) {
	  alert ("Your browser does not support AJAX!");
	  return;  
	} 
    	
	xmlHttp.onreadystatechange=originZipCode;		
		
	xmlHttp.open("GET","../common_scripts/originZipCode.jsp?saleNo=" + saleNo, true);  
	xmlHttp.send(null); 		  		

}

function parseWeight(xml) {
	var xmlDoc = parseXml(xml);
	var error = "";
	
	try {
		error = (xmlDoc.getElementsByTagName("error")[0] != null) ? xmlDoc.getElementsByTagName("error")[0].childNodes[0].nodeValue: "";
	} catch (e) {}
	
	if (error == "The service is currently unavailable, please try again later. We apologize for the inconvenience.") {
		document.getElementById('error').innerHTML = error;
		return;
	} 
		
	var weight = (xmlDoc.getElementsByTagName("weight")[0] != null)? xmlDoc.getElementsByTagName("weight")[0].childNodes[0].nodeValue: "0"
	
	var length = (xmlDoc.getElementsByTagName("length")[0] != null) ? xmlDoc.getElementsByTagName("length")[0].childNodes[0].nodeValue: "";
	var width = (xmlDoc.getElementsByTagName("width")[0] != null) ? xmlDoc.getElementsByTagName("width")[0].childNodes[0].nodeValue: "";
	var height = (xmlDoc.getElementsByTagName("height")[0] != null) ? xmlDoc.getElementsByTagName("height")[0].childNodes[0].nodeValue: "";

	//var dimensionunit = xmlDoc.getElementsByTagName("dimensionunit")[0].childNodes[0].nodeValue;	
	
	document.ShippingEstimate.itemWeight.value = weight;   	
	document.ShippingEstimate.length.value = length;   	
	document.ShippingEstimate.width.value = width;   	
	document.ShippingEstimate.height.value = height;   	
	document.ShippingEstimate.dimensionunit.value = "ft"; //dimensionunit;

	
	var unit ;
	if (weight == "0") {
		unit = "lb";
		document.ShippingEstimate.itemWeight.value = "";   	
		
	} else {
		unit = (xmlDoc.getElementsByTagName("weightunit")[0] != null) ? xmlDoc.getElementsByTagName("weightunit")[0].childNodes[0].nodeValue: "";
	}
	if (unit == "kg") {		
		document.ShippingEstimate.unit_selection.selectedIndex = 1;
	} else {
		document.ShippingEstimate.unit_selection.selectedIndex = 0;
	}	
}
function parseOriginXML(xml) {
	var xmlDoc = parseXml(xml);		
	document.ShippingEstimate.originzipcode.value = "";
	var zip = (xmlDoc.getElementsByTagName("zip")[0] != null) ? xmlDoc.getElementsByTagName("zip")[0].childNodes[0].nodeValue: "";
	document.ShippingEstimate.originzipcode.value = zip; 
	
}

function parseLotInfoXML(xml) {	
	
	var xmlDoc = parseXml(xml);	

	if (xmlDoc == null) {
		return false;
	}
	var itemDesc = (xmlDoc.getElementsByTagName("itemdesc")[0] != null) ? xmlDoc.getElementsByTagName("itemdesc")[0].childNodes[0].nodeValue: "";
	
   	if (itemDesc == "null" || itemDesc == "") {
   	   	document.getElementById('itemDesc').innerHTML = "Lot Number does not exist.";
  		document.ShippingEstimate.itemWeight.value = "";  
  		document.ShippingEstimate.make.value = "";
		document.ShippingEstimate.model.value = "";
		document.ShippingEstimate.equipmentdesc.value = "";
		document.ShippingEstimate.classcd.value = "";
		document.ShippingEstimate.equipid.value = "";
		document.ShippingEstimate.itemdescp.value = "";
		document.ShippingEstimate.length.value = "";   	
		document.ShippingEstimate.width.value = "";   	
		document.ShippingEstimate.height.value = "";
		document.ShippingEstimate.dimensionunit.value = "";
		document.ShippingEstimate.unit_selection.selectedIndex = 0;
		document.ShippingEstimate.numOfPics.value = "";
		return false;
   	} 
	document.ShippingEstimate.make.value = (xmlDoc.getElementsByTagName("make")[0] != null) ? (xmlDoc.getElementsByTagName("make")[0].childNodes[0].nodeValue): "";
	document.ShippingEstimate.model.value = (xmlDoc.getElementsByTagName("model")[0] != null) ? (xmlDoc.getElementsByTagName("model")[0].childNodes[0].nodeValue): "";
	document.ShippingEstimate.equipmentdesc.value = (xmlDoc.getElementsByTagName("eqdesc")[0] != null) ? xmlDoc.getElementsByTagName("eqdesc")[0].childNodes[0].nodeValue: "";
   	document.getElementById('itemDesc').innerHTML = (xmlDoc.getElementsByTagName("itemdesc")[0] != null) ? xmlDoc.getElementsByTagName("itemdesc")[0].childNodes[0].nodeValue: "";
	document.ShippingEstimate.classcd.value = (xmlDoc.getElementsByTagName("classcd")[0] != null) ? xmlDoc.getElementsByTagName("classcd")[0].childNodes[0].nodeValue: "";
	document.ShippingEstimate.equipid.value = (xmlDoc.getElementsByTagName("equipid")[0] != null) ? xmlDoc.getElementsByTagName("equipid")[0].childNodes[0].nodeValue: "";
	document.ShippingEstimate.itemdescp.value = (xmlDoc.getElementsByTagName("itemdesc")[0] != null) ? xmlDoc.getElementsByTagName("itemdesc")[0].childNodes[0].nodeValue: "";
	document.ShippingEstimate.numOfPics.value = (xmlDoc.getElementsByTagName("numofpics")[0] != null) ? xmlDoc.getElementsByTagName("numofpics")[0].childNodes[0].nodeValue: "";
	
}

function parseXml(xml) {
	var xmlDoc;
	try {//Internet Explorer	  
	  xmlDoc=new ActiveXObject("Microsoft.XMLDOM");
	  xmlDoc.async="false";
	  xmlDoc.loadXML(xml);
	} catch(e) {
	  try {//Firefox, Mozilla, Opera, etc.
		  parser=new DOMParser();
		  xmlDoc=parser.parseFromString(xml,"text/xml");
	  } catch(e) {
		  alert(e.message);
		  return;
	  }
	} return xmlDoc;	
}

function lotInfoDetail() {

  	if(xmlHttp.readyState==4){ 	   	  		
   		var lot = xmlHttp.responseText;	  
		if (parseLotInfoXML(lot) == false) {
			return;
		} 		
		getWeight();		
	}  	
}
function getWeight() {
	xmlHttp=GetXmlHttpObject();
	if (xmlHttp==null) {
	  alert ("Your browser does not support AJAX!");
	  return;  
	} 
	addWeightLoadingGif();
    	
    var make = document.ShippingEstimate.make.value;
	var model = document.ShippingEstimate.model.value;
	make = escape(make);
	model = escape(model);
	//document.ShippingEstimate.make.value = make;
	//document.ShippingEstimate.model.value = model;
	var equipmentdesc = document.ShippingEstimate.equipmentdesc.value;
	var classcd = document.ShippingEstimate.classcd.value;
	xmlHttp.onreadystatechange=weightInfo;		
		
	xmlHttp.open("GET","../common_scripts/equipmentWeight.jsp?make=" + make + "&model=" + model + "&equipmentdesc=" + equipmentdesc + "&classcd=" + classcd, true);  
	xmlHttp.send(null);    		

}
function GetXmlHttpObject() {
	  
	try  {
	  // Firefox, Opera 8.0+, Safari
	  xmlHttp=new XMLHttpRequest();
	} catch (e) { 
	  // Internet Explorer
		try {
    		xmlHttp=new ActiveXObject("Msxml2.XMLHTTP");
	    } catch (e) {
    		xmlHttp=new ActiveXObject("Microsoft.XMLHTTP");
    	}
  	}
	return xmlHttp;
}
function isNumber(str) {
	if (str == "") {
		return false;
	} else if (isNaN(str)) { // is NOT a number
		return false;
	} else {
		return true;
	}

}
function getEstimate(estbaseurl) {	   	
	
	var origin = document.ShippingEstimate.originzipcode.value;
	var destination = document.ShippingEstimate.zipcode.value;
	var weight = document.ShippingEstimate.itemWeight.value;
	var unit = document.ShippingEstimate.unit_selection.selectedIndex;
	var classcd = document.ShippingEstimate.classcd.value;		
	var error = "";
	
	initTable();
	
	if (document.getElementById("estimate_row") != null) {
		theTableBody.deleteRow(6);
		//theTableBody.deleteRow(4);

	}
	if (document.getElementById("error_row") != null) {
		theTableBody.deleteRow(6);
	}
	if (document.getElementById("loading") != null) {
		theTableBody.deleteRow(6);
	}
	if (origin == "") {
		error = "Origin zip code is not available";
	} 
	if (destination == "") {
		error = (error == ""? "" : error + "<br/>") + "A destination is required";
	} else if (containsSpecialCharacter(destination)) {
		error = (error == ""? "" : error + "<br/>") + "Invalid destination";
	} 	
	if (weight == "") {
		error = (error == ""? "" : error + "<br/>") + "A weight estimate is required";	
	}	
	else if (!isNumber(weight)) {
		error = (error == ""? "" : error + "<br/>") + "Invalid weight";
	}	
	if (error != "") {
		addErrorRow(error, 6);
		return;
	}

	// update hidden weight and unit, dest zip code
	document.ShippingEstimate.p_zip.value = destination;
	document.ShippingEstimate.p_weight.value = weight;
	document.ShippingEstimate.p_unit.value = unit;

	addLoadingGif();	
	if (unit == 1) {
		unit = "kg";
	} else {
		unit = "lbs";
	}	

	var urlString = "zipcode=" + destination + "&originzipcode=" + origin + "&itemWeight=" + weight + "&classcd=" + classcd + "&unit_selection=" + unit;
	xmlHttp=GetXmlHttpObject();
	if (xmlHttp==null) {
	  alert ("Your browser does not support AJAX!");
	  return;  
	} 
    	
	xmlHttp.onreadystatechange=function(estbaseurl) {
		return function() {
			if(xmlHttp.readyState==4){ 	   	  		
		  		var estimate = xmlHttp.responseText;	     
		   		parseEstimate(estimate, estbaseurl); 		
			}  	   
		};
		}(estbaseurl);
			
	xmlHttp.open("GET","../equipment_search/getEstimate.jsp?" + urlString, true);  
	xmlHttp.send(null); 		
} 

function parseEstimate(xml, baseurl) {
	var xmlDoc = parseXml(xml);	

	var error = "";
	try {
		error = (xmlDoc.getElementsByTagName("error")[0] != null) ? xmlDoc.getElementsByTagName("error")[0].childNodes[0].nodeValue: "";
	} catch (e) {}
	
	if (document.getElementById("loading") != null) {
		theTableBody.deleteRow(6);
	}
	if (error == "The service is currently unavailable, please try again later. We apologize for the inconvenience.") {
		addErrorRow(error, 6);
		return;
	} 
	if (error != "") {
		addErrorRow(error, 6);
		return;
	} else {
	}
		
	var price = xmlDoc.getElementsByTagName("price")[0].childNodes[0].nodeValue;	
	var url = xmlDoc.getElementsByTagName("url")[0].childNodes[0].nodeValue;
	url = unescape(url);		
	
	addEstimateRow(price, url, baseurl);	
}

function getShippingLink(type, url) {

	var saleNo = document.ShippingEstimate.p_saleNo.value;   	
	var length = document.ShippingEstimate.p_length.value;   	
	var width = document.ShippingEstimate.p_width.value;   	
	var height = document.ShippingEstimate.p_height.value;
	var equipid = document.ShippingEstimate.p_equipid.value;
	var classcd = document.ShippingEstimate.p_classcd.value;	
	var origin = document.ShippingEstimate.p_originzipcode.value;
	var destination = document.ShippingEstimate.zipcode.value;
	var make = escape(document.ShippingEstimate.p_make.value);	
	var model = escape(document.ShippingEstimate.p_model.value);
	var weight = document.ShippingEstimate.p_itemWeight.value;
	var unit = document.ShippingEstimate.p_unit.value;
	var pageOrigin = document.ShippingEstimate.pageOrigin.value; 
	var lot = document.ShippingEstimate.lot.value;	
	
	var numOfPic = 0;
	var fileNames = "";		
	
	var p_lot = document.ShippingEstimate.p_lot.value;
	
	if (unit=="2" && weight!="" && weight!="null") {
	   	weight = weight * 2.2;
	}
		
	if (saleNo == "" && p_lot == "" && weight == "") {
		saleNo = document.ShippingEstimate.basic_auction_id.options[document.ShippingEstimate.basic_auction_id.selectedIndex].value;
		if (saleNo == "All") {
			saleNo = "-1";
		}
		length = document.ShippingEstimate.length.value;   	
		width = document.ShippingEstimate.width.value;   	
		height = document.ShippingEstimate.height.value;
		equipid = document.ShippingEstimate.equipid.value;
		classcd = document.ShippingEstimate.classcd.value;	
		origin = document.ShippingEstimate.originzipcode.value;
		destination = document.ShippingEstimate.zipcode.value;
		/*if (pageOrigin == "index") {
			make = (document.ShippingEstimate.make.value);	
			model = (document.ShippingEstimate.model.value);
		} else { */
			make = escape(document.ShippingEstimate.make.value);	
			model = escape(document.ShippingEstimate.model.value);
	//	}
		weight = document.ShippingEstimate.itemWeight.value;
		if (document.ShippingEstimate.unit_selection.selectedIndex == 1 && weight!="" && weight!="null") {
			weight = weight * 2.2;
		}
	} 
	if (!isNumber(weight)) {
		weight = "";
	}
	if (containsSpecialCharacter(destination)) {
		destination = "";
	}
	var picPath = "&a_iurl=http://www.rbauction.com/equipment_images/" + saleNo +  "/large/";
	if (pageOrigin == "index") {
		numOfPic = document.ShippingEstimate.numOfPics.value;

	} else if (pageOrigin != "index") {
		numOfPic = arrAngles.length;
	} 	
	
	fileNames ="&a_iname=";
	if (numOfPic == 0) {
		picPath = "";
		fileNames = "";
	}
	for (i=0; i < numOfPic && i< 10; i++) {
		var index = i + 1;
		fileNames = fileNames + equipid + "_" + index + ".jpg" +";" ;
	}
	
	var urlString =	"&a_OvrHei=" + height + "&a_OvrLen=" + length + "&a_OvrWid=" + width + "&equipid=" + equipid;	
	if (isNumber(weight)) {
		urlString = urlString  + "&a_OvrWei=" + weight;
		if (type == "detail") {
			urlString = urlString + "&w=" + weight;
		}
	}	
	
	urlString = urlString + "&a_LotNumber=" + lot;
	
	urlString = "&baseUrl=" + url + urlString;
	url = "../common_scripts/save_quote.jsp";
	urlString = urlString + "&a_SaleID=" + saleNo + "&a_Code=" + classcd + "&r=569890&a_Make=" + make + "&a_Model=" + model;
	url = url + "?skip=1&z1=" + origin + "&z2=" + destination + urlString + picPath + fileNames;

	window.location.href=url;	
}

function getShippingLinkGFU(type, url) {
	
	var saleNo = document.ShippingEstimate.saleNum.value; 
	var length = document.ShippingEstimate.length.value;   	
	var width = document.ShippingEstimate.width.value;   	
	var height = document.ShippingEstimate.height.value;
	var equipid = document.ShippingEstimate.equipid.value;
	var classcd = document.ShippingEstimate.classcd.value;	
	var origin = document.ShippingEstimate.originzipcode.value;
	var destination = document.ShippingEstimate.zipcode.value;
	var make = escape(document.ShippingEstimate.make.value);	
	var model = escape(document.ShippingEstimate.model.value);	
	var unit = document.ShippingEstimate.unit_selection.selectedIndex;	
	var weight = document.ShippingEstimate.itemWeight.value;
	var lot = document.ShippingEstimate.lot.value;	

	if(document.ShippingEstimate.p_zip.value!="" && document.ShippingEstimate.p_weight.value!="" && document.ShippingEstimate.p_unit.value!="") {
		destination = document.ShippingEstimate.p_zip.value;
		weight = document.ShippingEstimate.p_weight.value;
		unit = document.ShippingEstimate.p_unit.value;
	}
	
	if (!isNumber(weight)) {
		weight = "";
	}
	if (containsSpecialCharacter(destination)) {
		destination = "";
	}
	var picPath = "&a_iurl=http://www.rbauction.com/equipment_images/" + saleNo +  "/large/";
	
	var numOfPic = arrAngles.length;
	var fileNames ="&a_iname=";
	for (i=0; i < numOfPic && i< 10; i++) {
		var index = i + 1;
		fileNames = fileNames + equipid + "_" + index + ".jpg" +";" ;
	}
	if (numOfPic == 0) {
		picPath = "";
		fileNames = "";
	}

	if (unit==1 && weight!="" && weight!="null") {
		weight = weight * 2.2;
	}
	
	var urlString =	"&a_OvrHei=" + height + "&a_OvrLen=" + length + "&a_OvrWid=" + width + "&equipid=" + equipid;
	
	if (isNumber(weight)) {
		urlString = urlString  + "&a_OvrWei=" + weight;
		if (type == "detail") {
			urlString = urlString  + "&w=" + weight;
		}
	}
	urlString = urlString + "&a_LotNumber=" + lot;

	urlString = "&baseUrl=" + url + urlString;
	url = "../common_scripts/save_quote.jsp";
	urlString = urlString + "&a_SaleID=" + saleNo + "&a_Code=" + classcd + "&r=569890&a_Make=" + make + "&a_Model=" + model;
	url = url + "?skip=1&z1=" + origin + "&z2=" + destination + urlString + picPath + fileNames;	
	window.location.href=url;
}
function submitEstimate() {

	initTable();
	if (document.getElementById("estimate_row") != null) {
		theTableBody.deleteRow(8);
	}
	if (document.getElementById("error_row") != null || document.getElementById("error") != null ) {
		theTableBody.deleteRow(8);
	}
			
	if (document.getElementById('itemDesc').innerHTML == "Lot Number does not exist." || document.getElementById('itemDesc').innerHTML == "" 
		|| document.getElementById('itemDesc').innerHTML == "&nbsp;"){		


		var error = "";		
		
		if (document.ShippingEstimate.lot.value == "" || document.ShippingEstimate.lot.value == "&nbsp;") {
			document.getElementById('itemDesc').innerHTML = "Lot Number does not exist.";
		}
	
		if (document.ShippingEstimate.itemWeight.value == "") {
			error = "A weight estimate is required";
		}		

		if (document.ShippingEstimate.zipcode.value == "") {
			error = error + "<br/>A destination is required";		
		} 		

		if (error != "") {	
			addErrorRow(error,8);
		}

		return false;
		
	} else {
		
		return true;
	}
	
}
