//////////////////////////////////////////////////////////
// www.atlas-mts.com
// - new methods shall be added object literal style -
//////////////////////////////////////////////////////////

// dropdown menu animation for top,submenu
topMenu = {
	// variablen definieren
	/*elem1:false,
	elem2:false,
	elem3:false,
	elem4:false,
	elem5:false,
	elem6:false,
	timeout:false,*/
  
	hide:function(){
		if(!topMenu.isTextNode(topMenu.elem1)) {
			topMenu.elem1.style.display="none";
		}
		if(!topMenu.isTextNode(topMenu.elem2)) {
			topMenu.elem2.style.display="none";
		}
		if(!topMenu.isTextNode(topMenu.elem3)) {
			topMenu.elem3.style.display="none";
		}
		if(!topMenu.isTextNode(topMenu.elem4)) {
			topMenu.elem4.style.display="none";
		}
		if(!topMenu.isTextNode(topMenu.elem5)) {
			topMenu.elem5.style.display="none";
		}
		if(!topMenu.isTextNode(topMenu.elem6)) {
			topMenu.elem6.style.display="none";
		}

		var hide_element = document.getElementById('hide');
		if(hide_element) {
			hide_element.style.visibility='visible';
		}
	},

	isTextNode:function(element) {
		if(element.nodeType==3) {
			return true;
		} else {
			return false;
		}
	},

	init:function(){
		var timer=2000;

		function activateMenu(){
			var list1=document.getElementById('nav_products');
			var list2=document.getElementById('nav_education');
			var list3=document.getElementById('nav_contact');
			var list4=document.getElementById('nav_about');
			var list5=document.getElementById('nav_news');
			var list6=document.getElementById('nav_services');

			topMenu.elem1=list1.nextSibling;
			//elem1=elem1.nextSibling;

			topMenu.elem2=list2.nextSibling;
			//elem2=elem2.nextSibling;

			topMenu.elem3=list3.nextSibling;
			//elem3=elem3.nextSibling;

			topMenu.elem4=list4.nextSibling;
			//elem4=elem4.nextSibling;

			topMenu.elem5=list5.nextSibling;
			//elem5=elem5.nextSibling;

			topMenu.elem6=list6.nextSibling;
			//elem6=elem6.nextSibling;

			list1.onmouseover=function(){
				topMenu.hide();
				window.clearTimeout(topMenu.timeout);
				if(!topMenu.isTextNode(topMenu.elem1)) {
					topMenu.elem1.style.display="block";
				}
			}
			list1.onmouseout=function(){
				topMenu.timeout = window.setTimeout("topMenu.hide()",timer);
			}
			setSubNavigation(topMenu.elem1);

			list2.onmouseover=function(){
				topMenu.hide();
				window.clearTimeout(topMenu.timeout);
				if(!topMenu.isTextNode(topMenu.elem2)) {
					topMenu.elem2.style.display="block";
				}
			}
			list2.onmouseout=function(){
				topMenu.timeout = window.setTimeout("topMenu.hide()",timer);
			}
			setSubNavigation(topMenu.elem2);

			list3.onmouseover=function(){
				topMenu.hide();
				window.clearTimeout(topMenu.timeout);
				if(!topMenu.isTextNode(topMenu.elem3)) {
					topMenu.elem3.style.display="block";
				}
			}
			list3.onmouseout=function(){
				topMenu.timeout = window.setTimeout("topMenu.hide()",timer);
			}
			setSubNavigation(topMenu.elem3);

			list4.onmouseover=function(){
				topMenu.hide();
				window.clearTimeout(topMenu.timeout);
				if(!topMenu.isTextNode(topMenu.elem4)) {
					topMenu.elem4.style.display="block";
				}
				var hide_element = document.getElementById('hide');
				if(hide_element) {
					hide_element.style.visibility='hidden';
				}
			}
			list4.onmouseout=function(){
				topMenu.timeout = window.setTimeout("topMenu.hide()",timer);
			}
			setSubNavigation(topMenu.elem4);

			list5.onmouseover=function(){
				topMenu.hide();
				window.clearTimeout(topMenu.timeout);
				if(!topMenu.isTextNode(topMenu.elem5)) {
					topMenu.elem5.style.display="block";
				}
			}
			list5.onmouseout=function(){
				topMenu.timeout = window.setTimeout("topMenu.hide()",timer);
			}
			setSubNavigation(topMenu.elem5);

			list6.onmouseover=function(){
				topMenu.hide();
				window.clearTimeout(topMenu.timeout);
				if(!topMenu.isTextNode(topMenu.elem6)) {
					topMenu.elem6.style.display="block";
				}
			}
			list6.onmouseout=function(){
				topMenu.timeout = window.setTimeout("topMenu.hide()",timer);
			}
			setSubNavigation(topMenu.elem6);
		}

		function setSubNavigation(element) {
			var i,child_element,link_element;
			var number_of_childs = element.childNodes.length;
			for(i=0;i<number_of_childs;++i) {
				child_element = element.childNodes[i];
				if(child_element.nodeName == 'LI') {
					link_element = child_element.firstChild;

					link_element.onmouseover=function(){
						window.clearTimeout(topMenu.timeout);
					}
					link_element.onmouseout=function(){
						topMenu.timeout = window.setTimeout("topMenu.hide()",timer);
					}

				}
			}

		}

		function isTextNode(element) {
			if(element.nodeType==3) {
				return true;
			} else {
				return false;
			}
		}
		activateMenu();
	}
}

