﻿
var submenues = new Array;

/*******************************************
*               Navigation                 *
********************************************/
var builtSubmenues = function(a)
{
	for (var i = 0; i < a; i++)
	{
		submenues[submenues.length] = $("sub" + i);
	}
}
var switchMenue = function(m)
{
	
	for (var i=0; i< submenues.length; i++)
	{
		submenues[i].style.display = "none";
	}
	if (m != 100)
	{
		submenues[m].style.display = "block";
	}
}

var setActLink = function(m,s)
{
	var menue = $("link" + m);
	var subm = $("sublink"+ s);
	var sMenue;
	var proof = document.getElementsByTagName("a");
	for (var i = 0; i < proof.length; i++)
	{
		if (Element.hasClassName(proof[i], 'act2'))
		{
			Element.removeClassName(proof[i], 'act2');
		}
	}
	
	if (m != "100")
	{
		Element.addClassName(menue, "actNav");
	}
	if (s != "100")
	{
		Element.addClassName(subm, "actSubnav");
		sMenue = s.charAt(0);
		switchMenue(sMenue);
	}
}

/*******************************************
*                  Search                  *
********************************************/
var startSearch = function(cat,lang)
{
	var strSearch = escape($("txtSearch").value);
	var query = "zoom_query=" + strSearch + "&zoom_per_page=10&zoom_cat=" + cat + "&zoom_and=1";
	var msg = (lang=1) ? "Search request is missing!" : "Es fehlt die Suchanfrage!";
	if (strSearch != "") 
	{
		location.href = "/search.asp?" + query;
	}
	else
	{
		alert(msg);
	}
}

/**********************************************
*                    POP UP                   *
***********************************************/

var openPop = function(theURL,winName,w,h)
{
	var features = "menubar=yes,scrollbars=yes,resizable=yes,width=" + w +",height=" + h;
	window.open(theURL,winName,features);
}

/**********************************************
*              HTTP Request                   *
***********************************************/

var ajaxRequest = function(u,f,m,b,h,s) {
    this.url      = u;
    this.wState   = f || function() { };
    this.method   = m || "GET";
    this.body     = b || null;
    this.headers  = h || false;
    this.sync     = s || true;
    this.abortReq = false;
    
    this.req = (window.XMLHttpRequest) 
           ?
           new XMLHttpRequest()
           :
           ((window.ActiveXObject)
           ?
           new ActiveXObject("Microsoft.XMLHTTP")
           :
           false
           );
    
    this.doRequest = function()     {
        this.req.open(this.method,this.url,this.sync);
        if (this.headers) {
            for (var i=0; i<this.headers.length; i+=2) {
                this.req.setRequestHeader(
                    this.headers[i],this.headers[i+1]
                );
            }
        }
        this.req.onreadystatechange = this.wState;
        (!this.abortReq) ? this.req.send(this.body) : this.req.abort();
    }
}

/**********************************************
*                   NEWS                      *
***********************************************/

var loadNews = function(out, reg, lang)
{
	var out = $(out);
	var query = "region=" + reg + "&Lng=" + lang;
	//alert(query);
	var xmlhttp = new ajaxRequest(
		"/loadNews.aspx",
		function() 
		{
			var r = xmlhttp.req;
			if ((r.readyState==4) && (r.status == 200)) 
			{
				if (parseInt(r.responseText) != 0)
				{
					out.innerHTML = r.responseText;
				}
				else
				{
					$("news").style.display = "none";
				}
			}
		},
		"POST",
		query,
		["Content-Type","application/x-www-form-urlencoded"]
	);
	xmlhttp.doRequest();
}

/**********************************************
*                   JOBS                      *
***********************************************/
var loadJobs = function(mode, out)
{
	var out = $(out);
	var query = "mode=" + mode; // 1 = count, 2 = preselect
	//alert(query);
	var xmlhttp = new ajaxRequest(
		"loadJobs.aspx",
		function() 
		{
			var r = xmlhttp.req;
			if ((r.readyState==4) && (r.status == 200)) 
			{
			
				out.innerHTML = r.responseText;
			}
		},
		"POST",
		query,
		["Content-Type","application/x-www-form-urlencoded"]
	);
	xmlhttp.doRequest();
}