// JavaScript Document
function switch_state_province(country){	
	if(country=='US'){
		$('STATE').show();
		$('PROVINCE').hide();
	}
	else
	{
		$('STATE').hide();
		$('PROVINCE').show();
	}
}
function switch_state_province2(country){	
	if(country=='US'){
		$('SHIPTOSTATE').show();
		$('SHIPTOPROVINCE').hide();
	}
	else
	{
		$('SHIPTOSTATE').hide();
		$('SHIPTOPROVINCE').show();
	}
}

function switch_to_qty(id, size)
{
	document.getElementById(id + '_sizes').className = "hidden";
	document.getElementById(id + '_qty').className = "visible";
	document.getElementById(id + 'sizepickerover').innerHTML = "";
	document.getElementById(id + '_qty').innerHTML = "<div style=\"padding:7px 0px 7px 0px; margin-bottom:7px; border-bottom:1px solid #555555;\"><span style=\"color:#fff;\">" + size + "</span> <input id=\"inp_qty_" + id + "\" type=\"text\" style=\"width:15px; font-size:9px;\" value=\"1\" /> <a style=\"color:#00cc99;\" href=\"javascript:;\" onclick=\"add_to_cart('" + id + "', '" + size + "'); return false;\">Add</a> or <a href=\"javascript:;\" onclick=\"switch_to_sizes('" + id + "', '" + size + "'); return false;\" style=\"color:#ff0000;\">Cancel</a></div>";
}

/*function switch_to_qty_detail(id, size)
{
	document.getElementById(id + '_sizes').className = "hidden";
	document.getElementById(id + '_qty').className = "visible";
	document.getElementById(id + '_qty').innerHTML = "<div style=\"padding:7px 0px 7px 0px; margin-bottom:7px; border-bottom:1px solid #555555;\"><span style=\"color:#fff;\">" + size + "</span> <input id=\"inp_qty_" + id + "\" type=\"text\" style=\"width:35px;\" value=\"1\" /> <a style=\"color:#00cc99;\" href=\"javascript:;\" onclick=\"add_to_cart_detail('" + id + "', '" + size + "'); return false;\">Add</a> or <a href=\"javascript:;\" onclick=\"switch_to_sizes_detail('" + id + "', '" + size + "'); return false;\" style=\"color:#ff0000;\">Cancel</a></div>";
}*/

function switch_to_qty_refresh(id, size)
{
	document.getElementById(id + '_sizes').className = "hidden";
	document.getElementById(id + '_qty').className = "visible";
	document.getElementById(id + 'sizepickerover').innerHTML = "";
	document.getElementById(id + '_qty').innerHTML = "<div style=\"padding:7px 0px 7px 0px; margin-bottom:7px; border-bottom:1px solid #555555;\"><span style=\"color:#fff;\">" + size + "</span> <input id=\"inp_qty_" + id + "\" type=\"text\" style=\"width:15px; font-size:9px;\" value=\"1\" /> <a style=\"color:#00cc99;\" href=\"javascript:;\" onclick=\"add_to_cart_refresh('" + id + "', '" + size + "'); return false;\">Add</a> or <a href=\"javascript:;\" onclick=\"switch_to_sizes('" + id + "', '" + size + "'); return false;\" style=\"color:#ff0000;\">Cancel</a></div>";
}

function switch_to_sizes(id, size)
{
	document.getElementById(id + '_sizes').className = "visible";
	document.getElementById(id + '_qty').className = "hidden";
	document.getElementById(id + '_qty').innerHTML = "";
	document.getElementById(id + 'sizepickerover').innerHTML = "Click Size To Add"
	document.getElementById('error_response' + id).className = "hidden";
}

/*function switch_to_sizes_detail(id, size)
{
	document.getElementById(id + '_sizes').className = "visible";
	document.getElementById(id + '_qty').className = "hidden";
	document.getElementById(id + '_qty').innerHTML = "";
}*/

