
//changes the property details images over
function showImage(filename,caption){
    $get("ctl00_ctl00_pagecontent_leftcolumncontent_imgmainphoto").src='/images/property/sm_'+filename;
}

function $n(element)
{
  if (arguments.length > 1) {
    for (var i = 0, elements = [], length = arguments.length; i < length; i++)
      elements.push($n(arguments[i]));
    return elements;
  }
  if (typeof element == 'string') {
    var el = document.getElementById(element);
    if( el ) 
      return el;
  }
  else
    return element;
 
  var regExp = new RegExp('_' + element + '$');
  var formsLength = document.forms.length;
  for( var i=0; i<formsLength; i++ ) {
    var form = document.forms[i];
    var elementsLength = form.elements.length;
    for( var j=0; j<elementsLength; j++ ) {
      element = form.elements[j];
      if( element.id && element.id.match(regExp) ) 
        return element;
    }
  }
  
  //try images
  var imagesLength = document.images.length;
  for( var i=0; i<imagesLength; i++ ) {
    element = document.images[i];
    if( element.id && element.id.match(regExp) ) 
    return element;
  }
  return null;
}

function isUserLoggedIn(){
    var cookievalue = getCookie("siteuserloggedin");

    if(cookievalue!=null&&cookievalue=="1"){
        return true;
    }
    return false;
}

function addToSelectList(propid){
    var now = new Date();
    if(doesSelectListContain(propid)==false){
        var existingvalues = getCookie("selectedprop");
        now.setTime(now.getTime() + 365 * 24 * 60 * 60 * 1000);
        
        if(existingvalues!=null&&existingvalues.length>0){
            setCookie("selectedprop", existingvalues + "," + propid,now,"/");
        }
        else{
            setCookie("selectedprop", propid,now,"/");
        }
    }    
}

function doesSelectListContain(propid){
    var cookievalue = getCookie("selectedprop");
    if(cookievalue!=null&&cookievalue.length>0){
        var props = cookievalue.split(",");
        for(i=0;i<props.length;i++){
            if(propid.toString()==props[i]){
                return true;
            }
        }
    }
    return false;
}


function removeFromSelectList(propid){
    var now = new Date();
    now.setTime(now.getTime() + 365 * 24 * 60 * 60 * 1000);
    if(getCookie("selectedprop")!=null){
        var props = getCookie("selectedprop").split(",");
        var result = "";
        for(i=0;i<props.length;i++){
            if(propid.toString()!=props[i]&&propid.toString().length>0){
                if(result!="") result += ",";
                result +=  + props[i];
            }
        }
        setCookie("selectedprop",result,now,"/");
    }
}

function deleteSelectList(){
    deleteCookie("selectedprop","/");
    
    //deselect any checkboxes on this page
    cb=document.getElementsByTagName('input');
    for (var i=0;i<cb.length;i++){
        if(cb[i].type=='checkbox'&&cb[i].id.substring(0,5)=='prop_'){
            cb[i].checked=false;
        }
    }
    
}

function selectPropertiesFromSelectList(){
    //loop all checkboxes and check if in selected cookie
    cb=document.getElementsByTagName('input');
    for (var i=0;i<cb.length;i++){
        if(cb[i].type=='checkbox'&&cb[i].id.substring(0,5)=='prop_'){
            if(doesSelectListContain(cb[i].id.substring(5))) cb[i].checked=true;
        }
    }    
}

function addToUserSelectList(propid){
    if(doesUserSelectListContain(propid)==false){
        var existingvalues = getCookie("userselectedprop");
        
        if(existingvalues!=null&&existingvalues.length>0){
            setCookie("userselectedprop", existingvalues + "," + propid,null,"/");
        }
        else{
            setCookie("userselectedprop", propid,null,"/");
        }
    }    

}

function doesUserSelectListContain(propid){
    var cookievalue = getCookie("userselectedprop");
    if(cookievalue!=null&&cookievalue.length>0){
        var props = cookievalue.split(",");
        for(i=0;i<props.length;i++){
            if(propid.toString()==props[i]){
                return true;
            }
        }
    }
    return false;
}


