// JavaScript Document
//<!--

var currentTime=new Date();
	//alert(AddProduct);
function GetXmlHttpObject(handler)
{ 
	var objXmlHttp=null;

	if (navigator.userAgent.indexOf("MSIE")>=0)
	{ 
		var strName="Msxml2.XMLHTTP";
		if (navigator.appVersion.indexOf("MSIE 5.5")>=0)
		{
			strName="Microsoft.XMLHTTP";
		} 
		try
		{ 
			objXmlHttp=new ActiveXObject(strName);
			objXmlHttp.onreadystatechange=handler;
			return objXmlHttp;
		} 
		catch(e)
		{ 
			alert("Error. Scripting for ActiveX might be disabled");
			return;
		} 
	} 
	if (navigator.userAgent.indexOf("Mozilla")>=0)
	{
		objXmlHttp=new XMLHttpRequest();
		objXmlHttp.onload=handler;
		objXmlHttp.onerror=handler;
		return objXmlHttp;
	}
} 


function AddProduct(id,time)
{ 
	
	var ram,hd,warr,drive,caseprice,ramtx,hdtx,warrtx,drivetx;
	var pid,name,price,warrinf,fee,sh,cpu,groupid,info;
	
	if(id!="")
	{
		
		pid=document.getElementById('ID' + id ).value;			
		name=document.getElementById('Name' + id ).value;
		price=document.getElementById('Price' + id ).value;
		

		warrinf=document.getElementById('Warranty' + id ).value;
		fee=document.getElementById('Fee' + id ).value;
		sh=document.getElementById('SH' + id ).value;
		cpu=document.getElementById('CPU' + id ).value;
		groupid=document.getElementById('GroupID' + id ).value;
		
		info="pid="+pid+ "&name="+name +"&price=" + price + "&warrinfo="+ warrinf + "&fee=" + fee + "&sh="+ sh + "&cpu="+ cpu + "&groupid="+ groupid;
		

		ram=document.getElementById('ram' + id ).value;
		hd=document.getElementById('HD' + id ).value;		
		drive=document.getElementById('drive' + id ).value;	
		
		warr=document.getElementById('warrantytx' + id ).value;
		
		
		
		var index=document.getElementById('ram' + id ).selectedIndex;
		ramtx=document.getElementById('ram' + id ).options[index].text;

			
		index=document.getElementById('HD' + id ).selectedIndex;
		hdtx=document.getElementById('HD' + id ).options[index].text;
		
		index=document.getElementById('drive' + id ).selectedIndex;
		drivetx=document.getElementById('drive' + id ).options[index].text;
		
		index=document.getElementById('warrantytx' + id).selectedIndex;
		warrtx=document.getElementById('warrantytx' + id ).options[index].text;
			
		
		var str="ram="+ram+"&hd="+hd+"&drive="+drive+"&warr="+warr+"&ramtx="+ramtx+"&hdtx="+hdtx+"&drivetx="+drivetx+"&warrtx="+warrtx;
		
								
		
		var url="DesktopsAjax.asp?act=add&productID=" + id +"&" + str  +"&"+ info+"&time="+currentTime;
		
		//alert(url);
		xmlHttp=GetXmlHttpObject(stateChanged);
		xmlHttp.open("GET", url , true);
		xmlHttp.send(null);
	}
	
} 
function FillData()
{ 
	
	var url="DesktopsAjax.asp?productID=&time="+currentTime;
	xmlHttp=GetXmlHttpObject(stateChanged);
	xmlHttp.open("GET", url , true);
	xmlHttp.send(null);
	
	
} 

function EditProduct(id)
{ 
	
	var url="DesktopsAjax.asp?orderID=" + id + "&act=edit&time="+currentTime;
	xmlHttp=GetXmlHttpObject(stateChanged);
	xmlHttp.open("GET", url , true);
	xmlHttp.send(null);
	
	
} 

var pQty,rQty,hQty;
pQty=rQty=hQty="0";

function GetValue(txt)
{ 
			
	var subStr = "";
	var fail = "";
		
		if (txt.value == "") {
			subStr = subStr + "- Please enter quantity.\n";		
		}

		if (subStr != ""){
		    messStr="The following fields are required:\n";
		    messStr=messStr + "____________________________________\n\n";		
		    endStr="Please enter the requested information.  Thank you!";
		    alert(messStr + subStr + "____________________________________\n\n" + endStr);
		    
	    }
		else
		{
			
			if(txt.id=="product")
				pQty=txt.value;
			else if(txt.id=="ram")
				rQty=txt.value;
			else if(txt.id=="hd")
				hQty=txt.value;
				
		}			
} 

function UpdateQuantity(id)
{ 
	
	
		try{
				pQty=document.getElementById(id).value;
		}catch(err){; }
		if(!isNaN(pQty) && pQty>=0)
		{
			try{
				//rQty=document.getElementById('ram2').value;
				rQty=document.getElementById(id).value;
			}catch(err){; }
			try{
				//hQty=document.getElementById('hd22').value;
				hQty=document.getElementById(id).value;
			}catch(err){; }
			//alert("DesktopsAjax.asp?act=updateQuantity&pQty="+ pQty +"&rQty=" + rQty + "&hQty="+ hQty);
		//	alert(document.getElementById('hd22').value);
			var url="DesktopsAjax.asp?act=updateQuantity&pQty="+ pQty +"&rQty=" + rQty + "&hQty="+ hQty +"&id="+ 

id +"&time="+currentTime;
			xmlHttp=GetXmlHttpObject(stateChanged);
			xmlHttp.open("GET", url , true);
			xmlHttp.send(null);
		}
		else		
			alert("Invalid value!");
	
	
} 

function stateChanged() 
{ 
	//alert(xmlHttp.readyState);
	if (xmlHttp.readyState==4 || xmlHttp.readyState=="complete")
	{

		s = xmlHttp.responseText;
		ss = s.split("__,__");				
		
		
		document.getElementById('item').innerHTML=ss[0];
		document.getElementById('amount').innerHTML=ss[1];					
			
		document.getElementById('yourcart').innerHTML=ss[2];
			
			
			//document.getElementById('edit').innerHTML="";
				
		
		
		
	}
	currentTime=new Date();

} 


function numberOnly(txt,e) {
    obj = document.all ? window.event : e;
            touch = document.all ? obj.keyCode : obj.which;
            var txtValue = txt.value;
            var ch = String.fromCharCode(touch)                    
            if(String(parseFloat(txtValue + ch)) == "NaN" || (touch < 48 || touch > 57) && touch != 46 || (txtValue.indexOf

(".") != -1 && touch == 46) )
            {                     
                if(document.all) 
                {                 
                    obj.returnValue = false;                                 
                } 
                else 
                {               
                    obj.preventDefault();                 
                }
            }        
}

//-->