// var checkboxes = new Array();
var selectedboxes = new Array();
var QtyList = new Array();
var _total_ = null;
var jf_merchant_id = 'UzI0OmU2YzRHVzNSPgvd8srS09hdz09CP';


var navigateURL = '/scard/html/checkout.html'

function SetContent(element,content)
{
    var e = document.getElementById(element);
    if (e!=null)
    	e.innerHTML = content;
}
function GetContent(element)
{
  var e = document.getElementById(element);
  if (e==null)
  	return '';
  return e.innerHTML;

}

function ScartCalcTotal(_checked, pos)
{
  if (_checked)
  {
    SetContent('total_summary', (parseFloat(GetContent('total_summary'))+parseFloat(GetContent('price_'+pos))).toFixed(2));
  }
  else
  {
   SetContent('total_summary', (parseFloat(GetContent('total_summary')) - parseFloat(GetContent('price_'+pos))).toFixed(2));
  }
}

var CouponCallbacks = {
    success: function (o) {
  var r = YAHOO.lang.JSON.parse(o.responseText);
    if (r.res=='false')
    {
      alert(r.msg)
      return;
    }
    CheckoutCalcTotal();
    alert('Coupon applied: ' + r.msg);
    
  
},
failure: function (o) {
    alert("Async call failed!");
},
timeout : 30000
}


var CouponRemoveCallbacks = {
    success: function (o) {
  var r = YAHOO.lang.JSON.parse(o.responseText);
    if (r.res=='false')
    {
      alert(r.msg)
      return;
    }
    CheckoutCalcTotal();
},
failure: function (o) {
    alert("Async call failed!");
},
timeout : 30000
}


function ltrim(str, chars) {
    chars = chars || "\\s";
    return str.replace(new RegExp("^[" + chars + "]+", "g"), "");
}

function rtrim(str, chars) {
    chars = chars || "\\s";
    return str.replace(new RegExp("[" + chars + "]+$", "g"), "");
}

function CouponValidate(coupon_id)
{
    if (ltrim(coupon_id)!='')
    {
	YAHOO.util.Connect.asyncRequest("GET", "/_backend/Coupon/add/" +'?coupon_id=' + coupon_id + '&subtotal=' + document.getElementById('subtotal').innerHTML + '&r'  +new Date().getTime(), CouponCallbacks);
    }
    else
	inlineMsg('coupon_id','Please enter coupon code.',3);
}


function CouponRemove(coupon_id)
{
    
	YAHOO.util.Connect.asyncRequest("GET", "/_backend/Coupon/remove/" +'?coupon_id=' + coupon_id + '&r'  +new Date().getTime(), CouponRemoveCallbacks);
    
}

function AuctionCheck(position)
{
  var checkbox_curr = document.getElementById('checkbox_'+String(position));
  selectedboxes[position] = String(checkbox_curr.checked);
  if (position>1)
	{
	   var checkbox_prev = document.getElementById('checkbox_'+String(position-1));
	   if (!checkbox_curr.checked)
		{
			checkbox_prev.disabled=false;
		}
	   else
		{
			checkbox_prev.disabled=true;
			checkbox_prev.checked=true;

			AuctionCheck(position-1);
		}

	}
	ScartCalcTotal(checkbox_curr.checked,position)
}

var total_summary = 0;
var store_total = null;
var auction_query = '?';

function AuctionChecked(position)
{
	var checkbox = document.getElementById('checkbox_'+String(position));

	if (checkbox.checked)
	    {
	        store_total = document.getElementById('store_total');
		if (store_total==null)
		    store_total = '0';
		else  store_total = store_total.value;
		//SetContent('total_summary',(parseFloat(store_total) +  parseFloat(GetContent('price_1'))).toFixed(2));
		SetContent('total_summary',(parseFloat(store_total)));
	    }
	selectedboxes[1] = 'true';
  	AuctionCheck(position);
	auction_query = '?';
	for (var i = 1; i<checkboxes.length; i++)
	{
	if (i >1 ) auction_query = auction_query + '&';
	   val = selectedboxes[i];
	   if (val == null)
		val = 'false';
	   auction_query = auction_query + parseInt(checkboxes[i]) + '=' + val ;
	}
	//document.title=auction_query;
}



