var c_objHistory = new clsHistory();
var c_objHint = new clsObjectCollection();
var xhttpHint;

var Class = {
  create: function() {
    return function() {
      this.initialize.apply(this, arguments);
    }
  }
}

/********************************************************************************/
/*            Houses Details Of The client Browser                              */
browser = Class.create();
browser.prototype = {
	initialize: function() 
	{
	    this.agt = navigator.userAgent.toLowerCase();
	    this.fullname = navigator.appName + " " + navigator.appVersion;
	    this.name = navigator.appName;
	    this.version = navigator.appVersion;
	    
	    this.is_IE = ((this.agt.indexOf("msie") != -1) && (this.agt.indexOf("opera") == -1));
	    this.is_IE6Up = (this.is_IE ? this.is_IE6OrGreater() : false);
	    this.is_IE6Down = (this.is_IE ? this.is_IE6OrLess() : false);
	    this.major = parseInt(navigator.appVersion);
	    this.minor = parseFloat(navigator.appVersion);
	    this.is_Nav  = ((this.agt.indexOf('mozilla') != -1) && (this.agt.indexOf('spoofer') == -1)
                        && (this.agt.indexOf('compatible') == -1) && (this.agt.indexOf('opera') == -1)
                        && (this.agt.indexOf('webtv') == -1) && (this.agt.indexOf('hotjava') == -1));
                        
	    this.is_Nav6Up = (this.is_Nav && (this.major >= 5));
	    this.is_Opera = (this.agt.indexOf("opera") != -1);
	    this.is_Opera7Up = (this.is_Opera ? (this.is_Opera7OrGreater()) : (false));
	    this.isSupported = (this.is_Opera5Up || this.is_Nav6Up || this.is_IE6Up) ? true: false;  
	}
	,
	is_IE6OrLess : function(){
       return((parseInt(this.agt.substr(this.agt.indexOf("msie") + 4,3)) <= 6) ? true : false);
	}
	,
	is_IE6OrGreater : function(){
       return((parseInt(this.agt.substr(this.agt.indexOf("msie") + 4,3)) >= 6) ? true : false);
	}
	,
	is_Opera7OrGreater : function(){
	    return((parseInt(this.agt.substr(this.agt.indexOf("opera") + 6,2)) >= 5) ? true : false);
	}
}

var ClientB = new browser();
//fix any png images for ie 6 or less
function fixPNG(){

    if(ClientB.is_IE6Down){
        for(var i = 0; i < document.images.length ; i++){
            var img = document.images[i];
            var imgName = img.src.toUpperCase();            
            if (imgName.substring(imgName.length-3, imgName.length) == "PNG"){
                var imgID = (img.id) ? "id='" + img.id + "' " : "";  
                var imgClass = (img.className) ? "class='" + img.className + "' " : "";
                var imgTitle = (img.title) ? "title='" + img.title + "' " : "title='" + img.alt + "' "; 
                var imgStyle = "display:inline-block;" + img.style.cssText;
                var strNewHTML = "<span " + imgID + imgClass + imgTitle
                    + " style=\"" + "width:" + img.width + "px; height:" + img.height + "px;" + imgStyle + ";"
                    + "filter:progid:DXImageTransform.Microsoft.AlphaImageLoader"
                    + "(src=\'" + img.src + "\', sizingMethod='scale');\"></span>" 
                    img.outerHTML = strNewHTML;
                    i--;
            }   
        }

    }
}

function WebTrends(strPath){
	if (ClientB.is_IE6Up)  {
		xhttpWebTrends = new ActiveXObject("Msxml2.XMLHTTP");
	}
	else {
		xhttpWebTrends = new XMLHttpRequest(); 
	}	
	xhttpWebTrends.open("POST",strPath, true);
	xhttpWebTrends.send("");		
}

function ImgHandleError(objImage) {
	objImage.src = "images/TH2_comingsoon.gif";
}
function ImgHandleErrorLarge(objImage) {
	objImage.src = "images/comingsoon.gif";
}
function ImgHandleErrorSmall(objImage) {
	objImage.src = "images/TH1_comingsoon.gif";
}
function GotoShortList(){
	window.location="shortlist.aspx";
}	

function GetShortListCount(){
	var strShortlist = GetCookie("PropertyShortlist");
	if (!strShortlist){
		return 0;
	}
	if (strShortlist.length==0){
		return 0;
	}
	var strArray = strShortlist.split(",");
	
	if (!strArray){
		return 0;
	}
	return strArray.length;
}

