// JavaScript Document

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

// 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 new window
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) {
	elem = getO(id);
	elem.blur();
}

// gives focus to an object based on it's id
function foc(id) {
	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';
}
