﻿//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 delete_msg(msg_id){
	var conf = confirm('האם אתה בטוח שברצונך למחוק את ההודעה');	
	if(conf){
		var serverPage = "bo/functions/delete_msg.php?msg_id="+msg_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.tmunaveshelet.co.il/bo/?page=msg';
				}			
			}
		xmlHttp.send(null)
	}
}
function delete_album(album_id){
	var conf = confirm('האם אתה בטוח שברצונך למחוק את האלבום');	
	if(conf){
		var serverPage = "bo/functions/delete_album.php?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.tmunaveshelet.co.il/bo/?page=gallery';
				}			
			}
		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.tmunaveshelet.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;
	}
}