function GetAjaxData(strType,strPath){
	if(strType=="P" || strType=="S" || strType=="W"){
		if (ClientB.is_IE6Up)  {
			xhttpProperty = new ActiveXObject("Msxml2.XMLHTTP");
		}
		else {
			xhttpProperty = new XMLHttpRequest(); 
		}	
		xhttpProperty.onreadystatechange = OnReadyStateProperty;
		xhttpProperty.open("GET",strPath, true);
		xhttpProperty.send("");		
	}
	if(strType=="H"){
		if (ClientB.is_IE6Up)  {
			xhttpHint = new ActiveXObject("Msxml2.XMLHTTP");
		}
		else {
			xhttpHint = new XMLHttpRequest(); 
		}	
		xhttpHint.onreadystatechange = OnReadyStateHint;
		xhttpHint.open("GET",strPath, true);
		xhttpHint.send("");		
	}
}

function GetHint(strHint){
	GetAjaxData("H","AjaxData.aspx?PageType=hint&HintValue=" + strHint);
}
function CreateHint(strData){
	c_objHint = new clsObjectCollection()
	
	if(strData && strData!=""){
		var strFilter = strData.split("[|]")
		
		for(x=0;x<strFilter.length;x++){
			if(strFilter[x] && strFilter[x]!=""){
				c_objHint.Add( new clsHint(strFilter[x]))
			}
		}			
	}
}

function clsSchool(strData){
	var strA = strData.split("|")
	
	if(strA.length==7){
		this.Age = strA[0]
		this.Gender = strA[1]		
		this.Name = strA[2]
		this.Postcode = strA[3]
		this.SchoolID = parseInt(strA[4])
		this.SchoolTypeID = parseInt(strA[5])
		this.SchoolTypeName = strA[6]		
	}	
	else{
		this.Age = ""
		this.Gender = ""
		this.Name = ""
		this.Postcode = ""
		this.SchoolID = 0
		this.SchoolTypeID = 0
		this.SchoolTypeName = ""
	}
}

//Hint object
function clsHint(strData){
	var strA = strData.split("|")
	
	if(strA.length==7){
		this.DefaultRadius = parseInt(strA[0])
		this.DisplayItem = strA[1]
		this.ID = parseInt(strA[2])
		this.Name = strA[3]
		this.Parent = strA[4]
		this.X = parseInt(strA[5])
		this.Y = parseInt(strA[6])	
	}	
	else{
		this.DefaultRadius = 0
		this.DisplayItem = ""
		this.ID = 0
		this.Name = ""
		this.Parent = ""
		this.X = 0
		this.Y = 0
	}
}
function clsFilter(strData){
	var strA = strData.split("|")
	
	if(strA.length==4){	
		this.ID = parseInt(strA[0])
		this.ItemCount = strA[1]
		this.Name = strA[2]
		this.Level = parseInt(strA[3])
	}
	else{
		this.ID = 0
		this.ItemCount = ""
		this.Name = ""
		this.Level = 0
	}
}
function clsProperty(strData){
	var strA = strData.split("|")
	if(strA.length==13){
		this.DateFirstAdded = strA[0]
		this.ImagePath = strA[1]
		if(strA[2].toLowerCase()=="true"){
			this.IsNew = true
		}
		else{
			this.IsNew = false
		}
		this.Price = strA[3]
		this.PropertyHash = strA[4]
		this.PropertyID = parseInt(strA[5])
		if(strA[6].toLowerCase()=="true"){
			this.PropertyOfTheWeek = true
		}
		else{
			this.PropertyOfTheWeek = false
		}				
		this.PropertyTypeID = parseInt(strA[7])
		this.PropertyTypeName = strA[8]
		if(strA[9].toLowerCase()=="true"){
			this.Shortlisted = true
		}
		else{
			this.Shortlisted = false
		}
		this.Town = strA[10]		
		this.Bedrooms = parseInt(strA[11])		
		this.EstateAgentID = parseInt(strA[12])
	}
	else{
		this.DateFirstAdded = ""
		this.ImagePath = ""
		this.IsNew = false
		this.Price = ""
		this.PropertyHash = ""
		this.PropertyID = 0
		this.PropertyOfTheWeek = false
		this.PropertyTypeID = 0
		this.PropertyTypeName = ""
		this.Shortlisted = false		
		this.Town = ""	
		this.Bedrooms = 0
		this.EstateAgentID = 0
	}		
}

