// JavaScript Document

// this saves u a bit of writing when you get links based on an js event.
function goto(url) {
	window.location=url;
}
function checkForm(form) {

	var patternEmail = /^[a-z0-9._%+-]+@[a-z0-9.-]+\.[a-z]{2,4}$/;
	
	var test1 = patternEmail.test(form.email.value);
	
	if (test1 == false) {
		form.email.focus();
		alert('Please enter a valid e-mail address');
		return false;
	}
	
	if ((form.email.value == "") || (form.email.value == " ")) {
		form.email.focus();
		alert('Please enter your e-mail');
		return false;
	}
	if ((form.name.value == "") || (form.name.value == " ")) {
		form.email.focus();
		alert('Please enter your name');
		return false;
	}
	
	
	return true;
	
}

// you need these 4 functions for 'positon()' and 'matchHeight()' to work.
// but you can also use them independently to write/simplify your own.
function getO(id) {
	return document.getElementById(id);
}

function getS(id) {
	return document.getElementById(id).style;
}
function getH(id) {
	return document.getElementById(id).offsetHeight;
}
function getT(id) {
	return document.getElementById(id).offsetTop;
}

// submits a form by its id (original function)
function submitForm1(id) {
	document.getElementById(id).submit();
}

// submits a form by its id (derived from previous function), used specifically in the Clients' Interface
function submitForm(id) {
	document.getElementById(id).submit();
	OpenWindow('index.php');
	window.close();
}

// opens a new window with all default features
function openFull(url){
     window.open(url, '', 'resizable=1, scrollbars=1, toolbar=1, location=1, status=1, menubar=1, copyhistory=0, directories=1');
}


// opens new window just with scrollbars and no navigation
function OpenWindow(url){
     window.open(url, '', 'resizable=yes, height=800, width=1000, scrollbars=1');
}

// positions id1 bellow id2 plus some 'gap', and displays, an element originally hidden.
// this function is usually all you need to expand a page's footer elements 'onload'.
// ie. position('footer', 'container', 0)
function posshow(id1, id2, gap) {
	var heightID2 = getH(id2);
	var topID2 = getT(id2);
	var styleID1 = getS(id1);
	styleID1.top = heightID2 + topID2 + gap + 'px';
	styleID1.display = 'block';
}

// a way to describe/read this function would be 'just position id1 relative to id2'
// same as above but it doesn't affect the display property.
function jpos(id1, id2, gap) {
	var heightID2 = getH(id2);
	var topID2 = getT(id2);
	var styleID1 = getS(id1);
	styleID1.top = heightID2 + topID2 + gap + 'px';
	styleID1.display = 'block';
}

// hides an element based on its id.
function hide(id) {
	var elem = getS(id);
	elem.display = 'none';
}

// shows a hidden element based on its id
function display(id) {
	var elem = getS(id);
	elem.display = 'block';
}

// takes focus away from an object based on it's id
function blr(id) {
	var elem = getO(id);
	elem.blur();
}

// gives focus to an object based on it's id
function foc(id) {
	var elem = getO(id);
	elem.focus();
}


// changes an element's opacity or alpha value to a target value given from 0 to 100
function opac(id, target) {
	var elem = getS(id);
	var ie = target;
	var w3 = target/100;
	elem.opacity = w3;
	elem.MozOpacity = w3;
	elem.KhtmlOpacity = w3;
	elem.filter = 'alpha(opacity='  + ie + ')';
}

// match the height of elem1 with respect to elem2, plus extra pixels if desired
function matchH(id1, id2, extra) {
	var h2 = getH(id2);
	var styleID1 = getS(id1);
	styleID1.height = h2 + extra + 'px';
	styleID1.display = 'block';
}

// resize the container relative to the footer's absolute position and heigt
function resizeC() {
	var t = getT('footer');
	var h = getH('footer');
	var container = getS('container');
	container.height = h + t + 'px';
}