var ie=0; var ns6=0; var displayer='block'; var globalTar=false;

if (document.all) ie=1;
if (document.getElementById && !ie) ns6=1;
if(ns6==1) {displayer='table-row';}

var noimage=new Image();
noimage.src=window.location.protocol+'//www.holidayautos.de/v2/Images/keinbild.gif';
var morePara='';
var otherMessage='';
var totalDif=0;

var checkWanteds=new Array();

function openPop(url, w, h, scroll) {
	if (scroll=='') scroll='yes';
	var nw=window.open(url, 'holiauto','height='+h+',width='+w+',toolbar=no,menubar=no,scrollbars='+scroll+',resizable=yes,location=no,directories=no,status=yes,left=250,top=50');
	if (nw) nw.focus();
}

function setPos(idname, lpos, tpos, vis){
	var e=document.getElementById(idname);
	if (e){
		if (lpos!='') e.style.left=lpos+'px';
		if (tpos!='') e.style.top=tpos+'px';
		e.style.visibility=vis;
	}
}

function setAtt(idname, attname, attvalue) {
	var e=document.getElementById(idname);
	if (e){
		eval('e.style.'+attname+'=\''+attvalue+'\'');
	}
}

function getAtt(idname, attname) {
	var e=document.getElementById(idname);
	if (e){
		return eval('e.style.'+attname);
	}
}

function setClass(idname, newclass) {
	var e=document.getElementById(idname);
	if (e){
		e.className=newclass;
	}
}

function checkForm(formname) {
	var noText = /^\s?$/
	if (checkWanteds.length==0) return '';
	var description='';
	var langId=1;
	if (lang!='') langId=2;
	for(var i=0;i<checkWanteds.length;i++) {
		var checkSplit=checkWanteds[i].split('#')
		var formEl=eval('document.'+formname+'.'+checkSplit[0]);
		if (formEl.type=='text') {
			var val=formEl.value;
		}else if (formEl.type=='select-one') {
			var val=formEl.options[formEl.selectedIndex].value;
		}else if (formEl.type=='checkbox') {
			if (formEl.checked==true){
				var val='true';
			}else{
				var val='';
			}
		}else{
			var val=formEl.value;
		}
		if (noText.test(val)) {
			description+='<LI onclick="document.'+formname+'.'+checkSplit[0]+'.focus();" style="cursor: pointer;">'+checkSplit[langId]+'</LI>'
			var testKo=true;
		}else{
			var testKo=false;
		}

		if (document.getElementById(checkSplit[0])){
			var oParent=document.getElementById(checkSplit[0]).offsetParent;
			if (oParent){
				var actClass=repAll(oParent.className, ' addColor', '');
				if (testKo){
					actClass+=' addColor';
				}
				oParent.className=actClass;
			}
		}

	}
	return description;
}

function sendForm(formobj, actio, targ) {
	formobj.action=addPara(actio, 'sId', sId);
	if (targ!=''){
		formobj.target=targ;
//	}else if(globalTar){
//		formobj.target='holinew';
	}
	formobj.submit();
}

function goUrl(url, targ, para) {
	if (url!='') {
		if (para) url=addPara(url, 'sId', sId)+morePara;
		if (targ=='new'){
			window.open(url, targ, '')
		}else if (targ!=''){
			window.open(url, targ,'height='+wH()+',width='+wW()+',scrollbars=yes,resizable=yes')
//		}else if(globalTar){
//			window.open(url, 'holinew','')
		}else{
			window.location.href=url;
		}
	}
}

function addPara(url, paran, parav) {
	if(url!=''){
		if (url.search(/\?/)==-1){
			url+='?';
		}else{
			url+='&';
		}
		return url+paran+'='+encodePlus(escape(parav));
	}else{
		return paran+'='+encodePlus(escape(parav));
	}
}

function encodePlus(parav){
	return parav.replace('+', '%2b');
}

function wW() {
	var ww=0;
	if (window.innerWidth) ww=window.innerWidth;
	else if (document.body && document.body.offsetWidth) ww=document.body.offsetWidth;
	return ww;
}

function wH() {
	var hh=0;
	if (window.innerHeight) hh=window.innerHeight;
	else if (document.body && document.body.offsetHeight) hh=document.body.offsetHeight;
	return hh;
}

function setH(idname, he){
	var e=document.getElementById(idname);
	if (e){
		e.style.height=he+'px';
	}else{
		//alert(idname);
	}
}

function togBor(name){
	var e=document.getElementById(name);
	if (e){
		var oldstyle='1px solid white' //document.getElementById(name).style.border;
		e.style.border='1px solid threedshadow';
		window.setTimeout("resetBor('"+name+"', '"+oldstyle+"')", 200);
	}
}

function resetBor(name, oldstyle){
	document.getElementById(name).style.border=oldstyle;
}

