function MM_swapImgRestore() { //v3.0
  var i,x,a=document.MM_sr; for(i=0;a&&i<a.length&&(x=a[i])&&x.oSrc;i++) x.src=x.oSrc;
}

function MM_findObj(n, d) { //v4.01
  var p,i,x;  if(!d) d=document; if((p=n.indexOf("?"))>0&&parent.frames.length) {
    d=parent.frames[n.substring(p+1)].document; n=n.substring(0,p);}
  if(!(x=d[n])&&d.all) x=d.all[n]; for (i=0;!x&&i<d.forms.length;i++) x=d.forms[i][n];
  for(i=0;!x&&d.layers&&i<d.layers.length;i++) x=MM_findObj(n,d.layers[i].document);
  if(!x && d.getElementById) x=d.getElementById(n); return x;
}

function MM_swapImage() { //v3.0
  var i,j=0,x,a=MM_swapImage.arguments; document.MM_sr=new Array; for(i=0;i<(a.length-2);i+=3)
   if ((x=MM_findObj(a[i]))!=null){document.MM_sr[j++]=x; if(!x.oSrc) x.oSrc=x.src; x.src=a[i+2];}
}

function GP_AdvOpenWindow(theURL,winName,features,popWidth,popHeight,winAlign,ignorelink,alwaysOnTop,autoCloseTime,borderless) { //v2.0
  var leftPos=0,topPos=0,autoCloseTimeoutHandle, ontopIntervalHandle, w = 480, h = 340;  
  if (popWidth > 0) features += (features.length > 0 ? ',' : '') + 'width=' + popWidth;
  if (popHeight > 0) features += (features.length > 0 ? ',' : '') + 'height=' + popHeight;
  if (winAlign && winAlign != "" && popWidth > 0 && popHeight > 0) {
    if (document.all || document.layers || document.getElementById) {w = screen.availWidth; h = screen.availHeight;}
		if (winAlign.indexOf("center") != -1) {topPos = (h-popHeight)/2;leftPos = (w-popWidth)/2;}
		if (winAlign.indexOf("bottom") != -1) topPos = h-popHeight; if (winAlign.indexOf("right") != -1) leftPos = w-popWidth; 
		if (winAlign.indexOf("left") != -1) leftPos = 0; if (winAlign.indexOf("top") != -1) topPos = 0; 						
    features += (features.length > 0 ? ',' : '') + 'top=' + topPos+',left='+leftPos;}
  if (document.all && borderless && borderless != "" && features.indexOf("fullscreen") != -1) features+=",fullscreen=1";
  if (window["popupWindow"] == null) window["popupWindow"] = new Array();
  var wp = popupWindow.length;
  popupWindow[wp] = window.open(theURL,winName,features);
  if (popupWindow[wp].opener == null) popupWindow[wp].opener = self;  
  if (document.all || document.layers || document.getElementById) {
    if (borderless && borderless != "") {popupWindow[wp].resizeTo(popWidth,popHeight); popupWindow[wp].moveTo(leftPos, topPos);}
    if (alwaysOnTop && alwaysOnTop != "") {
    	ontopIntervalHandle = popupWindow[wp].setInterval("window.focus();", 50);
    	popupWindow[wp].document.body.onload = function() {window.setInterval("window.focus();", 50);}; }
    if (autoCloseTime && autoCloseTime > 0) {
    	popupWindow[wp].document.body.onbeforeunload = function() {
  			if (autoCloseTimeoutHandle) window.clearInterval(autoCloseTimeoutHandle);
    		window.onbeforeunload = null;	}  
   		autoCloseTimeoutHandle = window.setTimeout("popupWindow["+wp+"].close()", autoCloseTime * 1000); }
  	window.onbeforeunload = function() {for (var i=0;i<popupWindow.length;i++) popupWindow[i].close();}; }   
  document.MM_returnValue = (ignorelink && ignorelink != "") ? false : true;
}


function sending_data(lang) {
	var get_name = document.getElementById('downloads_name').value;
	var get_mail = document.getElementById('downloads_email').value;
	var get_firm = document.getElementById('downloads_firma').value;
	var get_tele = document.getElementById('downloads_telefon').value;
	
	loadData('/'+lang+'/Download/download.php?kat=1&name='+get_name+'&mail='+get_mail+'&firma='+get_firm+'&telefon='+get_tele);
}

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;
}

//Keyhandler for Overlay
function keyPressHandler(e) {
  
  var kC  = (window.event) ?    // MSIE or Firefox?
			 event.keyCode : e.keyCode;
  var Esc = (window.event) ?   
			27 : e.DOM_VK_ESCAPE // MSIE : Firefox
  
  if(kC==Esc && document.getElementById("Overlay").style.display != 'none')
	 hideOverlay();
}

document.onkeypress = keyPressHandler;

//Overlay
function showBox(val) {
		
	var obj = document.getElementById("InlineFrame");
	
	obj.style.display = val;
}

