// JavaScript Document

/**************************************************************\
* Index:
*  goto(url) - go to url
*  getO(id) - get object
*  getS(id) - get style (css)
*  getH(id) - get height
*  getT(id) - get top
*  getL(id) - get left
*  getR(id) - get right
*  submitForm(id) - submits a form
*  opFull(url, name) - open full window
*  opStd(url, name) - open 1000x800 standard size window
*  pshow(id1, id2, gap) - position and show id1 relative to id2 + gap (sets display: block;)
*  jpos(id1, id2, gap) - just position
*  hide(id) - sets display: none;
*  display(id) - sets display: block;
*  blr(id) - takes focus
*  foc(id) - gives focus
*  opac(id, target) - sets opacity to a target (0-100)
*  matchH(id1, id2, extra) - match height of 2 elems + extra if needed
*  resizeC() - resize container - change id if needed
*/ 


// 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;
}
function getL(id) {
	return document.getElementById(id).offsetLeft;
}
function getR(id) {
	return document.getElementById(id).offsetRight;
}

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

// opens a new window with all default features, name is just a reference to the new window
function opFull(url, name){
     window.open(url, name, '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 opStd(url, name){
     window.open(url, name, '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 pshow(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';
}
