function $(elem)
{
  return document.getElementById(elem);
}

function checkThisForm(ff,arr,title)
{
 var err='';
 for(i=0;i<arr.length;i++)
 {
  if(ff.elements[arr[i]].value==''){err+="* Field required: "+title[i]+"\n";}
 }
 if(err!=''){alert("Please correct these problems:\n\n"+err);return false;}
}

function setSelect(select,value)  	
{
  if(select==undefined){ return; };
  if(select.options==undefined){ return; };

  for (var i=0; i<select.options.length;i++)
  {
     if(select.options[i].value==value){select.options[i].selected=true;}
  }
}

function setRadio(radio,value)  	
{
  if(radio==undefined){ return; };
  for (var i=0; i<radio.length;i++)
  {
     if(radio[i].value.toLowerCase()==value.toLowerCase()){radio[i].checked=true;}
  }
}

function ConfirmLink(str,link)
{
    if( confirm(str) )
    {
        document.location=link;
    }
}

/* Retrieves the value from any type of form element */
function getValue(e) {
  if (e.value) {
    /* Text box/text area */
    return e.value;
  } else if (e.length) {
    if (e.options) {
      /* Select box */
      return e.options[e.selectedIndex].value;
    } else {
      /* Checkbox or radio */
      for (i = 0; i < e.length; i++) {
        if (e[i].checked) {
          return e[i].value;
        }
      }
    }
  }
  return null;
}

/* prefex the url with http:// if it doesn't have the scheme already */
function adjUrl(u) {
  str = String(u);
  if (str.substr(0,4) != "http") {
    u = "http://" + u;
  }
  return u;
}

function ConfirmLink2(str)
{
    if( !confirm(str) )
    {
        return false;
    }
 return true;
}

function OpenWin(link,w,h)
{
  if(!w)w=680;
  if(!h)h=680;
  var popupWin = window.open(link,null, 'width='+w+',height='+h+',status=no,scrollbars=yes,resizable=yes,top=50,left=50');
  popupWin.focus();
  return false;
}


function checkEmail(email)
{
 var re = new RegExp("^[\\w-_\.]*[\\w-_\.]\@[\\w]\.+[\\w]+[\\w]$","i");
 if(!re.test(email.value)){alert("* Email address you entered is invalid!\n");return false;}
 return true;
}

function addRate()
{
  var name = prompt('Enter new Rate Table name',' ');
  if(!name || name.length<2)return false;
  document.location='?op=rate_table_add&name='+escape(name);
}

//-------------------------------------------------------------------------

var prevWin = null;
function fShow(oForm)
{
    //if(CheckForm()==false){return false;}
    oForm.target = 'prevWin';
    //var w = screen.width-30, h = screen.height-80;
    var w = 720, h = 500;
	 //var l = (screen.availWidth - w) * .5;
	 //var t = (screen.availHeight - h) * .5;
	prevWin = open('about:blank', 'prevWin', 'width='+w+',height='+h+',left=20,top=20,status=0,scrollbars=1,resizable=1');
	if (prevWin && !prevWin.closed)
		prevWin.focus();
	return true;
}

function fSend(oForm)
{
    //if(CheckForm()==false){return false;}
    oForm.target = '_self';
    if (prevWin && !prevWin.closed)
		prevWin.close();
	return true;
}

function fixFloat(x)
{
    if(x==undefined||x==''){x=0;}
    str = x+'';
    ind = str.indexOf('.');
    if(ind==-1)return str+".00";
    if(ind==str.length-2){str+='0'};
    return str.substring(0,ind+3);
}

function fixInt(x,fl)
{
    x=x+'';
    if(!fl)fl=2;
    if(x.length<fl)
    {
        while(x.length<fl)x='0'+x;
    }
    return x;
}

function set_field(field,value)
{
    if(document.F1[field]==undefined){return;}
    document.F1[field].value=value;
}

function calc_subtotal(prop_id)
{
    var subtotal=0;
    for(i=1;i<7;i++)
    {
       var el = document.F1["fee_"+i+"_"+prop_id];
       if(el!=undefined && el.value>0){subtotal+=parseFloat(el.value);}
    }
    document.F1["subtotal_"+prop_id].value = fixFloat(subtotal);
    var tax = document.F1["taxes_"+prop_id];
    tax.value = fixFloat( tax.value );
    document.F1["total_"+prop_id].value = fixFloat( subtotal+parseFloat(tax.value) );

}

