function rowMouseOver(objRow) {
	objRow.style.backgroundColor='#eee';
}
function rowMouseOut(objRow) {
	objRow.style.backgroundColor='';
}
function rowMouseOverPlus(objRow,plus) {
	objRow.style.backgroundColor='#eee';
	objRow.parentNode.rows[objRow.rowIndex + plus].style.backgroundColor='#eee';
}
function rowMouseOutPlus(objRow,plus) {
	objRow.style.backgroundColor='';
	objRow.parentNode.rows[objRow.rowIndex + plus].style.backgroundColor='';
}
function RadioCheck(objRadio, sName) {
	find_object('method' + objRadio).checked = true;
	refreshOrder(this, true);
}
function searchFocus(oInput) {
	var val = oInput.value;
	if (val == _searchDefault) {
	    oInput.value = ''; //remove the default text if it is present
	    //oInput.style.color='#000';
	    oInput.className = 'search_text'
	    //oInput.style.fontStyle='normal';
	}
	oInput.select();
}
function searchBlur(oInput) {
	var val = oInput.value;
	if (val == null || val.length == 0) {
	    oInput.value = _searchDefault;
	    //oInput.style.color='#888';
	    oInput.className = 'search_helptext'
	    //oInput.style.fontStyle='italic';
	}
}
function textFocus(obj) {
	obj.className = 'input-focus';
}
function textBlur(obj) {
	obj.className = 'input-blur';
}
function selectFocus(obj) {
	document.getElementById(obj).className = 'select-focus';
}
function selectBlur(obj) {
	document.getElementById(obj).className = 'select-blur';
}

function findPos() {
	var obj = document.getElementById('estimate');
	var curleft = curtop = 0;
	if (obj.offsetParent) {
		curleft = obj.offsetLeft
		curtop = obj.offsetTop
		while (obj == obj.offsetParent) {
			curleft += obj.offsetLeft
			curtop += obj.offsetTop
		}
	}
	return [curleft,curtop];
}

function formatCurrency(num) {
num = num.toString().replace(/\$|\,/g,'');
if(isNaN(num))
num = '0';
sign = (num == (num = Math.abs(num)));
num = Math.floor(num*100+0.50000000001);
cents = num%100;
num = Math.floor(num/100).toString();
if(cents < 10)
cents = '0' + cents;
for (var i = 0; i < Math.floor((num.length-(1+i))/3); i++)
num = num.substring(0,num.length-(4*i+3))+ ','+
num.substring(num.length-(4*i+3));
return (((sign)?'':'-') + '$' + num + '.' + cents);
}

function billDestinationChanged(el){
    changeDiv('billinginfo', ('billaddress' == el.value)?'block':'none');
}

function getCheckedValue(radioObj) {
	if(!radioObj)
		return "";
	var radioLength = radioObj.length;
	if(radioLength == undefined)
		if(radioObj.checked)
			return radioObj.value;
		else
			return "";
	for(var i = 0; i < radioLength; i++) {
		if(radioObj[i].checked) {
			return radioObj[i].value;
		}
	}
	return "";
}

function CheckPOBox() {
	var address1 = find_object('ShippingInfo_Address_Address').value.toUpperCase();
	var boxwarning = find_object('boxwarning');
	var boxstart = find_object('boxstart');
	var boxend = find_object('boxend');
	
	if (document.fmCheckout) {
		var shippingmethod = document.fmCheckout.ShippingMethodID;
		
		if(shippingmethod) {
			var smid = getCheckedValue(shippingmethod)
			
			if (smid == '1041' || smid == '1042' || smid == '1039' || smid == '1040' || smid == '1037' || smid == '1036' || smid == '1035' || smid == '1034' || smid == '1033' || smid == '1032' || smid == '1031') {
				if (address1.indexOf('P O BOX') == -1 && address1.indexOf('P. O. BOX') == -1 && address1.indexOf('POBOX') == -1 && address1.indexOf('PO BOX') == -1 && address1.indexOf('P.O. BOX') == -1 && address1.indexOf('P.O BOX') == -1 && address1.indexOf('PMB ') == -1 && address1.indexOf('PO. BOX') == -1) {
					boxwarning.style.visibility = 'hidden';
					boxwarning.style.display = 'none';
					boxstart.className = '';
					boxend.className = '';
				}
				else {
					boxwarning.style.visibility = 'visible';
					boxwarning.style.display = 'block';
					boxstart.className = 'err_start';
					boxend.className = 'err_end';
					pobox = true;
					//setTimeout("find_object('ShippingInfo_Address_Address').focus();",100);
				}
			}
			else {
				boxwarning.style.visibility = 'hidden';
				boxwarning.style.display = 'none';
			}
		}
	}
}