// ajax database extract for local representitives
represent={

	// variablen
	request:false,

	init:function(lang){
		represent.request = represent.makeObject();
		represent.info(lang);
		represent.clearScr();
		page.scrollTo("form");
	},

	makeObject:function(){
		var x;
		var browser = navigator.appName;
		if(browser == "Microsoft Internet Explorer"){
			x = new ActiveXObject("Microsoft.XMLHTTP");
		} else {
			x = new XMLHttpRequest();
		}
		return x;
	},
	clearScr:function(){
		document.getElementById('continental').innerHTML="";
	},
	info:function(lang){
		var ajax_search = document.getElementById('repres');
		//represent.request.open('get', '/cgi/repres.cgi?action=get&item='+ ajax_search.value);
		represent.request.open('get', '/cgi/repres.cgi?action=get&lang='+lang+'&item='+ajax_search.options[ajax_search.selectedIndex].text);
		represent.request.onreadystatechange = represent.parseInfo;
		represent.request.send('');
	},

	parseInfo:function(){
		if(represent.request.readyState == 1){
			document.getElementById('statusbox').innerHTML = "searching...";
		}
		if(represent.request.readyState == 4){
			document.getElementById('statusbox').innerHTML = represent.request.responseText;
		}
	}

}

// url selector for left navigation at the start page
FormListener={
	init:function(){
		var select1=document.getElementById("nav_input1");
		var select2=document.getElementById("nav_input2");
		var select3=document.getElementById("nav_input3");

		if(select1) {
			select1.onchange=function() {
				if(select1.selectedIndex!=0) {
					top.location.href=select1.options[select1.selectedIndex].value;
				}
			}
		}

		if(select2) {
			select2.onchange=function() {
				if(select2.selectedIndex!=0) {
					top.location.href=select2.options[select2.selectedIndex].value;
				}
			}
		}

		if(select3) {
			select3.onchange=function() {
				if(select3.selectedIndex!=0) {
					top.location.href=select3.options[select3.selectedIndex].value;
				}
			}
		}
	}
}

