
// Don't allow site to be framed
if (top.frames.length!=0) {
   top.location=self.document.location;
}

var IE_all_cache = new Object();
//function IE_getElementById(id) { if (IE_all_cache[id] == null) { IE_all_cache[id] = document.all[id]; } return IE_all_cache[id]; }
//function NS_getElementById(id) { if (IE_all_cache[id] == null) { IE_all_cache[id] = document.layers[id]; } return IE_all_cache[id]; }
//if (document.all) { document.getElementById = IE_getElementById; is_ie = 1; } else { is_ie = 0; }
//if (document.layers) { document.getElementById = NS_getElementById; }
var agt = navigator.userAgent.toLowerCase();
var is_ie = (agt.indexOf("msie") != -1);
var is_opera = (agt.indexOf("opera") != -1);
var is_mac = (agt.indexOf("mac") != -1);
var is_netscape = (agt.indexOf("netscape") != -1);
var is_gecko = (agt.indexOf("gecko") != -1);
var is_safari = (agt.indexOf("safari") != -1);
var scrolldef = "", loaddef = "", resizedef = "", d = "", t = 60, p = 0;

function ss(w) { window.status=w; return true; }
function cs() { window.status=''; }

function addLoadEvent(func) {
  var old = window.onload;
  if (typeof window.onload != 'function') { window.onload = func; }
  else { window.onload = function() { if (old) { old(); } func(); } }
}

function addUnLoadEvent(func) {
  var old = window.onunload;
  if (typeof window.onunload != 'function') { window.onunload = func; }
  else { window.onunload = function() { if (old) { old(); } func(); } }
}

function addScrollEvent(func) {
  var old = window.onscroll;
  if (typeof window.onscroll != 'function') { window.onscroll = func; }
  else { window.onscroll = function() { if (old) { old(); } func(); } }
}

function addClickEvent(func) {
  var old = window.onclick;
  if (typeof window.onclick != 'function') { window.onclick = func; }
  else { window.onclick = function() { if (old) { old(); } func(); } }
}

function addKeyPressEvent(func) {
  var old = window.onkeypress;
  if (typeof window.onkeypress != 'function') { window.onkeypress = func; }
  else { window.onkeypress = function() { if (old) { old(); } func(); } }
}

function addResizeEvent(func) {
  var old = window.onresize;
  if (typeof window.onresize != 'function') { window.onresize = func; }
  else { window.onresize = function() { if (old) { old(); } func(); } }
}

function show() {
  for (var i=0,j=arguments.length; i<j; ++i) {
		_show(arguments[i] + "_open");
		_hide(arguments[i] + "_closed");
	}
}

function hide() {
  for (var i=0,j=arguments.length; i<j; ++i) {
		_show(arguments[i] + "_closed");
		_hide(arguments[i] + "_open");
	}
}

function toggle() {
  for (var i=0, j = arguments.length; i<j; ++i) {
		var o = document.getElementById(arguments[i]);
		if (o) o.style.display = o.style.display == "block" ? "none" : "block";
	}
}

function _hide() {
  for (var i=0,j=arguments.length; i<j; ++i) {
		var o = document.getElementById(arguments[i]);		
		if (o) o.style.display = "none";
	}
}

function _show() {
  for (var i=0,j=arguments.length; i<j; ++i) {
		var o = document.getElementById(arguments[i]);		
		if (o) o.style.display = "block";
	}
}

function set_check() {
  for (var i=0,j=arguments.length; i<j; ++i) {
		var o = document.getElementById(arguments[i]);
		if (o && o.type == "checkbox") { o.checked = true; }		
	}
}

function get_check() {
	var rv = true, o;
	for (var i=0,j=arguments.length; i<j; ++i) {
		o = document.getElementById(arguments[i]);
		if (o) { rv &= o.checked; }
	}
	return rv;
}

