<!--

/*
	AVIGO Scriptfunction $Version: 0.1
	(c) 2005 NEXUM GMBH
*/

/*
 Due to the internationalization of Avigo / Darwin the following constants have to
 be supplied outside this script by the application:
 MSG_POPUPBLOCKER: String for Popup-Blocker Warning
 ARR_MONATE: new Array("Januar","Februar","M&auml;rz","April","Mai","Juni","Juli","August","September","Oktober","November","Dezember");
 ARR_DAYS: 
 */
 
 
function Fenster(url,nameW,widthW,heightW,scrollbarsW,resizeableW) {
	win = window.open( url,nameW,'top=0,left=0,width='+widthW+',height='+heightW+',scrollbars='+scrollbarsW+',resizable='+resizeableW );
	if (!win) alert(MSG_POPUPBLOCKER);
	else win.focus();
}

function valInt(i) {
	i = parseInt(i, 10);
	return (isNaN(i) ? 0 : i);
}

function valForm(s) {
	if(s=='') return s;
	var objTmp = valObject(s);
	return objTmp!='null' ? objTmp.value : '';
}

function valObject(s) {
	if(s=='') return s;
	var i = 0;	var v = 'null';
	while ((document.forms.length > 1) && (document.forms[i].length > 0) && (document.forms[i].elements[s] == null)) {
		i++;
	}
	if (document.forms[i].elements[s] != null) v = document.forms[i].elements[s];
	return v;
}

function valDate(s) {
	var tmp = s.split(".");
	var n = new Date();
	var n = new Date(n.getFullYear(), n.getMonth(), n.getDate());
	if (tmp.length == 3) {
		if (tmp[2].length == 2) tmp[2] = "20"+tmp[2]; // 21st Century Only
		n = new Date(valInt(tmp[2]), valInt(tmp[1]-1), valInt(tmp[0]));
	}
	return n;
}
//--- Get year in two digits (YYYY -> YY)
function GetLastTwoDigits(strPrm) {
	strPrm=strPrm.toString();//to make sure it is string...
	if(strPrm.length>2)	return strPrm.substring(2);
	return strPrm;
}
function GetTextInSize(strPrm,fill,size,isBefore) {
	strPrm=strPrm.toString();//to make sure it is string...
	//alert(strPrm.length+"....."+strPrm)
	while(strPrm.length<size)isBefore?strPrm=fill+""+strPrm:strPrm=strPrm+""+fill;//alert("strPrm:  "+strPrm)
	return strPrm;
}
function GetInTwoDigits(strPrm) {
	return GetTextInSize(strPrm,"0",2,true);
}

function GetDateStr(dateObj) {
	return GetInTwoDigits(dateObj.getDate()) + "."+ GetInTwoDigits(dateObj.getMonth()+1) + "."+ GetLastTwoDigits(dateObj.getFullYear());
}
function GetAddedDateStr(dateObj, addDay) {
	return GetDateStr(valDate((dateObj.getDate()+addDay) + "."+ (dateObj.getMonth()+1) + "."+ dateObj.getFullYear()));
}
function GetAddedDate(addDay) {
	return valDate(GetAddedDateStr(new Date(), addDay));
}


function GetDocWidth(doc) {
  var docWt = 0, sw, ow;
  if( doc.width ) {
  	docWt = doc.width;
  }
  else if( doc.body ) {
    if( doc.body.scrollWidth ) 
    	docWt = sw = doc.body.scrollWidth;
    if( doc.body.offsetWidth ) 
    	docWt = ow = doc.body.offsetWidth;
    if( sw && ow )
    	docWt = Math.max(sw, ow);
  }
  return docWt;
}