function writeInfo(idname, txt) {
	var e=document.getElementById(idname);
	if (e){
		e.innerHTML=txt;
	}
}

function addInfo(idname, txt) {
	var e=document.getElementById(idname);
	if (e){
		e.innerHTML+=txt;
	}else{
	alert(txt);
	}
}

function getInfo(idname) {
	var e=document.getElementById(idname);
	if (e){
		return e.innerHTML;
	}else{
		//alert(idname);
	}
}

function showMes(msg, errorLevel, MessageId) {
		var m=document.getElementById(MessageId);
		if (m){
			if (msg==''){
				m.innerHTML='&nbsp;';
				m.style.display='none';
			}else{
				var backbutton='<INPUT type="button" name="RESET" value="zur�ck" class="knob ks" onClick="history.back();">&nbsp;&nbsp;&nbsp;';
				//1.Hinweis mit zur�ck 2.Hinweis mit Neue Suche  0..Fehler
				if (errorLevel==1) {
					m.innerHTML='<SPAN class="titleKlein">'+allachtung+': </SPAN><SPAN>'+msg+'</SPAN><DIV style="text-align: right;"><BR>'+backbutton+'</DIV>';
				}else if (errorLevel==2) {
					m.innerHTML='<SPAN class="titleKlein">'+allhinweis+': </SPAN><SPAN>'+msg+'</SPAN>';
				}else if (errorLevel==3) {
					m.innerHTML='<SPAN class="titleKlein">'+allhinweis+': </SPAN><SPAN>'+msg+'</SPAN><DIV style="text-align: right;"><BR>'+backbutton+'</DIV>';
				}else if (errorLevel==4) {
					m.innerHTML='<SPAN class="titleKlein">'+msg+'</SPAN>';
				}else{
					m.innerHTML='<SPAN class="titleKlein">'+allachtung+': </SPAN><SPAN>'+msg+'</SPAN>';
				}
				if (errorLevel!=4) m.className+=' addColor1';
				m.style.display=displayer;
			}
		}else{
			//alert('kein M');
		}
}

//Funktionen f�r selectboxes
function emptyDD(thisDD) {
	if (thisDD){
		var oOptions=thisDD.options;
		for (var i=oOptions.length; i>0; i--) {
			oOptions[i]=null;
		}
		thisDD.selectedIndex=0;
		thisDD.length=1;
	}
}

function addOptDD(thisDD, optionText, optionValue) {
	if (thisDD) thisDD[thisDD.length]=new Option(optionText, optionValue);
}

function getselValue(thisDD, sWhat) {
	var retVal='';
	if (thisDD){
		if (sWhat=='v') {
			retVal=thisDD.options[thisDD.selectedIndex].value
		}else if (sWhat=='t') {
			retVal=thisDD.options[thisDD.selectedIndex].text
		}else if (sWhat=='i') {
			retVal=thisDD.selectedIndex
		}
	}
	return retVal;
}

function selIt(thisDD, sVal, sWhat) {
	//alert(thisDD.length+' '+thisDD.name+' '+sVal);
	if (thisDD){
		thisDD.selectedIndex=0;
		if (sVal!=''){
			if (sWhat=='v') {
				for(var i=1;i<thisDD.length;i++) {
					if (thisDD.options[i].value.toString()==sVal.toString()) {
						thisDD.selectedIndex=i;
						break;
					}
				}
			}else if (sWhat=='t') {
				sVal=prepSearch(sVal.toLowerCase());
				for(var i=1;i<thisDD.length;i++) {
					if (thisDD.options[i].text.toLowerCase().search(sVal)!=-1) {
						thisDD.selectedIndex=i;
						break;
					}
				}
			}else if (sWhat=='i') {
				if (thisDD.length>sVal) thisDD.selectedIndex=sVal;
			}
		}
		return thisDD.selectedIndex;
	}
}

function prepSearch(sVal){
	var metaCharacters = /([\.\\\(\)\{\}\[\]\*\+\?\|\^\$])/g;
	return new RegExp(sVal.replace(metaCharacters, '\\$1'));
}

function repAll(txt, was, mit){
	var dummy='#dummy#';
	while(txt.search(was)!=-1) {
		txt=txt.replace(was, dummy)
	}

	while(txt.search(dummy)!=-1) {
		txt=txt.replace(dummy, mit)
	}
	return txt;
}

function checkImage(bname) {
	var actbild=eval('document.images.'+bname);
	if (actbild){
		actbild.src=noimage.src;
	}
}

function setRadio(fobj, fvalue){
	if (fobj){
		if (fobj.length){
			var checkerFound=false;
			for(var i=0;i<fobj.length;i++) {
				if (fobj[i].value==fvalue){
					fobj[i].checked=true;
					checkerFound=true
				}else{
					fobj[i].checked=false;
				}
			}
			if (!checkerFound) fobj[0].checked=true;
		}else{
			fobj.checked=true;
		}
	}
}