function clsObjectCollection() {
	var objItems =new Array()
		
	this.Items = objItems
	
	this.Add=function(objItem) {
		if (typeof(objItem)=="object") {
			objItems[objItems.length]=objItem
		}
	}
	
	this.ClearAll=function() {
		objItems =new Array()
	}	
}
function clsHistory(){
	this.DataID = 0
	this.Type = ""
	this.SearchA = ""
	this.SearchB = ""
	this.FilterA = -1
	this.FilterB = -1
	this.SortOrder = 0
	this.Page = 1
	this.Index = 0
	this.Radius = 0
	this.MaxPrice = 0
	this.MinPrice = 0
	this.DetailID = 0
	this.NextDataID = 0
	this.Status = 0
	this.LocationID = 0
	this.MaxPriceValue = 0
	this.MinPriceValue = 0

	this.NextData = function(){
		this.NextDataID += 1;
		this.DataID = this.NextDataID ;
	}
	
	this.FromString=function(strData){
		if(strData && strData!=""){
			var strA = strData.split("|")
			if(strA.length==15){	
				this.DataID = parseInt(strA[0])
				this.Type = strA[1]
				this.SearchA = strA[2]
				this.SearchB = strA[3]		
				this.FilterA = parseInt(strA[4])
				this.FilterB = parseInt(strA[5])
				this.SortOrder = parseInt(strA[6])
				this.Page = parseInt(strA[7])
				this.Radius = parseInt(strA[8])
				this.MaxPrice = parseInt(strA[9])
				this.MinPrice = parseInt(strA[10])
				this.DetailID = parseInt(strA[11])
				this.LocationID = parseInt(strA[12])
				this.MaxPriceValue = parseInt(strA[131])
				this.MinPriceValue = parseInt(strA[14])
			}
		}
	}	
	this.ToString = function(){
		return this.DataID + "|" + this.Type + "|" +this.SearchA + "|" +this.SearchB + "|" +this.FilterA + "|" + this.FilterB + "|" + this.SortOrder + "|" + this.Page + "|" + this.Radius + "|" + this.MaxPrice + "|" + this.MinPrice + "|" + this.DetailID + "|" + this.LocationID + "|" + this.MaxPriceValue + "|" + this.MinPriceValue;
	}
}
function clsAjaxState(){
	this.KeyValue = "";
	this.Runing = false;
	this.Flag = "";
}
//Find the position of an element
function findPosX(obj){
	var intCurrentLeft = 0;
	if (obj.offsetParent)
	{
		while (obj.offsetParent)
		{

			intCurrentLeft += obj.offsetLeft;
			obj = obj.offsetParent;			
		}
	}
	else if (obj.x)
		intCurrentLeft += obj.x;	
	
	if(ClientB.is_IE6Up){
		if(document.getElementById("frame")){
			intCurrentLeft += document.getElementById("frame").offsetParent.offsetLeft;
		}
	}
	
	return intCurrentLeft;	
}

function findPosY(obj)
{
	var intCurrentTop = 0;
	if (obj.offsetParent)
	{
		while (obj.offsetParent)
		{
			intCurrentTop += obj.offsetTop
			obj = obj.offsetParent;
		}
	}
	else if (obj.y)
		intCurrentTop += obj.y;
	return intCurrentTop;
}
//Cross browser event handlers
function addEvent(obj, evType, fn, useCapture){
  if (obj.addEventListener){
    obj.addEventListener(evType, fn, useCapture);
    return true;
  } else if (obj.attachEvent){
    var r = obj.attachEvent("on"+evType, fn);
    return r;
  } else {
    alert("Handler could not be attached");
  }
}

function removeEvent(obj, evType, fn, useCapture){
  if (obj.removeEventListener){
    obj.removeEventListener(evType, fn, useCapture);
    return true;
  } else if (obj.detachEvent){
    var r = obj.detachEvent("on"+evType, fn);
    return r;
  } else {
    alert("Handler could not be removed");
  }
}
function GotoShortList(){
	window.location="shortlist.aspx";
}	

function GetShortListCount(){
	var strShortlist = GetCookie("PropertyShortlist");
	if (!strShortlist){
		return 0;
	}
	if (strShortlist.length==0){
		return 0;
	}
	var strArray = strShortlist.split(",");
	
	if (!strArray){
		return 0;
	}
	return strArray.length;
}

