// Created: march 9, 2007
// Author:  Zishan Zulfiqar


if (/MSIE ([0-6]\.\d+)/.test(navigator.appVersion)){
   var ie6 = true;
}else if (/MSIE (\d\.\d+)/.test(navigator.appVersion)){
   var ie7 = true;
}else if(navigator.userAgent.indexOf('Gecko')!=-1){
   var moz = true;
}

var page_NAME;

function setMinHeight (obj, height, boolStretch) {
   if (typeof(boolStretch)=='undefined') boolStretch = false;

   if (!obj) return 0;//modifd by ezra, to prevent if obj is not exist; 200705

   if (/MSIE ([0-6]\.\d+)/.test(navigator.appVersion) || boolStretch==false)
      obj.style.height = height + 'px';
   else
      obj.style.minHeight = height + 'px';

}

listen(window, 'resize', Load);
//listen(window, 'resize', cekWinResize);
listen(window, 'load', Load);



function Load()
{
	// modified 20070703: ezra dalimunthe, to meet the current layout;
	// modified 20070911: ezra dalimunthe, add minimum height;
	var objHeader		= elemById('header');
	var objFooter 		= elemById('footer');
	var objContent  	= elemById('content');

	var intWindowHeight  = measure('window').y;
	var intContentHeight = intWindowHeight;
	var whtspace=30;
	var intMinHeight      = 300;
	var intContractHeight = moz?0:10;
	intContractHeight+= whtspace;
	var intSetHeight      = (intContentHeight > intMinHeight ? intContentHeight : intMinHeight);
	intSetHeight -= getStyleValue(objHeader, 'height', true);
	intSetHeight -= getStyleValue(objFooter, 'height', true);

//   setContentImg();

	var iObjContentHeight = intSetHeight-intContractHeight

	if (objContent)
	{
		//objContent.style.width = measure('window').x;
		setMinHeight(objContent,iObjContentHeight);
	}

	if ((screen.height >= 1024) && (ie7))
	{
		setMinHeight(objContent,objContent.offsetHeight - 106);

		var objActieBlock = elemById("actieblock")
		var iObjActieblockHeight =0;
		if (objActieBlock)
			 iObjActieblockHeight = getStyleValue(objActieBlock, 'height',true) ;

		var iContent_scrolled = iObjContentHeight-iObjActieblockHeight-5 ;
		iContent_scrolled = (iContent_scrolled > intMinHeight ? iContent_scrolled : intMinHeight);
		var home_content = elemById("home_scroller");
		if (home_content) setMinHeight(home_content,iContent_scrolled- (moz?15:110))

		var direktbooken = elemById("direkt_boeken");
		if (direktbooken) setMinHeight(direktbooken,iContent_scrolled- (moz?20:115))
		var zoek_hotel  = elemById("zoek_hotel");
		if (zoek_hotel) setMinHeight(zoek_hotel,iContent_scrolled- (moz?20:115))

		var objCntLeft = elemById('cntLeft')
		if (objCntLeft)	setMinHeight(objCntLeft,iContent_scrolled- (moz?15:115))

		var objCntRight= elemById('cntRight')
		if (objCntRight)
		{
			setMinHeight(objCntRight,iContent_scrolled- (moz?15:115));

			if (page_NAME != undefined)
			{
				if ((page_NAME == "roomservice") || (page_NAME == "nieuwsbrief"))
				{
					var objCntRight= elemById('cntRight');
					objCntRight.style.padding="4px 4px 0px 0px;";

					var objCntRightLeft= elemById('cntRightLeft');
					setMinHeight(objCntRightLeft,iContent_scrolled- (moz?15:20));

					objCntRight.style.overflow = "hidden";
					objCntRightLeft.style.overflow = "auto";
				}
			}
		}

		var zoekvergader_text = elemById("zoekvergader_text");
		{
			if (zoekvergader_text) zoekvergader_text.style.width = "495";
		}

		var zoekevent_text = elemById("zoekevent_text");
		{
			if (zoekevent_text) zoekevent_text.style.width = "495";
		}

		var objCntSingle = elemById('cntSng');
		if (objCntSingle)
		{
			setMinHeight(objCntSingle,iContent_scrolled - 90);

			var node= objCntSingle.firstChild;
			while(node)
			{
				if (node.nodeType==1){
					setMinHeight(node,iContent_scrolled - 100);
				}
				node=node.nextSibling;
			}
		}

		var objCntRightCUG = elemById('cntRightCUG');
		if (objCntRightCUG)
		{
			setMinHeight(objCntRightCUG,iContent_scrolled);
		}

		//use on vergaderen and evenementen corp
		var dinamic_zoek_heigth = elemById('dinamic_zoek_heigth');
		if(dinamic_zoek_heigth)
		{
			var varHeight=365;
			var height = iContent_scrolled - varHeight;
			setMinHeight(dinamic_zoek_heigth,height);
		}
		//use on vacature corp
		var dinamic_zoek_vacature_heigth = elemById('dinamic_zoek_vacature_heigth');
		if(dinamic_zoek_vacature_heigth)
		{
			var varHeight=moz?265:270;
			var height = iContent_scrolled - varHeight;
			setMinHeight(dinamic_zoek_vacature_heigth,height);
		}
		//user zoek
		var soliciteer_button = elemById('soliciteer_button');
		if(soliciteer_button)
		{
			var varHeight=moz?334:332;
			//alert(iContent_scrolled+ " " +varHeight);
			var height = iContent_scrolled - varHeight;
			setMinHeight(soliciteer_button,height);
		}

		var vacature_zoek_static = elemById('vacature_zoek_static');
		if(vacature_zoek_static)
		{
			setMinHeight(vacature_zoek_static,iContent_scrolled- (moz?15:115));
		}

	/*	var nbs = elemById("nbs");
		if(nbs)
		{
			nbs.className="overflownbs";
			var varHeight=moz?200:210;
			//alert(iContent_scrolled+ " " +varHeight);
			var height = iContent_scrolled - varHeight;
			setMinHeight(nbs,height);
		}*/

	}

	else
	{
		var objActieBlock = elemById("actieblock")
		var iObjActieblockHeight =0;
		if (objActieBlock)
			 iObjActieblockHeight = getStyleValue(objActieBlock, 'height',true) ;

		var iContent_scrolled = iObjContentHeight-iObjActieblockHeight-5 ;
		iContent_scrolled = (iContent_scrolled > intMinHeight ? iContent_scrolled : intMinHeight);
		var home_content = elemById("home_scroller");
		if (home_content) setMinHeight(home_content,iContent_scrolled- (moz?15:17))

		var direktbooken = elemById("direkt_boeken");
		if (direktbooken) setMinHeight(direktbooken,iContent_scrolled- (moz?20:115))
		var zoek_hotel  = elemById("zoek_hotel");
		if (zoek_hotel) setMinHeight(zoek_hotel,iContent_scrolled- (moz?20:115))

		var objCntLeft = elemById('cntLeft')
		if (objCntLeft)
		{
			setMinHeight(objCntLeft,iContent_scrolled- (moz?15:20))
			if(moz)
			{
				objCntLeft.style.margin = "2px 0px 2px 2px";
			}
		}

		var objCntRight= elemById('cntRight')
		if (objCntRight)
		{
			setMinHeight(objCntRight,iContent_scrolled- (moz?15:20));
			
			//add by adit, just for special showing
			//alert(page_NAME);
			if (page_NAME != undefined)
			{
				if ((page_NAME == "roomservice") || (page_NAME == "nieuwsbrief"))
				{
					var objCntRight= elemById('cntRight');
					objCntRight.style.width = "725px";
					objCntRight.style.padding="4px 2px 0px 0px;";
					//alert(objCntRight.style.padddingright);

					var objCntRightLeft= elemById('cntRightLeft');
					setMinHeight(objCntRightLeft,iContent_scrolled- (moz?15:20));

					objCntRight.style.overflow = "hidden";
					objCntRightLeft.style.overflow = "auto";
				}
			}
		}

		var objCntSingle = elemById('cntSng');
		if (objCntSingle)
		{
			if(moz)
			{
				setMinHeight(objCntSingle,iContent_scrolled -30);

				var node= objCntSingle.firstChild;
				while(node)
				{
					if (node.nodeType==1){
						setMinHeight(node,iContent_scrolled -100);
					}
					node=node.nextSibling;
				}
			}
			else
			{
				setMinHeight(objCntSingle,iContent_scrolled -10);

				var node= objCntSingle.firstChild;
				while(node)
				{
					if (node.nodeType==1){
						setMinHeight(node,iContent_scrolled -18);
					}
					node=node.nextSibling;
				}
			}
		}

		var objCntRightCUG = elemById('cntRightCUG');
		if (objCntRightCUG)
		{
			setMinHeight(objCntRightCUG,iContent_scrolled);
		}

		//use on vergaderen and evenementen corp
		var dinamic_zoek_heigth = elemById('dinamic_zoek_heigth');
		if(dinamic_zoek_heigth)
		{
			var varHeight=moz?215:220;
			var height = iContent_scrolled - varHeight;
			setMinHeight(dinamic_zoek_heigth,height);
		}
		//use on vacature corp
		var dinamic_zoek_vacature_heigth = elemById('dinamic_zoek_vacature_heigth');
		if(dinamic_zoek_vacature_heigth)
		{
			var varHeight=moz?265:270;
			var height = iContent_scrolled - varHeight;
			setMinHeight(dinamic_zoek_vacature_heigth,height);
		}
		//user zoek
		var soliciteer_button = elemById('soliciteer_button');
		if(soliciteer_button)
		{
			var varHeight=moz?334:332;
			//alert(iContent_scrolled+ " " +varHeight);
			var height = iContent_scrolled - varHeight;
			setMinHeight(soliciteer_button,height);
		}


		var nbs = elemById("nbs");
		if(nbs)
		{
			nbs.className="overflownbs";
			var varHeight=moz?400:400;
			//alert(iContent_scrolled+ " " +varHeight);
			var height = iContent_scrolled - varHeight;
			setMinHeight(nbs,height);
		}

		/*var cntRightLeft = elemById("cntRightLeft");
		if(cntRightLeft)
		{
			cntRightLeft.className="overflow";
			var varHeight=moz?100:100;
			var height= iContent_scrolled - varHeight;
			setMinHeight(cntRightLeft,height);
		}*/

		var vac_center = elemById("vac_center");
		if(vac_center)
		{
			var varHeight=moz?19:25;
			var height= iContent_scrolled - varHeight;
			setMinHeight(vac_center,height);
		}

	}

	//used on privacy,voorwaarden, sitemap, mail a friend
	var objCorpTextClean = elemById('corp_text_clean');
	if(objCorpTextClean)
	{
		//var varHeight=moz?415:420;
		//var height = screen.height-varHeight;
		//return false;

		var varHeight = objActieBlock.offsetHeight;
		var height;

		if (screen.height >= 1024 )
		{
			if (ie6)
			{
				setMinHeight(objCorpTextClean,screen.height - 420);
			}
			else if (ie7)
			{
				setMinHeight(objContent,objContent.offsetHeight - 12);
				height = objContent.offsetHeight - varHeight - 33 ;
				setMinHeight(objCorpTextClean,height);
			}
			else
			{
				height = objContent.offsetHeight - varHeight - 30 ;
				setMinHeight(objCorpTextClean,height);
			}
		}
		else
		{
			if (ie6)
			{
				setMinHeight(objCorpTextClean,screen.height - 410);
			}
			else
			{
				height = objContent.offsetHeight - varHeight - 32 ;
				setMinHeight(objCorpTextClean,height);
			}
		}
		objCorpTextClean.style.overflow="auto";
	}

	/*
	var innercnt = elemById('innercnt')

	if (innercnt)
		setMinHeight(innercnt,iContent_scrolled)


	var objHotelContent = elemById('div_scroller');

	if (objHotelContent)
	{
		if(moz) intSetHeight += 40;
		var objHotelFooter = elemById('footer_hotels');
		intSetHeight -= getStyleValue(objHotelFooter,'height',true);
		intContractHeight=200;
		setMinHeight(objHotelContent, intSetHeight - intContractHeight );

	}
	*/
	var objHotelContent = elemById('contentHotel');
	var contentTopHotel = elemById('contentTopHotel');
	if (objHotelContent)
	{
		var children = elemsChilds(objContent);
		var intPrefHeight =0;
		for (var i = 0; i < children.length;i++)
		{
			//alert(children[i].offsetHeight);
			if (children[i] != objHotelContent)
				intPrefHeight += children[i].offsetHeight;
		}
		var x=45;
		if(moz) x=75;
		if ((screen.height >= 1024) && (ie7))
		{
			setMinHeight(contentTopHotel,(iContent_scrolled-intPrefHeight - x - 90));
		}
		else
		{
			setMinHeight(contentTopHotel,(iContent_scrolled-intPrefHeight - x ));
		}

		//alert("intPrefHeight = " + intPrefHeight + ",iContent_scrolled = " + iContent_scrolled );
	}
	//if (objHotelContent) alert("objHotelContent");
	//if (contentTopHotel) alert("contentTopHotel");

//		var objWrapper = elemById("wrapper");
//		objWrapper.style.border = "solid 2px";
//		alert("Height : " + objContent.height + ", Width: " + objContent.width);
//		alert(objWrapper.offsetLeft);

	var objHome_Scroller = elemById('home_scroller');
	if (objHome_Scroller)
	{
		//alert($_("zoek_hotel").offsetHeight +":"+ $_("corp_free_text").offsetHeight) ;
		if (($_("zoek_hotel").offsetHeight - 4) > $_("corp_free_text").offsetHeight)
		{
			//alert("scroll_hilang");
			$_("zoekboeken").style.left = "542px";
			$_("corp_free_text").style.width = "510px";
			//$_("zoek_hotel").style.left = $_("zoek_hotel").offsetWidth + 10 + "px";
		}
		else
		{
			//alert("scroll_muncul");
			$_("zoekboeken").style.left = "526px";
			$_("corp_free_text").style.width = "490px";
		}
	}
}