//---AceFlex---//
function GetResourceString(lKey, sDefaultValue){
	return sDefaultValue;
}
function Added() {
	alert(GetResourceString(81074, 'Your item has been added to your shopping cart'));
}
function OnLoad() {}

//--- Ajax implementation---//

function loadShippingMethods(countryID, prefix, useShipping)
{
  var xmlHttp = GetXmlHttpObject();
  if (xmlHttp != null)
  {
    var stateID='', postalCode='';
    var sel = document.getElementById('ShippingMethodID');
        if(sel != null) {
            //sel.disabled = true;
      while (sel.length > 0) {
        sel.options[0] = null;
      }
    }
    sel = find_object(prefix + 'StateID');
        if(sel != null) stateID = sel.value;
        sel = find_object(prefix + 'PostalCode');
        if(sel != null) postalCode = sel.value;
        
    var url = "ajax_contact.asp?OrderID="+sOrderID+"&CountryID="+countryID+"&GroupID="+sGroupID+"&Prefix="+prefix+"&UseShipping="+useShipping+"&StateID="+stateID+"&PostalCode="+postalCode;
    xmlHttp.onreadystatechange = function(){
        if (xmlHttp.readyState==4 || xmlHttp.readyState=="complete"){
            try{
                   eval(xmlHttp.responseText)
                }
                catch(e){};
            }
    };
    if (window.XMLHttpRequest){
            xmlHttp.open("GET",url,true);
        }
        else if (window.ActiveXObject){
            xmlHttp.open("GET",url,false);
        }
    xmlHttp.send(null);
  }
  else
  {
    Refresh();
  }
}

// update billinginfo and promotes order to open status
function updateBillingInfo(form){
  if(null == document.getElementById("ExpressCheckout"))
      return;
      
  if("undefined" == typeof(form)) return;
  
  var arrRequired = new Array("Contact_FirstName", "Contact_LastName", "Contact_Phone", 
          "Contact_Email", "Address_City", "Address_PostalCode", "Address_Address");
          
  var i;
  for(i=0; i<arrRequired.length; i++)
      if(form[arrRequired[i]].value == "") return;
  
    var xmlHttp = GetXmlHttpObject();
  if (xmlHttp != null){
    //    var progressDiv = find_object("progress_div");
    //if(progressDiv != null) progressDiv.display();
      
      var tmp = form.Action.value;
    form.Action.value = "ajax-updatebilling";
    var querystring = getFormElements(form);
    form.Action.value = tmp;
        
        var url = "ajax_order.asp";
    
    xmlHttp.onreadystatechange = function(){
        if (xmlHttp.readyState==4 || xmlHttp.readyState=="complete") {
                try{
                //var progressDiv = find_object("progress_div");
                    //if(progressDiv) progressDiv.hide();
            }
            catch(e){
                //alert(e);
            }
            finally{
                    //var progressDiv = find_object("progress_div");
                    //if(progressDiv) progressDiv.hide();
                };
            }
    }
    if (window.XMLHttpRequest){
            xmlHttp.open("POST",url,true);
        }
        else if (window.ActiveXObject){
            xmlHttp.open("POST",url,false);
        }
    xmlHttp.setRequestHeader("Content-Type", "application/x-www-form-urlencoded");
    xmlHttp.send(querystring);
  }
}

