/* Funktionen für die Toolbox (Impressum , Datenschutz) */

function Toolbox(action,preSelect) {

	//Seite grundsätzlich nach oben scrollen
	location.href='#top';

	var toolbox = document.getElementById("tb");
	var toolbox_content = document.getElementById("tb_content");
	var html = document.getElementsByTagName("body")[0];

	var htmlheight = $("html").height();
	$("#tb").css("height", htmlheight);

	if(action == true) {
		$("#tb").css("display","block");
		$("#tb_content").css("display","block");

		$("#tb_content").css("left",
		function() {
			return ($("html").width()/2)-110;
		});

		$("html").css("overflow-y","hidden");

		if(preSelect != "")
			selTab(preSelect)
		} else {
			$("#tb").css("display","none");
			$("#tb_content").css("display","none");
			$("html").css("overflow-y","scroll");
		}
}

function setScroller() {
	$("#tabs_scroller").jScrollPane({showArrows:true});
}

function selTab(tbID) {
	var tabs = document.getElementById("tabs");
	var tabscontent = document.getElementById("tabs_scroller");

	tablength = tabs.childNodes.length;
	tabcontentlength = tabscontent.childNodes.length;

	intTrack = 0;

	for(i=0;i<tablength;i++) {
		if(tabs.childNodes[i].nodeType == "1") {
			if(tabs.childNodes[i].firstChild.id == tbID) {
				tabs.childNodes[i].firstChild.className = "link_selected";
				tabscontent.childNodes[i].className="show";
				$("#"+tbID).css("height","100px");
				//setTimeout("setScroller();",200);
			} else {
				tabs.childNodes[i].firstChild.className = "link";
				tabscontent.childNodes[i].className="hide";
			}
			intTrack++;
		}
	}
}


function showMediabox(sValue,sType,sWidth,sHeight,sTop) {

	var mediaboxHtml = '<div class="mediabox" id="mb" onClick="hideMediabox();">&nbsp;</div><div class="mediabox_chain" id="mb_chain"><a href="javascript:void(0)" class="mediabox_close" onClick="hideMediabox();">'+$("a.toolbox_close").html()+'</a><div class="mediabox_content" id="mb_content">&nbsp;</div></div>';


	var sWinHeight = $(window).height();
	var sWinWidth = $(window).width();

	var sBodyHeight = $("body").height();
	var sBodyWidth = $("body").width();

	var sLayerHeight = parseInt(sHeight) + 25;
	var sLayerWidth = parseInt(sWidth);


/*	if(sTop == 0) {
		if(sWinHeight > sBodyHeight) {
			var posY = 15;
		} else {
			var posY = (sBodyHeight/2)-(sLayerHeight/2);
		}
	} else {
		if(document.all) {
			var posY = sTop-120;
		} else {
			var posY = sTop-220;
		}
	}*/

	var posY = sTop;
	var posX = (sWinWidth/2)-(sLayerWidth/2);

	$("body").append(mediaboxHtml);

	if($("body").height()<$("html").height()) {
		mb_height = $("html").height();
	} else {
		mb_height = $("body").height();
	}

	if(sType == "movie") {
		flashembed("mb_content",
			{
				src:'scripts/FlowPlayerClassic.swf',
				width: sWidth,
				height: sHeight
			},
			{config: {
				autoPlay:true,
				initialScale: 'scale',
				videoFile: sValue
			}}
		);
	}

	if(sType == "image") {
		$("#mb_content").css({
			height: sHeight + "px",
			width: sWidth + "px"
		});
		$("#mb_content").append("<img src=\""+sValue+"\" alt=\"\" width=\""+sWidth+"\" height=\""+sHeight+"\" />");
	}

	$("#mb_chain").css({
		display:"block",
		width:sLayerWidth+"px",
		height:sLayerHeight+"px",
		top:posY+"px",
		left:posX+"px"
	});

	$("#mb").css({
		display:"block",
		height:mb_height
	});



}

function hideMediabox() {
/*	$("#mb").css("display","none");
	$("#mb_chain").css("display","none");
	$("#mb_content").html("&nbsp;");*/
	$("#mb").remove();
	$("#mb_content").html("&nbsp;");
	$("#mb_content").remove();
	$("#mb_chain").remove();
}

