//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 new_order_details(order_bride,order_groom,order_event_date,order_domain,order_password,order_notes){
	var url = "functions/invite_site_function.php";
	var params = "order_bride="+order_bride+"&order_groom="+order_groom+"&order_event_date="+order_event_date+"&order_domain="+order_domain+"&order_password="+order_password+"&order_notes="+order_notes+"";
	xmlHttp.open("POST", url, true);
	xmlHttp.onreadystatechange = function() {//Call a function when the state changes.
		if(xmlHttp.readyState == 4 && xmlHttp.status == 200) {
			alert(xmlHttp.responseText);
			
		}
	}
	//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 select_template(template_id){
	var serverPage = "functions/select_template.php?template_id="+template_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('step_1').style.display = 'none';
			document.getElementById('step_2').style.display = '';
			
			document.getElementById('step_1_img').src = 'images/order_steps/1.gif';
			document.getElementById('step_2_img').src = 'images/order_steps/22.gif';
			
			
			document.getElementById('order_template').value = template_id;
			
			document.getElementById('select_template_picture').src = 'images/templates_examples/'+template_id+'.jpg';
		}			
	}
	xmlHttp.send(null)
}
function send_site_to_friend(){
	
	var serverPage = "user/show_send_to_friend.php";
	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 id_name = "show_send_to_friend";
			if(document.getElementById(id_name)==null)
			{
				
				var newdiv = document.createElement('div');
				newdiv.setAttribute('id', id_name);

				newdiv.innerHTML = xmlHttp.responseText;
				document.body.appendChild(newdiv);
				var obj = document.getElementById(id_name);

				var width = 460;
				var height = 150;
				obj.style.width=width;
				obj.style.height=height;	
				
				var top = document.documentElement.scrollTop+100;
				var left = 	(document.documentElement.clientWidth/2)-(width/2);

				obj.style.top=""+top+"px";
				obj.style.left=""+left+"px";

				obj.style.position='absolute';
				obj.style.zIndex="3";

				Drag.init(obj);
			}
			else
			{
				var obj = document.getElementById(id_name);
				var width = 460;
				var height = 150;
				obj.style.width=width;
				obj.style.height=height;	
				
				var top = document.documentElement.scrollTop+100;
				var left = 	(document.documentElement.clientWidth/2)-(width/2);


				obj.style.top=""+top+"px";
				obj.style.left=""+left+"px";
				obj.style.display='none';
				obj.style.display='';
			}
		}
	}
	xmlHttp.send(null)
}
function forget_password(){	

	var serverPage = "user/show_forget_password.php";
	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 id_name = "show_forget_password";
			if(document.getElementById(id_name)==null)
			{
				
				var newdiv = document.createElement('div');
				newdiv.setAttribute('id', id_name);

				newdiv.innerHTML = xmlHttp.responseText;
				document.body.appendChild(newdiv);
				var obj = document.getElementById(id_name);

				var width = 460;
				var height = 150;
				obj.style.width=width;
				obj.style.height=height;	
				
				var top = document.documentElement.scrollTop+100;
				var left = 	(document.documentElement.clientWidth/2)-(width/2);

				obj.style.top=""+top+"px";
				obj.style.left=""+left+"px";

				obj.style.position='absolute';
				obj.style.zIndex="3";

				Drag.init(obj);
			}
			else
			{
				var obj = document.getElementById(id_name);
				var width = 460;
				var height = 150;
				obj.style.width=width;
				obj.style.height=height;	
				
				var top = document.documentElement.scrollTop+100;
				var left = 	(document.documentElement.clientWidth/2)-(width/2);


				obj.style.top=""+top+"px";
				obj.style.left=""+left+"px";
				obj.style.display='none';
				obj.style.display='';
			}
		}
	}
	xmlHttp.send(null)
}
function next_forward_picture_edit_page(pic_id,hide){	
	
	if(document.getElementById("show_picture_edit_view_"+hide) != null){
		document.getElementById("show_picture_edit_view_"+hide).style.display = 'none';		
	}
	if(document.getElementById("show_picture_edit_view_"+pic_id) != null){
		document.getElementById("show_picture_edit_view_"+pic_id).style.display = '';		
	}
	else{
		
		var serverPage = "user/pictures/next_picture_edit_page.php?picture_id="+pic_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 id_name = "show_picture_edit_view_"+pic_id;
			
				if(document.getElementById(id_name)==null){
					var newdiv = document.createElement('div');
					newdiv.setAttribute('id', id_name);
	                
					newdiv.innerHTML = xmlHttp.responseText;
					document.getElementById('picture_edit_div').appendChild(newdiv);
					var obj = document.getElementById(id_name);
					                							
					Drag.init(obj);
				}			
			}
		}
		xmlHttp.send(null)
	}
}
function update_picture_done(update_id){
	var conf = confirm('האם אתה בטוח שברצונך לסגור את העדכון?');	
	if(conf){
		var serverPage = "../bo/functions/update_picture.php?update_id="+update_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;
					window.location = 'http://www.wedd.co.il/bo/?page=updated'
				}			
			}
		xmlHttp.send(null)
	}
}
function delete_order(order_id){
	var conf = confirm('האם אתה בטוח שברצונך למחוק את ההזמנה?');	
	if(conf){
		var serverPage = "../bo/functions/delete_order.php?order_id="+order_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;
					window.location = 'http://www.wedd.co.il/bo'
				}			
			}
		xmlHttp.send(null)
	}
}
function delete_picture_talk(talkback_id,album_idtalkback_id_){
	var conf = confirm('האם אתה בטוח שברצונך למחוק תגובה זאת?');	
	if(conf){
		var serverPage = "user/pictures/delete_picture_talkback.php?talkback_id="+talkback_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("talkback_id_"+talkback_id).style.display='none';
				}			
			}
		xmlHttp.send(null)
	}
}
function delete_picture(picture_id,album_id){
	var conf = confirm('האם אתה בטוח שברצונך למחוק את התמונה?');	
	if(conf){
		var serverPage = "user/pictures/delete_picture.php?picture_id="+picture_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.wedd.co.il/user/?page=pictures&type=view_album&a_id='+album_id;
				}			
			}
		xmlHttp.send(null)
	}
}
//functions.js
function uploadimg (theform,loading_id){
	if(check_file(loading_id)){		
		document.getElementById("loading_image_"+loading_id).style.display=''
		document.getElementById("image_"+loading_id).style.display='none';	
		document.getElementById("error_message_"+loading_id).style.display='none';		
		document.getElementById("submit_"+loading_id).style.display='none';
		document.getElementById("select_file_"+loading_id).style.display='none';
		document.getElementById("picture_description_"+loading_id).style.display='none';
		
		theform.submit();
		return true;
	}
	else{
		return false;
	}
}
function add_picture_to_album(album_id){
	for(i=1; i<=100; i++){
		if(document.getElementById("add_picture_"+i+"_view") == null){
			var number = i;
			break;
		}		
	}
	
	var serverPage = "user/pictures/add_picture_to_album_aj.php?num="+number+"&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 id_name = "add_picture_"+number+"_view";
		
			if(document.getElementById(id_name)==null){
				var newdiv = document.createElement('div');
				newdiv.setAttribute('id', id_name);
                
				newdiv.innerHTML = xmlHttp.responseText;
				document.getElementById('upload_image_div').appendChild(newdiv);
				var obj = document.getElementById(id_name);
                							
				var width = 600+"px";
				
				obj.style.width=width;
				obj.style.height=height;
				
				Drag.init(obj);
			}			
		}
	}
	xmlHttp.send(null)
}
function delete_confirm(id){
	var conf = confirm('האם אתה בטוח שברצונך למחוק את אישור הגעה זה?');	
	if(conf){
		var serverPage = "user/confirm/delete_confirm.php?confirm_id="+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.wedd.co.il/user/?page=confirm';
			}			
		}
		xmlHttp.send(null)
	}
}
function delete_guestbook(id){
	var conf = confirm('האם אתה בטוח שברצונך למחוק ברכה זאת?');	
	if(conf){
		var serverPage = "user/guestsbook/delete_guestbook.php?guestbook_id="+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.wedd.co.il/user/?page=guest_book';
			}			
		}
		xmlHttp.send(null)
	}
}