function calc_subtotal2(prop_id)
{
    document.F1["total_"+prop_id].value = fixFloat( parseFloat(document.F1["subtotal_"+prop_id].value) + parseFloat(document.F1["taxes_"+prop_id].value) );
}

function Check4Int(obj)
{
    if(!obj.value.match(/^\d*$/))
    {
        obj.focus();
        alert("Invalid value! Should contain digits only.");
    }
}

function ajaxHelp(obj)
{
    if(!obj.hdn)
    {
        obj.hdn=1;
        obj.innerHTML = 'Hide help';
        jah('/cgi-bin/help.cgi?q='+obj.href, obj.id+'_text' );
    }
    else
    {
        obj.hdn=0;
        obj.innerHTML = 'Show help';
        $(obj.id+'_text').innerHTML='';
    }
    return false;
}

function jah(url,target,txt,func)
{
    if(txt)
    {
     document.getElementById(target).innerHTML += "<Center>"+txt+"<br><img src='/images/ajax-loader3.gif'></Center>";
    }
    else if(target)
    {
     document.getElementById(target).innerHTML = "<Center>Loading...<br><img src='/images/ajax-loader3.gif'></Center>";
    }
    
    if (window.XMLHttpRequest)
    {
        req = new XMLHttpRequest();
        req.onreadystatechange = function() {jahDone(target,func);};
        req.open("GET", url, true);
        req.send(null);
    }
    else if (window.ActiveXObject)
    {
        req = new ActiveXObject("Microsoft.XMLHTTP");
        if (req)
        {
            req.onreadystatechange = function() {jahDone(target,func);};
            req.open("GET", url, true);
            req.send();
        }
    }
}

function jahDone(target,func)
{
    if (req.readyState == 4)
    {
        if (req.status == 200)
        {
            results = req.responseText;
            if(func)
            {
                func(results);
                return;
            }
            else
            {
                $(target).innerHTML=results;
            }
            
        }
        else
        {
            $(target).innerHTML="jah error:\n" + req.statusText;
        }
    }
}

function submitAjaxRequest(f)
{
    if(f.arrive_date.value=='' || f.depart_date.value=='')return false;
    url='/cgi-bin/admin.cgi?op=ajax_quote&owner_id='+f.oid.value+'&arrive_date='+f.arrive_date.value+'&depart_date='+f.depart_date.value;
    if(f.prop_name)url+='&prop_name='+f.prop_name.value;
    if(f.admin)url+='&admin=1';
    if(f.task_id)url+='&task_id='+f.task_id.value;
    if(f.currency)url+='&currency='+getValue(f.currency);
    jah(url,'jah1');
    if(self.xcalendar)
    {
        top.xcalendar.document.location='/cgi-bin/admin.cgi?op=ext_calendar&select=1&owner_id='+f.oid.value+'&Nmonths=4&start_date='+f.arrive_date.value+'&end_date='+f.depart_date.value;
    }
}

function showhide_acp()
{
    var rb = document.F1.prop_id;
    for(i=0;i<rb.length;i++)
    {
        if(rb[i].checked)
        {
            $('acp_'+rb[i].value).style.display = 'block';
            $('tr'+rb[i].value).className='yellow';
        }
        else
        {
            $('acp_'+rb[i].value).style.display = 'none';
            if(!rb[i].disabled)$('tr'+rb[i].value).className='';
        }
    }
}

function addTotal( prop_id, amount, tax, tax1, tax2, tax3, status )
{
   if(status){amount=-amount; tax=-tax; tax1=-tax1; tax2=-tax2; tax3=-tax3;}
   b=document.F1["tax_"+prop_id];
   b.value=parseFloat(b.value);
   a=document.F1["total_"+prop_id];
   a.value = parseFloat(a.value) - 1*parseFloat(tax);
   a.value -= parseFloat(amount);
   b.value -= parseFloat(tax);
   document.getElementById("total_txt_"+prop_id).innerHTML = fixFloat(a.value);
   document.getElementById("tax_txt_"+prop_id).innerHTML = fixFloat(b.value);
   document.getElementById('custom4_'+prop_id).value -= parseFloat(tax1);
   document.getElementById('custom5_'+prop_id).value -= parseFloat(tax2);
   document.getElementById('custom6_'+prop_id).value -= parseFloat(tax3);
   document.getElementById('subtotal_'+prop_id).value -=parseFloat(amount);
   calculate_total();
}