document.CreateDIV = function (parentObj, id) {
	if(!parentObj) return false;
	var addParentOffset = true;
	if(arguments.length>2) addParentOffset = (arguments[2]=="true");
	var docWidth=GetDocWidth(document);
	var n = parentObj;
	var xpos = n.offsetLeft;
	while ((n=n.offsetParent) != null && addParentOffset) { xpos += n.offsetLeft; }
	var n = parentObj;
	var ypos = n.offsetTop;
	while ((n=n.offsetParent) != null && addParentOffset) { 
		if (!n.id || n.id!="ignoreOffset") 
			ypos += n.offsetTop;
	}
	if ((xpos + 150) > docWidth) xpos = docWidth-155;
	var my_div = document.createElement('DIV');
	my_div.setAttribute("id", id);
	my_div.style.position = 'absolute';
	my_div.style.left = xpos+"px";
	my_div.style.top = ypos+"px";
	parentObj.parentNode.appendChild(my_div);
	return my_div;
}

function placedCalendar(parentObj,id,top,left)
{
	Kalender(parentObj);
}


var CALNDR_dependentObj = '';
var CALNDR_addToDependent = 0;

function Kalender(t) {
	Kalender_Zu();
	document.CreateDIV(t, "kalender");
	
	var now = new Date();
	var initialValue = '';
	var selectedValue = '0';
	if (arguments.length > 1) {
		initialValue = valForm(arguments[1]);
		now = valDate(initialValue);
		
		if (arguments.length > 2) {
			//----if arguments[2] is for setting DependentObj which will be updated after this
			if(valInt(arguments[2])==0){
				
				//--- for fixing Bugzilla.BUG6735
				CALNDR_dependentObj = valObject(arguments[2]);
				if(arguments.length > 3 && valInt(arguments[3])!=0){
					CALNDR_addToDependent = valInt(arguments[3]);
				}
				
			//----if arguments[2] is for adding days to the date
			}else{ 
				initialValue = GetAddedDateStr(new Date(), arguments[2]);
				now = valDate(initialValue);
			}
		}
		
		var x = Kalender_GetInputObj();
		if (x.tagName == "INPUT") selectedValue = x.value;
		if (selectedValue != '') now = valDate(selectedValue);
	}
	var my_year = now.getFullYear();
	var my_month = now.getMonth()+1;
	return Kalender_Zeichne(my_month, my_year, initialValue, selectedValue);
	return false;
}
// m=monat, y=Jahr, ab=Datum ab, ov: Old value(?)
function Kalender_Zeichne(m, y, ab, ov) {
	//alert(m +","+ y +","+ ab +","+ ov)
	
	var now = new Date();
	var year = now.getFullYear();
	var month = now.getMonth()+1;
	var day = now.getDate();
	var now = new Date(year, month-1, day);
	var draw = new Date(y, m-1, 1);
	var draw_year = draw.getFullYear();
	var draw_month = draw.getMonth()+1;
	var draw_day = draw.getDate();
	var draw_weekday = draw.getDay();
	if (draw_weekday == 0) draw_weekday = 7;
	var ovv = ov;
	if (ovv == '')	ovv = ab;
	if (ovv == '0')	ovv = '';
	var ab_date = valDate(ab);
	var ov_date = valDate(ovv);

	var draw_lastday = 31;
	if (draw_month == 2) {
		draw_lastday = 28;
		if (((draw_year%4 == 0) && (draw_year%100 != 0)) || (draw_year%400 == 0)) draw_lastday = 29;
	}
	if ((draw_month == 4) || (draw_month == 6) || (draw_month == 9) || (draw_month == 11)) draw_lastday = 30;
	var last_month = (draw_month-1)+","+draw_year+",'"+ab+"','"+ov+"'";
	if ((draw_month-1) < 1) var last_month = "12,"+(draw_year-1)+",'"+ab+"','"+ov+"'";
	var next_month = (draw_month+1)+","+draw_year+",'"+ab+"','"+ov+"'";
	if ((draw_month+1) > 12) var next_month = "1,"+(draw_year+1)+",'"+ab+"','"+ov+"'";
	var my_div = document.getElementById("kalender");
	if (my_div) {
		var cobj = "";
		cobj += '<!--[if lt IE 7]><iframe frameborder="0" id="kal_place" src="" scroll="none"></iframe><![endif]-->';
		cobj += '<div id="kal_setup"><table class="month" summary=""><tr><td><a href="#" class="last" onclick="return Kalender_Zeichne('+last_month+');"><b>&lt;</b></a></td><td class="month">'+monate[draw.getMonth()]+' '+draw.getFullYear()+'</td><td><a href="#" class="next" onclick="return Kalender_Zeichne('+next_month+');"><b>&gt;</b></a></td></tr></table>';
		cobj += '<table class="days" summary="">';
		cobj += days;
		var dw = 0; var dz = 0;	var dm = 1;
		while (dz < 42) {
			if (dw == 0) cobj += '<tr>';
			cobj += '<td'+(dw<5 ? '' : ' class="we"')+'>'
			if (((dz+1) < draw_weekday) || (dm > draw_lastday)) cobj += '&nbsp;';
			else {
				var tmp = new Date(draw_year, draw_month-1, dm);
				if ((ovv == '') && (ab_date.valueOf() == tmp.valueOf())) cobj += '<a href="#" onclick="return Kalender_Wert(\''+GetInTwoDigits(dm)+'.'+GetInTwoDigits(draw_month)+'.'+GetLastTwoDigits(draw_year)+'\');"><span class="cur">'+dm+'</span></a>'; // '<a href="#"><span class="cur">'+dm+'</span></a>';
				else if ((ovv != '') && (ov_date.valueOf() == tmp.valueOf())) cobj += '<a href="#" onclick="return Kalender_Wert(\''+GetInTwoDigits(dm)+'.'+GetInTwoDigits(draw_month)+'.'+GetLastTwoDigits(draw_year)+'\');"><span class="cur">'+dm+'</span></a>'; // '<a href="#"><span class="cur">'+dm+'</span></a>';
				else if ((ov == '0') && ((now.valueOf() > tmp.valueOf()) || (ov_date.valueOf() > tmp.valueOf()))) cobj += dm;
				else if (((ab == '') && (ov == '0')) && ((now.valueOf() > tmp.valueOf()) || (ov_date.valueOf() > tmp.valueOf()))) cobj += dm;
				else if (((ab == '') && (ov == '')) && ((now.valueOf() > tmp.valueOf()) || (ov_date.valueOf() > tmp.valueOf()))) cobj += dm;
				else if ((ovv != '') && ((now.valueOf() > tmp.valueOf()) || (ab_date.valueOf() > tmp.valueOf()))) cobj += dm;
				else if (now.valueOf() <= tmp.valueOf()) cobj += '<a href="#" onclick="return Kalender_Wert(\''+GetInTwoDigits(dm)+'.'+GetInTwoDigits(draw_month)+'.'+GetLastTwoDigits(draw_year)+'\');">'+dm+'</a>';
				dm++;
			}
			cobj += '</td>';
			dw = (dw+1)%7;
			if (dw == 0) cobj += '</tr>';
			dz++;
		}
		cobj += '</table><p class="right"><a class="close" href="#" onclick="return Kalender_Zu();"><b>x</b></a></p></div>';
		my_div.innerHTML = cobj;
	}
	return false;
}
function Kalender_GetInputObj() {
	var my_div = document.getElementById("kalender");
	var x = my_div;
	var look = true;
	while (look) {
		if (x.tagName == "INPUT") look = false;
		else {
			if (x.previousSibling != null) x = x.previousSibling;
			else if (x.parentNode.previousSibling != null) x = x.parentNode.previousSibling;
			else if ((x.previousSibling == null) && (x.parentNode.previousSibling == null))	x = x.parentNode.parentNode.previousSibling;
			if (x.hasChildNodes()) x = x.lastChild;
			if (x == null) look = false;
		}
	}
	return x;
}
function Kalender_Wert(n) {
	var x = Kalender_GetInputObj();
	if (x.tagName == "INPUT"){
	 x.value = n;
	 try{ //try to execute onchange event
	 x.onchange();
	 }
	 catch(e){ //ignore, i.e. if no onchange is defined
	 }
	}
	//--- for fixing Bugzilla.BUG6735
	if(CALNDR_dependentObj!='null' && x.name!=CALNDR_dependentObj.name){
		if(CALNDR_addToDependent!=0){
			CALNDR_dependentObj.value = GetAddedDateStr(valDate(n), CALNDR_addToDependent);
		}else{
			CALNDR_dependentObj.value = n;			
		}
	}

	return Kalender_Zu();
}
function Kalender_Zu() {
	var my_div = document.getElementById("kalender");
	if (my_div) {
		my_div.style.backgroundColor = 'transparent';
		my_div.innerHTML = '&nbsp;';
		my_div.parentNode.removeChild(my_div);	
	}
	return false;
}
function Anzeige_AnAus(s, v) {
	var my_div = document.getElementById(s);
	if (my_div != null) my_div.style.display = v;
}
/*
v1: t,s
= s wird eingeblendet wenn t.value = 1
v2: t,s,m
= s und s_[n] wird eingeblendet wenn t.value = n
v3: t,s,s2
= s wird ein und s2 wird ausgeblendet wenn t.value = 1
*/
function Anzeige() {
	switch (arguments.length) {
		case 2:	break;
		case 3:	var m = 0;
			if (typeof(arguments[2])=="number") m = arguments[2];
			else var s2 = arguments[2];
			break;
		default:
			return true;
	}
	var t = arguments[0];
	var s = arguments[1];
	var n = 0;
	switch (t.type) {
		case "radio":
			Anzeige_AnAus(s2, "none");
			Anzeige_AnAus(s, "block");
			break;
		case "checkbox":
			if (t.checked) Anzeige_AnAus(s, "block");
			else Anzeige_AnAus(s, "none");
			break;
		case "select-one":
			n = valInt(t.options[t.selectedIndex].value);
			Anzeige_AnAus(s, "none");
			if (n > 0) Anzeige_AnAus(s, "block");
			var i = 1;
			while (i <= m) Anzeige_AnAus(s+(i++), "none");
			var i = 1;
			while (i <= n) Anzeige_AnAus(s+(i++), "block");
			break;
	}
	return true;
}