function refreshOrder(el, recalculate)
{
  if(document.getElementById('ExpressCheckout') == null)
      return;
      
  /*
  // in case there is no payment section and order total can change
  // call recalculate instead of refresh
  if (el.form.PaymentMethodID == null) {
      recalculateOrder();
      return;
  }
  */
  
    var xmlHttp=GetXmlHttpObject();
  if (xmlHttp != null)
  {
    //    var progressDiv = find_object('progress_div');
    //if(progressDiv != null) progressDiv.display();
    //var prefix = '';
    //if('shipaddress' == document.getElementById('ShipDestination').value){
        /*if('undefined' != typeof(el))
            if('Address_StateID' == el.name)
                return;*/
        prefix = 'ShippingInfo_';
    //}
    var elState = document.getElementById(prefix + 'Address_StateID');
    var lStateID='';
    if(elState != null){
        lStateID = elState.value;
    }
    
    var elPostalCode = document.getElementById(prefix + 'Address_PostalCode');
    var sPostalCode='';
    if(sPostalCode != null){
        sPostalCode = elPostalCode.value;
    }
    
    /*var elState = document.getElementById(prefix + 'ShippingInfo_Address_StateID');
    if(elState){
        elState.value = lStateID;
    }*/
    
    //var elShipping = document.getElementById('ShippingMethodID');
	var elShipping = document.fmCheckout.ShippingMethodID;
    var lShippingMethodID='';
    if(elShipping != null){
	    // TJM 11/10/07
        //lShippingMethodID = elShipping.value;
        //elShipping.disabled = true;
		var val = 0;
		
		for (i = 0; i < elShipping.length; i++) {
			if (elShipping[i].checked == true)
			lShippingMethodID = elShipping[i].value;
		}
		
	    // END TJM    
	}
    
    var url = "ajax_contact.asp?CurrentOrderID=" + sOrderID + "&CurrentShippingMethodID=" + lShippingMethodID + "&StateID=" + lStateID + "&Prefix=" + prefix + "&PostalCode=" + sPostalCode;
    xmlHttp.onreadystatechange = function(){
        if (xmlHttp.readyState==4 || xmlHttp.readyState=="complete") {
                try{
                eval(xmlHttp.responseText);
                var progressDiv = find_object('progress_div');
                    if(progressDiv) progressDiv.hide();
                     CheckPOBox();
            }
            catch(e){}
            finally{
                    var progressDiv = find_object('progress_div');
                    if(progressDiv) progressDiv.hide();
                };
            }
    };
    if (window.XMLHttpRequest){
            xmlHttp.open("GET",url,true);
        }
        else if (window.ActiveXObject){
            xmlHttp.open("GET",url,false);
        }
    xmlHttp.send(null);
  }
  else
  {
    if('undefined' == typeof(recalculate))
        Refresh();
    else{
        el.form.Action.value='recalculate';
        el.form.submit();
    }
  }
}

function recalculateOrder(){
    if(null == document.getElementById('ExpressCheckout'))
      return;
      
      
	var CountryID = find_object('ShippingInfo_Address_CountryID');
      
    
	if (CountryID.value == 223)  {
		if(find_object('ShippingInfo_Address_PostalCode').value=="" || find_object('ShippingInfo_Address_StateID').value=="")
			return;
	}
		      
    var xmlHttp=GetXmlHttpObject();
  if (xmlHttp != null){
        //var progressDiv = find_object('progress_div');
    //if(progressDiv != null) progressDiv.display();
    

      var form = document.fmCheckout;
    var tmp = form.Action.value;
    form.Action.value = 'ajax-recalculate';
    var querystring = getFormElements(form);
    form.Action.value = tmp;
        //var url = 'expresscheckout.asp?'+querystring;
        var url = 'expresscheckout.asp';
        /*
    var sel = document.getElementById('ShippingMethodID');
      while (sel.length > 0){
          sel.options[0] = null;
      }
      sel.disabled = true;
      */

    	find_object('divShippingMethodContainer').innerHTML = '<div class="loading"></div><div class="small"><strong>Loading...</strong></div>';
		      
      xmlHttp.onreadystatechange = function(){
        if (xmlHttp.readyState==4 || xmlHttp.readyState=="complete") {
        	clearTimeout(requestTimer); 
        	
			if (xmlHttp.status != 200)  {
				showShippingError();
				return;
			}
        	
            try{
                //sel.disabled = false;
                eval(xmlHttp.responseText);
                //var progressDiv = find_object('progress_div');
                //if(progressDiv) progressDiv.hide();
            }
            catch(e){
                showShippingError();
            }
            finally{
                    //var progressDiv = find_object('progress_div');
                    //if(progressDiv) progressDiv.hide();
                };
            }
    }

	var requestTimer = setTimeout(function() {
		xmlHttp.abort();
		showShippingError();
	}, 10000); 
    
    if (window.XMLHttpRequest){
            xmlHttp.open("POST",url,true);
        }
        else if (window.ActiveXObject){
            xmlHttp.open("POST",url,false);
        }
    xmlHttp.setRequestHeader("Content-Type", "application/x-www-form-urlencoded");
    xmlHttp.send(querystring);
  }
  else{
      var el=find_object('tdRecalculate');
        if(el != null) el.style.display='block';
    }
}