/*
var imgLarge;
function setContentImg() {
   if (elemById('content')) {
      var arrImg = elemsByTag('img', elemById('content'));

      for (i = 0; i < arrImg.length; i++) {
         if (arrImg[i].parentNode.nodeName.toLowerCase() != 'a') {
            arrImg[i].onclick = function() {

               imgLarge = new Image();

               //prep source of large version
               var strSrc = this.src.slice(0,this.src.length - 4);
               strSrc += '[1]';
               strSrc += this.src.slice(this.src.length - 4, this.src.length);

               imgLarge.src = strSrc;

               // insert delay so that image has time to load.
               // otherwise, width and height are zero.
               setTimeout("openImagePop(imgLarge)", 1200);
            }
         }
      }
   }
}

function openImagePop(objImage)
{
   var width = objImage.width + 25;
   var height = objImage.height + 25;
   window.open(objImage.src,'img','width='+width+',height='+height+',resizable=1');
}
*/



function activateMe(obj)
{
	var p = elemById("cntRightRight");
	if (p){
		var arrLink = p.getElementsByTagName("a");
		for (var i=0;i<arrLink.length;i++)
		{
			arrLink[i].className="";
		}
	}
	obj.className = "active_nav"
}

function activateTopLink()
{
	var p = elemById("cntRightRight");
	if (p){
		var arrLink = p.getElementsByTagName("a");
		for (var i=0;i<arrLink.length;i++)
		{
			if(i==1)
				arrLink[i].className="active_nav";
			else
				arrLink[i].className="";
		}
	}
}

