﻿// JScript File
function doNop()
{
}
function toMoneyStr(d,p)
{
    if (d==0) return "";
    if (p==null) p=2;
    var f=new Number(Math.round(Math.pow(10,p)*d));
    var sgn="&nbsp;";
    if (f<0)
    {
        sgn="-";
        f=-1*f;
    }
    
    var s=f.toString();
    while (s.length<p+1) s="0"+s;
    
    var p2 = s.substr(s.length-p, p);
    var p1 = s.substr(0, s.length-p);
    var k = (p1.length%3);
    if (k==0) k=3;
    while (k<p1.length)
    {
        p1=p1.substr(0,k) + "," + p1.substr(k, p1.length-k);
        k+=4;
    }
    
    if (p1==""&&(p>0?"." + p2:"")=="") return "";
    return p1 + (p>0?"." + p2:"") + sgn;
}
function getIntVal(d)
{
    if (d==null) return 0;
    if (d=="") return 0;
    
    var ok=true,s=new String(d);
    for(var i=0;ok&&i<d.length;i++)
        ok=s.charAt(i)>='0'&&s.charAt(i)<='9'; 
    if (!ok) return null;
    return 1*s;       
}
function AgentName()
{
    var name="";
    try{name=navigator.userAgent.toLowerCase();}catch(e){name="";}	
    return new String(name);
}
function IsNetscape()
{
    return (AgentName().indexOf("netscape")>=0);
}
function IsSafari()
{
    return (AgentName().indexOf("safari")>=0);
}
function IsFireFox()
{
    return (AgentName().indexOf("firefox")>=0);
}
function IsOpera()
{
    return (AgentName().indexOf("opera")>=0);
}
function IsMac()
{
    return (AgentName().indexOf("mac")>=0);
}
function IsIE()
{
    return (document.all!=null&&!IsOpera()&&!IsSafari());
}
function IsIE7()
{
    return (IsIE()&&(AgentName().indexOf("msie 7")>=0));
}
function IsWin()
{
    return (AgentName().indexOf("win")>=0);
}
function NGTable(tableID)
{
    var p=new Object;
    p.ID=tableID;
    p.tbl=null;
    try {if (tableID.rows==null) p.tbl=document.getElementById(tableID); else p.tbl=tableID;} catch(e) {p.tbl=document.getElementById(tableID);}
    p.rowVisible=function(rowIndex,visible)
    {
        this.tbl.rows[rowIndex].style.display=(visible?"":"none");
    }
    p.rowVisiblity=function(rowIndex)
    {
        return (this.tbl.rows[rowIndex].style.display!="none"?true:false);
    }
    p.rowCount=function()
    {
        return this.tbl.rows.length;
    }
    p.Row=function(rowIndex)
    {
        return this.tbl.rows[rowIndex];
    }
    p.getRowWithValue=function(tagName,tagValue)
    {
        for(var i=0;i<this.rowCount();i++)
        {
            var row=this.Row(i);
            if (row.getAttribute(tagName)!=null&&
                row.getAttribute(tagName)==tagValue)
                return row;
        }
        
        return null;
    }
    p.Cell=function(rowIndex,cellIndex)
    {
        var row=this.Row(rowIndex);
        return row.cells[cellIndex];
    }
    p.insertRow=function(index)
    {
        return this.tbl.insertRow(index);
    }
    p.insertCell=function(row,innerHTML)
    {
        var cell=row.insertCell(row.cells.length);
        cell.innerHTML=innerHTML;
        
        return cell;
    }
    p.deleteRow=function(rowIndex)
    {
        if (this.rowCount()>rowIndex) 
            this.tbl.deleteRow(rowIndex);
    }
    return p;
}
//
// HashTable
//
function hashNode(key,data)
 {
    var p=new Object;
    
    p.link=new Array(2);
    p.link[0]=null; p.link[1]=null;
    p.key=key;
    p.data=data;
	p.balance=0;
	
	return p;
}
function hashTraverser()
{
    var p=new Object;
    p.node=null;
    p.stack=new Array(128);
    for(var i=0;i<128;i++)
        p.stack[i]=null;
    
    p.height=0;
	p.generation=0;
	
	p.clear=function(){
        this.node=null;
        for(var i=0;i<128;i++)
            this.stack[i]=null;
        
        this.height=0;
	    this.generation=0;
	}
	
    return p;		
}
function hashTable()
{
    var p=new Object;
	p.trav=hashTraverser();

    p.root=null;
    p.count=0;
    p.generation=0;

    p.compare=function(key1,key2){
        if (key1>key2) return 1;
        else if (key1<key2) return -1;
        return 0;
    }
    p.get=function(key){
	    var p, cmp;
	    for(p=this.root;p!=null;){
		    cmp = this.compare(key, p.key);
		    if (cmp<0) p=p.link[0];
		    else if (cmp>0) p=p.link[1];
		    else 
		        return p.data;
	    }

	    return null;
    }
    p.replace=function(key,data){
	    var p, cmp;
	    for(p=this.root;p!=null;){
		    cmp = this.compare(key, p.key);
		    if (cmp<0) p=p.link[0];
		    else if (cmp>0) p=p.link[1];
		    else{
		        p.data=data;
		        return true;
		    }
	    }
	    
	    return false;
    }
    p.add=function(key,data){
	    if (this.count==0){
		    this.root=hashNode(key, data);
		    this.count++;
		    return true;
	    }

        var k=0,da=new Array(128);
        var dir=0,y=this.root,z=null,p=this.root,q=null,n,w;
        while (p!=null){
            var cmp=this.compare(key,p.key);
            if (cmp==0) return p.data;

            if (p.balance!=0){
                z=q;
                y=p;
                k=0;
            }
          
            dir=(cmp>0?1:0);
            da[k++]=dir;
          
            q=p;
            p=p.link[dir];
        }
        n=hashNode(key, data); 
        q.link[dir]=n;
        this.count++;
        if (y==null) return data;
        p=y;
        for (k=0;p.key!=n.key;k++){
            if (da[k]==0) p.balance--;
            else p.balance++;
            p=p.link[da[k]];
        }
        if (y.balance==-2){
            var x=y.link[0];
            if (x.balance==-1){
                w=x;
                y.link[0]=x.link[1];
                x.link[1]=y;
                x.balance=0;
                y.balance=0;
            }
            else{
                w=x.link[1];
                x.link[1]=w.link[0];
                w.link[0]=x;
                y.link[0]=w.link[1];
                w.link[1]=y;
                if (w.balance==-1){
                    x.balance=0;
                    y.balance=1;
                }
                else if (w.balance==0){
                    x.balance=0;
                    y.balance=0;
                }
                else{
                    x.balance=-1;
                    y.balance=0;
                }
                w.balance = 0;
            }
        }
        else if (y.balance==2){
            var x=y.link[1];
            if (x.balance==1){
                w=x;
                y.link[1]=x.link[0];
                x.link[0]=y;
                x.balance=0;
                y.balance=0;
            }
            else{
                w=x.link[0];
                x.link[0]=w.link[1];
                w.link[1]=x;
                y.link[1]=w.link[0];
                w.link[0]=y;
                if (w.balance==1){
                    x.balance=0;
                    y.balance=-1;
                }
                else if (w.balance==0){
                    x.balance=0;
                    y.balance=0;
                }
                else{
                    x.balance=1;
                    y.balance=0;
                }
                w.balance=0;
            }
        }
        else
            return data;
            
        if (z==null) this.root=w;    
        else z.link[(y.key!=z.link[0].key?1:0)]=w;

        this.generation++;
        return data;
    }
    p.getCountSub=function(q){
	    if (q == null) return 0;
	    var i = 1 + this.getCountSub(q.link[0]) + this.getCountSub(q.link[1]);
	    return i;
    }
    p.getCount=function(){
	    return this.getCountSub(this.root);
    }
    p.del=function(key){
	    if (!this.root) return false;
	    var k=0,cmp,pa=new Array(128),da=new Array(128),p=this.root;
	    while (true){
            cmp=this.compare(key,p.key);
            if (cmp==0) break;
		    var dir=(cmp>0?1:0);
		    pa[k]=p;
		    da[k++]=dir;
		    p=p.link[dir];
		    if (p==null) return false;
	    }
        if (p.link[1]==null){
            if (k==0) this.root=p.link[0];
            else pa[k-1].link[da[k-1]]=p.link[0];
        }
        else{
            var r=p.link[1];
            if (r.link[0]==null){
                r.link[0]=p.link[0];
                r.balance=p.balance;
                if (k==0) this.root=r;
                else pa[k-1].link[da[k-1]]=r;
                da[k]=1;
                pa[k++]=r;
            }
            else
            {
                var s,j=k++;
                while (true){
                    da[k]=0;
                    pa[k++]=r;
                    s=r.link[0];
                    if (s.link[0]==null)
                        break;
                    r = s;
                }

                s.link[0]=p.link[0];
                r.link[0]=s.link[1];
                s.link[1]=p.link[1];
                s.balance=p.balance;

                if (j==0) this.root=s;
                else pa[j-1].link[da[j- 1]]=s;
                da[j]=1;
                pa[j]=s;
            }
        }

        while (--k>0){
            var y=pa[k];
            if (da[k]==0){
                y.balance++;
                if (y.balance==1) break;
                else if (y.balance==2){
                    var x=y.link[1];
                    if (x.balance==-1){
                        var w;
                        w=x.link[0];
                        x.link[0]=w.link[1];
                        w.link[1]=x;
                        y.link[1]=w.link[0];
                        w.link[0]=y;
                        if (w.balance==1){
                            x.balance=0; 
                            y.balance=-1;
                        }
                        else if (w.balance==0){
                            x.balance=0;
                            y.balance=0;
                        }
                        else{
                            x.balance=1;
                            y.balance=0;
                        }
                        w.balance=0;
                        if (k==0) this.root=w;
                        else pa[k-1].link[da[k-1]]=w;
                    }
                    else{
                        y.link[1]=x.link[0];
                        x.link[0]=y;
                        if (k==0) this.root=x;
                        else pa[k-1].link[da[k-1]] = x;
                        if (x.balance == 0){
                            x.balance=-1;
                            y.balance=1;
                            break;
                        }
                        else{
                            x.balance=0;
                            y.balance=0;
                        }
                    }
                }
            }   
            else{
                y.balance--;
                if (y.balance==-1) break;
                else if (y.balance==-2){
                    var x = y.link[0];
                    if (x.balance==1){
                        var w=x.link[1];
                        x.link[1]=w.link[0];
                        w.link[0]=x;
                        y.link[0]=w.link[1];
                        w.link[1]=y;
                        if (w.balance==-1){
                            x.balance=0;
                            y.balance=1;
                        }
                        else if (w.balance==0){
                            x.balance=0;
                            y.balance=0;
                        }
                        else{
                            x.balance=-1;
                            y.balance=0;
                        }
                        w.balance=0;
                        if (k==0) this.root=w;
                        else pa[k-1].link[da[k-1]]=w;
                    }
                    else{
                        y.link[0]=x.link[1];
                        x.link[1]=y;
                        if (k==0) this.root=x;
                        else pa[k-1].link[da[k-1]]=x;
                        if (x.balance == 0){
                            x.balance=1;
                            y.balance=-1;
                            break;
                        }
                        else{
                            x.balance=0;
                            y.balance=0;
                        }
                    }
                }
            }
        }

        this.count--;
        this.generation++;

	    return true;
    }
    p.findFirst=function(){
	    this.trav.height = 0;
	    this.trav.generation = this.generation;

	    var x = this.root;
	    if (x != null)
		    while (x.link[0]!=null){
	            this.trav.stack[this.trav.height++] = x;
			    x = x.link[0];
		    }

	    this.trav.node = x;

	    return (x != null ? x.data : null);
    }
    p.findLast=function(){
	    this.trav.height = 0;
	    this.trav.generation = this.generation;

	    var x = this.root;
	    if (x != null)
		    while (x.link[1] != null){
	            this.trav.stack[this.trav.height++] = x;
			    x = x.link[1];
		    }

	    this.trav.node = x;

	    return (x != null ? x.data : null);
    }
    p.findFirstWithKey=function(key){
	    var p, q;

	    this.trav.height = 0;
	    this.trav.generation = this.generation;
	    for (p = this.root; p != null; p = q){
		    var cmp = this.compare(key, p.key);
		    if (cmp < 0) q = p.link[0];
		    else if (cmp > 0) q = p.link[1];
		    else{
			    this.trav.node = p;
			    return p.data;
            }

		    this.trav.stack[this.trav.height++] = p;
        }

	    this.trav.height = 0;
	    this.trav.node = null;

	    return null;
    }
    p.next=function(){
	    if (this.trav.generation != this.generation)
		    this.trav_refresh();

	    var x = this.trav.node;
	    if (x == null)
		    return this.findFirst();
	    else if (x.link[1] != null){
		    this.trav.stack[this.trav.height++] = x;
		    x = x.link[1];
		    while (x.link[0] != null){
			    this.trav.stack[this.trav.height++] = x;
			    x = x.link[0];
            }
        }
	    else{
		    var y;

		    do{
			    if (this.trav.height == 0){
				    this.trav.node = null;
				    return null;
                }

			    y = x;
			    x = this.trav.stack[--this.trav.height];
            }
		    while (y == x.link[1]);
        }

	    this.trav.node = x;

	    return x.data;
    }
    p.prev=function(){
	    if (this.trav.generation != this.generation)
		    this.trav_refresh();

	    var x = this.trav.node;
	    if (x == null)
		    return this.findLast();
	    else if (x.link[0] != null){
		    this.trav.stack[this.trav.height++] = x;
		    x = x.link[0];

		    while (x.link[1] != null){
			    this.trav.stack[this.trav.height++] = x;
			    x = x.link[1];
            }
        }
	    else{
		    var y;

		    do{
			    if (this.trav.height == 0){
				    this.trav.node = null;
				    return null;
                }

			    y = x;
			    x = this.trav.stack[--this.trav.height];
            }
		    while (y == x.link[0]);
        }
      
	    this.trav.node = x;

	    return x.data;
    }
    p.trav_refresh=function(){
	    this.trav.generation = this.generation;

	    if (this.trav.node != null){
		    var node = this.trav.node, i;

		    this.trav.height = 0;
		    for (i = this.root; i != node; ){
			    this.trav.stack[this.trav.height++] = i;
			    i = i.link[(this.compare(node.key, i.key) > 0?1:0)];
            }
        }
    }
    p.clear=function(){
	    this.count = 0;
	    this.generation=0;
	    this.root = null;
        this.trav.clear();
    }
        
    return p;
}
//
// arrayList
//
function arrayList()
{
    var tbl=new Object;
    tbl.items=null;
    
    tbl.clear=function()
    {
        this.items=null;
    }
    tbl.add=function(value)
    {
        var itm=new Object;
        itm.value=value;
        itm.next=null;
        
        if (this.items==null) this.items=itm;
        else
        {
            var i=this.items;
            while (i.next!=null)
                i=i.next;
                
            i.next=itm;
        }
    }
    tbl.count=function()
    {
        var i=0,itm=this.items;
        while(itm!=null)
        {
            i++;
            itm=itm.next;
        }
        
        return i;
    }
    tbl.item=function(i)
    {
        var itm=this.items;
        while(itm!=null)
        {
            if (i==0) return itm.value;
            i--;
            itm=itm.next;
        }
        
        return null;
    }
    tbl.removeAt=function(i)
    {
        var pitm=null,itm=this.items;
        while(itm!=null)
        {
            if (i==0)
            {
                if (pitm==null) this.items=itm.next;
                else pitm.next=itm.next;
                return itm.value;
            }
            
            i--;
            pitm=itm;
            itm=itm.next;
        }
        
        return null;
    }
    tbl.clear=function()
    {
        this.items=null;
    }
        
    return tbl;
}
function callSearchForm(xml)
{
    var f=document.createElement("form");
    f.method="POST";
    f.action="search.aspx";
    document.body.appendChild(f);

    var x=document.createElement("input");
    x.name="prms";
    x.type="hidden";
    x.value=xml;
    f.appendChild(x);

    f.submit();    
}
function callSearchForm2(id,d)
{
    var f=document.createElement("form");
    f.method="POST";
    f.action="search.aspx";
    document.body.appendChild(f);

    var x=document.createElement("input");
    x.name="id";
    x.type="hidden";
    x.value=id;
    f.appendChild(x);

    x=document.createElement("input");
    x.name="d";
    x.type="hidden";
    x.value=d;
    f.appendChild(x);

    f.submit();    
}
function callSearchForm21(id,d,data)
{
    var f=document.createElement("form");
    f.method="POST";
    f.action="search.aspx";
    document.body.appendChild(f);

    var x=document.createElement("input");
    x.name="id";
    x.type="hidden";
    x.value=id;
    f.appendChild(x);

    x=document.createElement("input");
    x.name="d";
    x.type="hidden";
    x.value=d;
    f.appendChild(x);

    x=document.createElement("input");
    x.name="dd2";
    x.type="hidden";
    x.value=data;
    f.appendChild(x);

    f.submit();    
}
function callSearchForm3(id,hotelCode,xml)
{
    var f=document.createElement("form");
    f.method="POST";
    f.action="search.aspx";
    document.body.appendChild(f);

    var x=document.createElement("input");
    x.name="id";
    x.type="hidden";
    x.value=id;
    f.appendChild(x);

    x=document.createElement("input");
    x.name="hotel";
    x.type="hidden";
    x.value=hotelCode;
    f.appendChild(x);

    x=document.createElement("input");
    x.name="xml";
    x.type="hidden";
    x.value=xml;
    f.appendChild(x);

    f.submit();    
}
function windowWidth()
{
    var w = 1 * 24;
    if (IsIE() && !IsOpera()) w = document.documentElement.clientWidth;
    else if (IsOpera()) w = document.body.clientWidth;
    else w = window.innerWidth;

    return w;
}
function documentWidth()
{
    var w=1024;
    if (IsIE()||IsOpera())
        w=document.documentElement.scrollWidth;
    else
        w=document.width;

    return w;
}
function windowHeight()
{
    var h=768;
    if (IsIE()) h=document.documentElement.clientHeight;
    else h=window.innerHeight;

    return h;
}
function documentHeight()
{
    var h=768;
    if (IsIE()||IsOpera())
        h=document.documentElement.scrollHeight;
    else
        h=document.height;

    return h;
}
function documentTop()
{
    if (IsIE()||IsOpera()||IsFireFox())
        return document.documentElement.scrollTop;
    else
        return document.body.scrollTop;
}
function documentLeft()
{
    if (IsIE()||IsOpera()||IsFireFox())
        return document.documentElement.scrollLeft;
    else
        return document.body.scrollLeft;
}
function trimStr(s)
{
    var str=new String(s);
    while(str.length>0&&str.charAt(0)==' ')
        str=str.substr(1, str.length-1);
    while(str.length>0&&str.charAt(str.length-1)==' ')
        str=str.substr(0, str.length-1);

    return str;        
}
function trimCtlValue(elm)
{
    var s="";
    if (elm.value!=null) s=elm.value;
    return trimStr(s);
}