function getPageScroll(){

	var yScroll;

	if (self.pageYOffset) {
		yScroll = self.pageYOffset;
	} else if (document.documentElement && document.documentElement.scrollTop){	 // Explorer 6 Strict
		yScroll = document.documentElement.scrollTop;
	} else if (document.body) {// all other Explorers
		yScroll = document.body.scrollTop;
	}

	arrayPageScroll = new Array('',yScroll)
	return arrayPageScroll;
}

function getPageSize(){

	var xScroll, yScroll;

	if (window.innerHeight && window.scrollMaxY) {
		xScroll = document.body.scrollWidth;
		yScroll = window.innerHeight + window.scrollMaxY;
	} else if (document.body.scrollHeight > document.body.offsetHeight){ // all but Explorer Mac
		xScroll = document.body.scrollWidth;
		yScroll = document.body.scrollHeight;
	} else { // Explorer Mac...would also work in Explorer 6 Strict, Mozilla and Safari
		xScroll = document.body.offsetWidth;
		yScroll = document.body.offsetHeight;
	}

	var windowWidth, windowHeight;
	if (self.innerHeight) {	// all except Explorer
		windowWidth = self.innerWidth;
		windowHeight = self.innerHeight;
	} else if (document.documentElement && document.documentElement.clientHeight) { // Explorer 6 Strict Mode
		windowWidth = document.documentElement.clientWidth;
		windowHeight = document.documentElement.clientHeight;
	} else if (document.body) { // other Explorers
		windowWidth = document.body.clientWidth;
		windowHeight = document.body.clientHeight;
	}

	// for small pages with total height less then height of the viewport
	if(yScroll < windowHeight){
		pageHeight = windowHeight;
	} else {
		pageHeight = yScroll;
	}

	// for small pages with total width less then width of the viewport
	if(xScroll < windowWidth){
		pageWidth = windowWidth;
	} else {
		pageWidth = xScroll;
	}

	arrayPageSize = new Array(pageWidth,pageHeight,windowWidth,windowHeight)
	return arrayPageSize;
}

function getTop() {
	var arrayPageSize = getPageSize();
	var arrayPageScroll = getPageScroll();

	var boxTop = arrayPageScroll[1] + (arrayPageSize[3]/10);

	return boxTop;
}


/* Wetter */

function listRegion(){
	$.get("scripts/wetter.asp", {act: "list"},
		function(sResult){
			arrRegion = sResult.split(",");
			arrRegion.sort();
			var selRegion = document.getElementById("selRegion");

			for(i=1;i<(arrRegion.length);i++) {
				aCurrentRegion = arrRegion[i].split("_");
				$("#selRegion").append("<li onClick=\"getRegProperties('"+aCurrentRegion[1]+"');\">"+aCurrentRegion[0] + "(" + aCurrentRegion[1] + ")</li>\n");
			}
		})
}

function getRegProperties(sRegion) {
	$.get("scripts/wetter.asp", {act: "getreg", region: sRegion},
		function(sResult) {
			$("#region_result").html(sResult);
		}
	)
}

