function validate_add()
{
	if ((document.getElementById('products_quantity').value == "") || (document.getElementById('products_quantity').value == "0"))
	{
		alert("Need quantity to add to cart!");
		document.getElementById('products_quantity').focus();
		return false;
	}
	var options_str = "";
	if (document.getElementById('has_options').value == "1")
	{
        var total_options = document.getElementById('total_options').value;
		for (i=0; i<total_options; i++)
		{
			if (i > 0)
				options_str +=  "|";
            sel_box = document.getElementById('option_' + i);
            options_str += sel_box.options[sel_box.selectedIndex].value;
		}
		document.getElementById('options_str').value = options_str;
	}
	return true;
}
function add_to_cart(return_page)
{
	//alert(page_name);
	if (validate_add() == false)
		return false;
		
	var postData = "products_id=" + document.getElementById('products_id').value;
	postData += "&products_quantity=" + document.getElementById('products_quantity').value;
	postData += "&products_price=" + document.getElementById('products_price').value;
	postData += "&options_str=" + document.getElementById('options_str').value;
	postData += "&products_image=" + document.getElementById('products_image').value;
	
	var sUrl = "include/add_to_cart.php";
	//alert(sUrl + " : " + postData);
    var callback = {
        success: function(o) {
			document.location = "view_cart.php?return_page=" + return_page;
			//alert(o.responseText);
        },
        failure: function(o) {
            alert("AJAX failed. Please try again.");
        }
    }
    var transaction = YAHOO.util.Connect.asyncRequest('POST', sUrl, callback, postData);
	return false;
}
function update_cart_info()
{
    var sUrl = "include/update_cart_info.php";
    var callback = {
        success: function(o) {
            document.getElementById('cart_info').innerHTML =  o.responseText;
        },
        failure: function(o) {
            alert("AJAX failed. Please try again.");
        }
    }
    var transaction = YAHOO.util.Connect.asyncRequest('GET', sUrl, callback, null);
	return false;
}
function update_cart_item(pid,return_page)
{
	var qty = document.getElementById('qty_' + pid).value;
	if ((qty == "") || (qty == "0"))
    {
        alert("Need quantity to add to cart!");
        document.getElementById('qty_' + pid).focus();
        return false;
    }
	var total_options = document.getElementById('total_options_' + pid).value;
    var options_str = "";
    for (i=0; i<total_options; i++)
    {
        if (i > 0)
            options_str +=  "|";
        sel_box = document.getElementById('option_select_' + pid + '_' + i);
        options_str += sel_box.options[sel_box.selectedIndex].value;
    }
    
    var price = document.getElementById('price_' + pid).value;
	var sUrl = "include/update_cart.php?pid=" + pid + "&qty=" + qty + "&options_str=" + options_str;
	var callback = {
        success: function(o) {
            document.location = "view_cart.php?return_page=" + return_page;
        },
        failure: function(o) {
            alert("AJAX failed. Please try again.");
        }
    }
    var transaction = YAHOO.util.Connect.asyncRequest('GET', sUrl, callback, null);
	return false;
}
function remove_from_cart(pid,return_page)
{
	if (!confirm("Remove this item from your cart?"))
    {
        return false;
    }
	var sUrl = "include/remove_from_cart.php?pid=" + pid;
    var callback = {
        success: function(o) {
            document.location = "view_cart.php?return_page=" + return_page;
        },
        failure: function(o) {
            alert("AJAX failed. Please try again.");
        }
    }
    var transaction = YAHOO.util.Connect.asyncRequest('GET', sUrl, callback, null);
	return false;
}



function remove_from_cart_NOT_USED(pid,cid,sid,pageno,items_per_page,search_str)
{
    if (!confirm("Remove this item from your cart?"))
    {
        return false;
    }
	if (search_str == undefined)
	{
		document.location = 'index.php?action=remove_from_cart&cid=' + cid + '&sid=' + sid + '&pid=' + pid + '&pageno=' + pageno + '&items_per_page=' + items_per_page;
	}
	else 
	{
		document.location = 'index.php?action=remove_from_cart&cid=' + cid + '&sid=' + sid + '&pid=' + pid + '&pageno=' + pageno + '&items_per_page=' + items_per_page + '&search_str=' + search_str;
	}
	
}