var niftyOk=(document.getElementById && document.createElement && Array.prototype.push);
var niftyCss=false;

String.prototype.find=function(what){
return(this.indexOf(what)>=0 ? true : false);
}

var oldonload=window.onload;
if(typeof(NiftyLoad)!='function') NiftyLoad=function(){};
if(typeof(oldonload)=='function')
    window.onload=function(){oldonload();NiftyLoad()};
else window.onload=function(){NiftyLoad()};

function AddCss(){
niftyCss=true;
var l=CreateEl("link");
l.setAttribute("type","text/css");
l.setAttribute("rel","stylesheet");
l.setAttribute("href","/niftyCorners.css");
l.setAttribute("media","screen");
document.getElementsByTagName("head")[0].appendChild(l);
}

function Nifty(selector,options){
if(niftyOk==false) return;
//if(niftyCss==false) AddCss();
var i,v=selector.split(","),h=0;
if(options==null) options="";
if(options.find("fixed-height"))
    h=getElementsBySelector(v[0])[0].offsetHeight;
for(i=0;i<v.length;i++)
    Rounded(v[i],options);
if(options.find("height")) SameHeight(selector,h);
}

function Rounded(selector,options){
var i,top="",bottom="",v=new Array();
if(options!=""){
    options=options.replace("left","tl bl");
    options=options.replace("right","tr br");
    options=options.replace("top","tr tl");
    options=options.replace("bottom","br bl");
    options=options.replace("transparent","alias");
    if(options.find("tl")){
        top="both";
        if(!options.find("tr")) top="left";
        }
    else if(options.find("tr")) top="right";
    if(options.find("bl")){
        bottom="both";
        if(!options.find("br")) bottom="left";
        }
    else if(options.find("br")) bottom="right";
    }
if(top=="" && bottom=="" && !options.find("none")){top="both";bottom="both";}
v=getElementsBySelector(selector);
for(i=0;i<v.length;i++){
    FixIE(v[i]);
    if(top!="") AddTop(v[i],top,options);
    if(bottom!="") AddBottom(v[i],bottom,options);
    }
}

function AddTop(el,side,options){
var d=CreateEl("b"),lim=4,border="",p,i,btype="r",bk,color;
d.style.marginLeft="-"+getPadding(el,"Left")+"px";
d.style.marginRight="-"+getPadding(el,"Right")+"px";
if(options.find("alias") || (color=getBk(el))=="transparent"){
    color="transparent";bk="transparent"; border=getParentBk(el);btype="t";
    }
else{
    bk=getParentBk(el); border=Mix(color,bk);
    }
d.style.background=bk;
d.className="niftycorners";
p=getPadding(el,"Top");
if(options.find("small")){
    d.style.marginBottom=(p-2)+"px";
    btype+="s"; lim=2;
    }
else if(options.find("big")){
    d.style.marginBottom=(p-10)+"px";
    btype+="b"; lim=8;
    }
else d.style.marginBottom=(p-5)+"px";
for(i=1;i<=lim;i++)
    d.appendChild(CreateStrip(i,side,color,border,btype));
el.style.paddingTop="0";
el.insertBefore(d,el.firstChild);
}

function AddBottom(el,side,options){
var d=CreateEl("b"),lim=4,border="",p,i,btype="r",bk,color;
d.style.marginLeft="-"+getPadding(el,"Left")+"px";
d.style.marginRight="-"+getPadding(el,"Right")+"px";
if(options.find("alias") || (color=getBk(el))=="transparent"){
    color="transparent";bk="transparent"; border=getParentBk(el);btype="t";
    }
else{
    bk=getParentBk(el); border=Mix(color,bk);
    }
d.style.background=bk;
d.className="niftycorners";
p=getPadding(el,"Bottom");
if(options.find("small")){
    d.style.marginTop=(p-2)+"px";
    btype+="s"; lim=2;
    }
else if(options.find("big")){
    d.style.marginTop=(p-10)+"px";
    btype+="b"; lim=8;
    }
else d.style.marginTop=(p-5)+"px";
for(i=lim;i>0;i--)
    d.appendChild(CreateStrip(i,side,color,border,btype));
el.style.paddingBottom=0;
el.appendChild(d);
}

