
function MM_findObj(n, d) { //v3.0
  var p,i,x;  if(!d) d=document; if((p=n.indexOf("?"))>0&&parent.frames.length) {
    d=parent.frames[n.substring(p+1)].document; n=n.substring(0,p);}
  if(!(x=d[n])&&d.all) x=d.all[n]; for (i=0;!x&&i<d.forms.length;i++) x=d.forms[i][n];
  for(i=0;!x&&d.layers&&i<d.layers.length;i++) x=MM_findObj(n,d.layers[i].document); return x;
}
function MM_swapImage() { //v3.0
  var i,j=0,x,a=MM_swapImage.arguments; document.MM_sr=new Array; for(i=0;i<(a.length-2);i+=3)
   if ((x=MM_findObj(a[i]))!=null){document.MM_sr[j++]=x; /*alert(x);*/ if(!x.oSrc) x.oSrc=x.src; x.src=a[i+2]; /*alert(i+2);*/}
}
function MM_swapImgRestore() { //v3.0
  var i,x,a=document.MM_sr; for(i=0;a&&i<a.length&&(x=a[i])&&x.oSrc;i++) x.src=x.oSrc;
}
function MM_preloadImages() { //v3.0
 var d=document; if(d.images){ if(!d.MM_p) d.MM_p=new Array();
   var i,j=d.MM_p.length,a=MM_preloadImages.arguments; for(i=0; i<a.length; i++)
   if (a[i].indexOf("#")!=0){ d.MM_p[j]=new Image; d.MM_p[j++].src=a[i];}}
}

window.name = "WinMain"; //used instead of .opener property for popups to open URLs in the main window
function popup(theURL,theWindowName,theWidth,theHeight) {
	window.open(theURL, theWindowName,"width="+theWidth+",height="+theHeight+",scrollbars=no");
	//put 'window.self.focus' in html header of popup page
	//instead of win.focus(); here to avoid an error in Internet Explorer
}

function MM_showHideLayers() { //v3.0

  var i,p,v,obj,args=MM_showHideLayers.arguments;
  for (i=0; i<(args.length-2); i+=3) if ((obj=MM_findObj(args[i]))!=null) { v=args[i+2];
    if (obj.style) { obj=obj.style; v=(v=='show')?'visible':(v='hide')?'hidden':v; }
    obj.visibility=v; }
}

function changeElementCssClass(element_id, css_class) {
	var x;
	if ((x=MM_findObj(element_id))!=null){
		x.className=css_class;
	}
}
function changeElementContent(element_id, content) {
	var x;
	if ((x=MM_findObj(element_id))!=null){
		x.innerHTML=content;
	}
}

function overArea() {

}

function outArea() {

}

////<summary>
////<created>07/02/07 PJB
////hides form objects, including table rows and can modify checked and disabled states
////usage: pass in multiple comma seperated parameters in groups of 4
////<param>'item to change'</param>
////<param>'"show" or "hide", this will show or hide the item'</param>
////<param>true or false to set disabled</param>
////<param>'' or 'checked' to set checked to true</param>
////and repeat as necessary
////</summary>
function modifyForm() {
var i,v,d,o, args=modifyForm.arguments;
for (i=0; i<(args.length); i+=4)
	if ((o=document.getElementById(args[i]))!=null) {v=args[i+1];
				obj = o;
				if (obj.style) { 
					obj=obj.style; 
					v=(v=='show')?'visible':(v='hide')?'hidden':v; 
					d=(v=='visible')?'':(v='hidden')?'none':d; 
				}
				obj.display = d; obj.visibility=v; obj.disabled=args[i+2]; o.checked=args[i+3]; 
	}
}




function switchAll(ClikSearchId) {
  for (var i=0;i<Form2.elements.length;i++) {
    var e = Form2.elements[i];
    if ( (e.name != ClikSearchId) && (e.type=='checkbox')) {
		Form2.elements[i].checked = false;
    }
  }
}

function checkAllZones() {
  for (var i=0;i<document.forms[0].elements.length;i++) {
    var e = document.forms[0].elements[i];
    if ((e.type=='checkbox')&&(e.name.indexOf('zone_') > 0)) {
		document.forms[0].elements[i].checked = true;
    }
  }
}
function checkAllLines() {
  for (var i=0;i<document.forms[0].elements.length;i++) {
    var e = document.forms[0].elements[i];
    if ((e.type=='checkbox')&&(e.name.indexOf('tube') > 0)) {
		document.forms[0].elements[i].checked = true;
    }
  }
}
function flagForDelete(ClikSearchId) {
  switchAll(ClikSearchId);
  for (var i=0;i<Form2.elements.length;i++) {
    var e = Form2.elements[i];
    if ( (e.name == ClikSearchId)) {
		Form2.elements[i].checked = true;
    }
  }
}

