function MM_swapImgRestore() { //v3.0
  var i,x,a=document.MM_sr; for(i=0;a&&i<a.length&&(x=a[i])&&x.oSrc;i++) x.src=x.oSrc;
}

function MM_preloadImages() { //v3.0
  var d=document; if(d.images){ if(!d.MM_p) d.MM_p=new Array();
    var i,j=d.MM_p.length,a=MM_preloadImages.arguments; for(i=0; i<a.length; i++)
    if (a[i].indexOf("#")!=0){ d.MM_p[j]=new Image; d.MM_p[j++].src=a[i];}}
}

function MM_findObj(n, d) { //v4.01
  var p,i,x;  if(!d) d=document; if((p=n.indexOf("?"))>0&&parent.frames.length) {
    d=parent.frames[n.substring(p+1)].document; n=n.substring(0,p);}
  if(!(x=d[n])&&d.all) x=d.all[n]; for (i=0;!x&&i<d.forms.length;i++) x=d.forms[i][n];
  for(i=0;!x&&d.layers&&i<d.layers.length;i++) x=MM_findObj(n,d.layers[i].document);
  if(!x && d.getElementById) x=d.getElementById(n); return x;
}

function MM_swapImage() { //v3.0
  var i,j=0,x,a=MM_swapImage.arguments; document.MM_sr=new Array; for(i=0;i<(a.length-2);i+=3)
   if ((x=MM_findObj(a[i]))!=null){document.MM_sr[j++]=x; if(!x.oSrc) x.oSrc=x.src; x.src=a[i+2];}
}

function getUrl(postid) {
    var d = new Date();
    var time = d.getTime();
	var url = '/postal'+postid+'.pgm';
//  This will force IE to show a fresh version (uncache the url) of your request all the time.
    url = url + '&time='+time;	
	return url;
}

function doPostal_1(postid) {
	// This function is fired by bill-to country select.
	var url = getUrl(postid);
    var pars = 'MODULE=POSTAL&ACTION=DSPPOST&TYPE=BILL&LANGUAGE='+escape($F('LANGUAGE'));	
        pars = pars + '&COUNTRY='+escape($F('BILLCOUNTRY'));  
	var target = 'stuffin1';
    var handlerFunc = function(t) { $('stuffin1').innerHTML=t.responseText; }
    var errFunc = function(t) { $('stuffin1').innerHTML=t.responseText; }			   				   
	// Synchronous ajax required so we can change focus afterward
    var myAjax = new Ajax.Updater(target, url, {method:'get', asynchronous:false, parameters:pars,
	             onSuccess:handlerFunc, onFailure:errFunc});
	if (typeof(document.frmMain.BILLCITYSELECT) != 'undefined') {
		// First redirect focus to get it off phone.  Then get it where it belongs.
		$('BILLCITY').focus();
		return true;
	}
	$('BILLCOUNTRY').focus();
}	

function doPostal_2(postid) {
	// This function is fired by ship-to country select.
	var url = getUrl(postid);
    var pars = 'MODULE=POSTAL&ACTION=DSPPOST&TYPE=SHIP&LANGUAGE='+escape($F('LANGUAGE'));	
        pars = pars + '&COUNTRY='+escape($F('SHIPCOUNTRY'));  	  
	var target = 'stuffin2';
    var handlerFunc = function(t) { $('stuffin2').innerHTML=t.responseText; }
    var errFunc = function(t) { $('stuffin2').innerHTML=t.responseText; }			   				   
	// Synchronous ajax required so we can change focus afterward
    var myAjax = new Ajax.Updater(target, url, {method:'get', asynchronous:false, parameters:pars,
	             onSuccess:handlerFunc, onFailure:errFunc});
	if (typeof(document.frmMain.SHIPCITYSELECT) != 'undefined') {
		// First redirect focus to get it off phone.  Then get it where it belongs.
		$('SHIPCITY').focus();
		return true;
	}
	$('SHIPCOUNTRY').focus();
}

function doPostal_3(postid) {
	// This function is fired by bill-to postal code blur.
	var url = getUrl(postid);
    var pars = 'MODULE=POSTAL&ACTION=DSPSTATE&TYPE=BILL&LANGUAGE='+escape($F('LANGUAGE'));	
        pars = pars + '&COUNTRY='+escape($F('BILLCOUNTRY'))+'&POSTALCD='+escape($F('BILLPOSTALCD'));
	var target = 'stuffin1';
    var handlerFunc = function(t) { $('stuffin1').innerHTML=t.responseText; }
    var errFunc = function(t) { $('stuffin1').innerHTML=t.responseText; }
	// Synchronous ajax required so we can change focus afterward
	var myAjax = new Ajax.Updater(target, url, {method:'get', asynchronous:false, parameters:pars,
	             onSuccess:handlerFunc, onFailure:errFunc});

	if (typeof(document.frmMain.BILLSTATESELECT) != 'undefined') {
		// First redirect focus to get it off phone.  Then get it where it belongs.
		$('BILLCITY').focus();
		return true;
	}
	if (typeof(document.frmMain.BILLCITYSELECT) != 'undefined') {
		// First redirect focus to get it off phone.  Then get it where it belongs.
		$('BILLCOUNTY').focus();
		return true;
	}
	if (typeof(document.frmMain.BILLCOUNTYSELECT) != 'undefined') {
		// First redirect focus to get it off phone.  Then get it where it belongs.
		$('BILLSTATE').focus();
		return true;
	}
	$('BILLCOUNTRY').focus();
}

