var languageParamValue,themeParamValue, firstDayOfWeek=1;
var daysNames;
var monthsNames;
var dateFormat="dd/MM/yyyy";
var isYearBeforeMonth=false;

function FormatDate(date)
{
    if(date==null)return "";
    var longYear=date.getYear();
    if(longYear<1000)longYear+=1900;
    var shortYear=longYear;
    while(shortYear>1000)
        shortYear-=1000;
    var month=date.getMonth()+1;
    if(month<10)month="0"+month;
    var day=date.getDate();
    if(day<10)day="0"+day;
    return dateFormat.replace(/yyyy/g,longYear).replace(/yy/g,shortYear).replace(/MM/g,month).replace(/M/g,date.getMonth()).replace(/dd/g,day).replace(/d/g,date.getDate());
}



function TruncDate(date)
{//Remove the time part of a date
    var result=new Date();
    result.setTime(date.getTime());
    result.setHours(0,0,0,0);
    return result;
}
function FormatDateIso(date)
{
    if(!date)return "";
    var longYear=date.getYear();
    if(longYear<1000)longYear+=1900;
    var month=date.getMonth()+1;
    if(month<10)month="0"+month;
    var day=date.getDate();
    if(day<10)day="0"+day;
    return longYear+""+month+""+day;
}
function Unselectable(dom)
{
dom.unselectable="on";
AddClass(dom,"unselectable");
}

var Shadow=function(dom,doNotChangeParent)
{
var parent=dom.parentElement||dom.parentNode;
if(!doNotChangeParent)
{
 parent.style.visibility="hidden";
 parent.style.display="block";
}
var sh=document.createElement("div");
sh.className="shadow";
var iIc=['xst','xsc','xsb'],jIc=['l','c','r'];
this.widthers=[];
this.heighters=[];
var inc,inc2;
for(var iI=0;iI<iIc.length;iI++)
{
    inc=document.createElement("div");
    sh.appendChild(inc);
    inc.className=iIc[iI];
    if(inc.className=="xsc")
    {
        inc.style.height=Math.max(0,(parent.clientHeight||dom.clientHeight)-12)+"px";
	this.heighters.push(inc);
    }
    for(var jI=0;jI<jIc.length;jI++)
    {
        inc2=document.createElement("div");
        inc2.className=inc.className+jIc[jI];
        inc.appendChild(inc2);
        if(jIc[jI]=='c'){inc2.style.width=dom.clientWidth+"px";this.widthers.push(inc2)}
    }
}
sh.style.width=(dom.clientWidth+12)+"px";
sh.style.height=(parent.clientHeight||dom.clientHeight)+"px";
this.sh=sh;
parent.insertBefore(sh,dom);
if(!doNotChangeParent)
{
  parent.style.display="none";
  parent.style.visibility="visible";
}
}
Shadow.prototype=
{
	widthers:null,heighters:null,
	SetSize:function(width,height)
	{
		this.sh.style.width=(width+12)+"px";
		this.sh.style.height=height+"px";
		for(var wI=0;wI<this.widthers.length;wI++)this.widthers[wI].style.width=width+"px";
		for(var wI=0;wI<this.heighters.length;wI++)this.heighters[wI].style.height=(height-12)+"px";
	}
}




var today=TruncDate(new Date());