function CreateStrip(index,side,color,border,btype){
var x=CreateEl("b");
x.className=btype+index;
x.style.backgroundColor=color;
x.style.borderColor=border;
if(side=="left"){
    x.style.borderRightWidth="0";
    x.style.marginRight="0";
    }
else if(side=="right"){
    x.style.borderLeftWidth="0";
    x.style.marginLeft="0";
    }
return(x);
}

function CreateEl(x){
return(document.createElement(x));
}

function FixIE(el){
if(el.currentStyle!=null && el.currentStyle.hasLayout!=null && el.currentStyle.hasLayout==false)
    el.style.display="inline-block";
}

function SameHeight(selector,maxh){
var i,v=selector.split(","),t,j,els=[],gap;
for(i=0;i<v.length;i++){
    t=getElementsBySelector(v[i]);
    els=els.concat(t);
    }
for(i=0;i<els.length;i++){
    if(els[i].offsetHeight>maxh) maxh=els[i].offsetHeight;
    els[i].style.height="auto";
    }
for(i=0;i<els.length;i++){
    gap=maxh-els[i].offsetHeight;
    if(gap>0){
        t=CreateEl("b");t.className="niftyfill";t.style.height=gap+"px";
        nc=els[i].lastChild;
        if(nc.className=="niftycorners")
            els[i].insertBefore(t,nc);
        else els[i].appendChild(t);
        }
    }
}

function getElementsBySelector(selector){
var i,j,selid="",selclass="",tag=selector,tag2="",v2,k,f,a,s=[],objlist=[],c;
if(selector.find("#")){ //id selector like "tag#id"
    if(selector.find(" ")){  //descendant selector like "tag#id tag"
        s=selector.split(" ");
        var fs=s[0].split("#");
        if(fs.length==1) return(objlist);
        f=document.getElementById(fs[1]);
        if(f){
            v=f.getElementsByTagName(s[1]);
            for(i=0;i<v.length;i++) objlist.push(v[i]);
            }
        return(objlist);
        }
    else{
        s=selector.split("#");
        tag=s[0];
        selid=s[1];
        if(selid!=""){
            f=document.getElementById(selid);
            if(f) objlist.push(f);
            return(objlist);
            }
        }
    }
if(selector.find(".")){      //class selector like "tag.class"
    s=selector.split(".");
    tag=s[0];
    selclass=s[1];
    if(selclass.find(" ")){   //descendant selector like tag1.classname tag2
        s=selclass.split(" ");
        selclass=s[0];
        tag2=s[1];
        }
    }
var v=document.getElementsByTagName(tag);  // tag selector like "tag"
if(selclass==""){
    for(i=0;i<v.length;i++) objlist.push(v[i]);
    return(objlist);
    }
for(i=0;i<v.length;i++){
    c=v[i].className.split(" ");
    for(j=0;j<c.length;j++){
        if(c[j]==selclass){
            if(tag2=="") objlist.push(v[i]);
            else{
                v2=v[i].getElementsByTagName(tag2);
                for(k=0;k<v2.length;k++) objlist.push(v2[k]);
                }
            }
        }
    }
return(objlist);
}

function getParentBk(x){
var el=x.parentNode,c;
while(el.tagName.toUpperCase()!="HTML" && (c=getBk(el))=="transparent")
    el=el.parentNode;
if(c=="transparent") c="#FFFFFF";
return(c);
}

function getBk(x){
var c=getStyleProp(x,"backgroundColor");
if(c==null || c=="transparent" || c.find("rgba(0, 0, 0, 0)"))
    return("transparent");
if(c.find("rgb")) c=rgb2hex(c);
return(c);
}

function getPadding(x,side){
var p=getStyleProp(x,"padding"+side);
if(p==null || !p.find("px")) return(0);
return(parseInt(p));
}

function getStyleProp(x,prop){
if(x.currentStyle)
    return(x.currentStyle[prop]);
if(document.defaultView.getComputedStyle)
    return(document.defaultView.getComputedStyle(x,'')[prop]);
return(null);
}

