function Browser() {
  var ua, s, i;

  this.isIE    = false;  // Internet Explorer
  this.isOP    = false;  // Opera
  this.isNS    = false;  // Netscape
  this.version = null;

  ua = navigator.userAgent;

  s = "Opera";
  if ((i = ua.indexOf(s)) >= 0) {
    this.isOP = true;
    this.version = parseFloat(ua.substr(i + s.length));
    return;
  }

  s = "Netscape6/";
  if ((i = ua.indexOf(s)) >= 0) {
    this.isNS = true;
    this.version = parseFloat(ua.substr(i + s.length));
    return;
  }

  // Treat any other "Gecko" browser as Netscape 6.1.

  s = "Gecko";
  if ((i = ua.indexOf(s)) >= 0) {
    this.isNS = true;
    this.version = 6.1;
    return;
  }

  s = "MSIE";
  if ((i = ua.indexOf(s))) {
    this.isIE = true;
    this.version = parseFloat(ua.substr(i + s.length));
    return;
  }
}



function isBlank(val) {
        if (val.length == 0) { return true; }
        for (var i=0; i < val.length; i++) {
                if ((val.charAt(i) != ' ') && (val.charAt(i) != "\t") && (val.charAt(i) != "\n")) { return false; }
        }
        return true;
}

function redirectPage(page) {
	return false; //for now
}


function checkAll2(checkboxes,flag,button) {
	var newValue=true;
    if(flag.value=='true') {
		newValue=true;
        flag.value='false';
        button.value='Uncheck All';
    } else {
		newValue=false;
        flag.value='true';
        button.value='Check All';
    }

	for(var i=0;i<checkboxes.length;i++) { checkboxes[i].checked = newValue; }
	return true;
}

function checkAll(checkboxes,value) {
	var value = true;
	for(var i=0;i<checkboxes.length;i++) { checkboxes[i].checked = value; }
}
function checkemail(str){
	var filter=/^([\w-]+(?:\.[\w-]+)*)@((?:[\w-]+\.)*\w[\w-]{0,66})\.([a-z]{2,6}(?:\.[a-z]{2})?)$/i
	if (filter.test(str)) return true; else return false;
}

function checkurl(str) {
	var filter=/^[http|https]+\:\/\/((?:[\w-]+\.)*\w[\w-]{0,66})\.([a-z]{2,6}(?:\.[a-z]{2})?).*$/i
	if (filter.test(str)) return true; else return false;
}

function checkimage(str) {
	var filter=/\.(gif|jpeg|jpg)$/i
	if (filter.test(str)) return true; else return false;
}

function checklogin(str) {
	var filter=/^[\w-\ ]{4,16}$/i
	if (filter.test(str)) return true; else return false;
}

function checkpassword(str) {
	var filter=/^.{6,32}$/i
	if (filter.test(str)) return true; else return false;
}

function checkdate(str) {
	var filter=/^\d\d\d\d-\d\d-\d\d$/
	if (filter.test(str)) return true; else return false;
}

function checkdate2(str) {
	var filter=/^\d\d\/\d\d\/\d{2,4}$/
	if (filter.test(str)) return true; else return false;
}

function check_usdate(str) {
  var filter=/^\d{1,2}\/\d{1,2}\/\d{2,4}$/
  if (filter.test(str)) return true; else return false;
}

function compare_dates(date1, date2){
  var arrDate1 = date1.split("/");
  var arrDate2 = date2.split("/");
  var rdate1= new Date(arrDate1[2],arrDate1[0]-1,arrDate1[1]);
  var rdate2= new Date(arrDate2[2],arrDate2[0]-1,arrDate2[1]);
  if ( rdate1 > rdate2) return false; else return true;
}

function compare_dates_strong(date1, date2){
  var arrDate1 = date1.split("/");
  var arrDate2 = date2.split("/");
  var rdate1= new Date(arrDate1[2],arrDate1[0]-1,arrDate1[1]);
  var rdate2= new Date(arrDate2[2],arrDate2[0]-1,arrDate2[1]);
  if ( rdate1 >= rdate2) return false; else return true;
}

function date_tousformat(date) {
  var y=date.getFullYear();
  var m=date.getMonth()+1;
  var d=date.getDate();
  if (m<10) m='0'+m;
  if (d<10) d='0'+d;
  return m+'/'+d+'/'+y;
}

function checkoccupants(str) {
	var filter=/^\d$/
	if (filter.test(str)) return true; else return false;
}

function checknumber(str) {
	var filter=/^\d+$/
	if (filter.test(str)) return true; else return false;
}

function checkcolor(str) {
	var filter=/^\#[\d\A\B\C\D\E\F\a\b\c\d\e\f]{6}$/
	if (filter.test(str)) return true; else return false;
}

function checkprice(str) {
	var filter=/^\d*(\.\d+)?$/
	if (filter.test(str)) return true; else return false;
}