function cekWinResize()
{
	var objHeader = document.getElementById("header");
	var objContent = document.getElementById("content");
	var objFooter = document.getElementById("footer");

	//alert(objHeader.offsetHeight + "," + objContent.style.height + "," + objFooter.offsetHeight );

	var sX = measure('window').x;
	var sY = measure('window').y;

//	alert(parseInt(objHeader.offsetHeight) + parseInt(objContent.style.height) + parseInt(objFooter.offsetHeight));
//	alert(sY);

	var minX = 0;
	var minY = 0;

	if (ie7)
	{
		minX = 1020;
		minY = 600;
	}
	else if (ie6)
	{
		minX = 1015;
		minY = 600;
	}
	else
	{
		minX = 1015;
		minY = 600;
	}

	if ((sX < minX) || (sY < minY ))
	{
		//alert("Minimum width and height is " + minX + " x " + minY);
		//alert(sY);
		window.resizeTo(1020,720);
	}
}

function mailfriend_opendialog(strHRef)
{
	if (elemById("ifr")) return 0

	var l = (screen.availWidth - 700) / 2   +"px";
	var t = (screen.availHeight - 340) / 2  + "px";
	var url = new String(window.location);
	var tempurl = url;
	//ff doesnt support word break on long text;
	url = url.substr(0, 30);
	var i = url.lastIndexOf("/" )
	url = tempurl.substr(0,i+1)+" " + tempurl.substr(i+1)
	url = url.replace(/&/gi, "& ");
	var wTitle = window.document.title;

	var wTitles = window.document.title.split("| ");//very weak here... :-( (ezra)
	wTitle= wTitles[wTitles.length-1]
	var strContent = ""

	//alert(HostName);

	var ifr = window.document.createElement("iframe");

	ifr.src= HostName + "/templates/" + strHRef + "&hlink=" + window.location;//'javascript:document.open();document.write("'+strContent+'");document.close();'
	//alert(ifr.src);
	ifr.style.position='absolute';
	ifr.style.top=t;
	ifr.style.left=l//'300px';
	ifr.width='700px';
	if (moz) ifr.height= '240px';
	else ifr.height= '280px';
	ifr.style.backgroundColor='#ffffff';
	ifr.frameBorder='1'
	ifr.marginHeight='0px'
	ifr.marginWidth='0px'
	ifr.style.zIndex="100";
	ifr.scrolling="no"
	ifr.setAttribute("id" , 'ifr');

//	var mf = window.document.createElement("input");
//	mf.name="mf1";
//	mf.value="hello ";
//	mf.setAttribute("type","text");
//	ifr.appendChild(mf);

	elemById("content").appendChild(ifr);

}

function dialogcancel()
{
	window.top.deleteifr();
}

function deleteifr()
{
	//alert(elemById("ifr"));
	f = removeNode(elemById("ifr"));

}
function getdialogval(obj)
{
	var opt = document.createElement("option");
	opt.setAttribute("value" , window.location);
	opt.innerHTML= obj.link;
	elemById("selFavoriten").appendChild(opt);
	deleteifr();
}