function CheckCheckboxes()
{

  for (var i=1; i<checkboxes.length;i++)
   {
	AuctionCheck(i)
	var checkbox = document.getElementById('checkbox_'+String(i));
	if (checkbox.checked)
	{
	  checkbox.disabled=true;
	}
   }
}

function Checkout1()
{
  //var params = '';
  //for (var i=1; i<checkboxes.length;i++)
  // {
//	checkbox = document.getElementById('checkbox_'+checkboxes[i]);
	//if (checkbox.checked)
	//	params = params+'/'+checkboxes[i];
   //}
   //alert(auction_query)
if (parseFloat(document.getElementById('total_summary').innerHTML)>0)
{
 	window.location = '/scard/html/checkout/' + new Date().getTime() +'.html' + auction_query;
 }
 else
 {
  alert('Please add to cart one or more products')
 }
}

///////////Checkout///////////////

var CheckoutCallBacks = {
    success: function (o) {
    var _total = YAHOO.lang.JSON.parse(o.responseText);
    SetContent('subtotal',_total.subtotal);
    SetContent('shipping_handling', _total.shipping_handling);
    SetContent('tax',_total.tax);
    SetContent('total',_total.total);
    document.getElementById('paypal_amount').value = _total.subtotal;
    document.getElementById('x_amount').value = _total.total;
    if (_total.coupon_type=='discount')
    {
	document.getElementById('paypal_discount_amount').value = _total.coupon_value;
    }
    if (_total.coupon_type=='percent_discount')
    {
	document.getElementById('paypal_discount_rate').value = _total.coupon_value;
    }
    document.getElementById('paypal_tax').value = _total.tax;
    document.getElementById('paypal_handling').value = _total.handling;
    document.getElementById('paypal_shipping').value = _total.shipping;
},
failure: function (o) {
    alert("Async call failed!");
},
timeout : 30000
}


var CalcTotal = {
    success: function (o) {
    var result = YAHOO.lang.JSON.parse(o.responseText);
    document.getElementById('coupon_description').innerHTML = result.discount.decription;
    document.getElementById('discount').className='';
    document.getElementById('amount').innerHTML=result.discount.amount;
    document.getElementById('paypal_discount_amount').value = result.discount.amount;
    var sm = document.getElementById('_shipping_method')
    sm.options.length = 0;
    var subtotal = document.getElementById('subtotal');
    var shipping_handling = document.getElementById('shipping_handling');
    var submit = document.getElementById('submit_btn');
    var tax = document.getElementById('tax');
    var total = document.getElementById('total');
    var r = result;
    result = result.calc;
    for (x in result)
     {
       sm.options[sm.length] = new Option(result[x].carrier + '      $' + result[x].shipping, result[x].identificator)
     }
    _total_ = result	;
    if (result.length==0)
     {
      	    subtotal.innerHTML = '0.00';
	    shipping_handling.innerHTML = '0.00'
	    tax.innerHTML = '0.00';
	    total.innerHTML = '0.00';
     }
    ShippingMethodChange();
},
failure: function (o) {
    alert("Async call failed!");
},
timeout : 30000
}



