var xmlHttp;
var oID = '';

function act(type,id)
{ 
  oID = type;
	xmlHttp=GetXmlHttpObject();
	if (xmlHttp==null)
	{
		alert ("Browser does not support HTTP Request");
		return;
	}
	var url="get_hospit.php";
	url=url+"?type="+type+"&id="+id+"&sid="+Math.random();
	xmlHttp.onreadystatechange=stateChanged;
	xmlHttp.open("GET",url,true);
	xmlHttp.send(null);
}

function changeSel(type,id)
{ 
	if( type == 'cities' ) {
    act(type, id);
    select_depart = '<select name="f_rcities" class="textField" onchange="changeSel(\'depart\',this.value);"><option value=\"-1\">- Pasirinkite -</option></select>';
    document.getElementById('depart').innerHTML=select_depart;
    select_div = '<select name="f_rdepart" class="textField" onchange="changeSel(\'depart\',this.value);"><option value=\"-1\">- Pasirinkite -</option></select>';
  }
  else if( type == 'depart' ) {
    act(type, id);
    select_div = '<select name="f_rdepart" class="textField" onchange="changeSel(\'depart\',this.value);"><option value=\"-1\">- Pasirinkite -</option></select>';
    document.getElementById('div').innerHTML=select_div;
    document.getElementById('opt2').className = '';
    if( id == 0 ) {
      document.getElementById('opt2').className = 'hide';
      document.getElementById('opt3').className = 'hide';
      document.getElementById('opt4').className = '';
      document.getElementById('opt5').className = 'hide';
      document.getElementById('opt6').className = 'hide';
      document.getElementById('opt9').className = 'hide';
    }
    else {
      document.getElementById('opt4').className = 'hide';
    }

  }
  else if( type == 'div' ) {
    act(type, id);
    document.getElementById('opt3').className = '';
    document.getElementById('opt9').className = '';
    if( id == 0 ) {
      document.getElementById('opt3').className = 'hide';
      document.getElementById('opt5').className = '';
      document.getElementById('opt6').className = 'hide';
    }
    else {
      document.getElementById('opt5').className = 'hide';
      document.getElementById('opt6').className = 'hide';
    }

  }
  else if( type == 'other' ) {
    if( id == 0 )
      document.getElementById('opt6').className = '';
    else
      document.getElementById('opt6').className = 'hide';

  }
}

function stateChanged() 
{
	if (xmlHttp.readyState==4 || xmlHttp.readyState=="complete") {
		if(xmlHttp.responseText) {
			document.getElementById(oID).innerHTML=xmlHttp.responseText
    }
	}
}

function GetXmlHttpObject()
{
	var xmlHttp=null;
	try {
		// Firefox, Opera 8.0+, Safari
		xmlHttp=new XMLHttpRequest();
	}
	catch (e) {
		//Internet Explorer
		try {
			xmlHttp=new ActiveXObject("Msxml2.XMLHTTP");
		}
		catch (e) {
			xmlHttp=new ActiveXObject("Microsoft.XMLHTTP");
		}
	}
	return xmlHttp;
}