function openPopup(theURL,w, h) {
        var left = (screen.width - w) / 2;
        var top = (screen.height - h) / 2;
        var twindow=window.open(theURL,'_blank',"toolbar=no,location=no,directories=no,status=no,menubar=no,scrollbars=yes,resizable=yes,copyhistory=no,left="+left+",top="+top+",width="+w+",height="+h);
        twindow.focus();
}

function replaceLocation(href) {
    window.open(href,'_self',"",false);
    return;
}

function openPage(file,target) {
    if (target != '')
        target.window.location.href = file;
    else
        window.location.href = file;
}

function up_item(item) {
  with(document.forms['order_form']) {
    item_up.value=item;
    submit();
  }
}

function down_item(item) {
  with(document.forms['order_form']) {
    item_down.value=item;
    submit();
  }
}

function changeCurentPage(page_tag, curl) {
  var page_id=page_tag.options[page_tag.selectedIndex].value;
  eval("parent.location='"+curl+"&page="+page_id+"'");
}



//tabs part
var panes = new Array();

function setupPanes(containerId, defaultTabId) {
  // go through the DOM, find each tab-container
  // set up the panes array with named panes
  // find the max height, set tab-panes to that height
  panes[containerId] = new Array();
  var maxHeight = 0; var maxWidth = 0;
  var container = document.getElementById(containerId);
  var paneContainer = container.getElementsByTagName("div")[0];
  var paneList = paneContainer.childNodes;
  for (var i=0; i < paneList.length; i++ ) {
    var pane = paneList[i];
    if (pane.nodeType != 1) continue;
    if (pane.offsetHeight > maxHeight) maxHeight = pane.offsetHeight;
    if (pane.offsetWidth  > maxWidth ) maxWidth  = pane.offsetWidth;
    panes[containerId][pane.id] = pane;
    pane.style.display = "none";
  }
    paneContainer.style.height = maxHeight + "px";
    paneContainer.style.width  = maxWidth + "px";
    document.getElementById(defaultTabId).onclick();
}

function showPane(paneId, activeTab) {
  // make tab active class
  // hide other panes (siblings)
  // make pane visible

    for (var con in panes) {
    activeTab.blur();
    activeTab.className = "tab-active";
    if (panes[con][paneId] != null) { // tab and pane are members of this container
      var pane = document.getElementById(paneId);
      pane.style.display = "block";
      var container = document.getElementById(con);
      var tabs = container.getElementsByTagName("ul")[0];
      var tabList = tabs.getElementsByTagName("a")
      for (var i=0; i<tabList.length; i++ ) {
        var tab = tabList[i];
        if (tab != activeTab) tab.className = "tab-disabled";
      }
      for (var i in panes[con]) {
        var pane = panes[con][i];
        if (pane == undefined) continue;
        if (pane.id == paneId) continue;
        pane.style.display = "none"
      }
    }
  }
  return false;
}

function fpage(tag) { document.location="#"+tag; }

function setObjectClass(object, className) {
  if (object.getAttributeNode("class")) {
    for (var i = 0; i < object.attributes.length; i++) {
      var attrName = object.attributes[i].name.toUpperCase();
      if (attrName == 'CLASS') {
        object.attributes[i].value = className;
      }
    }
  // otherwise create a new attribute
  } else {
    object.setAttribute("class", className);
  }
}

//MM menu
function MM_jumpMenu(targ,selObj,restore){ //v3.0
  var value=selObj.options[selObj.selectedIndex].value;
  if (value != 0) {
    eval(targ+".location='"+value+"'");
    if (restore) selObj.selectedIndex=0;
  }
}

function MM_preloadImages() { //v3.0
  var d=document; if(d.images){ if(!d.MM_p) d.MM_p=new Array();
    var i,j=d.MM_p.length,a=MM_preloadImages.arguments; for(i=0; i<a.length; i++)
    if (a[i].indexOf("#")!=0){ d.MM_p[j]=new Image; d.MM_p[j++].src=a[i];}}
}

function MM_swapImgRestore() { //v3.0
  var i,x,a=document.MM_sr; for(i=0;a&&i<a.length&&(x=a[i])&&x.oSrc;i++) x.src=x.oSrc;
}

function MM_findObj(n, d) { //v4.01
  var p,i,x;  if(!d) d=document; if((p=n.indexOf("?"))>0&&parent.frames.length) {
    d=parent.frames[n.substring(p+1)].document; n=n.substring(0,p);}
  if(!(x=d[n])&&d.all) x=d.all[n]; for (i=0;!x&&i<d.forms.length;i++) x=d.forms[i][n];
  for(i=0;!x&&d.layers&&i<d.layers.length;i++) x=MM_findObj(n,d.layers[i].document);
  if(!x && d.getElementById) x=d.getElementById(n); return x;
}

function MM_swapImage() { //v3.0
  var i,j=0,x,a=MM_swapImage.arguments; document.MM_sr=new Array; for(i=0;i<(a.length-2);i+=3)
   if ((x=MM_findObj(a[i]))!=null){document.MM_sr[j++]=x; if(!x.oSrc) x.oSrc=x.src; x.src=a[i+2];}
}


