var onLoadFunctions="";
function initOnLoadEvent(){
	eval(onLoadFunctions);
}
function addOnLoadEvent(functionString){
	if(functionString.lastIndexOf(';')!=functionString.length-1)functionString += ';';
	onLoadFunctions += functionString;
}
window.onload =initOnLoadEvent;

var lastEventMouseX=0;
var lastEventMousey=0;	
	function createXMLHttpRequest() {
		var ua;
	       try{
	           ua = new XMLHttpRequest();
	       }
	       catch (e){
	           try{
	               ua = new ActiveXObject("Msxml2.XMLHTTP");
	           }
	           catch (e){
	               try{
	                   ua = new ActiveXObject("Microsoft.XMLHTTP");
	               }
	               catch (failed){
	                   ua = null;
	               }
	           }
	       }
		    return ua;
	}
	var ajaxReqURLs = new Array();
	var runningAjaxReqs = new Array();
	var ajaxReqFunctions = new Array();
	var req=null;
	function setAjaxRequestRunning(){
		var runningCount=0;
		for(var i=0;i<ajaxReqURLs.length;i++){
			var curReq = runningAjaxReqs[i];
			if(curReq!=null)runningCount++;
			if(curReq!=null && curReq.readyState == 4){
				if(curReq.status == 200){
					var text = curReq.responseText;
					req = runningAjaxReqs[i];
					window.setTimeout(ajaxReqFunctions[i], 1);
				 	ajaxReqURLs[i]=null;
					runningAjaxReqs[i]=null;
					ajaxReqFunctions[i]=null;
				}else{
					alert("Request Fail: Statustext:"+curReq.statustext+" Status:"+curReq.status+" readyState"+curReq.readyState+"\nText:"+curReq.responseText);
				}
			}
		}
		if(runningCount==0){
			ajaxReqURLs = new Array();
			runningAjaxReqs = new Array();
			ajaxReqFunctions = new Array();
		}
	}
	function sendAjaxRequest1(url,processReq){
		var curReq = createXMLHttpRequest();
		ajaxReqURLs.push(url);
		var pos = ajaxReqURLs.length-1;
		runningAjaxReqs[pos]=curReq;
		ajaxReqFunctions[pos]=processReq;

		curReq.onreadystatechange=setAjaxRequestRunning;
		curReq.open("GET",url,true);
		curReq.send(null);
	}
	function genAjaxFormSubmit(url, form_id, processReq){
		var form = document.getElementById(form_id);
		var attribute = "";
		var select_fields = form.getElementsByTagName("select");
		//Select-Felder
		for(var i=0;i<select_fields.length;i++){
			attribute = attribute + "&" + select_fields[i].name + "="+ select_fields[i].options[select_fields[i].options.selectedIndex].value;
		}
		// Input-Felder
		var input_fields = form.getElementsByTagName("input");
		for(var i=0;i<input_fields.length;i++){
			if(input_fields[i].type=="checkbox"){
				if(input_fields[i].checked == true){
					attribute = attribute + "&" + input_fields[i].name + "="+ input_fields[i].value;
				}
			}else{
				attribute = attribute + "&" + input_fields[i].name + "="+ input_fields[i].value;
			}
		}
		var input_fields = form.getElementsByTagName("textarea");
		for(var i=0;i<input_fields.length;i++){
			attribute = attribute + "&" + input_fields[i].name + "="+ input_fields[i].value;
		}
//		alert(attribute);
//		window.open(url+attribute,"","");
		sendAjaxRequest1(url+attribute,processReq);
	}
	function processReq(){
		if(req.readyState == 4 && req.status == 200) {
			return req.responseText;
		}else if(this.readyState == 4){
			alert("Request Fail:"+req.statustext+" "+req.status);
		}
	}
	function processReqYachtList(){
		if(processReq() != "undefined"){
			document.getElementById("hover").innerHTML = processReq();
		}
		sIFRReplace();
	}
	var imggro =new Array();
	var imgkl =new Array();
	function getparam(){
		var temp = document.getElementById("imgbig").getElementsByTagName("img");
		for(var i=0;i<temp.length;i++){
			imggro.push(temp[i].src);
		}
		temp = document.getElementById("imgsmall").getElementsByTagName("img");
		for(var i=0;i<temp.length;i++){
			imgkl.push(temp[i].src);
		}
		/*
		var zeichenkette=document.getElementById("imgbig").firstChild.nodeValue;
		var zeichenkettezwo=document.getElementById("imgsmall").firstChild.nodeValue;
		sondiert=zeichenkette.replace(/'/g, "");
		sondiertzwo=zeichenkettezwo.replace(/'/g, "");
		imggro = sondiert.split (',');
		imgkl  = sondiertzwo.split (',');*/
	}

	function showImage(x){
		document.getElementById("large_img2").innerHTML ="<div style='width:450px;height:300px;overflow:hidden;text-align:center;'><img style='height:300px;' src='"+x+"' alt='Grossansicht' /></div>";
	}
	function showImage2(x){
		document.getElementById("large_img_src").src =x;
	}
	function showContactFrom(url){
		set_bgblack("kontaktform_background");
		sendAjaxRequest1(url,processReqShowContactFrom);
	}
	function closeContact(){
		document.getElementById('kontaktform_div').style.display='none';
		document.getElementById('kontaktform_background').style.display='none';
	}
	function processReqShowNormalContactForm(){	
		var html =  processReq();
		document.getElementById("kontaktform_div").innerHTML =html;
	}
	function processReqShowContactFrom(){
		var html =  processReq();
		if(html=="OK"){
			closeContact();
			return;
		}
		document.getElementById("kontaktform_div").innerHTML =html;
		document.getElementById('kontaktform_div').style.display='block';
		document.getElementById('kontaktform_background').style.display='block';
		//set_bgblack('kontaktform_background');
		center_kontaktform_div();
	}
	
	function vis_an_aus(x){
		if(x=='an'){
			document.getElementById('kontaktform_div').style.display='block';
			document.getElementById('kontaktform_background').style.display='block';
		}else if(x=='aus'){
			document.getElementById('kontaktform_div').style.display='none';
			document.getElementById('kontaktform_background').style.display='none';
		}
	}

	function submitformcon(){
	  document.conform.submit();
	}
	function BilderInsert(){
		var html;
		for(var i=0; i<imgkl.length; i++){
			html="<li><img src='"+imgkl[i]+"' style='cursor:pointer;height:70px;' alt='Thumbnail' onmouseover=\"showImage('"+imggro[i]+"');\" /></li>";
			document.getElementById('thumbnails').innerHTML+=html;
		}
	}
	function processReqDetailView(){
		var html =  processReq();
		document.getElementById("detailViewContent").innerHTML =html;
		document.getElementById("yachtblock").style.position="absolute";
		center_yacht_block();
		if(document.getElementById("imgbig").firstChild !=null){
			getparam();
			showImage(imggro['0']);
			BilderInsert();
			hanseSlideshow2();
		}
	}
	function showImagesDetailView(){
		if(document.getElementById("imgbig").firstChild !=null){
			getparam();
			showImage(imggro['0']);
			BilderInsert();
		}
	}
	function showYachtListLoad(){
		document.getElementById("hover").innerHTML = "<div style=\"text-align:center;\"><img src=\"images/ajax-loader.gif\" alt=\"\" /></div>";
	}

	function center_yacht_block(){
		var scrollPos = document.body.scrollTop;
		var lightBoxHeight=660;
		var lightBoxTop=30;
		if(scrollPos==0)scrollPos=document.documentElement.scrollTop;
//		alert(scrollPos+" "+lastEventMouseY);
		if(lastEventMouseY > scrollPos+lightBoxHeight+lightBoxTop){
			scrollPos = lastEventMouseY - (lightBoxHeight+lightBoxTop);
		}else{
			scrollPos +=lightBoxTop;
		}
		//var bodyhight=document.getElementsByTagName('body')[0].scrollHeight;
		var bodywidth=document.getElementsByTagName('body')[0].scrollWidth;
		//var yachtblock_height=document.getElementById('yachtblock').style.height;
		var yachtblock_width=document.getElementById('yachtblock').style.width;

		//var yacht_block_y=yachtblock_height.substr(0,yachtblock_height.length-2);
		var yacht_block_x=yachtblock_width.substr(0,yachtblock_width.length-2);
		//var erg= parseInt(bodyhight)-(parseInt(yachtblock_height)+parseInt(160));
		var erg2=(parseInt(bodywidth)-parseInt(yacht_block_x))/2;
		document.getElementById('yachtblock').style.top=scrollPos+'px';
		document.getElementById('yachtblock').style.left=erg2+'px';
	}

	function set_bgblack(divName){
		var bodyhight=document.getElementsByTagName('body')[0].scrollHeight;
		var bodywidth=document.getElementsByTagName('body')[0].scrollWidth;
		document.getElementById(divName).style.width=bodywidth+'px';
		document.getElementById(divName).style.height=bodyhight+'px';
		//document.getElementById('yachtblock').style.zIndex="49";
	}

	function center_kontaktform_div(){
		//var bodyhight=document.getElementsByTagName('body')[0].scrollHeight;
		var bodywidth=document.getElementsByTagName('body')[0].scrollWidth;

		//var kontaktform_height=document.getElementById('kontaktform_div').style.height;
		var kontaktform_width=document.getElementById('kontaktform_div').style.width;

		//var kontaktform_y=kontaktform_height.substr(0,kontaktform_height.length-2);
		var kontaktform_x=kontaktform_width.substr(0,kontaktform_width.length-2);

		//var erg= parseInt(bodyhight)-(parseInt(kontaktform_height)+parseInt(300));
		var erg2=(parseInt(bodywidth)-parseInt(kontaktform_x))/2;
		var top = parseInt(document.getElementById('yachtblock').style.top); 
		top+=50;
		document.getElementById('kontaktform_div').style.top= top+"px"; //erg+'px';
		document.getElementById('kontaktform_div').style.left=erg2+'px';
	}
