﻿/********************************************************************************************************/
/*                                                                                                      */
/*Author: Tony Smith-Brewster                                                                           */
/*Date: 1st August 2007                                                                                 */
/*Description:                                                                                          */
/*   Library of common classes relating to propertytoday.                                               */
/********************************************************************************************************/
            
/********************************************************************************************************/
var Class = {
  create: function() {
    return function() {
      this.initialize.apply(this, arguments);
    }
  }
}

/********************************************************************************************************/
/*Class Name: clsCookie                                                                                 */
/*Author: Tony Smith-Brewster                                                                           */
/*Description: Used for cookie operations                                                               */
/********************************************************************************************************/
clsCookie = Class.create();
clsCookie.prototype = {
   
    initialize : function (strName,arrData,intDays) {

        this.name  = (strName) ? ((strName.length > 0) ? strName : false) : false;
        this.value = (arrData) ? ((arrData.length > 0) ? arrData : false) : false;
        this.days  = (intDays) ? ((isNaN(intDays)) ? false : intDays) : false;

        this.bNewCookie = ( ( (this.name) && (this.value) && (this.days) ) ? true : false)
       
        if(this.bNewCookie){
            //create the cookie if it ain't there!
            if(this.readCookie(this.name) == null){
                this.createCookie(this.name,
                                  this.value,
                                  this.days);
            }
        }
        if(this.name){
            var tmpCookieData = this.readCookie(this.name);
            this.cookieData = null ;
            if(tmpCookieData){
                //Check for an array in the cookie
                if(tmpCookieData.indexOf("|") != -1)
                    this.cookieData = tmpCookieData.split("|");
                else
                    this.cookieData = tmpCookieData;
            }
        }
    }
    ,
    createCookie : function(name,value,days){
        //check for the array and make the required adjustments
        if(value[0]){
                strData = value.toString();
                var rExp = /,/g;             //Create regular expression pattern.
                value = strData.replace(rExp, "|");    //Replace "," with "|".
        }
        
	    if (days) {
		    var date = new Date();
		    date.setTime( date.getTime() + (days * 24 * 60 * 60 * 1000) ); //Set Cookie Expire Time in Milliseconds
		    var expires = "; expires=" + date.toGMTString();
	    }
	    
	    else var expires = "";
	    document.cookie = name + "=" + value + expires + "; path=/";
	    
    }
    ,
    readCookie : function (name) {
	    var nameEQ = name + "=";
	    var ca = document.cookie.split(';');
	        for(var i = 0; i < ca.length; i++) {
		        var c = ca[i];
		        while (c.charAt(0)==' ') c = c.substring(1,c.length);
		        if (c.indexOf(nameEQ) == 0) 
		        return unescape(c.substring(nameEQ.length,c.length));
	        }
	    return null;
    }
    ,
    deleteCookie : function (name) {
	    this.createCookie(name,"",-1);
    }
}

/********************************************************************************************************/
/*Class Name: clsPostcode                                                                                 */
/*Author: Tony Smith-Brewster                                                                           */
/*Description: Used for postcode operations                                                               */
/********************************************************************************************************/
clsPostcode = Class.create();
clsPostcode.prototype = {
   
    initialize : function (postCode) {
        var intIndexOf = 0;
        var size = 0;
       
        var strCleanCode = "";
        
        this.isValid = true;
        this.IsPartPostcodeValid = false;
        
        while (intIndexOf != -1){
            strCleanCode = postCode.replace( " ", "" )
            intIndexOf = strCleanCode.indexOf( " " );
        }
        
        postCode = strCleanCode;
        size = postCode.length;
        
        this.IsPartPostcodeValid = (!(isNaN(postCode.charAt(0)))) ? false : true;
        this.IsPartPostcodeValid = ((isNaN(postCode.charAt(2)))) ? false : this.IsPartPostcodeValid;
        
        this.isValid = (size < 5 || size > 7) ? false : true;
        this.isValid = (!(isNaN(postCode.charAt(0))))? false : this.isValid;
        this.isValid = ( isNaN(postCode.charAt(size - 3)))? false : this.isValid;
        this.isvalid = (!(isNaN(postCode.charAt(size-2))))? false : this.isValid;
        this.isValid = (!(isNaN(postCode.charAt(size-2))))? false : this.isValid;
        this.isValid = (!(isNaN(postCode.charAt(size-1))))? false : this.isValid;
    }
}
    
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);
	}
}
        //fix any png images for ie 6 or less
function fixPNG(){
    var ClientB = new browser();
    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--;
            }   
        }

    }
}
