// JavaScript Document
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 show_div(divid)
{
	$("#"+divid+":hidden:first").fadeIn("slow");
}
function hide_div(divid)
{
	$("#"+divid).fadeOut("slow");
}

var product_id='';
function add_to_cart_ajax(pid,quantity)
{
	product_id=pid;
	var divid='ajax_loader_'+product_id;
	show_div(divid);
	xmlHttp=GetXmlHttpObject();
	if(xmlHttp==null)
	{
	  alert ("Your browser does not support AJAX!");
	  return;
	}
	var url="add_to_cart_ajax.php?product_id="+product_id+"&quantity="+quantity;
	xmlHttp.onreadystatechange=addToCartAjax;
	xmlHttp.open("GET",url,true);
	xmlHttp.send(null);
}

function addToCartAjax()
{
	if(xmlHttp.readyState==4) 
	{
		var divid='ajax_loader_'+product_id;
		var but_id='order_now_'+product_id;
		var added_to_cart='added_to_cart_'+product_id;
		hide_div(divid);
		hide_div(but_id);
		show_div(added_to_cart);
		document.getElementById('item_number').innerHTML=xmlHttp.responseText;
	}
}




var busket_id;
function add_to_cart_ajax1(pid,bid,quantity)
{
	busket_id=bid;
	var divid='ajax_loader_'+busket_id;
	show_div(divid);
	xmlHttp=GetXmlHttpObject();
	if(xmlHttp==null)
	{
	  alert ("Your browser does not support AJAX!");
	  return;
	}
	var url="add_to_cart_ajax1.php?busket_id="+busket_id+"&quantity="+quantity+"&product_id="+pid;
	xmlHttp.onreadystatechange=addToCartAjax1;
	xmlHttp.open("GET",url,true);
	xmlHttp.send(null);
}

function addToCartAjax1()
{
	if(xmlHttp.readyState==4) 
	{
		var divid='ajax_loader_'+busket_id;
		hide_div(divid);
		var price_id='product_price_'+busket_id;
		
		var return_str=xmlHttp.responseText;
		var arr=new Array();
		arr=return_str.split(':');
		//alert(arr);
		document.getElementById(price_id).innerHTML=arr[0];
		document.getElementById('total_price').innerHTML=arr[1];
		if(arr.length>2)
		{
			document.getElementById('tax_price').innerHTML=arr[3];
			document.getElementById('final_price').innerHTML=arr[2];
			//Modified On 17-3-2011
			if(parseInt(arr[2])>3000)
			{
				document.getElementById('checkout_display_id').style.display='none';
				document.getElementById('no_checkout_id').style.display='block';
			}
			else
			{
				document.getElementById('no_checkout_id').style.display='none';
				document.getElementById('checkout_display_id').style.display='block';
			}
			//End Modified On 17-3-2011
		}
	}
}



/*Check Discunt Coupon*/
function check_discount_coupon()
{
	var discount_coupon=document.getElementById('discount_coupon').value;

	if(discount_coupon=="")
	{
		document.getElementById('frm_checkout').submit();
	}
	else
	{
		xmlHttp=GetXmlHttpObject();
		if(xmlHttp==null)
		{
		  alert ("Your browser does not support AJAX!");
		  return;
		}
		var url="check_discount_coupon_ajax.php?discount_coupon="+discount_coupon;
		//alert(url);
		xmlHttp.onreadystatechange=checkDiscountCoupon;
		xmlHttp.open("GET",url,true);
		xmlHttp.send(null);
	}
}

function checkDiscountCoupon()
{
	if(xmlHttp.readyState==4) 
	{
		if(xmlHttp.responseText>0)
		{
			document.getElementById('frm_checkout').submit();
		}
		else
		{
			document.getElementById('is_valid_discount_coupon').innerHTML="Invalid Discount Coupon.";
		}
	}
}