function OpenPopupWindow(winurl, winname, winfeatures) {
	newwin = window.open(winurl,winname,winfeatures);
}

/* image swapping code */
function imagedata(url,title,height,width)
{this.url=url;					// url of image
 this.title=title;				// image title (alt text)
 this.height=height;			// image height
 this.width=width;				// image width
};

var currentimage=0;				// current displayed image
var imageresize=false;			// if the main image will resize (PhotoAlbum sets in ASPX code)

var imagearray=new Array();
/* imagedata object should be added to this array. see PhotoAlbum as an example */

// display image n (0-based) using image control ctl and optional label (title)
function DisplayImage(n)
{var ctl=document.getElementById('imgMainPhoto');
 var labelctl=document.getElementById('labelMainPhoto');
 if (ctl!=null)
 
     		
   // is image within imagedata range
   if (n>=0 && n<imagearray.length)
     {ctl.src=imagearray[n].url;
      ctl.title=imagearray[n].title;
      // optionally resize
      if (imageresize)
        {ctl.width=imagearray[n].width;
	     ctl.height=imagearray[n].height;
        }
      // optional label control  
      if (labelctl!=null)
        labelctl.innerHTML=imagearray[n].title;
	  currentimage=n;    
     };
 UpdateNavigation();
};

function UpdateNavigation()
{var pctl=document.getElementById('PrevDiv');
 var nctl=document.getElementById('NextDiv');
 if (pctl!=null) pctl.style.visibility=(imagearray.length>0)?'visible':'hidden';				
 if (nctl!=null) nctl.style.visibility=(imagearray.length>0)?'visible':'hidden';
}

function DisplayPreviousImage()
{
  if (currentimage==0)
    currentimage = imagearray.length;
	
  DisplayImage(--currentimage);
}

function DisplayNextImage()
{
  if (currentimage==imagearray.length-1)
    currentimage = -1;

   DisplayImage(++currentimage);
}

function PopupPrintWindow(url)
{var pwin=window.open(url,"printwin","height=700,width=790,resizable=yes,scrollbars=yes,menubar=yes,status=yes");
 if (navigator.appName.substring(0,8)=="Netscape")
   pwin.location=url
 pwin.focus();   
}

//left(bottom),right(bottom),left(top),right(bottom),middle(top),middle(bottom)
var images=new Array("images/tube_bottom_left.gif","images/tube_top_right.gif","images/tube_top_left.gif","images/tube_bottom_right.gif","images/tube_top_middle.gif","images/tube_bottom_middle.gif");
var pos = 0
var toplevel = false;
var bottomlevel = true;
var top=new Array("2","4","1");
var bottom=new Array("0","5","3");

function ImagePicker(){
	var tubemap = MM_findObj('tubemap');
	if(pos<0){pos = 0}else if(pos>2){pos = 2}
	if(bottomlevel ==true){
		tubemap.src = images[bottom[pos]]
	}else{
		tubemap.src = images[top[pos]]
	}	
}

function multipleChecked() {
	var x = 0
	var Form2=document.getElementById("Form2")
	//always reset the exec ind
	for (var i=0;i<Form2.elements.length;i++) {
	var e = Form2.elements[i];
		if ((e.name=='SavedResultsListViewControl:hidExec')) {
			e.value="0";
		}
	}
	//get a count of number of searches selected
	for (var i=0;i<Form2.elements.length;i++) {
		var e = Form2.elements[i];
		if ((e.type=='checkbox')&&(e.checked == true)) {
			x++;
		}
	}
	//take action
	if (x > 1){
		alert('You can only run one search at a time');
		x=0
		for (var i=0;i<Form2.elements.length;i++) {
		var e = Form2.elements[i];
			if ((e.name=='SavedResultsListViewControl:hidExec')) {
				e.value="1";
			}
		}
	}
}

