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 state = document.getElementById("timezone1").value;
	
			var country = document.getElementById("country1").value;
			
			var zipcode =  document.getElementById("txt_shipping_zip").value;
			$.ajaxSetup({async:false});
			$.post(BASE_URL+"checkout/checkShipping",{timezone:state,zipcode:zipcode,country:country}, function (data){
				if(data=='error'){
					$.ajaxSetup({async:false});	
					$.post(BASE_URL+"checkout/calcUPSShippingRate2",{timezone:state,zipcode:zipcode,country:country}, 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">Choose a shipping method</span>';
						document.getElementById("ship_but").style.visibility = 'hidden';
					});
				}			
			});		
			
		
		}
	
	
		function change_shipping(){
			var methods = $('input:radio[name=method]:checked').val();
			var method_arr = methods.split('||');
			$.ajaxSetup({async:false});
			$.post(BASE_URL+"checkout/setShipping",{methods:methods}, function (data){
				if(data=='success')
					document.getElementById("ship_method").innerHTML='<span style="font-weight:strong; color:green; font-size:21px; margin-top:10px">Shipping Cost ('+method_arr[0]+') : $ '+method_arr[1]+'</span>';

					document.getElementById("ship_but").style.visibility = 'visible';
	
					document.getElementById("inreview").innerHTML='$'+method_arr[1];
				
			
					document.getElementById("method_name").innerHTML= method_arr[0];
				
					document.getElementById("hidden_method").value = method_arr[0];		
			});
		}


		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)
		{
				
		if(xmlhttp.responseText) {
		
			setshipping();

			document.getElementById("ship").innerHTML=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 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_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() {

			$.post(BASE_URL+"checkout/get_grand",{}, function (data){
				costs = data;
				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 = '';
				}
			});

		}


		function getState(countryId1,countryId2){

			$('#statediv').html("<img src='"+BASE_URL+"images/ajax-loader1.gif'  />");
			$.post(BASE_URL+"checkout/getstate",{country:countryId1}, function (data){
				$('#statediv').html(data);
			});
			
			if(countryId2){
				getState1(countryId2);
			}

		}

		function getState1(countryId,state){

			$('#statediv1').html("<img src='"+BASE_URL+"images/ajax-loader1.gif'  />");
			$.ajaxSetup({async:false});
			$.post(BASE_URL+"checkout/getstate1",{country:countryId}, function (data){
				$('#statediv1').html(data);
			});

			if(state == 'new') {
			
				newstate();
			
			}

		}
		function getState2(countryId){
			$('#statediv2').html("<img src='"+BASE_URL+"images/ajax-loader1.gif'  />");
			$.ajaxSetup({async:false});
			$.post(BASE_URL+"checkout/getstate2",{country:countryId}, function (data){
				$('#statediv2').html(data);
			});

		}

		function account_state(billing_country,shipping_country) {
		
			getState(billing_country);
			getState1(shipping_country);
			getState2(shipping_country);
		
		}

		function newstate() {
		
			var e = document.getElementById("timezone");
		
			var s1 = document.getElementById("timezone1");
	
			s1.options[e.selectedIndex].selected = true;

		}

		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;
				}
			}
			
			document.getElementById('custom_company2').value = document.getElementById('company').value;
			if (document.getElementById('company')){
				if (document.getElementById('company').value == false)
				{
					alert("Please insert a company name.");
					return false;
				}
			}
			
			document.getElementById('custom_phone2').value = document.getElementById('phone').value;
			if (document.getElementById('phone')){
				if (document.getElementById('phone').value == false)
				{
					alert("Please insert a contact phone number.");
					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;
				}
			}
			
			order_company = document.getElementById('company').value;
			if (document.getElementById('company')){
				if (document.getElementById('company').value == false)
				{
					alert("Please insert a company name.");
					return false;
				}
			}
			
			order_phone = document.getElementById('phone').value;
			if (document.getElementById('phone')){
				if (document.getElementById('phone').value == false)
				{
					alert("Please insert a contact phone number.");
					return false;
				}
			}

			$.ajaxSetup({async:false});
			$.post(BASE_URL+"checkout/saveOrder",{custom_memo:order_memo,custom_phone:order_phone,custom_company:order_company}, 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;
				}
			} );
				
		
		}

		function showOptImage(theForm){
			var option='';
			for (i=0; i<theForm.elements.length; i++) {
				if (theForm.elements[i].id=='Pro_option'){
					option =option+":"+theForm.elements[i].value;
				}
			}
			option = option.substr(1);
			product_id = document.getElementById('product_id').value;
			$.post(BASE_URL+"catalog/getOptionImage",{product_id:product_id,option:option}, function (data){
						$('#opt_img').html(data);
						$("a#sample1").fancybox();
					});			
		}
		