function showShippingError() {
	find_object('divShippingMethodContainer').innerHTML = find_object('divShippingError').innerHTML;
}

function selectForm(paymentType)
{
	var pCheckForm = document.getElementById('check-form');
	var pCardForm = document.getElementById('card-form');
	var pTitle = document.getElementById('title_grid');
	var pTitleSpace = document.getElementById('title_grid_space');

	pCardForm.style.display = 'none';
	pCheckForm.style.display = 'none';
	pTitle.style.display = 'none';
	pTitleSpace.style.display = 'none';

	if (paymentType == 'card')
	{		
		pCardForm.style.display = 'inline';
		pTitle.style.display = 'inline';
		pTitleSpace.style.display = 'inline';			
	}
	
	if (paymentType == 'check')
	{
		pCheckForm.style.display = 'inline';
		pTitle.style.display = 'inline';
		pTitleSpace.style.display = 'inline';			
	}	
	
}

function openAddressBookItem(id,customerID,paymentType)
{
	var xmlHttp=GetXmlHttpObject()
	
	if ((paymentType != 'card') && (paymentType != 'check')) {
		paymentType = '';
	}

	if (xmlHttp && (customerID.length > 0) && (id > 0)){
        //var progressDiv = find_object('progress_div');
	    //if(progressDiv) progressDiv.display();
		document.fmObject.ID.value = id.toString();
		document.fmObject.Action.value = 'update';
	
		setValue('Contact_FirstName','');
		setValue('Contact_LastName','');
		setValue('Contact_Company','');
		setValue('Address_Address','');
		setValue('Address_Address2','');
		setValue('Address_City','');
		setValue('Address_PostalCode','');
		setValue('Address_CountryID','');
		setValue('Contact_Phone','');
		setValue('Contact_Email','');

		/*
		var pPaymentType = document.getElementById('PaymentType');
		setValue('PaymentType',paymentType);
		pPaymentType.disabled = true;
		
		var pCheckForm = document.getElementById('check-form');
		var pCardForm = document.getElementById('card-form');
		var pTitle = document.getElementById('title_grid');
		var pTitleSpace = document.getElementById('title_grid_space');
		var pRemoveButton = document.getElementById('remove-button');

		pCardForm.style.display = 'none';
		pCheckForm.style.display = 'none';
		pTitle.style.display = 'none';
		pTitleSpace.style.display = 'none';
		pRemoveButton.style.display = 'inline'

		setValue('CashAssets_Name','');
		
		setValue('Type','');
		setValue('Number','');
		setValue('Name_cardholder','');
		setValue('ExpMonth','1');
		setValue('ExpYear','2007');
		
		setValue('Bank','');
		setValue('AccountNumber','');
		setValue('RoutingNumber','');
		setValue('BankAddress','');
		setValue('BankPhone','');
		setValue('FederalID','');		
		*/

		if (paymentType == 'card')
		{
			pTitle.style.display = 'inline';
			pTitleSpace.style.display = 'inline';
			pCardForm.style.display = 'block';
		}

		if (paymentType == 'check')
		{
			pTitle.style.display = 'inline';
			pTitleSpace.style.display = 'inline';
			pCheckForm.style.display = 'block';
		}

		var sel = document.getElementById('Address_StateID');

		while (sel.length > 0) {
			sel.options[0] = null;
		}
		
		if (window.ActiveXObject)
		{
			var td1 = document.getElementById('Address_StateID_1');
			var td2 = document.getElementById('Address_StateID_2');
			
			sel.disabled=true;
			td1.style.display='none';
			td2.style.display='none';
		}		

		var url = "ajax_contact.asp?AddressBookItemID="+id+"&ClientID="+customerID+"&PaymentType="+paymentType;
		xmlHttp.onreadystatechange = function(){
		    if (xmlHttp.readyState==4 || xmlHttp.readyState=="complete") {
		        eval(xmlHttp.responseText);
                var progressDiv = find_object('progress_div');
                if(progressDiv != null) progressDiv.hide();
            } 
		}
		 if (window.XMLHttpRequest)
		 {
				xmlHttp.open("GET",url,true);
		 }
		 else if (window.ActiveXObject)
		 {
				xmlHttp.open("GET",url,false);
		 }
		xmlHttp.send(null);	
	}
	else{
		window.location = location.pathname + "?ID="+id;
	}
}