function rgb2hex(value){
var hex="",v,h,i;
var regexp=/([0-9]+)[, ]+([0-9]+)[, ]+([0-9]+)/;
var h=regexp.exec(value);
for(i=1;i<4;i++){
    v=parseInt(h[i]).toString(16);
    if(v.length==1) hex+="0"+v;
    else hex+=v;
    }
return("#"+hex);
}

function Mix(c1,c2){
var i,step1,step2,x,y,r=new Array(3);
if(c1.length==4)step1=1;
else step1=2;
if(c2.length==4) step2=1;
else step2=2;
for(i=0;i<3;i++){
    x=parseInt(c1.substr(1+step1*i,step1),16);
    if(step1==1) x=16*x+x;
    y=parseInt(c2.substr(1+step2*i,step2),16);
    if(step2==1) y=16*y+y;
    r[i]=Math.floor((x*50+y*50)/100);
    r[i]=r[i].toString(16);
    if(r[i].length==1) r[i]="0"+r[i];
    }
return("#"+r[0]+r[1]+r[2]);
}

//--------------------------------

Array.prototype.indexOf = function(item) {
    for (var i = 0; i < this.length; i++) {
        if (this[i] == item) {
            return i;
        }
    }
    return -1;
};
Array.prototype.filter = function(test) {
    var matches = [];
    for (var i = 0; i < this.length; i++) {
        if (test(this[i])) {
            matches[matches.length] = this[i];
        }
    }
    return matches;
};

var monthNames = "January February March April May June July August September October November December".split(" ");
var weekdayNames = "Sunday Monday Tuesday Wednesday Thursday Friday Saturday".split(" ");

function parseMonth(month) {
    var matches = monthNames.filter(function(item) { 
        return new RegExp("^" + month, "i").test(item);
    });
    if (matches.length == 0) {
        throw new Error("Invalid month string");
    }
    if (matches.length > 1) {
        throw new Error("Ambiguous month");
    }
    return monthNames.indexOf(matches[0]);
}
function parseWeekday(weekday) {
    var matches = weekdayNames.filter(function(item) {
        return new RegExp("^" + weekday, "i").test(item);
    });
    if (matches.length == 0) {
        throw new Error("Invalid day string");
    }
    if (matches.length > 1) {
        throw new Error("Ambiguous weekday");
    }
    return weekdayNames.indexOf(matches[0]);
}

var dateParsePatterns = [
    // Today
    {   re: /^tod/i,
        handler: function() { 
            return new Date();
        } 
    },
    // Tomorrow
    {   re: /^tom/i,
        handler: function() {
            var d = new Date(); 
            d.setDate(d.getDate() + 1); 
            return d;
        }
    },
    // Yesterday
    {   re: /^yes/i,
        handler: function() {
            var d = new Date();
            d.setDate(d.getDate() - 1);
            return d;
        }
    },
    // 4th
    {   re: /^(\d{1,2})(st|nd|rd|th)$/i, 
        handler: function(bits) {
            var d = new Date();
            d.setDate(parseInt(bits[1], 10));
            return d;
        }
    },
    // 4th Jan
    {   re: /^(\d{1,2})(?:st|nd|rd|th)? (\w+)$/i, 
        handler: function(bits) {
            var d = new Date();
            d.setMonth(parseMonth(bits[2]));
            d.setDate(parseInt(bits[1], 10));
            return d;
        }
    },
    // 4th Jan 2003
    {   re: /^(\d{1,2})(?:st|nd|rd|th)? (\w+),? (\d{4})$/i,
        handler: function(bits) {
            var d = new Date();
            d.setMonth(parseMonth(bits[2]));
            d.setDate(parseInt(bits[1], 10));
            d.setYear(bits[3]);
            return d;
        }
    },
    // Jan 4th
    {   re: /^(\w+) (\d{1,2})(?:st|nd|rd|th)?$/i, 
        handler: function(bits) {
            var d = new Date();
            d.setMonth(parseMonth(bits[1]));
            d.setDate(parseInt(bits[2], 10));
            return d;
        }
    },
    // Jan 4th 2003
    {   re: /^(\w+) (\d{1,2})(?:st|nd|rd|th)?,? (\d{4})$/i,
        handler: function(bits) {
            var d = new Date();
            d.setMonth(parseMonth(bits[1]));
            d.setDate(parseInt(bits[2], 10));
            d.setYear(bits[3]);
            return d;
        }
    },
    // next Tuesday - this is suspect due to weird meaning of "next"
    {   re: /^next (\w+)$/i,
        handler: function(bits) {
            var d = new Date();
            var day = d.getDay();
            var newDay = parseWeekday(bits[1]);
            var addDays = newDay - day;
            if (newDay <= day) {
                addDays += 7;
            }
            d.setDate(d.getDate() + addDays);
            return d;
        }
    },
    // last Tuesday
    {   re: /^last (\w+)$/i,
        handler: function(bits) {
            throw new Error("Not yet implemented");
        }
    },
    // mm/dd/yyyy (American style)
    {   re: /(\d{1,2})\/(\d{1,2})\/(\d{2,4})/,
        handler: function(bits) {
            var d = new Date();
            //alert(parseInt(bits[1], 10)+':'+bits[2]+':'+bits[3]);
            if(bits[3].length==2)bits[3]='20'+bits[3];
            d.setYear(bits[3]);
            d.setMonth( parseInt(bits[1], 10)-1 );
            d.setDate(parseInt(bits[2], 10));
            
            
            return d;
        }
    },
    // yyyy-mm-dd (ISO style)
    {   re: /(\d{4})-(\d{1,2})-(\d{1,2})/,
        handler: function(bits) {
            var d = new Date();
            d.setYear(parseInt(bits[1]));
            d.setMonth(parseInt(bits[2], 10) - 1);
            d.setDate(parseInt(bits[3], 10));
            return d;
        }
    },
];

