function createXMLHttpRequest() {
	var ua;
	if(window.XMLHttpRequest) {
    		try {
      			ua = new XMLHttpRequest();
    		} catch(e) {
      			ua = false;
    		}
  	}
	else if(window.ActiveXObject) {
    		try {
      			ua = new ActiveXObject("Microsoft.XMLHTTP");
    		} catch(e) {
      			ua = false;
    		}
  	}
  	return ua;
}

var req = createXMLHttpRequest();
var qer = createXMLHttpRequest();

function sendRequest(source_field, dest_field, dest_field1) {
	destination_field = dest_field;
	destination_field1 = dest_field1;
 	id = document.getElementById(source_field).value;
  	req.open('get', 'ajax/' + dest_field +'.php?s='+ id);
	qer.open('get', 'ajax/' + dest_field1 +'.php?s='+ id);
  	req.onreadystatechange = handleResponse;
	qer.onreadystatechange = handleResponse;
  	req.send(null);
	qer.send(null);
}

function handleResponse() {
	if(req.readyState == 4){
    		document.getElementById(destination_field).innerHTML = req.responseText;
  	}
	if(qer.readyState == 4){
		document.getElementById(destination_field1).innerHTML = qer.responseText;
	}
}

var color="1px solid #E89302";
var color2="1px solid #7F9DB9";

function changeBgImage (image, id) {
	var element = document.getElementById(id);
	element.style.backgroundImage = "url("+image+")";
}

function a_set(obj,x)
{
	if(x=="1")
	{ 
		obj.style.border=color;
	}
	else
	{
		obj.style.border=color2; 
	}
}

function toggleMe(a){
  var e=document.getElementById(a);
  if(!e)return true;
  if(e.style.display=="none"){
    e.style.display="block"
  } else {
    e.style.display="none"
  }
  return true;
}

if(window.navigator.systemLanguage && !window.navigator.language) {
  	function hoverIE(load) {
    		var LI = document.getElementById(load).firstChild;
    		do {
      			if (sucheUL(LI.firstChild)) {
			LI.onmouseover=einblenden; LI.onmouseout=ausblenden;
      		}
      		LI = LI.nextSibling;
    	}
     	while(LI);
}

function sucheUL(UL) {
	do {
      		if(UL) UL = UL.nextSibling;
      		if(UL && UL.nodeName == "UL") return UL;
    	}
    	while(UL);
    		return false;
  	}
  	function einblenden() {
    		var UL = sucheUL(this.firstChild);
    		UL.style.display = "block";
  	}
  	function ausblenden() {
    		sucheUL(this.firstChild).style.display = "none";
  	}
	function onHookLoad() {
		var x = 9;
		var i = 1;
		try
		{ 
			hoverIE('leftbox');
			hoverIE('sort');
			do {
    				hoverIE('show_'+ i +'');
				hoverIE('hp_'+ i +'');
    				hoverIE('mail_'+ i +'');
    				hoverIE('map_'+ i +'');
				i++;
			} while(i <= x);
		}
		catch(e)
		{

		}
	}
	window.onload=onHookLoad;
}

function print(seite)
{
	var eigenschaft,sbreite,shoehe,fenster02;
  	var ns6=(!document.all && document.getElementById);
   	var ie4=(document.all);
   	var ns4=(document.layers);

	if(ns6||ns4)
     	{
      		sbreite = innerWidth;
      		shoehe = innerHeight;
      	} 
	else if(ie4)
        {
         	sbreite = document.body.clientWidth;
         	shoehe = document.body.clientHeight;
        }
 	fensterbreite=656;
   	shoehe=shoehe-100;

   	popUp=window.open(seite, 'NewWindows', 'toolbar=no, location=no, directories=no, status=no, menubar=no, scrollbars=yes, resizable=yes, width='+fensterbreite+', height='+shoehe+', left=50, top=50');
}

function selectLang(idx) {
   var locale = locales[idx];
   collapseLandLangPulldown();
   changelang(idx);
}

function hiLight(langImg, idx, over) {
   langImg.src = (over) ? langOverImgs[idx].src : langImgs[idx].src;
}

function createTooltip(id) {
   var tt = document.createElement("DIV");
   tt.id = id;
   tt.style.border='none';
   tt.style.position='absolute';
   document.body.appendChild(tt);
   return tt;
}

function findPos(obj) {
	var curleft = 0;
    var curtop = 0;
	if (obj.offsetParent) {
		curleft = obj.offsetLeft
		curtop = obj.offsetTop
		while (obj = obj.offsetParent) {
			curleft += obj.offsetLeft
			curtop += obj.offsetTop
		}
	}
    return [curleft,curtop];
}

function getLangPulldownMenu(img) {
    var pdDiv = createTooltip('langselection');
    var top = img.clientY;
    var pos = findPos(img);
    pdDiv.style.left = (pos[0] + 3) + 'px';
    pdDiv.style.top = (pos[1]+ 22) + 'px';
    return pdDiv;
}