function ShippingMethodChange()
{
  var value = document.getElementById('_shipping_method').value;
  var subtotal = document.getElementById('subtotal');
  var shipping_handling = document.getElementById('shipping_handling');
  var handling = document.getElementById('handling');
  var submit = document.getElementById('submit_btn');
  var tax = document.getElementById('tax');
  var total = document.getElementById('total');
  var coupon_id = document.getElementById('_coupon_id').value;
  var coupon_value = document.getElementById('_coupon_value').value;
  var coupon_type = document.getElementById('_coupon_type').value;
  var coupon_name = document.getElementById('_coupon_name').value;
  var total_with_coupon_elem = document.getElementById('amount');
  for (x in _total_)
     {
       if (value==_total_[x].identificator)
        {
	
        //-------------------coupons section--------------------
        if ((coupon_type=='free_shipping') || (coupon_type=='discount') || (coupon_type=='percent_discount'))
        	{
        		total_with_coupon_elem.innerHTML = _total_[x].discount;
        	}
        //--------------------------------------------------

	    if (subtotal!=null)
		subtotal.innerHTML = _total_[x].subtotal;
		document.getElementById('paypal_amount').value = _total_[x].subtotal;
		if (document.getElementById('x_amount')!=null)
		    document.getElementById('x_amount').value = _total_[x].total;
	    if (shipping_handling!=null)
		shipping_handling.innerHTML = _total_[x].shipping_handling;
		document.getElementById('paypal_shipping').value = _total_[x].shipping;
	    if (tax!=null)
		tax.innerHTML = _total_[x].tax;
		document.getElementById('paypal_tax').value = _total_[x].tax;
	     if (total!=null)
		{
			total.innerHTML = _total_[x].total;
			if (parseInt(total.innerHTML)<0)
			{
				total.innerHTML = '0.00';
				document.getElementById('payment_method').className = 'hid';
			}
			else
			  document.getElementById('payment_method').className = 'full';
		}		
	    document.getElementById('paypal_handling').value = _total_[x].handling;
	    submit.className = 'but';
	 //if (coupon_type=='free_shipping')
        //	{
        //		document.getElementById('shipping_handling').value = (parseFloat(handling)).toFixed(2);
        //	}
	}
     }
  if (_total_.length==0)
     {
      	    subtotal.innerHTML = '0.00';
	    shipping_handling.innerHTML = '0.00'
	    tax.innerHTML = '0.00';
	    total.innerHTML = '0.00';
	    submit.className = 'hid';
     }
}

//function CheckoutCalcTotal()
//{
// _url = '/scard/html/calc/'+document.getElementById('_bill_to#_state').value+'/'+document.getElementById('_shipping_method').value;
// YAHOO.util.Connect.asyncRequest("POST", _url, CheckoutCallBacks);
//}

function ShowHideShipAddrsForm(checkbox)
{
 if (checkbox.checked)
     document.getElementById('ship_to').className='display_table'
 else
     document.getElementById('ship_to').className='display_none'
}


var BillAddressCallbacks = {
    success: function (o) {
  var response = o.responseText;
  if (response!='ok')
  {
    alert(o.responseText)
  }
  else
   {
    window.location = '/scard/html/final';
    }

},
failure: function (o) {
    alert("Async call failed!");
},
timeout : 30000
}

function PayPalPay(orderid)
{
    if (parseInt(document.getElementById('total').innerHTML) >0 ) { 	
     document.getElementById('paypal_orderNo').value = orderid;
     document.getElementById('paypal_orderDescr').value = 'TopJewels.com order #' + orderid;
     document.paypal_form.submit()
    }
    else 
    {
      window.location.href = 'https://www.topjewels.com/scard/html/receipt.html?invoice=' + orderid + '&payment_date=' +
      '&txn_id=' + orderid + '&payment_status=Approved&payment_gross=0.00&x_response_code=0' 
    }
}


var CSCallbacks = {
    success: function (o) {
  var r = YAHOO.lang.JSON.parse(o.responseText);
  document.getElementById('x_login').value = r.x_login;
  document.getElementById('x_fp_timestamp').value = r.x_fp_timestamp;
  document.getElementById('x_fp_hash').value = r.x_fp_hash;
  document.getElementById('x_fp_sequence').value = r.x_fp_sequence;
  document.authorizedotnet_sim_form.submit()
},

failure: function (o) {
    alert("Async call failed!");
},
timeout : 30000
}

