var transtext=new Array();
transtext.pl=new Array();
transtext.en=new Array();
transtext.de=new Array();

String.prototype.trim = function() { return this.replace(/^\s+|\s+$/, ''); };


var dALL;
var cities;
var get=new Array();
var url=new String(window.location);
url.replace(new RegExp('#.*$/'),'');
url=url.split('?');
url=url[1];
if (url)
   {
   url=url.split('&');
   for (k in url)
      {
      var param=url[k].split('=');
      get[unescape(param[0])]=unescape(param[1]);
      }
   }

function fillform(formname)
{
for (k in get)
   if (document.forms[formname].elements[k])
   {
      var el=document.forms[formname].elements[k];
         el.value=get[k];
   }
}


function formval(formname,field)
    {
    var el=document.forms[formname].elements[field];
    if(el.length)
	{
        var i,el2;
        for(i=0;i<el.length;i++)
    	    {
    	    el2=el[i];
    	    if((el2.type=='radio') && (el2.checked))
		return el2.value;
            }
         }
    if((el.tagName=='INPUT') || (el.tagName=='TEXTAREA') || (el.tagName=='SELECT'))
	{
        if (el.type=='checkbox')
    	    {
    	    if (el.checked)
		return el.value;
    	    }
	    else 
		return el.value;
        }
    return false;
    }

function redirect(x)
   {
   var oldTID=formval("searchform","TID");
   var TID;
   var PID=formval("searchform","PID");
   var el=document.searchform.TID
   var set=false;
   el.length=0;
   if (dALL) el.options.add(new Option(dALL,0));
   var i;
   for (cityname in cities[PID])
      {
      if (oldTID==cities[PID][cityname])
      {
          el.options.add(new Option(cityname,cities[PID][cityname],true));
	  set=true;
      }
      else
          el.options.add(new Option(cityname,cities[PID][cityname]));
      }
   if (set)
      {
      document.searchform.TID.value=oldTID;
      }
   }



function manage_search()
{
dALL=false;
cities=new Array();
cities[0]=new Array();
var c=new Array();
var i;
for (var i=0;i<document.forms['searchform']['TID'].options.length;i++)
   {
   var el=document.forms['searchform']['TID'].options[i];
   var TID=el.value;
   if (TID>0)
      {
      var PID=el.id.replace('P'+TID+'_','');
      if (!cities[PID]) cities[PID]=new Array();
      cities[PID][el.text]=TID;
      cities[0][el.text]=TID;
      }
   if (TID==0)
      {
      dALL=el.text;
      }
   }
   fillform('searchform');
   redirect(0);
}





function get_absolute_pos(obj)
{
var oLeft=0;
var oTop=0;
while(obj.offsetParent)
{
oLeft+=obj.offsetLeft;
oTop+=obj.offsetTop;

if (navigator.userAgent.indexOf('MSIE'))
{
if (obj.style.marginTop.replace("px","")>0) oTop-=obj.style.marginTop.replace("px","");
if (obj.style.margin.replace("px","")>0) oTop-=obj.style.margin.replace("px","");
if (obj.style.paddingTop.replace("px","")>0) oTop-=obj.style.paddingTop.replace("px","");
if (obj.style.padding.replace("px","")>0) oTop-=obj.style.padding.replace("px","");

if (obj.style.marginLeft.replace("px","")>0) oLeft-=obj.style.marginLeft.replace("px","");
if (obj.style.margin.replace("px","")>0) oLeft-=obj.style.margin.replace("px","");
if (obj.style.paddingLeft.replace("px","")>0) oLeft-=obj.style.paddingLeft.replace("px","");
if (obj.style.padding.replace("px","")>0) oLeft-=obj.style.padding.replace("px","");
}

obj=obj.offsetParent;
}
return [oLeft, oTop];

}


function f_filterResults(n_win, n_docel, n_body)
{
	var n_result = n_win ? n_win : 0;
	if (n_docel && (!n_result || (n_result > n_docel)))
		n_result = n_docel;
	return n_body && (!n_result || (n_result > n_body)) ? n_body : n_result;
}



function get_window_size()
{
	var width=f_filterResults (
		window.innerWidth ? window.innerWidth : 0,
		document.documentElement ? document.documentElement.clientWidth : 0,
		document.body ? document.body.clientWidth : 0
	);
	var height=f_filterResults (
		window.innerHeight ? window.innerHeight : 0,
		document.documentElement ? document.documentElement.clientHeight : 0,
		document.body ? document.body.clientHeight : 0
	);
	return [width,height];
}

function get_window_pos()
{
	var left=f_filterResults (
		window.pageXOffset ? window.pageXOffset : 0,
		document.documentElement ? document.documentElement.scrollLeft : 0,
		document.body ? document.body.scrollLeft : 0
	);
	var top=f_filterResults (
		window.pageYOffset ? window.pageYOffset : 0,
		document.documentElement ? document.documentElement.scrollTop : 0,
		document.body ? document.body.scrollTop : 0
	);
	return [left,top];
}


function get_element_size(obj)
{
    var width=obj.offsetWidth;
    var height=obj.offsetHeight;
    
    if (obj.style.paddingTop>0) height+=obj.style.paddingTop;
    if (obj.style.paddingBottom>0) height+=obj.style.paddingBottom;
    if (obj.style.padding>0) height+=obj.style.padding;

if (navigator.userAgent.indexOf('MSIE'))
{
    if (obj.style.marginTop>0) height-=obj.style.marginTop;
    if (obj.style.marginBottom>0) height-=obj.style.marginBottom;
    if (obj.style.margin>0) height-=obj.style.margin;
}
    return [width,height];
}

function tooltip(p_id,p_content,id2)
{
    var control=(typeof id2==='string')?document.getElementById(id2):id2;
    var id=p_id;
    var content=p_content;
    var intervalid;
    var oldwinpos;
    var oldwinsize;
    
    this.remove=function()
    {
	var container=document.getElementById('tooltip_'+id);
	if (container)
	    container.parentNode.removeChild(container);
	    
	if (this.intervalid)
	    clearInterval(this.intervalid);
    }
    
    this.interval=function()
    {
	var winpos=get_window_pos();
	var winsize=get_window_size();
	var container=document.getElementById('tooltip_'+id);
	if (!container)
	{
	    if (this.intervalid)
	        clearInterval(this.intervalid);
	    return;
	}
	if (this.oldwinpos)
	{
	if ((this.oldwinpos[0]!=winpos[0]) || (this.oldwinpos[1]!=winpos[1]) || (this.oldwinsize[0]!=winsize[0]) || (this.oldwinsize[1]!=winsize[1]))
	{
	this.remove();
	this.draw();
	}
	}
	this.oldwinpos=winpos;
	this.oldwinsize=winsize;
    }


    
    this.draw=function()
    {
	this.remove();

	var container;
	var containerinner;
	
	container=document.createElement('div');
        container.setAttribute('id', 'tooltip_'+id);
	container.style.zIndex=100;
	container.style.background="white";
	container.style.border="1px solid gray";

	containerinner=document.createElement('div');
        containerinner.innerHTML=content;
        containerinner.style.display="inline";

        container.appendChild(containerinner);
        document.body.appendChild(container);

	container.style.position="absolute";
        containerinner.style.position="relative";
	container.style.padding=5+"px";


        container.style.paddingRight=25+"px";
	var closelink=document.createElement("a");
	closelink.innerHTML="<img src='/hotele_gfx_pl_szczecin/hotele_closetip.png'>";
	closelink.style.zIndex=100;
	closelink.style.position="absolute";
	closelink.style.cursor="pointer";
	closelink.style.right=5+"px";
	closelink.style.top=5+"px";
	closelink.onclick=this.remove;

	container.appendChild(closelink);

        var pos=get_absolute_pos(control);
        var size=get_element_size(control);
        var size2=get_element_size(container);


        if((control.tagName=='INPUT') )
	{
	pos[0]+=size[0];
	pos[1]+=0;
	}
	else
	{
	pos[0]+=size[0]/2;
	pos[1]+=size[1]/2;
	}
	
	var pos2=new Array(pos[0],pos[1]);
	var winpos=get_window_pos();
	var winsize=get_window_size();
	
	pos2[0]-=winpos[0];
	pos2[1]-=winpos[1];


        var img=document.createElement('img');
        container.appendChild(img);
        img.style.position="absolute";
	var shift;
	
	if (container.offsetWidth<100)
	   container.style.width=100+"px";
	
	shift=220;
	shift=container.offsetWidth-80;
	
	if (pos[0]-shift<10)
	   shift=0;


	
	img.style.left=shift+"px";
	imgoffsetHeight=20; // MSIE & FF hack
	
	if (pos2[1]>winsize[1]/2)
	{
	    pos[1]-=(size2[1]+10); // nad
    	    img.setAttribute('src', "/hotele_gfx_pl_szczecin/hotele_dymek1.gif");
	    img.style.top=(container.offsetHeight-2)+"px";
	}
	else
	{
	    pos[1]+=(imgoffsetHeight+10);
    	    img.setAttribute('src', "/hotele_gfx_pl_szczecin/hotele_dymek2.gif");
	    img.style.top=(-imgoffsetHeight)+"px";
	}
	
        container.style.left=(pos[0]-shift)+"px";
	container.style.top=(pos[1])+"px";
	container.style.position="absolute";

        this.intervalid=setInterval(this.interval,500);
    }

    this.draw();
    return this;
}



// domy¶lny kierunek sortowania w kolumnach
var sortcols=new Array();
sortcols["wyniki1"]=new Array();
sortcols["wyniki1"][1]=0;
sortcols["wyniki1"][2]=0;
sortcols["wyniki1"][3]=1;

sortcols["wyniki2"]=new Array();
sortcols["wyniki2"][1]=0;
sortcols["wyniki2"][2]=0;
sortcols["wyniki2"][3]=1;

sortcols["wyniki"]=new Array();
sortcols["wyniki"][1]=0;
sortcols["wyniki"][2]=0;
sortcols["wyniki"][3]=1;

function sortfunc_wyniki1_1_up(a,b)
{
    var l1,l2;
    l1=a.cells[1].abbr;
    l2=b.cells[1].abbr;
    if (l1<l2) return -1;
    if (l1>l2) return 1;
    return 0;
}
function sortfunc_wyniki1_1_down(a,b)
{
    return (-sortfunc_wyniki1_1_up(a,b));
}


function sortfunc_wyniki1_2_up(a,b)
{
    var l1,l2;
    l1=parseInt(a.cells[2].abbr);
    l2=parseInt(b.cells[2].abbr);
    return l1-l2;
}
function sortfunc_wyniki1_2_down(a,b)
{
    return (-sortfunc_wyniki1_2_up(a,b));
}


function sortfunc_wyniki1_3_up(a,b)
{
    var l1,l2;
    l1=parseInt(a.cells[3].abbr);
    l2=parseInt(b.cells[3].abbr);
    return l1-l2;
}
function sortfunc_wyniki1_3_down(a,b)
{
    return (-sortfunc_wyniki1_3_up(a,b));
}




function sortfunc_wyniki2_1_up(a,b) { return (sortfunc_wyniki1_1_up(a,b)); }
function sortfunc_wyniki2_2_up(a,b) { return (sortfunc_wyniki1_2_up(a,b)); }
function sortfunc_wyniki2_3_up(a,b) { return (sortfunc_wyniki1_3_up(a,b)); }
function sortfunc_wyniki2_1_down(a,b) { return (sortfunc_wyniki1_1_down(a,b)); }
function sortfunc_wyniki2_2_down(a,b) { return (sortfunc_wyniki1_2_down(a,b)); }
function sortfunc_wyniki2_3_down(a,b) { return (sortfunc_wyniki1_3_down(a,b)); }


function sortfunc_wyniki_1_up(a,b) { return (sortfunc_wyniki1_1_up(a,b)); }
function sortfunc_wyniki_2_up(a,b) { return (sortfunc_wyniki1_2_up(a,b)); }
function sortfunc_wyniki_3_up(a,b) { return (sortfunc_wyniki1_3_up(a,b)); }
function sortfunc_wyniki_1_down(a,b) { return (sortfunc_wyniki1_1_down(a,b)); }
function sortfunc_wyniki_2_down(a,b) { return (sortfunc_wyniki1_2_down(a,b)); }
function sortfunc_wyniki_3_down(a,b) { return (sortfunc_wyniki1_3_down(a,b)); }





function sorttable(t_id,col)
{
    var i;

    if (sortcols[t_id][col]!=0)
	sortcols[t_id][col]=-sortcols[t_id][col];
    else
    {
	for (i in sortcols[t_id])
	{
	    if (i!=col)
		sortcols[t_id][i]=0;
	    else
		sortcols[t_id][i]=1;
	}
    }
    el=document.getElementById(t_id);

    for (i in sortcols[t_id])
    {
	var icon=document.getElementById("sorticon_"+t_id+"_"+i);
	if (sortcols[t_id][i]==-1)
	    icon.className="sort_up";
	else
	if (sortcols[t_id][i]==1)
    	    icon.className="sort_down";
	else
    	    icon.className="sort_none";
    }

    var newRows = new Array();
    for (i=0;i<el.tBodies[0].rows.length;i++)
        newRows[i]=el.tBodies[0].rows[i];

    var func;
    if (sortcols[t_id][col]==-1)
        func="sortfunc_"+t_id+"_"+col+"_down";
    else
        func="sortfunc_"+t_id+"_"+col+"_up";

    newRows.sort(eval(func));

    for (i=0;i<newRows.length;i++)
        el.tBodies[0].appendChild(newRows[i]);
}


function OpenHotelRating(src) { 
var w=490;
var s=654;

var l=(screen.width-w)/2;
var t=(screen.height-s)/2;
Nowe= window.open(src,"rating",'width=' + w + ',height=' + s + ',directories=no,resizable=0,scrollbars=yes,menubar=no,left=' + l + ',top=' + t);
Nowe.focus() 
} 

var mapfunc;

