function prop_check(field){

var theForm = field.form;
var valueget=field.value;
if (field.value==0){
for(z=0; z<theForm.length;z++){
  if(theForm[z].type == 'checkbox' &&  theForm[z].name == 'TypeProperties[]' &&  theForm[z].value != '0'){
   theForm[z].checked=false
  }
  }
}
else{
for(z=0; z<theForm.length;z++){
  if(theForm[z].type == 'checkbox' &&  theForm[z].name == 'TypeProperties[]' &&  theForm[z].value == '0'){
   theForm[z].checked=false
  }
  }
}


}

function search_geo(newlayer,oldlayer1,oldlayer2){
//var menu1= 
 if (typeof oldlayer1 != 'undefined' ) 
  document.getElementById(oldlayer1).innerHTML="";
  
 if (typeof oldlayer2 != 'undefined' ) 
  document.getElementById(oldlayer2).innerHTML="";
  
document.getElementById(newlayer).innerHTML="";
document.getElementById(newlayer).innerHTML="<table class=\"checkUser\">"+
	"<tr>"+
		"<td><select id=\"search_country\" name=\"search_country\"  onchange=\"getRegioni(this.value);\" style=\"width:80px;\"></select></td>"+
    "<td><select id=\"search_regioni\" name=\"search_regioni\" onchange=\"getProvince(this.value);\"  style=\"width:165px;\"></select></td>"+
    "<td><select id=\"search_province\" name=\"search_province\"  onchange=\"getComuni(this.value);\" style=\"width:50px;\"  ></select></td>"+
    "<td><select id=\"search_comuni\" name=\"search_comuni\"    style=\"width:210px;\"  ></select></td>"+
	"</tr>"+
"</table>";
 initformsearch();

} 
function toggle_it(itemID,newlayer,oldlayer1,oldlayer2){
//var menu1= 
 if (typeof oldlayer1 != 'undefined' ) 
  document.getElementById(oldlayer1).innerHTML="";
  
 if (typeof oldlayer2 != 'undefined' ) 
  document.getElementById(oldlayer2).innerHTML="";
  
document.getElementById(newlayer).innerHTML="";

if (itemID=="azienda")
          document.getElementById(newlayer).innerHTML="<table class=\"checkUser\">"+
	"<tr>"+
		"<td><input type=\"checkbox\" name=\"TypeProperties[]\" checked=\"checked\" value=\"0\" onclick=\"prop_check(this);\" />Tutti</td>"+
    "<td><input type=\"checkbox\" name=\"TypeProperties[]\" value=\"10\" onclick=\"prop_check(this);\" />Ufficio</td>"+
    "<td><input type=\"checkbox\" name=\"TypeProperties[]\"  value=\"11\"onclick=\"prop_check(this);\" />Negozio</td>"+
     "<td><input type=\"checkbox\" name=\"TypeProperties[]\"  value=\"12\"onclick=\"prop_check(this);\" />Magazzino</td>"+
	"</tr><tr>"+
	 "<td><input type=\"checkbox\" name=\"TypeProperties[]\" value=\"13\" onclick=\"prop_check(this);\" />Laboratorio</td>"+
		"<td><input type=\"checkbox\" name=\"TypeProperties[]\" value=\"14\" onclick=\"prop_check(this);\" />Attivita' commerciale</td>"+
    "<td><input  type=\"checkbox\" name=\"TypeProperties[]\" value=\"15\" onclick=\"prop_check(this);\" />Capannone</td>"+
    "<td><input type=\"checkbox\" name=\"TypeProperties[]\" value=\"16\" onclick=\"prop_check(this);\"/>Albergo</td>"+
	"</tr>"+
"</table>";
else if (itemID=="privato")
    document.getElementById(newlayer).innerHTML="<table class=\"checkUser\">"+
	"<tr>"+
		"<td><input type=\"checkbox\" name=\"TypeProperties[]\" checked=\"checked\" value=\"0\" onclick=\"prop_check(this);\" />Tutti</td>"+
    "<td><input type=\"checkbox\" name=\"TypeProperties[]\" value=\"1\" onclick=\"prop_check(this);\" />Bifamiliare</td>"+
    "<td><input type=\"checkbox\" name=\"TypeProperties[]\" value=\"2\" onclick=\"prop_check(this);\" />Appartamento</td>"+
    "<td><input type=\"checkbox\" name=\"TypeProperties[]\"  value=\"3\"onclick=\"prop_check(this);\" />Attico</td>"+
    "<td><input  type=\"checkbox\" name=\"TypeProperties[]\" value=\"6\" onclick=\"prop_check(this);\" />Rustico</td>"+
    "<td><input type=\"checkbox\" name=\"TypeProperties[]\" value=\"30\" onclick=\"prop_check(this);\"/>Palazzetto</td>"+
	"</tr><tr>"+
	  "<td><input type=\"checkbox\" name=\"TypeProperties[]\" value=\"9\" onclick=\"prop_check(this);\"/>Casa Singola</td>"+ 
		"<td><input type=\"checkbox\" name=\"TypeProperties[]\" value=\"5\" onclick=\"prop_check(this);\" />Trifamiliare</td>"+
    "<td><input type=\"checkbox\" name=\"TypeProperties[]\"  value=\"8\"onclick=\"prop_check(this);\" />Villetta a schiera</td>"+
    "<td><input type=\"checkbox\" name=\"TypeProperties[]\" value=\"4\" onclick=\"prop_check(this);\" />Villa</td>"+   
    "<td><input type=\"checkbox\" name=\"TypeProperties[]\" value=\"7\" onclick=\"prop_check(this);\"/>Box</td>"+
     
	"</tr>"+
"</table>";
else  
  document.getElementById(newlayer).innerHTML="<table class=\"checkUser\">"+
	"<tr>"+
		"<td><input type=\"checkbox\" name=\"TypeProperties[]\" checked=\"checked\" value=\"0\" onclick=\"prop_check(this);\" />Tutti</td>"+
    "<td><input type=\"checkbox\" name=\"TypeProperties[]\" value=\"20\" onclick=\"prop_check(this);\" />Terreno agricolo</td>"+
    "<td><input type=\"checkbox\" name=\"TypeProperties[]\" value=\"21\" onclick=\"prop_check(this);\" />Terreno edificabile</td>"+
    "<td><input type=\"checkbox\" name=\"TypeProperties[]\"  value=\"22\"onclick=\"prop_check(this);\" />Terreno industriale</td>"+
	"</tr>"+
"</table>";
  

} 
function toggle_it_all(newlayer){
         document.getElementById(newlayer).innerHTML="<table>"+
	"<tr>"+
		"<td><input type=\"checkbox\" name=\"TypeProperties[]\" checked=\"checked\" value=\"0\" onclick=\"prop_check(this);\" />Tutti</td>"+
    "<td><input type=\"checkbox\" name=\"TypeProperties[]\" value=\"10,Ufficio\" onclick=\"prop_check(this);\" />Ufficio</td>"+
    "<td><input type=\"checkbox\" name=\"TypeProperties[]\"  value=\"11,Negozio\"onclick=\"prop_check(this);\" />Negozio</td>"+
     "<td><input type=\"checkbox\" name=\"TypeProperties[]\"  value=\"12,Magazzino\"onclick=\"prop_check(this);\" />Magazzino</td>"+
	"</tr><tr>"+
	 "<td><input type=\"checkbox\" name=\"TypeProperties[]\" value=\"13,Laboratorio\" onclick=\"prop_check(this);\" />Laboratorio</td>"+
		"<td><input type=\"checkbox\" name=\"TypeProperties[]\" value=\"14,Attivita\' commerciale\" onclick=\"prop_check(this);\" />Attivita' commerciale</td>"+
    "<td><input  type=\"checkbox\" name=\"TypeProperties[]\" value=\"15,Capannone\" onclick=\"prop_check(this);\" />Capannone</td>"+
    "<td><input type=\"checkbox\" name=\"TypeProperties[]\" value=\"16,Albergo\" onclick=\"prop_check(this);\"/>Albergo</td>"+
	"</tr>"+
	"<tr>"+
		"<td><input type=\"checkbox\" name=\"TypeProperties[]\" value=\"4,Villa\" onclick=\"prop_check(this);\" />Villa</td>"+
		"<td><input type=\"checkbox\" name=\"TypeProperties[]\" value=\"5,Trifamiliare\" onclick=\"prop_check(this);\" />Trifamiliare</td>"+
		"<td><input type=\"checkbox\" name=\"TypeProperties[]\" value=\"1,Bifamiliare\" onclick=\"prop_check(this);\" />Bifamiliare</td>"+
		"<td><input type=\"checkbox\" name=\"TypeProperties[]\" value=\"8,Villetta a schiera\" onclick=\"prop_check(this);\"/>Villetta a schiera</td>"+
		"<td><input type=\"checkbox\" name=\"TypeProperties[]\" value=\"9,Casa singola\" onclick=\"prop_check(this);\"/>Casa singola</td>"+
	"</tr>"+
	"<tr>"+
    "<td><input type=\"checkbox\" name=\"TypeProperties[]\" value=\"2,Appartamento\" onclick=\"prop_check(this);\" />Appartamento</td>"+
    "<td><input type=\"checkbox\" name=\"TypeProperties[]\"  value=\"3,Attico\"onclick=\"prop_check(this);\" />Attico</td>"+
    "<td><input  type=\"checkbox\" name=\"TypeProperties[]\" value=\"6,Rustico\" onclick=\"prop_check(this);\" />Rustico</td>"+
    "<td><input type=\"checkbox\" name=\"TypeProperties[]\" value=\"7,Box\" onclick=\"prop_check(this);\"/>Box</td>"+
    "<td><input type=\"checkbox\" name=\"TypeProperties[]\" value=\"30,Palazzetto\" onclick=\"prop_check(this);\" />Palazzetto</td>"+
	"</tr>"+
 	"<tr>"+
    "<td><input type=\"checkbox\" name=\"TypeProperties[]\" value=\"20,Terreno agricolo\" onclick=\"prop_check(this);\" />Terreno agricolo</td>"+
    "<td><input type=\"checkbox\" name=\"TypeProperties[]\" value=\"21,Terreno edificabile\" onclick=\"prop_check(this);\" />Terreno edificabile</td>"+
    "<td><input type=\"checkbox\" name=\"TypeProperties[]\"  value=\"22,Terreno industriale\"onclick=\"prop_check(this);\" />Terreno industriale</td>"+
	"</tr>"+
"</table>";	

}
var ajax = new Array();
function initformsearch(){
getCountryInit();
}
function getCountryInit(){
    document.getElementById('search_country').options.length = 0;
		var index = ajax.length;
		ajax[index] = new sack();
		ajax[index].requestFile = 'varpage/formSearchPosition.php?getCountry=1';	// Specifying which file to get
		ajax[index].onCompletion = function(){ iCountry(index) };	// Specify function that will be executed after file has been found
		ajax[index].runAJAX();		// Execute AJAX function
}
function getCountry(value){
 
    document.getElementById('search_country').options.length = 0;
		var index = ajax.length;
		ajax[index] = new sack();
		ajax[index].requestFile = 'varpage/formSearchPosition.php?getCountry='+value;	// Specifying which file to get
		ajax[index].onCompletion = function(){ createCountry(index) };	// Specify function that will be executed after file has been found
		ajax[index].runAJAX();		// Execute AJAX function
}
function getRegioni(value){
  document.getElementById('search_regioni').options.length = 0;
  var index = ajax.length;
	ajax[index] = new sack();
	ajax[index].requestFile = 'varpage/formSearchPosition.php?codeCountry='+value;	// Specifying which file to get
	ajax[index].onCompletion = function(){ createRegioni(index) };	// Specify function that will be executed after file has been found
	ajax[index].runAJAX();
	}