function add_question_to_quiz(){
	if(document.getElementById('question_20_view') == null){
		var number = 20;
	}
	if(document.getElementById('question_19_view') == null){
		var number = 19;
	}
	if(document.getElementById('question_18_view') == null){
		var number = 18;
	}
	if(document.getElementById('question_17_view') == null){
		var number = 17;
	}
	if(document.getElementById('question_16_view') == null){
		var number = 16;
	}
	if(document.getElementById('question_15_view') == null){
		var number = 15;		
	}
	if(document.getElementById('question_14_view') == null){
		var number = 14;		
	}
	if(document.getElementById('question_13_view') == null){
		var number = 13;		
	}
	if(document.getElementById('question_12_view') == null){
		var number = 12;		
	}
	if(document.getElementById('question_11_view') == null){
		var number = 11;		
	}
	if(document.getElementById('question_10_view') == null){
		var number = 10;		
	}
	if(document.getElementById('question_9_view') == null){
		var number = 9;		
	}
	if(document.getElementById('question_8_view') == null){
		var number = 8;		
	}
	if(document.getElementById('question_7_view') == null){
		var number = 7;
	}
	if(document.getElementById('question_6_view') == null){
		var number = 6;		
	}
	if(document.getElementById('question_5_view') == null){
		var number = 5;
	}
	if(document.getElementById('question_4_view') == null){
		var number = 4;
	}
	if(document.getElementById('question_3_view') == null){
		var number = 3;
	}
	if(document.getElementById('question_2_view') == null){
		var number = 2;		
	}
	if(document.getElementById('question_1_view') == null){
		var number = 1;
		
	}
	if(number>=1 && number <=20){  
	var serverPage = "user/quiz/add_question_to_quiz_aj.php?num="+number;
	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 id_name = "question_"+number+"_view";
		
			if(document.getElementById(id_name)==null){
				var newdiv = document.createElement('div');
				newdiv.setAttribute('id', id_name);
                
				newdiv.innerHTML = xmlHttp.responseText;
				document.getElementById('add_question').appendChild(newdiv);
				var obj = document.getElementById(id_name);
                							
				var width = 600;
				var height = 300;
				obj.style.width=width;
				obj.style.height=height;
				
				Drag.init(obj);
			}			
		}
	}
	if (number>=20){
		alert('לא ניתן להוסיף יותר מ-20 שאלות');
	}
	xmlHttp.send(null)
	}
}

