var xmlHttp = createXmlHttpRequestObject();

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;
}

function get_region_list(type) {
	var url;
	var country_id;
	var xmlDocumentElement;
	
	country_element_id = type + "_country";
	
	country_id = document.getElementById(country_element_id).value;
	url = "wa_terr_links.php?country_id=" + country_id + "&type=" + type;
	xmlHttp.open("GET", url, false);
	xmlHttp.send(null);
	
	region_element_id = type + "_region_list_area";
	
	if (xmlHttp.readyState == 4) {
		if (xmlHttp.status == 200) {
			xmlResponse = xmlHttp.responseText;
			document.getElementById(region_element_id).innerHTML = xmlResponse;
		}
	}
	
}

function get_region_list_for_lots(country_id) {
	var url;
	var xmlDocumentElement;
	
	url = "wa_terr_links.php?country_id=" + country_id + "&type=";
	xmlHttp.open("GET", url, false);
	xmlHttp.send(null);
	
	region_element_id = "_region_list_area";
	
	if (xmlHttp.readyState == 4) {
		if (xmlHttp.status == 200) {
			xmlResponse = xmlHttp.responseText;
			document.getElementById(region_element_id).innerHTML = xmlResponse;
		}
	}
	
}
function get_region_list_for_currentlots(country_id) {
	var url;
	var xmlDocumentElement;
	
	url = 'wa_terr_links.php?country_id_for_currentlots=' + country_id;
	xmlHttp.open("GET", url, false);
	xmlHttp.send(null);
	
	region_element_id = 'selectregion_container';
	
	if (xmlHttp.readyState == 4) {
		if (xmlHttp.status == 200) {
			xmlResponse = xmlHttp.responseText;
			document.getElementById(region_element_id).innerHTML = xmlResponse;
		}
	}
	
}
function get_region_list_for_currentlots_en(country_id) {
	var url;
	var xmlDocumentElement;
	
	url = 'wa_terr_links_en.php?country_id_for_currentlots=' + country_id;
	xmlHttp.open("GET", url, false);
	xmlHttp.send(null);
	
	region_element_id = 'selectregion_container';
	
	if (xmlHttp.readyState == 4) {
		if (xmlHttp.status == 200) {
			xmlResponse = xmlHttp.responseText;
			document.getElementById(region_element_id).innerHTML = xmlResponse;
		}
	}
	
}

function get_city_list(type) {
	var url;
	var country_id;
	var xmlDocumentElement;
	
	region_element_id = type + "_region";
	
	region_id = document.getElementById(region_element_id).value;
	url = "wa_terr_links.php?region_id=" + region_id + "&type=" + type;
	xmlHttp.open("GET", url, false);
	xmlHttp.send(null);
	
	city_element_id = type + "_city_list_area";
	
	if (xmlHttp.readyState == 4) {
		if (xmlHttp.status == 200) {
			xmlResponse = xmlHttp.responseText;
			document.getElementById(city_element_id).innerHTML = xmlResponse;
		}
	}
	
}

function hide_ya_area(){
	if (document.getElementById('fa_ya_show').value == 1){
		document.getElementById('fa_ya_show').value = 0;
		document.getElementById('ya_area').style.display = 'none';
	}
	else {
		document.getElementById('fa_ya_show').value = 1;
		document.getElementById('ya_area').style.display = 'block';
	}
}

function summa(aa){
	document.getElementById('all_cost').value = document.getElementById('count').value * document.getElementById('ed_cost').value;
}

function show_inn_file_area(){
	if (document.getElementById('display_inn_file_area').value == 1){
		document.getElementById('inn_file_area').style.display = 'none';
		document.getElementById('display_inn_file_area').value = 0;
	}
	else {
		document.getElementById('inn_file_area').style.display = 'block';
		document.getElementById('display_inn_file_area').value = 1;
	}
}

function show_ogrn_file_area(){
	if (document.getElementById('display_ogrn_file_area').value == 1){
		document.getElementById('ogrn_file_area').style.display = 'none';
		document.getElementById('display_ogrn_file_area').value = 0;
	}
	else {
		document.getElementById('ogrn_file_area').style.display = 'block';
		document.getElementById('display_ogrn_file_area').value = 1;
	}
}
