
function $_(idVal) { return document.getElementById(idVal); }

/* Show a hidden element, hide a shown element */
function showHide(idVal) {
	if ($_(idVal)) {
		$_(idVal).style.display = ($_(idVal).style.display == '') ? 'none': '';
	}
	return true;
}

function inArray(needle, haystack) {
	var size = haystack.length;
	for(var x = 0; x < size; x++) {
		if (needle == haystack[x]) {
			return x;
		}
	}
	return false;
}

function ltrim(str) { 
	for(var k = 0; k < str.length && isWhitespace(str.charAt(k)); k++);
	return str.substring(k, str.length);
}
function rtrim(str) {
	for(var j=str.length-1; j>=0 && isWhitespace(str.charAt(j)) ; j--) ;
	return str.substring(0,j+1);
}
function trim(str) {
	return ltrim(rtrim(str));
}
function isWhitespace(charToCheck) {
	var whitespaceChars = " \t\n\r\f";
	return (whitespaceChars.indexOf(charToCheck) != -1);
}

/* Cookie functions */
function createCookie(name,value,days) {
	if (days) {
		var date = new Date();
		date.setTime(date.getTime()+(days*24*60*60*1000));
		var expires = "; expires="+date.toGMTString();
	}
	else var expires = "";
	document.cookie = name+"="+value+expires+"; path=/";
}

function readCookie(name) {
	var nameEQ = name + "=";
	var ca = document.cookie.split(';');
	for(var i=0;i < ca.length;i++) {
		var c = ca[i];
		while (c.charAt(0)==' ') c = c.substring(1,c.length);
		if (c.indexOf(nameEQ) == 0) return c.substring(nameEQ.length,c.length);
	}
	return null;
}

function eraseCookie(name) {
	createCookie(name,"",-1);
}

function goTo(address) {
    document.location = address;
}


function getWindowWidth() {
	if (self.innerWidth)
	{
		frameHeight = self.innerWidth;
	}
	else if (document.documentElement && document.documentElement.clientWidth)
	{
		frameHeight = document.documentElement.clientWidth;
	}
	else if (document.body)
	{
		frameHeight = document.body.clientWidth;
	}
	else
	{
		return;
	}
	return frameHeight;
}
function getWindowHeight() {
	if (self.innerWidth)
	{
		frameHeight = self.innerHeight - 20;
	}
	else if (document.documentElement && document.documentElement.clientWidth)
	{
		frameHeight = document.documentElement.clientHeight;
	}
	else if (document.body)
	{
		frameHeight = document.body.clientHeight;
	}
	else
	{
		return;
	}
	return frameHeight;
}

function findPos(obj) {
	var curleft = curtop = 0;
	if (obj) {
		curleft = obj.offsetLeft
		curtop = obj.offsetTop
		if (obj.offsetParent) {
    		while (obj = obj.offsetParent) {
    			curleft += obj.offsetLeft
    			curtop += obj.offsetTop
    		}
		}
	}
	return [curleft,curtop];
}

function scrollDetect() {
	var scrolled = new Object();
	var x = 0;
	var y = 0;
	if (self.pageYOffset) // all except Explorer
	{
		x = self.pageXOffset;
		y = self.pageYOffset;
	}
	else if (document.documentElement && document.documentElement.scrollTop)
		// Explorer 6 Strict
	{
		x = document.documentElement.scrollLeft;
		y = document.documentElement.scrollTop;
	}
	else if (document.body) // all other Explorers
	{
		x = document.body.scrollLeft;
		y = document.body.scrollTop;
	}
	scrolled.x = x;
	scrolled.y = y
	return scrolled;
}

function getPageSizeWithScroll(){
	if (window.innerHeight && window.scrollMaxY) {// Firefox
		yWithScroll = window.innerHeight + window.scrollMaxY;
		xWithScroll = window.innerWidth + window.scrollMaxX;
	} else if (document.body.scrollHeight > document.body.offsetHeight){ // all but Explorer Mac
		yWithScroll = document.body.scrollHeight;
		xWithScroll = document.body.scrollWidth;
	} else { // works in Explorer 6 Strict, Mozilla (not FF) and Safari
		yWithScroll = document.body.offsetHeight;
		xWithScroll = document.body.offsetWidth;
  	}
	arrayPageSizeWithScroll = new Array(xWithScroll,yWithScroll);
	//alert( 'The height is ' + yWithScroll + ' and the width is ' + xWithScroll );
	return arrayPageSizeWithScroll;
}


function checkInput(fields) {
    var count = fields.length;
    for(var x = 0; x < count; x++) {
        if ($_(fields[x]).value == 0) {
            return false;
        }
    }
    return true;
}
	
window.onresize = function() {

}
window.onscroll = function() {

}