function checkAll(field)
{
for (i = 0; i < field.length; i++)
	field[i].checked = true ;
}

function uncheckAll(field)
{
for (i = 0; i < field.length; i++)
	field[i].checked = false ;
}



// pad area with 0 (example 0001 ot 0203)
function paddedAreaId(ar)
{var tp="000"+ar;
 return tp.substring(tp.length-4,tp.length);
}

// pad agent id with 0 (example 00001 ot 00203)
function paddedAgentId(ag)
{var tp="0000"+ag;
 return tp.substring(tp.length-5,tp.length);
}

/* used by AreaList and AreaListForLondon 
   append an arealist (al=xxxxx), with a list of area ids.
   The area ids are padded with zeros (max of 4 digits), example al=000100020003

   If there are no checked checkboxes, then pass regionid (padded) and allareas=1
*/

function AreaListRedirect(url,regionid,ctlgrpname,listagents)
{// get the collection of checkboxes
  var x=document.getElementsByName(ctlgrpname);
  if (x!=null)
    {var al="";
     for (var n=0;n<x.length;n++)
      if (x[n].checked)
         al+=paddedAreaId(x[n].value);
	 /* If there is a area list, append to url and redirect
        If there is no area list (nothing checked), then append allareas 
     */
     if (al.length!=0) 
         url+="&al="+al;   
     else
      	 url+="&regionid="+regionid;  
	
     window.location=url;			// redirect to ur 
    } 
  return false;					// avoids normal submit action
}

/* used by ShortListAgents 
   append a list of agent ids (agl=0xxxxx) to the redirect url.
   The agent ids are padded with zeros (5 places), example agl=000010000200003
*/
function AgentListRedirect(url,ctlgrpname)
{// get the collection of checkboxes
 var x=document.getElementsByName(ctlgrpname);
 if (x!=null)
   {var agl="";
    var selCount = 0
	for (var n=0;n<x.length;n++)
	  if (x[n].checked)
        {
			agl+=paddedAgentId(x[n].value);
			selCount++
		}
	
	// only redirect if there is a agent list and there is not more than 50 agents in it
	if (agl.length!= 0 && selCount <= 50) 
	  {url+="&agl="+agl;
//    alert("url="+url);  
       window.location=url;
      }
   }
 return false;					// avoids normal submit action
}

function validateform() {
var theform;

	if (window.navigator.appName.toLowerCase().indexOf("microsoft") > -1) {
		theform = document.rsform;
	}
	else {
		theform = document.forms["rsform"];
	}

	if (theform.RefineSearchControl_loc.value=='place or postcode') {
		alert('Please enter a placename or postcode');
		theform.RefineSearchControl_loc.focus();
		return false;
	}

	if (theform.RefineSearchControl_loc.value.length==0) {
		alert('Please enter a placename or postcode');
		theform.RefineSearchControl_loc.focus();
		return false;
	}

	return true;
}
function resetresolved() {
var theform;

	if (window.navigator.appName.toLowerCase().indexOf("microsoft") > -1) {
		theform = document.rsform;
	}
	else {
		theform = document.forms["rsform"];
	}

	theform.RefineSearchControl_res.value='0';
	theform.RefineSearchControl_regionid.value='0';
	theform.RefineSearchControl_countyid.value='0';
	theform.RefineSearchControl_areaid.value='0';
	theform.RefineSearchControl_al.value='';
	theform.RefineSearchControl_tl.value='';
	theform.RefineSearchControl_zl.value='';
	theform.RefineSearchControl_ll.value='';

	return true;
}

function resetabeds() {
var theform;

	if (window.navigator.appName.toLowerCase().indexOf("microsoft") > -1) {
		theform = document.rsform;
	}
	else {
		theform = document.forms["rsform"];
	}

	theform.RefineSearchControl_abeds.value='0';

	return true;
}