function removeFromUserSelectList(propid){    
    if(getCookie("userselectedprop")!=null){
        var props = getCookie("userselectedprop").split(",");
        var result = "";
        for(i=0;i<props.length;i++){
            if(propid.toString()!=props[i]&&propid.toString().length>0){
                if(result!="") result += ",";
                result +=  + props[i];
            }
        }
        setCookie("userselectedprop",result,null,"/");
    }
}

function deleteUserSelectList(){
    deleteCookie("userselectedprop","/");
    
    //deselect any checkboxes on this page
    cb=document.getElementsByTagName('input');
    for (var i=0;i<cb.length;i++){
        if(cb[i].type=='checkbox'&&cb[i].id.substring(0,5)=='prop_'){
            cb[i].checked=false;
        }
    }
    
}

function selectPropertiesFromUserSelectList(){
    //loop all checkboxes and check if in selected cookie
    cb=document.getElementsByTagName('input');
    for (var i=0;i<cb.length;i++){
        if(cb[i].type=='checkbox'&&cb[i].id.substring(0,5)=='prop_'){
            if(doesUserSelectListContain(cb[i].id.substring(5))) cb[i].checked=true;
        }
    }    
}

function addToWatchList(propid){
    if(isUserLoggedIn()==true){
        //show message about adding
        TB_show('Adding to Watchlist', '/adding-to-watchlist.aspx?propertyid=' + propid + '&keepThis=true&TB_iframe=true&height=200&width=300', null);
    }
    else {
        TB_show('Login Or Register', '/my-property-portfolio/register.aspx?watchlistlogin=1&propertyid=' + propid + '&keepThis=true&TB_iframe=true&height=570&width=820', null);
    }
}

function addSavedSearch(qs) {
    if (isUserLoggedIn() == true) {
        //show saved search wizard
        TB_show('Add email subscription', '/my-property-portfolio/save-new-search.aspx?' + qs + '&keepThis=true&TB_iframe=true&height=570&width=820', null);
    }
    else {
        //show registration page
        TB_show('Login Or Register', '/my-property-portfolio/register.aspx?savedsearchlogin=1&' + qs + '&keepThis=true&TB_iframe=true&height=570&width=820', null);
    }
}

/*
   name - name of the cookie
   value - value of the cookie
   [expires] - expiration date of the cookie
     (defaults to end of current session)
   [path] - path for which the cookie is valid
     (defaults to path of calling document)
   [domain] - domain for which the cookie is valid
     (defaults to domain of calling document)
   [secure] - Boolean value indicating if the cookie transmission requires
     a secure transmission
   * an argument defaults when it is assigned null as a placeholder
   * a null placeholder is not required for trailing omitted arguments
*/

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 null;
  } else
    begin += 2;
  var end = document.cookie.indexOf(";", begin);
  if (end == -1)
    end = dc.length;
  return unescape(dc.substring(begin + prefix.length, end));
}


function deleteCookie(name, path, domain) {
  if (getCookie(name)) {
    document.cookie = name + "=" +
    ((path) ? "; path=" + path : "") +
    ((domain) ? "; domain=" + domain : "") +
    "; expires=Thu, 01-Jan-70 00:00:01 GMT";
  }
}

function ShowLoading(el,loadingclass){
        
     if($(el))$(el).startWaiting(loadingclass);
     return true;

}

function ValidateAndShowLoading(el,loadingclass,valgroup,hidetime){
    if(Page_Validate(valgroup)){
        if(Page_IsValid!=null&&Page_IsValid)
        {
             $(el).startWaiting(loadingclass);
             if(hidetime!=null) setTimeout('$(el).stopWaiting();',hidetime);
             return true;
        }
        else
        return false;
    }
    else
        //assume no validators on page
        return true;
}

function Page_Validate(valgroup)
{
    try{
        var i;
        for (i = 0; i < Page_Validators.length; i++)
        {
            if(valgroup==null){
                ValidatorValidate(Page_Validators[i]);
            }
            else{
                ValidatorValidate(Page_Validators[i],valgroup);
            }
                
        }
        ValidatorUpdateIsValid();
        ValidationSummaryOnSubmit();
        Page_BlockSubmit = !Page_IsValid;
        return true;
    }
    catch(err){
        //assume no validators on page
        return false;
    }


}

function textboxMultilineMaxNumber(txt,maxLen){ 
    try{ 
        if(txt.value.length > (maxLen-1))return false;
    }
        catch(e){ 
    } 
} 