function myurlencode(str) {
  var new_str=str;
  new_str=new_str.replace(/\&/g, "-and-");
  new_str=new_str.replace(/\//g, "-or-");
  new_str=new_str.replace(/ /g, "-");
  new_str=escape(new_str);
  return new_str;
}

function doCompanySearch() {
    var search_form=document.getElementById('search_company_form');
    var company_template=document.getElementById('company_keyword').value;
    if (isBlank(company_template)) {alert("Please enter keyword to search by unit"); return false;}
    else {
      search_form.action='/search-rentals/'+myurlencode(company_template)+'/page1.html';
      search_form.submit();
      return true;
    }
}

//email link
function log_emaillink(listing_id, site_id) {
 (new Image()).src="/rbo_common/d_images/spy_emaillink.script?listing_id="+listing_id+"&site_id="+site_id;
}

//website link
function log_weblink(listing_id, site_id) {
 (new Image()).src="/rbo_common/d_images/spy_weblink.script?listing_id="+listing_id+"&site_id="+site_id;
}

function log_weblink_open(listing_id, site_id, url) {
 (new Image()).src="/rbo_common/d_images/spy_weblink.script?listing_id="+listing_id+"&site_id="+site_id;
 var twindow=window.open(url);
 return true;
}

//logo link
function log_logolink(listing_id, site_id) {
 (new Image()).src="/rbo_common/d_images/spy_logolink.script?listing_id="+listing_id+"&site_id="+site_id;
}

function log_logolink_open(listing_id, site_id, url) {
 (new Image()).src="/rbo_common/d_images/spy_logolink.script?listing_id="+listing_id+"&site_id="+site_id;
 var twindow=window.open(url);
 return true;
}

//availability request link
function log_availabilitylink(listing_id, site_id) {
  if(document.images){
    (new Image()).src="/rbo_common/d_images/spy_availabilitylink.script?listing_id="+listing_id+"&site_id="+site_id;
  }
}

//log banner
function log_banner(relation_id, package_id, page_id) {
  (new Image()).src="/rbo_common/d_images/banner_redirect.script?relation_id="+relation_id+"&package_id="+package_id+"&page_id="+page_id;
  return true;
}

function swapJImages(imgo)
{
    if(imgo.src.indexOf('over') < 0) {
        imgo.src = imgo.src.replace('.jpg', '_over.jpg');
    } else {
        imgo.src = imgo.src.replace('_over.jpg', '.jpg');
    }
}

function AJAX_NewsLetterSignup() {
	var email_tag=document.getElementById('newsletter_email');

  var callback = {
      success: function(o) {/*success handler code*/
	  		YAHOO.RBO.ServiceDiv.innerHTML=o.responseText;
        /*show add note dialog*/
        var handleCancel = function() { this.cancel(); this.destroy(); }

        var Buttons = [ { text:"Close", handler:handleCancel, isDefault:true  } ];
        var Dialog = new YAHOO.widget.Dialog("ServiceDialog", { width : "500px", fixedcenter : true, visible : false, constraintoviewport : true, modal: true, draggable:true, postmethod:"async" });
        Dialog.cfg.queueProperty("buttons", Buttons);
        Dialog.render();
        Dialog.show();
      },
      failure: function(o) { alert('ERROR: Can not process request: can not setup connection with server'); }
  }

  YAHOO.util.Connect.asyncRequest('POST', '/rbo_common/ajax/newsletter-signup.html?newsletter_email='+email_tag.value, callback);
  email_tag.value='';
}


function AJAX_EmailToFriend(listing_id, formObject) {
	var callback = {
		      success: function(o) {/*success handler code*/
			  	YAHOO.RBO.ServiceDiv.innerHTML=o.responseText;
		        /*show add note dialog*/
		        var handleCancel = function() { this.cancel(); this.destroy(); }
		        var handleSubmit = function() { 
		        	var formObject = document.getElementById('EmailFriendPrintDialog_form');
		        	this.hide(); this.destroy();
		        	AJAX_EmailToFriend(listing_id, formObject);
		        }

		        var Buttons = [ { text:"Submit", handler:handleSubmit, isDefault:true  }, { text:"Close", handler:handleCancel} ];
		        var Dialog = new YAHOO.widget.Dialog("EmailFriendPrintDialog", { width : "500px", fixedcenter : true, visible : false, constraintoviewport : true, modal: true, draggable:true, postmethod:"async" });
		        Dialog.cfg.queueProperty("buttons", Buttons);
		        Dialog.render();
		        Dialog.show();
		      },
		      failure: function(o) { alert('ERROR: Can not process request: can not setup connection with server'); }
	}
	
	if (formObject != null && typeof(formObject) != 'undefined') {
		YAHOO.util.Connect.setForm(formObject);
		YAHOO.util.Connect.asyncRequest('POST', '/rbo_common/ajax/email-friend-printform.html?listing_id='+listing_id, callback);
	} else {
		YAHOO.util.Connect.asyncRequest('POST', '/rbo_common/ajax/email-friend-printform.html?listing_id='+listing_id, callback);
	}
}