if(!global){
	var global = {};
}
global.IE6 = navigator.userAgent.indexOf('MSIE 6.0') > -1 ? true : false;
global.Element = {
	checkNumber: function(element){
		element = $(element);
		Event.observe(element, "keyup", function(event){
			var element = Event.element(event);
			if(isNaN(element.value))
				element.value = element.value.replace(/\D/g, "");
		}, false);
	}
}

/***********************************************************
* Description: To get infos in browser windows
* Function name: getWindowInfo()
* returnValue: object
***************************************************************/
function getWindowInfo()
{
	var scrollX=0,scrollY=0,width=0,height=0,contentWidth=0,contentHeight=0;
	if(typeof(window.pageXOffset)=='number')
	{
		scrollX=window.pageXOffset;
		scrollY=window.pageYOffset;
	}
	else if(document.body&&(document.body.scrollLeft||document.body.scrollTop))
	{
		scrollX=document.body.scrollLeft;
		scrollY=document.body.scrollTop;
	}
	else if(document.documentElement&&(document.documentElement.scrollLeft||document.documentElement.scrollTop))
	{
		scrollX=document.documentElement.scrollLeft;
		scrollY=document.documentElement.scrollTop;
	}
	if(typeof(window.innerWidth)=='number')
	{
		width=window.innerWidth;
		height=window.innerHeight;
	}
	else if(document.documentElement&&(document.documentElement.clientWidth||document.documentElement.clientHeight))
	{
		width=document.documentElement.clientWidth;
		height=document.documentElement.clientHeight;
	}
	else if(document.body&&(document.body.clientWidth||document.body.clientHeight))
	{
		width=document.body.clientWidth;
		height=document.body.clientHeight;
	}
	if(document.documentElement&&(document.documentElement.scrollHeight||document.documentElement.offsetHeight))
	{
		if(document.documentElement.scrollHeight>document.documentElement.offsetHeight)
		{
			contentWidth=document.documentElement.scrollWidth;
			contentHeight=document.documentElement.scrollHeight;
		}
		else
		{
			contentWidth=document.documentElement.offsetWidth;
			contentHeight=document.documentElement.offsetHeight;
		}
	}
	else if(document.body&&(document.body.scrollHeight||document.body.offsetHeight))
	{
		if(document.body.scrollHeight>document.body.offsetHeight)
		{
			contentWidth=document.body.scrollWidth;
			contentHeight=document.body.scrollHeight;
		}
		else
		{
			contentWidth=document.body.offsetWidth;
			contentHeight=document.body.offsetHeight;
		}
	}
	else
	{
		contentWidth=width;
		contentHeight=height;
	}
	if(height>contentHeight)
		height=contentHeight;
	if(width>contentWidth)
		width=contentWidth;
	var rect=new Object();
	rect.ScrollX=scrollX;
	rect.ScrollY=scrollY;
	rect.Width=width;
	rect.Height=height;
	rect.ContentWidth=contentWidth;
	rect.ContentHeight=contentHeight;
	return rect;
}

/** 
* Description: The Function that fetch the Object By Id The Function will return an object if 
			   there's an Element in the document. Or it will return a boolean value ‘false’.
* @param string str the Id of the Element
* Author: Huaisheng Hu
* returnValue: HTMLElement
*/ 
function getId(str)
{
	//If the object exist in the page 
	if(document.getElementById(str))
	{
		return document.getElementById(str);  //Return to get the object 
	}
	return false; 
}

/**
 * Description: To get object collection of name label, the styles of them have 
 				appointed value Name Control in page
 * @param: str and the name of node 
 * Author: Huaisheng Hu
 * returnValue: HTMLElements
 */
function getName(str)
{
	//If the object exist in the page 
	if(document.getElementsByName(str))
	{
		return document.getElementsByName(str);  //Return to get object collection
	}
	return false; 
}


/**
 * Description: According to the ID to show and hide the menu
 * Author: Huaisheng Hu
 * @param: str and the name of node 
 */
function showMenu(id,pid)
{	
	if (document.getElementById(id).className == "hidden")
	{
		document.getElementById(id).className="show";
		if(pid!="")document.getElementById(pid).className="showCon";
	}
	else
	{
		document.getElementById(id).className = "hidden";
		if(pid!="")document.getElementById(pid).className="hiddenCon";
	}
}


