/**
* (c) 2006 Vortex Webdesign
* Routines to be used for general purpose
* Written by Mike De Smet
* http://www.vortex-webdesign.be
*/

function findObj(theObj, theDoc)
{
	var p, i, foundObj;
	
	if (!theDoc) 
		theDoc = document;
	
	if ( (p = theObj.indexOf("?")) > 0 && parent.frames.length)
	{
		theDoc = parent.frames[theObj.substring(p+1)].document;
		theObj = theObj.substring(0,p);
	}

	if (!(foundObj = theDoc[theObj]) && theDoc.all) 
		foundObj = theDoc.all[theObj];
		
	for (i=0; !foundObj && i < theDoc.forms.length; i++) 
		foundObj = theDoc.forms[i][theObj];
		
	for (i=0; !foundObj && theDoc.layers && i < theDoc.layers.length; i++) 
		foundObj = findObj(theObj,theDoc.layers[i].document);
		
	if (!foundObj && document.getElementById) 
		foundObj = document.getElementById(theObj);
		
	return foundObj;
}

function strlen(str)
{
	return str.length;
}

function strpos(haystack,needle)
{
	return haystack.indexOf(needle);
}

function strtr(strWork,valSearch,valReplace)
{
	var tsearch  = '';
	var treplace = valReplace.substring(0,1);
	var containsSearch = false;
	var temp = '';
	var result = strWork;
	
	for (var i = 0; i < valSearch.length; i++)
	{
		tsearch  = valSearch.charAt(i);

		if (valReplace.length > i)
			treplace = valReplace.charAt(i);
	
		while (strpos(result,tsearch) != -1)
		{
			temp  = result.substring(0,strpos(result,tsearch));
			temp += treplace;
			temp += result.substring(strpos(result,tsearch)+1);
			result = temp;
		}
	}
	return result;
}

function trim(str)
{
	var tresult = str;
	return tresult.replace(/^\s+|\s+$/g, '_');
}

function explode(separator,str)
{
	return str.split(separator);
}

function implode(glue,pieces)
{
	return pieces.join(glue);
}

function in_array(needle,haystack)
{
	var telement = haystack.pop();

	while (telement)
	{
		if (telement == needle)
			return true;

		telement = haystack.pop();
	}

	return false;
}

function strtolower(str)
{
	return str.toLowerCase();
}

function strtoupper(str)
{
	return str.toUpperCase();
}

function is_float(str)
{
	floatValue=parseFloat(str);

	return (!isNaN(floatValue)) 
}

function is_int(str)
{
	intValue=parseInt(str);

	return (!isNaN(intValue));
}

function intval(str)
{
	return parseInt(str,10);
}

function floatval(str)
{
	return parseFloat(str);
}

function is_integer(str)
{
	return (is_int(str));
}

function is_numeric(str)
{
	return (is_int(str));
}
