/* - - - - - - - - - - - - - - - - - - - - - - -
 JavaScript
 Comments Architecture
 Tuesday, October 13, 2009 11:06 PM
 HAPedit 3.1.11.111
 Written by Perry Mason
 - - - - - - - - - - - - - - - - - - - - - - - */

var xmlhttp
var submitted_country_id = ""
var submitted_region_id  = ""
var submitted_field_name  = ""

//Called on when someone selects a country from the countries dropdown
function displayRegionsSelect(sel)
{
xmlhttp=GetXmlHttpObject();

   if(sel.options.selectedIndex == 0){
      alert('Please choose a country!');
      return false;
   } 

   submitted_country_id = sel.options[sel.selectedIndex].value
   submitted_field_name = sel.title

if (xmlhttp==null)
  {
  alert ("Your browser does not support AJAX!");
  return;
  }

var url="index2.php?option=com_locations&task=getRegionsLive";
//var url="components/com_comprofiler/like.php";
url=url+"&countryId="+submitted_country_id+"&fieldName="+submitted_field_name+"&sid="+Math.random();
//url=url+"&sid="+Math.random();

xmlhttp.onreadystatechange=stateChangedCountries;
xmlhttp.open("GET",url,true);
xmlhttp.send(null);

}



//Called on when the httpRequest responds to the call from addComment or deleteComment
function stateChangedCountries()
{

if (xmlhttp.readyState==4)
  {
  document.getElementById(submitted_field_name+"_regionsArea").innerHTML=xmlhttp.responseText;
  //displayCommentFormLive(submitted_type, submitted_item_id);
  }
}


//Called on when someone selects a region from the regions dropdown
function displayCitiesSelect(sel)
{
xmlhttp=GetXmlHttpObject();

   /*if(sel.options.selectedIndex == 0){
      alert('Please choose a region!');
      return false;
   }*/
   submitted_field_name = sel.title

   if(submitted_country_id == ""){

      var countryElement = document.getElementById(submitted_field_name+"_countryId")
      //alert("Country: "+countryElement.options[countryElement.selectedIndex].value)
      submitted_country_id = countryElement.options[countryElement.selectedIndex].value

   }

   submitted_region_id = sel.options[sel.selectedIndex].value


if (xmlhttp==null)
  {
  alert ("Your browser does not support AJAX!");
  return;
  }

var url="index2.php?option=com_locations&task=getCitiesLive";
//var url="components/com_comprofiler/like.php";
url=url+"&countryId="+submitted_country_id+"&fieldName="+submitted_field_name+"&regionId="+submitted_region_id+"&sid="+Math.random();
//url=url+"&sid="+Math.random();

xmlhttp.onreadystatechange=stateChangedRegions;
xmlhttp.open("GET",url,true);
xmlhttp.send(null);

}



//Called on when the httpRequest responds to the call from addComment or deleteComment
function stateChangedRegions()
{

if (xmlhttp.readyState==4)
  {
  document.getElementById(submitted_field_name+"_citiesArea").innerHTML=xmlhttp.responseText;
  //displayCommentFormLive(submitted_type, submitted_item_id);
  }
}





function GetXmlHttpObject()
{
if (window.XMLHttpRequest)
  {
  // code for IE7+, Firefox, Chrome, Opera, Safari
  return new XMLHttpRequest();
  }
if (window.ActiveXObject)
  {
  // code for IE6, IE5
  return new ActiveXObject("Microsoft.XMLHTTP");
  }
return null;
}

