function initCommon(){
	//*** Init.
}

function preloadImages() {
	var d = document;
	if (d.images) {
		if (!d.preloadArray) d.preloadArray = new Array();
    	var i;
    	var j = d.preloadArray.length;
    	var a = preloadImages.arguments;
    	for (i = 0; i < a.length; i++) {
    		if (a[i].indexOf("#") != 0) { 
    			d.preloadArray[j] = new Image(); 
    			d.preloadArray[j++].src = a[i];
    		}
    	}
    }
}

function setPage(page_id){
	switch(page_id){
		case "form":
			if(document.getElementById("heard_about_us").value=="other"){
				triggerOnchangeEvent(document.getElementById("heard_about_us"));
			}
		break;
	}
}

function redirectTo(sPage){
	window.location=sPage;
}

function popupPic(sPicURL) { 
	window.open("/imgpopup.html?"+sPicURL, "", "resizable=1,height=200,width=200");
}

function openPopup(URL, width, height){
	window.open(URL,"my_window","toolbar=no,location=no,directories=no,status=no,menubar=no,scrollbars=yes,resizable=yes,width=" + width + ",height=" + height)
}

function isValidEmail(sEmail){
    var isValid;
	var re = /^(([^<>()[\]\\.,;:\s@\"]+(\.[^<>()[\]\\.,;:\s@\"]+)*)|(\".+\"))@((\[[0-9]{1,3}\.[0-9]{1,3}\.[0-9]{1,3}\.[0-9]{1,3}\])|(([a-zA-Z\-0-9]+\.)+[a-zA-Z]{2,}))$/
    if (!sEmail.match(re)) {
        isValid = false; 
    }
	else {
		isValid = true; 
	}
    return isValid;
}

function triggerOnchangeEvent(oSelect, args){
	switch(oSelect.id){
		case "heard_about_us":
			var sHTML = "";
			var oSelectWidth=190;
			if(document.getElementById("heard_about_us").value=="other"){
				if(document.getElementById("div_other")){
					sHTML+="<input type='text' name='other_way' id='other_way' style='width: 110px;'/>";
					oSelectWidth=80;
				}
			}
			document.getElementById("div_other").innerHTML = sHTML;
			document.getElementById("heard_about_us").style.width=oSelectWidth + "px";
		break;
	}
}

function checkForm(oForm){
	switch(oForm.id){
		case "form_register":
			if(document.getElementById("name").value==""){
				alert(errEmptyField("Name"));
				document.getElementById("name").focus();
				return false;
			}
			if(document.getElementById("email").value==""){
				alert(errEmptyField("E-mail"));
				document.getElementById("email").focus();
				return false;
			}
			else if(!isValidEmail(document.getElementById("email").value)){
				alert(errInvalidValue("E-mail"));
				document.getElementById("email").focus();
				return false;
			}

			return true;
		break;
	}
}

function errEmptyField(label_nl){
	var sErrMsg;
	sErrMsg = "The field " + "\"" + label_nl +  "\" can not be empty."
	return sErrMsg;
}

function errInvalidValue(label_nl){
	var sErrMsg;
	sErrMsg = "Your " + label_nl +  " is not valid."
	return sErrMsg;
}