
AjaxPro.timeoutPeriod = 240000;

AjaxPro.onTimeout=function(err)
{
  alert('timeout');
}

AjaxPro.onError = function(err)
{
	if(err.Type == 'ConnectFailure')
	{
	    alert('Blad');
		return;
    }

	if(err.Type == 'System.NullReferenceException')
	{
		alert('Blad');
		return;
	}
	
	
	
}


function GetRegions(regiontype,parentid)
{
	return Modules_Search.GetRegions(regiontype,parentid);
}
function OnchangeWoj(ddlwoj,ddlPowiatyId,ddlGminyId,ddlMiastaId)
{
  idwoj = ddlwoj.options[ddlwoj.options.selectedIndex].value;
 
  //Wojewodzwtwo = 1,Powiat = 2,Gmina = 3,   Miasto =4
  powiaty = GetRegions(2,idwoj);
  BindDDL(document.getElementById(ddlPowiatyId),powiaty.value);
  gminy = GetRegions(3,powiaty.value[0].Id);
  BindDDL(document.getElementById(ddlGminyId),gminy.value);
  miasta = GetRegions(4,idwoj);
 
  BindDDL(document.getElementById(ddlMiastaId),miasta.value);
}
function OnchangePow(ddlpowiaty,ddlGminyId)
{
  idpow = ddlpowiaty.options[ddlpowiaty.options.selectedIndex].value;
  gminy = GetRegions(3,idpow);
  BindDDL(document.getElementById(ddlGminyId),gminy.value);
}
function OnchangeRB(rb,ismiasta,rowgminaid,rowmiastoid)
{
    if(ismiasta)
    {
        toggleLayer(rowmiastoid,false);
        toggleLayer(rowgminaid,true);
    }
    else
    {
        toggleLayer(rowmiastoid,true);
        toggleLayer(rowgminaid,false);
    }
  
}
function toggleLayer( whichLayer,hide )
{
  var elem, vis;
  if( document.getElementById ) // this is the way the standards work
    elem = document.getElementById( whichLayer );
  else if( document.all ) // this is the way old msie versions work
      elem = document.all[whichLayer];
  else if( document.layers ) // this is the way nn4 works
    elem = document.layers[whichLayer];
  vis = elem.style;
  // if the style.display value is blank we try to figure it out here
  if(vis.display==''&&elem.offsetWidth!=undefined&&elem.offsetHeight!=undefined)
    vis.display = (elem.offsetWidth!=0&&elem.offsetHeight!=0)?'block':'none';
  vis.display = (hide)?'none':'block';
}
function BindDDL(ddl,regions)
{
    ddl.options.length=0;
    ddl.options[0] = new Option('Wszystkie',0);
    for(i=1;i<regions.length+1;i++)
	{
		ddl.options[i] = new Option(regions[i-1].Name,regions[i-1].Id);
	}
}