function parseDateString(s) {
    for (var i = 0; i < dateParsePatterns.length; i++) {
        var re = dateParsePatterns[i].re;
        var handler = dateParsePatterns[i].handler;
        var bits = re.exec(s);
        if (bits) {
            return handler(bits);
        }
    }
    throw new Error("Invalid date string");
}

function magicDate(input) {
    var messagespan = input.id + 'Msg';
    try {
        var d = parseDateString(input.value);
        //alert(d.getMonth());
        input.value = fixInt(d.getMonth() + 1) + '/' + fixInt(d.getDate()) + '/' + d.getFullYear();
        input.style.backgroundColor='#ffffff';
        //input.className = '';
        // Human readable date
        //document.getElementById(messagespan).firstChild.nodeValue = d.toDateString();
        //document.getElementById(messagespan).className = 'normal';
    }
    catch (e) {
        if(input.value.match(/^\d*$/))return;
        input.style.backgroundColor='#eedddd';
    }
}

//--------------------------

window.onerror = null;

ttp = {

	attr_name: "ttp",
	blank_text: "(Open in New Window)",
	newline_entity: "  ",
	max_width: 0,
	delay: 500,

	t: document.createElement("DIV"),
	c: null,
	g: false,

	m: function(e){
		if (ttp.g){
			oCanvas = document.getElementsByTagName(
			(document.compatMode && document.compatMode == "CSS1Compat") ? "HTML" : "BODY"
			)[0];
			x = window.event ? event.clientX + oCanvas.scrollLeft : e.pageX;
			y = window.event ? event.clientY + oCanvas.scrollTop : e.pageY;
			ttp.a(x, y);
		}
	},

	d: function(){
		ttp.t.setAttribute("id", "tooltip");
		ttp.t.style.filter = "alpha(opacity=85)"; // buggy in ie5.0
        document.body.appendChild(ttp.t);
		a = document.all && !window.opera ? document.all : document.getElementsByTagName("*"); // in opera 9 document.all produces type mismatch error
		aLength = a.length;
		for (var i = 0; i < aLength; i++)
        {
			if (!a[i]) continue;
			ttp_title = a[i].getAttribute("title"); // returns form object if IE & name="title"; then IE crashes; so...
			if (ttp_title && typeof ttp_title != "string") ttp_title = "";
			ttp_alt = a[i].getAttribute("alt");
			ttp_blank = a[i].getAttribute("target") && a[i].getAttribute("target") == "_blank" && ttp.blank_text;
			if (ttp_title || ttp_blank){
				a[i].setAttribute(ttp.attr_name, ttp_blank ? (ttp_title ? ttp_title + " " + ttp.blank_text : ttp.blank_text) : ttp_title);
				if (a[i].getAttribute(ttp.attr_name)){
					a[i].removeAttribute("title");
					if (ttp_alt && a[i].complete) a[i].removeAttribute("alt");
					ttp.l(a[i], "mouseover", ttp.s);
					ttp.l(a[i], "mouseout", ttp.h);
				}
			}else if (ttp_alt && a[i].complete){
				a[i].setAttribute(ttp.attr_name, ttp_alt);
				if (a[i].getAttribute(ttp.attr_name)){
					a[i].removeAttribute("alt");
					ttp.l(a[i], "mouseover", ttp.s);
					ttp.l(a[i], "mouseout", ttp.h);
				}
			}
		}
		document.onmousemove = ttp.m;
		window.onscroll = ttp.h;
		ttp.a(-99, -99);
	},

	s: function(e){
		d = window.event ? window.event.srcElement : e.target;
		if (!d.getAttribute(ttp.attr_name)) return;
		s = d.getAttribute(ttp.attr_name);
		if (ttp.newline_entity){
			s = s.replace(/\&/g,"&amp;");
			//s = s.replace(/\</g,"&lt;");
			//s = s.replace(/\>/g,"&gt;");
			//s = s.replace(eval("/" + ttp.newline_entity + "/g"), "<br />");
			ttp.t.innerHTML = s;
		}else{
			if (ttp.t.firstChild) ttp.t.removeChild(ttp.t.firstChild);
			ttp.t.appendChild(document.createTextNode(s));
		}
		ttp.c = setTimeout("ttp.t.style.visibility = 'visible';", ttp.delay);
		ttp.g = true;
	},

	h: function(e){
		ttp.t.style.visibility = "hidden";
		if (!ttp.newline_entity && ttp.t.firstChild) ttp.t.removeChild(ttp.t.firstChild);
		clearTimeout(ttp.c);
		ttp.g = false;
		ttp.a(-99, -99);
	},

	l: function(o, e, a){
		if (o.addEventListener) o.addEventListener(e, a, false); // was true--Opera 7b workaround!
		else if (o.attachEvent) o.attachEvent("on" + e, a);
			else return null;
	},

	a: function(x, y){
		oCanvas = document.getElementsByTagName(
		(document.compatMode && document.compatMode == "CSS1Compat") ? "HTML" : "BODY"
		)[0];
		
		w_width = oCanvas.clientWidth ? oCanvas.clientWidth + oCanvas.scrollLeft : window.innerWidth + window.pageXOffset;
		w_height = window.innerHeight ? window.innerHeight + window.pageYOffset : oCanvas.clientHeight + oCanvas.scrollTop; // should be vice verca since Opera 7 is crazy!

		ttp.t.style.width = ((ttp.max_width) && (ttp.t.offsetWidth > ttp.max_width)) ? ttp.max_width + "px" : "auto";
		
		t_width = ttp.t.offsetWidth;
		t_height = ttp.t.offsetHeight;

		ttp.t.style.left = x + 8 + "px";
		ttp.t.style.top = y + 8 + "px";
		
		if (x + t_width > w_width) ttp.t.style.left = w_width - t_width + "px";
		if (y + t_height > w_height) ttp.t.style.top = w_height - t_height + "px";
	}
}

var root = window.addEventListener || window.attachEvent ? window : document.addEventListener ? document : null;
if (root){
	if (root.addEventListener) root.addEventListener("load", ttp.d, false);
	else if (root.attachEvent) root.attachEvent("onload", ttp.d);
}

function rr(date,prop_id)
{
    document.location = '/?op=rental_edit&arrive_date='+date+'&prop_id='+prop_id;
}

function reloadFresh()
{
    window.location=window.location+'&r='+Math.random();
}

function gTD(date,cx1,cx,prop_id)
{
    for(i=0;i<cx;i++)
    {
        id = parseInt(cx1)+i;
        if(id<10)id='0'+id;
        document.write("<TD><a href='/?op=rental_edit&arrive_date="+date+'-'+id+"&prop_id="+prop_id+"'>&curren;</a></TD>");
    }
}


function setDocumentCookie( sName, sValue )
{
    if ( sName.length < 1 )return;
    if ( 0 < sValue.length )
    {
        var expDate = new Date();
        expDate.setTime( expDate.getTime() + 365*24*60*60*1000 );
        document.cookie = ""
                        + sName + "=" + sValue + "; "
                        + "expires=" + expDate.toGMTString();
    }
    else
    {
        document.cookie = sName + "=";
    }
}