function getProvince(value){
   document.getElementById('search_province').options.length = 0;
  var index = ajax.length;
	ajax[index] = new sack();
	ajax[index].requestFile = 'varpage/formSearchPosition.php?codeRegion='+value;	// Specifying which file to get
	ajax[index].onCompletion = function(){ createProvince(index) };	// Specify function that will be executed after file has been found
	ajax[index].runAJAX();
	
}
function getComuni(value){
  document.getElementById('search_comuni').options.length = 0;
  var index = ajax.length;
	ajax[index] = new sack();
	ajax[index].requestFile = 'varpage/formSearchPosition.php?codeProvince='+value;	// Specifying which file to get
	ajax[index].onCompletion = function(){ createComuni(index) };	// Specify function that will be executed after file has been found
	ajax[index].runAJAX();
}

function createCountry(index){

	var obj = document.getElementById('search_country');
	eval(ajax[index].response);	// Executing the response from Ajax as Javascript code

	}
function iCountry(index){

	var obj = document.getElementById('search_country');
	eval(ajax[index].response);	// Executing the response from Ajax as Javascript code
	obj.options[1].selected=true;
	getRegioni("1");

  
	}
function createRegioni(index){
	var obj = document.getElementById('search_regioni');
	eval(ajax[index].response);	// Executing the response from Ajax as Javascript code
	getProvince(obj.options[0].value);
}
function createProvince(index){
  var obj = document.getElementById('search_province');
	eval(ajax[index].response);	// Executing the response from Ajax as Javascript code
	getComuni(obj.options[0].value);
}
function createComuni(index){
  var obj = document.getElementById('search_comuni');
  eval(ajax[index].response);	// Executing the response from Ajax as Javascript code

}
