var xmlHttp;
var a1,b1,c1,d1;
var temp;
function GetAmount(str,str2,str3,str4)
{
	a1=str;
	b1=str2;
	c1=str3;
	d1=str4;
	
xmlHttp=GetXmlHttpObject();
if (xmlHttp==null)
  {
  alert ("Your browser does not support AJAX!");
  return;
  } 
var url="getamt.php";
url=url+"?price="+str;
url=url+"&qty="+str2;
url=url+"&place="+str3;
url=url+"&count="+str4;
url=url+"&mode="+"ajax";
url=url+"&sid="+Math.random();
xmlHttp.onreadystatechange=stateChanged;
xmlHttp.open("GET",url,true);
xmlHttp.send(null);
}

function stateChanged() 
{ 
if (xmlHttp.readyState==4)
{ 
var a=xmlHttp.responseText;
if(a>0)
{
a=xmlHttp.responseText;	
}
else
{
a="";	
}
document.getElementById("amount"+c1).value=a;

GetTotalAmount(d1);

}
}

function GetTotalAmount(str4)
{
	var famount=0;
	var i;
	var tmpno=0;
	for(i=1;i<str4;i++)
	{
		if(parseInt(document.getElementById("amount"+i).value)>0)
		{
		famount=parseFloat(famount) + parseFloat(document.getElementById("amount"+i).value);
		tmpno=tmpno+1;
		}
		
		
	}
	if(tmpno<1)
	{
	famount="";
	document.getElementById("totalamount").value=famount;
	}
	else
	{
	document.getElementById("totalamount").value=famount.toFixed(2);
	}
	GetDiscount(a1,b1);
	
}

function GetDiscount(str,str2)
{
xmlHttp=GetXmlHttpObject();
if (xmlHttp==null)
  {
  alert ("Your browser does not support AJAX!");
  return;
  } 
var url="getdiscount.php";
url=url+"?price="+str;
url=url+"&qty="+str2;
url=url+"&mode="+"ajax";
url=url+"&sid="+Math.random();
xmlHttp.onreadystatechange=stateChanged2;
xmlHttp.open("GET",url,true);
xmlHttp.send(null);
}

function stateChanged2() 
{ 
if (xmlHttp.readyState==4)
{
var b=xmlHttp.responseText;
if(b>0)
{
b=xmlHttp.responseText;	
}
else
{
b="";	
}
document.getElementById("discount"+c1).value=b;
GetTotalDiscount(b1,d1);

}
}


function GetTotalDiscount(str2,str4)
{
	var fdiscount=0;
	var i;
	var tmpno=0;
	for(i=1;i<str4;i++)
	{
		if(parseFloat(document.getElementById("amount"+i).value)>0 && parseFloat(document.getElementById("discount"+i).value)>0)
		{
			
			fdiscount=parseFloat(fdiscount) + parseFloat(document.getElementById("discount"+i).value);
		tmpno=tmpno+1;
		}
		
	}
	if(tmpno<1)
	{
	fdiscount="";
	document.getElementById("totaldiscount").value=fdiscount;
	}
	else
	{
	document.getElementById("totaldiscount").value=fdiscount.toFixed(2);
	}
	getFinalAmount(a1,b1);
	
}

function getFinalAmount(str,str2)
{

xmlHttp=GetXmlHttpObject();
if (xmlHttp==null)
  {
  alert ("Your browser does not support AJAX!");
  return;
  } 
var url="getfinalamount.php";
url=url+"?price="+str;
url=url+"&qty="+str2;
url=url+"&mode="+"ajax";
url=url+"&sid="+Math.random();
xmlHttp.onreadystatechange=stateChanged4;
xmlHttp.open("GET",url,true);
xmlHttp.send(null);
}

function stateChanged4() 
{ 
if (xmlHttp.readyState==4)
{
var c=xmlHttp.responseText;
if(c>0)
{
c=xmlHttp.responseText;	
}
else
{
c="";	
}
document.getElementById("finalamount"+c1).value=c;
getTotalFinalAmount(a1,b1,d1);
}
}

function getTotalFinalAmount(str,str2,str4)
{
	var ftotamt=0;
	var i;
	var tmpno=0;
	for(i=1;i<str4;i++)
	{
		if(parseFloat(document.getElementById("finalamount"+i).value)>0)
		{
		ftotamt=parseFloat(ftotamt) + parseFloat(document.getElementById("finalamount"+i).value);
		tmpno=tmpno+1;
		}
		
	}
	//alert(tmpno);
	if(tmpno<1)
	{
	ftotamt="";
	document.getElementById("totalfinalamount").value=ftotamt;
	}
	else
	{
	document.getElementById("totalfinalamount").value=ftotamt.toFixed(2);
	}	
	getShipping(ftotamt);
	
}

