/**                  
 * functions.js
 *
 * This file profites an general function set! 
 * The functions below are very handy for handling
 * common javascript functionality or Dynamic (X)HTML.
 *
 * @version 	1.0
 * @author	A.J. de Vries	
 * @package	javascript 
 * 
 * Copyright (c) 2005 Malibomba                               
 * IT IS NOT ALLOWED TO USE OR MODIFY ANYTHING OF THIS SITE,  
 * WITHOUT THE PERMISION OF THE AUTHOR.                       
 * Info? Mail to info@malibomba.com                           
 */
//<![CDATA[ 
/*@cc_on @*/
/*@if(@_jscript_version >= 5)
	try {
		var xmlhttp = new ActiveXObject('Msxml2.XMLHTTP');
	} catch(e) {
		try {
			var xmlhttp = new ActiveXObject('Microsoft.XMLHTTP');
		} catch(e) {
			var xmlhttp = false;
		}
	}
@else
	var xmlhttp = false;
@end @*/
if(!xmlhttp && document.createElement) {
	try {
		var xmlhttp = new XMLHttpRequest();
	} catch(e) {
		var xmlhttp = false;
	}
}


/**
 * setCookie(name, value)
 *
 * Set a Cookie with the given name and 
 * given value
 *
 * @version 	1.0
 * @author 	A.J. de Vries
 * @param 	[string] name: the name of the new cookie.
 * @param	[mixed]  the value of the new cookie with the given name.
 * @return	[void]
 */
function setCookie(name, value) {
	var argv = setCookie.arguments;
	var argc = setCookie.arguments.length;
	var expires = (argc > 2) ? argv[2] : null;
	var path = (argc > 3) ? argv[3] : null;
	var domain = (argc > 4) ? argv[4] : null;
	var secure = (argc > 5) ? argv[5] : false;
	document.cookie = name + "=" + escape (value) +
	((expires == null) ? "" : ("; expires=" + expires.toGMTString())) +
	((path == null) ? "" : ("; path=" + path)) +
	((domain == null) ? "" : ("; domain=" + domain)) +
	((secure == true) ? "; secure" : "");
}



/**
 * getCookie(name)
 *
 * Get the cookie (value) with the given name.
 *
 * @version 	1.0
 * @author 	A.J. de Vries
 * @param 	[string] name: the name of the cookie.
 * @return	[string] the value of the cookie with the given name
 */
function getCookie(name) {
	var arg = name + "=";
	var alen = arg.length;
	var clen = document.cookie.length;
	var i = 0;
	while(i < clen) {
		var j = i + alen;
		if(document.cookie.substring(i, j) == arg) {
			return getCookieVal(j);
		}
		i = document.cookie.indexOf(" ", i) + 1;
		if(i == 0) {
			break;
		}
	}
	return null;
}



/**
 * getCookieVal(offset)
 *
 * private function:
 * Is used by getCookie(name) to return the value 
 * of the requested cookie.
 *
 * @version 	1.0
 * @author 	A.J. de Vries
 * @param 	[integer] offset: the offset value of the cookie value.
 * @return	[string]  the value of the cookie with the given name
 */
function getCookieVal(offset) {
	var endstr = document.cookie.indexOf (";", offset);
	if(endstr == -1) {
		endstr = document.cookie.length;
	}
	return unescape(document.cookie.substring(offset, endstr));
}



/**
 * getElement(elem)
 *
 * Get the element with the given name (elem)
 * and return a reference (object) to it.
 *
 * @version 	1.0
 * @author 	A.J. de Vries
 * @param 	[string] elem: the name of the element
 * @return	[object] the object that references the element with the given name.
 */
function getElement(elem) {
	if(document.getElementById)
		return document.getElementById(elem);
	if(document.all)
		return document.all[elem];
}



/**
 * addEvent(elem, evt, func)
 *
 * Add an event to the given element (elem)
 *
 * @version 	1.0
 * @author 	A.J. de Vries
 * @param 	[object]   elem: the element(object) on which the event is set to.
 * @param 	[string]   evt:  the name of the event, e.g: 'load', 'focus', 'unload', etc.
 * @param 	[function] func: the function to execute.
 * @return	[void]
 */
function addEvent(elem, evt, func) {
	if(elem.addEventListener)
		elem.addEventListener(evt, func, false);
	else if(elem.attachEvent)
		elem.attachEvent('on'+evt, func);
}

function submitForm(formName, offset) {
	var F = document.forms[formName];
	F['offset'].value = offset;
	F.submit();
}
//]]>