InfoRequest={

	init:function() {
		InfoRequest.product_info = document.getElementById('product_infos');
		InfoRequest.further_information = document.getElementById('further_information');
		//InfoRequest.refresh_all();
	},

	refresh_all:function() {
		InfoRequest.refresh('product_info');
		InfoRequest.refresh('further_information');
	},

	hide:function(element) {
		if(element) {
			//element.style.display = 'none';
		}
	},

	refresh:function(id) {
		switch(id) {
			case 'product_info':	var check_element = document.getElementById('f_getmail');
									//var display = check_element && check_element.checked ? 'block' : 'none';
									InfoRequest.refresh_element(InfoRequest.product_info,display);
									break;
			case 'further_information':	var check_element = document.getElementById('f_furtherinformation');
										var display = check_element && check_element.checked ? 'block' : 'none';
										InfoRequest.refresh_element(InfoRequest.further_information,display);
										break;
		}
	},

	refresh2:function(id) {
		switch(id) {
			case 'product_info':	var check_element = $(".f_getmail");
									var display = check_element && $(".f_getmail").attr("checked") ? 'block' : 'none';
									InfoRequest.refresh_element(InfoRequest.product_info,display);
									break;
			case 'further_information':	var check_element = $(".f_furtherinformation");
										var display = check_element && $(".f_furtherinformation").attr("checked") ? 'block' : 'none';
										InfoRequest.refresh_element(InfoRequest.further_information,display);
										break;
		}
	},

	refresh_element:function(element,display) {
		if(element) {
			//var display = element.style.display == 'none' ? 'block' : 'none';
			element.style.display = display;
		}
	},

	get_country:function() {
		var value = '';
		var result = document.URL.match(/(\?|&)f_country=([^&?]*)/);
		if(result) {
			value = result[2].replace(/%20/g,' ');
		}
		return value;
	},

	select_country:function(selectbox) {
		var country = InfoRequest.get_country();

		for(i=0;i<selectbox.length; ++i) {
			if(selectbox[i].text==country.toUpperCase()) {
				selectbox.selectedIndex = i;
			}
		}
	}
}

worldMap={
	init:function(){
		var map=document.getElementById('world_list');
		if(map){
			worldMap.reset();
			worldMap.preloadImg();
		}
	},
	trigger:function(p_node){
		/*worldMap.reset();
		document.getElementById('l'+p_node).style.display='block';
		document.getElementById('l'+p_node).style.position='absolute';
		document.getElementById('l'+p_node).style.left=xpos+"px";
		document.getElementById('l'+p_node).style.top=ypos+"px";*/
		switch(p_node){
			case 1:
				document.getElementById('image_world').src="/images/local_representatives/samerica.jpg";
				break;
			case 2:
				document.getElementById('image_world').src="/images/local_representatives/australia.jpg";
				break;
			case 3:
				document.getElementById('image_world').src="/images/local_representatives/namerica.jpg";
				break;
			case 4:
				document.getElementById('image_world').src="/images/local_representatives/africa.jpg";
				break;
			case 5:
				document.getElementById('image_world').src="/images/local_representatives/europe.jpg";
				break;
			case 6:
				document.getElementById('image_world').src="/images/local_representatives/asia.jpg";
				break;
			default:
				document.getElementById('image_world').src="/images/globe.jpg";
		}
	},
	untrigger:function(p_node){
		//document.getElementById('l'+p_node).style.display='none';
		document.getElementById('image_world').src="/images/globe.jpg";
	},
	reset:function(){
		document.getElementById('l1').style.display='none';
		document.getElementById('l2').style.display='none';
		document.getElementById('l3').style.display='none';
		document.getElementById('l4').style.display='none';
		document.getElementById('l5').style.display='none';
		document.getElementById('l6').style.display='none';
	},
	preloadImg:function(img_name){
		document.preload = new Array();
		document.preload[0] = new Image();
		document.preload[0].src = "/images/local_representatives/namerica.jpg";
		document.preload[1] = new Image();
		document.preload[1].src = "/images/local_representatives/samerica.jpg";
		document.preload[2] = new Image();
		document.preload[2].src = "/images/local_representatives/europe.jpg";
		document.preload[3] = new Image();
		document.preload[3].src = "/images/local_representatives/africa.jpg";
		document.preload[4] = new Image();
		document.preload[4].src = "/images/local_representatives/asia.jpg";
		document.preload[5] = new Image();
		document.preload[5].src = "/images/local_representatives/australia.jpg";
	},
	conInfo:function(p_con, lang){
		document.getElementById('statusbox').innerHTML="";
		region.init(p_con, lang);
		page.scrollTo("form");
	},
	repInfo:function(p_rep){
		rep.init(p_rep);
		page.scrollTo("form");
	},
	repContact:function(obj){
		obj.childNodes[1].style.display='inline';
		obj.childNodes[1].focus();
	}
}