function doPostal_4(postid) {
// This function is fired by ship-to postal code blur.
//  var tt=postid;
//	alert('PostID='+tt)
    var url = getUrl(postid);
    var pars = 'MODULE=POSTAL&ACTION=DSPSTATE&TYPE=SHIP&LANGUAGE='+escape($F('LANGUAGE'));	
        pars = pars + '&COUNTRY='+escape($F('SHIPCOUNTRY'))+'&POSTALCD='+escape($F('SHIPPOSTALCD'));
	var target = 'stuffin2';
    var handlerFunc = function(t) { $('stuffin2').innerHTML=t.responseText; }
    var errFunc = function(t) { $('stuffin2').innerHTML=t.responseText; }			   				   
	// Synchronous ajax required so we can change focus afterward
	var myAjax = new Ajax.Updater(target, url, {method:'get', asynchronous:false, parameters:pars,
	             onSuccess:handlerFunc, onFailure:errFunc});

	if (typeof(document.frmMain.SHIPSTATESELECT) != 'undefined') {
		// First redirect focus to get it off phone.  Then get it where it belongs.
		$('SHIPCITY').focus();
		return true;
	}
	if (typeof(document.frmMain.SHIPCITYSELECT) != 'undefined') {
		// First redirect focus to get it off phone.  Then get it where it belongs.
		$('SHIPCOUNTY').focus();
		return true;
	}
	if (typeof(document.frmMain.SHIPCOUNTYSELECT) != 'undefined') {
		// First redirect focus to get it off phone.  Then get it where it belongs.
		$('SHIPSTATE').focus();
		return true;
	}
//	$('SHIPCOUNTRY').focus();
	$('PHONE').focus();	
}

function doPostal_5(postid) {	
	// This function is fired by bill-to county select.
// If there are multiple city/county combinations, edit them to be sure the selections are valid.     
  if (document.frmMain.BILLCITY.value.length > 0 && document.frmMain.BILLCOUNTY.value.length > 0) { 
	var url = getUrl(postid);
    var pars = 'MODULE=POSTAL&ACTION=CHKCOUNTY&TYPE=BILL&LANGUAGE='+escape($F('LANGUAGE'));	
        pars = pars + '&COUNTRY='+escape($F('BILLCOUNTRY'))+'&POSTALCD='+escape($F('BILLPOSTALCD'));
        pars = pars + '&STATE='+escape($F('BILLSTATE'))+'&CITY='+escape($F('BILLCITY'));
        pars = pars + '&COUNTY='+escape($F('BILLCOUNTY'));		
    var target = 'stuffin1';
    var handlerFunc = function(t) { $('stuffin1').innerHTML=t.responseText; }
    var errFunc = function(t) { $('stuffin1').innerHTML=t.responseText; }			   				   
    var myAjax = new Ajax.Updater(target, url, {method:'get', parameters:pars,
	             onSuccess:handlerFunc, onFailure:errFunc});
  }
}

function doPostal_6(postid) {	
	// This function is fired by ship-to county select.
// If there are multiple city/county combinations, edit them to be sure the selections are valid.     
  if (document.frmMain.SHIPCITY.value.length > 0 && document.frmMain.SHIPCOUNTY.value.length > 0) { 
	var url = getUrl(postid);
    var pars = 'MODULE=POSTAL&ACTION=CHKCOUNTY&TYPE=SHIP&LANGUAGE='+escape($F('LANGUAGE'));	
        pars = pars + '&COUNTRY='+escape($F('SHIPCOUNTRY'))+'&POSTALCD='+escape($F('SHIPPOSTALCD'));
        pars = pars + '&STATE='+escape($F('SHIPSTATE'))+'&CITY='+escape($F('SHIPCITY'));
        pars = pars + '&COUNTY='+escape($F('SHIPCOUNTY'));		
    var target = 'stuffin2';
    var handlerFunc = function(t) { $('stuffin2').innerHTML=t.responseText; }
	var errFunc = function(t) { $('stuffin2').innerHTML=t.responseText; }
    var myAjax = new Ajax.Updater(target, url, {method:'get', parameters:pars,
	             onSuccess:handlerFunc, onFailure:errFunc});
  }
}
