﻿//holds an instance of XMLHttpRequest
var xmlHttp = createXmlHttpRequestObject();
// creates an XMLHttpRequest instance
function createXmlHttpRequestObject(){
	// will store the reference to the XMLHttpRequest object
	var xmlHttp;
	// this should work for all browsers except IE6 and older
	try{
		// try to create XMLHttpRequest object
		xmlHttp = new XMLHttpRequest();
	}
	catch(e){
		// assume IE6 or older
		var XmlHttpVersions = new Array("MSXML2.XMLHTTP.6.0",
		"MSXML2.XMLHTTP.5.0",
		"MSXML2.XMLHTTP.4.0",
		"MSXML2.XMLHTTP.3.0",
		"MSXML2.XMLHTTP",
		"Microsoft.XMLHTTP");
		// try every prog id until one works
		for (var i=0; i<XmlHttpVersions.length && !xmlHttp; i++)
		{
			try
			{
				// try to create XMLHttpRequest object
				xmlHttp = new ActiveXObject(XmlHttpVersions[i]);
			}
			catch (e) {}
		}
	}
	// return the created object or display an error message
	if (!xmlHttp){
	alert("Error creating the XMLHttpRequest object.");
	}
	return xmlHttp;
}
function search_auto_comp(value){

	var serverPage = "functions/search_auto_comp.php?value="+value;
	xmlHttp.open("GET",serverPage);
	xmlHttp.setRequestHeader("Content-type", "application/x-www-form-urlencoded; charset=utf-8");	
	xmlHttp.onreadystatechange = function(){
	if(xmlHttp.readyState == 4 && xmlHttp.status == 200){		    
			var temp = xmlHttp.responseText;
			
			var h = document.getElementById('term');
			var obj = document.getElementById('search_result_div');
			
			//obj.style.opacity = 5/10;
			//obj.style.filter = 'alpha(opacity=' + 5*10 + ')';

			
			
			myPos = findPos(h)
			var left = myPos[0];
			var top = myPos[1];
				
			obj.style.left = left -350 + "px"
			obj.style.top = top+25 + "px"
			if(temp==undefined){
				temp='';				
			}
			obj.style.position='absolute';
			obj.style.zIndex="3";
			obj.innerHTML = temp;
			obj.style.display = '';
		}			
	}
	xmlHttp.send(null)
}
function manual_shipment_option(value){
var obj = document.getElementById('manual_shipment_type').checked;
var url = "functions/manual_shipment_type_change.php";
	var params = "shipment_type="+obj+"";
	xmlHttp.open("POST", url, true);
	xmlHttp.onreadystatechange = function() {//Call a function when the state changes.
		if(xmlHttp.readyState == 4 && xmlHttp.status == 200) {
			window.location = 'http://www.Kimurim.co.il/?page=shop_cart';
		}
	}
	//Send the proper header information along with the request
	xmlHttp.setRequestHeader("Content-type", "application/x-www-form-urlencoded");
	xmlHttp.setRequestHeader("Content-length", params.length);
	xmlHttp.setRequestHeader("Connection", "close");
	
	xmlHttp.send(params);
	return true;
}
function add_product_to_cart2(product_id){
	var serverPage = "functions/add_product_to_cart.php?product_id="+product_id;
	xmlHttp.open("GET",serverPage);
	xmlHttp.setRequestHeader("Content-type", "application/x-www-form-urlencoded; charset=utf-8");	
	xmlHttp.onreadystatechange = function(){
		if(xmlHttp.readyState == 4 && xmlHttp.status == 200){		    
			var test = xmlHttp.responseText;			
			document.getElementById('cart_counter').innerHTML = "("+test+")";
			alert('המוצר נוסף בהצלחה לעגלת הקניות');		
		}			
	}
	xmlHttp.send(null)
}
function count_customize(customize_id){	
	var serverPage = "functions/count_customize.php?customize_id="+customize_id;
	xmlHttp.open("GET",serverPage);
	xmlHttp.setRequestHeader("Content-type", "application/x-www-form-urlencoded; charset=utf-8");	
	xmlHttp.onreadystatechange = function(){
		if(xmlHttp.readyState == 4 && xmlHttp.status == 200){		    
			var test = xmlHttp.responseText;			
		}			
	}
	xmlHttp.send(null)
}
function count_news(news_id){	
	var serverPage = "functions/count_news.php?news_id="+news_id;
	xmlHttp.open("GET",serverPage);
	xmlHttp.setRequestHeader("Content-type", "application/x-www-form-urlencoded; charset=utf-8");	
	xmlHttp.onreadystatechange = function(){
		if(xmlHttp.readyState == 4 && xmlHttp.status == 200){		    
			var test = xmlHttp.responseText;			
		}			
	}
	xmlHttp.send(null)
}
function count_marquee(marquee_id){
	
	var serverPage = "functions/count_marquee.php?marquee_id="+marquee_id;
	xmlHttp.open("GET",serverPage);
	xmlHttp.setRequestHeader("Content-type", "application/x-www-form-urlencoded; charset=utf-8");	
	xmlHttp.onreadystatechange = function(){
		if(xmlHttp.readyState == 4 && xmlHttp.status == 200){		    
			var test = xmlHttp.responseText;			
		}			
	}
	xmlHttp.send(null);	
}
function count_links(link_id){
	
	var serverPage = "functions/count_links.php?link_id="+link_id;
	xmlHttp.open("GET",serverPage);
	xmlHttp.setRequestHeader("Content-type", "application/x-www-form-urlencoded; charset=utf-8");	
	xmlHttp.onreadystatechange = function(){
		if(xmlHttp.readyState == 4 && xmlHttp.status == 200){		    
			var test = xmlHttp.responseText;			
		}			
	}
	xmlHttp.send(null);	
}
