//string funktionen
//trim: Strip whitespace from the beginning and end of a string
function trim(stringToTrim)
{
	return stringToTrim.replace(/^\s+|\s+$/g,"");
}

//replace string hits with repl using regExp.. u can use $n as backreference
function pregReplace(strRegExp, repl, str)
{
	var result = false;
	var regExp = new RegExp(strRegExp);
	result[i] = str.replace(regExp, repl);
	return result;
}

//replace all array-string-objects hits in arr with repl using regExp.. u can use $n as backreference
function arrPregReplace(strRegExp, repl, arr)
{
	var result = new Array();
	var regExp = new RegExp(strRegExp);

	if(arr[0])
	{
		for(var i=0;i<arr.length;i++)
		{		
			result[i] = arr[i].replace(regExp, repl);
		}
	}
	return result;
}

//return an array with all arr-string-objects that matched the reg. expr.
function arrPregMatch(strRegExp, repl, arr)
{
	var result = new Array();
	var regExp = new RegExp(strRegExp);

	if(arr[0])
	{
		for(var i=0;i<arr.length;i++)
		{
			if(arr[i].match(regExp, repl))
				result[i] = arr[i];
		}
	}
	return result;
}

//url encoding and decoding
function urlEncodeCharacter(c)
{
	return '%' + c.charCodeAt(0).toString(16);
};

function urlDecodeCharacter(str, c)
{
	return String.fromCharCode(parseInt(c, 16));
};

function urlEncode(s)
{
      return encodeURIComponent(s).replace( /\%20/g, '+' ).replace( /[!'()*~]/g, urlEncodeCharacter );
};

function urlDecode(s)
{
      return decodeURIComponent(s.replace( /\+/g, '%20' )).replace( /\%([0-9a-f]{2})/g, urlDecodeCharacter);
};


function strstr (haystack, needle, bool) {
    
	pos = haystack.indexOf(needle);
    if (pos == -1)
    {
        return false;
    }
    else
    {
        if (bool)
        {
            return haystack.substr(0, pos);        
        }
        else
        {
            return haystack.slice(pos);
        }
    }
}

