/* Ein neues XMLHttpRequest Objekt erstellen, um mit dem Webserver zu sprechen */
var xmlHttp = false;
/*@cc_on @*/
/*@if (@_jscript_version >= 5)
try {
  xmlHttp = new ActiveXObject("Msxml2.XMLHTTP");
} catch (e) {
  try {
    xmlHttp = new ActiveXObject("Microsoft.XMLHTTP");
  } catch (e2) {
    xmlHttp = false;
  }
}
@end @*/

if (!xmlHttp && typeof XMLHttpRequest != 'undefined') {
  xmlHttp = new XMLHttpRequest();
}

function callServer() {
  var url = "/cgi-bin/CiXbase/brewis/CiXbase_search?act=screen&screen=D005&CID=new";
  xmlHttp.open("GET", url, true);
  xmlHttp.onreadystatechange = updatePage;
  xmlHttp.send(null);
  return;
  }

function callServer2() {
	eraseCookie('VisitorID');
	callServer();
	return;
	}

function updatePage() {
  if (xmlHttp.readyState == 4) {
    var response = xmlHttp.responseText.split(':');
	if (response[2]) {
	var end1 = response[2].length-2;
	var antwort = response[2].substring(0,end1);
    Set_Cookie('VisitorID',antwort,"; expires=at end of session","/");
	document.getElementById("CID").value = antwort;	
	if (document.thema) {document.thema.CID.value = antwort;}
	}
  }
  return;
}

function SetCID() {
if (Get_Cookie('VisitorID')) {
       var VisitorID = Get_Cookie('VisitorID');
	   if (document.suche) {document.suche.CID.value = VisitorID;}
   	   if (document.autoren) {document.autoren.CID.value = VisitorID};	
	   if (document.merkliste) {document.merkliste.CID.value = VisitorID};
	   if (document.getElementById('PagesDisplayForm')) {document.getElementById('PagesDisplayForm').CID.value = VisitorID};
   }
}

function Get_Cookie(name) {
   var start = document.cookie.indexOf(name+"=");
   var len = start+name.length+1;
   if ((!start) && (name != document.cookie.substring(0,name.length))) return null;
   if (start == -1) return null;
   var end = document.cookie.indexOf(";",len);
   if (end == -1) end = document.cookie.length;
   return unescape(document.cookie.substring(len,end));
}

function Set_Cookie(name,value,expires,path,domain,secure) {
    var cookieString = name + "=" + value +
       expires +
       ( (path) ? ";path=" + path : "") +
       ( (domain) ? ";domain=" + domain : "") +
       ( (secure) ? ";secure" : "");
    document.cookie = cookieString;
	return;
}

function Delete_Cookie(name,path,domain) {
   if (Get_Cookie(name)) document.cookie = name + "=" +
      ( (path) ? ";path=" + path : "") +
      ( (domain) ? ";domain=" + domain : "") +
      ";expires=Thu, 01-Jan-70 00:00:01 GMT";
}

var today = new Date();
var zero_date = new Date(0,0,0);
today.setTime(today.getTime() - zero_date.getTime());
var cookie_expire_date = new Date(today.getTime() + (8 * 7 * 86400000));

function setVisitorID() {
   if (Get_Cookie('VisitorID')) {
       SetCID();
   }else{
   		callServer();
   }
}

function createElement(type, name) {
   var element = null;

   try {
      // First try the IE way; if this fails then use the standard way
      element = document.createElement('<'+type+' name="'+name+'">');
   } catch (e) {
      // Probably failed because we�re not running on IE
   }
   if (!element) {
      element = document.createElement(type);
      element.name = name;
   }
   return element;
	try {
   		element.setAttribute("type", "radio");
		} catch (e) {
	var newElement = null;
   	var tempStr = element.getAttribute("name");
   	try {
    	newElement = document.createElement("<input type=\"" +typeStr+ "\" name=\"" +tempStr+ "\">");
   		} catch (e) {}
   	if (!newElement) {
      	newElement = document.createElement("input");
      	newElement.setAttribute("type", "radio");
      	newElement.setAttribute("name", tempStr);
   		}
   	if (tempStr = element.getAttribute("value")) {
      	newElement.setAttribute("value", tempStr);
   		}
   	element.parentNode.replaceChild(newElement, element);
}
}

var loaded_script = true; 
