var req = new empireAJAX();

function changeCountry(_order_id){
var _country;
_country = document.forms["ship_calc"].calc_country.options[document.forms["ship_calc"].calc_country.selectedIndex].value;
req.reset();
req.addParameter('order_id', _order_id);
req.addParameter('country', _country);
req.setURL('/rpc_calls/ship_calculator.asp');
req.setMethod('get');
req.setAsynch(true);
req.cacheResponse(false);
req.setCallback(processResponse);
sent = req.send();
}

function processResponse(){
var _xml = new REXML(req.getResponseText());
var _openhtml;
var _closehtml;
var _innerhtml;
var l_html = '';
var _freeMsg = 'False';

_openhtml = '<table width="100%" cellpadding="0" cellspacing="0" border="0" bgcolor="#ffffff">';

_closehtml = '</table>';

_innerhtml = '';
//parse the xml and generate the html
for (var i=0; i < _xml.rootElement.childElements.length; i++){
_innerhtml = _innerhtml + '<tr><td style="padding-top:5px;padding-bottom:5px;padding-left:7px;padding-right:7px" class="fontmedium" valign="middle" align="left" bgcolor="#f2f2f2" nowrap>';
_innerhtml = _innerhtml + '<b>' + _xml.rootElement.childElements[i].childElement("name").text + '</b></td>';
_innerhtml = _innerhtml + '<td style="padding-top:5px;padding-bottom:5px;padding-right:7px" class="fontmedium" bgcolor="#f2f2f2" valign="middle" align="right">';
if (_xml.rootElement.childElements[i].childElement("rate").text == '0.00'){
_innerhtml = _innerhtml + '<font color="#c02020"><b>FREE';
_freeMsg = 'False';
} else {
if (_xml.rootElement.childElements[i].childElement("name").text == 'Standard Shipping' && _xml.rootElement.childElements[i].childElement("orderfreeshipeligible").text == 'True')
{
_innerhtml = _innerhtml + '<b>$' + _xml.rootElement.childElements[i].childElement("rate").text + '<font color="#c02020">*</font>';
_freeMsg = 'True';
}
else
{
_innerhtml = _innerhtml + '<b>$' + _xml.rootElement.childElements[i].childElement("rate").text;
_freeMsg = 'False';
}
}

if (_freeMsg == 'True')
{
_innerhtml = _innerhtml + '</b></font></td></tr><tr><td style="padding-top:5px;padding-bottom:5px;" class="fontmedium" valign="middle" align="center" bgcolor="#f2f2f2" colspan="2" nowrap><font color="#c02020"><b>*Free on orders $25 or more</b></font></td></tr>';
}
else
{
_innerhtml = _innerhtml + '</b></font></td></tr>';
}

if (i < _xml.rootElement.childElements.length - 1){
//put the spacer in
_innerhtml = _innerhtml + '</tr><tr bgcolor="#ffffff"><td colspan="2"><img src="http://cdn1b.dvdempire.org/res/pm/blank.gif" align="left" width="1" height="1" hspace="0" vspace="0"></td>';
_innerhtml = _innerhtml + '</tr>';
}
}

if (_innerhtml != ''){
l_html = _openhtml + _innerhtml + _closehtml;
}

//write it out
if (document.layers) {
//NN4
tempLayer = document.layers["shipCalcDisplay"];
if (tempLayer != null && l_html != ''){
tempLayer.document.open();
tempLayer.document.write(l_html);
tempLayer.document.close();
}
}
if (document.all) {
//ie
tempLayer = document.all["shipCalcDisplay"];
if (tempLayer != null && l_html != ''){
tempLayer.innerHTML = l_html;
}
}
if(!document.all && document.getElementById){
//NN6
tempLayer = document.getElementById("shipCalcDisplay");
if (tempLayer != null && l_html != ''){
tempLayer.innerHTML = l_html;
}
}
}