function runLangPulldown(img) {
    var langPulldown = document.getElementById('langselection');
    if (langPulldown != null) {
        collapseLandLangPulldown()
    }
    else {
        expandLangPulldown(img);
    }
}

function collapseLandLangPulldown() {
    var langPulldown = document.getElementById('langselection');
    if (langPulldown != null) {
        langPulldown.style.visibility='hidden';
        document.body.removeChild(langPulldown);
        langPulldown = null;
    }
}

function expandLangPulldown(img) {
    var langPulldown = getLangPulldownMenu(img);
    langPulldown.innerHTML=getPulldownHTML();
    langPulldown.style.visibility='visible';
}

function getPulldownHTML() 
{
    var pulldownHTML = '<table cellpadding="0" cellspacing="0" border="0" id="langSelection" class="lang_pulldown">';
	    pulldownHTML = pulldownHTML.concat('<tr class="lang_pulldown">');
    pulldownHTML = pulldownHTML.concat('<td class="lang_pulldown"><img src="img/en_a.gif" onclick="javascript:selectLang(0)" onMouseOut="javascript:hiLight(this, 0, false)" onMouseOver="javascript:hiLight(this, 0, true)"/></td>');
    pulldownHTML = pulldownHTML.concat('</tr>');
	    pulldownHTML = pulldownHTML.concat('<tr class="lang_pulldown">');
    pulldownHTML = pulldownHTML.concat('<td class="lang_pulldown"><img src="img/de_a.gif" onclick="javascript:selectLang(1)" onMouseOut="javascript:hiLight(this, 1, false)" onMouseOver="javascript:hiLight(this, 1, true)"/></td>');
    pulldownHTML = pulldownHTML.concat('</tr>');
	    pulldownHTML = pulldownHTML.concat('<tr class="lang_pulldown">');
    pulldownHTML = pulldownHTML.concat('<td class="lang_pulldown"><img src="img/ct_a.gif" onclick="javascript:selectLang(2)" onMouseOut="javascript:hiLight(this, 2, false)" onMouseOver="javascript:hiLight(this, 2, true)"/></td>');
    pulldownHTML = pulldownHTML.concat('</tr>');
	    pulldownHTML = pulldownHTML.concat('<tr class="lang_pulldown">');
    pulldownHTML = pulldownHTML.concat('<td class="lang_pulldown"><img src="img/ru_a.gif" onclick="javascript:selectLang(3)" onMouseOut="javascript:hiLight(this, 3, false)" onMouseOver="javascript:hiLight(this, 3, true)"/></td>');
    pulldownHTML = pulldownHTML.concat('</tr>');
	
    return pulldownHTML;
}

function autoSenseLang() {
    try {
        var url = window.location.href;
        var locale = getLocale();
        if (undefined == locale) {
            return;
        }
        if ('en_US' != locale && url.indexOf('/' + locale + '/') == -1) {
            window.location.href = '/' + locale;
        }
    }
    catch (error) {
        ;
    }
}

function getLangFromURL() {
    var url = window.location.href;
    var lang = locales[0];
    for (var i=1; i < locales.length; i++) {
        if (url.indexOf('/' + locales[i] + '/') != -1) {
            lang = locales[i];
            break;
        }
    }
    return lang;
}

function getUnique(max) {
    var now = new Date();
    return (now.getMilliseconds() * Math.floor(Math.random()*max+1));
}

function isWin() {
    return (navigator.platform.indexOf('Win') != -1);
}

function isVista() {
    return (navigator.userAgent.indexOf("Windows NT 6.0") != -1);
}

function isMac() {
    return (navigator.platform.indexOf('Mac') != -1);
}

function isLinux() {
    return (navigator.platform.indexOf('Linux') != -1);
}


function changelang(id)
{
	if (id == 0)
	{
		document.location = '?lang=en';
	}
	if (id == 1)
	{
		document.location = '?lang=de';
	}
	if (id == 2)
	{
		document.location = '?lang=ct';
	}
	if (id == 3)
	{
		document.location = '?lang=ru';
	}
}

function CheckLen(Target)
{
	var maxlength = "1000";

	StrLen=Target.value.length;

	if (StrLen==1&&Target.value.substring(0,1)==" ")
	{
		Target.value="";
		StrLen=0;
	}
	if (StrLen>maxlength )
	{
		Target.value=Target.value.substring(0,maxlength);
		CharsLeft=0;
	}
	else
	{
		CharsLeft=maxlength-StrLen;
	}
	document.email.counter.value=CharsLeft;
}

function CheckLen1(Target)
{
	var maxlength = "1000";

	StrLen=Target.value.length;

	if (StrLen==1&&Target.value.substring(0,1)==" ")
	{
		Target.value="";
		StrLen=0;
	}
	if (StrLen>maxlength )
	{
		Target.value=Target.value.substring(0,maxlength);
		CharsLeft=0;
	}
	else
	{
		CharsLeft=maxlength-StrLen;
	}
   document.register.counter.value=CharsLeft;
}

function clearSelect(targetSel) {
	for (var i=targetSel.length; i>=0; i--) {
		targetSel.options[i] = null;
	}
}