function setValue(elementID, elementValue)
{
  var el = document.getElementById(elementID);
  if (el != null)
    el.value = elementValue;
    else{
        // try to find in forms
        for(i=0;i < document.forms.length; i++){
            el = document.forms[i].elements[elementID]
            if(el != null){
                el.value = elementValue;
                return;
            }
        }
    }
}

function loadAddressBook(addrBookID, prefix, clientID)
{
	var xmlHttp=GetXmlHttpObject();
	if (xmlHttp){
		if (addrBookID != 'empty')
		{
            //var progressDiv = find_object('progress_div');
            //if(progressDiv) progressDiv.display();
			//New address
			if (addrBookID == -1)
			{
				setValue(prefix+'Contact_FirstName','');
				setValue(prefix+'Contact_LastName','');
				setValue(prefix+'Contact_Company','');
				setValue(prefix+'Address_Address','');
				setValue(prefix+'Address_Address2','');
				setValue(prefix+'Address_City','');
				setValue(prefix+'Address_PostalCode','');
				setValue(prefix+'Address_CountryID','');
				setValue(prefix+'Contact_Phone','');
				setValue(prefix+'Contact_Email','');

				var sel = document.getElementById(prefix+'Address_StateID');

				while (sel.length > 0) {
					sel.options[0] = null;
				}
				
				if (window.ActiveXObject)
				{
					var td1 = document.getElementById(prefix + 'Address_StateID' + '_1');
					var td2 = document.getElementById(prefix + 'Address_StateID' + '_2');
					
					sel.disabled=true;
					td1.style.display='none';
					td2.style.display='none';
				}
			}

			//Copy Billing info to Shipping
			if (addrBookID == 0)
			{
				document.getElementById(prefix+'AddressBookItem').value = 'empty';

				setValue(prefix+'Contact_FirstName',document.getElementById('Contact_FirstName').value);
				setValue(prefix+'Contact_LastName',document.getElementById('Contact_LastName').value);
				setValue(prefix+'Contact_Company',document.getElementById('Contact_Company').value);
				setValue(prefix+'Address_Address',document.getElementById('Address_Address').value);
				setValue(prefix+'Address_Address2',document.getElementById('Address_Address2').value);
				setValue(prefix+'Address_City',document.getElementById('Address_City').value);
				setValue(prefix+'Address_PostalCode',document.getElementById('Address_PostalCode').value);
				setValue(prefix+'Address_CountryID',document.getElementById('Address_CountryID').value);
				setValue(prefix+'Contact_Phone',document.getElementById('Contact_Phone').value);
				setValue(prefix+'Contact_Email',document.getElementById('Contact_Email').value);

				var sel = document.getElementById(prefix+'Address_StateID');

				while (sel.length > 0) {
					sel.options[0] = null;
				}
				
				//if (window.ActiveXObject){
					var td1 = document.getElementById(prefix + 'Address_StateID' + '_1');
					var td2 = document.getElementById(prefix + 'Address_StateID' + '_2');
					
					sel.disabled=true;
					td1.style.display='none';
					td2.style.display='none';
				//}
				
				if (document.getElementById('Address_StateID').value > 0)
				{
					loadStates(document.getElementById('Address_CountryID').value,prefix);
					document.getElementById(prefix+'Address_StateID').value = document.getElementById('Address_StateID').value;
				}
			}
			
			//Load Address from Address Book
			if (addrBookID > 0)
			{		
				var url = "ajax_contact.asp?AddressBookID="+addrBookID+"&Prefix="+prefix+"&ClientID="+clientID;
				xmlHttp.onreadystatechange = function(){
				     if (xmlHttp.readyState==4 || xmlHttp.readyState=="complete") {
		                eval(xmlHttp.responseText);
                        var progressDiv = find_object('progress_div');
                        if(progressDiv != null) progressDiv.hide();
		                var el;
                        if(el=document.getElementById('tdRecalculate')) el.style.display='block';
                    }
				}
				 if (window.XMLHttpRequest)
				 {
						xmlHttp.open("GET",url,true);
				 }
				 else if (window.ActiveXObject)
				 {
						xmlHttp.open("GET",url,false);
				 }
				xmlHttp.send(null);
			}
		}
	}
	else
	{
		//Copy(this,prefix); //For Mozilla Firefox using old conception
	}
}

