// Load functions
onLoadList = new Array();

// Example: addOnLoad('someFunction');
function addOnLoad(func){
	onLoadList[onLoadList.length] = func;
}

function runOnLoad(){
	for(i in onLoadList){
		var addPar = "";
		// alert(onLoadList[i])
		if (onLoadList[i].indexOf("(") == -1) addPar = "()";
		eval(onLoadList[i]+addPar);
	}
}

// Init
addOnLoad('clearSearch');
addOnLoad('clearSubscription');
addOnLoad('parseLinks');
addOnLoad('fixOpera');
window.onload = runOnLoad;

if (!document.getElementById){
	document.getElementById = function(){return null;}
}

function getObj(obj){
	var obj;
	for(i=0;i<obj.parentNode.childNodes.length;i++){
		if(obj.parentNode.childNodes[i].className=='skip'){
			obj = obj.parentNode.childNodes[i];
			break;
		}
	}
	return obj;
}
document.onmousedown=function(evt){
	evt = (evt) ? evt: ((event) ? event : null);
	if(evt){
		var elem =	(evt.target)? evt.target :
					((evt.srcElement) ? evt.srcElement : null);
		if (elem){
			if(elem.className=='toggleIt'){
				if(getObj(elem).style.display=='block'){
					getObj(elem).style.display='none';
				}else{
					getObj(elem).style.display='block';
					
				}
			}
			//NN6
			if(elem.parentNode.className=='toggleIt'){
				if(getObj(elem.parentNode).style.display=='block'){
					getObj(elem.parentNode).style.display='none';
				}else{
					getObj(elem.parentNode).style.display='block';
					
				}
			}
		}
	}
}
function parseLinks() {
	// make sure the browser supports the object
	if (document.getElementsByTagName) {
		// get the links
		var a = document.getElementsByTagName('a');
		
		// loop through each link (negatively for increased performance)
		for (var i=a.length;i!=0;i--) {
		
			// make alias variable to ease fingers
			var c = a[i-1];
			
			// make sure URL has a href
			if (!c.href) continue;
			
			// convert www links to externals, docs, pdfs
								
			if((c.target.indexOf('_blank') != -1 || c.href.indexOf('.txt') != -1) && !isImgLink(c))c.className='external';
			if(c.href.indexOf('.doc') != -1 && !isImgLink(c))c.className='externalDoc';
			if(c.href.indexOf('.pdf') != -1 && !isImgLink(c))c.className='externalPdf';
	
			if (c.className.indexOf('external') == -1) continue;
			
			// the handler that handles clicking
			c.onclick = function() {
			
				// open the window
				// var win = window.open(this.href,'','width=530,height=450,scrollbars=1,toolbar=1,status=1,resizable=1');
				var win = window.open(this.href);
				// if the window doesn't open, continue normally
				if (win) return false;
			}
		}
	}
}


//But not if imgLink
function isImgLink(obj){
	var imgLink = false;
	if(obj.childNodes.length > 0){
		for(i=0;i < obj.childNodes.length;i++){
			if(obj.childNodes[i].nodeName=='IMG'){
				imgLink=true;
				break;
			}
		}	
	}
	return imgLink;
}


//checks input field for valid e-mail, new toplvl's allowed (ie. info). alert message set by <input type="hidden" name="strTxt"> for language versioning
function validateEmail(strValue,strTxt) {
	var objRegExp  = /^[a-z0-9]([a-z0-9_\-\.]*)@([a-z0-9_\-\.]*)(\.[a-z]{2,4}(\.[a-z]{2}){0,2})$/i;
  	if(objRegExp.test(strValue)){return true;}
  	else{alert(strTxt);return false;}
}

function clearSearch(){
	var searchField = (document.getElementById('searchButton'))?document.getElementById('searchButton'):null;
	if(searchField){
		searchField.onfocus = function(){
			if(searchField.value=='Search'){
				searchField.value = '';
			}
		}
	}
}

function clearSubscription(){
	var wName = (document.getElementById('idName'))?document.getElementById('idName'):null;
	var wAddress = (document.getElementById('idAddress'))?document.getElementById('idAddress'):null;
	var wZip = (document.getElementById('idZip'))?document.getElementById('idZip'):null;
	var wCountry = (document.getElementById('idCountry'))?document.getElementById('idCountry'):null;
	if(wName){
		wName.onfocus = function(){
			if(wName.value!=''){
				wName.value = '';
			}
		}
	}
	if(wAddress){
		wAddress.onfocus = function(){
			if(wAddress.value!=''){
				wAddress.value = '';
			}
		}
	}	
	if(wZip){
		wZip.onfocus = function(){
			if(wZip.value!=''){
				wZip.value = '';
			}
		}
	}		
	if(wCountry){
		wCountry.onfocus = function(){
			if(wCountry.value!=''){
				wCountry.value = '';
			}
		}
	}		
}
function fixOpera(){
	if(navigator.userAgent.indexOf('Opera') != -1){
		document.getElementById('serviceNav').style.width = '300';
		document.getElementById('langNav').style.width = '250';
		document.getElementById('searchForm').style.width = '200';
	}
}
/*
function hideThemeIfSubNav(){
	var subNav = (document.getElementById('subNav'))?document.getElementById('subNav'):null;
	var themePic = (document.getElementById('themePic'))?document.getElementById('themePic'):null;
	
	if(subNav.getElementsByTagName('UL').length > 0 && themePic){
		themePic.style.display = 'none';
	}

}
*/