var Calendar=function(textBox,icon, container, options, displayedDate)
{
    if(options && options.numberOfMonths)this.NumberOfMonthsDisplayed=options.numberOfMonths;
    var table=document.createElement("table");
    table.cellSpacing=0;
    table.style.position="absolute";
    table.style.zIndex=2;
    
    this.monthLabelRow=table.insertRow(-1);
    this.monthLabelRow.className="months";
    for(var monthShift=0;monthShift<this.NumberOfMonthsDisplayed;monthShift++)
    {
        if(monthShift>0)
            this.monthLabelRow.insertCell(-1);//Separation
        this.monthLabelRow.insertCell(-1);
        this.monthLabelRow.insertCell(-1).colSpan=5;
        this.monthLabelRow.insertCell(-1);
    }

    this.daysLabelRow=table.insertRow(-1);
    this.daysLabelRow.className="days";

    this.daysRows=new Object();
    this.daysRows[0]=table.insertRow(-1);
    this.daysRows[1]=table.insertRow(-1);
    this.daysRows[2]=table.insertRow(-1);
    this.daysRows[3]=table.insertRow(-1);
    this.daysRows[4]=table.insertRow(-1);
    this.daysRows[5]=table.insertRow(-1);

    var cellWidth=(100.0/this.NumberOfMonthsDisplayed/(7+1/3))+"%";
    var dcell;

    for(var monthShift=0;monthShift<this.NumberOfMonthsDisplayed;monthShift++)
    {
        if(monthShift>0)
        {
            var sepCell=this.daysLabelRow.insertCell(-1);
            sepCell.width=(100.0/this.NumberOfMonthsDisplayed/(7+1/3)/3)+"%";
            sepCell.innerHTML="&nbsp;";
            Unselectable(sepCell);
		    for(var weekI=0;weekI<6;weekI++)
		    {
			    dcell=this.daysRows[weekI].insertCell(-1);
		SetHandler(dcell,"mouseover",CreateDelegate(this.OnDayOver,this,[dcell]));
		SetHandler(dcell,"mouseout",CreateDelegate(this.OnDayOut,this,[dcell]));
		    }
        }
	    for(var d=1;d<=7;d++)
	    {
		    var dayCell=this.daysLabelRow.insertCell(-1);
		    dayCell.innerHTML=daysNames[(d+firstDayOfWeek-1)%7];
		    dayCell.width=cellWidth;
			Unselectable(dayCell);

		    for(var weekI=0;weekI<6;weekI++)
		    {
				dcell=this.daysRows[weekI].insertCell(-1);
				Unselectable(dcell);
				SetHandler(dcell,"mouseover",CreateDelegate(this.OnDayOver,this,[dcell]));
				SetHandler(dcell,"mouseout",CreateDelegate(this.OnDayOut,this,[dcell]));
		    }
	    }
    }
    this.Container=container;
    this.TextBox=textBox;
    container.appendChild(table);
    if(options)
    {
        this.OnDateDisplayed=options.ondisplaydate;
        if(options.cannotbrowse)this.CanBrowse=!options.cannotbrowse;
        this.CanBrowseBeforeToday=options.canbrowsebeforetoday;
    }
    if(!displayedDate)displayedDate=TruncDate(new Date()).getTime()+24*60*60*1000;
    var fn=CreateDelegate(this.Open,this);
    SetHandler(icon,"click",fn);
    SetHandler(textBox,"click",fn);
    SetHandler(textBox,"focus",fn);
    fn=CreateDelegate(this.Close,this);
    SetHandler(document.body,"click",fn);
    closeControlsHandlers.push(fn);
    if(!displayedDate)displayedDate=TruncDate(new Date()).getTime()+24*60*60*1000;
    this.Refresh(displayedDate);
    new Shadow(table);
    SetHandler(table,"click",CreateDelegate(this.OnClick,this));
}
var closeControlsHandlers=[];
function CloseControls()
{
for(var fnI=0;fnI<closeControlsHandlers.length;fnI++)closeControlsHandlers[fnI]();
}
Calendar.prototype=
{
    NumberOfMonthsDisplayed:1,
    OnDateDisplayed:null,
    CanBrowse:true,
    CanBrowseBeforeToday:false,
    OnDayOver:function(cell)
    {
	AddClass(cell,"over");
    },
    OnDayOut:function(cell)
    {
	RemoveClass(cell,"over");
    },
    Open:function(e)
    {
        CloseControls();
        this.Refresh(ParseDate(this.TextBox.value));
        this.Container.style.display="block";
        if (!e)e = window.event;
        e.cancelBubble=true;
        return false;
    },
    OnClick:function(e)
    {
        if (!e)e = window.event;
        e.cancelBubble=true;
        return false;
    },
    Close:function()
    {
        this.Container.style.display="none";
    },
    NextMonth:function(e)
    {
    	this.displayedDate=new Date(this.displayedDate);
	    this.displayedDate.setDate(15);
	    this.displayedDate=new Date(this.displayedDate.getTime()+20*24*60*60*1000);
	    this.displayedDate.setDate(15);
	    this.Refresh();
        if (!e)e = window.event;
        e.cancelBubble=true;
        return false;
    },
    PreviousMonth:function(e)
    {
	    this.displayedDate=new Date(this.displayedDate);
	    this.displayedDate.setDate(15);
	    this.displayedDate=new Date(this.displayedDate.getTime()-20*24*60*60*1000);
	    this.displayedDate.setDate(15);
	    this.Refresh();
        if (!e)e = window.event;
        e.cancelBubble=true;
        return false;
    },
    OnDateClick:function(cell)
    {
	var otherBox=null;
	if(this.TextBox.id=="qbArrv")
	{
		otherBox=document.getElementById("qbDept");
		try{var otherDate=ParseDate(otherBox.value);
		var previousDate=ParseDate(this.TextBox.value);
		if(otherDate!=null)
		{
			otherBox.value=FormatDate(new Date(cell.date.getTime()-previousDate.getTime()+otherDate.getTime()));
		}
		}catch(ex){}
	}
	if(this.TextBox.id=="qbDept")
	{
		otherBox=document.getElementById("qbArrv");
		try{var otherDate=ParseDate(otherBox.value);
		if(otherDate!=null && TruncDate(otherDate)>=TruncDate(cell.date))
		{
			otherBox.value=FormatDate(new Date(cell.date.getTime()-1*24*3600000));
		}
		}catch(ex){}
	}
        this.TextBox.value=FormatDate(cell.date);
        this.Close();
    },
    IsDateVisible:function(date)
    {
        if(!this.displayedDate)return false;
	    var firstDisplayedDate=new Date(this.displayedDate.getTime()+20*24*60*60*1000);
	    firstDisplayedDate.setDate(1);
	    var lastDisplayedDateExcluded=new Date(this.displayedDate.getTime()+(30.5*this.NumberOfMonthsDisplayed+20)*24*60*60*1000);
	    lastDisplayedDateExcluded.setDate(1);
	    return date.getTime()>=firstDisplayedDate.getTime() && date.getTime()<=lastDisplayedDateExcluded.getTime();
    },
    EnsureDateIsVisible:function(date)
    {
        if(this.IsDateVisible(date))
            this.Refresh();
        else
            this.Refresh(date);
    },
    Refresh:function(displayedDateAtLeft)
    {
	var selectedDate=null;
        if(!displayedDateAtLeft)displayedDateAtLeft=this.displayedDate;
	else{selectedDate=new Date(displayedDateAtLeft);selectedDate.setHours(0,0,0,0);selectedDate=selectedDate.getTime()}
    	this.displayedDate=new Date(displayedDateAtLeft);
	    this.displayedDate.setDate(15);
	    this.displayedDate.setHours(0,0,0,0);//Remove the time component

	    for(var monthShift=0;monthShift<this.NumberOfMonthsDisplayed;monthShift++)
	    {
		    var firstDisplayedDate=new Date(this.displayedDate.getTime()+monthShift*20*24*60*60*1000);
		    firstDisplayedDate.setDate(1);
		    var year = (firstDisplayedDate.getYear() < 1000) ? firstDisplayedDate.getYear()+ 1900 :firstDisplayedDate.getYear();
		    var monthCell=this.monthLabelRow.cells[monthShift*4+1];
		    if(isYearBeforeMonth)
		    {
		        if(cultureCode=="ja-jp")
    		        monthCell.innerHTML=year+"? "+monthsNames[firstDisplayedDate.getMonth()];
		        else
    		        monthCell.innerHTML=year+" "+monthsNames[firstDisplayedDate.getMonth()];
		    }
		    else
		    {
		        monthCell.innerHTML=monthsNames[firstDisplayedDate.getMonth()]+" "+year;
		    }
		    monthCell.style.textAlign="center";
	        var previousCell=this.monthLabelRow.cells[monthShift*4];
	        previousCell.innerHTML="";
		    if(monthShift==0 && this.CanBrowse && (this.CanBrowseBeforeToday || firstDisplayedDate.getTime()-(24*60*60*1000)>new Date()) )
		    {//Add the previous month link
		        var previous=document.createElement("div");
		        previous.innerHTML="&lt;";
		        previousCell.appendChild(previous);
		        try{previousCell.style.cursor="pointer";}catch(e){}
		        previousCell.onclick=CreateDelegate(this.PreviousMonth,this);
		    }
		    else
		    {
		        previousCell.onclick=null;
		        try{previousCell.style.cursor="default";}catch(e){}
		    }
		    if(monthShift==this.NumberOfMonthsDisplayed-1 && this.CanBrowse)
		    {//Add the next month link
		        var next=document.createElement("div");
		        next.innerHTML="&gt;";
		        var nextCell=this.monthLabelRow.cells[monthShift*4+2];
		        nextCell.innerHTML="";
		        nextCell.appendChild(next);
		        try{nextCell.style.cursor="pointer";}catch(e){}
		        nextCell.onclick=CreateDelegate(this.NextMonth,this);
		    }
		    if(firstDisplayedDate.getDay()!=firstDayOfWeek)
		    {//Go to the first day of the week that is before the first day of the month
			    if(firstDisplayedDate.getDay()==((firstDayOfWeek+6)%7))
				    firstDisplayedDate.setDate(firstDisplayedDate.getDate()-((7-firstDayOfWeek)));
			    else
				    firstDisplayedDate.setDate(firstDisplayedDate.getDate()- (firstDisplayedDate.getDay()-firstDayOfWeek));
		    }
		    firstDisplayedDate.setHours(0,0,0,0);
		    for(var d=1;d<=7;d++)
		    {
			    for(var weekI=0;weekI<6;weekI++)
			    {
				    var cell=this.daysRows[weekI].cells[d-1+monthShift*8];
				    var cellDate=new Date(firstDisplayedDate.getTime());
				    cellDate.setDate(cellDate.getDate() + (weekI*7 + d-1));
				    cellDate.setHours(0,0,0,0);
				    var cellIsEmpty=false;
				    if(cellDate.getMonth()!=(this.displayedDate.getMonth()+monthShift)%12)
				    {
					    cell.className="unselectable otherMonth";
					    if(cellDate.getMonth()==(this.displayedDate.getMonth()+monthShift+11)%12 && monthShift!=0)
					        cellIsEmpty=true;//Previous month
					    if(cellDate.getMonth()==(this.displayedDate.getMonth()+monthShift+1)%12 && monthShift!=this.NumberOfMonthsDisplayed-1)
					        cellIsEmpty=true;//Next month
				    }
				    else
					    cell.className="unselectable";
				    if(!cellIsEmpty)
					    cell.innerHTML=cellDate.getDate();
				    else
					    cell.innerHTML="";
    				    try{cell.style.cursor="default";}catch(e){}
				    if(this.OnDateDisplayed && !cellIsEmpty)
				    {
				        cell.inactive=null;
					cellDate.setHours(0,0,0,0);
				        this.OnDateDisplayed(cellDate,cell,d,weekI);
				    }
		                    if(cell.fn){RemoveHandler(cell,"click",cell.fn);cell.fn=null;}
				    if(cellDate.getTime()>=today.getTime())
				    {
			                    if(!cellIsEmpty && cell.inactive==null)
			                    {
			                        cell.fn=CreateDelegate(this.OnDateClick,this,[cell]);
		        	                try{cell.style.cursor="pointer";}catch(e){}
		                	        cell.date=cellDate;
			                        SetHandler(cell,"click",cell.fn);
        	        		    }
				    }
				    else
					cell.className+=" beforeToday";
				   var wkD=cellDate.getDay();
				   if(wkD==0 || wkD==6)cell.className+=" weekend";
				   if(selectedDate && selectedDate==cellDate.getTime())cell.className+=" selected";
				}
		    }
	    }
    }
}


