jQuery().ready(function(){
		var wizard = $("#wizard").accordion({
			header: '.title',
			event: false,
			autoheight: false 

		});
		
		var wizardButtons = $([]);
		$("div.title", wizard).each(function(index) {
			wizardButtons = wizardButtons.add($(this)
			.next()
			.children(":button")
			.filter(".next, .previous")
			.click(function() {
				wizard.accordion("activate", index + ($(this).is(".next") ? 1 : -1))
			}));
		});
		
		// bind to change event of select to control first and seconds accordion
		// similar to tab's plugin triggerTab(), without an extra method
		var accordions = jQuery('#list1a, #list1b, #list2, #list3, #navigation, #wizard');
		
		jQuery('#switch select').change(function() {
			accordions.accordion("activate", this.selectedIndex-1 );
		});
		jQuery('#close').click(function() {
			accordions.accordion("activate", -1);
		});
		jQuery('#switch2').change(function() {
			accordions.accordion("activate", this.value);
		});
		jQuery('#enable').click(function() {
			accordions.accordion("enable");
		});
		jQuery('#disable').click(function() {
			accordions.accordion("disable");
		});
		jQuery('#remove').click(function() {
			accordions.accordion("destroy");
			wizardButtons.unbind("click");
		});
	});

		function SetasShipping(isChecked) {				

		if (isChecked) {
	
		document.getElementById('txt_shipping_firstname').value = window.document.billing.txtfirstname.value;
		document.getElementById('txt_shipping_lastname').value = window.document.billing.txtlastname.value;
		document.getElementById('txt_shipping_Address1').value =window.document.billing.txtAddress.value;
		document.getElementById('txt_shipping_Address2').value = window.document.billing.txtAddress2.value;
		document.getElementById('txt_shipping_city').value =window.document.billing.txtCity.value;
		document.getElementById('txt_shipping_zip').value =window.document.billing.txtZip.value;
		document.getElementById('zipcode').value = window.document.billing.txtZip.value;
// 		document.getElementById('txt_shipping_state').value =window.document.billing.txtState.value;

		var e = document.getElementById("country");
		
		var v = e.options[e.selectedIndex].value;
		
	
		var e = document.getElementById("timezone");
			
		var v1 = e.options[e.selectedIndex].value;
	
	
		var s = document.getElementById("country1");



		for ( var i = 0; i < s.options.length; i++ ) {
			if ( s.options[i].value == v ) {
			s.options[i].selected = true;
			
			}
		}

		getState1(v,'new');

			}
	}


		function setshipping() {
				
		var e = document.getElementById("timezone1");
	
		var s1 = document.getElementById("timezone2");

		s1.options[e.selectedIndex].selected = true;
		var timezone1val = e.value;
		$.ajaxSetup({async:false});
		$.post(BASE_URL+"checkout/checkShipping",{timezone1:timezone1val}, function (data){
			if(data=='error')
				document.getElementById("shipping_methods").innerHTML='';			
		});		
		
		}


		function newstate() {
		
		var e = document.getElementById("timezone");
	
		var s1 = document.getElementById("timezone1");

		s1.options[e.selectedIndex].selected = true;

		}
	
		function theChecker()
		{
		if(document.getElementById('terms_checkout').checked==false)
		{
		document.getElementById('paypal').disabled=true;
		document.getElementById('chkout').disabled=true;
		}
		else
		{
		document.getElementById('paypal').disabled=false;
		document.getElementById('chkout').disabled=false;		
		}
		}

		
		function hidediv() {
		
		document.getElementById('paypal').style.visibility = 'hidden'; 
		document.getElementById('chkout').style.visibility = 'visible'; 

		}

		function showdiv() {
			
			document.getElementById('paypal').style.visibility = 'visible'; 
			document.getElementById('chkout').style.visibility = 'hidden'; 
			
		}

		function register_redirect() {
		
		window.location = BASE_URL+"customer/register";
		
		}

		

		
		function Form1_Validator(theForm)
		{
		var alertsay = "";
		if (theForm.txtfirstname.value == "")
		{
		alertsay = alertsay+"Please enter First name.\n";
		theForm.txtfirstname.focus();
		document.getElementById("txtfirstname").style.borderColor="#FF0000";
		
		// return (false);
		}
		if (theForm.txtlastname.value == "")
		{
		alertsay = alertsay+"Please enter last name.\n";
		theForm.txtlastname.focus();
		document.getElementById("txtlastname").style.borderColor="#FF0000";
		
		}
		
		if (theForm.txtEmail.value == "")
		{
		
		alertsay = alertsay+"Please enter Email address.\n";
		theForm.txtEmail.focus();
		document.getElementById("txtEmail").style.borderColor="#FF0000";
		
		}
		
		if (theForm.txtAddress.value == "")
		{
		
		alertsay = alertsay+"Please enter address 1.\n";
		theForm.txtAddress.focus();
		document.getElementById("txtAddress").style.borderColor="#FF0000";
		
		}
		if (theForm.txtCity.value == "")
		{
		alertsay = alertsay+"Please enter city name.\n";
		theForm.txtCity.focus();
		document.getElementById("txtCity").style.borderColor="#FF0000";
		
		}
		if (theForm.txtZip.value == "")
		{
		alertsay = alertsay+"Please enter zipcode.\n";
		theForm.txtZip.focus();
		document.getElementById("txtZip").style.borderColor="#FF0000";
		
		}
		
		
		if (theForm.country.selectedIndex < 0)
		{
		
		alertsay =  alertsay+"Please select one of the \"country\" options.";
		
		theForm.country.focus();
		
		}
		
		if (theForm.timezone.selectedIndex < 0)
		{
		
		alertsay =  alertsay+"Please select one of the \"state\" options.";
		
		}
		
		if (theForm.timezone.selectedIndex == 0)
		{
		
		alertsay =  alertsay+"The first \"state\" option is not a valid selection";
		
		}
		
		if(alertsay) {
		document.getElementById("bil").innerHTML='';
		alert(alertsay);
		return (false);
		}
		else {
		document.getElementById("bil").innerHTML='';
		// theForm.txt_shipping_firstname.focus();
		loadXMLDoc();
		return (false);
		// return(true);
		}
		
		}
		
		function loadXMLDoc()
		{
		
		var xmlhttp;
		
		if (window.XMLHttpRequest)
		{// code for IE7+, Firefox, Chrome, Opera, Safari
		xmlhttp=new XMLHttpRequest();
		}
		else
		{// code for IE6, IE5
		xmlhttp=new ActiveXObject("Microsoft.XMLHTTP");
		}
		xmlhttp.onreadystatechange=function()
		{
		if (xmlhttp.readyState==4 && xmlhttp.status==200)
		{
		document.getElementById("bil").innerHTML=xmlhttp.responseText;
		
		if(xmlhttp.responseText) {
		
		document.getElementById("con_bil").style.visibility = 'visible';
		document.getElementById("bil_status").className = 'title error';
		}
		
		}
		else {
		document.getElementById("bil").innerHTML= "<img src='"+BASE_URL+"images/ajax-loader.gif'  />";
		}
		}
			
		var e = document.getElementById("country");
		
		var country = e.options[e.selectedIndex].value;
		
		var e = document.getElementById("timezone");
		
		var timezone = e.options[e.selectedIndex].value;
		
		var txtfirstname =  document.getElementById("txtfirstname").value;
		var txtlastname =  document.getElementById("txtlastname").value;
		var txtAddress =  document.getElementById("txtAddress").value;
		var txtAddress2 =  document.getElementById("txtAddress2").value;
		var txtEmail =  document.getElementById("txtEmail").value;
		// var txtState =  document.getElementById("txtState").value;
		var txtCity =  document.getElementById("txtCity").value;
		var txtZip =  document.getElementById("txtZip").value;
		
		xmlhttp.open("POST",BASE_URL+"checkout/billing",true);
		
		xmlhttp.setRequestHeader("Content-type","application/x-www-form-urlencoded");
		
		xmlhttp.send("txtfirstname="+txtfirstname+"&txtlastname="+txtlastname+"&txtAddress="+txtAddress+"&txtAddress2="+txtAddress2+"&txtCity="+txtCity+"&txtZip="+txtZip+"&txtEmail="+txtEmail+"&country="+country+"&timezone="+timezone);
		
		
		}

		
		function Ajax_call()
		{
		var xmlhttp;
		if (window.XMLHttpRequest)
		{// code for IE7+, Firefox, Chrome, Opera, Safari
		xmlhttp=new XMLHttpRequest();
		}
		else
		{// code for IE6, IE5
		xmlhttp=new ActiveXObject("Microsoft.XMLHTTP");
		}
		xmlhttp.onreadystatechange=function()
		{
		if (xmlhttp.readyState==4 && xmlhttp.status==200)
		{
		document.getElementById("ship").innerHTML=xmlhttp.responseText;
		
		if(xmlhttp.responseText) {
		
		document.getElementById("con_ship").style.visibility = 'visible';
		
		document.getElementById("ship_status").className = 'title error';
		}
		
		}
		
		else {
		document.getElementById("ship").innerHTML= "<img src='"+BASE_URL+"images/ajax-loader.gif'  />";
		}
		}
			
		var e = document.getElementById("country1");
		
		var country = e.options[e.selectedIndex].value;
		
		var e = document.getElementById("timezone1");
		
		var timezone = e.options[e.selectedIndex].value;
		
		var txt_shipping_firstname =  document.getElementById("txt_shipping_firstname").value;
		var txt_shipping_lastname =  document.getElementById("txt_shipping_lastname").value;
		var txt_shipping_Address1 =  document.getElementById("txt_shipping_Address1").value;
		var txt_shipping_Address2 =  document.getElementById("txt_shipping_Address2").value;
		// var txt_shipping_state =  document.getElementById("txt_shipping_state").value;
		var txt_shipping_city =  document.getElementById("txt_shipping_city").value;
		var txt_shipping_zip =  document.getElementById("txt_shipping_zip").value;
		xmlhttp.open("POST",BASE_URL+"checkout/shipping",true);
		xmlhttp.setRequestHeader("Content-type","application/x-www-form-urlencoded");
		xmlhttp.send("txt_shipping_firstname="+txt_shipping_firstname+"&txt_shipping_lastname="+txt_shipping_lastname+"&txt_shipping_Address1="+txt_shipping_Address1+"&txt_shipping_Address2="+txt_shipping_Address2+"&txt_shipping_city="+txt_shipping_city+"&txt_shipping_zip="+txt_shipping_zip+"&country1="+country+"&timezone1="+timezone);
		// xmlhttp.send();
		}


		function shippingrate2() {

			document.getElementById("ship_method").innerHTML= '';
	
			var state = document.getElementById("timezone2").value;

			var country = document.getElementById("country2").value;

			var val = '';
			
			
			var zipcode =  document.getElementById("zipcode").value;
			
			
			var str = $('input:radio[name=method]:checked').val();
			if(str){
				vals = str.lastIndexOf("-");
				val = str.substr(0,vals);
// 				val = vals[0];
			}
			if (window.XMLHttpRequest)
			{// code for IE7+, Firefox, Chrome, Opera, Safari
				xmlhttp=new XMLHttpRequest();
			}
			else
			{// code for IE6, IE5
				xmlhttp=new ActiveXObject("Microsoft.XMLHTTP");
			}
			xmlhttp.onreadystatechange=function()
			{
				if (xmlhttp.readyState==4 && xmlhttp.status==200)
				{
					if(xmlhttp.responseText=="setform"){
						$.ajaxSetup({async:false});	
						$.post(BASE_URL+"checkout/setShippingMethods",{}, function (data){
							document.getElementById("shipping_methods").innerHTML=data;
							document.getElementById("ship_method").innerHTML='<span style="font-weight:strong; color:green; font-size:21px; margin-top:10px">Please select a shipping method</span>';
						});		
					}else{
						document.getElementById("ship_method").innerHTML='<span style="font-weight:strong; color:green; font-size:21px; margin-top:10px">Shipping Cost '+xmlhttp.responseText+'</span>';
			
						if(xmlhttp.responseText > 0) {
						
							document.getElementById("ship_but").style.visibility = 'visible';
						
						} else {
						
							document.getElementById("ship_but").style.visibility = 'hidden';
						
						}
						
						document.getElementById("inreview").innerHTML='$'+xmlhttp.responseText;
				
// 						document.getElementById("paypal_shipcost").value = xmlhttp.responseText;
				
						document.getElementById("method_name").innerHTML= val;
				
						document.getElementById("hidden_method").value = val;
				
						document.getElementById("ship_type").className = 'title error';
					}
				
				} else {
				
					document.getElementById("ship_method").innerHTML= "<img src='"+BASE_URL+"images/ajax-loader.gif'  />";
				
				}
				
			}
	
			xmlhttp.open("POST",BASE_URL+"checkout/calcUPSShippingRate2",true);
			xmlhttp.setRequestHeader("Content-type","application/x-www-form-urlencoded");
			xmlhttp.send("method="+str+"&states="+state+"&zipcode="+zipcode+"&country2="+country);

		}

		function shippingrate(str)
		{
		
		document.getElementById("ship_method").innerHTML= '';
		
		if (window.XMLHttpRequest)
		{// code for IE7+, Firefox, Chrome, Opera, Safari
		xmlhttp=new XMLHttpRequest();
		}
		else
		{// code for IE6, IE5
		xmlhttp=new ActiveXObject("Microsoft.XMLHTTP");
		}
		xmlhttp.onreadystatechange=function()
		{
		if (xmlhttp.readyState==4 && xmlhttp.status==200)
		{
		document.getElementById("ship_method").innerHTML=xmlhttp.responseText;
		}
		else {
		document.getElementById("ship_method").innerHTML= "<img src='"+BASE_URL+"images/ajax-loader.gif'  />";
		}
		}
		
		xmlhttp.open("POST",BASE_URL+"checkout/shippingrate",true);
		xmlhttp.setRequestHeader("Content-type","application/x-www-form-urlencoded");
		xmlhttp.send("method="+str);
		}



		function Form2_Validator(theForm)
		{
		var alertsay = "";
		if (theForm.txt_shipping_firstname.value == "")
		{
		alertsay = alertsay+"Please enter First name.\n";
		theForm.txt_shipping_firstname.focus();
		document.getElementById("txt_shipping_firstname").style.borderColor="#FF0000";
		
		// return (false);
		}
		if (theForm.txt_shipping_lastname.value == "")
		{
		alertsay = alertsay+"Please enter last name.\n";
		theForm.txt_shipping_lastname.focus();
		document.getElementById("txt_shipping_lastname").style.borderColor="#FF0000";
		
		}
		
		if (theForm.txt_shipping_Address1.value == "")
		{
		
		alertsay = alertsay+"Please enter address.\n";
		theForm.txt_shipping_Address1.focus();
		document.getElementById("txt_shipping_Address1").style.borderColor="#FF0000";
		
		}
		
		if (theForm.txt_shipping_city.value == "")
		{
		alertsay = alertsay+"Please enter city.\n";
		theForm.txt_shipping_city.focus();
		document.getElementById("txt_shipping_city").style.borderColor="#FF0000";
		
		}
		
		
		if (theForm.country1.selectedIndex < 0)
		{
		
		alertsay =  alertsay+"Please select one of the \"country\" options.";
		
		theForm.country1.focus();
		
		}
		
		if (theForm.timezone1.selectedIndex < 0)
		{
		
		alertsay =  alertsay+"Please select one of the \"state\" options.";
		
		}
		
		if (theForm.timezone1.selectedIndex == 0)
		{
		
		alertsay =  alertsay+"The first \"state\" option is not a valid selection";
		
		}
		
		if (theForm.txt_shipping_zip.value == "")
		{
		alertsay = alertsay+"Please enter zipcode.\n";
		theForm.txt_shipping_zip.focus();
		document.getElementById("txt_shipping_zip").style.borderColor="#FF0000";
		
		}
		
		if(alertsay) {
		document.getElementById("ship").innerHTML='';
		alert(alertsay);
		return (false);
		}
		else {
		// theForm.txt_shipping_firstname.focus();
		document.getElementById("ship").innerHTML='';
		Ajax_call();
		return (false);
		// return(true);
		}
		
		
		}



		/*     select all check box in wishlist  */


		function checkAll(theForm)
		{
		
		if(theForm.wish_chk.checked) {
		
		
		for (i=0; i<theForm.elements.length; i++) {
			if (theForm.elements[i].name=='cart_pro[]')
			theForm.elements[i].checked = 1;
		}
		
		} else {
		
		
		for (i=0; i<theForm.elements.length; i++) {
			if (theForm.elements[i].name=='cart_pro[]')
			theForm.elements[i].checked = 0;
		
			}
		
		
		}
		
		
		}

		function validate_shippingrate2(theForm) {
		
		var alertsay = "";

		if (theForm.zipcode.value == "")
		{
		alertsay = alertsay+"Please enter zip code.\n";
		theForm.zipcode.focus();
		document.getElementById("zipcode").style.borderColor="#FF0000";
		
		}
		
		if(alertsay) {
		
		document.getElementById("ship_method").innerHTML='';
		
		alert(alertsay);
		
		return (false);
		
		}
		else {
		
		document.getElementById("ship_method").innerHTML='';
		
		shippingrate2();
		
		return (false);
	
		}
		
		
		}


		function validate_paymentmethod(theForm) {
		
		var alertsay = "";
		
		for (var i=0; i < theForm.payment.length; i++) {
		
		if (theForm.payment[i].checked) {
		
		pay_method();
		
		alertsay = "ok";
				
		return (false);
		
		} 
			
	}		
		if(alertsay == "") {
		
		alertsay = "Please enter payment method.\n";

		alert(alertsay);
		
		return (false);
		
		}
		
				
}

		function pay_method()
		{
		
		document.getElementById("pay_cont").style.visibility = 'visible';
		
		var selection =  document.paymethod.payment;
		
		for (i=0; i<selection.length; i++) { 
		
		if (selection[i].checked == true)
		var payment = selection[i].value;
		
		}
		
		if (window.XMLHttpRequest)
		{// code for IE7+, Firefox, Chrome, Opera, Safari
		xmlhttp=new XMLHttpRequest();
		}
		else
		{// code for IE6, IE5
		xmlhttp=new ActiveXObject("Microsoft.XMLHTTP");
		}
		xmlhttp.onreadystatechange=function()
		{
		if (xmlhttp.readyState==4 && xmlhttp.status==200)
		{


			var ptext = xmlhttp.responseText;
			pmethod = ptext.split('||');
			document.getElementById("pay").innerHTML='<div class="successBar">Updated payment method. <br> '+pmethod[0]+'</div>';
	
	
			document.getElementById("pay_tab").className = 'title error';
			
			document.getElementById("paytype").innerHTML= payment;

			if(pmethod[1]>0){
			
				document.getElementById("add_fee_label").style.visibility = 'visible';
				document.getElementById("add_fee").style.visibility = 'visible';
				document.getElementById("add_fee").innerHTML= '$'+pmethod[1];
			}else{
				document.getElementById("add_fee_label").style.visibility = 'hidden';
				document.getElementById("add_fee").style.visibility = 'hidden';
			}
			if(payment=='PayPal')
				showdiv();
			else
				hidediv();
		}else {

		document.getElementById("pay").innerHTML= "<img src='"+BASE_URL+"images/ajax-loader.gif'  />";

		}

}
		
		xmlhttp.open("POST",BASE_URL+"checkout/newpayment_method",true);
		
		xmlhttp.setRequestHeader("Content-type","application/x-www-form-urlencoded");
		
		xmlhttp.send("payment="+payment);
		
		}


		function show_grand() {


		if (window.XMLHttpRequest)
		{// code for IE7+, Firefox, Chrome, Opera, Safari
		xmlhttp=new XMLHttpRequest();
		}
		else
		{// code for IE6, IE5
		xmlhttp=new ActiveXObject("Microsoft.XMLHTTP");
		}
		xmlhttp.onreadystatechange=function()
		{
			if (xmlhttp.readyState==4 && xmlhttp.status==200)
			{
				costs = xmlhttp.responseText;
				vals = costs.split('||');
				
				document.getElementById("grand").innerHTML = vals[1];
				if(vals[0]>0){
					document.getElementById("tax_label").style.visibility = 'visible';
					document.getElementById("tax_value").style.visibility = 'visible';
					document.getElementById("tax_value").innerHTML = '$'+vals[0];
				}else{
					document.getElementById("tax_label").style.visibility = 'hidden';
					document.getElementById("tax_value").style.visibility = 'hidden';
					document.getElementById("tax_value").innerHTML = '';
				}
		
			} 

		}
		
		xmlhttp.open("POST",BASE_URL+"checkout/get_grand",true);
		
		xmlhttp.setRequestHeader("Content-type","application/x-www-form-urlencoded");
		
		xmlhttp.send();
		

}

		function getState(countryId,state)
		{
		
		if (window.XMLHttpRequest)
		{// code for IE7+, Firefox, Chrome, Opera, Safari
		xmlhttp=new XMLHttpRequest();
		}
		else
		{// code for IE6, IE5
		xmlhttp=new ActiveXObject("Microsoft.XMLHTTP");
		}
		xmlhttp.onreadystatechange=function()
		{
		
		if (xmlhttp.readyState==4 && xmlhttp.status==200)
		{
		
		document.getElementById('statediv').innerHTML=xmlhttp.responseText;

		getState2(countryId);
		
		if(state) {
		
		getState2(state);
		
		}
		
		} 
		}
		
		xmlhttp.open("POST",BASE_URL+"checkout/getstate",true);
		
		xmlhttp.setRequestHeader("Content-type","application/x-www-form-urlencoded");
		
		xmlhttp.send("country="+countryId);
		
		}

		
		function account_state(a,b,c) {
		
		getState1(b,a,c);
		
		}

		
		function getState1(countryId,state,s3)
		{
		
		if (window.XMLHttpRequest)
		{// code for IE7+, Firefox, Chrome, Opera, Safari
		xmlhttp=new XMLHttpRequest();
		}
		else
		{// code for IE6, IE5
		xmlhttp=new ActiveXObject("Microsoft.XMLHTTP");
		}
		xmlhttp.onreadystatechange=function()
		{
		if (xmlhttp.readyState==4 && xmlhttp.status==200)
		{
		
		document.getElementById('statediv1').innerHTML=xmlhttp.responseText;

		getState2(countryId);
		
		if(state == 'new') {
		
		newstate();
		
		} else if(state) {
		
		getState(state,s3);
		
		}
		
		}
		}
		
		xmlhttp.open("POST",BASE_URL+"checkout/getstate1",true);
		
		xmlhttp.setRequestHeader("Content-type","application/x-www-form-urlencoded");
		
		xmlhttp.send("country="+countryId);
		
		}

		
		function getState2(countryId) {
		
		if (window.XMLHttpRequest)
		{// code for IE7+, Firefox, Chrome, Opera, Safari
		xmlhttp=new XMLHttpRequest();
		}
		else
		{// code for IE6, IE5
		xmlhttp=new ActiveXObject("Microsoft.XMLHTTP");
		}
		xmlhttp.onreadystatechange=function()
		{
		if (xmlhttp.readyState==4 && xmlhttp.status==200)
		{
		
		document.getElementById('statediv2').innerHTML=xmlhttp.responseText;
		
		} else {
		
				}
		}
		
		xmlhttp.open("POST",BASE_URL+"checkout/getstate2",true);
		
		xmlhttp.setRequestHeader("Content-type","application/x-www-form-urlencoded");
		
		xmlhttp.send("country="+countryId);
		
		}

		
		function checkCheckBox(f){
			document.getElementById('custom_memo2').value = document.getElementById('memo').value;
			if (document.getElementById('terms_checkout')){
				if (document.getElementById('terms_checkout').checked == false)
				{
					alert("Please tick the terms & condition checkbox to checkout");
					return false;
				}
			}
			return true;
		
		}
		function checkPaypalCheckBox(f){
			
			order_memo = document.getElementById('memo').value;
			if (document.getElementById('terms_checkout')){
				if (document.getElementById('terms_checkout').checked == false)
				{
					alert("Please tick the terms & condition checkbox to checkout");
					return false;
				}
			}

			$.ajaxSetup({async:false});
			$.post(BASE_URL+"checkout/saveOrder",{custom_memo:order_memo}, function (data){				
				if(data>0){	
					document.getElementById('custom').value = data;
					$.ajaxSetup({async:false});	
					$.post(BASE_URL+"checkout/addAdditionalDetails",{}, function (data){
						$('#frm').append(data);
					});			
					return true;
				}else{
					alert('Order is not saving with paypal. Please try another payment method');
					return false;
				}
			} );
				
		
		}

