function GetXmlHttpObjectSC() {
var xmlHttpSC=null;
try
  {
  // Firefox, Opera 8.0+, Safari
  xmlHttpSC=new XMLHttpRequest();
  }
catch (e)
  {
  // Internet Explorer
  try
    {
    xmlHttpSC=new ActiveXObject("Msxml2.XMLHTTP");
    }
  catch (e)
    {
    xmlHttpSC=new ActiveXObject("Microsoft.XMLHTTP");
    }
  }
return xmlHttpSC;
}

var xmlHttpSC;



function stateChangedShip() { 
	if (xmlHttpSC.readyState==4) {
		document.getElementById('shippingCalc').innerHTML = xmlHttpSC.responseText;
	} else {
		document.getElementById('shippingCalc').innerHTML = 'Please wait<br><img src="/images/ajax-loader.gif" width="16" height="16">';
	}
}

function shippingEstimate(productId) {
	xmlHttpSC = GetXmlHttpObjectSC();
	if (xmlHttpSC==null) {
		alert ("Your browser does not support AJAX!");
		return;
	}
	
	var url = '/ajaxShipping.php';

	var postVals = 'sid=' + Math.random();
	postVals = postVals + '&product_id=' + escape(productId);


	xmlHttpSC.onreadystatechange = stateChangedShip;
	xmlHttpSC.open('POST', url, true);
	xmlHttpSC.setRequestHeader('Content-type', 'application/x-www-form-urlencoded');
	xmlHttpSC.setRequestHeader('Content-length', postVals.length);
	xmlHttpSC.setRequestHeader('Connection', 'close');
	xmlHttpSC.send(postVals);

}

function formShipProcess(productId) {

	var fCountryCode = document.frmShip.shipCountry[document.frmShip.shipCountry.selectedIndex].value;
	var fPostalCode = document.frmShip.shipPostal.value;

	// we just really care if we have a postal code
	// if it's US or Canada
	if (fCountryCode == 'US' || fCountryCode == 'CA') {
		if (fPostalCode.length < 5) {
			alert('Please enter your postal code.');
			return FALSE;
		}
	}

	// post back to our AJAX whack dope poo

	xmlHttpSC = GetXmlHttpObjectSC();
	if (xmlHttpSC==null) {
		alert ("Your browser does not support AJAX!");
		return;
	}
	
	var url = '/ajaxShipping.php';
	var postVals = 'sid=' + Math.random();
	postVals = postVals + '&action=setShippingAddress';
	postVals = postVals + '&countryCode=' + escape(fCountryCode);
	postVals = postVals + '&postalCode=' + escape(fPostalCode);
	postVals = postVals + '&product_id=' + escape(productId);


	xmlHttpSC.onreadystatechange = stateChangedShip;
	xmlHttpSC.open('POST', url, true);
	xmlHttpSC.setRequestHeader('Content-type', 'application/x-www-form-urlencoded');
	xmlHttpSC.setRequestHeader('Content-length', postVals.length);
	xmlHttpSC.setRequestHeader('Connection', 'close');
	xmlHttpSC.send(postVals);

}

function shippingChangeLocation (productId) {

	xmlHttpSC = GetXmlHttpObjectSC();
	if (xmlHttpSC==null) {
		alert ("Your browser does not support AJAX!");
		return;
	}
	
	var url = '/ajaxShipping.php';
	var postVals = 'sid=' + Math.random();
	postVals = postVals + '&action=resetLocation';
	postVals = postVals + '&product_id=' + escape(productId);


	xmlHttpSC.onreadystatechange = stateChangedShip;
	xmlHttpSC.open('POST', url, true);
	xmlHttpSC.setRequestHeader('Content-type', 'application/x-www-form-urlencoded');
	xmlHttpSC.setRequestHeader('Content-length', postVals.length);
	xmlHttpSC.setRequestHeader('Connection', 'close');
	xmlHttpSC.send(postVals);


}

function openResource(resourceId,wWidth,wHeight) {
        openUrl = '/product_resource?resource_id=' + resourceId;
        winName = 'resource';
        features = 'scrollbars=yes,resizable=yes,width=' + wWidth + ',height=' + wHeight;
        window.open(openUrl,winName,features);
}