function getOptions() {
  var output = "";
  for (var i=0,part="",l_args=arguments.length; i<l_args; ++i, part = "") {
    var x = document.getElementById(arguments[i]);
		if (x) {
			var x_t = x.type;
			if (x_t == "select-one" || x_t == "select-multiple") {
				var x_o = x.options;
				for (var j = 0, l_x_o = x_o.length; j < l_x_o; ++j) {
					var o = x_o[j];
					if (o.selected && o.value != "__NO_VALUE__") { if (part != "") part += ','; part += o.value; }
				}
			} else if (x_t == "textarea" || x_t == "text") {
				if (part != "") part += ','; part += x.value;
			} else if (x_t == "radio") {
				if (x.checked) { if (part != "") part += ','; part += x.value; }
			}
		}
		if (part != "") output += part;
		if (i < l_args-1) output += '|';
  }
	return output
}

var popupwindow = '';
var popup_width = 570;
var popup_height = 480;

function popitup(url) {
try{
    if(url.match("Property")=="Property")
    {
        popup_width = 580;
        popup_height = 800;
    }
    else //requirement
    {
        popup_width = 580;
        popup_height = 480;
    }
	if (popupwindow.location && !popupwindow.closed) { popupwindow.location.href = url; popupwindow.centre(); if (window.focus) popupwindow.focus(); } 
	else { popupwindow=window.open(url,'popupwindow','width=' + popup_width + ',height=' + popup_height + ',resizable=1,scrollbars=1') ; }
	if (!popupwindow || popupwindow.closed) alert('Unable to open popup - please disable popup blocking and try again');
	}
	catch (e)
	{}
	return false; 
}
 
function popitup1(url, name, scrollResize, size) {
	var features = "" + size;
	features += scrollResize ? ",scrollbars=yes,resizeable=yes" : "";
	
	var popup = window.open(url, name, features);
	if (!popup || popup.closed) {
		alert('Unable to open popup - please disable popup blocking and try again');
		return false; 
	}
	
	var strpostcode = popup.opener.document.getElementById('postcode').value;
	var arrpostcode = strpostcode.split(' ');
	var strtowncity = popup.opener.document.getElementById('towncity').value;
	
	if (arrpostcode[0].length > 0) {
		popup.document.getElementById('search_text').value = arrpostcode[0];		
	}
	else if (strtowncity.length > 0) {
		popup.document.getElementById('search_text').value = strtowncity;
	}
	popup.focus();
	return true;
}

 

function fullScreen() {
  window.moveTo(0,0);
  window.resizeTo(screen.availWidth,screen.availHeight);
};


function centre() {
  if (parseInt(navigator.appVersion) >= 4) {
	  window.moveTo((screen.availWidth/2)-(popup_width/2-5),(screen.availHeight/2)-(popup_height/2-5));
	}
};

   
            var fav=0;            
            var enableCache = false;
            var jsCache = new Array();
            var AjaxObjects = new Array();        
            


      function ShowContent(divId,ajaxIndex,url)
        {
	        //alert(AjaxObjects[ajaxIndex].response);
	        /*document.getElementById(divId).innerHTML = AjaxObjects[ajaxIndex].response;
	        
	        if(enableCache){
		        jsCache[url] = 	AjaxObjects[ajaxIndex].response;
	        }
	        AjaxObjects[ajaxIndex] = false;
	        */
        }
        
        function Ajax(divId,url)
        {
	        /*if(enableCache && jsCache[url]){
		        document.getElementById(divId).innerHTML = jsCache[url];
		        return;
	        }	
	        */
	        var ajaxIndex = AjaxObjects.length;
	        //document.getElementById(divId).innerHTML = '<img src=images/movewait.gif width=16 height=16 hspace=10 vspace=10 />';
	        AjaxObjects[ajaxIndex] = new sack();
	        AjaxObjects[ajaxIndex].requestFile = url;
	        //AjaxObjects[ajaxIndex].onCompletion = function(){ShowContent(divId,ajaxIndex,url); };
	        //AjaxObjects[ajaxIndex].onLoading = function(){alert('onLoading');};
	        //AjaxObjects[ajaxIndex].onInteractive=function(){alert('onInteractive');};
	        AjaxObjects[ajaxIndex].runAJAX();}
           
        function AjaxSave(dv,note)//,bid
        {
            //alert(dv);
	        var ajaxIndex = AjaxObjects.length;
	        //document.getElementById(divId).innerHTML = '<img src=images/movewait.gif width=16 height=16 hspace=10 vspace=10 />';
	        AjaxObjects[ajaxIndex] = new sack();
	        AjaxObjects[ajaxIndex].requestFile = "async/AsyncHandler.aspx?t=an_save_note&note="+note;//+"&bid="+bid
	        AjaxObjects[ajaxIndex].onCompletion = function(){ShowMsg(dv); };
	        //AjaxObjects[ajaxIndex].onLoading = function(){alert('onLoading');};
	        //AjaxObjects[ajaxIndex].onInteractive=function(){alert('onInteractive');};
	        AjaxObjects[ajaxIndex].runAJAX();
        }               
    
