var fieldstocheck = new Array();
var fieldnames = new Array();


function showGlossarContent(word, el) {
	if (document.getElementById("activeElement")){
		document.getElementById("activeElement").style.color = "#666666";
		document.getElementById("activeElement").style.cursor = "pointer";
		document.getElementById("activeElement").style.textDecoration = "none";
		document.getElementById("activeElement").removeAttribute("id");
	}
	el.id = "activeElement";
	el.style.cursor = "pointer";
	url = "/ajaxresult?id="+word;
	
	new Ajax(url, {method: 'get', update: $('glossarContent')}).request();
}


function markGlossarContent(el) {
	el.style.color = "#bc002f";
	el.style.cursor = "pointer";
	el.style.textDecoration = "underline";
}

function unmark(el) {
	if(el.id != "activeElement"){
		el.style.color = "#666666";
		el.style.cursor = "pointer";
		el.style.textDecoration = "none";
	} else{
		el.style.textDecoration = "none";
	}
}
/*
function getSubscriptionIface(){
	url = "/phplist/lists/?p=subscribe&id=4";
	new Ajax(url, {method: 'get', update: $('newsletterContent')}).request();
	}
	
function getUnSubscriptionIface(){
	url = "/lists/?p=unsubscribe&id=4";
	new Ajax(url, {method: 'get', update: $('newsletterContent')}).request();
	addFieldToCheck("email","E-Mail");
	addFieldToCheck("emailconfirm","Confirm email");
	addFieldToCheck("attribute1","Name");
	addFieldToCheck("attribute14","Vorname");
	addFieldToCheck("attribute16","PLZ");
	addFieldToCheck("attribute17","Ort");
	}
*/

function showNumber(){
	url = "/ajaxresult";
	if (window.location.pathname == '/telephone_book_en.html')
			url = "/ajaxresult_en";		
	new Ajax(url, {method: 'post', postBody: $('telSearchForm'), update: $('directories')}).request();
	}

function getTel(title){
	url = "/ajaxresult";
	if (window.location.pathname == '/telephone_book_en.html')
			url = "/ajaxresult_en";	
	new Ajax(url, {method: 'post', postBody: {telSearch: title}, update: $('directories')}).request();

}

window.onload = function() {			
			if (window.location.pathname == '/' || window.location.pathname == '/home_de.html'){
				pharma = new Array('Home_Pharma_1.jpg', 'Home_Pharma_3.jpg', 'Home_Pharma_4.jpg');
				food = new Array('Home_Food_1.jpg','Home_Food_3.jpg','Home_Food_4.jpg');
				agency = new Array('Home_Agentur_1.jpg', 'Home_Agentur_3.jpg', 'Home_Agentur_4.jpg');
				finance = new Array('Home_Finance_1.jpg','Home_Finance_3.jpg','Home_Finance_4.jpg');
				aemter = new Array('Home_Aemter_1.jpg','Home_Aemter_3.jpg','Home_Aemter_4.jpg');

				var slideParts = new Array(pharma, food, agency, finance, aemter);
				output = new Array();
				myArray = slideParts;			
				for (i=slideParts.length-1;i>= 0; i--){
					rand = Math.round(i*Math.random());
					if (i == slideParts.length-1 && navigator.userAgent.indexOf("AppleWebKit") == "-1"){		
						document.getElementById("banner").firstChild.src = '/assets/images/Banners/'+myArray[rand][0];				
					}		
					if (myArray.length > 1){
					myNewArray = myArray.slice(0, rand);				
					myNewArray = myNewArray.concat(myArray.slice(rand+1, myArray.length));
					output = output.concat(myArray[rand]);				
					}
					else {
						output = output.concat(myArray[0]);
					}					
				myArray = myNewArray;

				}  	
				myShow = new Slideshow('banner', { hu: '/assets/images/Banners/', type: 'fade', duration: [2000, 2000], images: output});

			}
			else if (window.location.pathname == '/home_en.html'){
				pharma = new Array('Home_Pharma_1.jpg', 'Home_Pharma_2.jpg', 'Home_Pharma_3.jpg');
				food = new Array('Home_Food_1.jpg','Home_Food_2.jpg','Home_Food_3.jpg');
				agency = new Array('Home_Agentur_1.jpg', 'Home_Agentur_2.jpg', 'Home_Agentur_3.jpg');
				finance = new Array('Home_Finance_1.jpg','Home_Finance_2.jpg','Home_Finance_3.jpg');
				aemter = new Array('Home_Aemter_1.jpg','Home_Aemter_2.jpg','Home_Aemter_3.jpg');

				var slideParts = new Array(pharma, food, agency, finance, aemter);
				output = new Array();
				myArray = slideParts;			
				for (i=slideParts.length-1;i>= 0; i--){
					rand = Math.round(i*Math.random());
					if (i == slideParts.length-1 && navigator.userAgent.indexOf("AppleWebKit") == "-1"){		
						document.getElementById("banner").firstChild.src = '/assets/images/Banners/en/'+myArray[rand][0];				
					}		
					if (myArray.length > 1){
					myNewArray = myArray.slice(0, rand);				
					myNewArray = myNewArray.concat(myArray.slice(rand+1, myArray.length));
					output = output.concat(myArray[rand]);				
					}
					else {
						output = output.concat(myArray[0]);
					}					
				myArray = myNewArray;

				}  	
				myShow = new Slideshow('banner', { hu: '/assets/images/Banners/en/', type: 'fade', duration: [2000, 2000], images: output});

			}
			else if (window.location.pathname == '/nlajax.html'){
				
				if (window.location.search == ''){
					getSubscriptionIface();
				}
				else if (window.location.search.indexOf("p=unsubscribe") != -1){
					getUnSubscriptionIface();
				}
			}
			else if (window.location.pathname == '/telefonbuch.html' || window.location.pathname == '/telephone_book_en.html'){
				var link = '/ajaxresult';
				if (window.location.pathname == '/telephone_book_en.html')
					var link = '/ajaxresult_en';				
				var el = $('telSearch');
				var searchInput = $('telSearch');
				var indicator = new Element('div').addClass('autocompleterLoading').setHTML('').setStyle('display', 'none').injectInside($('loadContainer'));
				var completer = new Autocompleter.Ajax.Xhtml(searchInput, link, {
					'postData': {html: 1},
					'onRequest': function(el) {
						indicator.setStyle('display', '');
					},
					'onComplete': function(el) {
						indicator.setStyle('display', 'none');
					},
					'parseChoices': function(el) {
						var value = el.innerHTML;
						el.inputValue = value;
						this.addChoiceEvents(el).setHTML(this.markQueryValue(value));
					}
				});
			}
			if (document.getElementById("scooter24x7")){        
				//alert("found");
				$("scooter24x7").addEvent('submit', function(e) {

					return false;

				});
				if (document.getElementById("Recipient")){
					$("Recipient").addEvent('click', function() {
						this.value = '';
					});
				}
			}
}