function update_cart_item_NOT_USED(pid,cid,sid,pageno,items_per_page,search_str)
{
	var qty = document.getElementById('qty_' + pid).value;
	if ((qty == "") || (qty == "0"))
    {
        alert("Need quantity to add to cart!");
        document.getElementById('qty_' + pid).focus();
        return false;
    }
	var total_options = document.getElementById('total_options_' + pid).value;
    var options_str = "";
    for (i=0; i<total_options; i++)
    {
        if (i > 0)
            options_str +=  "|";
        sel_box = document.getElementById('option_select_' + pid + '_' + i);
        options_str += sel_box.options[sel_box.selectedIndex].value;
    }
    
    var price = document.getElementById('price_' + pid).value;
	if (search_str == undefined)
	{
		document.location = 'index.php?action=update_cart&cid=' + cid + '&sid=' + sid + '&pid=' + pid + '&pageno=' + pageno + '&items_per_page=' + items_per_page + '&options_str=' + options_str + '&price=' + price + '&qty=' + qty;
	}
	else 
	{
		document.location = 'index.php?action=update_cart&cid=' + cid + '&sid=' + sid + '&pid=' + pid + '&pageno=' + pageno + '&items_per_page=' + items_per_page + '&options_str=' + options_str + '&price=' + price + '&qty=' + qty + '&search_str=' + search_str;
	}
	
    return false;
}
function load_zones_NOT_USED(target)
{
    var src_sel = document.getElementById(target + "_countries");
    var countries_id = src_sel.options[src_sel.selectedIndex].value;
    
    var sUrl = target + "_zones.php?&countries_id=" + countries_id;
    var callback = {
        success: function(o) {
            document.getElementById(target + '_zones').innerHTML =  o.responseText;
        },
        failure: function(o) {
            alert("AJAX failed. Please try again.");
        }
    }
    var transaction = YAHOO.util.Connect.asyncRequest('GET', sUrl, callback, null);
}


function clarify_NOT_USED(form)
{
	var theForm = form;
	var element_i;
	var returnval;
	if (theForm.qty.value == "") 
	{
		alert("Please enter a quantity to order!");
		qtyreq = true;
		returnval = false;
		theForm.qty.focus();
	} 
	else 
	{
		var qtyvalue = parseInt(form.qty.value);
		returnval = true;
		var alertText = "";
		var qtyreq = false;
		var optreq = false;
		for(i=0; i<theForm.elements.length; i++)
		{
			if ((qtyvalue < 1) || (qtyvalue == "")) 
			{
				qtyreq = true;
				returnval = false;
		    }
	    	else if(theForm.elements[i].type == "checkbox")
			{
    		}
		    else if(theForm.elements[i].type == "select-one")
			{
				if (theForm.elements[i].options[theForm.elements[i].selectedIndex].text == "--Select--") 
				{
					element_i = i;
					optreq = true;
					returnval = false;
				}
	    	}
		}
		if (returnval == false) 
		{
			if (qtyreq == true) 
			{
				alertText += "Qty must be greater than 0!\n";
				theForm.qty.select();
			}
			if (optreq == true) 
			{
				alertText += "Please select from available options!\n";
				theForm.elements[element_i].focus();
			}
			alert(alertText);
		}
	}
	return returnval;
} 
function add_to_cart_NOT_USED(pid,cid,sid,pageno,items_per_page,search_str)
{
    var price = document.getElementById('products_price').value;
    var qty = document.getElementById('products_quantity').value;
    var options_str = "";
	if ((document.getElementById('products_quantity').value == "") || (document.getElementById('products_quantity').value == "0"))
	{
		alert("Need quantity to add to cart!");
		document.getElementById('products_quantity').focus();
		return false;
	}
	if (document.getElementById('has_options').value == "1")
	{
        var total_options = document.getElementById('total_options').value;
		for (i=0; i<total_options; i++)
		{
			if (i > 0)
				options_str +=  "|";
            sel_box = document.getElementById('option_' + i);
            options_str += sel_box.options[sel_box.selectedIndex].value;
		}
	}
	if (search_str == undefined)
	{
		document.location = 'index.php?action=add_to_cart&cid=' + cid + '&sid=' + sid + '&pid=' + pid + '&pageno=' + pageno + '&items_per_page=' + items_per_page + '&options_str=' + options_str + '&price=' + price + '&qty=' + qty;
	}
	else 
	{
		document.location = 'index.php?action=add_to_cart&cid=' + cid + '&sid=' + sid + '&pid=' + pid + '&pageno=' + pageno + '&items_per_page=' + items_per_page + '&options_str=' + options_str + '&price=' + price + '&qty=' + qty + '&search_str=' + search_str;
	}
	return false;
}