// JavaScript Document
var xmlHttp

function showcart(start,qty,stockQty)
{

	document.getElementById("cartdiv").style.display = "";
	document.getElementById("cartbefore").style.display = "";
	xmlHttp=GetXmlHttpObject()
	if (xmlHttp==null)
	{
	alert ("Browser does not support HTTP Request")
	return
	} 
	var url3="cart_ajax.php";
	url3=url3+"?start="+start+"&qty="+qty+"&stockQty="+stockQty;
	xmlHttp.onreadystatechange=stateChanged 
	xmlHttp.open("GET",url3,true)
	xmlHttp.send(null)
} 



function stateChanged() 
{ 

	if(xmlHttp.readyState==1)
	{
	document.getElementById("loadingtxt").innerHTML="<strong>Loading Your Cart Please Wait...</strong>"	;
	document.getElementById("loadingimg").innerHTML="<strong><img src='images/ajax-loader.gif' border='0'></strong>";
	
	}
	if (xmlHttp.readyState==4 || xmlHttp.readyState=="complete")
				{
				document.getElementById("cartbefore").style.display = "none";
				document.getElementById("cart").style.display = "block";
				document.getElementById("cart").innerHTML=xmlHttp.responseText;
				document.getElementById("loadingtxt").innerHTML="";
				document.getElementById("loadingimg").innerHTML="";
				}
				
}

function GetXmlHttpObject()
{
var xmlHttp=null;

try
{
// Firefox, Opera 8.0+, Safari
xmlHttp=new XMLHttpRequest();
}
catch (e)
{
// Internet Explorer
try
{
xmlHttp=new ActiveXObject("Msxml2.XMLHTTP");
}
catch (e)
{
xmlHttp=new ActiveXObject("Microsoft.XMLHTTP");
}
}
return xmlHttp;
}


// JavaScript Document
function showNavigationMenu(showMenu, hideMenu, showImage, hideImage) {
	document.getElementById(showMenu).style.display ='';
	document.getElementById(hideMenu).style.display ='none';
	document.getElementById(showImage).style.display ='';
	document.getElementById(hideImage).style.display ='none';
}

function showTitleTooltips(divId) {
	document.getElementById(divId).style.display='';
}


function Paging(start)
{
showcart(start);
}

function hidecart()
{
document.getElementById("cart").style.display = "none";
document.getElementById("cartdiv").style.display = "none";
}




function showTechSpecs(showDiv, showTab, id) { 
	for (var i=1; i <= 3; i++)
	{
		
		if(i == id) {
			document.getElementById(showDiv+"_"+i).style.display ='';
			document.getElementById(showTab+"_"+i).className ='active';
		} else {	
			document.getElementById(showDiv+"_"+i).style.display ='none';
			document.getElementById(showTab+"_"+i).className ='';
		}	
	}
	
}

// EVENT HANDLERS
function pressButton(btName, btSrc) { 
 if (document.images)
  eval('document.'+btName+'.src='+btSrc+'_down.src');
}

function releaseButton(btName, btSrc) {
 if (document.images)
  eval('document.'+btName+'.src='+btSrc+'_up.src');
}


//Create a boolean variable to check for a valid Internet Explorer instance.
var xmlhttpC = false;
//Check if we are using IE.
try {
//If the Javascript version is greater than 5.
xmlhttpC = new ActiveXObject("Msxml2.XMLHTTP");
//alert ("You are using Microsoft Internet Explorer.");
} catch (e) {
//If not, then use the older active x object.
try {
//If we are using Internet Explorer.
xmlhttpC = new ActiveXObject("Microsoft.XMLHTTP");
//alert ("You are using Microsoft Internet Explorer");
} catch (E) {
//Else we must be using a non-IE browser.
xmlhttpC = false;
}
}
//If we are using a non-IE browser, create a javascript instance of the object.
if (!xmlhttpC && typeof XMLHttpRequest != 'undefined') {
xmlhttpC = new XMLHttpRequest();
//alert ("You are not using Microsoft Internet Explorer");
}
function updateCart(serverPage, id, formField) {
	//var obj = document.getElementById(objID);
	xmlhttpC.open("GET", serverPage);	
	xmlhttpC.onreadystatechange = function() {
		if (xmlhttpC.readyState==4 || xmlhttpC.readyState=="complete"){
			var allData = xmlhttpC.responseText.split("~");
			formField.value = allData[0];
			document.getElementById("price_"+id).innerHTML = allData[1];
			document.getElementById("subTotal").innerHTML  = allData[2];
			document.getElementById("vatCharge").innerHTML = allData[3];
			document.getElementById("exVat").innerHTML     = allData[4];
			document.getElementById("cartTotal").innerHTML = allData[2];
			document.getElementById("cartTotals").innerHTML = allData[2];
		}
	}
	xmlhttpC.send(null);
}