function ShowMsg(div)
{    
    //getElementById(dv).style.display='block';
}
function sack(id) {//file,
	this.xmlhttp = null;
    this.xmlhttp2 = null;
    
	this.resetData = function() {
		//alert('this.resetData');
		this.method = "POST";
  		this.queryStringSeparator = "?";
		this.argumentSeparator = "&";
		this.URLString = "";
		this.encodeURIString = true;
  		this.execute = false;
  		this.element = null;
		this.elementObj = null;
		this.requestFile = null;//file;
		this.vars = new Object();
		this.responseStatus = new Array(2);
  	};

	this.resetFunctions = function() {
  		this.onLoading = function() { };
  		this.onLoaded = function() { };
  		this.onInteractive = function() { };
  		this.onCompletion = function() { };
  		this.onError = function() { };
		this.onFail = function() { };
	};

	this.reset = function() {
		this.resetFunctions();
		this.resetData();
	};

	this.createAJAX = function() {
		try {
			this.xmlhttp = new ActiveXObject("Msxml2.XMLHTTP");
		} catch (e1) {
			try {
				this.xmlhttp = new ActiveXObject("Microsoft.XMLHTTP");
			} catch (e2) {
				this.xmlhttp = null;
			}
		}

		if (! this.xmlhttp) {
			if (typeof XMLHttpRequest != "undefined") {
				this.xmlhttp = new XMLHttpRequest();
			} else {
				this.failed = true;
			}
		}
	};

	this.setVar = function(name, value){
		this.vars[name] = Array(value, false);
	};

	this.encVar = function(name, value, returnvars) {
		if (true == returnvars) {
			return Array(encodeURIComponent(name), encodeURIComponent(value));
		} else {
			this.vars[encodeURIComponent(name)] = Array(encodeURIComponent(value), true);
		}
	}

	this.processURLString = function(string, encode) {
		encoded = encodeURIComponent(this.argumentSeparator);
		regexp = new RegExp(this.argumentSeparator + "|" + encoded);
		varArray = string.split(regexp);
		for (i = 0; i < varArray.length; i++){
			urlVars = varArray[i].split("=");
			if (true == encode){
				this.encVar(urlVars[0], urlVars[1]);
			} else {
				this.setVar(urlVars[0], urlVars[1]);
			}
		}
	}

	this.createURLString = function(urlstring) {
	    //alert('urlstring='+this.URLString);
		if (this.encodeURIString && this.URLString.length) {
			this.processURLString(this.URLString, true);
		}

		if (urlstring) {
			if (this.URLString.length) {
				this.URLString += this.argumentSeparator + urlstring;
			} else {
				this.URLString = urlstring;
			}
		}

		// prevents caching of URLString
		this.setVar("rf", new Date().getTime());//rndval

		urlstringtemp = new Array();
		for (key in this.vars) {
			if (false == this.vars[key][1] && true == this.encodeURIString) {
				encoded = this.encVar(key, this.vars[key][0], true);
				delete this.vars[key];
				this.vars[encoded[0]] = Array(encoded[1], true);
				key = encoded[0];
			}

			urlstringtemp[urlstringtemp.length] = key + "=" + this.vars[key][0];
			//alert(key + "=" + this.vars[key][0]);
		}
		if (urlstring){
			this.URLString += this.argumentSeparator + urlstringtemp.join(this.argumentSeparator);
		} else {
			this.URLString += urlstringtemp.join(this.argumentSeparator);
		}
		//alert('urlstring='+this.URLString);
	}

	this.runResponse = function() {
		eval(this.response);
	}

	this.runAJAX = function(urlstring) {
		//alert(urlstring);
		if (this.failed) {
			this.onFail();
		} else {
			this.createURLString(urlstring);
			if (this.element) {
			    alert('this.element');
				this.elementObj = document.getElementById(this.element);
			}
			if (this.xmlhttp) {
				var self = this;
				//alert(this.xmlhttp);
				if (this.method == "GET") {
					totalurlstring = this.requestFile + this.queryStringSeparator + this.URLString;
					//alert(totalurlstring );
					this.xmlhttp.open(this.method, totalurlstring, true);
				} else {
					this.xmlhttp.open(this.method, this.requestFile, true);
					try {
						this.xmlhttp.setRequestHeader("Content-Type", "application/x-www-form-urlencoded")
					} catch (e) { }
				}

				this.xmlhttp.onreadystatechange = function() {
					//alert(self.xmlhttp.readyState);
					switch (self.xmlhttp.readyState) {
						case 1:
							self.onLoading();
							break;
						case 2:
							self.onLoaded();
							break;
						case 3:
							self.onInteractive();
							break;
						case 4:
							self.response = self.xmlhttp.responseText;
							self.responseXML = self.xmlhttp.responseXML;
							self.responseStatus[0] = self.xmlhttp.status;
							self.responseStatus[1] = self.xmlhttp.statusText;

							if (self.execute) {
								self.runResponse();
							}

							if (self.elementObj) {
								elemNodeName = self.elementObj.nodeName;
								elemNodeName.toLowerCase();
								if (elemNodeName == "input"
								|| elemNodeName == "select"
								|| elemNodeName == "option"
								|| elemNodeName == "textarea") {
									self.elementObj.value = self.response;
								} else {
									self.elementObj.innerHTML = self.response;
								}
							}
							if (self.responseStatus[0] == "200") {
							    //alert(self.xmlhttp.responseText);
								self.onCompletion();
							} else {
								self.onError();
							}

							self.URLString = "";
							break;
					}
				};
               //alert(this.URLString);
				this.xmlhttp.send(555);//this.URLString
			}
		}
	};

	this.reset();
	this.createAJAX();
}

