var xmlHttp
var request
var str = '';
var globalGiveBackMethod;
var data;
var cal1;

function prepareRequestData(data,url,httpRequestMethod,giveBackMethod) {

  xmlHttp=GetXmlHttpObject()
  if (xmlHttp==null) {
    alert ("Browser does not support HTTP Request")
    return
  }
	
	parseData(data);
  
  return_data(data);
	return_GiveBackMethod(giveBackMethod);
		
	if(httpRequestMethod == "GET") {
    url += "?"+str;
	}
	else if(httpRequestMethod == "POST") {
	  request = str;
	}
	
	XmlHttpExecute(url,request,httpRequestMethod);
	  
}


function parseData(data) {
		
  for (var i = 0; i < data.length; i++) {
    for (var key in data[i]) { 
		  if (str.length > 0) str += "&";
		  str += key+"="+escape(data[i][key]);
	  }
  }
	//document.write(str);
  return str;
	
} 

function return_GiveBackMethod(giveBackMethod) {
   
	 globalGiveBackMethod = giveBackMethod;
   return globalGiveBackMethod;

}

function return_data(data) {
   
   data1 = data;
	 return data1;

}


function stateChanged() { 

  if(xmlHttp.readyState==4 || xmlHttp.readyState=="complete") { 
	  
    //var rawdata = xmlHttp.responseText.split("|");	
    //location.reload();
    if(document.getElementById("loader")) document.getElementById("loader").innerHTML = ''; 
    
        
    if(globalGiveBackMethod == 0) {
      if(document.getElementById('loeschcontainer')) document.getElementById('loeschcontainer').style.visibility='hidden';
      if(document.getElementById('papierkorb')) document.getElementById('papierkorb').style.visibility='hidden';
      document.getElementById("tab"+data1[0]['tabnr']).className = "active";
      document.getElementById("anchor"+data1[0]['tabnr']).className = "current";
      document.getElementById("content").innerHTML = xmlHttp.responseText;     
		}     
   	else if(globalGiveBackMethod == 1) {
      document.getElementById('main').innerHTML = xmlHttp.responseText;      
		}
    else if(globalGiveBackMethod == 2) {
           
      for(var i=1; i <= data1[0]['totaltabs']; i++) {
        document.getElementById("tab"+i).className = "";
        document.getElementById("anchor"+i).className = "";
      }
  
      document.getElementById("tab"+data1[0]['tabnr']).className = "active";
      document.getElementById("anchor"+data1[0]['tabnr']).className = "current";
      
      document.getElementById("content").innerHTML = xmlHttp.responseText;
      
      // Datum Wahlwerkzeug für GNM
      if(data1[0]['tabnr'] == '5') {
        cal1 = new calendar1(content.document.getElementById('ntermin'));
        cal1.year_scroll = true;
        cal1.time_comp = false;
      }
         	
	  }
       
  }
	 
}