function afterload()
{
if (mapfunc) mapfunc();
for(var id in adbutler)
    document.getElementById('adbutler_'+id).src=adbutler[id];
//ajax('/'+languageCode+'/ajax_login.php');
};
function insert_baner()
{
document.write('<object classid="clsid:d27cdb6e-ae6d-11cf-96b8-444553540000" codebase="http://fpdownload.macromedia.com/pub/shockwave/cabs/flash/swflash.cab#version=8,0,0,0" width="786" height="100" data="/hotele_gfx_pl_szczecin/hotele_banner_ver5.swf" >');
document.write('<param name="movie" value="/hotele_gfx_pl_szczecin/hotele_banner_ver5.swf" />');
document.write('<embed width="786" height="100" src="/hotele_gfx_pl_szczecin/hotele_banner_ver5.swf" />');
document.write('</object>');
}
/************************************************************************************************************
JS Calendar
Copyright (C) September 2006  DTHMLGoodies.com, Alf Magne Kalleland

This library is free software; you can redistribute it and/or
modify it under the terms of the GNU Lesser General Public
License as published by the Free Software Foundation; either
version 2.1 of the License, or (at your option) any later version.

This library is distributed in the hope that it will be useful,
but WITHOUT ANY WARRANTY; without even the implied warranty of
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
Lesser General Public License for more details.

You should have received a copy of the GNU Lesser General Public
License along with this library; if not, write to the Free Software
Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA  02110-1301  USA

Dhtmlgoodies.com., hereby disclaims all copyright interest in this script
written by Alf Magne Kalleland.

Alf Magne Kalleland, 2006
Owner of DHTMLgoodies.com
	
************************************************************************************************************/	

/* Update log:
(C) www.dhtmlgoodies.com, September 2005

Version 1.2, November 8th - 2005 - Added <iframe> background in IE
Version 1.3, November 12th - 2005 - Fixed top bar position in Opera 7
Version 1.4, December 28th - 2005 - Support for Spanish and Portuguese
Version 1.5, January  18th - 2006 - Fixed problem with next-previous buttons after a month has been selected from dropdown
Version 1.6, February 22nd - 2006 - Added variable which holds the path to images.
									Format todays date at the bottom by use of the todayStringFormat variable
									Pick todays date by clicking on todays date at the bottom of the calendar
Version 2.0	 May, 25th - 2006	  - Added support for time(hour and minutes) and changing year and hour when holding mouse over + and - options. (i.e. instead of click)
Version 2.1	 July, 2nd - 2006	  - Added support for more date formats(example: d.m.yyyy, i.e. one letter day and month).

*/
if (!languageCode)
    var languageCode = 'en';	// Possible values: 	en,ge,no,nl,es,pt-br,fr	
							// en = english, ge = german, no = norwegian,nl = dutch, es = spanish, pt-br = portuguese, fr = french, da = danish, hu = hungarian(Use UTF-8 doctype for hungarian)

var calendar_display_time = true;
								
// Format of current day at the bottom of the calendar
// [todayString] = the value of todayString
// [dayString] = day of week (examle: mon, tue, wed...)
// [UCFdayString] = day of week (examle: Mon, Tue, Wed...) ( First letter in uppercase)
// [day] = Day of month, 1..31
// [monthString] = Name of current month
// [year] = Current year							
var todayStringFormat = '[todayString] [UCFdayString]. [day]. [monthString] [year]';						
if (!pathToImages)
    var pathToImages = 'images/';	// Relative to your HTML file

var speedOfSelectBoxSliding = 200;	// Milliseconds between changing year and hour when holding mouse over "-" and "+" - lower value = faster
var intervalSelectBox_minutes = 5;	// Minute select box - interval between each option (5 = default)

var calendar_offsetTop = 0;		// Offset - calendar placement - You probably have to modify this value if you're not using a strict doctype
var calendar_offsetLeft = 0;	// Offset - calendar placement - You probably have to modify this value if you're not using a strict doctype
var calendarDiv = false;

var MSIE = false;
var Opera = false;
if(navigator.userAgent.indexOf('MSIE')>=0 && navigator.userAgent.indexOf('Opera')<0)MSIE=true;
if(navigator.userAgent.indexOf('Opera')>=0)Opera=true;


switch(languageCode){
	case "en":	/* English */
		var monthArray = ['January','February','March','April','May','June','July','August','September','October','November','December'];
		var monthArrayShort = ['Jan','Feb','Mar','Apr','May','Jun','Jul','Aug','Sep','Oct','Nov','Dec'];
		var dayArray = ['Mon','Tue','Wed','Thu','Fri','Sat','Sun'];
		var weekString = 'Week';
		var todayString = 'Today';
		break;
	case "pl":	/* Polish */
		var monthArray = ['Styczeñ','Luty','Marzec','Kwiecieñ','Maj','Czerwiec','Lipiec','Sierpieñ','Wrzesieñ','Pa¼dziernik','Listopad','Grudzieñ'];
		var monthArrayShort = ['Sty','Lut','Mar','Kwi','Maj','Cze','Lip','Sie','Wrz','Paz','Lis','Gru'];
		var dayArray = ['Pon','Wto','¦ro','Czw','Pt','Sob','Nie'];
		var weekString = 'Tyg';
		var todayString = 'Dzisiaj';
		break;
	case "de":	/* German */
		var monthArray = ['Januar','Februar','März','April','Mai','Juni','Juli','August','September','Oktober','November','Dezember'];
		var monthArrayShort = ['Jan','Feb','Mar','Apr','Mai','Jun','Jul','Aug','Sep','Okt','Nov','Dez'];
		var dayArray = ['Mon','Die','Mit','Don','Fre','Sam','Son'];	
		var weekString = 'Woche';
		var todayString = 'Heute';		
		break;
	case "no":	/* Norwegian */
		var monthArray = ['Januar','Februar','Mars','April','Mai','Juni','Juli','August','September','Oktober','November','Desember'];
		var monthArrayShort = ['Jan','Feb','Mar','Apr','Mai','Jun','Jul','Aug','Sep','Okt','Nov','Des'];
		var dayArray = ['Man','Tir','Ons','Tor','Fre','L&oslash;r','S&oslash;n'];	
		var weekString = 'Uke';
		var todayString = 'Dagen i dag er';
		break;	
	case "nl":	/* Dutch */
		var monthArray = ['Januari','Februari','Maart','April','Mei','Juni','Juli','Augustus','September','Oktober','November','December'];
		var monthArrayShort = ['Jan','Feb','Mar','Apr','Mei','Jun','Jul','Aug','Sep','Okt','Nov','Dec'];
		var dayArray = ['Ma','Di','Wo','Do','Vr','Za','Zo'];
		var weekString = 'Week';
		var todayString = 'Vandaag';
		break;	
	case "es": /* Spanish */
		var monthArray = ['Enero','Febrero','Marzo','April','Mayo','Junio','Julio','Agosto','Septiembre','Octubre','Noviembre','Diciembre'];
		var monthArrayShort =['Ene','Feb','Mar','Abr','May','Jun','Jul','Ago','Sep','Oct','Nov','Dic'];
		var dayArray = ['Lun','Mar','Mie','Jue','Vie','Sab','Dom'];
		var weekString = 'Semana';
		var todayString = 'Hoy es';
		break; 	
	case "pt-br":  /* Brazilian portuguese (pt-br) */
		var monthArray = ['Janeiro','Fevereiro','Mar&ccedil;o','Abril','Maio','Junho','Julho','Agosto','Setembro','Outubro','Novembro','Dezembro'];
		var monthArrayShort = ['Jan','Fev','Mar','Abr','Mai','Jun','Jul','Ago','Set','Out','Nov','Dez'];
		var dayArray = ['Seg','Ter','Qua','Qui','Sex','S&aacute;b','Dom'];
		var weekString = 'Sem.';
		var todayString = 'Hoje &eacute;';
		break;
	case "fr":      /* French */
		var monthArray = ['Janvier','Février','Mars','Avril','Mai','Juin','Juillet','Août','Septembre','Octobre','Novembre','Décembre'];		
		var monthArrayShort = ['Jan','Fev','Mar','Avr','Mai','Jun','Jul','Aou','Sep','Oct','Nov','Dec'];
		var dayArray = ['Lun','Mar','Mer','Jeu','Ven','Sam','Dim'];
		var weekString = 'Sem';
		var todayString = "Aujourd'hui";
		break; 	
	case "da": /*Danish*/
		var monthArray = ['januar','februar','marts','april','maj','juni','juli','august','september','oktober','november','december'];
		var monthArrayShort = ['jan','feb','mar','apr','maj','jun','jul','aug','sep','okt','nov','dec'];
		var dayArray = ['man','tirs','ons','tors','fre','l&oslash;r','s&oslash;n'];
		var weekString = 'Uge';
		var todayString = 'I dag er den';
		break;	
	case "hu":	/* Hungarian  - Remember to use UTF-8 encoding, i.e. the <meta> tag */
		var monthArray = ['JanuÃ¡r','FebruÃ¡r','MÃ¡rcius','Ã?prilis','MÃ¡jus','JÃºnius','JÃºlius','Augusztus','Szeptember','OktÃ³ber','November','December'];
		var monthArrayShort = ['Jan','Feb','MÃ¡rc','Ã?pr','MÃ¡j','JÃºn','JÃºl','Aug','Szep','Okt','Nov','Dec'];
		var dayArray = ['HÃ©','Ke','Sze','Cs','PÃ©','Szo','Vas'];
		var weekString = 'HÃ©t';
		var todayString = 'Mai nap';	
		break;
	case "it":	/* Italian*/
		var monthArray = ['Gennaio','Febbraio','Marzo','Aprile','Maggio','Giugno','Luglio','Agosto','Settembre','Ottobre','Novembre','Dicembre'];
		var monthArrayShort = ['Gen','Feb','Mar','Apr','Mag','Giu','Lugl','Ago','Set','Ott','Nov','Dic'];
		var dayArray = ['Lun',';Mar','Mer','Gio','Ven','Sab','Dom'];
		var weekString = 'Settimana';
		var todayString = 'Oggi &egrave; il';
		break;		
	case "sv":	/* Swedish */
		var monthArray = ['Januari','Februari','Mars','April','Maj','Juni','Juli','Augusti','September','Oktober','November','December'];
		var monthArrayShort = ['Jan','Feb','Mar','Apr','Maj','Jun','Jul','Aug','Sep','Okt','Nov','Dec'];
		var dayArray = ['M&aring;n','Tis','Ons','Tor','Fre','L&ouml;r','S&ouml;n'];
		var weekString = 'Vecka';
		var todayString = 'Idag &auml;r det den';
		break;
		

		
}



var daysInMonthArray = [31,28,31,30,31,30,31,31,30,31,30,31];
var currentMonth;
var currentYear;
var currentHour;
var currentMinute;
var calendarContentDiv;
var returnDateTo;
var returnFormat;
var activeSelectBoxMonth;
var activeSelectBoxYear;
var activeSelectBoxHour;
var activeSelectBoxMinute;

var iframeObj = false;
//// fix for EI frame problem on time dropdowns 09/30/2006
var iframeObj2 =false;
function EIS_FIX_EI1(where2fixit)
{ 

		if(!iframeObj2)return;
		iframeObj2.style.display = 'block';
		iframeObj2.style.height =document.getElementById(where2fixit).offsetHeight+1;
		iframeObj2.style.width=document.getElementById(where2fixit).offsetWidth;
		iframeObj2.style.left=getleftPos(document.getElementById(where2fixit))+1-calendar_offsetLeft;
		iframeObj2.style.top=getTopPos(document.getElementById(where2fixit))-document.getElementById(where2fixit).offsetHeight-calendar_offsetTop;
}

function EIS_Hide_Frame()
{		if(iframeObj2)iframeObj2.style.display = 'none';}
//// fix for EI frame problem on time dropdowns 09/30/2006
var returnDateToYear;
var returnDateToMonth;
var returnDateToDay;
var returnDateToHour;
var returnDateToMinute;

var inputYear;
var inputMonth;
var inputDay;
var inputHour;
var inputMinute;
var calendarDisplayTime = false;

var selectBoxHighlightColor = '#D60808'; // Highlight color of select boxes
var selectBoxHighlightColor = '#000'; // Highlight color of select boxes
//var selectBoxRolloverBgColor = '#E2EBED'; // Background color on drop down lists(rollover)
//var selectBoxRolloverBgColor = '#FDF5DD'; // Background color on drop down lists(rollover)
var selectBoxRolloverBgColor = '#4d95d2'; // Background color on drop down lists(rollover)

var selectBoxMovementInProgress = false;
var activeSelectBox = false;

function cancelCalendarEvent()
{
	return false;
}
function isLeapYear(inputYear)
{
	if(inputYear%400==0||(inputYear%4==0&&inputYear%100!=0)) return true;
	return false;	
	
}
var activeSelectBoxMonth = false;
var activeSelectBoxDirection = false;

function highlightMonthYear()
{
	if(activeSelectBoxMonth)activeSelectBoxMonth.className='';
	activeSelectBox = this;

	
	if(this.className=='monthYearActive'){
		this.className='';	
	}else{
		this.className = 'monthYearActive';
		activeSelectBoxMonth = this;
	}
	
	if(this.innerHTML.indexOf('-')>=0 || this.innerHTML.indexOf('+')>=0){
		if(this.className=='monthYearActive')
			selectBoxMovementInProgress = true; 
		else 
			selectBoxMovementInProgress = false;	
		if(this.innerHTML.indexOf('-')>=0)activeSelectBoxDirection = -1; else activeSelectBoxDirection = 1;	
			
	}else selectBoxMovementInProgress = false;
	
}

function showMonthDropDown()
{
	if(document.getElementById('monthDropDown').style.display=='block'){
		document.getElementById('monthDropDown').style.display='none';	
		//// fix for EI frame problem on time dropdowns 09/30/2006
				EIS_Hide_Frame();
	}else{
		document.getElementById('monthDropDown').style.display='block';		
		document.getElementById('yearDropDown').style.display='none';
		document.getElementById('hourDropDown').style.display='none';
		document.getElementById('minuteDropDown').style.display='none';
			if (MSIE)
		{ EIS_FIX_EI1('monthDropDown')}
		//// fix for EI frame problem on time dropdowns 09/30/2006

	}
}