function loadStates(countryID, prefix)
{
  if (find_object('ExpressCheckout')) {
  		if (prefix == 'ShippingInfo_')
			recalculateExpressCheckout(countryID, prefix);
	}
	
	if (countryID > 0)
	{
        //var progressDiv = find_object('progress_div');
    	//if(progressDiv != null) progressDiv.display();
		if (prefix == "undefined") prefix = "";
		statePrefix = prefix + "Address_StateID";
        var sel = document.getElementById(statePrefix); //Object of <select> with id="{$prefix}Address_StateID"
      var xmlHttp=GetXmlHttpObject();
    if (xmlHttp != null)
		{
			while (sel.length > 0) {
		        sel.options[0] = null;
	        }
            sel.disabled = true;
		}
		else{
		    sel.form.action=location;
		    Refresh();
		    return;
		}
		
		var sel2 = find_object(prefix + "Address_StateID_1");
		if(sel2) {
			if(countryID == 223) sel2.innerHTML = 'State <span class="warning">*</span>'
			if(countryID == 38) sel2.innerHTML = 'Province <span class="warning">*</span>'
		}
		
		var url="ajax_contact.asp?CountryID="+countryID+"&Prefix="+statePrefix;
		xmlHttp.onreadystatechange = function(){
		    if (xmlHttp.readyState==4 || xmlHttp.readyState=="complete") {
		        try {
		       		eval(xmlHttp.responseText);
                var progressDiv = find_object('progress_div');
                    if(progressDiv) progressDiv.hide();
		        }
		        catch(e){
		        }
            finally{
                    var progressDiv = find_object('progress_div');
                    if(progressDiv) progressDiv.hide();
		        };
            } 
		}
		if (window.XMLHttpRequest){
        	xmlHttp.open("GET",url,true);
		}
		else if (window.ActiveXObject){
		    xmlHttp.open("GET",url,false);
		}
		xmlHttp.send(null);
	}
}

function recalculateExpressCheckout(countryID, prefix){
    /*var ShipDestination = document.fmCheckout.ShipDestination;
	theone = 0;
	if(document.getElementById('ShippingMethodID')) {
	    theone = ('shipaddress' == ShipDestination.value)?1:0;
		var shippingMethod = document.getElementById('ShippingMethodID').value;
		loadShippingMethods(countryID, prefix, theone);
		var shipping = document.getElementById('ShippingMethodID');
		var i = 1;
		while (i < shipping.length) {
			if (shipping.options[i].value == shippingMethod)
			{
				document.getElementById('ShippingMethodID').value = shippingMethod;
			}
			i++;
		}
	} else {
		loadShippingMethods(countryID, prefix, theone);
	}*/
	recalculateOrder();
	//loadPayments();
}

function shipDestinationChanged(el){
    changeDiv('shippinginfo', ('shipaddress' == el.value)?'block':'none');
    var prefix = ('shipaddress' == el.value)?'ShippingInfo_':'';
    
    if (document.getElementById('ExpressCheckout')) {
        xmlHttp=GetXmlHttpObject();
        if (xmlHttp != null)
	        recalculateExpressCheckout(find_object(prefix + 'Address_CountryID').value, prefix);
		else{
		    el.form.Action.value='recalculate';
		    el.form.submit();
		}
	}
}

