	courier_on = new Array();
	var bg_colors = new Array();

	function d2h(d) {return d.toString(16);}
	function h2d(h) {return parseInt(h,16);} 

	var gndFix = '';

	var region_code = '';
	var x_pzfromtown = "";
	var x_pztotown = "";
	var x_weight = "";
	var x_time = "";
	var x_currency = "";
	var x_error = 0;
	var x_error_mess = "";
	var x_international = false;
	var ex_time = "";

	var x_pztown = "";

	var y_pzfromtown = "";
	var y_pztotown = "";
	var y_weight = "";

	var y_postal1 = "";
	var y_postal2 = "";
	var yy_postal1 = "";
	var yy_postal2 = "";
	var yyy_postal1 = "";
	var yyy_postal2 = "";
	var yyy_postal2 = "";
	var yyy_weight = "";
	var yyy_packages = "";
	var yy_envelope = "";
	var y_length = "";
	var y_width = "";
	var y_height = "";
	var y_residential = "";
	var yy_residential = "";
	var adv_interface = "0";
	var d_weight = 1;
	var state_var1=0;
	var state_var2=0;
	var wgt_text = "";
	var dimw_flag = 0;

	var map_status;
	var ship_distance = 0;

	var x_rates = new Array();
	var rate_table = "";

	var xmlDoc;
	var xmlDoc1;
	var xmlDoc2;

	var xmlHttp=new Array();
	var xmlHttp_full=new Array();
	var xmlHttp_sq=new Array();
	var loc_num;
	var xml_index = 0;
	var xml_index2 = 0;
	var xml_index3 = 0;

	var first_rates_done = 0;

	var col_bg = new Array("ffffff","f9f9ff","f4f4ff","ececff","e4e4ff","dcdcff","d4d4ff","ccccff");

	var turn_time = 0;
	var turn_time2 = 0;
	var total_turn_time = 0;

	var currency = new Array();
	currency["CAD"] = "Canadian";
	currency["USD"] = "U.S.";

	var last_view = 0;
	var rate_cell = false;

	var sv_t_chk = new Array("checked","","");
	var sv_c_chk = new Array("","checked","");
	var sv_m_chk = new Array("","","checked");

	var account;
	var x_flagfrom = '';
	var x_flagto = '';

	var featured = new Array();
	var featured_nam = new Array();
	var featured_chk = new Array();
	var featured_txt = new Array();
	var featured_img = new Array();
	var featured_phn = new Array();
	var featured_web = new Array();
	var numFeatured = 0;

	function myRate (r_courier, r_service, r_service_desc, r_transit_days, r_rate, r_phone, r_website, r_svc_code, r_discount, r_subscriber) {
		this.courier = r_courier;
		this.service = r_service;
		this.service_desc = r_service_desc;
		this.transit = r_transit_days;
		this.rate = r_rate;
		this.phone = r_phone;
		this.website = r_website;
		this.service_code = r_svc_code;
		this.discount = r_discount;
		this.subscriber = r_subscriber;
	}

	function showDesc(obj, myDesc) {
		var mD = document.getElementById("serviceDiv");
		mD.innerHTML = myDesc;
		mD.style.top=obj.offsetTop + 60 + 'px';
		mD.style.left=obj.offsetLeft + 100 + 'px';
		mD.style.display = 'inline';
	}

	function hideDesc(obj, myDesc) {
		var mD = document.getElementById("serviceDiv").style.display='none';
	}

	function show_results(v_type) {
		if (old_browser) { return; }
		var rate_cell_divID = '';
		var couriers = xmlDoc.getElementsByTagName('courier');
		//var num_val2 = document.getElementById("weight");
		var result_text = document.getElementById("results");
		document.getElementById("status").style.visibility='hidden';
		if (x_error == 0) {
			last_view = v_type;
			var r_str = "";
			document.getElementById("from_to").innerHTML = '<b>' + x_flagfrom + '&nbsp;&nbsp;' + x_pzfromtown + '&nbsp;&nbsp;&nbsp;To&nbsp;&nbsp;&nbsp;' + x_pztotown + '</b>&nbsp;&nbsp;' + x_flagto + '</b>';

			rate_table = '<center>';
			rate_table += '<div style="padding-left:10px; font-size:11px; float:left; width:200px;"><b>View:</b>&nbsp;&nbsp;<input ' + sv_t_chk[v_type] + ' type="radio" name="t_view" value="0" onClick="show_results(0);">Days' + '&nbsp;&nbsp;<input ' + sv_c_chk[v_type] + ' type="radio" name="t_view" value="1" onClick="show_results(1);">Couriers' +  '&nbsp;&nbsp;<input ' + sv_m_chk[v_type] + ' type="radio" name="t_view" value="2" onClick="show_results(2);">Map</div>';
			rate_table+= '<div style="width:400px; color:#666666; border:1px solid #cccccc; background:#ffffee; font-size:11px;"><b>Click</b> on the <b>courier names</b> below to go to their websites.</div>';
			rate_table+= '<br style="height:1px;" />';

			if (v_type == 0){
				if (account) {
					//rate_table+= ' Rates shown in <div style="background:#ffffcc; display:inline;">&nbsp;<b>yellow</b>&nbsp;</div> have your discounts applied.';
				}
				rate_table+= '<div class="rates_top" style="margin-left:3px;"><b>Same Day</b></div>';
				rate_table+= '<div class="rates_top"><b>Next Day</b></div>';
				rate_table+= '<div class="rates_top"><b>Two Days</b></div>';
				rate_table+= '<div class="rates_top"><b>Three Days</b></div>';
				rate_table+= '<div class="rates_top"><b>Ground (1-6 Days)</b></div><br />';
				cellWidth = 184;
				for (c=0;c<couriers.length;c++) {
					with (x_rates[c]) {
					if (courier_on[courier] == 1) {
						rate_table+="<tr>";
						for (k=0;k<=4;k++) {
							bg_col = col_bg[k];
							cursorStyle = '';
							if (k==0) {
								leftMargin = "margin-left:3px; border-left:1px solid #bbbbbb;";
							} else {
								leftMargin = "";
							}
							if (c==0) {
								leftMargin += ' border-top:1px solid #bbbbbb;';
							}
							if ((k<4) & (transit == k)) {
								r_str = rate_string(c);
								rate_cell = true;
								if ((account) && (discount > 0)) {
									bg_col = 'ffffcc';
								}
							} else if ((k==4) && (transit > 3)) {
								r_str = rate_string(c);
								rate_cell = true;
								if ((account) && (discount > 0)) {
									bg_col = 'ffffcc';
								}
							} else {
								rate_cell = false;
								rate_cell_divID = '';
								r_str = '<div class="t_left">&nbsp;</div>';
								mo_js = '';
							}
							rightBorder = ''
							fWgt = '';
							rate_cell_divID = '';
							if (rate_cell) {
								rate_cell_divID = ' id="rates_cell' + c + '"';
								if (subscriber === 'S') {
									//bg_col = 'ffffcc';
									//fWgt = ' font-weight:bold;';
									fWgt = '';
									if (featured_chk[courier] == null) {
										featured_chk[courier] = 1;
										featured[numFeatured++] = courier;
									}
									gotoURL = './click.php?courier=' + courier + '&url=http://' + website + '&svc=' + service + '&pzfrom=' + y_postal1 + '&pzto=' + y_postal2 + '&weight=' + y_weight + '&packages=' + y_packages + '&rate=' + rate + '&residential=' + y_residential;
								} else {
									gotoURL = './launch.php?courier=' + courier + '&url=http://' + website + '&svc=' + service + '&pzfrom=' + y_postal1 + '&pzto=' + y_postal2 + '&weight=' + y_weight + '&packages=' + y_packages + '&rate=' + rate + '&residential=' + y_residential;
									//gotoURL = './launch.php?courier=' + courier + '&url=http://' + website;
								}
								if (k<4) {
									r_len = '$ ' + rate + ' ' + courier + ' ' + service;
									r_len = r_len.length;
									cellWidth = parseInt(r_len * 6.5);
									if (cellWidth < 184) {
										cellWidth = 184;
									} else	if (cellWidth > 184) {
										rightBorder = 'border-right:1px solid #' + bg_col + '; ';
										cellWidth--;
									}
								}							
								cursorStyle = 'cursor:pointer; ';
								bg_colors[c] = bg_col;
								mo_js = ' onMouseOver="document.getElementById(\'rates_cell' + c + '\').style.backgroundColor=\'#bbeeee\';showDesc(this,\'' + service_desc + '\');" onMouseOut="document.getElementById(\'rates_cell' + c + '\').style.backgroundColor=\'#\'+bg_colors[' + c + '];hideDesc();" onClick="javascript:_gaq.push([\'_trackPageview\', \'Clickthrough: ' + courier + '\']);document.location=\'' + gotoURL + '\';"';
							}
							if (k==4) {
								cellWidth--;
							}
							rate_table+='<div class="rates_cell" style="' + cursorStyle + rightBorder + leftMargin + 'width:' + cellWidth + 'px; background-color:#' + bg_col + ';' + fWgt + '"' + rate_cell_divID + mo_js + '>' + r_str + '</div>';
							if ((rate_cell)&(cellWidth > 184)) {
								cellWidth = 184 - (cellWidth - 184);
							} else {
								cellWidth = 184;
							}
						}
						rate_table+="<br />";
					}}
				}
				rate_table+= '<div class="rates_top" style="margin-left:3px; margin-top:1px; width:943px; height:4px; font-size:1px; padding:0; line-height:1px;"></div><br />';
				document.title='ShipGooder: Shipping Rates from ' + y_postal1 + ' to ' + y_postal2;
			} else if (v_type == 1){
				var c_names_chk = new Array();
				var c_rates = new Array();
				var c_names = new Array();
				var c_name = '';
				var c_count = 0;
				var r_counts = new Array();
				var max_rows = 0;
				rate_table+= '<tr>';
				for (c=0;c<couriers.length;c++) {
					with (x_rates[c]) {
					if (courier_on[courier] == 1) {
						if (c_names_chk[courier] == null) {
							c_names_chk[courier] = courier;
							r_counts[courier] = 0;
							c_rates[courier] = new Array();
							c_rates[courier][r_counts[courier]++] = c;
							rate_table+= '<div class="rates_top"><b>' + courier + '</b></div>';
							c_names[c_count++]=courier;
							if (r_counts[courier] > max_rows) {
								max_rows = r_counts[courier];
							}
						} else {
							c_rates[courier][r_counts[courier]++] = c;
							if (r_counts[courier] > max_rows) {
								max_rows = r_counts[courier];
							}
						}
					}}
				}
				var numIterations = parseInt((c_count-1) / 5); //alert(numIterations);
				for (k=c_count;k<5;k++) {
					rate_table+= '<div class="rates_top">&nbsp;</div>';
				}
				rate_table+= '<br />';
				for (m=0;m<max_rows;m++) {
					rate_table+= '<tr>';
					for (k=0;k<c_count;k++) {
						c_name = c_names[k];
						bg_col = '#ececff';
						if (c_rates[c_name][m] != null) {
							c = c_rates[c_name][m];
							r_str = rate_string2(c);
							if (x_rates[c].subscriber == 'S') {
								bg_col = '#ffffff';
							}
							rate_table+='<div class="rates_cell" style="height:40px; background:' + bg_col + ';" id="rates_cell' + c + '">' + r_str + '</div>';
						} else {
							rate_table+= '<div class="rates_cell" style="height:40px; background:' + bg_col + ';">&nbsp;</div>';
						}
					}
					for (k=c_count;k<5;k++) {
						rate_table+= '<div class="rates_cell" style="height:40px; background:#ececff;">&nbsp;</div>';
					}
					rate_table+= '<br />';
				}
				document.title='ShipGooder: Couriers and Rates from ' + y_postal1 + ' to ' + y_postal2;
			} else if (v_type == 2){
				if (document.getElementById("map").style.display != 'block') {
					document.getElementById("map").style.display='block';
					document.getElementById("map_dist").style.display='block';
					document.title='ShipGooder: Map Route from ' + y_postal1 + ' to ' + y_postal2;
				}
				if ((y_postal1 != yy_postal1) || (y_postal2 != yy_postal2)) {
					mapload();
					yy_postal1 = y_postal1;
					yy_postal2 = y_postal2;
				}
				rate_table+='<div style="height:420px;"></div>';
			}

			if ((y_postal1 != yyy_postal1) || (y_postal2 != yyy_postal2) || (y_weight != yyy_weight) || (y_packages != yyy_packages)) {
				yyy_postal1 = y_postal1;
				yyy_postal2 = y_postal2;
				yyy_weight = y_weight;
				yyy_packages = y_packages;
				turn_time2=new Date().getTime();
				total_turn_time=turn_time2-turn_time;
				total_turn_time = total_turn_time / 1000;
			}

			if (v_type != 2){
				document.getElementById("map").style.display='none';
				document.getElementById("map_dist").style.display='none';
				rate_table+='<div style="border-bottom:1px solid #cccccc; background:#eeeeee; float:left; width:935px; text-align:center; margin-left:3px; padding:5px;">All rates are displayed in ' + currency[x_currency] + ' dollars.';
				if (x_currency == "CAD") {
					rate_table+=' Rates include fuel surcharges and G.S.T.';
				} else {
					rate_table+=' Rates include fuel surcharges.';
				}
				rate_table+='<br /><div style="color:#666666; font-size:10px;">Real-time quotes generated at ' + x_time + ' EDT in ' + x_extime + '.';
				rate_table+='&nbsp&nbsp;&nbsp;Total execution time: ' + total_turn_time + ' seconds';
				//rate_table+= '<div style="float:left; display:inline; margin-top:80px;"><img src="/images/sharethis.png" /></div>';
				//rate_table+= '<div style="float:left; display:inline; margin-top:80px;"><iframe src="http://www.facebook.com/plugins/like.php?href=http%253A%252F%252Fshipgooder.com%252F&amp;layout=button_count&amp;show_faces=true&amp;width=100&amp;action=like&amp;font&amp;colorscheme=light&amp;height=21" scrolling="no" frameborder="0" style="border:none; overflow:hidden; width:100px; height:21px;" allowTransparency="true"></iframe></div>';
				//rate_table+= '<div style="float:right; display:inline; margin-top:40px;">For History, Your Discounts, Reports...<br /><a href="http://shipgooderpro.com/"><img border="0" src="/images/smb2.png" /></a></div>';
				rate_table+= '<div style="float:none; width:100%; margin:15px 0 0 0; text-align:center;">';
				//rate_table+= 'Display rates from:&nbsp;';
				colCount = 0;
				for (c=0;c<courier_names.length;c++) {
					colCount++;
					if (colCount > 8) {
						colCount = 1;
						rate_table+= '<br />';
					}
					if (courier_name_chk[courier_names[c]] >= 1) {
						rate_table+= '<input style="border-color:#666666;" type="checkbox"';
						if (courier_on[courier_names[c]] == 1) {
							rate_table+= ' checked';
						}
						rate_table+= ' onClick="courier_on[\'' + courier_names[c] + '\']=Math.abs(courier_on[\'' + courier_names[c] + '\']-1);show_results(' + v_type + ');"> ' + courier_names[c] + '&nbsp;&nbsp;&nbsp;&nbsp;';
					}
				}
				rate_table+= '</div><div style="float:none; padding:10px;">';
				if (account) {
					rate_table+= '<a href="JavaScript:save_quote();" onMouseOver="icon_hi(4);" onMouseOut="icon_lo(4);"><img id="icon4" hspace="8" width="24" height="24" border="0" src="./images/icons/save_bw.gif" alt="Save these rates" title="Save these rates"></a>';
				}
				rate_table+= '<a href="rates_page.php?postal1=' + y_postal1 + '&postal2=' + y_postal2 + '&weight=' + y_weight + '&packages=' + y_packages + '&v_type=' + v_type + '&page=print" target="_print" onMouseOver="icon_hi(1);" onMouseOut="icon_lo(1);"><img id="icon1" hspace="8" width="24" height="24" border="0" src="./images/icons/print_bw.gif" alt="Print this page" title="Print this page"></a>';
				rate_table+= '<a href="rates3.php?pzfrom=' + y_postal1 + '&pzto=' + y_postal2 + '&weight=' + y_weight + '&packages=' + y_packages + '" onMouseOver="icon_hi(2);" onMouseOut="icon_lo(2);"><img id="icon2" hspace="8" width="24" height="24" border="0" src="./images/icons/export_bw.gif" alt="Save to spreadsheet" title="Save to spreadsheet"></a>';
				rate_table+= '<a href="mailto:?subject=ShipGooder.com: Shipping Rates from ' + y_postal1 + ' to ' + y_postal2 + '&body=http://shipgooder.com/rates_page.php?postal1=' + y_postal1 + '%26postal2=' + y_postal2 + '%26weight=' + y_weight + '%26packages=' + y_packages + '" onMouseOver="icon_hi(3);" onMouseOut="icon_lo(3);"><img id="icon3" hspace="8" width="24" height="24" border="0" src="./images/icons/email_bw.gif" alt="Email this page" title="Email this page"></a>';
				//rate_table+= '<a href="JavaScript:bookmark();" onMouseOver="icon_hi(5);" onMouseOut="icon_lo(5);"><img id="icon5" hspace="8" width="24" height="24" border="0" src="./images/icons/bookmark_bw.gif" alt="Bookmark this page" title="Bookmark this page"></a>';

				rate_table+= '</div></div></div>';
				if (couriers.length < 42) {
					//rate_table+='<img style="margin-top:20px; width="50" height="32" border="0" src="./images/smiley_half.gif">';
				}
			}
			if (numFeatured > 0) {
				echo_title = false;
				for (c=0;c<numFeatured;c++) {
					if (courier_on[featured[c]] == 1) {
						if (!echo_title) {
							rate_table += '<div style="float:left; text-align:left; width:700px; padding-left:120px; padding-top:30px;"><h1>Featured Couriers</h1>';
							echo_title = true;
						}
						try {
							a_link = '<a href="./click.php?courier=' + featured[c] + '&url=' + featured_web[featured[c]] + '" onClick="javascript:_gaq.push([\'_trackPageview\', \'Clickthrough: ' + featured[c] + '\']);">';
							rate_table += '<div style="float:left; margin-bottom:25px; width:700px;"><div class="text_content2"><h2>' + a_link + featured_nam[featured[c]] + '</a></h2></div>';
							rate_table += '<div style="width:200px;">' + a_link + '<img style="border:none; float:left;" src="' + featured_img[featured[c]] + '" /></a></div>';
							rate_table += '<div style="float:right; width:470px; color:#666666; line-height:130%;">' + featured_txt[featured[c]] + '<br /><div class="text_content2">' + a_link + featured_web[featured[c]].replace(/http:/i,'').replace(/\//g,'').replace(/shipgooder.com/i,'shipgooder.com/').replace(/comshipgooder/i,'com/shipgooder') + '</a></div></div></div>';
						} catch (err) {
						}
					}
				}
				rate_table += '</div>';
			}
			rate_table+='</center>';

			result_text.innerHTML=rate_table;

		} else {
			//document.getElementById("map").style.display='none';
			//document.getElementById("map_dist").style.display='none';
			rate_table='<br><br><center><table cellpadding="10" bgcolor="#efefef" width="550"><tr><td align="center"><b>Errors were encountered:</b><br><br>' + x_error_mess;
			rate_table+='<br><br><b>Questions? Comments?&nbsp;&nbsp;&nbsp;<div class="text_content2"><a class="text_content2" href="/contact_us/contact_feedback/">Please give us your feedback</a></div></b>';
			rate_table+='</td></tr></table></center>';
			result_text.innerHTML=rate_table;
		}
		if (v_type != 2){ 
			//setTimeout("cell_bgs()",100);
		}
	}

	function pause(milliseconds) {
		var dt = new Date();
		while ((new Date()) - dt <= milliseconds) { /* Do nothing */ }
	}

	function cell_bgs () {
		var couriers = xmlDoc.getElementsByTagName('courier');
		var c = 0;
		for (c=couriers.length-1;c>=0;c--) {
			if (bg_colors[c] != 'ffffff') {
				setTimeout('document.getElementById("rates_cell' + c + '").style.backgroundColor="#eeffff"',c*20);
			} else {
				setTimeout('document.getElementById("rates_cell' + c + '").style.backgroundColor="#eeffff"',c*20);
			}
			setTimeout('document.getElementById("rates_cell' + c + '").style.backgroundColor="#' + bg_colors[c] + '"',c*40);
		}
	}

	function format_state(s_str,s_type) {
		function cnvrt() {
            	return arguments[0].toUpperCase();
		}
		if ((x_international) & (s_type == 'to')) {
			s_str = s_str.toLowerCase().replace(/\b[a-z]/g, cnvrt);
			s_str = s_str.replace(/'S/g, "'s");
			return(s_str);
		}
		var s_code = s_str.substring(s_str.length-2,s_str.length);
		//s_str = s_str.replace(/\//g, "&&");
		if (s_str.indexOf('/') > 0) {
			s_str = s_str.substring(0,s_str.indexOf('/')+3);
		}
		s_str = s_str.toLowerCase().replace(/\b[a-z]/g, cnvrt);
		s_str = s_str.replace(/ De /g, " de ");
		s_str = s_str.replace(/ Del /g, " del ");
		s_str = s_str.replace(/Fpo/g, "FPO");
		s_str = s_str.replace(/Afb/g, "AFB");
		s_str = s_str.replace(/Apo/g, "APO");
		s_str = s_str.replace(/Nyc/g, "NYC");
		s_str = s_str.replace(/'S/g, "'s");
		s_str = s_str.substring(0,s_str.length-3)+', '+s_code;
		return(s_str);
	}

	function next_input(n_input) {
		var next_input_id = document.getElementById(n_input);
		next_input_id.focus();
		next_input_id.select();
	}


	function top_inputs() {
		var new_input = '<div style="position:absolute; width:100%; text-align:left; top:-60px; left:-20px; padding:0; margin:0;">';
		if (adv_interface != "1") {
			new_input+= '<div style="width:480px; border:1px solid #cccccc; background:#ffffee; color:#666666; padding:2px; font-size:11px; margin-bottom:3px;">&nbsp;<b>Change</b> the values in the fields below and press the <b>TAB</b> key to view <b>real-time updates</b>.&nbsp;</div>';
		}
		new_input+= '<b>From:</b> <input tabindex="1" type="text" id="x2_postal1" value="' + y_postal1 + '" size="6" maxlength="7" onClick="this.focus();this.select();" onChange="format_pz(this);next_input(\'x2_postal2\');" onBlur="format_pz(this);dim_weight();new_rates();">&nbsp;&nbsp;';
		new_input+= '<b>To:</b> <input tabindex="2" type="text" id="x2_postal2" value="' + y_postal2 + '" size="6" maxlength="7" onClick="this.focus();this.select();" onChange="format_pz(this);next_input(\'x2_weight\');" onBlur="format_pz(this);dim_weight();new_rates();">&nbsp;&nbsp;';
		//if (y_envelope == 'true') {
			//new_input+= '<div id="wgt2" style="display:none;"><b>Weight:</b> <input tabindex="3" type="text" id="x2_weight" value="' + y_weight + '" size="3" maxlength="5" onClick="this.focus();this.select();" onChange="GetNum(this);next_input(\'x2_postal1\');" onBlur="GetNum(this);dim_weight();new_rates();">&nbsp;&nbsp;</div>';
			//new_input+= '&nbsp;&nbsp;&nbsp;<input type="radio" name="envelope" id="envelope0" value="false" onClick="y_envelope=\'false\';document.getElementById(\'wgt2\').style.display=\'inline\';new_rates();"> Package&nbsp;&nbsp;&nbsp;';
			//new_input+= '<input type="radio" name="envelope" id="envelope1" value="true" checked onClick="y_envelope=\'true\';document.getElementById(\'wgt2\').style.display=\'none\';new_rates();"> Envelope';
		//} else {
			new_input+= '<div id="wgt2" style="display:inline;"><b>Weight:</b> <input tabindex="3" type="text" id="x2_weight" value="' + y_weight + '" size="3" maxlength="5" onClick="this.focus();this.select();" onChange="GetNum(this);next_input(\'x2_postal1\');" onBlur="GetNum(this);dim_weight();new_rates();">&nbsp;&nbsp;</div>';
			//new_input+= '&nbsp;&nbsp;&nbsp;<input type="radio" name="envelope" id="envelope0" value="false" checked onClick="y_envelope=\'false\';document.getElementById(\'wgt2\').style.display=\'inline\';new_rates();"> Package&nbsp;&nbsp;&nbsp;';
			//new_input+= '<input type="radio" name="envelope" id="envelope1" value="true" onClick="y_envelope=\'true\';document.getElementById(\'wgt2\').style.display=\'none\';new_rates();"> Envelope';
		//}
		if (adv_interface != "1") {
			new_input+= '<input type="hidden" id="x2_packages" value="' + y_packages + '">';
			//new_input+= '<b>Packages:</b> <input tabindex="4" type="text" id="x2_packages" value="' + y_packages + '" size="2" maxlength="3" onClick="this.focus();this.select();" onChange="GetNum(this);next_input(\'x2_postal1\');" onBlur="GetNum(this);dim_weight();new_rates();">&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;';
		} else {
			new_input+= '&nbsp;<b>Dimensional Weight:</b>&nbsp;<div id="dimWgtStr" style="display:inline;"></div>&nbsp;lbs';
			new_input+= '<br /><b>Packages:</b> <input tabindex="4" type="text" id="x2_packages" value="' + y_packages + '" size="2" maxlength="2" onClick="this.focus();this.select();" onChange="GetNum(this);next_input(\'x2_length\');" onBlur="GetNum(this);dim_weight();new_rates();">&nbsp;&nbsp;';
			new_input+= '<b>L:</b> <input tabindex="5" type="text" id="x2_length" value="' + y_length + '" size="2" maxlength="2" onClick="this.focus();this.select();" onChange="GetNum(this);next_input(\'x2_width\');dim_weight();" onBlur="GetNum(this);dim_weight();new_rates();">&nbsp;&nbsp;';
			new_input+= '<b>W:</b> <input tabindex="6" type="text" id="x2_width" value="' + y_width + '" size="2" maxlength="2" onClick="this.focus();this.select();" onChange="GetNum(this);next_input(\'x2_height\');dim_weight();" onBlur="GetNum(this);dim_weight();new_rates();">&nbsp;&nbsp;';
			new_input+= '<b>H:</b> <input tabindex="7" type="text" id="x2_height" value="' + y_height + '" size="2" maxlength="2" onClick="this.focus();this.select();" onChange="GetNum(this);next_input(\'x2_postal1\');dim_weight();" onBlur="GetNum(this);dim_weight();new_rates();">&nbsp;&nbsp;';
			new_input+= '<input tabindex="8" type="checkbox" id="x2_residential" value="y"';
			if (y_residential == "y") {
				new_input+= ' checked';
			}
			new_input+= ' onClick="dim_weight();new_rates();" onChange="dim_weight();new_rates();">&nbsp;Residential Dest.';
		}
		//new_input+= '<div class="text_content2" style="font-size:11px;"><a class="text_content2" href="./?adv_interface=1"> &raquo; Use ';
		//if (adv_interface == "1") {
		//	new_input+= 'Basic';
		//} else {
		//	new_input+= 'Advanced';
		//}
		//new_input+= '</a></div>';
		//new_input+= '</div>';
 		document.getElementById("input_box2").innerHTML=new_input;
 		document.getElementById("input_box2").style.display='inline';
		dim_weight(); //alert('welcome!');
		loadXML();
	}


	function dim_weight() {
		if (adv_interface == "0") {
			return;
		}
		gndFix = false;
		var len = document.getElementById("x2_length").value;
		var wid = document.getElementById("x2_width").value;
		var hgt = document.getElementById("x2_height").value;
		if (document.getElementById("x2_residential").checked == true) {
			y_residential = "y";
		} else {
			y_residential = "n";
		}
		var st1 = state_var1;
		var st2 = state_var2;
		var dim_weight_formula = 194;
		var dim_weight_label = "U.S. Domestic";
		var boxVolume = (len*wid*hgt);
		if ((boxVolume > 1500)&(boxVolume < 5184)) {
			gndFix = true;
		}
		if ((st1 == "AB") | (st1 == "BC") | (st1 == "MB") | (st1 == "NB") | (st1 == "NL") | (st1 == "NS") | (st1 == "NT") | (st1 == "NU") | (st1 == "ON") | (st1 == "PE") | (st1 == "QC") | (st1 == "SK") | (st1 == "YK")) {
			dim_weight_formula = 166;
			dim_weight_label = "International";
		}
		if ((st2 == "AB") | (st2 == "BC") | (st2 == "MB") | (st2 == "NB") | (st2 == "NL") | (st2 == "NS") | (st2 == "NT") | (st2 == "NU") | (st2 == "ON") | (st2 == "PE") | (st2 == "QC") | (st2 == "SK") | (st2 == "YK")) {
			dim_weight_formula = 166;
			dim_weight_label = "International";
		}
		if ((len > 0) && (wid > 0) && (hgt > 0)) {
			d_weight = (len * wid * hgt) / dim_weight_formula;
			d_weight = Math.ceil(d_weight);
			if (boxVolume > 1728) {
				if (d_weight > maxWeight) {
					d_weight = maxWeight;
				}
				if (d_weight > document.getElementById("x2_weight").value) {
					dimw_flag = 1;
				} else {
					dimw_flag = 0;
				}
			}
			document.getElementById("dimWgtStr").innerHTML = d_weight;
			new_rates();
		}
		document.getElementById("dimWgtStr").innerHTML = d_weight;
	}

	function toggle_adv() {
		if (adv_interface == "1") {
			adv_interface = "0";
		} else {
			adv_interface = 1;
		}
		top_inputs();
	}

	function new_rates() {
		if (old_browser) { return; }
		if ((yy_envelope == y_envelope) & (y_postal1 == document.quote_form.x2_postal1.value) & (y_postal2 == document.quote_form.x2_postal2.value) & (y_weight == document.quote_form.x2_weight.value) & (y_packages == document.quote_form.x2_packages.value)) {
			if (adv_interface != "1") {
				return;
			} else {
				if ((y_length == document.quote_form.x2_length.value) & (y_width == document.quote_form.x2_width.value) & (y_height == document.quote_form.x2_height.value) & (y_residential == yy_residential)) {
					 return;
				}
			}
		}

		if (document.quote_form.x2_weight.value > maxWeight) {
			y_weight = maxWeight;
		} else if (document.quote_form.x2_weight.value == 0) {
			y_weight = 1;
		} else if (document.quote_form.x2_weight.value < 0) {
			y_weight = document.quote_form.x2_weight.value * -1;
		} else if (document.quote_form.x2_weight.value - parseInt(document.quote_form.x2_weight.value) > 0) {
			y_weight = parseInt(document.quote_form.x2_weight.value);
		} else if (isNaN(document.quote_form.x2_weight.value)) {
			y_weight = 1;
		} else {
			y_weight = document.quote_form.x2_weight.value;
		}
		y_postal1 = document.quote_form.x2_postal1.value;
		y_postal2 = document.quote_form.x2_postal2.value;
		y_packages = document.quote_form.x2_packages.value;
		yy_envelope = y_envelope;

		if (adv_interface == "1") {
			y_length = document.quote_form.x2_length.value;
			y_width = document.quote_form.x2_width.value;
			y_height = document.quote_form.x2_height.value;
			if (document.quote_form.x2_residential.checked == true) {
				y_residential = "y";
			} else {
				y_residential = "n";
			}
			yy_residential = y_residential;
		}

		loadXML();
	}

	function format_price(num) {
		var result = Math.round(num*Math.pow(10,2))/Math.pow(10,2);
		result = result.toString();
		if (result.search(/\./) < 0) {
			result += '.00';
		} else	if (result.search(/\./) == (result.length-2)) {
			result += '0';
		}
		return result;
	}

	function rate_string(c_index) {
		with (x_rates[c_index]) {
			var theRate = '$ ' + addCommas(rate);
			if (subscriber === 'S') {
				var gotoURL = './click.php?courier=' + courier + '&url=http://' + website + '&svc=' + service + '&pzfrom=' + y_postal1 + '&pzto=' + y_postal2 + '&weight=' + y_weight + '&packages=' + y_packages + '&rate=' + rate + '&residential=' + y_residential;
			} else {
				//var gotoURL = './launch.php?courier=' + courier + '&url=http://' + website;
				var gotoURL = './launch.php?courier=' + courier + '&url=http://' + website + '&svc=' + service + '&pzfrom=' + y_postal1 + '&pzto=' + y_postal2 + '&weight=' + y_weight + '&packages=' + y_packages + '&rate=' + rate + '&residential=' + y_residential;
			}
			r_string = '<div class="t_left">&nbsp;<b>' + theRate + '</b></div><div class="t_right"><a href="' + gotoURL + '">' + courier + '</a>' + '&nbsp;&nbsp;' + service + '</div>';
			_gaq.push(['_trackPageview', 'Impressions: ' + courier]);
			return (r_string);
		}
	}


	function rate_string2(c_index) {
		with (x_rates[c_index]) {
			var theRate = '$ ' + addCommas(rate);
			if (subscriber === 'S') {
				var gotoURL = './click.php?courier=' + courier + '&url=http://' + website + '&svc=' + service + '&pzfrom=' + y_postal1 + '&pzto=' + y_postal2 + '&weight=' + y_weight + '&packages=' + y_packages + '&rate=' + rate + '&residential=' + y_residential;
			} else {
				var gotoURL = './launch.php?courier=' + courier + '&url=http://' + website + '&svc=' + service + '&pzfrom=' + y_postal1 + '&pzto=' + y_postal2 + '&weight=' + y_weight + '&packages=' + y_packages + '&rate=' + rate + '&residential=' + y_residential;
				//var gotoURL = './launch.php?courier=' + courier + '&url=http://' + website;
			}
			r_string = '<div class="t_left">&nbsp;<b>' + theRate + '</b></div><div class="t_right">&nbsp;<a href="' + gotoURL + '">' + courier + '</a><br />&nbsp;' + service + '</div>';
			_gaq.push(['_trackPageview', 'Impressions: ' + courier]);
			return (r_string);
		}
	}


	function save_quote() {
		if (old_browser) { return; }
		loadXML_sq();
	}


	function loadXML_sq() {
		if (old_browser) { return; }
		xmlHttp_sq[xml_index3]=GetXmlHttpObject();
		if (xmlHttp_sq[xml_index3]==null) {
			alert ("Your browser does not support AJAX!");
			return;
		}
		var url="save_quote.php";
		url=url+"?account="+account;
		url=url+"&pzfrom="+y_postal1;
		url=url+"&pzto="+y_postal2;
		url=url+"&weight="+y_weight;
		url=url+"&packages="+y_packages;
		url=url+"&length="+y_length;
		url=url+"&width="+y_width;
		url=url+"&height="+y_height;
		url=url+"&residential="+y_residential;
		xmlHttp_sq[xml_index3].onreadystatechange=stateChanged_sq;
		xmlHttp_sq[xml_index3].open("GET",url,true);
		xmlHttp_sq[xml_index3].send(null);
	}


	function stateChanged_sq() {
		if (old_browser) { return; }
		if (xmlHttp_sq[xml_index3].readyState==4) {
			alert('Your rate quote was saved successfully.\n\nTo view your saved quotes, click "My Account" above.');
			xml_index3++;
			if (xml_index3 > 9) {
				xml_index3=0;
			}
		}
	}

	function loadXML() {
		if (old_browser) { return; }
		turn_time=new Date().getTime();
		document.getElementById("status").innerHTML='<img width="16" height="16" border="0" src="./images/working.gif">&nbsp;Searching...';
		document.getElementById("status").style.visibility='visible';
		xmlHttp_full[xml_index2]=GetXmlHttpObject();
		if (xmlHttp_full[xml_index2]==null) {
			alert ("Your browser does not support AJAX!");
			return;
		}
		var url="rates2.php";
		url=url+"?pzfrom="+y_postal1;
		url=url+"&pzto="+y_postal2;
		if (y_envelope == 'true') {
			url=url+"&weight=ENV";
		} else {
			if ((adv_interface == "1") & (d_weight > y_weight)) {
				url=url+"&weight="+d_weight;
				if (gndFix) {
					url=url+"&gndfix="+y_weight;
				}
			} else {
				url=url+"&weight="+y_weight;
			}
		}
		url=url+"&packages="+y_packages;
		url=url+"&residential="+y_residential;
		if (account) {
			url=url+"&account="+account;
		}
		url=url+"&sid="+Math.random();
		xmlHttp_full[xml_index2].onreadystatechange=stateChanged_full;
		xmlHttp_full[xml_index2].open("GET",url,true);
		xmlHttp_full[xml_index2].send(null);
	}


	function stateChanged_full() {
		if (old_browser) { return; }
		if (xmlHttp_full[xml_index2].readyState==4) {
			xmlDoc=xmlHttp_full[xml_index2].responseXML.documentElement;
			x_error=xmlDoc.getElementsByTagName("error_code")[0].childNodes[0].nodeValue;
			x_error_mess=xmlDoc.getElementsByTagName("error_message")[0].childNodes[0].nodeValue;
			if (x_error == 0) {
				x_time=xmlDoc.getElementsByTagName("time")[0].childNodes[0].nodeValue;
				x_extime=xmlDoc.getElementsByTagName("executiontime")[0].childNodes[0].nodeValue;
				if (x_extime == " 0 msecs") {
					x_extime = "less than 0.015 seconds";
				} else {
					x_extime = x_extime.replace(/ /g, "");
					x_extime = x_extime.replace(/msecs/g, "");
					x_extime = x_extime / 1000;
					x_extime = x_extime + " seconds";
				}
				x_weight=xmlDoc.getElementsByTagName("weight")[0].childNodes[0].nodeValue;
				x_packages=xmlDoc.getElementsByTagName("packages")[0].childNodes[0].nodeValue;
				x_pzfromtown=xmlDoc.getElementsByTagName("pzfromtown")[0].childNodes[0].nodeValue;
				x_pztotown=xmlDoc.getElementsByTagName("pztotown")[0].childNodes[0].nodeValue;
				x_distance=xmlDoc.getElementsByTagName("distance")[0].childNodes[0].nodeValue;
				x_fromcountry=xmlDoc.getElementsByTagName("fromcountry")[0].childNodes[0].nodeValue;
				x_tocountry=xmlDoc.getElementsByTagName("tocountry")[0].childNodes[0].nodeValue;
				if (x_pztotown.length == 2) {
					x_international = true;
					x_flagfrom = '<img width="16" height="11" border="0" src="./images/icons/flags/' + x_fromcountry.toLowerCase() + '.png" />';
					x_flagto = '<img width="16" height="11" border="0" src="./images/icons/flags/' + x_pztotown.toLowerCase() + '.png" />';
					x_pztotown = x_tocountry;
				} else {
					x_international = false;
					x_flagfrom = '';
					x_flagto = '';
				}
				x_distance = x_distance.replace(/ /g, " ");
				if (x_fromcountry == "US") {
					x_distance = x_distance / 1.6;
				}
				x_distance = Math.round(x_distance);
				x_currency=xmlDoc.getElementsByTagName("currency")[0].childNodes[0].nodeValue;
				var couriers = xmlDoc.getElementsByTagName('courier');
				x_rates = new Array();
				for (c=0;c<couriers.length;c++) {
					var x_courier=xmlDoc.getElementsByTagName("courier")[c].childNodes[0].nodeValue;
					var x_service=xmlDoc.getElementsByTagName("service")[c].childNodes[0].nodeValue;
					var x_service_code=xmlDoc.getElementsByTagName("servicecode")[c].childNodes[0].nodeValue;
					try {
						var x_service_desc=xmlDoc.getElementsByTagName("servicedesc")[c].childNodes[0].nodeValue;
					} catch (err) {
						var x_service_desc='No service description';
					}
					var x_transit_days=xmlDoc.getElementsByTagName("transit")[c].childNodes[0].nodeValue;
					var x_rate=xmlDoc.getElementsByTagName("rate")[c].childNodes[0].nodeValue;
					var x_discount=xmlDoc.getElementsByTagName("discount")[c].childNodes[0].nodeValue;
					if (xmlDoc.getElementsByTagName("phone")[c].childNodes[0]) {
						var x_phone=xmlDoc.getElementsByTagName("phone")[c].childNodes[0].nodeValue;
					}
					var x_website=xmlDoc.getElementsByTagName("website")[c].childNodes[0].nodeValue;
					var x_svc_code=xmlDoc.getElementsByTagName("servicecode")[c].childNodes[0].nodeValue;
					var x_subscriber=xmlDoc.getElementsByTagName("type")[c].childNodes[0].nodeValue;
					x_rates[c] = new myRate(x_courier, x_service, x_service_desc, x_transit_days, x_rate, x_phone, x_website, x_svc_code, x_discount, x_subscriber);
				}
				if (x_pzfromtown != null) {
					if (x_pzfromtown.substring(1,4)!="Zip") {
						state_var1 = x_pzfromtown.substring(x_pzfromtown.length-2,x_pzfromtown.length);
						x_pzfromtown=format_state(x_pzfromtown,'from');
					}
				}
				if (x_pztotown != null) {
					if (x_pztotown.substring(1,4)!="Zip") {
						state_var2 = x_pztotown.substring(x_pztotown.length-2,x_pztotown.length);
						x_pztotown=format_state(x_pztotown,'to');
					}
				}
				courier_names = new Array();
				courier_name_chk = new Array();
				courier_on = Array();
				for (c=0;c<couriers.length;c++) {
					with (x_rates[c]) {
						if (courier_name_chk[courier] == null) {
							if (subscriber == 'S') {
								courier_name_chk[courier] = 2;
							} else {
								courier_name_chk[courier] = 1;
							}
							courier_names[courier_names.length] = courier;
							if (courier_on[courier] == null) {
								courier_on[courier] = 1;
							}
						}
					}
				}
				if (courier_name_chk['UPS']) {
					//courier_on['UPS'] = 0;
				}
			}
			xml_index2++;
			if (xml_index2 > 9) {
				xml_index2=0;
			}
			if (account) {
				if ((y_postal1.length == 5) & (y_postal2.length == 5)) {
					region_code = 0;
				} else if ((y_postal1.length == 6) & (y_postal2.length == 6)) {
					region_code = 1;
				} else if ((y_postal1.length == 6) & (y_postal2.length == 5)) {
					region_code = 2;
				}
			}
			show_results(last_view);
		}
	}

	function stopRKey(evt) {
		var evt = (evt) ? evt : ((event) ? event : null);
		var node = (evt.target) ? evt.target : ((evt.srcElement) ? evt.srcElement : null);
		if ((evt.keyCode == 13) && (node.type=="text"))  {return false;}
	}

	document.onkeypress = stopRKey;

	function icon_hi (i_num) {
		document.getElementById("icon"+i_num).src=document.getElementById("icon_on"+i_num).src;
	}
	function icon_lo (i_num) {
		document.getElementById("icon"+i_num).src=document.getElementById("icon_off"+i_num).src;
	}

	function bookmark() {

		var title = 'ShipGooder - Shipping Rates from ' + y_postal1 + ' to ' + y_postal2;
		var url = 'http://shipgooder.com/rates_page.php?postal1=' + y_postal1 + '&postal2=' + y_postal2 + '&weight=' + y_weight + '&packages=' + y_packages;
		if (window.sidebar) { // Mozilla Firefox Bookmark
			window.sidebar.addPanel(title, url,"");
		} else if (window.external ) { // IE Favorite
			window.external.AddFavorite( url, title);
		} else if (window.opera && window.print) { // Opera Hotlist
			return true;
		}
	}