function add_to_cart(id, size)
{
	var qtyval = parseInt(document.getElementById('inp_qty_' + id).value);	
	var url = 'site_inc/classes/addtocart.php';
	var params = 'item_id=' + id + '&size=' + size + '&qty=' + qtyval;
	var ajax = new Ajax.Request(url,{
		method: 'post', 
		parameters: params, 
		onLoading: function(){	
			//document.getElementById(id + '_qty').className = "hidden";	
			document.getElementById(item_id + 'sizepickerover').innerHTML = "Adding...";
		},
		onSuccess: function(check){
			if(check.responseText != '')
			{
				//document.write(check.responseText);
				document.getElementById('error_response' + id).className = "visible";
				document.getElementById(id + '_qty').className = "visible";
				document.getElementById('error_response' + id).innerHTML = check.responseText;
			}
			else
			{
				switch_to_sizes(id, size);
				document.getElementById('error_response' + id).className = "hidden";
				var curr_qty = parseInt(document.getElementById('cart_qty').innerHTML);
				var new_qty = curr_qty + qtyval;
				document.getElementById('cart_qty').innerHTML = new_qty;
				var color = "#00FF99";
				new Effect.Highlight('top_shopping_cart', {startcolor: color, restorecolor: 'transparent'});
			}
		}
	});
}
function add_to_cart_detail(id)
{	
	var selObj = document.getElementById('item_size');
	var size = selObj.options[selObj.selectedIndex].value;
	var qtyval = parseInt(document.getElementById('item_qty').value);	
	var url = 'site_inc/classes/addtocart.php';
	var params = 'item_id=' + id + '&size=' + size + '&qty=' + qtyval;
	var error_msg = "";
	if(size=='nosize')
	{
		var error = true;
		error_msg += "You must select a size. ";
	}
	if(qtyval==0 || qtyval == "")
	{
		var error = true;
		error_msg += "You must enter a quantity.";
	}
	if(error !== true)
	{
		var ajax = new Ajax.Request(url,{
			method: 'post', 
			parameters: params, 
			onLoading: function(){	
				document.getElementById(id + 'sizepicker_form').className = "hidden";
				document.getElementById(id + 'sizepicker_loading').className = "visible";
				document.getElementById('cart_error').className = "hidden";
			},
			onSuccess: function(check){
				if(check.responseText != '')
				{
					document.getElementById('error_response' + id).className = "visible";
					document.getElementById(id + 'sizepicker_form').className = "size_picker";
					document.getElementById(id + 'sizepicker_loading').className = "hidden";
					document.getElementById('error_response' + id).innerHTML = check.responseText;	
				}
				else
				{
					document.getElementById('error_response' + id).className = "hidden";
					document.getElementById(id + 'sizepicker_loading').className = "hidden";
					document.getElementById(id + 'sizepicker_form').className = "size_picker";				
					var curr_qty = parseInt(document.getElementById('cart_qty').innerHTML);
					var new_qty = curr_qty + qtyval;
					document.getElementById('cart_qty').innerHTML = new_qty;
					var color = "#00FF99";
					new Effect.Highlight('top_shopping_cart', {startcolor: color, restorecolor: 'transparent'});
				}
			}
		})
	}
	else
	{
		document.getElementById('cart_error').className = "visible";
		document.getElementById('cart_error').innerHTML = "<span style=\"color:#ff0000;\">" + error_msg + "</span>";
	}
}
function add_to_cart_refresh(id, size)
{
	var qtyval = parseInt(document.getElementById('inp_qty_' + id).value);	
	var url = 'site_inc/classes/addtocart.php';
	var params = 'item_id=' + id + '&size=' + size + '&qty=' + qtyval;
	var ajax = new Ajax.Request(url,{
		method: 'post', 
		parameters: params, 
		onSuccess: function(check){
			if(check.responseText != '')
			{
				//document.write(check.responseText);
				document.getElementById('error_response' + id).className = "visible";
				document.getElementById(id + '_qty').className = "visible";
				document.getElementById('error_response' + id).innerHTML = check.responseText;
			}
			else
			{
				window.location = "shopping_cart.php";
			}
		}
	});
}
function MM_jumpmenu(targ,selObj,restore)
{ //v3.0 
eval(targ+".location='"+selObj.options[selObj.selectedIndex].value+"'"); 
if (restore) selObj.selectedIndex=0; 
}
function update_shopping_cart(key, id, qty, old_qty, size)
{
	var qtyval = parseInt(qty);
	var old_qtyval = parseInt(old_qty);
	var url = 'site_inc/classes/updatecart.php';
	var params = 'key=' + key + '&item_id=' + id + '&size=' + size + '&qty=' + qtyval + '&old_qty=' + old_qtyval;
	var ajax = new Ajax.Request(url,{
		method: 'post', 
		parameters: params, 
		onLoading: function(){	
			document.getElementById('updating_notice').className = "visible";
		},
		onSuccess: function(check){
			if(check.responseText == '')
			{
				document.getElementById('updating_notice').className = "hidden";
				document.location = "shopping_cart.php";
			}
			else
			{
				document.getElementById('updating_notice').innerHTML = check.responseText;
				document.getElementById('qty_' + key).innerHTML = "<input onchange=\"update_shopping_cart('" + key + "', '" + id + "', this.value, '" + old_qtyval + "', '" + size + "'); return false;\" type=\"text\" style=\"width:25px;\" name=\"qty\" value=\"" + old_qtyval + "\" />";
			}
		}
	});
}
function update_shopping_cart_pkg(key, id, qty, old_qty, size)
{
	var qtyval = parseInt(qty);
	var old_qtyval = parseInt(old_qty);
	var url = 'site_inc/classes/updatecart_pkg.php';
	var params = 'key=' + key + '&item_id=' + id + '&size=' + size + '&qty=' + qtyval + '&old_qty=' + old_qtyval;
	var ajax = new Ajax.Request(url,{
		method: 'post', 
		parameters: params, 
		onLoading: function(){	
			document.getElementById('updating_notice').className = "visible";
		},
		onSuccess: function(check){
			if(check.responseText == '')
			{
				document.getElementById('updating_notice').className = "hidden";
				document.location = "shopping_cart.php";
			}
			else
			{
				document.getElementById('updating_notice').innerHTML = check.responseText;
				document.getElementById('qty_' + key).innerHTML = "<input onchange=\"update_shopping_cart_pkg('" + key + "', '" + id + "', this.value, '" + old_qtyval + "', '" + size + "'); return false;\" type=\"text\" style=\"width:25px;\" name=\"qty\" value=\"" + old_qtyval + "\" />";
			}
		}
	});
}
function delete_from_cart(key)
{
	var answer = confirm("Are you sure you want to remove this item? THIS CANNOT BE UNDONE!");
	if (answer)
	{
		var url = 'site_inc/classes/remove_from_cart.php';
		var params = 'key=' + key;
		var ajax = new Ajax.Request(url,{
		method: 'post', 
		parameters: params, 
		//onLoading: function(){$('workingMsg').show()},
		onLoaded: function(){window.location = "shopping_cart.php";}
		});
	}
	else
	{
		//
	}	
}
function delete_question(id)
{
	var answer = confirm("Are you sure you want to remove this question? THIS CANNOT BE UNDONE!");
	if (answer)
	{
		var url = 'site_inc/classes/delete_question.php';
		var params = 'id=' + id;
		var ajax = new Ajax.Request(url,{
		method: 'post', 
		parameters: params, 
		//onLoading: function(){$('workingMsg').show()},
		onLoaded: function(){window.location = "overlord_admin_contactus.php";}
		});
	}
	else
	{
		//
	}	
}
function detail_jump(height)
{
	var jumpToVal = parseInt(height);
	window.scroll(0, jumpToVal);
}
function switch_shipping(type)
{
	if(type == 'usa')
	{
		document.getElementById('usa_ship').className = 'visible';	
		document.getElementById('intl_ship').className = 'hidden';	
	}
	else
	{
		document.getElementById('usa_ship').className = 'hidden';	
		document.getElementById('intl_ship').className = 'visible';
	}
}
function show_colls(val)
{
	if(val==1)
	{
		$('coll_select').hide();	
	}
	else
	{
		$('coll_select').show();
	}
}
function show_sign(val)
{
	if(val==1)
	{
		$('dollar_sign').show();
		$('pct_sign').hide();	
	}
	else
	{
		$('dollar_sign').hide();
		$('pct_sign').show();
	}
}
function show_colls_b(val, id)
{
	if(val==1)
	{
		$(id + '_coll_select').hide();	
	}
	else
	{
		$(id + '_coll_select').show();
	}
}
function show_sign_b(val, id)
{
	if(val==1)
	{
		$(id + '_dollar_sign').show();
		$(id + '_pct_sign').hide();	
	}
	else
	{
		$(id + '_dollar_sign').hide();
		$(id + '_pct_sign').show();
	}
}