function loadPayments(){
    var xmlHttp = GetXmlHttpObject();
    var settlePayment = false;
    if (xmlHttp)
  {
    //var progressDiv = find_object('progress_div');
    //if(progressDiv != null) progressDiv.display();
    var form = document.fmCheckout;
    if(!form){
      form = document.fmSettlePayment;
      settlePayment = true;
    }
    var tmp = form.Action.value;
    form.Action.value = 'ajax-payment-method';
    var querystring = getFormElements(form);
    form.Action.value = tmp;

    var url = ((settlePayment)?'settlepayment.asp?':'expresscheckout.asp?');

    xmlHttp.onreadystatechange = function(){
            if (xmlHttp.readyState==4 || xmlHttp.readyState=="complete"){
            try{
                    var sResponse = xmlHttp.responseText;
                    if(sResponse != ''){
                      var divPaymentMethodContainer = find_object('divPaymentMethodContainer');
                      if(divPaymentMethodContainer != null) divPaymentMethodContainer.innerHTML = sResponse;
                      var progressDiv = find_object('progress_div');
                        if(progressDiv) progressDiv.hide();
                  }
                }
                catch(e){}
                finally{
                    var progressDiv = find_object('progress_div');
                    if(progressDiv) progressDiv.hide();
                };
            }
    }
    if (window.XMLHttpRequest){
        xmlHttp.open("POST",url,true);
    }
    else if (window.ActiveXObject){
        xmlHttp.open("POST",url,false);
    }
    xmlHttp.setRequestHeader("Content-Type", "application/x-www-form-urlencoded");
    xmlHttp.send(querystring);
  }
  else
  {
    Refresh();
  }
}

function accumulateQueryString(queryString, newValues) {
    if(queryString == "") {
        queryString = newValues; 
    }
    else {
        queryString = queryString + "&" +  newValues;
    }
    return queryString;
}
    
function getFormElements(form){
    var querystring='';
    var formElements = new Array();
    if (form != null) {
        if (typeof form == "string") {
            var el = document.getElementById(form);
            if (el != null) {
                formElements = el.elements;
            }
        } else {
            formElements = form.elements;
        }
    }
    var values = toQueryString(formElements);
    return accumulateQueryString(querystring, values);
}

/** @private */
function toQueryString(elements) {
    var node = null;
    var qs = "";
    var name = "";
    
    var tempString = "";
    for(var i = 0; i < elements.length; i++) {
        tempString = "";
        node = elements[i];
        
        name = node.getAttribute("name");
        //use id if name is null
        if (!name) {
            name = node.getAttribute("id");
        }
        name = encodeURIComponent(name);
                
        if(node.tagName.toLowerCase() == "input") {
            if(node.type.toLowerCase() == "radio" || node.type.toLowerCase() == "checkbox") {
                if(node.checked) {
                    tempString = name + "=" + encodeURIComponent(node.value);
                }
            }
            
            if(node.type.toLowerCase() == "text" || node.type.toLowerCase() == "hidden" || node.type.toLowerCase() == "password") {
                tempString = name + "=" + encodeURIComponent(node.value);
            }
        }
        else if(node.tagName.toLowerCase() == "select") {
            tempString = getSelectedOptions(node);
        }
        
        else if(node.tagName.toLowerCase() == "textarea") {
            tempString = name + "=" + encodeURIComponent(node.value);
        }
        
        if(tempString != "") {
            if(qs == "") {
                qs = tempString;
            }
            else {
                qs = qs + "&" + tempString;
            }
        }
        
    }
    
    return qs;
}

/** @private */
function getSelectedOptions(select) {
    var options = select.options;
    var option = null;
    var qs = "";
    var tempString = "";
    
    for(var x = 0; x < options.length; x++) {
        tempString = "";
        option = options[x];
        
        if(option.selected) {
            tempString = encodeURIComponent(select.name) + "=" + encodeURIComponent(option.value);
        }
        
        if(tempString != "") {
            if(qs == "") {
                qs = tempString;
            }
            else {
                qs = qs + "&" + tempString;
            }
        }
    }
    
    return qs;
}
//---//