function CyberSourcePay(orderid)
{
    document.getElementById('x_invoice_num').value = orderid;
    document.getElementById('x_description').value = 'TopJewels.com order #' + orderid;
    //--billing info
    document.getElementById('x_first_name').value = document.getElementById('_bill_to#_first_name').value;
    document.getElementById('x_last_name').value = document.getElementById('_bill_to#_last_name').value;
    document.getElementById('x_address').value = document.getElementById('_bill_to#_address').value;
    document.getElementById('x_city').value = document.getElementById('_bill_to#_city').value;
    if (document.getElementById('_bill_to#_country').value=='US')
	document.getElementById('x_state').value = document.getElementById('_bill_to#_state').value;
    else
	document.getElementById('x_state').value = document.getElementById('_bill_to#_not_usa_state').value;
    document.getElementById('x_zip').value = document.getElementById('_bill_to#_postal_code').value;
    document.getElementById('x_country').value = document.getElementById('_bill_to#_country').value;
    document.getElementById('x_phone').value = document.getElementById('_bill_to#_phone').value;
    document.getElementById('x_email').value = document.getElementById('_bill_to#_email').value;
    //--shipping info
    document.getElementById('x_ship_to_first_name').value = document.getElementById('_ship_to#_first_name').value;
    document.getElementById('x_ship_to_last_name').value = document.getElementById('_ship_to#_last_name').value;
    document.getElementById('x_ship_to_address').value = document.getElementById('_ship_to#_address').value;
    document.getElementById('x_ship_to_city').value = document.getElementById('_ship_to#_city').value;
    if (document.getElementById('_ship_to#_country').value=='US')
	document.getElementById('x_ship_to_state').value = document.getElementById('_ship_to#_state').value;
    else
	document.getElementById('x_ship_to_state').value = document.getElementById('_ship_to#_not_usa_state').value;
    document.getElementById('x_ship_to_zip').value = document.getElementById('_ship_to#_postal_code').value;
    document.getElementById('x_ship_to_country').value = document.getElementById('_ship_to#_country').value;

    uri = "/authorizedotnet/auth_params/" +new Date().getTime() + '?amount=' + document.getElementById('x_amount').value
    YAHOO.util.Connect.asyncRequest("GET",uri , CSCallbacks);
}


var fsCallbacks = {
    success: function (o) {
    var r = YAHOO.lang.JSON.parse(o.responseText);
    if (r.method=='paypal')
     {
        PayPalPay(r.order_id);
     }
    else
    {
	window.location = "/scard/html/receipt.html?invoice=" +r.invoice + "&payment_date=" + r.payment_date + "&txn_id=" + r.txn_id + "&payment_status=" + r.payment_status + "&payment_gross=" + r.payment_gross + "&x_response_code=" + r.reason_code;
    }
},

failure: function (o) {
    alert("Async call failed!");
},
timeout : 30000
}

function FinalSave()
{
  var formObject = document.getElementById('order_data');
  YAHOO.util.Connect.setForm(formObject);
  YAHOO.util.Connect.asyncRequest('POST', '/_backend/order/save', fsCallbacks);
}

var RegistrationCallbacks = {
    success: function (o) {
  var r = YAHOO.lang.JSON.parse(o.responseText);
  if (r[0]!=true)
  {
    var w = document.getElementById('please_wait');
    var submit_btn = document.getElementById('submit_btn');
    w.className = 'hid';
    submit_btn.disabled = false;
    alert(r[1]);
  }
  else
   {
     FinalSave();
    }
},
failure: function (o) {
    alert("Async call failed!");
},
timeout : 30000
}