// ajax database extract for local representitives (II)
region={

	// variablen
	request:false,

	init:function(p_region, lang){
		region.request = region.makeObject();
		switch(p_region){
			case 1:
				p_region=2;
			break;
			case 2:
				p_region=6;
			break;
			case 3:
				p_region=1;
			break;
			case 4:
				p_region=3;
			break;
			case 5:
				p_region=4;
			break;
			case 6:
				p_region=5;
			break;
		}
		region.info(p_region, lang);
	},

	makeObject:function(){
		var x;
		var browser = navigator.appName;
		if(browser == "Microsoft Internet Explorer"){
			x = new ActiveXObject("Microsoft.XMLHTTP");
		} else {
			x = new XMLHttpRequest();
		}
		return x;
	},

	info:function(p_region, lang){
		var ajax_search = p_region;
		region.request.open('get', '/cgi/repres.cgi?action=con&lang='+ lang + '&item='+ ajax_search);
		region.request.onreadystatechange = region.parseInfo;
		region.request.send('');
	},

	parseInfo:function(){
		if(region.request.readyState == 1){
			document.getElementById('continental').focus();
			document.getElementById('continental').innerHTML = "searching...";
		}
		if(region.request.readyState == 4){
			document.getElementById('continental').innerHTML = region.request.responseText;
		}
	}

}

// ajax database extract for local representitives (II)
rep={

	// variablen
	request:false,

	init:function(p_rep){
		rep.request = rep.makeObject();
		rep.info(p_rep);
	},

	makeObject:function(){
		var x;
		var browser = navigator.appName;
		if(browser == "Microsoft Internet Explorer"){
			x = new ActiveXObject("Microsoft.XMLHTTP");
		} else {
			x = new XMLHttpRequest();
		}
		return x;
	},

	info:function(p_rep){
		var ajax_search = p_rep;
		rep.request.open('get', '/cgi/repres.cgi?action=rep&item='+ ajax_search);
		rep.request.onreadystatechange = rep.parseInfo;
		rep.request.send('');
	},

	parseInfo:function(){
		if(rep.request.readyState == 1){
			document.getElementById('continental').focus();
			document.getElementById('continental').innerHTML = "searching...";
		}
		if(rep.request.readyState == 4){
			document.getElementById('continental').innerHTML = rep.request.responseText;
		}
	}

}

		xpos=0;
		ypos=0;
		if(document.layers) {
			window.captureEvents(Event.MOUSEMOVE);
			window.onmousemove=koordinaten;
		}
		else {
			document.onmousemove=koordinaten;
		}
		function koordinaten(e) {
			if(document.body) {
				xpos = (document.layers || (document.getElementById && !document.all)) ? e.pageX : document.body.scrollLeft + event.clientX;
				ypos = (document.layers || (document.getElementById && !document.all)) ? e.pageY : document.body.scrollTop + event.clientY;
			}
		}


/* check form */
formValidator={
	checkForm:function(formname, werte, country, state, address) {
		var intern = werte;
		if(!werte) intern = new Array();
		var fields = new Array();
		var check = 0;
		var regex=/^[\w,_,\-,.]*$/;
		for (var i=0; i<intern.length; i++) {
			if(document[formname][intern[i]]) {
				fields[i] = document[formname][intern[i]].value;
			}
		}

		for (var i=0; i<fields.length; i++) {
			switch (fields[i]) {
			case "":
				alert('You must fill out all fields marked with a star!');
				return false;
			case "Bitte wählen:":
				alert('You must fill out all fields marked with a star!');
				return false;
			default: check++;
			}
		}

		if (document.info_request_form) {
			var search = document.info_request_form.f_country;
			var country = search.options[search.selectedIndex].text;

			if ( (country == 'USA' || country == 'CANADA') && ( (document.info_request_form.f_state.value == "") || (document.info_request_form.f_address1.value == "") || (document.info_request_form.f_zip.value == "") || (document.info_request_form.f_city.value == "") ) ) {
				alert('You must fill out all fields marked with a star!');
				return false;
			}
		}

		if (check == intern.length) {
			return true;
		} else {
			return false;
		}
	}
}

