// JavaScript Document

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("nachricht").value;
	var email = document.getElementById("meine_email").value;
	var name = document.getElementById("mein_name").value;
	var args = 'valid=1&nachricht='+nachricht+'&meine_email='+email+'&mein_name='+name;
	ajaxRequest(whichLayer, whichArticle, whichLang, args);
}

function checkVote(whichLayer, whichArticle, whichLang, whichValue) {
	var vote = whichValue;
	var args = 'valid=1&vote='+vote;
	ajaxRequest(whichLayer, whichArticle, whichLang, args);
}

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