function SaveOrder()
{
 document.getElementById('paypal_first_name').value = document.getElementById('_bill_to#_first_name').value;
 document.getElementById('paypal_last_name').value = document.getElementById('_bill_to#_last_name').value;
 document.getElementById('paypal_city').value = document.getElementById('_bill_to#_city').value;
 document.getElementById('paypal_zip').value = document.getElementById('_bill_to#_postal_code').value;

 var nameRegex = /^[a-zA-Z]+(([\'\,\.\- ][a-zA-Z ])?[a-zA-Z]*)*\.*$/;
 var emailRegex = /^[\w-\.]+@([\w-]+\.)+[\w-]{2,4}$/;

 if (document.getElementById('paypal_first_name').value=='')
    {
	//alert('First name is required field.');
	inlineMsg('_bill_to#_first_name','You must enter your first name.',3);
	return;
    }
 if (!document.getElementById('paypal_first_name').value.match(nameRegex))
  {
     inlineMsg('_bill_to#_first_name','You have entered an invalid name.',3);
     return;
  }

  if (document.getElementById('paypal_last_name').value=='')
    {
	//alert('First name is required field.');
	inlineMsg('_bill_to#_last_name','You must enter your last name.',3);
	return;
    }
 if (!document.getElementById('paypal_last_name').value.match(nameRegex))
  {
     inlineMsg('_bill_to#_last_name','You have entered an invalid name.',3);
     return;
  }

  if (document.getElementById('_bill_to#_address').value=='')
    {
	//alert('City is required field.');
	inlineMsg('_bill_to#_address','Address is required field.',3);
	return;
    }

 if (document.getElementById('paypal_city').value=='')
    {
	//alert('City is required field.');
	inlineMsg('_bill_to#_city','City is required field.',3);
	return;
    }

 if (!document.getElementById('paypal_city').value.match(nameRegex))
  {
     inlineMsg('_bill_to#_city','You have entered an invalid city name.',3);
     return;
  }
  if (document.getElementById('_bill_to#_country').value=='')
  {
         inlineMsg('_bill_to#_country','Country is required field.',3);
	 return;
  }
  if (document.getElementById('_bill_to#_country').value=='US')
  {
    if (document.getElementById('_bill_to#_state').value=='')
    {
         inlineMsg('_bill_to#_state','State is required field.',3);
         return;
    }
  }
  else
  {
    if (document.getElementById('_bill_to#_not_usa_state').value=='')
    {
         inlineMsg('_bill_to#_not_usa_state','.State is required field.',3);
         return;
    }
  }


 if (document.getElementById('paypal_zip').value=='')
    {
	inlineMsg('_bill_to#_postal_code','Zip/Postal Code is required field.',3);
	return;
    }

 if (document.getElementById('_bill_to#_phone').value=='')
    {
	inlineMsg('_bill_to#_phone','Phone is required field.',3);
	return;
    }

 if (document.getElementById('_bill_to#_email').value=='')
    {
	inlineMsg('_bill_to#_email','Email address is required field.',3);
	return;
    }

 if (!document.getElementById('_bill_to#_email').value.match(emailRegex))
    {
	inlineMsg('_bill_to#_email','You have entered an invalid email.',3);
	return;
    }

 //------------------------------------------------
  if (document.getElementById('_ship_to#_first_name').value=='')
    {
	//alert('First name is required field.');
	inlineMsg('_ship_to#_first_name','You must enter your first name.',3);
	return;
    }
 if (!document.getElementById('_ship_to#_first_name').value.match(nameRegex))
  {
     inlineMsg('_ship_to#_first_name','You have entered an invalid name.',3);
     return;
  }

  if (document.getElementById('_ship_to#_last_name').value=='')
    {
	//alert('First name is required field.');
	inlineMsg('_ship_to#_last_name','You must enter your last name.',3);
	return;
    }
 if (!document.getElementById('_ship_to#_last_name').value.match(nameRegex))
  {
     inlineMsg('_ship_to#_last_name','You have entered an invalid name.',3);
     return;
  }

 if (document.getElementById('_ship_to#_address').value=='')
    {
	//alert('First name is required field.');
	inlineMsg('_ship_to#_address','Address is required field.',3);
	return;
    }


  if (document.getElementById('_ship_to#_city').value=='')
    {
	//alert('City is required field.');
	inlineMsg('_ship_to#_city','City is required field.',3);
	return;
    }
 if (!document.getElementById('_ship_to#_city').value.match(nameRegex))
  {
     inlineMsg('_ship_to#_city','You have entered an invalid city name.',3);
     return;
  }

  if (document.getElementById('_ship_to#_country').value=='US')
  {
    if (document.getElementById('_ship_to#_state').value=='')
    {
         inlineMsg('_ship_to#_state','State is required field.',3);
         return;
    }
  }
  else
  {
    if (document.getElementById('_ship_to#_not_usa_state').value=='')
    {
         inlineMsg('_ship_to#_not_usa_state','State is required field.',3);
         return;
    }
  }

 if (document.getElementById('_ship_to#_postal_code').value=='')
    {
	inlineMsg('_ship_to#_postal_code','Zip/Postal Code is required field.',3);
	return;
    }

 if (document.getElementById('_ship_to#_email').value=='')
    {
	inlineMsg('_ship_to#_email','Email address is required field.',3);
	return;
    }

 if (!document.getElementById('_ship_to#_email').value.match(emailRegex))
    {
	inlineMsg('_ship_to#_email','You have entered an invalid email.',3);
	return;
    }

 if (document.getElementById('_payment_method').value=='2'){
  if (document.getElementById('cc_cn').value=='')
    {
	inlineMsg('cc_cn','Credit cart number is required field.',3);
	return;
    }

  if (document.getElementById('cc_cvv2').value=='')
    {
	inlineMsg('cc_ccv','Cart validation number is required field.',3);
	return;
    }

  if (document.getElementById('cc_e_month').value=='')
    {
	inlineMsg('cc_e_month','Expiration month is required field.',3);
	return;
    }
    
     if (document.getElementById('cc_e_year').value=='')
    {
	inlineMsg('cc_e_year','Expiration year is required field.',3);
	return;
    }
    
    }
 //------------------------------------------------


 if (document.getElementById('_password')!= null)
 {
  var password = document.getElementById('_password').value;
  var confirm = document.getElementById('_password_confirm').value;
  var _login = document.getElementById('_login').value;
  if (_login=='')
   {
    inlineMsg('_login','User name is required field.',3);
    return;
   }
   if (password=='')
   {
    inlineMsg('_password','Please enter your password and confirmation.',3);
    return;
   }
  if (password!=confirm)
   {
    inlineMsg('_password_confirm',"Password and confirm don't match",3);
    return;
   }
  }
  else
  {
    password = '';
    _login = '';
  }
  //var filter = /^([a-zA-Z0-9_\.\-])+\@(([a-zA-Z0-9\-])+\.)+([a-zA-Z0-9]{2,4})+$/;
  //if (!filter.test(_login)) {
//    alert('Please enter or provide a valid your email address');
//    document.getElementById('_bill_to#_email').focus;
//    return;
  //}
    var formData =
   '&email='+ document.getElementById('_bill_to#_email').value +
   '&first_name='+ document.getElementById('_bill_to#_first_name').value+
   '&last_name='+ document.getElementById('_bill_to#_last_name').value+
   '&phone='+ document.getElementById('_bill_to#_phone').value+
   '&b_first_name='+  document.getElementById('_bill_to#_first_name').value+
   '&b_last_name='+ document.getElementById('_bill_to#_last_name').value+
   '&b_phone='+  document.getElementById('_bill_to#_phone').value+
   '&b_company='+  document.getElementById('_bill_to#_company').value+
   '&b_email='+  document.getElementById('_bill_to#_email').value+
   '&b_address='+ document.getElementById('_bill_to#_address').value+
   '&b_address1='+ document.getElementById('_bill_to#_address1').value+
   '&b_city='+  document.getElementById('_bill_to#_city').value+
   '&b_state='+  document.getElementById('_bill_to#_state').value+
   '&b_not_usa_state='+  document.getElementById('_bill_to#_not_usa_state').value+
   '&b_zip='+  document.getElementById('_bill_to#_postal_code').value+
   '&b_country='+  document.getElementById('_bill_to#_country').value+
   '&s_first_name='+  document.getElementById('_ship_to#_first_name').value+
   '&s_last_name='+ document.getElementById('_ship_to#_last_name').value+
   '&s_phone='+  document.getElementById('_ship_to#_phone').value+
   '&s_company='+  document.getElementById('_ship_to#_company').value+
   '&s_email='+  document.getElementById('_ship_to#_email').value+
   '&s_address='+ document.getElementById('_ship_to#_address').value+
   '&s_address1='+ document.getElementById('_ship_to#_address1').value+
   '&s_city='+ document.getElementById('_ship_to#_city').value+
   '&s_state='+  document.getElementById('_ship_to#_state').value+
   '&s_not_usa_state='+  document.getElementById('_ship_to#_not_usa_state').value+
   '&s_zip='+  document.getElementById('_ship_to#_postal_code').value+
   '&s_country='+ document.getElementById('_ship_to#_country').value;
    var submit_btn = document.getElementById('submit_btn');
    if (_login!='')
	{
		formData+='&login=' + _login + '&password=' + password;	
	}
    var w = document.getElementById('please_wait');
    w.className = '';
    submit_btn.disabled = true;
    YAHOO.util.Connect.asyncRequest("POST", "/_backend/customers/update", RegistrationCallbacks,formData);
    return;

   //FinalSave();
}

function BillAddressAdd()
{
  var formData = '_bill_to#_name_attn='+document.getElementById('_bill_to#_name_attn').value+
  '&_bill_to#_address='+  document.getElementById('_bill_to#_address').value+
  '&_bill_to#_city='+  document.getElementById('_bill_to#_city').value+
  '&_bill_to#_state='+  document.getElementById('_bill_to#_state').value+
  '&_bill_to#_notinusa='+  document.getElementById('_bill_to#_notinusa').value+
  '&_bill_to#_country='+  document.getElementById('_bill_to#_country').value+
  '&_bill_to#_postal_code='+  document.getElementById('_bill_to#_postal_code').value+
  '&_bill_to#_phone='+  document.getElementById('_bill_to#_phone').value+
  '&_bill_to#_email='+  document.getElementById('_bill_to#_email').value+
  '&_ship_to#_name_attn='+document.getElementById('_ship_to#_name_attn').value+
  '&_ship_to#_address='+  document.getElementById('_ship_to#_address').value+ ' % ' +document.getElementById('_ship_to#_address1').value +
  '&_ship_to#_city='+  document.getElementById('_ship_to#_city').value+
  '&_ship_to#_state='+  document.getElementById('_ship_to#_state').value+
  '&_ship_to#_notinusa='+  document.getElementById('_ship_to#_notinusa').value+
  '&_ship_to#_country='+  document.getElementById('_ship_to#_country').value+
  '&_ship_to#_postal_code='+  document.getElementById('_ship_to#_postal_code').value+
  '&_ship_to#_phone='+  document.getElementById('_ship_to#_phone').value+
  '&_ship_to#_email='+  document.getElementById('_ship_to#_email').value+
  '&shipping_method='+  document.getElementById('_shipping_method').value;
   YAHOO.util.Connect.asyncRequest("POST", "/scard/html/billaddressadd", BillAddressCallbacks,formData);
}

function ProductQty(sku, qty)
{
   QtyList[sku] = qty;
   }



function BillingToShipping()
{

 if (document.getElementById('_checkbox').checked==true)
 {
  document.getElementById('_ship_to#_first_name').value = document.getElementById('_bill_to#_first_name').value;
  document.getElementById('_ship_to#_last_name').value = document.getElementById('_bill_to#_last_name').value;
  document.getElementById('_ship_to#_company').value = document.getElementById('_bill_to#_company').value;
  document.getElementById('_ship_to#_address').value = document.getElementById('_bill_to#_address').value;
  document.getElementById('_ship_to#_address1').value = document.getElementById('_bill_to#_address1').value;
  document.getElementById('_ship_to#_city').value = document.getElementById('_bill_to#_city').value;
  document.getElementById('_ship_to#_country').options[document.getElementById('_bill_to#_country').selectedIndex].selected = true;
  document.getElementById('_ship_to#_state').options[document.getElementById('_bill_to#_state').selectedIndex].selected = true;
  document.getElementById('_ship_to#_postal_code').value = document.getElementById('_bill_to#_postal_code').value;
  document.getElementById('_ship_to#_phone').value = document.getElementById('_bill_to#_phone').value;
  document.getElementById('_ship_to#_fax').value = document.getElementById('_bill_to#_fax').value;
  document.getElementById('_ship_to#_email').value = document.getElementById('_bill_to#_email').value;
  document.getElementById('_ship_to#_state').className = document.getElementById('_bill_to#_state').className;
  document.getElementById('_ship_to#_not_usa_state').className = document.getElementById('_bill_to#_not_usa_state').className;
  document.getElementById('_ship_to#_not_usa_state').value = document.getElementById('_bill_to#_not_usa_state').value;
  CheckoutCalcTotal();
  }
}
function FirstNameFieldChange()
{
if (document.getElementById('_checkbox').checked==true)
 {
    document.getElementById('_checkbox').checked=false;
 }
 document.getElementById('paypal_first_name').value = document.getElementById('_bill_to#_first_name').value;
}

function LastNameFieldChange()
{
if (document.getElementById('_checkbox').checked==true)
 {
    document.getElementById('_checkbox').checked=false;
 }
 document.getElementById('paypal_last_name').value = document.getElementById('_bill_to#_last_name').value;
}

function CompanyFieldChange()
{
if (document.getElementById('_checkbox').checked==true)
 {
    document.getElementById('_checkbox').checked=false;
 }
}

function AddressFieldChange()
{
if (document.getElementById('_checkbox').checked==true)
 {
    document.getElementById('_checkbox').checked=false;
 }
 document.getElementById('paypal_address1').value = document.getElementById('_bill_to#_address').value;
}

function CityFieldChange()
{
if (document.getElementById('_checkbox').checked==true)
 {
    document.getElementById('_checkbox').checked=false;
 }
 document.getElementById('paypal_city').value = document.getElementById('_bill_to#_city').value;
}

function BCountryChange()
{
 if (document.getElementById('_checkbox').checked==true)
 {
    document.getElementById('_checkbox').checked=false;
 }
 document.getElementById('paypal_country').value = document.getElementById('_bill_to#_country').value;
 if (document.getElementById('paypal_country').value=='US')
    {
	document.getElementById('_bill_to#_state').className = null;
	document.getElementById('_bill_to#_not_usa_state').className = 'hid';
    }
  else
  {
	document.getElementById('_bill_to#_state').className = 'hid';
	document.getElementById('_bill_to#_not_usa_state').className = null;
  }
}

function SCountryChange()
{
 if (document.getElementById('_checkbox').checked==true)
 {
    document.getElementById('_checkbox').checked=false;
 }
 if (document.getElementById('_ship_to#_country').value=='US')
    {
	document.getElementById('_ship_to#_state').className = null;
	document.getElementById('_ship_to#_not_usa_state').className = 'hid';
    }
  else
  {
	document.getElementById('_ship_to#_state').className = 'hid';
	document.getElementById('_ship_to#_not_usa_state').className = null;
  }

   CheckoutCalcTotal();
}


function CheckoutCalcTotal()
{
  var state = document.getElementById('_ship_to#_state').value;
  var country = document.getElementById('_ship_to#_country').value;
  if (country!="US")
    state = 'None';
  query = "/scard/calc?country=" + country + "&state=" + state+"&r=";
  YAHOO.util.Connect.asyncRequest("GET", query, CalcTotal);
}

function StateChange()
{
 if (document.getElementById('_checkbox').checked==true)
 {
    document.getElementById('_checkbox').checked=false;
 }
 document.getElementById('paypal_state').value = document.getElementById('_bill_to#_state').value;
}

function PostalCodeFieldChange()
{
if (document.getElementById('_checkbox').checked==true)
 {
    document.getElementById('_checkbox').checked=false;
 }
 document.getElementById('paypal_zip').value = document.getElementById('_bill_to#_postal_code').value;
}

function PhoneFieldChange()
{
if (document.getElementById('_checkbox').checked==true)
 {
    document.getElementById('_checkbox').checked=false;
 }
}

function FaxFieldChange()
{
if (document.getElementById('_checkbox').checked==true)
 {
    document.getElementById('_checkbox').checked=false;
 }
}

function EmailFieldChange()
{
document.getElementById('payer_email').value = document.getElementById('_bill_to#_email').value;
if (document.getElementById('_checkbox').checked==true)
 {
    document.getElementById('_checkbox').checked=false;
 }

}

