// stores the reference to the XMLHttpRequest object
/*var xmlHttp = createXmlHttpRequestObject(); 

// retrieves the XMLHttpRequest object
function createXmlHttpRequestObject() 
{	
  // will store the reference to the XMLHttpRequest object
  var xmlHttp;
  // if running Internet Explorer
  if(window.ActiveXObject)
  {
    try
    {
      xmlHttp = new ActiveXObject("Microsoft.XMLHTTP");
    }
    catch (e) 
    {
      xmlHttp = false;
    }
  }
  // if running Mozilla or other browsers
  else
  {
    try 
    {
      xmlHttp = new XMLHttpRequest();
    }
    catch (e) 
    {
      xmlHttp = false;
    }
  }
  // return the created object or display an error message
  if (!xmlHttp)
 
    alert("Error creating the XMLHttpRequest object.");
  else 
    return xmlHttp;
}

// make asynchronous HTTP request using the XMLHttpRequest object 
function ajax_add_company(name, loading_div_id)
{
	document.getElementById(loading_div_id).innerHTML = 'Please wait..';
  // proceed only if the xmlHttp object isn't busy
  if (xmlHttp.readyState == 4 || xmlHttp.readyState == 0)
  {
    //xmlHttp.open("GET", "/home/igalstl/public_html/admin/ajax_func.php?action=add_company&company_name="+name, true);  
    //xmlHttp.open("GET", "C:\WebServer\www\igal/"+ajax_func+"?action=add_company&company_name="+name, true);
    xmlHttp.open("GET", window.web_path+"admin/ajax_func.php?action=add_company&company_name="+name, true);
    xmlHttp.onreadystatechange = function () {ajax_add_company_response(name, loading_div_id)};
    xmlHttp.send(null);
  }
  else
    // if the connection is busy, try again after one second  
    setTimeout('ajax_add_company(name, loading_div_id)', 1000);
}

// executed automatically when a message is received from the server
function ajax_add_company_response(name, loading_div_id)
{	
	if (xmlHttp.readyState == 4)
    if (xmlHttp.status == 200) {	
    	
		if (xmlHttp.responseText=='1') {
			document.getElementById(loading_div_id).innerHTML = '<font style="color:green;">Added!</font>';
		}
		else {
			document.getElementById(loading_div_id).innerHTML = '';
			alert('Company already exists!');
			return false;
		}
		
    } 
    else {
      alert("There was a problem accessing the server: " + xmlHttp.statusText);
    }
}


function ajax_rename_company(id,new_name) {
	document.getElementById('company_loading_'+id).className = 'loading';
	if (xmlHttp.readyState == 4 || xmlHttp.readyState == 0)
	  {
	    xmlHttp.open("GET", window.web_path+"admin/ajax_func.php?action=rename_company&company_id="+id+"&company_name="+new_name, true);
	    xmlHttp.onreadystatechange = function () {ajax_rename_company_response(id,new_name)};
	    xmlHttp.send(null);
	  } else
	    // if the connection is busy, try again after one second  
	    setTimeout('ajax_rename_company(id,new_name)', 1000);
}

// executed automatically when a message is received from the server
function ajax_rename_company_response(id,new_name)
{	
	if (xmlHttp.readyState == 4)
    if (xmlHttp.status == 200) {	
    	
		if (xmlHttp.responseText=='1') {
			document.getElementById('company_loading_'+id).className = 'loading_completed';
		}
		
    } 
    else {
      alert("There was a problem accessing the server: " + xmlHttp.statusText);
    }
}


function ajax_delete_element(type,id) {
	if (xmlHttp.readyState == 4 || xmlHttp.readyState == 0)
	  {
	    xmlHttp.open("GET", window.web_path+"admin/ajax_func.php?action=delete_"+type+"&"+type+"_id="+id, true);
	    xmlHttp.onreadystatechange = function () {ajax_delete_element_response(type,id)};
	    xmlHttp.send(null);
	  } else
	    // if the connection is busy, try again after one second  
	    setTimeout('ajax_delete_element(type,id)', 1000);
}

// executed automatically when a message is received from the server
function ajax_delete_element_response(type, id)
{	
	if (xmlHttp.readyState == 4)
    if (xmlHttp.status == 200) {	
    	
		if (xmlHttp.responseText=='1') {
			document.getElementById('tr_'+type+'_'+id).style.display = 'none';
			//alert('got it');
		}
		
    } 
    else {
      alert("There was a problem accessing the server: " + xmlHttp.statusText);
    }
}


function ajax_change_current_template(template_name) {
	if (xmlHttp.readyState == 4 || xmlHttp.readyState == 0)
	  {
	    xmlHttp.open("GET", window.web_path+"admin/ajax_func.php?action=change_current_template&template_name="+template_name, true);
	    xmlHttp.onreadystatechange = function () {ajax_change_current_template_response(template_name)};
	    xmlHttp.send(null);
	  } else
	    // if the connection is busy, try again after one second  
	    setTimeout('ajax_change_current_template(template_name)', 1000);	
}
function ajax_change_current_template_response(template_name)
{	
	if (xmlHttp.readyState == 4)
    if (xmlHttp.status == 200) {	
    	
		if (xmlHttp.responseText=='1') {
			//document.getElementById(template_name).style.display = 'none';
			window.location.reload();
		}
		
    } 
    else {
      alert("There was a problem accessing the server: " + xmlHttp.statusText);
    }
}*/



function ajax_delete_element(type,id) {
	$.post(window.web_path+"admin/ajax_func.php", {action:'delete', type:type, id:id }, function(data)
	{
		window.location = window.location.href;
	});
}


function choose_and_close(page_ID, target_page_ID) {
	if(!target_page_ID) target_page_ID='';
	if(opener.document.getElementById('parent_page_ID')) { opener.document.getElementById('parent_page_ID').innerHTML = 'Loading..'; }
	if(opener.document.getElementById('navigation_blocks')) { opener.document.getElementById('navigation_blocks').innerHTML = 'Loading..'; }
	
	$.post(window.web_path+"admin/ajax_func.php", {action:'get_page_name_by_id', page_ID:page_ID }, function(data) {
		
		opener.document.getElementById('parent_page_ID').innerHTML = data;
		opener.document.getElementById('txtparent_page_ID').value = page_ID;
		
		$.post(window.web_path+"admin/ajax_func.php", {action:'get_navigation_blocks_by_parent_ID', parent_ID:page_ID, target_page_ID:target_page_ID }, function(navigation_data) {
			if(opener.document.getElementById('navigation_blocks')) opener.document.getElementById('navigation_blocks').innerHTML = navigation_data;
			window.close();
		});
	});
}