//-----AJAX routine-----//
function GetXmlHttpObject()
{ 
 var xmlHttp1 = false;
  try
    {
    // Firefox, Opera 8.0+, Safari
    xmlHttp1=new XMLHttpRequest();
    }
  catch (e)
    {
    // Internet Explorer
    try
      {
      xmlHttp1=new ActiveXObject("Msxml2.XMLHTTP"); //IE 6.0+
      }
    catch (e)
      {
      try
        {
        xmlHttp1=new ActiveXObject("Microsoft.XMLHTTP"); //IE 5.5+
        }
      catch (e)
        {
        alert("Your browser does not support AJAX!");
        return false;
        }
      }
    }
 return xmlHttp1;
}
//---//

function openWindow(url, name, width, height, features) {
	var win;
	var top = 0;
	var left = 0;
	
	if (screen.width > width) left = (screen.width - width) / 2;
	if (screen.height > height) top = (screen.height - height) / 2;
	
	if (typeof(features) == "undefined") win = window.open(url, name, 'left='+left+',top='+top+',screenX='+left+',screenY='+top+',width='+width+',height='+ height);
	else win = window.open(url, name, 'left='+left+',top='+top+',screenX='+left+',screenY='+top+',width='+width+',height='+ height +', ' + features);
		
	if (navigator.appName != 'Microsoft Internet Explorer')  { if ( window.focus )  win.focus()};
}
//------------image expancion--------------//

function preview(imgSource, id){
	var divElement = find_object('preview_div'+id);
	var imgElement = find_object('preview_img'+id);
	var imgThumb = find_object('thumb_img'+id);
	//var imgElement = divElement.firstChild.firstChild.firstChild.firstChild.firstChild.firstChild;
	//alert(imgElement.nodeName);
	
	if(!divElement || !imgElement) return;
	var top = 0;
	var left = 0;
	var width = parseInt(divElement.style.width);
	var height = parseInt(divElement.style.height);
	//if (screen.width > width) left = (screen.width - width)/2;
	//if (screen.height > height) top = (screen.height - height)/2;
    
	divElement.style.display = 'inline';
	
	init(imgElement, imgThumb);
	
	if (imgElement.inited){
		//divElement.style.width=imgElement.originalWidth;
		//divElement.height=imgElement.originalHeight;
		imgElement.expand();
	}
	//divElement.style.top = top;
	//divElement.style.left = left;
	
}
 
 function init(imgElement, imgThumb)
  {
   imgElement.originalHeight = imgElement.height;
   imgElement.originalWidth = imgElement.width;
   imgElement.width = imgThumb.width;
   if(parseInt(imgElement.originalWidth)>0) imgElement.height = parseInt(imgThumb.width) / parseInt(imgElement.originalWidth ) * parseInt(imgElement.originalHeight);
   
   imgElement.expand = function() 
        {
         var factor1 = Math.round(imgElement.height*.15);
		 var factor2 = Math.round(imgElement.width*.15);
         if(imgElement.width + factor2 < imgElement.originalWidth)
         {
          imgElement.width += factor2;
          imgElement.height += factor1;
          imgElement.imgDelayID = window.setTimeout(imgElement.expand,5);
         }
         else
         {
			
          imgElement.width = imgElement.originalWidth;
          imgElement.height = imgElement.originalHeight;
		  clearTimeout(imgElement.imgDelayID);
         }
        };
	imgElement.inited = true;
}

function closePreview(id){
    var imgElement = find_object('preview_img'+id);
    var imgThumb = find_object('thumb_img'+id);
	if(imgElement && imgThumb)
		if(imgElement.inited){
			clearTimeout(imgElement.imgDelayID);
			imgElement.height = imgElement.originalHeight;
			imgElement.width = imgElement.originalWidth;
			imgElement.inited = false;
	}
	setVisibility('preview_div'+id, false);
}

function setVisibility(objname, vis, type){
    var obj = find_object(objname);
    if(!obj) return;
    if('visibility' == type)
        obj.style.visibility = vis?'visible':'hidden';
    else
        obj.style.display = vis?'inline':'none';
    
    
}

function find_object(sID)
{
	if (document.getElementById)
	{
		return document.getElementById(sID);
	}
	else if (document.all)
	{
		return document.all[sID];
	}
	else if (document.layers)
	{
		return document.layers[sID];
	}
	else
	{
		return null;
	}
}

    //---//			