function multipleEmailChecked() {
	var x = 0
	var Form1=document.getElementById("Form1")
	//always reset the exec ind
	for (var i=0;i<Form1.elements.length;i++) {
	var e = Form1.elements[i];
		if ((e.name=='hidExec')) {
			e.value="0";
		}
	}
	//get a count of number of props selected
	for (var i=0;i<Form1.elements.length;i++) {
		var e = Form1.elements[i];
		if ((e.type=='checkbox')&&(e.checked == true)) {
			x++;
		}
	}
	//take action
	if (x <=0){
		alert('Please select at least one property to email to a friend');
		x=0
		for (var i=0;i<Form1.elements.length;i++) {
		var e = Form1.elements[i];
			if ((e.name=='hidExec')) {
				e.value="1";
			}
		}
		return false;
	}
	if (x > 20){
		alert('You can only email twenty properties at a time');
		x=0
		for (var i=0;i<Form1.elements.length;i++) {
		var e = Form1.elements[i];
			if ((e.name=='hidExec')) {
				e.value="1";
			}
		}
		return false;
	}
}

function tubeChecked(obj) {

	var x = 0
	if (obj.checked == true) {
		var Form1=document.getElementById("Form1")
	
		//get a count of number of searches selected
		for (var i=0;i<Form1.elements.length;i++) {
			var e = Form1.elements[i];
			if ((e.type=='checkbox')&&(e.checked == true)) {
				x++;
			}
		}
	
		//take action
		if (x > 6){
			alert('A maximum of six tube stations may be included in one search');
			obj.checked = false;
			return;
		}
	}
}

function agentsChecked() {
	var x = 0
	var Form1=document.getElementById("estateagent_select_form")
	//get a count of number of searches selected
	for (var i=0;i<Form1.elements.length;i++) {
		var e = Form1.elements[i];
		if ((e.type=='checkbox')&&(e.checked == true)) {
			x++;
		}
	}
	//take action
	if (x <=0){
		alert('Please select at least one agent to contact');
	}
	else if (x > 50 ) {
		alert('You cannot select more than 50 agents to contact at any one time');
	}
}

function multipleAgentsChecked() {
	var x = 0
	var Form1=document.getElementById("Form1")
	//always reset the exec ind
	for (var i=0;i<Form1.elements.length;i++) {
	var e = Form1.elements[i];
		if ((e.name=='hidExec')) {
			e.value="0";
		}
	}
	//get a count of number of props selected
	for (var i=0;i<Form1.elements.length;i++) {
		var e = Form1.elements[i];
		if ((e.type=='checkbox')&&(e.checked == true)) {
			x++;
		}
	}
	//take action
	if (x <=0){
		alert('Please select at least one property from your shortlist to contact the agent');
		x=0
		for (var i=0;i<Form1.elements.length;i++) {
		var e = Form1.elements[i];
			if ((e.name=='hidExec')) {
				e.value="1";
			}
		}
		return false;
	}	
	if (x > 20){
		alert('You can only email twenty agents at a time');
		x=0
		for (var i=0;i<Form1.elements.length;i++) {
		var e = Form1.elements[i];
			if ((e.name=='hidExec')) {
				e.value="1";
			}
		}
		return false;
	}
}

function showPasswordcontrol(nr)
{
	if (document.layers)
	{
		current = (document.layers[nr].display == 'none') ? 'block' : 'none';
		document.layers[nr].display = current;
	}
	else if (document.all)
	{
		if (typeof(document.all[nr])!= "undefined"){
			current = (document.all[nr].style.display == 'none') ? 'block' : 'none';
			document.all[nr].style.display = current;
		}
	}
	else if (document.getElementById)
	{
		vista = (document.getElementById(nr).style.display == 'none') ? 'block' : 'none';
		document.getElementById(nr).style.display = vista;
	}
}


function hidePasswordcontrol(nr)
{
	if (document.layers)
	{
		current = (document.layers[nr].display == 'none') ? 'block' : 'none';
		document.layers[nr].display = current;
	}
	else if (document.all)
	{
		if (typeof(document.all[nr])!= "undefined"){
			current = (document.all[nr].style.display == 'none') ? 'block' : 'none';
			document.all[nr].style.display = current;
		}
	}
	else if (document.getElementById)
	{
		vista = (document.getElementById(nr).style.display == 'none') ? 'block' : 'none';
		document.getElementById(nr).style.display = vista;
	}
}