function select_filter()
{
    mywindow=window.open('Settings.aspx',"mywindow","menubar=0,scrollbars=1,resizable=1,width=815,height=825");        
    mywindow.moveTo(45,0);  
}

function o(o){o.className=o.className+"Over";} 
function u(o){o.className=o.className.replace(/Over/,'');} 




    function focused(object)
    {       
            object.style.background="yellow";  
            //alert(1);        
    }
    function focused(object,selected)
    {       
        //selected_FID.className
        //alert(object.className);
        if(object.className!="NEW")
        {
            object.style.background="yellow";  
            //document.getElementById("selected_FID").value=selected;
        }
        
    }    
    function blured(object, available, numeric, floorname)
    {       
        var i=1;
       // alert(0);
       object.style.background="#FFFFFF";
        object.value=object.value.replace(/ /g,"");
        object.value=object.value.replace(/,/g,".");
        if(floorname)
        {
            //alert(object.value.substring(0,1));      
            for(i=1;i<object.value.length;i++)
            {
                if(isNaN(object.value.substring(0,i)))
                    break;
            
            }      
            /*while(!isNaN(object.value.substring(0,i)))
            {
                
                i++;
            }   */
            //alert(i);
            if(i==1 && object.value.length>1)
            {
                object.style.background="#FF8081";
                object.value=1+" "+object.value;
                alert("the first letter (=floor number) of the floor name must be numeric!");
                return;
            }
            else
            {
                
                if(object.value.length>1)
                object.value=object.value.substring(0,i-1)+" "+object.value.substring(i-1,object.value.length);
            }
        }
        
        if(numeric)
        {
                if(isNaN(object.value))
                {
                  
                  
                  object.style.background="#FF8081"; 
                  alert("The red box value must be numeric, please correct!");  
                  object.value=0;
                  return;
                }            
        
        }
        if(available)
        {             
             //alert(object.value.length);
             if(object.value.length==0)
             {
                setColor(object);
                return;
             }
             
             if(object.value.length<4 || object.value.length>6)
             {
                
                object.style.background="#FF8081"; 
                alert('Check entered Available Date Format, it should be: mm.yy');
                return;
             }
            
            var month, arValidMonth=Array("jan","feb","mar","apr","may","jun","jul","aug","sep","oct","nov","dec");
            //alert(arValidMonth);
            try
            {
                //var intMM=parseInt(object.value);
                
                var year=object.value.substr(3,2);
                if(object.value.length==4)
                    year=object.value.substr(2,2);
                
                if(isNaN(object.value.substr(0,2)))
                {
                    //year=alert(object.value.substr(0,3).toLowerCase());
                    month=object.value.substr(0,3).toLowerCase();
                    for(i=0;i<arValidMonth.length;i++)//arValidMonth=;
                    {
                        if(month==arValidMonth[i])
                            break;
                        
                    }
                    if(i==12)
                    {
                        month=object.value.substr(0,2).toLowerCase();
                        for(i=0;i<arValidMonth.length;i++)//arValidMonth=;
                        {
                            if(month==arValidMonth[i].substr(0,2))
                            {
                                object.value=arValidMonth[i].substr(0,1).toUpperCase()+arValidMonth[i].substr(1,2)+"."+year;
                                break;
                            }    
                        }                        
                            //alert(i);
                            if(i==12)
                            {
                                object.style.background="#FF8081"; 
                                alert('Check enetered Available Date Format, it should be: mm.yy');                                                    
                                return;
                            }                                
                    }
                    
                }
                else
                {
                    switch(object.value.substr(0,2))
                    {
                        case "1":
                        case "01":
                            object.value="Jan."+year;
                            break;
                        case "2":
                        case "02":
                            object.value="Feb."+year;
                            break;                        
                        case "3":
                        case "03":
                            object.value="Mar."+year;
                            break;                        
                        case "4":
                        case "04":
                            object.value="Apr."+year;
                            break;                 
                        case "5":
                        case "05":
                            object.value="May."+year;
                            break;  
                        case "6":
                        case "06":
                            object.value="Jun."+year;
                            break;  
                        case "7":
                        case "07":
                            object.value="Jul."+year;
                            break;  
                        case "8":
                        case "08":
                            object.value="Aug."+year;
                            break;  
                        case "9":
                        case "09":
                            object.value="Sep."+year;
                            break;  
                        case "10":
                            object.value="Oct."+year;
                            break;  
                        case "11":
                            object.value="Nov."+year;
                            break;  
                        case "12":
                            object.value="Dec."+year;
                            break;        
                        default:
                            object.style.background="#FF8081";
                            alert('Check entered Available Date Format, it should be: mm.yy');                        
                            break;                                                                                                                                                                                          
                    }
                }                
                //object.value+=year;
            }            
            catch(e)
            {
                //alert(0);
            }
        }


        //setColor(object);//object.className,object.style.background);
    }    
    
    
    function setColor(obj)
    {
        switch(obj.className)
        {        
        case "COMPLETED":
            obj.style.background="#FFE6CC";        
            break;
        case "AVAILABLE":
            obj.style.background="#d6eac2";        
            break;
        case "UNDER_OFFER":
            obj.style.background="#FFFFCC";        
            break;
        case "WITHDRAWN":
            obj.style.background="#FFE6CC";        
            break;                                
        
        
        }            
    
    }