function ParseDate(dateAsString)
{
    if(!dateAsString || dateAsString.length==0)return null;
    var dfy,dfm,dfd;
    if(dateAsString && dateAsString.length==6 || dateAsString.length==8)
    { //format ddmmyy
        dfy="^"+ dateFormat.replace(/dd/g,"d").replace(/d/gi,"\\d?\\d").replace(/yyyy/g,"((?:\\d\\d)?\\d\\d)").replace(/yy/g,"(\\d\\d)").replace(/mm/gi,"\\d?\\d").replace(/m/gi,"\\d").replace(/\//g,"") + "$";
        dfm="^"+ dateFormat.replace(/dd/g,"d").replace(/d/gi,"\\d?\\d").replace(/yyyy/g,"(?:\\d\\d)?\\d\\d").replace(/yy/g,"\\d\\d").replace(/mm/gi,"(\\d?\\d)").replace(/m/gi,"(\\d)").replace(/\//g,"") + "$";
        dfd="^"+ dateFormat.replace(/dd/g,"d").replace(/d/gi,"(\\d?\\d)").replace(/yyyy/g,"(?:\\d\\d)?\\d\\d").replace(/yy/g,"\\d\\d").replace(/mm/gi,"\\d?\\d").replace(/m/gi,"\\d").replace(/\//g,"") + "$";
    }
    else
    {
        dfy="^"+ dateFormat.replace(/dd/g,"d").replace(/d/gi,"\\d?\\d").replace(/yyyy/g,"((?:\\d\\d)?\\d\\d)").replace(/yy/g,"(\\d\\d)").replace(/mm/gi,"\\d?\\d").replace(/m/gi,"\\d") + "$";
        dfm="^"+ dateFormat.replace(/dd/g,"d").replace(/d/gi,"\\d?\\d").replace(/yyyy/g,"(?:\\d\\d)?\\d\\d").replace(/yy/g,"\\d\\d").replace(/mm/gi,"(\\d?\\d)").replace(/m/gi,"(\\d)") + "$";
        dfd="^"+ dateFormat.replace(/dd/g,"d").replace(/d/gi,"(\\d?\\d)").replace(/yyyy/g,"(?:\\d\\d)?\\d\\d").replace(/yy/g,"\\d\\d").replace(/mm/gi,"\\d?\\d").replace(/m/gi,"\\d") + "$";
    }
    var dateFormatRegExYear=new RegExp(dfy,"g");
    var dateFormatRegExMonth=new RegExp(dfm,"g");
    var dateFormatRegExDay=new RegExp(dfd,"g");
    var yRes=dateFormatRegExYear.exec(dateAsString);
    var mRes=dateFormatRegExMonth.exec(dateAsString);
    var dRes=dateFormatRegExDay.exec(dateAsString);
    if(yRes!=null && mRes!=null && dRes!=null)
    {
        try
        {
        var date=new Date();
        var year=parseInt(yRes[1],10);
        if(year<100)year=year+2000;
        date.setFullYear(year,parseInt(mRes[1],10)-1,parseInt(dRes[1],10));
        date.setHours(0, 0, 0, 0);
        return date;
        }catch(e){return null;}
    }
    else
        return null;
}


function DropdownInformation(rootId, newwidth, data) {
    var list = document.getElementById(rootId + "List");
    var options = document.getElementById(rootId + "Options");
    if (!options) return;
    if (newwidth != null)
        options.style.width = newwidth + "px";


    optionItem = document.createElement("div");
    optionItem.className = "info";
    var option = document.createElement("div");
    optionItem.appendChild(option);
    var dataElement = data;
    option.innerHTML = dataElement;

    options.appendChild(optionItem);


    var parent = options.parentElement || options.parentNode;
    for (var ci = 0; ci < parent.childNodes.length; ci++) {
        var ch = parent.childNodes[ci];
        if (ch.className == "shadow") {
            ch.style.display = "none";
            break;
        }
    }
    new Shadow(options);
}

var Dropdown=function(rootId,onclick,data)
{
    var list=document.getElementById(rootId+"List");
    var options=document.getElementById(rootId+"Options");
    if(!options)
    {
	options=document.createElement("div");
	options.id=rootId+"Options";
	options.className="dropdownOptions";
	(list.parentElement||list.parentNode).appendChild(options);
	options.style.width=list.style.width;
    }
    options.style.visibility="hidden";

    var optionsAndShadow=document.createElement("div");
    var optionsParent=options.parentElement||options.parentNode;
    optionsParent.replaceChild(optionsAndShadow,options);
    optionsAndShadow.appendChild(options);
    optionsAndShadow.style.width=options.style.width;
    SetHandler(list,"click", CreateDelegate(this.Toggle,this));
    this.TextCtrl=null;
    for(var ci=0;ci<list.childNodes.length;ci++)
    {
        var ch=list.childNodes[ci];
        if(ch.className=="sel")
	{
		this.TextCtrl=ch;
        	ch.style.width=(list.clientWidth-24)+"px";
		break;
	}
    }

    var ch;
    for(var ci=0;ci<options.childNodes.length;ci++)
    {
        ch=options.childNodes[ci];
        if(ch.className=="item")
        {
		SetHandler(ch,"mouseover",CreateDelegate(this.OnItemOver,this,[ch]));
		SetHandler(ch,"mouseout",CreateDelegate(this.OnItemOut,this,[ch]));
		if(onclick)
			SetHandler(ch,"click",CreateDelegate(this.OnItemClick,this,[ch,onclick]));
        }
    }
    if(typeof(data)=='object')
    {//An array
	var optionItem;
	for(var dI=0;dI<data.length;dI++)
	{
		optionItem=document.createElement("div");
		optionItem.className="item";
		var option=document.createElement("div");
		optionItem.appendChild(option);
		var dataElement=data[dI];
		if(typeof(dataElement)=="object")
		{//Sub array
			optionItem.value=dataElement[0];
			option.innerHTML=dataElement[1];
		}
		else
		{
			optionItem.value=dataElement;
			option.innerHTML=dataElement;
		}
		options.appendChild(optionItem);
		Unselectable(option);
		SetHandler(optionItem,"mouseover",CreateDelegate(this.OnItemOver,this,[optionItem]));
		SetHandler(optionItem,"mouseout",CreateDelegate(this.OnItemOut,this,[optionItem]));
		SetHandler(optionItem,"click",CreateDelegate(this.OnItemClick,this,[optionItem,onclick]));
	}
    }

    var closeFn=CreateDelegate(this.Close,this);
    SetHandler(document.body,"click",closeFn);
    closeControlsHandlers.push(closeFn);
    this.Options=optionsAndShadow;
    new Shadow(options);
    options.style.visibility="visible";

}
Dropdown.prototype=
{
    Options:null,TextCtrl:null,preventClose:false,
    Toggle:function(e)
    {
        this.preventClose=true;
        CloseControls();
        this.preventClose=false;
        if(this.Options.style.display=="block")this.Options.style.display="none";
        else{this.Options.style.display="block";}
        if (!e)e = window.event;
        e.cancelBubble=true;
        return false;
    },
    OnItemOver:function(item)
    {
        item.className="item over";
    },
    OnItemOut:function(item)
    {
        item.className="item";
    },
    Close:function()
    {
        if(this.preventClose)return;
        this.Options.style.display="none";
    },
    OnItemClick:function(item,handler)
    {
    CloseControls();
    this.TextCtrl.innerHTML=item.innerHTML;
    if(!handler)return;
    if(typeof(item.value)!="undefined"){handler(item.value);return;}
    var itemAttrs=item.attributes;
    for(var j=0;j<itemAttrs.length;j++)
     if(itemAttrs[j].name=="value")
     {
        handler(itemAttrs[j].value);
        return;
     }
    handler(this.TextCtrl.innerHTML);
    }
}


function SetLTab(index)
{
for(var ti=0;true;ti++)
{
var ctrl=document.getElementById("leftTab"+ti);
if(!ctrl)break;
ctrl.style.display="none";
document.getElementById("leftTa"+ti).className="";
}
document.getElementById("leftTab"+index).style.display="block";
document.getElementById("leftTa"+index).className="sel";
}

function SetHandler(obj,evt,fnc)
{
if(obj.addEventListener) obj.addEventListener(evt,fnc,false);
else obj.attachEvent("on"+evt,fnc);
}
function RemoveHandler(obj,evt,fnc)
{
if(obj.removeEventListener) obj.removeEventListener(evt,fnc,false);
else obj.detachEvent("on"+evt,fnc);
}
function CreateDelegate(func,scope,args)
{
    return function(){func.apply(scope,args||arguments)}
}

function ScrollNow(scrolled,isUp)
{
    scrolled.scrollTop=scrolled.scrollTop+(isUp?-10:10);
}
function BeginScrollNow(scrolled,isUp)
{
    if(scrolled.timer)return;
    ScrollNow(scrolled,isUp);
    scrolled.timer=window.setInterval(CreateDelegate(ScrollNow,this,[scrolled,isUp]),50);
}

function StopScroll(scrolled)
{
    if(!scrolled.timer)return;
    window.clearInterval(scrolled.timer);
    scrolled.timer=null;
}
function SetScroller(scrolled,up,down)
{
    SetHandler(up,"mousedown",CreateDelegate(BeginScrollNow,this,[scrolled,true]));
    SetHandler(down,"mousedown",CreateDelegate(BeginScrollNow,this,[scrolled,false]));
    var stopScroll=CreateDelegate(StopScroll,this,[scrolled]);
    SetHandler(up,"mouseup",stopScroll);
    SetHandler(down,"mouseup",stopScroll);
    SetHandler(document.body,"mouseup",stopScroll);
}
function AddClass(dom,cls)
{
 if((' '+(dom.className||'')+' ').indexOf(' '+cls+' ')>=0)return;
 dom.className+=' '+cls;
}
function RemoveClass(dom,cls)
{
 var i=(' '+(dom.className||'')+' ').indexOf(' '+cls+' ');
 if(i<0)return;
 dom.className=dom.className.substr(0,i-1)+dom.className.substr(i+cls.length);
}

var ExtButton=function(buttonId,onclickHandler)
{
	var buttonDom=document.getElementById(buttonId);
	SetHandler(buttonDom,"mouseover",CreateDelegate(AddClass,this,[buttonDom,"hover"]));
	SetHandler(buttonDom,"mouseout",CreateDelegate(RemoveClass,this,[buttonDom,"hover"]));
	if(typeof(onclickHandler)!='undefined')
		SetHandler(buttonDom,"click",CreateDelegate(onclickHandler,this,[buttonDom]));
}
ExtButton.prototype=
{
}

function textFieldOnFocus(field)
{
 if(field.value==field.emptyText)field.value="";
 RemoveClass(field,"defaultValue")
}
function textFieldOnUnFocus(field)
{
 if(field.value==""){field.value=field.emptyText;AddClass(field,"defaultValue")}
}
function SetTextField(fieldId,emptyText)
{
var field=document.getElementById(fieldId);
if(!field)return;
field.emptyText=emptyText;
if(field.value=="" || field.value==emptyText){field.value=emptyText;AddClass(field,"defaultValue");}
SetHandler(field,"focus",CreateDelegate(textFieldOnFocus,this,[field]));
SetHandler(field,"blur",CreateDelegate(textFieldOnUnFocus,this,[field]));

}

function SearchForLocation(webName)
{
CloseControls();
AsyncDownload("/"+webName+"/_layouts/lh.quicksearch.aspx","location="+EncodeCallback(document.getElementById("locationSearch").value),SearchForLocationResult);
}


var locationSearchO=null;

function HideSearchLocationResults()
{
if(!locationSearchO)return;
locationSearchO.cnt.style.visibility="hidden";
locationSearchO.list.style.visibility="hidden";
}

function SearchForLocationResult(result,status)
{
try{result=eval('('+result+')');}catch(exc){result=null}
if(!result || result.length==0){alert(noLocationFound);return;}
var locationSearch=document.getElementById("locationSearch");
var parent=locationSearch.parentElement||locationSearch.parentNode;

if(!locationSearchO)
{
	locationSearchO={};
	locationSearchO.cnt=document.createElement("div");
	parent.appendChild(locationSearchO.cnt);
	locationSearchO.list=document.createElement("div");
	locationSearchO.cnt.appendChild(locationSearchO.list);
	locationSearchO.list.className="dropdownOptions";
	locationSearchO.list.style.width=locationSearch.clientWidth+"px";
	locationSearchO.sh=new Shadow(locationSearchO.list,true);
	closeControlsHandlers.push(HideSearchLocationResults);
	SetHandler(document.body,"click",HideSearchLocationResults);
}
locationSearchO.list.innerHTML="";
var optionItem;
for(var lI=0;lI<result.length;lI++)
{
	optionItem=document.createElement("div");
	optionItem.className="item";
	var option;
	locationSearchO.list.appendChild(optionItem);
	if(result[lI].url)
	{
		if(result[lI].goto)document.location.href=result[lI].url;
		option=document.createElement("a");
		option.innerHTML=result[lI].name;
		option.href=result[lI].url;
		SetHandler(optionItem,"mouseover",CreateDelegate(Dropdown.prototype.OnItemOver,this,[optionItem]));
		SetHandler(optionItem,"mouseout",CreateDelegate(Dropdown.prototype.OnItemOut,this,[optionItem]));
	}
	else
	{
		option=document.createElement("div");
		option.innerHTML=result[lI].name;
	}
	optionItem.appendChild(option);
	Unselectable(option);
}
locationSearchO.sh.SetSize(locationSearchO.list.clientWidth,locationSearchO.list.clientHeight);
locationSearchO.cnt.style.visibility="visible";
locationSearchO.list.style.visibility="visible";
}


function Fetch(langCode)
{
if(typeof(wbeBase)=="undefined")wbeBase="http://webbooking.louvre-hotels.fr/";
document.location.href=(wbeBase.replace('http','https'))+"fetch.login.aspx?confirmation="+(EncodeCallback(document.getElementById("fetchConf").value)||"")+
	"&name="+(EncodeCallback(document.getElementById("fetchLast").value)||"")+
	"&cc="+(EncodeCallback(document.getElementById("fetchCC").value)||"")+"&l="+langCode+"&s=PC";
}

function FetchHelho(langCode)
{
if(typeof(wbeBase)=="undefined")wbeBase="http://webbooking.louvre-hotels.fr/";
document.location.href=(wbeBase.replace('http','https'))+"fetch.login.aspx?holder="+(EncodeCallback(document.getElementById("fetchLastHelho").value)||"")+
	"&card="+(EncodeCallback(document.getElementById("fetchCardHelho").value)||"")+"&l="+langCode+"&s=PC";
}

function EncodeCallback(parameter) {
if(!parameter)return null;
    if (encodeURIComponent) {
        return encodeURIComponent(parameter);
    }
    else {
        return escape(parameter);
    }
}

function AsyncDownload(url,postData, eventCallback) {
    var xmlRequest,e;
    try {// If IE7, Mozilla, Safari, and so on: Use native object
        xmlRequest = new XMLHttpRequest();
    }
    catch(e) {
        try {
            xmlRequest = new ActiveXObject("Microsoft.XMLHTTP");
        }
        catch(e) {
        }
    }
    var setRequestHeaderMethodExists = true;
    try {
        setRequestHeaderMethodExists = (xmlRequest && xmlRequest.setRequestHeader);
    }catch(e){}
    xmlRequest.onreadystatechange = function()
            {
                if(xmlRequest.readyState == 4 && eventCallback)
                    eventCallback(xmlRequest.responseText,xmlRequest.status);
            };
    xmlRequest.open(postData?"POST":"GET", url, true);
    if (setRequestHeaderMethodExists) {
        xmlRequest.setRequestHeader("Content-Type", "application/x-www-form-urlencoded");
        //The following line is added due to a bug on IE5 on Windows 2000
        xmlRequest.setRequestHeader("If-Modified-Since","Sat, 1 Jan 2000 00:00:00 GMT");
     }
    xmlRequest.send(postData);
}

function GoBook()
{
if(typeof(wbeBase)=="undefined")wbeBase="http://webbooking.louvre-hotels.fr/";
document.location.href=wbeBase+"book/switch.aspx?f="+FormatDateIso(ParseDate(document.getElementById("qbArrv").value))+
"&d="+FormatDateIso(ParseDate(document.getElementById("qbDept").value))+"&city="+document.getElementById("qbLocation").value+"&country="+selectedCountry+
"&adults="+selectedAdults+"&children="+selectedChildren+"&rn="+selectedRoomsCount+(document.getElementById("qbWifi").checked?"&wifi=1":"")+"&l="+langCode+"&s=PC";

}