function showYearDropDown()
{
	if(document.getElementById('yearDropDown').style.display=='block'){
		document.getElementById('yearDropDown').style.display='none';	
		//// fix for EI frame problem on time dropdowns 09/30/2006
				EIS_Hide_Frame();
	}else{
		document.getElementById('yearDropDown').style.display='block';	
		document.getElementById('monthDropDown').style.display='none';	
		document.getElementById('hourDropDown').style.display='none';
		document.getElementById('minuteDropDown').style.display='none';		
			if (MSIE)
		{ EIS_FIX_EI1('yearDropDown')}
		//// fix for EI frame problem on time dropdowns 09/30/2006

	}		

}
function showHourDropDown()
{
	if(document.getElementById('hourDropDown').style.display=='block'){
		document.getElementById('hourDropDown').style.display='none';	
		//// fix for EI frame problem on time dropdowns 09/30/2006
				EIS_Hide_Frame();
	}else{
		document.getElementById('hourDropDown').style.display='block';	
		document.getElementById('monthDropDown').style.display='none';	
		document.getElementById('yearDropDown').style.display='none';	
		document.getElementById('minuteDropDown').style.display='none';	
				if (MSIE)
		{ EIS_FIX_EI1('hourDropDown')}
		//// fix for EI frame problem on time dropdowns 09/30/2006
	}		

}
function showMinuteDropDown()
{
	if(document.getElementById('minuteDropDown').style.display=='block'){
		document.getElementById('minuteDropDown').style.display='none';	
		//// fix for EI frame problem on time dropdowns 09/30/2006
				EIS_Hide_Frame();
	}else{
		document.getElementById('minuteDropDown').style.display='block';	
		document.getElementById('monthDropDown').style.display='none';	
		document.getElementById('yearDropDown').style.display='none';	
		document.getElementById('hourDropDown').style.display='none';	
				if (MSIE)
		{ EIS_FIX_EI1('minuteDropDown')}
		//// fix for EI frame problem on time dropdowns 09/30/2006
	}		

}

function selectMonth()
{
	document.getElementById('calendar_month_txt').innerHTML = this.innerHTML
	currentMonth = this.id.replace(/[^\d]/g,'');

	document.getElementById('monthDropDown').style.display='none';
	//// fix for EI frame problem on time dropdowns 09/30/2006
				EIS_Hide_Frame();
	for(var no=0;no<monthArray.length;no++){
		document.getElementById('monthDiv_'+no).style.color='';	
	}
	this.style.color = selectBoxHighlightColor;
	activeSelectBoxMonth = this;
	writeCalendarContent();
	
}

function selectHour()
{
	document.getElementById('calendar_hour_txt').innerHTML = this.innerHTML
	currentHour = this.innerHTML.replace(/[^\d]/g,'');
	document.getElementById('hourDropDown').style.display='none';
	//// fix for EI frame problem on time dropdowns 09/30/2006
				EIS_Hide_Frame();
	if(activeSelectBoxHour){
		activeSelectBoxHour.style.color='';
	}
	activeSelectBoxHour=this;
	this.style.color = selectBoxHighlightColor;
}

function selectMinute()
{
	document.getElementById('calendar_minute_txt').innerHTML = this.innerHTML
	currentMinute = this.innerHTML.replace(/[^\d]/g,'');
	document.getElementById('minuteDropDown').style.display='none';
	//// fix for EI frame problem on time dropdowns 09/30/2006
				EIS_Hide_Frame();
	if(activeSelectBoxMinute){
		activeSelectBoxMinute.style.color='';
	}
	activeSelectBoxMinute=this;
	this.style.color = selectBoxHighlightColor;
}


function selectYear()
{
	document.getElementById('calendar_year_txt').innerHTML = this.innerHTML
	currentYear = this.innerHTML.replace(/[^\d]/g,'');
	document.getElementById('yearDropDown').style.display='none';
	//// fix for EI frame problem on time dropdowns 09/30/2006
				EIS_Hide_Frame();
	if(activeSelectBoxYear){
		activeSelectBoxYear.style.color='';
	}
	activeSelectBoxYear=this;
	this.style.color = selectBoxHighlightColor;
	writeCalendarContent();
	
}

function switchMonth()
{
	if(this.src.indexOf('left')>=0){
		currentMonth=currentMonth-1;;
		if(currentMonth<0){
			currentMonth=11;
			currentYear=currentYear-1;
		}
	}else{
		currentMonth=currentMonth+1;;
		if(currentMonth>11){
			currentMonth=0;
			currentYear=currentYear/1+1;
		}	
	}	
	
	writeCalendarContent();	
	
	
}

function createMonthDiv(){
	var div = document.createElement('DIV');
	div.className='monthYearPicker';
	div.id = 'monthPicker';
	
	for(var no=0;no<monthArray.length;no++){
		var subDiv = document.createElement('DIV');
		subDiv.innerHTML = monthArray[no];
		subDiv.onmouseover = highlightMonthYear;
		subDiv.onmouseout = highlightMonthYear;
		subDiv.onclick = selectMonth;
		subDiv.id = 'monthDiv_' + no;
		subDiv.style.width = '56px';
		subDiv.onselectstart = cancelCalendarEvent;		
		div.appendChild(subDiv);
		if(currentMonth && currentMonth==no){
			subDiv.style.color = selectBoxHighlightColor;
			activeSelectBoxMonth = subDiv;
		}				
		
	}	
	return div;
	
}

function changeSelectBoxYear(e,inputObj)
{
	if(!inputObj)inputObj =this;
	var yearItems = inputObj.parentNode.getElementsByTagName('DIV');
	if(inputObj.innerHTML.indexOf('-')>=0){
		var startYear = yearItems[1].innerHTML/1 -1;
		if(activeSelectBoxYear){
			activeSelectBoxYear.style.color='';
		}
	}else{
		var startYear = yearItems[1].innerHTML/1 +1;
		if(activeSelectBoxYear){
			activeSelectBoxYear.style.color='';

		}			
	}

	for(var no=1;no<yearItems.length-1;no++){
		yearItems[no].innerHTML = startYear+no-1;	
		yearItems[no].id = 'yearDiv' + (startYear/1+no/1-1);	
		
	}		
	if(activeSelectBoxYear){
		activeSelectBoxYear.style.color='';
		if(document.getElementById('yearDiv'+currentYear)){
			activeSelectBoxYear = document.getElementById('yearDiv'+currentYear);
			activeSelectBoxYear.style.color=selectBoxHighlightColor;;
		}
	}
}
function changeSelectBoxHour(e,inputObj)
{
	if(!inputObj)inputObj = this;
	
	var hourItems = inputObj.parentNode.getElementsByTagName('DIV');
	if(inputObj.innerHTML.indexOf('-')>=0){
		var startHour = hourItems[1].innerHTML/1 -1;
		if(startHour<0)startHour=0;
		if(activeSelectBoxHour){
			activeSelectBoxHour.style.color='';
		}
	}else{
		var startHour = hourItems[1].innerHTML/1 +1;
		if(startHour>14)startHour = 14;
		if(activeSelectBoxHour){
			activeSelectBoxHour.style.color='';

		}			
	}
	var prefix = '';
	for(var no=1;no<hourItems.length-1;no++){
		if((startHour/1 + no/1) < 11)prefix = '0'; else prefix = '';
		hourItems[no].innerHTML = prefix + (startHour+no-1);	
		
		hourItems[no].id = 'hourDiv' + (startHour/1+no/1-1);	
		
	}		
	if(activeSelectBoxHour){
		activeSelectBoxHour.style.color='';
		if(document.getElementById('hourDiv'+currentHour)){
			activeSelectBoxHour = document.getElementById('hourDiv'+currentHour);
			activeSelectBoxHour.style.color=selectBoxHighlightColor;;
		}
	}
}

function updateYearDiv()
{
	var div = document.getElementById('yearDropDown');
	var yearItems = div.getElementsByTagName('DIV');
	for(var no=1;no<yearItems.length-1;no++){
		yearItems[no].innerHTML = currentYear/1 -6 + no;	
		if(currentYear==(currentYear/1 -6 + no)){
			yearItems[no].style.color = selectBoxHighlightColor;
			activeSelectBoxYear = yearItems[no];				
		}else{
			yearItems[no].style.color = '';
		}
	}		
}

function updateMonthDiv()
{
	for(no=0;no<12;no++){
		document.getElementById('monthDiv_' + no).style.color = '';
	}		
	document.getElementById('monthDiv_' + currentMonth).style.color = selectBoxHighlightColor;
	activeSelectBoxMonth = 	document.getElementById('monthDiv_' + currentMonth);
}


function updateHourDiv()
{
	var div = document.getElementById('hourDropDown');
	var hourItems = div.getElementsByTagName('DIV');
	
	var addHours = 0;
	if((currentHour/1 -6 + 1)<0){
		addHours = 	(currentHour/1 -6 + 1)*-1;
	}
	for(var no=1;no<hourItems.length-1;no++){
		var prefix='';
		if((currentHour/1 -6 + no + addHours) < 10)prefix='0';
		hourItems[no].innerHTML = prefix +  (currentHour/1 -6 + no + addHours);	
		if(currentHour==(currentHour/1 -6 + no)){
			hourItems[no].style.color = selectBoxHighlightColor;
			activeSelectBoxHour = hourItems[no];				
		}else{
			hourItems[no].style.color = '';
		}
	}
}

function updateMinuteDiv()
{
	for(no=0;no<60;no+=intervalSelectBox_minutes){
		var prefix = '';
		if(no<10)prefix = '0';
	
		document.getElementById('minuteDiv_' + prefix + no).style.color = '';
	}	
	if(document.getElementById('minuteDiv_' + currentMinute)){	
		document.getElementById('minuteDiv_' + currentMinute).style.color = selectBoxHighlightColor;
		activeSelectBoxMinute = document.getElementById('minuteDiv_' + currentMinute);
	}
}



function createYearDiv()
{

	if(!document.getElementById('yearDropDown')){
		var div = document.createElement('DIV');
		div.className='monthYearPicker';
	}else{
		var div = document.getElementById('yearDropDown');
		var subDivs = div.getElementsByTagName('DIV');
		for(var no=0;no<subDivs.length;no++){
			subDivs[no].parentNode.removeChild(subDivs[no]);	
		}	
	}	
	
	
	var d = new Date();
	if(currentYear){
		d.setFullYear(currentYear);	
	}

	var startYear = d.getFullYear()/1 - 5;

	
	var subDiv = document.createElement('DIV');
	subDiv.innerHTML = '&nbsp;&nbsp;- ';
	subDiv.onclick = changeSelectBoxYear;
	subDiv.onmouseover = highlightMonthYear;
	subDiv.onmouseout = function(){ selectBoxMovementInProgress = false;};	
	subDiv.onselectstart = cancelCalendarEvent;			
	div.appendChild(subDiv);
	
	for(var no=startYear;no<(startYear+10);no++){
		var subDiv = document.createElement('DIV');
		subDiv.innerHTML = no;
		subDiv.onmouseover = highlightMonthYear;
		subDiv.onmouseout = highlightMonthYear;		
		subDiv.onclick = selectYear;		
		subDiv.id = 'yearDiv' + no;	
		subDiv.onselectstart = cancelCalendarEvent;	
		div.appendChild(subDiv);
		if(currentYear && currentYear==no){
			subDiv.style.color = selectBoxHighlightColor;
			activeSelectBoxYear = subDiv;
		}			
	}
	var subDiv = document.createElement('DIV');
	subDiv.innerHTML = '&nbsp;&nbsp;+ ';
	subDiv.onclick = changeSelectBoxYear;
	subDiv.onmouseover = highlightMonthYear;
	subDiv.onmouseout = function(){ selectBoxMovementInProgress = false;};		
	subDiv.onselectstart = cancelCalendarEvent;			
	div.appendChild(subDiv);		
	return div;
}

/* This function creates the hour div at the bottom bar */

function slideCalendarSelectBox()
{
	if(selectBoxMovementInProgress){
		if(activeSelectBox.parentNode.id=='hourDropDown'){
			changeSelectBoxHour(false,activeSelectBox);			
		}
		if(activeSelectBox.parentNode.id=='yearDropDown'){
			changeSelectBoxYear(false,activeSelectBox);			
		}
		
	}
	setTimeout('slideCalendarSelectBox()',speedOfSelectBoxSliding);
		
}

function createHourDiv()
{
	if(!document.getElementById('hourDropDown')){
		var div = document.createElement('DIV');
		div.className='monthYearPicker';
	}else{
		var div = document.getElementById('hourDropDown');
		var subDivs = div.getElementsByTagName('DIV');
		for(var no=0;no<subDivs.length;no++){
			subDivs[no].parentNode.removeChild(subDivs[no]);	
		}	
	}		
	
	if(!currentHour)currentHour=0;
	var startHour = currentHour/1;	
	if(startHour>14)startHour=14;

	var subDiv = document.createElement('DIV');
	subDiv.innerHTML = '&nbsp;&nbsp;- ';
	subDiv.onclick = changeSelectBoxHour;
	subDiv.onmouseover = highlightMonthYear;
	subDiv.onmouseout = function(){ selectBoxMovementInProgress = false;};	
	subDiv.onselectstart = cancelCalendarEvent;			
	div.appendChild(subDiv);
		
	for(var no=startHour;no<startHour+10;no++){
		var prefix = '';
		if(no/1<10)prefix='0';
		var subDiv = document.createElement('DIV');
		subDiv.innerHTML = prefix + no;
		subDiv.onmouseover = highlightMonthYear;
		subDiv.onmouseout = highlightMonthYear;		
		subDiv.onclick = selectHour;		
		subDiv.id = 'hourDiv' + no;	
		subDiv.onselectstart = cancelCalendarEvent;	
		div.appendChild(subDiv);
		if(currentYear && currentYear==no){
			subDiv.style.color = selectBoxHighlightColor;
			activeSelectBoxYear = subDiv;
		}			
	}
	var subDiv = document.createElement('DIV');
	subDiv.innerHTML = '&nbsp;&nbsp;+ ';
	subDiv.onclick = changeSelectBoxHour;
	subDiv.onmouseover = highlightMonthYear;
	subDiv.onmouseout = function(){ selectBoxMovementInProgress = false;};		
	subDiv.onselectstart = cancelCalendarEvent;			
	div.appendChild(subDiv);	
		
	return div;	
}
/* This function creates the minute div at the bottom bar */