/**
 * Description: According to the ID to show and hide the menu
 * Author: Huaisheng Hu
 * @param: str and the name of node 
 */
function showIcon(id)
{	

	if (document.getElementById(id).className == "hidden")
	{
		document.getElementById(id).className="show";
		getId("imgMore").src="fileadmin/templates/images/show.gif";
	}
	else
	{
		document.getElementById(id).className="hidden";
		getId("imgMore").src="fileadmin/templates/images/hidden.gif";
	}
}

/**
 * Description: According to the ID to show and hide the menu
 * Author: Huaisheng Hu
 * @param: str and the name of node 
 */


function showAdvancedSearch(){
	var defauliSearch = getId("defaultSearch");
	var advancedSearch = getId("advancedSearch");
	defauliSearch.className = "goTop";
	advancedSearch.className = "";
}

function hidenAdvancedSearch(){
	var defauliSearch = getId("defaultSearch");
	var advancedSearch = getId("advancedSearch");
	defauliSearch.className = "";
	advancedSearch.className = "goTop";
}

 
  function stringreplace(str){
		imgstr = str.replace('(und)', '-und-');
		imgstr = imgstr.replace('-ae-','ä');
  		imgstr = imgstr.replace('-oe-','ö');
  		imgstr = imgstr.replace('-ue-','ü');
  		imgstr = imgstr.replace('-ss-','ß');
  		imgstr = imgstr.replace('-AE-','Ä');
  		imgstr = imgstr.replace('-OE-','Ö');
  		imgstr = imgstr.replace('-UE-','Ü');
	  return imgstr;
  }
/*=======================================================*/
/*set footer style*/
/*=======================================================*/
function setFooterStyle(){
	
	if(!getId('navAndSearch')) return;
	if(!getId('header')) return;
	if(!getId('main')) return;
	if(!getId('sidebar')) return;
	if(!getId('mainCon')) return;
	if(!getId('mainRight')) return;
	if(!getId('main')) return;
	if(!getId('footer')) return;
	
	
	var menuHeight = getId('navAndSearch').offsetHeight;
	var headerHeight = getId('header').offsetHeight;
	var mainHeight = getId('main').offsetHeight;
	var sidebarHeight = getId('sidebar').offsetHeight;
	var mainConHeight = getId('mainCon').offsetHeight;
	var mainRightHeight = getId('mainRight').offsetHeight;
	var MaxHeight = Math.max(sidebarHeight,mainConHeight,mainRightHeight);
	
	if(getId('main')){
		getId('main').style.height = MaxHeight + 'px';
	}
	
	var top = menuHeight + headerHeight + MaxHeight;
	
	if(getId('footer')){
		getId('footer').style.top = top - 1 + 'px';
	}
	
}

function IeClearFix(){
	var mailformEMailAdresse = getId('mailformEMailAdresse');
	if(mailformEMailAdresse){
		var odiv = mailformEMailAdresse.parentNode;
		var obr = document.createElement("br");
		obr.className = 'clear';
		odiv.appendChild(obr);
	}
}

function setImgMaxWidth(){
	var element = getId('reiseleiterInfo_left');
	if(element){
		var imgElements = element.getElementsByTagName('img');
		if(imgElements.length > 0){
			var oimg = imgElements[0];
			oimg.style.width = oimg.width > 262 ? "262px" : "auto";
		}
	}
}

function setImgMaxWidth(){
	var element = getId('reiseleiterInfo_left');
	if(element){
		var imgElements = element.getElementsByTagName('img');
		if(imgElements.length > 0){
			var oimg = imgElements[0];
			oimg.style.width = oimg.width > 262 ? "262px" : "auto";
		}
	}
}

function setListHeight(){
	if(!getId('travelList')) return false;
	var oH6 = getId('travelList').getElementsByTagName('h6');
	for(var i = 0; i<oH6.length; i++){
		if(oH6[i].offsetHeight > 20){
			//var oClass = oH6[i].parentNode.className ;
			//oClass += ' imgInfo2'
			oH6[i].parentNode.className += ' imgInfo2';
		}	
	}
}

