var xmlHttp
var productPrice;


function init()
{
	productPrice = parseFloat(document.getElementById("price").innerHTML);
}

function hideMenu(){
	$(".sub_menu").hide();	
}

function showMenu()
{
	$(".sub_menu").slideDown();
}

function ajaxCall(action, data, returnID, optGroup)
{ 
	var xmlHttp=GetXmlHttpObject()
	if (xmlHttp==null)
	{
		alert ("Browser does not support HTTP Request")
		return
	} 
	var url="/shop/inc/parseAjax.php"
	url=url+"?action="+action+"&data="+data
	if(returnID == 'price'){
		if(productPrice === undefined){} else {url = url+'&productPrice='+productPrice;}
	}
	url=url+"&sid="+Math.random()
	xmlHttp.onreadystatechange=function() {
		if (xmlHttp.readyState==4 || xmlHttp.readyState=="complete")
		{
			//If return id = price then store return data in var for further calculations
			/*if(returnID == 'price'){
				addition = parseFloat(xmlHttp.responseText);
				document.getElementById(optGroup).value = (addition).toFixed(2);
				document.getElementById("price").innerHTML = calcTotal();
				return;
			}*/
			//alert(document.getElementById(returnID).innerHTML);
			if(returnID!='') { document.getElementById(returnID).innerHTML=xmlHttp.responseText; }
			//alert(document.getElementById(returnID).innerHTML);
		} 
	}
	xmlHttp.open("GET",url,true)
	xmlHttp.send(null)

}
function GetXmlHttpObject()
{ 
	var XMLHttp=null
	try
	{
		XMLHttp=new ActiveXObject("Msxml2.XMLHTTP")
	}
	catch(e)
	 {
	 try
	 {
	 	XMLHttp=new ActiveXObject("Microsoft.XMLHTTP")
	 }
	 catch(e)
	 {}
	}
	
	if (XMLHttp==null)
	{
		XMLHttp=new XMLHttpRequest()
	}
	
	return XMLHttp
}

function imageSwitch(imageSRC, displayContainer, width, height, padWidth, padHeight)
{
	var padWidth = (padWidth == null) ? 0 : padWidth;
	var padHeight = (padHeight == null) ? 0 : padHeight;

	document.getElementById(displayContainer).src = imageSRC;	
	document.getElementById(displayContainer).style.margin = padHeight + 'px ' + padWidth + 'px';
	
	if(width != null) document.getElementById(displayContainer).width = width;
	if(height != null) document.getElementById(displayContainer).height = height;
}

function calcTotal()
{
	//var adjust = parseFloat(document.getElementById(changedVal).value)
	var total = parseFloat(productPrice);
	for(var this_item in optionList)
	{
		if(optionList[this_item] != 'x') {
			if(document.getElementById(optionList[this_item]).value === undefined || document.getElementById(optionList[this_item]).value == ""){} else {
				total = total + parseFloat(document.getElementById(optionList[this_item]).value);
			}
		}
	}
	return (total).toFixed(2);
	
}
