function createMinuteDiv()
{
	if(!document.getElementById('minuteDropDown')){
		var div = document.createElement('DIV');
		div.className='monthYearPicker';
	}else{
		var div = document.getElementById('minuteDropDown');
		var subDivs = div.getElementsByTagName('DIV');
		for(var no=0;no<subDivs.length;no++){
			subDivs[no].parentNode.removeChild(subDivs[no]);	
		}	
	}		
	var startMinute = 0;	
	var prefix = '';
	for(var no=startMinute;no<60;no+=intervalSelectBox_minutes){
		
		if(no<10)prefix='0'; else prefix = '';
		var subDiv = document.createElement('DIV');
		subDiv.innerHTML = prefix + no;
		subDiv.onmouseover = highlightMonthYear;
		subDiv.onmouseout = highlightMonthYear;		
		subDiv.onclick = selectMinute;		
		subDiv.id = 'minuteDiv_' + prefix +  no;	
		subDiv.onselectstart = cancelCalendarEvent;	
		div.appendChild(subDiv);
		if(currentYear && currentYear==no){
			subDiv.style.color = selectBoxHighlightColor;
			activeSelectBoxYear = subDiv;
		}			
	}
	return div;	
}

function highlightSelect()
{
	
	if(this.className=='selectBoxTime'){
		this.className = 'selectBoxTimeOver';	
		this.getElementsByTagName('IMG')[0].src = pathToImages + 'down_time_over.gif';
	}else if(this.className=='selectBoxTimeOver'){
		this.className = 'selectBoxTime';	
		this.getElementsByTagName('IMG')[0].src = pathToImages + 'down_time.gif';			
	}
	
	if(this.className=='selectBox'){
		this.className = 'selectBoxOver';	
		this.getElementsByTagName('IMG')[0].src = pathToImages + 'down_over.gif';
	}else if(this.className=='selectBoxOver'){
		this.className = 'selectBox';	
		this.getElementsByTagName('IMG')[0].src = pathToImages + 'down.gif';			
	}
	
}

function highlightArrow()
{
	if(this.src.indexOf('over')>=0){
		if(this.src.indexOf('left')>=0)this.src = pathToImages + 'left.gif';	
		if(this.src.indexOf('right')>=0)this.src = pathToImages + 'right.gif';				
	}else{
		if(this.src.indexOf('left')>=0)this.src = pathToImages + 'left_over.gif';	
		if(this.src.indexOf('right')>=0)this.src = pathToImages + 'right_over.gif';	
	}
}

function highlightClose()
{
	if(this.src.indexOf('over')>=0){
		this.src = pathToImages + 'close.gif';
	}else{
		this.src = pathToImages + 'close_over.gif';	
	}	

}

function closeCalendar(){

	document.getElementById('yearDropDown').style.display='none';
	document.getElementById('monthDropDown').style.display='none';
	document.getElementById('hourDropDown').style.display='none';
	document.getElementById('minuteDropDown').style.display='none';
		
	calendarDiv.style.display='none';
	if(iframeObj){
		iframeObj.style.display='none';
		 //// //// fix for EI frame problem on time dropdowns 09/30/2006
			EIS_Hide_Frame();}
	if(activeSelectBoxMonth)activeSelectBoxMonth.className='';
	if(activeSelectBoxYear)activeSelectBoxYear.className='';
	

}

function writeTopBar()
{

	var topBar = document.createElement('DIV');
	topBar.className = 'topBar';
	topBar.id = 'topBar';
	calendarDiv.appendChild(topBar);
	
	// Left arrow
	var leftDiv = document.createElement('DIV');
	leftDiv.style.marginRight = '1px';
	var img = document.createElement('IMG');
	img.src = pathToImages + 'left.gif';
	img.onmouseover = highlightArrow;
	img.onclick = switchMonth;
	img.onmouseout = highlightArrow;
	leftDiv.appendChild(img);	
	topBar.appendChild(leftDiv);
	if(Opera)leftDiv.style.width = '16px';
	
	// Month selector
	var monthDiv = document.createElement('DIV');
	monthDiv.id = 'monthSelect';
	monthDiv.onmouseover = highlightSelect;
	monthDiv.onmouseout = highlightSelect;
	monthDiv.onclick = showMonthDropDown;
	var span = document.createElement('SPAN');		
	span.innerHTML = monthArray[currentMonth];
	span.id = 'calendar_month_txt';
	monthDiv.appendChild(span);

	// Right arrow
	var rightDiv = document.createElement('DIV');
	rightDiv.style.marginRight = '1px';
	var img = document.createElement('IMG');
	img.src = pathToImages + 'right.gif';
	img.onclick = switchMonth;
	img.onmouseover = highlightArrow;
	img.onmouseout = highlightArrow;
	rightDiv.appendChild(img);
	if(Opera)rightDiv.style.width = '16px';
	topBar.appendChild(rightDiv);		

			
	var img = document.createElement('IMG');
	img.src = pathToImages + 'down.gif';
	img.style.position = 'absolute';
	img.style.right = '0px';
	monthDiv.appendChild(img);
	monthDiv.className = 'selectBox';
	if(Opera){
		img.style.cssText = 'float:right;position:relative';
		img.style.position = 'relative';
		img.style.styleFloat = 'right';
	}
	topBar.appendChild(monthDiv);

	var monthPicker = createMonthDiv();
	monthPicker.style.left = '37px';
	monthPicker.style.top = monthDiv.offsetTop + monthDiv.offsetHeight + 1 + 'px';
	monthPicker.style.width ='60px';
	monthPicker.id = 'monthDropDown';
	
	calendarDiv.appendChild(monthPicker);
			
	// Year selector
	var yearDiv = document.createElement('DIV');
	yearDiv.onmouseover = highlightSelect;
	yearDiv.onmouseout = highlightSelect;
	yearDiv.onclick = showYearDropDown;
	var span = document.createElement('SPAN');		
	span.innerHTML = currentYear;
	span.id = 'calendar_year_txt';
	yearDiv.appendChild(span);
	topBar.appendChild(yearDiv);
	
	var img = document.createElement('IMG');
	img.src = pathToImages + 'down.gif';
	yearDiv.appendChild(img);
	yearDiv.className = 'selectBox';
	
	if(Opera){
		yearDiv.style.width = '50px';
		img.style.cssText = 'float:right';
		img.style.position = 'relative';
		img.style.styleFloat = 'right';
	}	
	
	var yearPicker = createYearDiv();
	yearPicker.style.left = '113px';
	yearPicker.style.top = monthDiv.offsetTop + monthDiv.offsetHeight + 1 + 'px';
	yearPicker.style.width = '35px';
	yearPicker.id = 'yearDropDown';
	calendarDiv.appendChild(yearPicker);
	
		
	var img = document.createElement('IMG');
	img.src = pathToImages + 'close.gif';
	img.style.styleFloat = 'right';
	img.onmouseover = highlightClose;
	img.onmouseout = highlightClose;
	img.onclick = closeCalendar;
	topBar.appendChild(img);
	if(!document.all){
		img.style.position = 'absolute';
		img.style.right = '2px';
	}
	
	

}

function writeCalendarContent()
{
	var calendarContentDivExists = true;
	if(!calendarContentDiv){
		calendarContentDiv = document.createElement('DIV');
		calendarDiv.appendChild(calendarContentDiv);
		calendarContentDivExists = false;
	}
	currentMonth = currentMonth/1;
	var d = new Date();	
	
	d.setFullYear(currentYear);		
	d.setDate(1);		
	d.setMonth(currentMonth);
	
	var dayStartOfMonth = d.getDay();
	if(dayStartOfMonth==0)dayStartOfMonth=7;
	dayStartOfMonth--;
	
	document.getElementById('calendar_year_txt').innerHTML = currentYear;
	document.getElementById('calendar_month_txt').innerHTML = monthArray[currentMonth];
	document.getElementById('calendar_hour_txt').innerHTML = currentHour;
	document.getElementById('calendar_minute_txt').innerHTML = currentMinute;
	
	var existingTable = calendarContentDiv.getElementsByTagName('TABLE');
	if(existingTable.length>0){
		calendarContentDiv.removeChild(existingTable[0]);
	}
	
	var calTable = document.createElement('TABLE');
	calTable.width = '100%';
	calTable.cellSpacing = '0';
	calendarContentDiv.appendChild(calTable);
	


	
	var calTBody = document.createElement('TBODY');
	calTable.appendChild(calTBody);
	var row = calTBody.insertRow(-1);
	row.className = 'calendar_week_row';
	var cell = row.insertCell(-1);
	cell.innerHTML = weekString;
	cell.className = 'calendar_week_column';
	cell.style.backgroundColor = selectBoxRolloverBgColor;
	cell.style.color = "#fff";
	
	for(var no=0;no<dayArray.length;no++){
		var cell = row.insertCell(-1);
		cell.innerHTML = dayArray[no]; 
	}
	
	var row = calTBody.insertRow(-1);
	var cell = row.insertCell(-1);
	cell.className = 'calendar_week_column';
	cell.style.backgroundColor = selectBoxRolloverBgColor;
	cell.style.color = "#fff";
	var week = getWeek(currentYear,currentMonth,1);
	cell.innerHTML = week;		// Week
	for(var no=0;no<dayStartOfMonth;no++){
		var cell = row.insertCell(-1);
		cell.innerHTML = '&nbsp;';
	}

	var colCounter = dayStartOfMonth;
	var daysInMonth = daysInMonthArray[currentMonth];
	if(daysInMonth==28){
		if(isLeapYear(currentYear))daysInMonth=29;
	}
	
	for(var no=1;no<=daysInMonth;no++){
		d.setDate(no-1);
		if(colCounter>0 && colCounter%7==0){
			var row = calTBody.insertRow(-1);
			var cell = row.insertCell(-1);
			cell.className = 'calendar_week_column';
			var week = getWeek(currentYear,currentMonth,no);
			cell.innerHTML = week;		// Week	
			cell.style.backgroundColor = selectBoxRolloverBgColor;			
			cell.style.color = "#fff";
		}
		var cell = row.insertCell(-1);
		if(currentYear==inputYear && currentMonth == inputMonth && no==inputDay){
			cell.className='activeDay';	
		}
		cell.innerHTML = no;
		cell.onclick = pickDate;
		colCounter++;
	}
	
	
	if(!document.all){
		if(calendarContentDiv.offsetHeight)
			document.getElementById('topBar').style.top = calendarContentDiv.offsetHeight + document.getElementById('timeBar').offsetHeight + document.getElementById('topBar').offsetHeight -1 + 'px';
		else{
			document.getElementById('topBar').style.top = '';
			document.getElementById('topBar').style.bottom = '0px';
		}
			
	}
	
	if(iframeObj){
		if(!calendarContentDivExists)setTimeout('resizeIframe()',350);else setTimeout('resizeIframe()',10);
	}
	
	
		
	
}

function resizeIframe()
{
	iframeObj.style.width = calendarDiv.offsetWidth + 'px';
	iframeObj.style.height = calendarDiv.offsetHeight + 'px' ;	
	
	
}

function pickTodaysDate()
{
	var d = new Date();
	currentMonth = d.getMonth();
	currentYear = d.getFullYear();
	pickDate(false,d.getDate());
	
}

function pickDate(e,inputDay)
{
	var month = currentMonth/1 +1;
	if(month<10)month = '0' + month;
	var day;
	if(!inputDay && this)day = this.innerHTML; else day = inputDay;
	
	if(day/1<10)day = '0' + day;
	if(returnFormat){
		returnFormat = returnFormat.replace('dd',day);
		returnFormat = returnFormat.replace('mm',month);
		returnFormat = returnFormat.replace('yyyy',currentYear);
		returnFormat = returnFormat.replace('hh',currentHour);
		returnFormat = returnFormat.replace('ii',currentMinute);
		returnFormat = returnFormat.replace('d',day/1);
		returnFormat = returnFormat.replace('m',month/1);
	
		returnDateTo.value = returnFormat;
		try{
			returnDateTo.onchange();
		}catch(e){
			
		}
	}else{
		for(var no=0;no<returnDateToYear.options.length;no++){
			if(returnDateToYear.options[no].value==currentYear){
				returnDateToYear.selectedIndex=no;
				break;
			}				
		}
		for(var no=0;no<returnDateToMonth.options.length;no++){			
			if(returnDateToMonth.options[no].value==parseInt(month)){
				returnDateToMonth.selectedIndex=no;
				break;
			}				
		}
		for(var no=0;no<returnDateToDay.options.length;no++){
			if(returnDateToDay.options[no].value==parseInt(day)){
				returnDateToDay.selectedIndex=no;
				break;
			}				
		}		
		if(calendarDisplayTime){
			for(var no=0;no<returnDateToHour.options.length;no++){
				if(returnDateToHour.options[no].value==parseInt(currentHour)){
					returnDateToHour.selectedIndex=no;
					break;
				}				
			}			
			for(var no=0;no<returnDateToMinute.options.length;no++){
				if(returnDateToMinute.options[no].value==parseInt(currentMinute)){
					returnDateToMinute.selectedIndex=no;
					break;
				}				
			}		
		}		
	}
	closeCalendar();
	
}

// This function is from http://www.codeproject.com/csharp/gregorianwknum.asp
// Only changed the month add
function getWeek(year,month,day){
	day = day/1;
	year = year /1;
    month = month/1 + 1; //use 1-12
    var a = Math.floor((14-(month))/12);
    var y = year+4800-a;
    var m = (month)+(12*a)-3;
    var jd = day + Math.floor(((153*m)+2)/5) + 
                 (365*y) + Math.floor(y/4) - Math.floor(y/100) + 
                 Math.floor(y/400) - 32045;      // (gregorian calendar)
    var d4 = (jd+31741-(jd%7))%146097%36524%1461;
    var L = Math.floor(d4/1460);
    var d1 = ((d4-L)%365)+L;
    NumberOfWeek = Math.floor(d1/7) + 1;
    return NumberOfWeek;        
}