page={
	// scrollTo
	// @param elem a@name
	scrollTo:function(elem){
		location.href="#"+elem;
	}
}


// event loader
window.onload= function(){
	topMenu.init();
	FormListener.init();
	worldMap.init();
}

randomBanner = {
	available_images : new Array(),

	init:function(lang) {
		randomBanner.available_images[0] = new Array();

		randomBanner.available_images[0]['link'] = '/';

		randomBanner.available_images[1] = new Array();
		randomBanner.available_images[1]['link'] = 'http://www.atlas-mts.com/en/services/natural_weathering_testing/natural_weathering_testing_sites/arizona/outdoor_accelerated_weathering/';

		randomBanner.available_images[2] = new Array();
		randomBanner.available_images[2]['link'] = '/shop/category?ID=001';

		randomBanner.available_images[3] = new Array();
		randomBanner.available_images[3]['link'] = '/shop/category?ID=001003';

		randomBanner.available_images[4] = new Array();
		randomBanner.available_images[4]['link'] = 'http://www.atlas-mts.com/en/services/natural_weathering_testing/';

		randomBanner.available_images[5] = new Array();
		randomBanner.available_images[5]['link'] = 'http://www.atlas-mts.com/en/global_news/atlas_news/what_is_a_complete_weathering_program_50441.shtml';

		randomBanner.available_images[6] = new Array();
		randomBanner.available_images[6]['link'] = 'http://www.solardurability.com/';

		switch (lang) {
			case "de":
						randomBanner.available_images[0]['path'] = '/images/banner_home/1_de.jpg';
						randomBanner.available_images[1]['path'] = '/images/banner_home/2_de.jpg';
						randomBanner.available_images[2]['path'] = '/images/banner_home/3_de.jpg';
						randomBanner.available_images[3]['path'] = '/images/banner_home/4_de.jpg';
						randomBanner.available_images[4]['path'] = '/images/banner_home/5_de.jpg';
						randomBanner.available_images[5]['path'] = '/images/banner_home/6_de.jpg';
						randomBanner.available_images[6]['path'] = '/images/banner_home/7_de.jpg';
						randomBanner.available_images[6]['link'] = 'http://www.solardurability.com/de/startseite/index.shtml';
						break;
			case "es":
						randomBanner.available_images[0]['path'] = '/images/banner_home/1_es.jpg';
						randomBanner.available_images[1]['path'] = '/images/banner_home/2_es.jpg';
						randomBanner.available_images[2]['path'] = '/images/banner_home/3_es.jpg';
						randomBanner.available_images[3]['path'] = '/images/banner_home/4_es.jpg';
						randomBanner.available_images[4]['path'] = '/images/banner_home/5_es.jpg';
						randomBanner.available_images[5]['path'] = '/images/banner_home/6_es.jpg';
						randomBanner.available_images[6]['path'] = '/images/banner_home/7_es.jpg';
						break;
			case "fr":
						randomBanner.available_images[0]['path'] = '/images/banner_home/1_fr.jpg';
						randomBanner.available_images[1]['path'] = '/images/banner_home/2_fr.jpg';
						randomBanner.available_images[2]['path'] = '/images/banner_home/3_fr.jpg';
						randomBanner.available_images[3]['path'] = '/images/banner_home/4_fr.jpg';
						randomBanner.available_images[4]['path'] = '/images/banner_home/5_fr.jpg';
						randomBanner.available_images[5]['path'] = '/images/banner_home/6_fr.jpg';
						randomBanner.available_images[6]['path'] = '/images/banner_home/7_fr.jpg';
						break;
			default :
						randomBanner.available_images[0]['path'] = '/images/banner_home/1.jpg';
						randomBanner.available_images[1]['path'] = '/images/banner_home/2.jpg';
						randomBanner.available_images[2]['path'] = '/images/banner_home/3.jpg';
						randomBanner.available_images[3]['path'] = '/images/banner_home/4.jpg';
						randomBanner.available_images[4]['path'] = '/images/banner_home/5.jpg';
						randomBanner.available_images[5]['path'] = '/images/banner_home/6.jpg';
						randomBanner.available_images[6]['path'] = '/images/banner_home/7.jpg';
		}

		randomBanner.displayBanner();
		// Andere Funktionen noch aufrufen
		topMenu.init();
		FormListener.init();
		worldMap.init();
	},

	displayBanner:function() {
		var random = Math.floor(Math.random() * randomBanner.available_images.length);
		// 2008-07-21: Banner #6 immer aktiv, da Atlas mehr Anmeldung fuer diese Kampagne benoetigt
		//random = 6;
		document.getElementById('banner_display').style.backgroundImage = 'url(' + randomBanner.available_images[random]['path'] + ')';
		document.getElementById('banner_link').href = randomBanner.available_images[random]['link'];
		window.setTimeout("randomBanner.displayBanner()", 10000);
	}
}