// PHPList Funcs

function checkform() {
  for (i=0;i<fieldstocheck.length;i++) {
    if (eval("document.subscribeform.elements['"+fieldstocheck[i]+"'].value") == "") {
      alert("Bitte geben Sie ein "+fieldnames[i]);
      eval("document.subscribeform.elements['"+fieldstocheck[i]+"'].focus()");
      return false;
    }
  }

  if(! compareEmail())
  {
    alert("Email Adressen stimmen nicht überein");
    return false;
  }
  new Ajax('/phplist/lists/?p=subscribe&id=4', {method: 'post', postBody: $('subscribeForm'), update: $('newsletterContent')}).request();
  return false;
}

function addFieldToCheck(value,name) {
  fieldstocheck[fieldstocheck.length] = value;
  fieldnames[fieldnames.length] = name;
}

function compareEmail()
{
  return (document.subscribeform.elements["email"].value == document.subscribeform.elements["emailconfirm"].value);
}

function send24x7(){
	new Ajax('/proxy.php' ,{ method: 'get', data: $('scooter24x7').toQueryString(), update: $('response')}).request();
}

function changeMap(id){
document.getElementById("base").style.display = "none";
document.getElementById("mp"+id).style.display = "block";
document.getElementById("csp"+id).style.display = "block";
        }

function restoreMap(id){
document.getElementById("csp"+id).style.display = "none";
document.getElementById("mp"+id).style.display = "none";
document.getElementById("base").style.display = "block";
}

function changeCatMap(num){
document.getElementById("trans"+(2-num)).style.display="none";
document.getElementById("trans"+(2-num+1)).style.display="none";
document.getElementById("trans"+num).style.display="block";
}


function changeImgMap(id){
document.getElementById("trans1").style.display="none";
document.getElementById("trans2").style.display="none";
document.getElementById("trans0").style.display="none";
document.getElementById("nextprev0").style.display="none";
document.getElementById("nextprev1").style.display="none";
document.getElementById("nextprev2").style.display="none";
document.getElementById("teaser0").style.display="none";
document.getElementById("teaser1").style.display="none";
document.getElementById("teaser2").style.display="none";

document.getElementById("trans"+id).style.display="block";
document.getElementById("nextprev"+id).style.display="block";
document.getElementById("teaser"+id).style.display="block";
}