function showhideValidation() 
{
	var Form1=document.getElementById("Form1")
	if (document.getElementById("chkMailingList").checked)
		{
			document.getElementById("address_label").innerText = "Address 1*";
			document.getElementById("county_label").innerText = "County*";
			document.getElementById("postcode_label").innerText = "Postcode*";
		}
	else
		{
			document.getElementById("address_label").innerText = "Address 1";
			document.getElementById("county_label").innerText = "County";
			document.getElementById("postcode_label").innerHTML = "Postcode<br>(* for valuation request)";
		}
}

function agentAdsExist()
{
	var noads = 0;
	//loop through the three ads and show them if an ad is available
	for (i=1; i<4; i++)
	{
		//if an image is served
		if (document.getElementById("featured_agent_pos"+i) != null) {
			if (document.getElementById("featured_agent_pos"+i).getElementsByTagName("img")[0] != null)
			{
				//if the id is noad then hide the containing element
				var img = document.getElementById("featured_agent_pos"+i).getElementsByTagName("img")[0];
				if (img.href == "http://iad.anm.co.uk/house/1x1.gif" || img.href == "http://iad.anm.co.uk/anmdefaultad.gif")
				{
					document.getElementById("featured_agent_pos"+i).style.display = "none";
					noads ++;
				}
			}
		}
	}
	// this is just a precaution to hide the controls if all three ads were to return blank
	if (noads == 3)
	{
		if (document.getElementById("featured_agents_column") != null)
		{
			document.getElementById("featured_agents_column").style.display = "none";
		}
		
		if (document.getElementById("featured_agents") != null)
			{
				document.getElementById("featured_agents").style.display = "none";
			}
		
	}
}

function UserOfferAdsExist()
{
	var noads = 0;

	//loop through the three ads and show them if an ad is available
	for (i=1; i<4; i++)
	{
		//if an image is served

		if (document.getElementById("user_offer_pos"+i) != null) {
		
			if (document.getElementById("user_offer_pos"+i).getElementsByTagName("iframe")[0] != null)
			{

				var iframe = document.getElementById("user_offer_pos"+i).getElementsByTagName("iframe")[0]

				if (iframe.contentWindow.document.getElementsByTagName("img")[0] != null)
				{
					//if the id is noad then hide the containing element
					var img = iframe.contentWindow.document.getElementsByTagName("img")[0];
					//Height is a hack for Firefox as the href property is undefined.
					if (img.href == "http://iad.anm.co.uk/house/1x1.gif" || img.href == "http://iad.anm.co.uk/anmdefaultad.gif" || img.height < 90)
					{
						document.getElementById("user_offer_pos"+i).style.display = "none";
						noads ++;
					}
				}

			}
		}

	}

	// this is just a precaution to hide the controls if all three ads were to return blank
	if (noads == 3)
	{
		
		if (document.getElementById("user_offer") != null)
			{
				document.getElementById("user_offer").style.display = "none";
			}
		
	}
	else
	{
	document.getElementById("user_offer").style.display = "block";
	}
			
}


function OpenMortgageCentre(url){
	if (!window.opener.closed) {
		window.opener.location.href = url;
		self.close();
	}
	else {
		self.close();
	}
}

function BannerAdsExist(noOfAds,controlName)
{
	var noads = 0;
	var addisplay = false;
	//loop through the ads and show them if an ad is available
	for (i=1; i<noOfAds+1; i++)
	{
		//if an image is served
		if (document.getElementById(controlName+i) != null) {

			if (document.getElementById(controlName+i).getElementsByTagName("iframe")[0] != null)
			{
				var iframe = document.getElementById(controlName+i).getElementsByTagName("iframe")[0]

				if (iframe.contentWindow.document.getElementsByTagName("img")[0] != null)
				{
					//if the id is noad then hide the containing element
					var img = iframe.contentWindow.document.getElementsByTagName("img")[0];
					//Height is a hack for Firefox as the href property is undefined.
					if (img.href == "http://iad.anm.co.uk/house/1x1.gif" || img.href == "http://iad.anm.co.uk/anmdefaultad.gif" || img.height < 10)
					{
						document.getElementById(controlName+i).style.display = "none";
						noads ++;
					}
					else
					{
						addisplay = true;
						document.getElementById("groupads").style.visibility = "visible";
						document.getElementById("groupads").style.height = "auto";
					}
				}

			}
		}
	
	}
	if(addisplay==false)
	{
		if (document.getElementById("groupads") != null) 
		{
			document.getElementById("groupads").style.display="none";
		}
	}
}