// JavaScript Document

function switchLayer(whichBtn,whichLayer){
	if(document.getElementById(whichLayer).style.display == "block") {
		document.getElementById(whichLayer).style.display = "none";
	}
	else{
		var posArray = findPos(whichBtn);
		var myCurTop = posArray[1] - 400;
		var myCurLeft = posArray[0] - 140;
		document.getElementById(whichLayer).style.display = "block";
		document.getElementById(whichLayer).style.top = myCurTop + 'px';
		document.getElementById(whichLayer).style.left = myCurLeft + 'px';
	}
}

function showDetail(whichLayer){
	if(document.getElementById(whichLayer).style.display == "block"){
		document.getElementById(whichLayer).style.display = "none";	
	}
	else{
		document.getElementById(whichLayer).style.display = "block";
	}
	
}

function findPos(obj) {
	var curleft = curtop = 0;

	if (obj.offsetParent) {

	do {
			curleft += obj.offsetLeft;
			curtop += obj.offsetTop;


	} while (obj = obj.offsetParent);

	var posArray = new Array(curleft,curtop);
	return posArray;
	}
}

function createXMLHttpRequest() {
   try { return new ActiveXObject("Msxml2.XMLHTTP"); } catch (e) {}
   try { return new ActiveXObject("Microsoft.XMLHTTP"); } catch (e) {}
   try { return new XMLHttpRequest(); } catch(e) {}
   alert("XMLHttpRequest not supported");
   return null;
 }
 
function ajaxRequest(whichLayer, whichArticle, whichLang, whichArgs){
	var req = createXMLHttpRequest();
	var myPath = createPath();
	req.open("POST", myPath + '?article_id='+whichArticle+'&clang='+whichLang+'', true);
	req.setRequestHeader('Content-Type', 'application/x-www-form-urlencoded');
	req.onreadystatechange = function(){            
                    switch(req.readyState) {
                            case 4:
                            if(req.status!=200) {
                                alert("Fehler:"+req.status); 
                            }else{    
                                document.getElementById(whichLayer).innerHTML = req.responseText;
								//schreibe die antwort in den div container mit der id content 
                                
                            }
                            break;                    
                              
                        }
	};
  
	req.send(whichArgs); 
}

function checkForm(whichLayer, whichArticle, whichLang) {
	var nachricht = document.getElementById("Message").value;
	var email = document.getElementById("Email").value;
	var name = document.getElementById("Last").value;
	var sender = document.getElementById("First").value;
	var link = document.getElementById("link").value;
	var args = 'valid=1&Message='+nachricht+'&Email='+email+'&Last='+name+'&First='+sender+'&link='+link;
	ajaxRequest(whichLayer, whichArticle, whichLang, args);
	return false;	
}


function createPath(){
	var host = window.location.host;
	var path = window.location.pathname;
	return("http://"+host+path);
	
}

function fadeContentIn(){
	$('#fadeContent').fadeIn('slow');
}

