function add_to_wishlist(cart_form, list_id){
	//is_preview declared in template.php

	document.getElementById("item"+list_id).innerHTML = '<img src="/images/img_loading.gif" align=absmiddle width=20 height=20> <font color=red>Adding to wishlist...</font>';

	var qty = cart_form.qty.value;
	if(qty==""){
		qty = 0;
	}
	//send xml
	url = "/store/wishlist-add.php?list_id="+list_id+"&qty="+qty;
	var request = new XHRequest().getObject();	
	request.onreadystatechange = function() {
		if (request.readyState == 4) {      
			if (request.status == 200) { 
				var txt = request.responseText;
				if(txt!=""){					
					document.getElementById("item"+list_id).innerHTML = "<font color=green>Item added to wishlist!</color>";
				}
			}
		}
	}
	url += "&r="+Math.random();

	request.open("GET",url, true);
	request.send(null);
}

function add_to_cart(cart_form, list_id){
	//is_preview declared in template.php

	document.getElementById("item"+list_id).innerHTML = '<img src="/images/img_loading.gif" align=absmiddle width=20 height=20> <font color=red>Adding to cart...</font>';

	var qty = cart_form.qty.value;
	if(qty==""){
		qty = 0;
	}
	//send xml
	url = "/store/cart-add.php?list_id="+list_id+"&qty="+qty;
	var request = new XHRequest().getObject();	
	request.onreadystatechange = function() {
		if (request.readyState == 4) {      
			if (request.status == 200) { 
				var txt = request.responseText;
				if(txt!=""){
					
					refresh_div_html("shopping_cart_1", txt);
					refresh_div_html("shopping_cart_2", txt);
					
					document.getElementById("item"+list_id).innerHTML = "<font color=green>Item added to cart!</color>";

					//refresh_bottom_nav();
				}
			}
		}
	}
	url += "&r="+Math.random();

	request.open("GET",url, true);
	request.send(null);
}
function refresh_cart(){
	refresh_div("shopping_cart_detail", "/store/ajax/cart.php?n=0", 1);
	//refresh_bottom_nav();
}
function refresh_bottom_nav(){
	document.getElementById("login_nav_bottom").innerHTML = document.getElementById("login_nav").innerHTML;
}
function check_all(true_false, field){
	for (i = 0; i < field.length; i++)
		field[i].checked = true_false ;
}
function confirmDelete(url){
	if(confirm("Are you sure?"))
		window.location=url;
}
function rdir(url){
	window.location=url;
}
function show_blackscreen(){
	oBody = document.getElementById('black_screen');
	oBody.style.visibility = 'visible';
	oBody.style.left = 0;
	oBody.style.top = 0;
	oBody.style.width = screen.width;
	oBody.style.height = 2000//screen.height;

	hide_combos();
}
function show_popup(url){

	//background
	oBody = document.getElementById('frame_body');
	oBody.className = "body_bg_fade";

	hide_combos();

	position_popup();

	popup_frame.location=url;

}
function close_popup(id){
	hidediv(id);

	//oBody = document.getElementById('black_screen');
	//oBody.style.visibility = 'hidden';

	oBody = document.getElementById('frame_body');
	oBody.className = "body_bg";

	show_combos();

	//refresh shopping cart when popup is closed
	//refresh_div("shopping_cart", "/store/ajax/cart-count.php", 1);

}
function reposition_popup(){
	if(document.getElementById('popup').style.display=="block"){
		position_popup();
	}
}
function position_popup(){
		
	obj = document.getElementById('popup');

	getScrollXY();
	getWindowXY();

	var new_left = myWidth/2 - 410;
	if(new_left<0)
			new_left = 0;

	obj.style.left = new_left;
	obj.style.top = screen.height/2 + scrOfY - 380;

	obj.style.display = "block";
}
function refresh_div(id, url, no_cache){

	//document.getElementById(id).innerHTML = '<img src="/images/img_wait.gif">';

	var request = new XHRequest().getObject();
		
	request.onreadystatechange = function() {
		if (request.readyState == 4) {      
			if (request.status == 200) { 
				var txt = request.responseText;
				if(txt!="")
					refresh_div_html(id, txt);
			}
		}
	}
	if(no_cache==1)
		url += "&r="+Math.random();

	request.open("GET",url, true);
	request.send(null);
}

function refresh_div_html(id, html){
	document.getElementById(id).innerHTML = html;
}

function hide_combos() {
	var arCombo = document.getElementsByTagName("select");
	for(var i=0;i<arCombo.length;i++) {
		arCombo[i].style.visibility="hidden";
	}
}
function show_combos() {
	var arCombo = document.getElementsByTagName("select");
	for(var i=0;i<arCombo.length;i++) {
		arCombo[i].style.visibility="inherit";
	}
}
function hideandshow(id){
	if (document.getElementById(id).style.display == "block")
		document.getElementById(id).style.display = "none";
	else
		document.getElementById(id).style.display = "block";
}
function showdiv(id){
	document.getElementById(id).style.display = "block";
}
function hidediv(id){
	document.getElementById(id).style.display = "none";
}
function hideshow(thisvalue, id){
	if(thisvalue==1)
		showdiv(id);
	else
		hidediv(id);
}
function refresh_state(country, state){
	//if(country=="US" || country=="CA"){
		refresh_div('state_div', '/js/get_state.php?country='+country+'&state='+state, 0);
	//}
}