function writeTimeBar()
{
	var timeBar = document.createElement('DIV');
	timeBar.id = 'timeBar';
	timeBar.className = 'timeBar';	
	
	var subDiv = document.createElement('DIV');
	subDiv.innerHTML = 'Time:';
	//timeBar.appendChild(subDiv);
	
	// Year selector
	var hourDiv = document.createElement('DIV');
	hourDiv.onmouseover = highlightSelect;
	hourDiv.onmouseout = highlightSelect;
	hourDiv.onclick = showHourDropDown;
	hourDiv.style.width = '30px';
	var span = document.createElement('SPAN');		
	span.innerHTML = currentHour;
	span.id = 'calendar_hour_txt';
	hourDiv.appendChild(span);
	timeBar.appendChild(hourDiv);
	
	var img = document.createElement('IMG');
	img.src = pathToImages + 'down_time.gif';
	hourDiv.appendChild(img);
	hourDiv.className = 'selectBoxTime';
	
	if(Opera){
		hourDiv.style.width = '30px';
		img.style.cssText = 'float:right';
		img.style.position = 'relative';
		img.style.styleFloat = 'right';
	}	
	
	var hourPicker = createHourDiv();
	hourPicker.style.left = '130px';
	//hourPicker.style.top = monthDiv.offsetTop + monthDiv.offsetHeight + 1 + 'px';
	hourPicker.style.width = '35px';
	hourPicker.id = 'hourDropDown';
	calendarDiv.appendChild(hourPicker);
	
	// Add Minute picker
	
	// Year selector
	var minuteDiv = document.createElement('DIV');
	minuteDiv.onmouseover = highlightSelect;
	minuteDiv.onmouseout = highlightSelect;
	minuteDiv.onclick = showMinuteDropDown;
	minuteDiv.style.width = '30px';
	var span = document.createElement('SPAN');		
	span.innerHTML = currentMinute;

	span.id = 'calendar_minute_txt';
	minuteDiv.appendChild(span);
	timeBar.appendChild(minuteDiv);
	
	var img = document.createElement('IMG');
	img.src = pathToImages + 'down_time.gif';
	minuteDiv.appendChild(img);
	minuteDiv.className = 'selectBoxTime';
	
	if(Opera){
		minuteDiv.style.width = '30px';
		img.style.cssText = 'float:right';
		img.style.position = 'relative';
		img.style.styleFloat = 'right';
	}	
	
	var minutePicker = createMinuteDiv();
	minutePicker.style.left = '167px';
	//minutePicker.style.top = monthDiv.offsetTop + monthDiv.offsetHeight + 1 + 'px';
	minutePicker.style.width = '35px';
	minutePicker.id = 'minuteDropDown';
	calendarDiv.appendChild(minutePicker);
		
	
	return timeBar;
	
}

function writeBottomBar()
{
	var d = new Date();
	var bottomBar = document.createElement('DIV');	
	
	bottomBar.id = 'bottomBar';
	
	bottomBar.style.cursor = 'pointer';
	bottomBar.className = 'todaysDate';
	// var todayStringFormat = '[todayString] [dayString] [day] [monthString] [year]';	;;
	
	var subDiv = document.createElement('DIV');
	subDiv.onclick = pickTodaysDate;
	subDiv.id = 'todaysDateString';
	subDiv.style.width = (calendarDiv.offsetWidth - 95) + 'px';
	var day = d.getDay();
	if(day==0)day = 7;
	day--;
	
	var bottomString = todayStringFormat;
	bottomString = bottomString.replace('[monthString]',monthArrayShort[d.getMonth()]);
	bottomString = bottomString.replace('[day]',d.getDate());
	bottomString = bottomString.replace('[year]',d.getFullYear());
	bottomString = bottomString.replace('[dayString]',dayArray[day].toLowerCase());
	bottomString = bottomString.replace('[UCFdayString]',dayArray[day]);
	bottomString = bottomString.replace('[todayString]',todayString);
	
	
	subDiv.innerHTML = todayString + ': ' + d.getDate() + '. ' + monthArrayShort[d.getMonth()] + ', ' +  d.getFullYear() ;
	subDiv.innerHTML = bottomString ;
	bottomBar.appendChild(subDiv);
	
	var timeDiv = writeTimeBar();
	bottomBar.appendChild(timeDiv);
	
	calendarDiv.appendChild(bottomBar);	
	
	
		
}
function getTopPos(inputObj)
{
	
  var returnValue = inputObj.offsetTop + inputObj.offsetHeight;
  while((inputObj = inputObj.offsetParent) != null)returnValue += inputObj.offsetTop;
  return returnValue + calendar_offsetTop;
}

function getleftPos(inputObj)
{
  var returnValue = inputObj.offsetLeft;
  while((inputObj = inputObj.offsetParent) != null)returnValue += inputObj.offsetLeft;
  return returnValue + calendar_offsetLeft;
}

function positionCalendar(inputObj)
{
	calendarDiv.style.left = getleftPos(inputObj) + 'px';
	calendarDiv.style.top = getTopPos(inputObj) + 'px';
	if(iframeObj){
		iframeObj.style.left = calendarDiv.style.left;
		iframeObj.style.top =  calendarDiv.style.top;
		//// fix for EI frame problem on time dropdowns 09/30/2006
		iframeObj2.style.left = calendarDiv.style.left;
		iframeObj2.style.top =  calendarDiv.style.top;
	}
		
}
	
function initCalendar()
{
	if(MSIE){
		iframeObj = document.createElement('IFRAME');
		iframeObj.style.filter = 'alpha(opacity=0)';
		iframeObj.style.position = 'absolute';
		iframeObj.border='0px';
		iframeObj.style.border = '0px';
		iframeObj.style.backgroundColor = '#FF0000';
		//// fix for EI frame problem on time dropdowns 09/30/2006
		iframeObj2 = document.createElement('IFRAME');
		iframeObj2.style.position = 'absolute';
		iframeObj2.border='0px';
		iframeObj2.style.border = '0px';
		iframeObj2.style.height = '1px';
		iframeObj2.style.width = '1px';
		document.body.appendChild(iframeObj2);
		//// fix for EI frame problem on time dropdowns 09/30/2006
		// Added fixed for HTTPS
//		iframeObj2.src = 'blank.html'; 
//		iframeObj.src = 'blank.html'; 
		document.body.appendChild(iframeObj);
	}
		
	calendarDiv = document.createElement('DIV');	
	calendarDiv.id = 'calendarDiv';
	calendarDiv.style.zIndex = 1000;
	slideCalendarSelectBox();
	
	document.body.appendChild(calendarDiv);	
	writeBottomBar();	
	writeTopBar();
	
	
	
	if(!currentYear){
		var d = new Date();
		currentMonth = d.getMonth();
		currentYear = d.getFullYear();
	}
	writeCalendarContent();	


		
}

function setTimeProperties()
{
	if(!calendarDisplayTime){
		document.getElementById('timeBar').style.display='none'; 
		document.getElementById('timeBar').style.visibility='hidden'; 
		document.getElementById('todaysDateString').style.width = '100%';
		
			
	}else{ 
		document.getElementById('timeBar').style.display='block';
		document.getElementById('timeBar').style.visibility='visible';
		document.getElementById('hourDropDown').style.top = document.getElementById('calendar_minute_txt').parentNode.offsetHeight + calendarContentDiv.offsetHeight + document.getElementById('topBar').offsetHeight + 'px';
		document.getElementById('minuteDropDown').style.top = document.getElementById('calendar_minute_txt').parentNode.offsetHeight + calendarContentDiv.offsetHeight + document.getElementById('topBar').offsetHeight + 'px';
		document.getElementById('minuteDropDown').style.right = '50px';
		document.getElementById('hourDropDown').style.right = '50px';
		document.getElementById('todaysDateString').style.width = '115px';
	}	
}

function calendarSortItems(a,b)
{
	return a/1 - b/1;
}


function displayCalendar(inputField,format,buttonObj,displayTime,timeInput)
{
	if(displayTime)calendarDisplayTime=true; else calendarDisplayTime = false;
	if(inputField.value.length>0){
		
		if(!format.match(/^[0-9]*?$/gi)){
			var items = inputField.value.split(/[^0-9]/gi);
			var positionArray = new Array();
			positionArray['m'] = format.indexOf('mm');
			if(positionArray['m']==-1)positionArray['m'] = format.indexOf('m');
			positionArray['d'] = format.indexOf('dd');
			if(positionArray['d']==-1)positionArray['d'] = format.indexOf('d');
			positionArray['y'] = format.indexOf('yyyy');
			positionArray['h'] = format.indexOf('hh');
			positionArray['i'] = format.indexOf('ii');
			
			var positionArrayNumeric = Array();
			positionArrayNumeric[0] = positionArray['m'];
			positionArrayNumeric[1] = positionArray['d'];
			positionArrayNumeric[2] = positionArray['y'];
			positionArrayNumeric[3] = positionArray['h'];
			positionArrayNumeric[4] = positionArray['i'];
			
			
			positionArrayNumeric = positionArrayNumeric.sort(calendarSortItems);
			var itemIndex = -1;
			currentHour = '00';
			currentMinute = '00';
			for(var no=0;no<positionArrayNumeric.length;no++){
				if(positionArrayNumeric[no]==-1)continue;
				itemIndex++;
				if(positionArrayNumeric[no]==positionArray['m']){
					currentMonth = items[itemIndex]-1;
					continue;
				}
				if(positionArrayNumeric[no]==positionArray['y']){
					currentYear = items[itemIndex];
					continue;
				}	
				if(positionArrayNumeric[no]==positionArray['d']){
					tmpDay = items[itemIndex];
					continue;
				}	
				if(positionArrayNumeric[no]==positionArray['h']){
					currentHour = items[itemIndex];
					continue;
				}	
				if(positionArrayNumeric[no]==positionArray['i']){
					currentMinute = items[itemIndex];
					continue;
				}	
			}

			currentMonth = currentMonth / 1;
			tmpDay = tmpDay / 1;
		}else{		
			var monthPos = format.indexOf('mm');
			currentMonth = inputField.value.substr(monthPos,2)/1 -1;	
			var yearPos = format.indexOf('yyyy');
			currentYear = inputField.value.substr(yearPos,4);		
			var dayPos = format.indexOf('dd');
			tmpDay = inputField.value.substr(dayPos,2);		
			
			var hourPos = format.indexOf('hh');
			if(hourPos>=0){
				tmpHour = inputField.value.substr(hourPos,2);	
				currentHour = tmpHour;
			}else{
				currentHour = '00';
			}
			var minutePos = format.indexOf('ii');
			if(minutePos>=0){
				tmpMinute = inputField.value.substr(minutePos,2);	
				currentMinute = tmpMinute;
			}else{
				currentMinute = '00';
			}	
		}
	}else{
		var d = new Date();
		currentMonth = d.getMonth();
		currentYear = d.getFullYear();
		currentHour = '08';
		currentMinute = '00';
		tmpDay = d.getDate();
	}
	
	inputYear = currentYear;
	inputMonth = currentMonth;
	inputDay = tmpDay/1;
	
	
	if(!calendarDiv){
		initCalendar();			
	}else{
		if(calendarDiv.style.display=='block'){
			closeCalendar();
			return false;
		}
		writeCalendarContent();
	}	
	
	
			
	returnFormat = format;
	returnDateTo = inputField;
	positionCalendar(buttonObj);
	calendarDiv.style.visibility = 'visible';	
	calendarDiv.style.display = 'block';	
	if(iframeObj){
		iframeObj.style.display = '';
		iframeObj.style.height = '140px';
		iframeObj.style.width = '195px';
				iframeObj2.style.display = '';
		iframeObj2.style.height = '140px';
		iframeObj2.style.width = '195px';
	}
	
	setTimeProperties();	
	updateYearDiv();
	updateMonthDiv();
	updateMinuteDiv();
	updateHourDiv();
	
}

function displayCalendarSelectBox(yearInput,monthInput,dayInput,hourInput,minuteInput,buttonObj)
{
	if(!hourInput)calendarDisplayTime=false; else calendarDisplayTime = true;
	
	currentMonth = monthInput.options[monthInput.selectedIndex].value/1-1;
	currentYear = yearInput.options[yearInput.selectedIndex].value;
	if(hourInput){
		currentHour = hourInput.options[hourInput.selectedIndex].value;
		inputHour = currentHour/1;
	}
	if(minuteInput){
		currentMinute = minuteInput.options[minuteInput.selectedIndex].value;
		inputMinute = currentMinute/1;
	}
	
	inputYear = yearInput.options[yearInput.selectedIndex].value;
	inputMonth = monthInput.options[monthInput.selectedIndex].value/1 - 1;
	inputDay = dayInput.options[dayInput.selectedIndex].value/1;
			
	if(!calendarDiv){
		initCalendar();			
	}else{
		writeCalendarContent();
	}		

	
	
	returnDateToYear = yearInput;
	returnDateToMonth = monthInput;
	returnDateToDay = dayInput;
	returnDateToHour = hourInput; 	
	returnDateToMinute = minuteInput; 	

	

	
	returnFormat = false;
	returnDateTo = false;
	positionCalendar(buttonObj);
	calendarDiv.style.visibility = 'visible';	
	calendarDiv.style.display = 'block';
	if(iframeObj){
		iframeObj.style.display = '';
		iframeObj.style.height = calendarDiv.offsetHeight + 'px';
		iframeObj.style.width = calendarDiv.offsetWidth + 'px';	
		//// fix for EI frame problem on time dropdowns 09/30/2006
		iframeObj2.style.display = '';
		iframeObj2.style.height = calendarDiv.offsetHeight + 'px';
		iframeObj2.style.width = calendarDiv.offsetWidth + 'px'
	}
	setTimeProperties();
	updateYearDiv();
	updateMonthDiv();
	updateHourDiv();
	updateMinuteDiv();
		
}


var transtext=new Array();
transtext.pl=new Array();
transtext.en=new Array();
transtext.de=new Array();

String.prototype.trim = function() { return this.replace(/^\s+|\s+$/, ''); };


var dALL;
var cities;
var get=new Array();
var url=new String(window.location);
url.replace(new RegExp('#.*$/'),'');
url=url.split('?');
url=url[1];
if (url)
   {
   url=url.split('&');
   for (k in url)
      {
      var param=url[k].split('=');
      get[unescape(param[0])]=unescape(param[1]);
      }
   }

function fillform(formname)
{
for (k in get)
   if (document.forms[formname].elements[k])
   {
      var el=document.forms[formname].elements[k];
         el.value=get[k];
   }
}


function formval(formname,field)
    {
    var el=document.forms[formname].elements[field];
    if(el.length)
	{
        var i,el2;
        for(i=0;i<el.length;i++)
    	    {
    	    el2=el[i];
    	    if((el2.type=='radio') && (el2.checked))
		return el2.value;
            }
         }
    if((el.tagName=='INPUT') || (el.tagName=='TEXTAREA') || (el.tagName=='SELECT'))
	{
        if (el.type=='checkbox')
    	    {
    	    if (el.checked)
		return el.value;
    	    }
	    else 
		return el.value;
        }
    return false;
    }

