﻿//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 change_gift_option(){
	if(document.getElementById('gift').checked){
		var val = 1;		
		document.getElementById('gift_option').value = val;					
	}
	else{
		var val = 0;		
		document.getElementById('gift_option').value = val;
	}
}
function change_shipment_area(area_id){
	var serverPage = "functions/change_shipment_area.php?value="+area_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 temp = xmlHttp.responseText;			
			document.getElementById('change_supply_area_tbl').innerHTML = temp;			
			
		}			
	}
	xmlHttp.send(null)
	
}
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 -29 + "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 delete_picture(picture_id,album_id){
	var conf = confirm('האם אתה בטוח שברצונך למחוק את התמונה');	
	if(conf){
		var serverPage = "bo/functions/delete_picture.php?picture_id="+picture_id+"&album_id="+album_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;
					alert('התמונה נמחקה בהצלחה');				
					window.location = 'http://www.Tomb.co.il/bo/?page=gallery&type=view_album&a_id='+album_id
				}			
			}
		xmlHttp.send(null)
	}
}
function uploadimg (theform,loading_id){
	if(check_file_extension(loading_id)){		
		document.getElementById("loading_image_"+loading_id).style.display=''
		document.getElementById("image_"+loading_id).style.display='none';
		document.getElementById("picture_description_"+loading_id).style.display='none';
		document.getElementById("error_message_"+loading_id).style.display='none';
		document.getElementById("what_in_picture_"+loading_id).style.display='none';
		document.getElementById("submit_"+loading_id).style.display='none';
		document.getElementById("select_file_"+loading_id).style.display='none';
		
		theform.submit();
		return true;
	}
	else{
		return false;
	}
}