function over_css(obj)
{
    obj.className="btOver"
}
function out_css(obj)
{
    obj.className="bt"
    
}
 

//-->


function getSERVER_URL()
{
    return "http://www.each.co.uk/"
   // return "http://localhost/"; 
}
/* -- STREET PROFILE  -- START ---*/
 
 var _NID=0;
function getStreetProfile(_st,_pc,_type) { 

        if(_type == 0) return;
        // note : if   make any change , please do same in Alert - Listing.aspx as well
        _pc = _pc.replace(' ',"05550");  //convert Empty space to "05550" string
        _st = _st.replace(',',"04440"); 
        _st = _st.replace('/',"03330");  
        _st = _st.replace('&',"02220"); 
        _st = _st.replace('-',"010"); 
        _st = _st.replace('(',"020"); 
        _st = _st.replace(')',"030"); 
        _st = _st.replace(':',"040"); 
         
        while(_st.indexOf(' ')>0)
        {
            _st = _st.replace(' ',"05550");
        }
        
        if(_st.length <=1 )
            _st = "05550";
        
        try{
         //  alert($('#NIDc').val());
            _NID=$('#NIDc').val();//document.getElementById('hNID');
        }catch(e){}
        //alert(_NID);
        var win;
        
        if(_type ==2)
            win = window.open(getSERVER_URL() + 'abu/' +_pc + '/'+ _st  +'/CentreEstateInfo.aspx?NID='+_NID, 'StProfile','width=900,height=700,scrollbars=1,resizable=1');          
        else
            win = window.open(getSERVER_URL() + 'abu/' +_pc + '/'+ _st  +'/streetinfo.aspx?NID='+_NID, 'StProfile','width=900,height=700,scrollbars=1,resizable=1'); 
         win.focus();
    }
    
    
    function getTownProfile(_town,_pc)
    {
     // note : if   make any change , please do same in Alert - Listing.aspx as well
        _pc = _pc.replace(' ',"05550");  //convert Empty space to "05550" string
        _town = _town.replace(',',"04440"); 
        _town = _town.replace('/',"03330");  
        _town = _town.replace('&',"02220");  
        _town = _town.replace('-',"010"); 
        _town = _town.replace('(',"020"); 
        _town = _town.replace(')',"030"); 
        
    
        while(_town.indexOf(' ')>0)
        {
            _town = _town.replace(' ',"05550");
        }
        
        if(_town.length <=1 )
            _town = "05550";
        
        try{
           //alert($('#NIDc').val());
            _NID=$('#NIDc').val();//document.getElementById('hNID');
          //  alert(_NID);
        }catch(e){}
        //alert(_NID);
        var win;
            win = window.open(getSERVER_URL() + 'abu/' +_pc + '/'+ _town  +'/TownInfo.aspx?NID='+_NID, 'TownProfile','width=600,height=700,scrollbars=1,resizable=1');          
            win.focus();
    }
    
    
    function getFloor(_id,_did)
    {
    var win ;
    if (_id>0)
        {
             win = window.open(getSERVER_URL() + 'abu/' +_id +'/'+_did +'/FloorInfo.aspx', 'FloorInfo','width=682,height=555,left=150,top=200,scrollbars=1,resizable=1'); 
            win.focus();
        }
    }
    
    var gHELP;
    function INSTANThelpOv(){
        //alert(1);
        clearInterval(gHELP);
       var helpText="1) There is a Need HELP BAR just below<br>";
        //helpText+="below and to the right <br>";
        helpText+="2) Have you seen the user guides below <br>";
        helpText+="otherwise, do call 020 7602 5947 <br>";
        helpText+="Anthony, Jeremy, or Jamie will be glad to help<br>";
        //helpText+="";
        document.getElementById('INSTANThelpText').innerHTML=helpText;
        document.getElementById('INSTANThelpText').style.display="block";
    }
    function INSTANThelpOu(){
        gHELP=setTimeout(INSTANThelpOFF,2000);
        
        //document.getElementById('INSTANThelpText').innerHTML="";
        //alert(10);
    }
    function INSTANThelpOFF(){
        document.getElementById('INSTANThelpText').innerHTML="";
        document.getElementById('INSTANThelpText').style.display="none";
    }
    
    function loadPropImage(_id,_found)
    {
    var win ;
    if (_id>0 && _found >0)
        {
             win = window.open(getSERVER_URL() + 'abu/Property/' +_id +'/Image.aspx', 'propImage','width=682,height=555,left=150,top=200,scrollbars=1,resizable=1'); 
            win.focus();
        }
    }
/* -- STREET PROFILE  -- END ---*/
    
function Clicks(pid){

    //alert(pid);
    var url=location.href+'';
    
    url=url.toLowerCase();//alert(url);
    if(url.indexOf('requirement')>0)url='&r=1';else url='';
    
    mywindow=window.open(getSERVER_URL()+'AttachmentClicked.aspx?p='+pid+url,"mywindow","menubar=0,scrollbars=1,resizable=1,width=1000,height=505");        
 //   alert(pid);
    mywindow.moveTo(45,0);  

}

/* ---- Call VOA site -start-- */
function callVOA(_postcode)
{
    var agt = navigator.userAgent.toLowerCase();
        if (agt.indexOf("msie") >=0 )
            window.clipboardData.setData("text",_postcode );
    winVOA = window.open("http://www.2010.voa.gov.uk/rli/en/advanced","winVOAsite");
    winVOA.focus();
}

/*--Call VOA site End- */