function redirect(x)
   {
   var oldTID=formval("searchform","TID");
   var TID;
   var PID=formval("searchform","PID");
   var el=document.searchform.TID
   var set=false;
   el.length=0;
   if (dALL) el.options.add(new Option(dALL,0));
   var i;
   for (cityname in cities[PID])
      {
      if (oldTID==cities[PID][cityname])
      {
          el.options.add(new Option(cityname,cities[PID][cityname],true));
	  set=true;
      }
      else
          el.options.add(new Option(cityname,cities[PID][cityname]));
      }
   if (set)
      {
      document.searchform.TID.value=oldTID;
      }
   }



function manage_search()
{
dALL=false;
cities=new Array();
cities[0]=new Array();
var c=new Array();
var i;
for (var i=0;i<document.forms['searchform']['TID'].options.length;i++)
   {
   var el=document.forms['searchform']['TID'].options[i];
   var TID=el.value;
   if (TID>0)
      {
      var PID=el.id.replace('P'+TID+'_','');
      if (!cities[PID]) cities[PID]=new Array();
      cities[PID][el.text]=TID;
      cities[0][el.text]=TID;
      }
   if (TID==0)
      {
      dALL=el.text;
      }
   }
   fillform('searchform');
   redirect(0);
}





function get_absolute_pos(obj)
{
var oLeft=0;
var oTop=0;
while(obj.offsetParent)
{
oLeft+=obj.offsetLeft;
oTop+=obj.offsetTop;

if (navigator.userAgent.indexOf('MSIE'))
{
if (obj.style.marginTop.replace("px","")>0) oTop-=obj.style.marginTop.replace("px","");
if (obj.style.margin.replace("px","")>0) oTop-=obj.style.margin.replace("px","");
if (obj.style.paddingTop.replace("px","")>0) oTop-=obj.style.paddingTop.replace("px","");
if (obj.style.padding.replace("px","")>0) oTop-=obj.style.padding.replace("px","");

if (obj.style.marginLeft.replace("px","")>0) oLeft-=obj.style.marginLeft.replace("px","");
if (obj.style.margin.replace("px","")>0) oLeft-=obj.style.margin.replace("px","");
if (obj.style.paddingLeft.replace("px","")>0) oLeft-=obj.style.paddingLeft.replace("px","");
if (obj.style.padding.replace("px","")>0) oLeft-=obj.style.padding.replace("px","");
}

obj=obj.offsetParent;
}
return [oLeft, oTop];

}


function f_filterResults(n_win, n_docel, n_body)
{
	var n_result = n_win ? n_win : 0;
	if (n_docel && (!n_result || (n_result > n_docel)))
		n_result = n_docel;
	return n_body && (!n_result || (n_result > n_body)) ? n_body : n_result;
}



function get_window_size()
{
	var width=f_filterResults (
		window.innerWidth ? window.innerWidth : 0,
		document.documentElement ? document.documentElement.clientWidth : 0,
		document.body ? document.body.clientWidth : 0
	);
	var height=f_filterResults (
		window.innerHeight ? window.innerHeight : 0,
		document.documentElement ? document.documentElement.clientHeight : 0,
		document.body ? document.body.clientHeight : 0
	);
	return [width,height];
}

function get_window_pos()
{
	var left=f_filterResults (
		window.pageXOffset ? window.pageXOffset : 0,
		document.documentElement ? document.documentElement.scrollLeft : 0,
		document.body ? document.body.scrollLeft : 0
	);
	var top=f_filterResults (
		window.pageYOffset ? window.pageYOffset : 0,
		document.documentElement ? document.documentElement.scrollTop : 0,
		document.body ? document.body.scrollTop : 0
	);
	return [left,top];
}


function get_element_size(obj)
{
    var width=obj.offsetWidth;
    var height=obj.offsetHeight;
    
    if (obj.style.paddingTop>0) height+=obj.style.paddingTop;
    if (obj.style.paddingBottom>0) height+=obj.style.paddingBottom;
    if (obj.style.padding>0) height+=obj.style.padding;

if (navigator.userAgent.indexOf('MSIE'))
{
    if (obj.style.marginTop>0) height-=obj.style.marginTop;
    if (obj.style.marginBottom>0) height-=obj.style.marginBottom;
    if (obj.style.margin>0) height-=obj.style.margin;
}
    return [width,height];
}

function tooltip(p_id,p_content,id2)
{
    var control=(typeof id2==='string')?document.getElementById(id2):id2;
    var id=p_id;
    var content=p_content;
    var intervalid;
    var oldwinpos;
    var oldwinsize;
    
    this.remove=function()
    {
	var container=document.getElementById('tooltip_'+id);
	if (container)
	    container.parentNode.removeChild(container);
	    
	if (this.intervalid)
	    clearInterval(this.intervalid);
    }
    
    this.interval=function()
    {
	var winpos=get_window_pos();
	var winsize=get_window_size();
	var container=document.getElementById('tooltip_'+id);
	if (!container)
	{
	    if (this.intervalid)
	        clearInterval(this.intervalid);
	    return;
	}
	if (this.oldwinpos)
	{
	if ((this.oldwinpos[0]!=winpos[0]) || (this.oldwinpos[1]!=winpos[1]) || (this.oldwinsize[0]!=winsize[0]) || (this.oldwinsize[1]!=winsize[1]))
	{
	this.remove();
	this.draw();
	}
	}
	this.oldwinpos=winpos;
	this.oldwinsize=winsize;
    }


    
    this.draw=function()
    {
	this.remove();

	var container;
	var containerinner;
	
	container=document.createElement('div');
        container.setAttribute('id', 'tooltip_'+id);
	container.style.zIndex=100;
	container.style.background="white";
	container.style.border="1px solid gray";

	containerinner=document.createElement('div');
        containerinner.innerHTML=content;
        containerinner.style.display="inline";

        container.appendChild(containerinner);
        document.body.appendChild(container);

	container.style.position="absolute";
        containerinner.style.position="relative";
	container.style.padding=5+"px";


        container.style.paddingRight=25+"px";
	var closelink=document.createElement("a");
	closelink.innerHTML="<img src='/hotele_gfx_pl_szczecin/hotele_closetip.png'>";
	closelink.style.zIndex=100;
	closelink.style.position="absolute";
	closelink.style.cursor="pointer";
	closelink.style.right=5+"px";
	closelink.style.top=5+"px";
	closelink.onclick=this.remove;

	container.appendChild(closelink);

        var pos=get_absolute_pos(control);
        var size=get_element_size(control);
        var size2=get_element_size(container);


        if((control.tagName=='INPUT') )
	{
	pos[0]+=size[0];
	pos[1]+=0;
	}
	else
	{
	pos[0]+=size[0]/2;
	pos[1]+=size[1]/2;
	}
	
	var pos2=new Array(pos[0],pos[1]);
	var winpos=get_window_pos();
	var winsize=get_window_size();
	
	pos2[0]-=winpos[0];
	pos2[1]-=winpos[1];


        var img=document.createElement('img');
        container.appendChild(img);
        img.style.position="absolute";
	var shift;
	
	if (container.offsetWidth<100)
	   container.style.width=100+"px";
	
	shift=220;
	shift=container.offsetWidth-80;
	
	if (pos[0]-shift<10)
	   shift=0;


	
	img.style.left=shift+"px";
	imgoffsetHeight=20; // MSIE & FF hack
	
	if (pos2[1]>winsize[1]/2)
	{
	    pos[1]-=(size2[1]+10); // nad
    	    img.setAttribute('src', "/hotele_gfx_pl_szczecin/hotele_dymek1.gif");
	    img.style.top=(container.offsetHeight-2)+"px";
	}
	else
	{
	    pos[1]+=(imgoffsetHeight+10);
    	    img.setAttribute('src', "/hotele_gfx_pl_szczecin/hotele_dymek2.gif");
	    img.style.top=(-imgoffsetHeight)+"px";
	}
	
        container.style.left=(pos[0]-shift)+"px";
	container.style.top=(pos[1])+"px";
	container.style.position="absolute";

        this.intervalid=setInterval(this.interval,500);
    }

    this.draw();
    return this;
}



// domy¶lny kierunek sortowania w kolumnach
var sortcols=new Array();
sortcols["wyniki1"]=new Array();
sortcols["wyniki1"][1]=0;
sortcols["wyniki1"][2]=0;
sortcols["wyniki1"][3]=1;

sortcols["wyniki2"]=new Array();
sortcols["wyniki2"][1]=0;
sortcols["wyniki2"][2]=0;
sortcols["wyniki2"][3]=1;

sortcols["wyniki"]=new Array();
sortcols["wyniki"][1]=0;
sortcols["wyniki"][2]=0;
sortcols["wyniki"][3]=1;

function sortfunc_wyniki1_1_up(a,b)
{
    var l1,l2;
    l1=a.cells[1].abbr;
    l2=b.cells[1].abbr;
    if (l1<l2) return -1;
    if (l1>l2) return 1;
    return 0;
}
function sortfunc_wyniki1_1_down(a,b)
{
    return (-sortfunc_wyniki1_1_up(a,b));
}


function sortfunc_wyniki1_2_up(a,b)
{
    var l1,l2;
    l1=parseInt(a.cells[2].abbr);
    l2=parseInt(b.cells[2].abbr);
    return l1-l2;
}
function sortfunc_wyniki1_2_down(a,b)
{
    return (-sortfunc_wyniki1_2_up(a,b));
}


function sortfunc_wyniki1_3_up(a,b)
{
    var l1,l2;
    l1=parseInt(a.cells[3].abbr);
    l2=parseInt(b.cells[3].abbr);
    return l1-l2;
}
function sortfunc_wyniki1_3_down(a,b)
{
    return (-sortfunc_wyniki1_3_up(a,b));
}




function sortfunc_wyniki2_1_up(a,b) { return (sortfunc_wyniki1_1_up(a,b)); }
function sortfunc_wyniki2_2_up(a,b) { return (sortfunc_wyniki1_2_up(a,b)); }
function sortfunc_wyniki2_3_up(a,b) { return (sortfunc_wyniki1_3_up(a,b)); }
function sortfunc_wyniki2_1_down(a,b) { return (sortfunc_wyniki1_1_down(a,b)); }
function sortfunc_wyniki2_2_down(a,b) { return (sortfunc_wyniki1_2_down(a,b)); }
function sortfunc_wyniki2_3_down(a,b) { return (sortfunc_wyniki1_3_down(a,b)); }


function sortfunc_wyniki_1_up(a,b) { return (sortfunc_wyniki1_1_up(a,b)); }
function sortfunc_wyniki_2_up(a,b) { return (sortfunc_wyniki1_2_up(a,b)); }
function sortfunc_wyniki_3_up(a,b) { return (sortfunc_wyniki1_3_up(a,b)); }
function sortfunc_wyniki_1_down(a,b) { return (sortfunc_wyniki1_1_down(a,b)); }
function sortfunc_wyniki_2_down(a,b) { return (sortfunc_wyniki1_2_down(a,b)); }
function sortfunc_wyniki_3_down(a,b) { return (sortfunc_wyniki1_3_down(a,b)); }





function sorttable(t_id,col)
{
    var i;

    if (sortcols[t_id][col]!=0)
	sortcols[t_id][col]=-sortcols[t_id][col];
    else
    {
	for (i in sortcols[t_id])
	{
	    if (i!=col)
		sortcols[t_id][i]=0;
	    else
		sortcols[t_id][i]=1;
	}
    }
    el=document.getElementById(t_id);

    for (i in sortcols[t_id])
    {
	var icon=document.getElementById("sorticon_"+t_id+"_"+i);
	if (sortcols[t_id][i]==-1)
	    icon.className="sort_up";
	else
	if (sortcols[t_id][i]==1)
    	    icon.className="sort_down";
	else
    	    icon.className="sort_none";
    }

    var newRows = new Array();
    for (i=0;i<el.tBodies[0].rows.length;i++)
        newRows[i]=el.tBodies[0].rows[i];

    var func;
    if (sortcols[t_id][col]==-1)
        func="sortfunc_"+t_id+"_"+col+"_down";
    else
        func="sortfunc_"+t_id+"_"+col+"_up";

    newRows.sort(eval(func));

    for (i=0;i<newRows.length;i++)
        el.tBodies[0].appendChild(newRows[i]);
}


function OpenHotelRating(src) { 
var w=490;
var s=654;

var l=(screen.width-w)/2;
var t=(screen.height-s)/2;
Nowe= window.open(src,"rating",'width=' + w + ',height=' + s + ',directories=no,resizable=0,scrollbars=yes,menubar=no,left=' + l + ',top=' + t);
Nowe.focus() 
} 

var mapfunc;

function afterload()
{
if (mapfunc) mapfunc();
for(var id in adbutler)
    document.getElementById('adbutler_'+id).src=adbutler[id];
//ajax('/'+languageCode+'/ajax_login.php');
};
transtext.en.incorrect_checkin="incorect arrival date format.\n\nPlease input date using  YYYY-MM-DD format.";
transtext.en.incorrect_checkout="incorect departure date format.\n\nPlease input date using YYYY-MM-DD format.";
transtext.en.checkinbeforetoday="the arrival date cannot be before today.";
transtext.en.checkoutbeforecheckin="the departure date cannot be before arrival date.";
transtext.en.checkoutafter60="departure date cannot be lower by more than 60 days from the date of the arrival";

transtext.pl.incorrect_checkin="Nieprawid³owy format Daty Przybycia.\n\nPrawid³owy format daty: YYYY-MM-DD.";
transtext.pl.incorrect_checkout="Nieprawid³owy format Daty Wyjazdu.\n\nPrawid³owy format daty: YYYY-MM-DD.";
transtext.pl.checkinbeforetoday="Data Przybycia nie mo¿e byæ wcze¶niejsza od daty dzisiejszej.";
transtext.pl.checkoutbeforecheckin="Data Wyjazdu musi byæ pó¼niejsza od Daty Przybycia.";
transtext.pl.checkoutafter60="Data Wyjazdu nie mo¿e byæ pó¼niejsza ni¿ 60 dni od Daty Przybycia.";