function Karte(iid,isrc,kid,ktext){
	document[iid].src = isrc;
	if (document.getElementById){
		document.getElementById(kid).innerHTML = ktext;
	}
}

function SetFormID(formID,elementID){
	fID = formID;
	gID = elementID;
}

function SetAirport(airport){
	window.opener.ChangeAirport(airport);
	top.window.close();
}

function ChangeAirport(airport) {
	var t = document.forms[fID][gID];
	t.value = airport;
}

function ImagePicker(url, name, description) {
	this.url = url;
	this.name = name;
	this.description = description;
}

function initSelectedPictureCombo(dropDownId, array) {
	pic = document.getElementById(dropDownId);
	pic.length=imagesInfo.length;
	for(i=0; i<imagesInfo.length; i++) {
	pic.options[i].text=array[i].name;
	pic.options[i].value=array[i].url;
	}
	pic.options[0].selected = true;
	showImage('selectedPicture', 'selectedHotelPictureImg', 'pictureDescription', imagesInfo);
}

function showImage(dropDownId, pictureId, descriptionId, array){
	picker = array[document.getElementById(dropDownId).selectedIndex];
	img = '<img  border="0" src="' + picker.url + '">';
	document.getElementById(pictureId).innerHTML = img;
	document.getElementById(descriptionId).innerHTML = "Bild: " + picker.description;
}

document.showChildAgeFields = function( childrenCount ) {
for(i=0; i<8; i++) {
	var field = document.getElementById('childAge'+i);

	if(field != null) {
		field.style.visibility = ( childrenCount > i ? 'visible' : 'hidden' );

		try {
			if (i%2==0) {
				field.style.display = ( childrenCount > i ? 'table-row' : 'none' );
			}
			else {
				if(i!=1) {
					field.style.display = ( childrenCount > i ? 'table-cell' : 'none' );
				}
			}
		}
		catch(err){
			field.style.display = ( childrenCount > i ? 'block' : 'none' );
		}
	}
}
}
//-->