function correctPNG()  
{
	// if this is no ie - return!
	if( !document.all )
	{
		return false;
	}
	
	for(var i=0; i<document.images.length; i++)
	{
	  var img = document.images[i]
	  var imgName = img.src;//.toUpperCase()
	  if (imgName.substring(imgName.length-3, imgName.length) == "png")
	  {
		   imgName = imgName.replace('ä','-ae-');
		   imgName = imgName.replace('ö','-oe-');
		   imgName = imgName.replace('ü','-ue-');
		   imgName = imgName.replace('ß','-ss-');
		   imgName = imgName.replace('Ä','-AE-');
		   imgName = imgName.replace('Ö','-OE-');
		   imgName = imgName.replace('Ü','-UE-');
		   var imgID = (img.id) ? "id='" + img.id + "' " : ""

		   var imgClass = (img.className) ? "class='" + img.className + "' " : ""
		   var imgTitle = (img.title) ? "title='" + img.title + "' " : "title='" + img.alt + "' "
		   var imgStyle = "display:inline-block;" + img.style.cssText  
		   if (img.align == "left") imgStyle = "float:left;" + imgStyle
		   if (img.align == "right") imgStyle = "float:right;" + imgStyle
		   if (img.parentElement && img.parentElement.href) imgStyle = "cursor:hand;" + imgStyle   
		   var strNewHTML = "<span " + imgID + imgClass + imgTitle
		   + " style=\"" + "width:" + img.width + "px; height:" + img.height + "px;" + imgStyle + ";"
		  + "filter:progid:DXImageTransform.Microsoft.AlphaImageLoader"
		   + "(src=\'" + imgName + "\', sizingMethod='image');\"></span>"  
		   img.outerHTML = strNewHTML
		   i = i-1
	  }
	}
}

if(global.IE6){
	attachEvent("onload", correctPNG);
	attachEvent("onload",setFooterStyle);
	attachEvent("onload",IeClearFix);
	attachEvent("onload",setImgMaxWidth);
	attachEvent("onload",setListHeight);
	attachEvent("onload",setSiteRating);
	attachEvent("onload",bookingFrom);
}else if(navigator.userAgent.indexOf("MSIE") > -1){
	attachEvent("onload",setFooterStyle);
	attachEvent("onload",IeClearFix);
	attachEvent("onload",setImgMaxWidth);
	attachEvent("onload",setListHeight);
	attachEvent("onload",setSiteRating);
	attachEvent("onload",bookingFrom);
}else{
	addEventListener("load",setFooterStyle,false);
	addEventListener("load",IeClearFix,false);
	addEventListener("load",setImgMaxWidth,false);
	addEventListener("load",setListHeight,false);
	addEventListener("load",setSiteRating,false);
	addEventListener("load",bookingFrom,false);
}

/**
 * ajax country
 *
 *
 */
function select_oncountry(obj)
{
	var value = obj.value
		.replace(/ä/g,'-ae-')
		.replace(/ö/g,'-oe-')
		.replace(/ü/g,'-ue-')
		.replace(/ß/g,'-ss-')
		.replace(/Ä/g,'-AE-')
		.replace(/Ö/g,'-OE-')
		.replace(/Ü/g,'-UE-');
	
	$( 'countryHolder' ).className = 'loading';
	
	var myAjax = new Ajax
	(
		'./index.php?id=87',
		{
			data:"op="+value+"",
			method: "get",
			onComplete:function( x )
			{
				$('safetyinstructions_country_info').innerHTML = x;
				$( 'countryHolder' ).className = '';
				
				setFooterStyle();
				if(global.IE6)
				{
					correctPNG()
				}
			}
		}
	);
	myAjax.request();
}

function setSiteRating(){

	   var Rating=new ImgRating({imgGray:"fileadmin/templates/images/icon_blue_empty.gif",imgColor:"fileadmin/templates/images/icon_blue_full.gif",spanId:"technik",valueArea:"technik_value",imgPre:"technik_",cleanLabel:"technik_chance"});
   Rating.init();
	   var Rating=new ImgRating({imgGray:"fileadmin/templates/images/icon_blue_empty.gif",imgColor:"fileadmin/templates/images/icon_blue_full.gif",spanId:"kondition",valueArea:"kondition_value",imgPre:"kondition_",cleanLabel:"kondition_chance"});
   Rating.init();   

}