transtext.de.incorrect_checkin="Falsches Anreisedatumformat.\n\nRichtiges Datumformat JJJJ-MM-TT.";
transtext.de.incorrect_checkout="Falsches Abreisedatumformat.\n\nRichtiges Datumformat JJJJ-MM-TT.";
transtext.de.checkinbeforetoday="Anreisedatum sollte nicht früher als heutiges Datum sein.";
transtext.de.checkoutbeforecheckin="Abreisedatum musst später als Anreisedatum sein.";
transtext.de.checkoutafter60="Abreisedatum sollte nicht später als 60 Tage von Anreisetag sein.";

function daysinmonth(year,month)
    {
    var days=31;
    if (month==4 || month==6 || month==9 || month==11)
        days=30;
    else if (month==2)
        {
        if (((year % 4)==0) && ((year % 100)!=0) || ((year % 400)==0))
    	    days=29;
        else
    	    days=28;
        }
    return days;
    }


// koryguje date je¶li to mo¿liwe oraz zwraca czy jest poprawna
function correct_date(el)
{
    var t;
    var ret=true;
    var tmp;
    var date;
    t=el.value;

    t=t.replace(/\./g,"-");
    t=t.replace(/ /g,"-");

    var array=t.split('-');

    if (array.length==2) // 22.06
    {
	if (array[1]>12) // dzien jest drugi
	{
	    tmp=array[1];
	    array[1]=array[0];
	    array[0]=tmp;
	}
        date = new Date();
	array[2]=new String(date.getFullYear());
    }

    if (array.length!=3)
    	ret=false;


    if (ret)
    {
    var year = array[0];
    var month = array[1].charAt(0)=='0' ? parseInt(array[1].substr(1, 1)) : parseInt(array[1]);
    var day = array[2].charAt(0)=='0' ? parseInt(array[2].substr(1, 1)) : parseInt(array[2]);
    }

    if(day>2000)
    {
	tmp=day;
	day=year;
	year=tmp;
    }

    if (month>12) ret=false;
    if (month<1) ret=false;

    if (year<2000) ret=false;
    if (year>2100) ret=false;

    if (day<1) ret=false;
    if (day>daysinmonth(year,month)) ret=false;

    if (ret)
    {
	if (month<10) month='0'+month;
	if (day<10) day='0'+day;
	t=year+'-'+month+'-'+day;
        el.value=t;
    }
    return ret;
}

//
// Zamienia obiekt Date na string w formacie YYYY-MM-DD.
//
function formatDate(date)
{
	return date.getFullYear() + "-" + formatDatePart(date.getMonth()+1) +
		"-" + formatDatePart(date.getDate());
}

//
// Funkcja pomocnicza dla funckcji formatDate(). Dodaje znak '0' do czesci daty.
//
function formatDatePart(value)
{
	var v = String(value);
	return v.length==1 ? "0"+v : v;
}

//
// Dodaje dni do daty.
//
function addDaysToDate(date, numOfDays)
{
	return new Date(date.getFullYear(), date.getMonth(), date.getDate()+numOfDays);
}

//
// Zamienia string w formacie YYYY-MM-DD na obiekt typu Date.
//
function parseDate(dateString)
{
	var str = new String(dateString);
	var array = str.split('-');
	if (array.length!=3)
		return null;
	var year = array[0];
	var month = array[1].charAt(0)=='0' ? parseInt(array[1].substr(1, 1)) : parseInt(array[1]);
	var day = array[2].charAt(0)=='0' ? parseInt(array[2].substr(1, 1)) : parseInt(array[2]);
	var date = new Date(year, month-1, day);
	if (isNaN(date))
		return null;
	date.setHours(0);
	date.setMinutes(0);
	date.setSeconds(0);
	date.setMilliseconds(0);
	return date;
}

//
// Funkcja obslugi zdarzenia - zmiana wartosci w okienku edycyjnym ArrivalDate.
//
function onArrivalDateChange(form, arrivalDate, hotel)
{
	var arrivalDate = parseDate(arrivalDate);
	if (!correct_date(form[arrivalDateName]))
	{
		alert(transtext[languageCode].incorrect_checkin);
		form[arrivalDateName].focus();
		return false;
	}
	
	var today = new Date();
	today.setHours(0);
	today.setMinutes(0);
	today.setSeconds(0);
	today.setMilliseconds(0);
	
	if (arrivalDate < today)
	{
		alert(transtext[languageCode].checkinbeforetoday);
		return false;
	}

	var depDate = parseDate(form[departureDateName].value);
	if (depDate <= arrivalDate)
	{
		form[departureDateName].value = formatDate(addDaysToDate(arrivalDate, 1));
	}
}

//
// Funkcja obslugi zdarzenia - zmiana wartosci w okienku edycyjnym DepartureDate.
//
function onDepartureDateChange(form, departureDate)
{
	var arrivalDate = parseDate(form[arrivalDateName].value);
	if (!correct_date(form[arrivalDateName]))
	{
		alert(transtext[languageCode].incorrect_checkin);
		form[arrivalDateName].focus();
		return false;
	}
	
	var depDate = parseDate(departureDate);
	if (!correct_date(form[departureDateName]))
	{
		alert(transtext[languageCode].incorrect_checkout);
		form[departureDateName].focus();
		return false;
	}
	
	if (depDate <= arrivalDate)
	{
		form[departureDateName].focus();
		return false;	
	}
	if ((depDate-arrivalDate)/(1000*60*60*24) > 60)
	{
		alert(transtext[languageCode].checkoutafter60);
		form[departureDateName].focus();
		return false;
	}
}

function formSubmit(form)
{
	var today = new Date();
	today.setHours(0);
	today.setMinutes(0);
	today.setSeconds(0);
	today.setMilliseconds(0);
	
	var arrivalDate = parseDate(form[arrivalDateName].value);
	var depDate = parseDate(form[departureDateName].value);

	if (!correct_date(form[arrivalDateName]))
	{
		alert(transtext[languageCode].incorrect_checkin);
		form[arrivalDateName].focus();
		return false;
	}
	
	if (!correct_date(form[departureDateName]))
	{
		alert(transtext[languageCode].incorrect_checkout);
		form[departureDateName].focus();
		return false;
	}

	if (arrivalDate < today)
	{
		alert(transtext[languageCode].checkinbeforetoday);
		form[arrival].value = formatDate(today);
		form[arrivalDateName].focus();
		return false;
	}

	
	if (depDate <= arrivalDate)
	{
		alert(transtext[languageCode].checkoutbeforecheckin);
		form[departureDateName].value = formatDate(addDaysToDate(arrivalDate, 1));
		form[departureDateName].focus();
		return false;	
	}
	if ((depDate-arrivalDate)/(1000*60*60*24) > 60)
	{
		alert(transtext[languageCode].checkoutafter60);
		form[departureDateName].value = formatDate(addDaysToDate(arrivalDate, 60));
		form[departureDateName].focus();
		return false;
	}
	return true;
}
var timeshow=10000;
var step=10;

function set_scroller(id)
{
    this.el=document.getElementById(id);
    var i;

    for (i=0;i<this.el.childNodes.length;i++)
    {
    if (this.el.childNodes[i].tagName!="DIV")
        this.el.childNodes[i].parentNode.removeChild(this.el.childNodes[i]);
    }


    this.vis=Math.floor(Math.random()*this.el.childNodes.length);


    for (i=0;i<this.el.childNodes.length;i++)
    {
	this.el.childNodes[i].style.position='absolute';
        if (vis!=i)this.el.childNodes[i].style.display='none';
    }

    this.scroll=function()
    {
	try
	{
    	    var size=get_element_size(this.el);
	    var pos=new String(this.el.childNodes[this.vis].style.top).replace("px","");
	    var pos2=new String(this.el.childNodes[this.vis2].style.top).replace("px","");
	    this.el.childNodes[this.vis].style.top=(pos-10)+"px";
	    this.el.childNodes[this.vis2].style.top=(pos2-10)+"px";
	    if (-pos>=size[1]) 
	    {
		if (this.interval)
		    clearInterval(this.interval);

    		this.el.childNodes[vis].style.display='none';
		this.vis=this.vis2;
		this.el.childNodes[vis].style.display='block';
		this.el.childNodes[vis].style.top="0px";

		this.timeout=setTimeout(this.start_scroll,timeshow);
		var size2=get_element_size(this.el.childNodes[vis]);
        	this.el.style.height=((Math.ceil(size2[1]/step))*step)+"px";
	    }
	}
	catch(err)
	{
//	    this.onunload();
	}
    }

    this.start_scroll=function()
    {
        if (this.timeout)
            clearTimeout(this.timeout);

	var size=get_element_size(this.el);
	this.vis2=this.vis;


	while(this.vis2==this.vis)
	{
	    this.vis2=Math.floor(Math.random()*this.el.childNodes.length);
	}
	this.el.childNodes[this.vis2].style.top=((Math.ceil(size[1]/step))*step)+"px";
	this.el.childNodes[this.vis2].style.display='block';
	this.interval=setInterval(this.scroll,200);
    }

    this.onunload=function()
    {
        if (this.timeout)
            clearTimeout(this.timeout);
        if (this.interval)
            clearInterval(this.interval);
    }


    this.vis2=this.vis;
    this.el.childNodes[vis].style.display='block';
    this.el.childNodes[vis].style.top="0px";

    var size=get_element_size(this.el.childNodes[vis]);
    this.el.style.height=((Math.ceil(size[1]/step))*step)+"px";

    window.onunload=this.onunload;
//    this.timeout=setTimeout(this.start_scroll,timeshow);
}

function form_val(formname,field)
    {
    var el=document.forms[formname].elements[field];
    if(el.length)
	{
        var i,el2;
        for(i=0;i<el.length;i++)
    	    {
    	    el2=el[i];
    	    if((el2.type=='radio') && (el2.checked))
		return el2.value;
	    }
         }
    if(el.tagName=='TEXTAREA')
    {
       return (el.value);
    }
    if((el.tagName=='INPUT') || (el.tagName=='SELECT'))
	{
	if (el.multiple)
	{
	var arr=new Array();
	var k;
	for (k in el.options)
	{
//	alert(k);
	    if (el.options[k].selected) arr[k]=el.options[k].value;
	}
	return arr;
	}
	
        if (el.type=='checkbox')
    	    {
    	    if (el.checked)
		return el.value;
    	    }
	    else 
		return el.value;
        }
    return false;
    }

function form_vals(formname)
{
//var arr=new Array();
var arr=new Object();
var i,k;
for (i=0;i<document.forms[formname].elements.length;i++)
    {
    k=document.forms[formname].elements[i].name;
    if (k)
    {
    arr[k]=form_val(formname,k);
//    alert(k+"="+arr[k]);
    }
    }
return arr;
}

function obj2data(obj)
{
var data='';

if (obj)
{
var params;
if (obj.tagName=='FORM')
    params=form_vals(obj.name);
else
    params=obj;
var k;

for (k in params)
{
    if (typeof params[k]==='object')
    {
    var k2;
    for (k2 in params[k])
    {
    data+=escape(k)+'='+escape(params[k][k2])+'&';
    }
    
    } else
    {
    data+=escape(k)+'='+escape(params[k])+'&';
    }
}
}
return data;
}
function ajax(url,obj)
{
if (window.XMLHttpRequest)     // Object of the current windows
{ 
    var xhr = new XMLHttpRequest();     // Firefox, Safari, ...
} 
else 
if (window.ActiveXObject)   // ActiveX version
{
    var xhr = new ActiveXObject("Microsoft.XMLHTTP");  // Internet Explorer 
} 
if (!xhr) return;

xhr.open("POST", url);
xhr.setRequestHeader("Content-Type", "application/x-www-form-urlencoded");

xhr.onreadystatechange = function()
{
if (xhr.readyState == 4)
{
try
{
if (xhr.responseText) eval(xhr.responseText);
}
catch(ex)
{
document.write("<pre>"+xhr.responseText+"</pre>");
}
};
}
xhr.send(obj2data(obj));
}
var IE = document.all?true:false;
var timestart=new Date();


function findPosX(obj){
var curleft = 0;
if (obj.offsetParent){
while (obj.offsetParent){
 curleft +=
 
obj.offsetLeft
obj = obj.offsetParent;
}
}else if (obj.x){
curleft += obj.x;
}
return curleft;
}

function findPosY(obj){
var curtop = 0;
if (obj.offsetParent){
while (obj.offsetParent){
curtop += obj.offsetTop
obj = obj.offsetParent;
}
}else if (obj.y){
curtop += obj.y;
}
return curtop;
}

function mousedown(ev)
{
var xOffset,yOffset;
var firstElement=document.getElementsByTagName('body')[0].childNodes[1];
xOffset=findPosX(firstElement);
yOffset=findPosY(firstElement);
if (IE){
var marginLeftExplorer  = parseInt(document.getElementsByTagName('body')[0].style.marginLeft);
var marginTopExplorer   = parseInt(document.getElementsByTagName('body')[0].style.marginTop);
if (!isNaN(marginLeftExplorer)) xOffset=xOffset+marginLeftExplorer;
if (!isNaN(marginTopExplorer)) yOffset=yOffset+marginTopExplorer;
}

    var a=new Array();
    if (IE)
    {
    a['x'] = event.clientX + document.body.scrollLeft
    a['y'] = event.clientY + document.body.scrollTop
    } else {
    a['x'] = ev.pageX
    a['y'] = ev.pageY
    }
    a['x']-=xOffset;
    a['y']-=yOffset;
    var d2=new Date();
    d2=d2-timestart;
    a['time']=d2;
    a['url']=window.location.href;
    ajax('/logclick.php',a);
}

function getElementXPath(elt)
{
     var path = "";
     for (; elt && elt.nodeType == 1; elt = elt.parentNode)
     {
    idx = getElementIdx(elt);
    xname = elt.tagName;
    if (elt.id) xname += "#" + elt.id;
    if (idx > 1) xname += "[" + idx + "]";
    path = "/" + xname + path;
     }
 
     return path;	
}

function findhref(elt)
{
     for (; elt && elt.nodeType == 1; elt = elt.parentNode)
     {
	if (elt.href)
	    return elt.href;
     }
}
function findid(elt)
{
     for (; elt && elt.nodeType == 1; elt = elt.parentNode)
     {
	if (elt.id)
	    return elt.id;
     }
}