function SetCookie(name, value, expires, path, domain, secure){
  var curCookie = name + "=" + escape(value) +
      ((expires) ? "; expires=" + expires.toGMTString() : "") +
      ((path) ? "; path=" + path : "") +
      ((domain) ? "; domain=" + domain : "") +
      ((secure) ? "; secure" : "");
  
  document.cookie = curCookie;
}

function GetCookie(name){
    var dc        = document.cookie;
    var prefix    = name + "=";
    var begin     = dc.indexOf("; " + prefix);
  
    if (begin == -1)
    {
        begin = dc.indexOf(prefix);        
        if (begin != 0)
            return '';
    }
    else{
        begin += 2;
    }
  
    var end = document.cookie.indexOf(";", begin);
    
    if (end == -1){
        end = dc.length;
    }  
    return unescape(dc.substring(begin + prefix.length, end));
}

function GoHome(){
	SetCookie("PropertyTodayHistoryOn", "False");
	window.location="frontpage.aspx"
}
function GetImagePathShort(strImage,intType){
	var strPrefix ="";
	var strFilename = "";

	if(intType==2){
		strPrefix="TH1_";
	}
	if(intType==3){
		strPrefix="TH2_";
	}
	if(!strImage){
		return  ""
	}
	
	if(strImage==""){
		return ""
	}
	var strArray = strImage.split("\/");
	
	if(strArray[strArray.length-1].indexOf('.jpg')>-1){
		strArray[strArray.length-1] = strPrefix + strArray[strArray.length-1];
		return strArray.join("\/");
	}
	else{
		return ""
	}
}
function GetImagePath(strImage,intType){
	var strStart = "http\:\/\/images.propertytoday.co.uk\/";
	var strPrefix ="";
	var strFilename = "";

	if(intType==2){
		strPrefix="TH1_";
	}
	if(intType==3){
		strPrefix="TH2_";
	}
	if(!strImage){
		return ""
	}
	
	strImage= strImage.toLowerCase();
	
	if(strImage==""){
		return  ""
	}
	
	var strArray = strImage.split("\/");
	
	if(strArray[strArray.length-1].indexOf('.jpg')>-1){
		strArray[strArray.length-1] = strPrefix + strArray[strArray.length-1];
		return strStart + strArray.join("\/");
	}
	else{
		return ""
	}
}

function pause(intMilliSecounds){
	date = new Date();
	var curDate = null;

	do { var curDate = new Date(); } 
	while(curDate-date < intMilliSecounds);
} 
function ReplaceString(strSource,strOldValue,strNewValue){ 
	var intIndex = strSource.indexOf(strOldValue);
	var strOutput = "";

	if (intIndex == -1 || strOldValue == ""){ 
		return strSource;
	}

	strOutput += strSource.substring(0,intIndex) + strNewValue;

	if ( intIndex + strOldValue.length < strSource.length){
		strOutput += ReplaceString(strSource.substring(intIndex + strOldValue.length, strSource.length), strOldValue, strNewValue);
	}
	return strOutput;

}
function DisplayPrice(objNumber,blnHasPound){
	var strTemp = "";
	var intValue = 3;
	var strValue = objNumber + "";

	if (strTemp=="0"){
		return "POA";	
	}

	if(blnHasPound){
		intValue = 4
	}	
	if(strValue.length > intValue){				
		if(strValue.length > intValue + 3){
			strTemp = strValue.substring(0,strValue.length-6)			
			strTemp = strTemp + "," + strValue.substring(strValue.length-6,strValue.length-3)			
			strTemp = strTemp + "," + strValue.substring(strValue.length-3,strValue.length)
			if(intValue==3){
				strTemp = "\&pound\;" + strTemp;
			}
			return strTemp;
			
		}
		else{
			strTemp = strValue.substring(0,strValue.length-3)			
			strTemp = strTemp + "," + strValue.substring(strValue.length-3,strValue.length)
			if(intValue==3){
				strTemp = "\&pound\;" + strTemp;
			}			
			return  strTemp;
		}
	}
	else{
		if(intValue==3){
			strValue = "\&pound\;" + strValue;
		}
		return strValue;
	}	
	
}
function hintopen(){
	var strUrl = "";
	strUrl = document.location.href;
	strUrl = strUrl.substring(0, strUrl.lastIndexOf("/"));
	window.open (strUrl+"/hints.aspx","hint","location=0,status=0,scrollbars=0,width=470,height=510");
}