function changeQty(formField, operation, id) {
	var qtyValue = document.getElementById("cartvalue").value;
	updateCart('addtocart.php?action=ajaxupdate&qty='+qtyValue+'&id='+id, id, formField);
}



	function addtocart(me,event){ 
	var productid=me.id;
	//alert(productid);
	if(productid.substr(0,2) == 'id')
	    {
		productid=productid.substr(2);
		}
	//alert(event);

    if(document.getElementById('pro_qty'))
	var quantity = document.getElementById('pro_qty').value;	
	else
	var quantity=1;
	
	pos_x  = event.clientX + document.body.scrollLeft - document.body.clientLeft;
	pos_y  = event.clientY + document.body.scrollTop  - document.body.clientTop;       
    if (document.body.parentElement && document.body.parentElement.clientLeft) {
		var bodParent = document.body.parentElement;
		pos_x+= bodParent.scrollLeft - bodParent.clientLeft;
		pos_y+= bodParent.scrollTop - bodParent.clientTop;
	}
    var xmlHttp = initXMLHTTPRequest();
	var attval ="";
	if(document.getElementById(me.name)){
	   var attval  = document.getElementById(me.name).value;
	} 
	var url="addproduct.php?pId="+productid+"&qty="+quantity+"&attval="+attval; 
	
    xmlHttp.open("GET",url, true);
	xmlHttp.onreadystatechange = function () {
	        if (xmlHttp.readyState == 4) {
			var xmlDoc = xmlHttp.responseText;
			if(xmlDoc!='')
				{
				
				}    
			var arr = xmlDoc.split("#");
			//alert(xmlDoc);
			if(arr[0] == "success"){
				//alert('success');
				document.getElementById("show1").style.display="none";
			  var cartItem  = '<a href="cart.php" title="View Cart" style="outline:none;" class="your-basket">'+document.getElementById("cartitemdiv").innerHTML+'</a>';
			  cartItem = arr[2];//parseInt(cartItem)+1;                   
			  //document.getElementById("cartitemdiv").innerHTML = cartItem;
			  document.getElementById("cartitemdiv").innerHTML = '<a href="cart.php" title="View Cart" style="outline:none;" class="your-basket">'+cartItem+'</a>';
			  document.getElementById("cartpricediv").innerHTML = '<a href="cart.php" title="View Cart" style="outline:none;" class="your-basket">'+arr[1]+'</a>'; 
			  var attributepair = "";
			  displaydiv();
			  
			 document.getElementById("parturi").innerHTML = arr[3]+" "+me.alt+""+attributepair;               
			if(navigator.appName == "Microsoft Internet Explorer"){
			      screenW = screen.width;
			      var x = parseInt(screenW)/2.5; 
				  var y = parseInt(pos_y)+100;    
			   }
			  else{
			    pos_x = event.pageX;
                pos_y = event.pageY;
				screenW = screen.width;
                
			    var x = (parseInt(screenW)/2.2)-100 ; 
				var y = parseInt(pos_y)-200;  
			  } 				
			  alwaysOnTop.init(
				
				{
					targetid: 'showevent',
					orientation: 3,
					position: [x, 325],
					fadeduration: [1000, 1000],
					frequency: 2,
					hideafter: 1500
				}
				)
			}
		}
	};
	xmlHttp.send(null);
}