function checkRadio(obj) {
	var retVal='';
	if (obj){
		if (obj.length){
			for (var i=0;i<obj.length;i++) {
				if (obj[i].checked==true) {
					retVal=obj[i].value;
					break;
				}
			}
		}else{
			if (obj.checked==true) retVal=obj.value;
		}
	}
	return retVal;
}

//Text in DIV schreiben
function writeAddIt(idname, text){
	var obj=document.getElementById(idname)
	if (obj){
		obj.innerHTML+=text;
	}
}

function getYPos(element, sourceObj) {
	var current_top=0;
	if(element){
		if (element.offsetParent) {
			while (element.offsetParent) {
				current_top+=element.offsetTop
				element=element.offsetParent;
			}
		} else if (element.y){
			current_top+=element.y;
		}
		if (sourceObj) current_top-=sourceObj.scrollTop;
	}
	return current_top;
}

function getXPos(element, sourceObj) {
	var current_left=0;
	if(element){
		if (element.offsetParent) {
			while (element.offsetParent) {
				current_left+=element.offsetLeft
				element=element.offsetParent;
			}
		} else if (element.x){
			current_left+=element.x;
		}
		if (sourceObj) current_left-=sourceObj.scrollLeft;
	}
	return current_left;
}

function setMenWidth() {
	if (ie){
		var CSSRulesobj = document.styleSheets[0].rules;
	}else{
		var CSSRulesobj = document.styleSheets[0].cssRules
	}
	if (CSSRulesobj){
		var totalW=getObjWidth(CSSRulesobj[1]);
		
		var menuObj=document.getElementById('menuSpace');
		var menuS=getObjWidth(menuObj);

		if (totalW>0 && menuS>0){
			totalDif=totalW-595;

			if (totalDif>0) menuObj.style.width=(totalDif+menuS)+'px';

			//Startseite
			if(document.countryForm){
		//		setObjWidth(document.getElementById('Country'));
		//		setObjWidth(document.getElementById('Region'));

			}else if(document.Stations){
				//Stationen+QuickBook
				setObjWidth(document.getElementById('Station'));
				setObjWidth(document.getElementById('StationTo'));
				if(document.Cars){
					//Preise
					setObjWidth(document.getElementById('Filter22'));
					setObjWidth(document.getElementById('Filter6'));
				}

			}else if (document.CarBook){
				//Buchungsseite
				var bookFormObj=document.CarBook
				if(totalDif<0){
					for(var i=0;i<bookFormObj.elements.length;i++) {
						if (bookFormObj.elements[i].type=='text' || bookFormObj.elements[i].type=='textarea'){
							setObjWidth(document.getElementById(bookFormObj.elements[i].name));
						}
					}
				}
			}
		}
	}
}

function setObjWidth(obj){
	if (obj){
		var oWidth=getObjWidth(obj);
		if (oWidth>100 && totalDif!=0) obj.style.width=(totalDif+oWidth)+'px';
	}
}

function getObjWidth(obj){
	var oWidth=0
	if (obj){
		oWidth=repAll(obj.style.width, 'px', '')
		if (isNaN(oWidth)) oWidth=0;
	}
	return parseInt(oWidth);
}

//ResponseTek
function RTeCollector(param){
	theHeight = 460;
	theWidth  = 640;

	theTop=(screen.height/2)-(theHeight/2)
	theLeft=(screen.width/2)-(theWidth/2)
	features='toolbar=no,location=no,directories=no,status=no,menubar=no,scrollbars=no,resizable=no,height='+theHeight+',width='+theWidth+',top='+theTop+',left='+theLeft;
	myWindow=window.open('http://ecollector.responsetek.com/eCollector.asp?' + param, 'eCollector', features);
}

function setT(aNumber,aDez) {
	var mEx = Math.pow(10,aDez);
	if(isFinite(aNumber)) {
		var mNeu = Math.abs(Math.round(parseFloat(aNumber)*mEx)/mEx);
		var mG   = Math.floor(mNeu);

		var mK   = Math.round((mNeu-mG) * mEx)/mEx;
		
		for (var i=mG.toString().length,j=0,mNeu='';i>-1;i--,j++) mNeu=((j%3==0)&&(j!=0)&&(j!=mG.toString().length)?'.':'')+mG.toString().charAt(i)+mNeu;
			return (parseFloat(aNumber)<0?'-':'')+mNeu+(aDez>0?','+(mK==0?mEx.toString().substr(1,aDez):(mK+mEx.toString().substr(1,aDez)).substr(2,aDez)):'');
	} else return aDez>0?'0,'+(mEx.toString()).substr(1,aDez):'0';
}