i_dont_like_bots = {
	get_email:function(element,postfix,prefix) {
		element.href = 'mailto:'+prefix+'@'+postfix;
	}
}
openWin = {
	xenosoft:function(path,w,h,title) {
		popup = window.open(path,title,"width="+w+",height="+h+",scrollbars=yes,resizable=yes,statusbar");
	}
}

// functions to show/hide required fields in forms
function showStar() {
	if (document.info_request_form) {
		var search = document.info_request_form.f_country;
		var country = search.options[search.selectedIndex].text;
		document.getElementById('star1').style.display = (country == 'USA' || country == 'CANADA') ? "inline" : "none";
		document.getElementById('star2').style.display = (country == 'USA' || country == 'CANADA') ? "inline" : "none";
		document.getElementById('star3').style.display = (country == 'USA' || country == 'CANADA') ? "inline" : "none";
		document.getElementById('star4').style.display = (country == 'USA' || country == 'CANADA') ? "inline" : "none";
	}
}

function setStars() {
	showStar();
	window.setTimeout("setStars()", 1000);
}

function getCountry () {
	var search = document.newsletter_feedback.f_country;
	var country = search.options[search.selectedIndex].text;
	document.getElementById('country').value = country;
}
function getCountry1 () {
	var search = document.info_request_form.f_country;
	var country = search.options[search.selectedIndex].text;
	document.getElementById('country').value = country;
}

// function for captcha
var requestcounter = 0;
var refresh_captcha = 1;
var request;

function loadXMLDoc(req, url) {
	var loadfunc = function() {
		if (req[requestcounter].readyState == 4) {
			if (req[requestcounter].status == 200) {
				document.getElementById("captcha_container").innerHTML = '';
				document.getElementById("captcha_container").innerHTML = req[requestcounter].responseText;
				requestcounter++;
			}
		}
	};

	if (window.XMLHttpRequest) {
		req[requestcounter] = new XMLHttpRequest();
		req[requestcounter].onreadystatechange = loadfunc;
		req[requestcounter].open("GET", url, true);
		req[requestcounter].send(null);
		// branch for IE/Windows ActiveX version
	} else {
		req[requestcounter] = new ActiveXObject("Microsoft.XMLHTTP");
		if (req[requestcounter]) {
			req[requestcounter].onreadystatechange = loadfunc;
			req[requestcounter].open("GET", url, true);
			req[requestcounter].send();
		}
	}
}

function viewCaptcha() {
	// Nur ausfuehren, wenn das refresh_captcha Flag auf 1 steht
	if (refresh_captcha) {
		request = new Array();
		loadXMLDoc(request, '/cgi/captcha.cgi?action=view&test='+requestcounter);
		// Flag zuruecksetzen
		refresh_captcha = 0;
	}
}

// E-Mail-Schutzfunktion
function openmailurl(prefix, postfix) {
	if(!postfix) { postfix = 'atlas-mts.com'; }
	location.href= 'mailto:' + prefix + '@' + postfix;
}