//Gets the browser specific XmlHttpRequest Object


function getXmlHttpRequestObject() {


	if (window.XMLHttpRequest) {


		return new XMLHttpRequest(); //Not IE


	} else if(window.ActiveXObject) {


		return new ActiveXObject("Microsoft.XMLHTTP"); //IE


	} else {


		//Display your error message here. 


		//and inform the user they might want to upgrade


		//their browser.


		alert("Your browser doesn't support the XmlHttpRequest object.  Better upgrade to Firefox.");


	}


}	








//Get our browser specific XmlHttpRequest object.


var receiveReq = getXmlHttpRequestObject();	


var global_product_id = "";











//function for checking the email on get_contact_detail page


function control_home_page_image(val) {


	if (receiveReq.readyState == 4 || receiveReq.readyState == 0) {


		receiveReq.open("GET", 'ajax-php/home_page_imgl.php', true);


		receiveReq.onreadystatechange = handle_control_home_page_image; 


		receiveReq.send(null);


	}			


}





function handle_control_home_page_image() {


	if (receiveReq.readyState == 4) {


		if(receiveReq.responseText != "")


		{


			document.getElementById('home_image_div').innerHTML = receiveReq.responseText;


		}


	}


}








//function for checking the email on get_contact_detail page


function ajax_add_to_cart(product_id)
{
	var target = "id_add_to_cart" + product_id;


	var url = 'ajax-php/add_to_cart.php';

	if(document.getElementById("quantity"))
	{
		var quantity = document.getElementById("quantity").value;
	}
	else
	{
		var quantity = 1;
	}
	var pars = "product_id=" + product_id + "&quantity=" + quantity; 
	var myAjax = new Ajax.Updater(target, url, {method: 'get', parameters: pars});


}








//function for checking the email on get_contact_detail page


function ajax_remove_cart_items()


{


	


	var count_product = document.getElementById("count_product").value;


	var product_id_str = "";


	var total_price_id = 0;


	


	


	for(i=0;i<count_product;i++)


	{


		if(document.getElementById("chk" + i).checked == true)


		{


			product_id_str += document.getElementById("chk" + i).value + ",";


			total_price_id += document.getElementById("qty" + i).value * document.getElementById("price" + i).value;


			//document.getElementById("tr" + i).style.display = "none";


			


			//uncheck the removed field


			document.getElementById("chk" + i).checked = false;


			


		}


	}


	


	if(product_id_str == "")


	{


		alert("Please select atleast one product to remove from Cart.");


		return false;


	}


	


	var str_len = product_id_str.length;


	product_id_str = product_id_str.substr(0, str_len - 1); 





	//document.getElementById("total_price_id").innerHTML = document.getElementById("total_price_id").innerHTML - total_price_id;


	


	//var target = "id_updated";


	//var url = 'ajax-php/remove_cart.php';


	var pars = 'mode=remove&product_id_str='+product_id_str; 


	//alert(pars);


	//var myAjax = new Ajax.Updater(target, url, {method: 'get', parameters: pars});


	//alert(pars);


	window.location = "cart.php?" + pars;


}








function ajax_update_cart_items()


{


	//document.getElementById("id_updated").innerHTML = '<img src="images/ajax-loader.gif" border="0" /> <font color="#ffffff">Loading...</font>';





	var count_product = document.getElementById("count_product").value;


	var product_qty_str = "";


	var total_price_id = 0;





	


	for(i=0;i<count_product;i++)


	{


		if(document.getElementById("tr" + i).style.display != "none")


		{


			if(i < (count_product-1))


			{


				product_qty_str += Math.abs(document.getElementById("qty" + i).value) + ",";


				//document.getElementById("total_id" + i).innerHTML = Math.abs(document.getElementById("qty" + i).value) * document.getElementById("price" + i).value;


				total_price_id += Math.abs(document.getElementById("qty" + i).value) * document.getElementById("price" + i).value;


			}


			else


			{


				product_qty_str += Math.abs(document.getElementById("qty" + i).value);


				//document.getElementById("total_id" + i).innerHTML = Math.abs(document.getElementById("qty" + i).value) * document.getElementById("price" + i).value;


				total_price_id += Math.abs(document.getElementById("qty" + i).value) * document.getElementById("price" + i).value;


			}


		}


	}


	


	


	//document.getElementById("total_price_id").innerHTML = total_price_id;


	


	


	//var target = "id_updated";


	//var url = 'ajax-php/update_cart.php'; 


	var pars = 'mode=update&product_qty_str=' + product_qty_str; 


	//var myAjax = new Ajax.Updater(target, url, {method: 'get', parameters: pars});


	window.location = "cart.php?" + pars;


	


}








//function to add product to wishlist


function ajax_add_to_wishlist(product_id, is_login) {


	if(is_login == "no")


	{


		alert("Please login to add the Item to your wishlist.");


		return false;


	}


	global_product_id = product_id;


	if (receiveReq.readyState == 4 || receiveReq.readyState == 0) {


		receiveReq.open("GET", 'ajax-php/add_to_wishlist.php?product_id=' + product_id, true);


		receiveReq.onreadystatechange = handle_ajax_add_to_wishlist; 


		receiveReq.send(null);


	}			


}





function handle_ajax_add_to_wishlist() {


	if (receiveReq.readyState == 4) {


		if(receiveReq.responseText != "")


		{


			document.getElementById('id_add_to_wishlist' + global_product_id).innerHTML = receiveReq.responseText;


		}


	}


}








//function to remove product from wishlist


function ajax_remove_from_wishlist(product_id) {


	global_product_id = product_id;


	if (receiveReq.readyState == 4 || receiveReq.readyState == 0) {


		receiveReq.open("GET", 'ajax-php/remove_from_wishlist.php?product_id=' + product_id, true);


		receiveReq.onreadystatechange = handle_ajax_remove_from_wishlist; 


		receiveReq.send(null);


	}			


}





function handle_ajax_remove_from_wishlist() {


	if (receiveReq.readyState == 4) {


		if(receiveReq.responseText != "")


		{


			document.getElementById('id_add_to_wishlist' + global_product_id).innerHTML = receiveReq.responseText;


		}


	}


}






























