function setPage(pid){
	switch(pid){
		case "welcome":
			//eqHght2("cnt_l", "cnt_r");
		break;
	}
}

function eqHght2(div_1, div_2){
		var maxHeight;
		var div1_vpad=77;
		var div2_vpad=0;
		if(document.getElementById(div_1) && document.getElementById(div_2)){
			if(document.getElementById(div_1).offsetHeight > document.getElementById(div_2).offsetHeight){
				maxHeight=document.getElementById(div_1).offsetHeight;
			}
			else {
				maxHeight=document.getElementById(div_2).offsetHeight;
			}
		}
		if(document.getElementById(div_1) && document.getElementById(div_2)){
				document.getElementById(div_1).style.height=maxHeight + div2_vpad + "px";
			document.getElementById(div_2).style.height=maxHeight + div1_vpad + "px";
		}
}

function eqHght3(div_1, div_2, div_3){
		var maxHeight;
		if(document.getElementById(div_1) && document.getElementById(div_2)){
			if(document.getElementById(div_1).offsetHeight > document.getElementById(div_2).offsetHeight){
				maxHeight=document.getElementById(div_1).offsetHeight;
			}
			else {
				maxHeight=document.getElementById(div_2).offsetHeight;
			}
		}
		if(document.getElementById(div_3)){
			if(document.getElementById(div_3).offsetHeight > maxHeight){
				maxHeight=document.getElementById(div_3).offsetHeight;
			}
		}
		if(document.getElementById(div_1) && document.getElementById(div_2) && document.getElementById(div_3)){
			document.getElementById(div_1).style.height=maxHeight + "px";
			document.getElementById(div_2).style.height=maxHeight + "px";
			document.getElementById(div_3).style.height=maxHeight + "px";
		}
}

function setSelectVal(sel_id, val){
	document.getElementById(sel_id).value=val;
}

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 checkForm(form_id){
	switch(form_id){
		case "form_contactus":
			if(document.getElementById("name").value==""){
				alert("Please fill out your name.");
				document.getElementById("name").focus();
				return false;
			}
			if(document.getElementById("email").value==""){
				alert("Please fill out your e-mail address.");
				document.getElementById("email").focus();
				return false;
			}
			else if(!isValidEmail(document.getElementById("email").value)){
				alert("The email you specified is not valid.");
				document.getElementById("email").focus();
				return false;
			}
			if(document.getElementById("topic").value==""){
				alert("Please select a subject.");
				document.getElementById("topic").focus();
				return false;
			}
			if(document.getElementById("message").value==""){
				alert("Please write your message.");
				document.getElementById("message").focus();
				return false;
			}
		break;
	}
	return true;
}

//*** Init event handler.
function initProgress(objForm) {
	$("input, select, textarea", objForm).attr("readonly", "readonly");
	$("#cancelButton").removeAttr("readonly");
	$("#progress").show();
	$("#progress div.image").width(0);
	$("#progress div.label").empty().append("0%");
	$("#progress div.remaining").empty().append("Est. time left: Calculating...");
}

//*** Update event handler.
function updateProgress(objForm, intCurrent, intTotal, intElapsed) {
	var intPercent = Math.round((100 / intTotal) * intCurrent);
	var intSecLeft = Math.round((100 - intPercent) * (intElapsed / intPercent));
	if (isNaN(intPercent)) intPercent = 0;
	if (intSecLeft == 0) intSecLeft = 1;
	
	$("#progress div.image").width(intPercent * 2);
	$("#progress div.label").empty().append(intPercent + "%");
	if (isNaN(intSecLeft)) {
		var strLeft = "Calculating...";
	} else {
		var strLeft = secsToHMS(intSecLeft);
	}
	$("#progress div.remaining").empty().append("Est. time left: " + strLeft);
}

//*** Complete event handler.
function completeUpload(objForm, strFilename) {
	$("#progress div.image").width(200);
	$("#progress div.label").empty().append("100%");
	$("#progress div.remaining").empty().append("File upload complete.");
}

//*** Error event handler.
function setError(objForm, strError) {
	switch (strError) {
		case "toobig":
			strError = "The file you are trying to upload is too big. Please select a smaller one and try again.";
			break;
		case "nofile":
			strError = "The file field is empty. Did you select a file?";
			break;
		case "noform":
			strError = "The form field is empty. Please refresh the page and try again.";
			break;
	}
	
	$("#progressError").empty().show().append(strError);
	$("#progress").hide();
	$(objForm).show();
}

//*** Method to convert seconds to hh:mm:ss notation.
function secsToHMS(intSeconds) {
	var strSeconds = intSeconds - (Math.floor(intSeconds / 60) * 60);
	var intMinutes = (intSeconds - strSeconds) / 60;
	var strMinutes = intMinutes - (Math.floor(intMinutes / 60) * 60);
	var intHours = (intMinutes - strMinutes) / 60;
	var strHours = intHours;

	(strSeconds < 10) ? strSeconds = "0" + Math.round(strSeconds) : strSeconds = Math.round(strSeconds);
	(strMinutes < 10) ? strMinutes = "0" + Math.round(strMinutes) : strMinutes = Math.round(strMinutes);
	(strHours < 10) ? strHours = "0" + Math.round(strHours) : strHours = Math.round(strHours);

	return strHours + ":" + strMinutes + ":" + strSeconds;
}