function getElementIdx(elt)
{
    var count = 1;
    for (var sib = elt.previousSibling; sib ; sib = sib.previousSibling)
    {
        if(sib.nodeType == 1 && sib.tagName == elt.tagName)	count++
    }
    
    return count;
}
// -----------------------------------------------------------------------------
// Generic Form Validation
//
// Copyright (C) 2000 Jacob Hage - [jacobhage@hotmail.com]
// Distributed under the terms of the GNU Library General Public License
// -----------------------------------------------------------------------------

// -----------------------------------------------------------------------------
// Initializing script  - setting global variables
// -----------------------------------------------------------------------------
var checkObjects		= new Array(); 	// Array containing the objects to validate.
var errors				= ""; 			// Variable holding the error message.
var returnVal			= false; 		// General return value. The validated form will only be submitted if true.
var language			= new Array(); 	// Language independent error messages!
language.en		= new Array();
language.pl		= new Array();
language.de		= new Array();
language.french			= new Array();
language.italian		= new Array();
language.russian		= new Array();
language.spanish		= new Array();



// Error messages in english:
	language.en.header		= "The following error(s) occured:"
	language.en.start		= "* ";
	language.en.field		= " Field <";
	language.en.require	= "> is required";
	language.en.min		= " and must consist of at least %d ";
	language.en.max		= " and must not contain more than %d ";
	language.en.minmax		= " and no more than %d ";
	language.en.chars		= " characters";
	language.en.num		= " and must contain a number";
	language.en.email		= "> must contain a valid e-mail address";
	language.en.date		= "> must contain a valid date";
	language.en.nip		= "> must contain a valid NIP number";
	language.en.terms		= "Please accept Conditions of the reservation";

// Error messages in polish: Thanks to Marcin Maciukiewicz <ciukes@poczta.fm>
	language.pl.header		= "Wyst±pi³y nastêpuj±ce b³êdy:"
	language.pl.start		= "* ";
	language.pl.field		= " Pole <";
	language.pl.require		= "> jest wymagane";
	language.pl.min			= " i musi zawieraæ conajmniej %d ";
	language.pl.max			= " i nie mo¿e zawieraæ wiêcej ni¿ %d ";
	language.pl.minmax		= " i nie wiêcej ni¿ %d ";
	language.pl.chars		= " znaki";
	language.pl.num			= " i musi zawieraæ liczbê";
	language.pl.email		= "> musi zawieraæ prawid³owy adres e-mail";
	language.pl.date		= "> musi zawieraæ prawid³ow¹ datê";
	language.pl.nip			= "> musi zawieraæ prawid³owy numer NIP";
	language.pl.terms		= "Brak akceptacji Warunków Rezerwacji";

// Error messages in german:
	language.de.header		= "Es sind folgende Fehler untergelaufen:"
	language.de.start		= "* ";
	language.de.field		= " das Feld <";
	language.de.require	= "> es ist erforderlich";
	language.de.min		= " und soll mindestens %d enthalten";
	language.de.max		= " und darf nicht mehr als %d enthalten";
	language.de.minmax		= " und nicht mehr als %d ";
	language.de.chars		= " Zeichen";
	language.de.num		= " und soll die Zahl enthalten";
	language.de.email		= "> soll die korrekte eMail Adresse enthalten";
	language.de.date		= "> soll das korrekte Datum enthalten";
	language.de.nip		= "> soll die korrekte Steuernummer enthalten";

// Error messages in french:
	language.french.header		= "The following error(s) occured:"
	language.french.start		= "* ";
	language.french.field		= " Field <";
	language.french.require	= "> is required";
	language.french.min		= " and must consist of at least %d ";
	language.french.max		= " and must not contain more than %d ";
	language.french.minmax		= " and no more than %d ";
	language.french.chars		= " characters";
	language.french.num		= " and must contain a number";
	language.french.email		= "> must contain a valid e-mail address";
	language.french.date		= "> must contain a valid date";
	language.french.nip		= "> must contain a valid NIP number";

// Error messages in italian:
	language.italian.header		= "The following error(s) occured:"
	language.italian.start		= "* ";
	language.italian.field		= " Field <";
	language.italian.require	= "> is required";
	language.italian.min		= " and must consist of at least %d ";
	language.italian.max		= " and must not contain more than %d ";
	language.italian.minmax		= " and no more than %d ";
	language.italian.chars		= " characters";
	language.italian.num		= " and must contain a number";
	language.italian.email		= "> must contain a valid e-mail address";
	language.italian.date		= "> must contain a valid date";
	language.italian.nip		= "> must contain a valid NIP number";

// Error messages in russian:
	language.russian.header		= "Ïðîèçîøëè ñëåäóþùèå îøèáêè:"
	language.russian.start		= "* ";
	language.russian.field		= " Ïîëå <";
	language.russian.require	= "> òðåáóåòñÿ";
	language.russian.min		= " i äîëæíî ñîäåðæàòü êàê ìèíèìóì %d ";
	language.russian.max		= " i íå ìîæåò ñîäåðæàòü áîëåå, ÷åì %d ";
	language.russian.minmax		= " i íå áîëåå, ÷åì %d ";
	language.russian.chars		= " çíàêè";
	language.russian.num		= " i äîëæíî ñîäåðæàòü ÷èñëî";
	language.russian.email		= "> äîëæåí áûòü ïðàâèëüíûé e-mail";
	language.russian.date		= "> äîëæíà áûòü ïðàâèëüíàÿ äàòà";
	language.russian.nip		= "> äîëæåí áûòü ïðàâèëüíûé íîìåð NIP";

// Error messages in spanish:
	language.spanish.header		= "Notamos las siguientes errores:"
	language.spanish.start		= "* ";
	language.spanish.field		= " Campo <";
	language.spanish.require	= "> es obligatorio";
	language.spanish.min		= " y tiene que incluir minimo %d ";
	language.spanish.max		= " y no puede incluir mas que %d ";
	language.spanish.minmax		= " y no mas que %d ";
	language.spanish.chars		= " signos";
	language.spanish.num		= " y tiene que incluir numero";
	language.spanish.email		= "> tiene que contener la direccion correcta";
	language.spanish.date		= "> tiene que contener la fecha correcta";
	language.spanish.nip		= "> tiene que contener al NIP correcta";
	
// -----------------------------------------------------------------------------
// define - Call this function in the beginning of the page. I.e. onLoad.
//
// n = name of the input field (Required)
// type= string, num, email, date (Required)
// min = the value must have at least [min] characters (Optional)
// max = the value must have maximum [max] characters (Optional)
// d = (Optional)
// -----------------------------------------------------------------------------
function define(n,type,HTMLname,min,max,d){
	var p;
	var i;
	var 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=define(n,type,HTMLname,min,max,d.layers[i].document);
		return x;		
	}
	
	// Create Object. The name will be "V_something" where something is the "n" parameter above.
	eval("V_"+n+" = new formResult(n,x,type,HTMLname,min,max);");
	
	// if defined, undefine it first
	undefine(n);
	
	checkObjects[eval(checkObjects.length)] = eval("V_"+n);
}

// -----------------------------------------------------------------------------
// formResult - Used internally to create the objects
// -----------------------------------------------------------------------------
function formResult(n,form,type,HTMLname,min,max){
	this.name = n;
	this.form = form;
	this.type = type;
	this.HTMLname = HTMLname;
	this.min  = min;
	this.max  = max;
}

// -----------------------------------------------------------------------------
// undefine - usuwa obiekt z listy walidacji
//
// n - identyfikator obiektu
//
// Zwraca true, jesli obiekt zostal znaleziony i usuniety; w przeciwnym wypadku
// zwraca false.
// -----------------------------------------------------------------------------
function undefine(n) {
	var i;
	for(i=0; i<checkObjects.length; i++)
	{
		if (checkObjects[i].name==n)
		{
			checkObjects.splice(i, 1);
			return true;
		}
	}
	return false;
}

// -----------------------------------------------------------------------------
// validate - Call this function onSubmit and return the "returnVal". (onSubmit="validate();return returnVal;")
// -----------------------------------------------------------------------------
function validate(){
	var first_err_obj;
	var old_errors;
	if(checkObjects.length>0){
		errorObject = "";
		for(i=0;i<checkObjects.length;i++){
			old_errors=errors;
			validateObject 			= new Object();
			validateObject.form 	= checkObjects[i].form;
			validateObject.HTMLname = checkObjects[i].HTMLname;
			validateObject.type 	= checkObjects[i].type;
			validateObject.val 		= (validateObject.type=="list") ? validateObject.form.selectedIndex : checkObjects[i].form.value;
			validateObject.len 		= (validateObject.type=="list") ? 1 : checkObjects[i].form.value.length;
			validateObject.min 		= checkObjects[i].min;
			validateObject.max 		= checkObjects[i].max;

			//if (validateObject.type=="list")
			//alert (validateObject.form.selectedIndex);	
			
			//Debug alert line
			//alert("validateObject: "+validateObject+"\nvalidateObject.val: "+validateObject.val+"\nvalidateObject.len: "+validateObject.len+"\nvalidateObject.min,validateObject.max: "+validateObject.min+","+validateObject.max+"\nvalidateObject.type: "+validateObject.type);
			
			// Checking input. If "min" and/or "max" is defined the input has to be within the specific range
			if(validateObject.type == "num" || validateObject.type == "string"){
				if((validateObject.type == "num" && validateObject.len <= 0) || (validateObject.type == "num" && isNaN(validateObject.val))){
					errors+=language[languageCode].start+language[languageCode].field+validateObject.HTMLname+language[languageCode].require+language[languageCode].num+"\n";
				} else if (validateObject.min && validateObject.max && (validateObject.len < validateObject.min || validateObject.len > validateObject.max)){
					errors+=language[languageCode].start+language[languageCode].field+validateObject.HTMLname+language[languageCode].require+language[languageCode].min.replace('%d',validateObject.min)+language[languageCode].minmax.replace('%d',validateObject.max)+language[languageCode].chars+"\n";
				} else if (validateObject.min && !validateObject.max && (validateObject.len < validateObject.min)){
					errors+=language[languageCode].start+language[languageCode].field+validateObject.HTMLname+language[languageCode].require+language[languageCode].min.replace('%d',validateObject.min)+language[languageCode].chars+"\n";
				} else if (validateObject.max && !validateObject.min &&(validateObject.len > validateObject.max)){
					errors+=language[languageCode].start+language[languageCode].field+validateObject.HTMLname+language[languageCode].require+language[languageCode].max.replace('%d',validateObject.max)+language[languageCode].chars+"\n";
				} else if (!validateObject.min && !validateObject.max && validateObject.len <= 0){
					errors+=language[languageCode].start+language[languageCode].field+validateObject.HTMLname+language[languageCode].require+"\n";
				}
			} else if(validateObject.type == "email"){
				// Checking existense of "@" and ".". The length of the input must be at least 5 characters. The "." must neither be preceding the "@" nor follow it.
				if((validateObject.val.indexOf("@") == -1) || (validateObject.val.charAt(0) == ".") || (validateObject.val.charAt(0) == "@") ||(validateObject.len < 6) || (validateObject.val.indexOf(".") == -1) || (validateObject.val.charAt(validateObject.val.indexOf("@")+1) == ".") || (validateObject.val.charAt(validateObject.val.indexOf("@")-1) == ".")){errors+=language[languageCode].start+language[languageCode].field+validateObject.HTMLname+language[languageCode].email+"\n";}
			} else if (validateObject.type == "list"){
				// Checking existense of "@" and ".". The length of the input must be at least 5 characters. The "." must neither be preceding the "@" nor follow it.
				if((validateObject.val == -1)){errors+=language[languageCode].start+language[languageCode].field+validateObject.HTMLname+language[languageCode].require+"\n";}
			}
			else if (validateObject.type == "date")
			{
				// Checking date format: yyyy-mm-dd
				var val = validateObject.val;
				val = val.replace(/^\s*/i, '');	// trim left
				val = val.replace(/\s*$/i, '');	// trim right
				var re = /^\d{4}-\d{2}-\d{2}$/gi;
				if (!re.test(val))
				{
					errors+=language[languageCode].start+language[languageCode].field+validateObject.HTMLname+language[languageCode].date+"\n";
				}
			}
			else if (validateObject.type == "nip")
			{
				// Checking NIP format
				var val = validateObject.val;
				val = val.replace(/^\s*/i, '');	// trim left
				val = val.replace(/\s*$/i, '');	// trim right
				var re = /(^\d{2,3}(\s|-)\d{2,3}(\s|-)\d{2,3}(\s|-)\d{2,3}$)|(^\d{10}$)/i;
				if (!re.test(val) || val.length!=10 && val.length!=13)
				{
					errors+=language[languageCode].start+language[languageCode].field+validateObject.HTMLname+language[languageCode].nip+"\n";
				}
			}
			else if (validateObject.type == "vatid")
			{
				// Checking NIP format
				var val = validateObject.val;
				val = val.replace(/^\s*/i, '');	// trim left
				val = val.replace(/\s*$/i, '');	// trim right
				if (val.length < 5 )
				{
					errors+=language[languageCode].start+language[languageCode].field+validateObject.HTMLname+language[languageCode].nip+"\n";
				}
			}
			else
			{
				alert('Nieznany typ do walidacji: "'+validateObject.type+'"');
			}

			if (old_errors!=errors)
			{
			    if (!first_err_obj) first_err_obj=validateObject.form;
			    validateObject.form.style.background='#FFE0B0';
			}
			else
			{
			    validateObject.form.style.background='#fff';
			}

		}
		var el=document.getElementById('ReservationTermsAgreement');
		if (!el.checked)
		{
			if (!first_err_obj) first_err_obj=el;
			errors+=language[languageCode].terms+"\n";
			el.style.background='#FFE0B0';
			el.style.outline='2px solid #FFE0B0';
		}
		else
		{
			el.style.background='#fff';
			el.style.outline='none';
		}



	}
	// Used to set the state of the returnVal. If errors -> show error messages in chosen language
	if(errors){
		alert(language[languageCode].header.concat("\n"+errors));
		errors = "";
		returnVal = false;
	} else {
		returnVal = true;
	}
        if (first_err_obj) first_err_obj.focus();
}
