// script.js



function showEonWorld()
{
	var width = 790;
	var height = 455;
	var left = getLeft(width);
	var top = getTop(height);
	var Url = "http://www.eon-energie.com/world/main_e.html";
	var features = "directories=no,location=no,menubar=no,scrollbars=no,status=no,toolbar=no,resizable=no,width=" + width + ",height=" + height + ",left=" + left +  ",top=" + top;
	NewWin = window.open(Url,"site", features); 	
	NewWin.focus();
}

function setLanguage(lang, home)
{
	document.cookie = "language=" + lang;
	document.location = home;
}

function showPopUp(url, width, height) {
	var left = getLeft(width);
	var top = getTop(height);
	var features = "directories=no,location=no,menubar=no,scrollbars=no,status=no,toolbar=no,resizable=no,width=" + width + ",height=" + height + ",left=" + left +  ",top=" + top;
	NewWin = window.open(url,"popup", features); 	
	NewWin.focus();
}

function changeCat(obj) 
{	
	var cat = obj.options[obj.selectedIndex].value
	document.cookie = "FAQCat=" + cat;
	var loc = document.location;
	document.location = loc;
}

function showFAQItem(url) {
	var obj = document.getElementById('answerframe')
	if (obj != null) {
		obj.src = url;
	}
}

function sitemapClick(url) {
	var main = window.opener;
	if (main != null) {
		main.location = url;
		window.close();
	}
}

function getLeft(width) {
	var scrwidth = screen.width;
	return (scrwidth/2) - (width/2); 
}

function getTop(height) {
	var scrheight = screen.height;
	return (scrheight/2) - (height/2); 
}

function contactSubmit() {
	var f = document.contactForm;
	if (f != null) {
		if (validateContactForm(f)) {
			f.submit();
		}
	}
}

function validateContactForm(f) {
	if ((f.Name.value == null) || (f.Name.value == "")) {
		alert(f.ErrorMessage.value);
		return false;
	}
	if ((f.Email.value == null) || (f.Email.value == "")) {
		alert(f.ErrorMessage.value);
		return false;
	}
	else {
		//alert(mail.value);
		if (!emailCheck(f.Email.value)) {
			alert(f.ErrorEmail.value);
			return false;
		}
	}
	if ((f.Comment.value == null) || (f.Comment.value == "")) {
		alert(f.ErrorMessage.value);
		return false;
	}	
	return true;
}

function docRequestSubmit() {
	var f = document.docRequestForm;
	if (f != null) {
		if (validateDocRequestForm(f)) {
			f.submit();
		}
	}
}

function validateDocRequestForm(f) {
	if ((f.Name.value == null) || (f.Name.value == "")) {
		alert(f.ErrorMessage.value);
		return false;
	}
	if ((f.Email.value == null) || (f.Email.value == "")) {
		alert(f.ErrorMessage.value);
		return false;
	}
	else {
		//alert(mail.value);
		if (!emailCheck(f.Email.value)) {
			alert(f.ErrorEmail.value);
			return false;
		}
	}
	if ((f.Address.value == null) || (f.Address.value == "")) {
		alert(f.ErrorMessage.value);
		return false;
	}
	if ((f.PostCode.value == null) || (f.PostCode.value == "")) {
		alert(f.ErrorMessage.value);
		return false;
	}
	if ((f.City.value == null) || (f.City.value == "")) {
		alert(f.ErrorMessage.value);
		return false;
	}
	return true;
}

function emailCheck(src) {
	var emailReg = "^[\\w-_\.]*[\\w-_\.]\@[\\w]\.+[\\w]+[\\w]$";
	var regex = new RegExp(emailReg);
	return regex.test(src);
}

function tglHi(obj) {
	obj.firstChild.src = obj.firstChild.src.replace(/_dark.gif/gi,".gif");	
}

function tglLo(obj) {
	obj.firstChild.src = obj.firstChild.src.replace(/.gif/gi,"_dark.gif");	
}