/* Grußkarten */

			function sendCard() {

			var form = document.getElementById("greeting");

			for (i = 0; i < form.elements.length; ++i){

                if(form.elements[i].checked == true) {
                    switch (form.elements[i].name) {
                        case "motiv": sMotiv = form.elements[i].value; sMotivRel = form.elements[i].getAttribute("rel");
                        break;
                        case "stamp": sStamp = form.elements[i].value;
                        break;
                        case "sound": sSound = form.elements[i].value;
                        break;
                    }
                }

                }

				$.post("scripts/greetings.asp", {
					motiv: sMotiv,
					stamp: sStamp,
					sound: sSound,
					name: $("#sname").val(),
					email: $("#semail").val(),
					rname: $("#rname").val(),
					remail: $("#remail").val(),
					message: $("#text").val(),
					subject: $("#csubject").val(),
					success: $("#csuccess").val(),
					error: $("#cerror").val(),
					url: $("#url").val(),
					greetings: 'new'
				}, function(data){
					$(".preview").css("background","none");
					$(".preview").html(data);
				});
			}

            function cancelPreview() {
            $(".preview .clearfix").html("");
            $(".preview").css({
                    display: 'none'
                });
                $(".form").css({
                    display: 'block'
                });
            }

            function preview() {

			var form = document.getElementById("greeting");
			var sendername = $("#sname").val();
			var sendermail = $("#semail").val();
			var recipientname = $("#rname").val();
			var recipientmail = $("#remail").val();
			var greettext = $("#text").val();


                for (i = 0; i < form.elements.length; ++i){

                if(form.elements[i].checked == true) {
                    switch (form.elements[i].name) {
                        case "motiv": sMotiv = form.elements[i].value; sMotivRel = form.elements[i].getAttribute("rel");
                        break;
                        case "stamp": sStamp = form.elements[i].value;
                        break;
                        case "sound": sSound = form.elements[i].value;
                        break;
                    }
                }

                }

                if(sStamp == "0") {
                    $(".preview").css({
                        background: 'url('+$("#cbg0").val()+')',
                        backgroundRepeat: 'no-repeat'
                    });
                } else {
                    $(".preview").css({
                        background: 'url('+$("#cbg1").val()+')',
                        backgroundRepeat: 'no-repeat'
                    });
                }

                $(".preview img").attr("src",sMotivRel);
                $(".preview span.sender").html(sendername + "<br />(" + sendermail+")");
                $(".preview span.recipient").html(recipientname + "<br />(" + recipientmail +")");
                $(".preview div.greets").html(greettext);

                if(sSound == "1") {
                    $(".preview .clearfix").html("<EMBED id=\"soundfile\" autostart=true hidden=true loop=true AUTOSTART=TRUE SRC=\""+$("#soundfile").val()+"\">");
                }


                $(".preview").css({
                    display: 'block'
                });

                $(".form").css({
                    display: 'none'
                });


            }

function getCard(sID) {

		$.post("scripts/greetings.asp", {
			cardID: sID
		},
			function(data){
				sCardArray = data.split(";");
				var form = document.getElementById("greeting");
				for (i = 0; i < form.elements.length; ++i){
		            if(form.elements[i].value == sCardArray[8]) {
		            	$(".preview img").attr("src",form.elements[i].getAttribute("rel"));
				    }
                }

           		if(sCardArray[5] == "False") {
					$(".preview").css({
						background: 'url(layout/bg_card_ohne.gif)',
		                backgroundRepeat: 'no-repeat'
					});
				} else {
					$(".preview").css({
						background: 'url(layout/bg_card_mit.gif)',
		                backgroundRepeat: 'no-repeat'
					});
				}

				$(".preview span.sender").html(sCardArray[2] + "<br />(" + sCardArray[2] +")");
                $(".preview span.recipient").html(sCardArray[3] + "<br />(" + sCardArray[4] +")");
                $(".preview div.greets").html(sCardArray[7]);

                 if(sCardArray[6] == "True") {
                    $(".preview .clearfix").html("<EMBED id=\"soundfile\" autostart=true hidden=true loop=true AUTOSTART=TRUE SRC=\"layout/fendt_sample_64kbps.mp3\">");
                }


		});



		$(".form").css("display","none");
		$(".preview").css("display","block");
		$(".preview .actions").css("display","none");


	}

function setFavorite(sDomain,sTitle) {
	if(document.all) {
		window.external.AddFavorite(sDomain, sTitle);
	} else {
		window.external.addPanel(sTitle, sDomain, '');
	}
}


/* Für PopUps aus einem Flash heraus */

function openBrWin(theURL,winName,w,h,size) {
	if(!w || !h) {
		var width = screen.width;
		var height = screen.height;
	} else {
		var width = w;
		var height = h;
	}

	var winl = (screen.width - w) / 2;
	var wint = (screen.height - h) / 2;

	winprops = 'height='+height+',width='+width+',top='+wint+',left='+winl+',resizable='+size+''
	win = window.open(theURL,winName,winprops)
	if (parseInt(navigator.appVersion) >= 4) { win.window.focus(); }
}

/* Für Konfigurator-Link */
function openConfigurator(model,language) {

$.get("/requestservervar.asp", function(returned_data) {

		var configWindow = window.open('http://www.fendt.com/publicweb/index.php?xIP='+returned_data+'&xSprache='+language+'&xBaureihe='+model,'Configurator','width=1024,height=740,resizable=no');
		
		configWindow.focus();
            
    });

}
	
/* JQUERY Function für IE-Navigation DropDown */

jQuery.fn.dropdown = function(type) {
        if ($.browser.msie && $.browser.version*1 < 7){
          this.find(type).hover(function(){
            $(this).addClass('over');
          },
          function(){
            $(this).removeClass('over');
          });
        }
      }

	  