function getShipping(str5)
{

xmlHttp=GetXmlHttpObject();
if (xmlHttp==null)
  {
  alert ("Your browser does not support AJAX!");
  return;
  } 
var url="getshipping.php";
url=url+"?ftotamt="+str5;
url=url+"&mode="+"ajax";
url=url+"&sid="+Math.random();
xmlHttp.onreadystatechange=stateChanged5;
xmlHttp.open("GET",url,true);
xmlHttp.send(null);
}

function stateChanged5() 
{ 
if (xmlHttp.readyState==4)
{	

document.getElementById("shippinghandling").value=xmlHttp.responseText;
getTotalPayable();
}
}

function getconsultancyfees(temp)
{

getTotalPayable(temp);
	
}

function getTotalPayable(temp)
{
	
	//var ftotamt;
	//var m,m2;
	var totpayable=0;
	var consultfees;
	

var shipping=document.getElementById("shippinghandling").value;	
var d=shipping;
if(d.length>0)
{
d=shipping;
}
else
{
d=0;
}
	
	if (temp>0)
	{
	consultfees=parseFloat(temp);
	}
	else
	{
	consultfees=0;	
	}
	
	
	var totfinamt=parseFloat(document.getElementById("totalfinalamount").value);
	var shipping=parseFloat(d);	
	totpayable=	totpayable + totfinamt + shipping + consultfees;											
	document.getElementById("totalpayable").value=totpayable.toFixed(2);	
	document.getElementById("totalfinalamount").value=totfinamt;
	
}


function addToBasket2(str,str2)
{	
if(str.length<1)
			{							
				alert("Please Enter Consultancy Amount.");
				document.form3.cfees.focus();
				return false;
			}
if (IsNumeric(str) == false) 
      {

				alert("Please Enter a Valid Consultancy Amount.");
				 document.getElementById('Qty' + i).value="";
				document.form3.cfees.focus();				
				return false;
			
	}
xmlHttp=GetXmlHttpObject();
if (xmlHttp==null)
  {
  alert ("Your browser does not support AJAX!");
  return;
  }
var url="addconsult.php";
url=url+"?cfees="+str;
url=url+"&action="+str2;
url=url+"&mode="+"ajax";
url=url+"&sid="+Math.random();
xmlHttp.onreadystatechange=stateChanged6;
xmlHttp.open("GET",url,true);
xmlHttp.send(null);
//document.getElementById("txtHint").innerHTML = "<img src=loading.gif>";
}

function stateChanged6() 
{ 
if (xmlHttp.readyState==4)
{

if(xmlHttp.responseText.length>2)
{
document.getElementById("object").style.display = '';
document.getElementById("consult").style.display = '';	
}
else
{
document.getElementById("consult").style.display = 'none';	
}
document.getElementById("txtHint").innerHTML=xmlHttp.responseText;
}
}



function resetBasket()
{	
var agree=confirm("Alert! All contents of shopping cart will be deleted?");
		if (agree)		
		xmlHttp=GetXmlHttpObject();
if (xmlHttp==null)
  {
  alert ("Your browser does not support AJAX!");
  return;
  }
var url="resetcart.php";
url=url+"?mode="+"ajax";
url=url+"&sid="+Math.random();
xmlHttp.onreadystatechange=stateChanged7;
xmlHttp.open("GET",url,true);
xmlHttp.send(null);
//document.getElementById("txtHint").innerHTML = "<img src=loading.gif>";
}

function stateChanged7() 
{ 
if (xmlHttp.readyState==4)
{
document.getElementById("object").style.display = 'none';
document.getElementById("consult").style.display = 'none';

document.getElementById("txtHint2").innerHTML=xmlHttp.responseText;
}
		else
		return false;
		

}
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;
}

function IsNumeric(strString)
   //  check for valid numeric strings	
   {
   var strValidChars = "1234567890";
   var strChar;
   var blnResult = true;

  
   //  test strString consists of valid characters listed above
   for (i = 0; i < strString.length && blnResult == true; i++)
      {
      strChar = strString.charAt(i);
      if (strValidChars.indexOf(strChar) == -1)
         {
         blnResult = false;
         }
      }
   return blnResult;
   }


//validate update category fields	
	function GetValidate(maxqty)
	{
		
		//alert(maxqty);
		var form =document.form3;		
		var count=document.form3.counter.value;
		var i;			
	
			for(i=1;i<count;i++)
		{
		
			
			var strValue = eval("form.Qty" + i + ".value");			
			
			if (IsNumeric(strValue) == false ) 
            {

				alert("Please Enter a Valid Qty.");
				 document.getElementById('Qty' + i).value="";
				eval("form.Qty" + i + ".focus()");				
				return false;
				
			
			}
			
			//var strValue1 = document.getElementById('Qty' + i).value;			
			
			if (parseInt(document.getElementById('Qty' + i).value)  > parseInt(maxqty)) 
            {

				alert("Entered Quantity too high");
				 document.getElementById('Qty' + i).value="";
				eval("form.Qty" + i + ".focus()");				
				return false;
			
			}
			
				
			
		}
			
			return true;
	}	
//End.