
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 switchAll(clickSearchId) {
  for (var i=0;i<Form2.elements.length;i++) {
    var e = Form2.elements[i];
    if ( (e.name != clickSearchId) && (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(clickSearchId) {
  switchAll(clickSearchId);
  for (var i=0;i<Form2.elements.length;i++) {
    var e = Form2.elements[i];
    if ( (e.name == clickSearchId)) {
		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 OpenMortgageCentre(url){
	if (!window.opener.closed) {
		window.opener.location.href = url;
		self.close();
	}
	else {
		self.close();
	}
}


function overArea(){
}
function outArea(){
}

function showSiteMap(showvalue)
{
	if (document.getElementById)
	{
		if (showvalue == "true")
		{
			if ( document.getElementById("sitemap") != null)
				{	document.getElementById("sitemap").style.display = ""; }

			if ( document.getElementById("map_menu") != null)
				{	document.getElementById("map_menu").style.display = "none"; }
		}
		else
		{
			if ( document.getElementById("sitemap") != null)
				{	document.getElementById("sitemap").style.display = "none"; }

			if ( document.getElementById("map_menu") != null)
				{	document.getElementById("map_menu").style.display = ""; }
			
		}
	}
}

function redirectTo(page) {
    window.location.href = page;
}

////<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 CheckAdsExist(selector) {

    var addisplay = false;
    var object = $(selector);
    object.find(".bannerads").each(function() {

        var obj = $(this);

        if (obj.find("object").length > 0 || obj.find("embed").length > 0 ||
            obj.find("iframe").length > 0) {
            obj.addClass("show_advert");
            addisplay = true;
        }
        else {
            var imageList = obj.find("img");

            if (imageList.length > 0) {
                var img = imageList.get(0);
                if (img != null) {

                    if (img.src == "http://iad.anm.co.uk/house/1x1.gif" ||
                             img.src == "http://iad.anm.co.uk/anmdefaultad.gif" || img.height < 3) {

                        this.style.display = "none";

                    }
                    else {
                        obj.addClass("show_advert");
                        addisplay = true;

                    }

                }
            }

        }
    });

    if (addisplay != false) {
       if (object.hasClass("hideAds")) { object.removeClass("hideAds"); }
        else {
            object.find(".hideAds").removeClass("hideAds");
       }
    }

}

function BannerAdsExist(noOfAds, objId) {
    CheckAdsExist('#groupads');
}