var requesturl = "_request/index.php";
// ----------------------- checkout ----------------------------- \\
function pageLink(go) {
	window.location.href=go;
}

function checkOut() {
	var myForm = document.createElement('form');
	myForm.method = 'post';
	myForm.action = "https://workingclassacupuncture.org/cart/";
	myForm.setAttribute('name', 'myForm');
	myForm.id = 'myForm';
	var cinput = document.createElement('input');
	cinput.type = 'hidden';
	cinput.setAttribute('value', 'go');
	cinput.setAttribute('name', 'do');
	cinput.id = "c";
	myForm.appendChild(cinput);
	document.body.appendChild(myForm);
	myForm.submit() ;
	document.body.removeChild(myForm) ;
}

// ----------------------- login ----------------------------- \\
function logIn(go) {
	var desurl = "login.php";
	var u = $("#u").val();
	var p = $("#p").val();
	$.post( requesturl, {durl: desurl, u:u, p:p, go:go },
		function( data ) { $( "#logininner" ).empty().append( data ); } 
	);
}
function chFocus(x) {
	$("#"+x).focus();
}

// ----------------------- cart ----------------------------- \\
function cartDeleteItem(itemid) {
	var desurl = "cart_deleteitem.php";
	$.post( requesturl, {durl: desurl, itid:itemid},
		function( data ) { $( "#cart" ).empty().append( data ); }
	);
	$.post( requesturl, { durl: "cart_top_refresh.php" },
		function( datab ) { $( "#hcart" ).empty().append( datab ); }
	);
}

function addEventToCart(eventid) {
	var desurl = "addeventtocart.php";
	var itmqty = $("#qty"+eventid).val();
	var priceid = $("#priceopt"+eventid).val();

	$.post( requesturl, { durl: desurl, eid:eventid, qty:itmqty, pid:priceid },
		function( data ) { $( "#cart" ).empty().append( data ); } 
	);
	$.post( requesturl, { durl: "cart_top_refresh.php" },
		function( datab ) { $( "#hcart" ).empty().append( datab ); }
	);
}

function addToCart(itemid) {
	var desurl = "addtocart.php";
	var itmqty = $("#qty"+itemid).val();
	var opta = $("#choosea"+itemid).val();
	var optb = $("#chooseb"+itemid).val();

	$.post( requesturl, { durl: desurl, itid:itemid, qty:itmqty, oa:opta, ob:optb },
		function( data ) { $( "#cart" ).empty().append( data ); } 
	);
	$.post( requesturl, { durl: "cart_top_refresh.php" },
		function( datab ) { $( "#hcart" ).empty().append( datab ); }
	);
}

function showCart() {
	var desurl = "cartinfo.php";
	$.post( requesturl, { durl: desurl },
		function( data ) { $( "#cart" ).empty().append( data ); } 
	);
}

function showHeadCart() {
	var desurl = "cartinfo_head.php";
	$.post( requesturl, { durl: desurl },
		function( data ) { $( "#hcart" ).empty().append( data ); } 
	);
}

// ----------------------- end cart ----------------------------- \\

// ----------------------- address ----------------------------- \\
function countryValue() {
	var s = document.getElementById("country").value;
	return s;
}
function stateValue() {
	var s = document.getElementById("state").value;
	return s;
}
function cityValue() {
	var s = document.getElementById("city").value;
	return s;
}
function countyValue() {
	var s = document.getElementById("county").value;
	return s;
}

function stateListAjax(state,country,e) {
	var vars = "country=" + country;
		vars = vars + "&state=" + state;
		vars = vars + "&error_style=" + e;
	doAjax("statelist.php", vars, stateListChange);
}
function stateListChange(response) {
	document.getElementById("pstate").innerHTML=response; 
}

function cityAutoFill(state,country) {
	if(state=='CA' && country=='US') {
		var options = {
			script:"scripts/autocomplete.php?&",
			varname:"input",
			json:true,
			shownoresults:false,
			delay:100,
			maxresults:6,
			callback: function (obj) { document.getElementById('cityid').value = obj.id; }
		};
		var as_json = new bsn.AutoSuggest('city', options);
	} else {
		as_json.shownoresults = true;
	}
}

function countyListAjax(state,city,county,country) { 
	var vars = "state=" + state;
		vars = vars + "&city=" + city;
		vars = vars + "&county=" + county;
		vars = vars + "&country=" + country;
	doAjax("countylist.php", vars, countyListChange);
}
function countyListChange(response) {
	document.getElementById("pcounty").innerHTML=response;
}
function disableEnterKey(e) {
	var key = (window.event) ? event.keyCode : e.which;
	return (key != 13);
}
// ----------------------- end address ----------------------------- \\
// ----------------------- jquery reveal hide ----------------------------- \\
function sh(x) {
	$('#'+x).slideToggle('fast');
}