function showOverlay(varfile) {
	
	loadData(varfile);
	
	// stretch overlay to fill page and fade in
	var arrayPageSize = getPageSize();
	document.getElementById("Overlay").style.height = arrayPageSize[1];
	
	new Effect.Appear('Overlay', {duration:0.5, from:0.0, to:0.7});
	setTimeout("showBox('')", 600);
}

function hideOverlay() {
	
	showBox('none');
	new Effect.Appear('Overlay', {duration:0.5, from:0.7, to:0.0});
	setTimeout("document.getElementById('Overlay').style.display = 'none'", 600);
}


function showBox_02(val) {
		
	var obj = document.getElementById("InlineFrame02");
	
	obj.style.display = val;
}

function showOverlay_02(varfile) {
	
	document.getElementById("InlineFrame02").innerHTML = '<div><img src="'+varfile+'" border="0" onClick="hideOverlay_02();"></div><div id="CloseButton" style="position:relative; top:-510px;">'+
    '<a href="javascript:;" onClick="hideOverlay_02();" title="Close"><img src="/Bilder/Layout/close.gif" border="0"> Close</a>'+
  '</div>';
	
	// stretch overlay to fill page and fade in
	var arrayPageSize = getPageSize();
	document.getElementById("Overlay02").style.height = arrayPageSize[1];
	
	new Effect.Appear('Overlay02', {duration:0.5, from:0.0, to:0.7});
	setTimeout("showBox_02('')", 600);
}

function hideOverlay_02() {
	
	showBox_02('none');
	new Effect.Appear('Overlay02', {duration:0.5, from:0.7, to:0.0});
	setTimeout("document.getElementById('Overlay02').style.display = 'none'", 600);
}


function createXMLHTTPRequest() {
	
	var http_request = null;
		
	if(window.XMLHttpRequest) {
		
		return new XMLHttpRequest();
	}
	else if(window.ActiveXObject) {
		
		try {
			
			return new ActiveXObject("Msxml2.XMLHTTP");
		}
		catch(e) {
			
			try {
				
				return new ActiveXObject("Microsoft.XMLHTTP");
			}
			catch(e) {
				
				return null;
			}
		}
	}
}

function setContent() {
	
	if(http_request.readyState < 4) {
		
		document.getElementById("InlineFrame").innerHTML = '<div>loading...</div>';
	}
	
	if (http_request.readyState == 4) {
			
		document.getElementById("InlineFrame").innerHTML = http_request.responseText;
	}
}

//Functions for subcontent
function loadData(varfile) {

	http_request = createXMLHTTPRequest();
	http_request.onreadystatechange = setContent;
	http_request.open('GET', varfile, true);
	http_request.send(null);
}

function showControl(val_obj) {
	
	var obj = document.getElementById(val_obj);
	
	obj.style.display = (obj.style.display) ? '' : 'none';
}

function resetControls(val_obj, arr_obj) {

	var arr_vals = arr_obj.split(",");
	
	for(var i = 0;i<arr_vals.length;i++) {
		
		var obj = document.getElementById(arr_vals[i]);
		
		obj.style.display = 'none';
	}
	
	document.getElementById(val_obj).style.display = '';
}

//Functions for retailer
function getRetailer(id, country) {
	
	var arr_id = id.split(";");
	
	if(arr_id[1] == true) {
		
		loadData('/'+country+'/Kontakt/kontakt.php?set=retailer');
	}
	else {
		
		http_request = createXMLHTTPRequest();
		http_request.onreadystatechange = setRetailerData;
		http_request.open('GET', '/Includes/retailer.php?id='+arr_id[0], true);
		http_request.send(null);
	}
}

function setRetailerData() {

	if(http_request.readyState < 4) {
		
		document.getElementById("retailer").innerHTML = 'loading...';
	}
	
	if (http_request.readyState == 4) {
		
		if(document.getElementById("retailer").innerHTML != http_request.responseText) {	
			
			document.getElementById("retailer").innerHTML = http_request.responseText;
		}
	}
}

//Mail
function setMailOutput() {
	
	if (http_request.readyState == 4) {
		
		document.getElementById("errors").style.display = '';
		document.getElementById("errors").innerHTML = http_request.responseText;
		
		if(http_request.responseText == "Nachricht erfolgreich versendet.") {
		
			setTimeout("hideOverlay()", 3000);
		}
	}
}

function send_mail(CCcode) {
	
	var el = document.form1.elements;
	var param = "";
	
	for(var i = 0;i<el.length;i++) {
		
		param += "&"+el[i].name+"="+encodeURI(el[i].value);
	}
	
	http_request = createXMLHTTPRequest();
	http_request.onreadystatechange = setMailOutput;
	http_request.open('POST', '/'+CCcode+'/Kontakt/mail.inc.php?', true);
	http_request.setRequestHeader("Content-type", "application/x-www-form-urlencoded");
	http_request.send(param);
}
