
//*****************  inserts HTML line breaks before all newlines in a string
function nl2br (str) {
   return str.replace(/([^>])\n/g, '$1<br/>');
}

//*****************  analog addslashes php function
function addslashes (str) {
    return str.replace('/(["\'\])/g', "\\$1").replace('/\0/g', "\\0");
}

//*****************  checks if a value exists in an array
function in_array (needle, haystack, strict) {
    // 
    // +   original by: Kevin van Zonneveld (http://kevin.vanzonneveld.net)
    var found = false, key, strict = !!strict;
    for (key in haystack) {
        if ((strict && haystack[key] === needle) || (!strict && haystack[key] == needle)) {
            found = true;
            break;
        }
    }
    return found;
} 

//*****************  push one or more elements onto the end of array
function array_push ( array ) { // 
	//
	// +   original by: Kevin van Zonneveld (http://kevin.vanzonneveld.net) 
	var i, argv = arguments, argc = argv.length;
	 
	for (i=1; i < argc; i++){
		array[array.length++] = argv[i];
	} 
	return array.length;
}

//*****************  find first occurrence of a string
function strstr( haystack, needle, bool ) {
	//
	// +   original by: Kevin van Zonneveld (http://kevin.vanzonneveld.net)
	var pos = 0;
 
    pos = haystack.indexOf( needle );
    if( pos == -1 ){
        return false;
    } else{
        if( bool ){
            return haystack.substr( 0, pos );
        } else{
            return haystack.slice( pos );
        }
    }
}

function explode( delimiter, string ) {	// Split a string by string
	// 
	// +   original by: Kevin van Zonneveld (http://kevin.vanzonneveld.net)
	// +   improved by: kenneth
	// +   improved by: Kevin van Zonneveld (http://kevin.vanzonneveld.net)

	var emptyArray = { 0: '' };

	if ( arguments.length != 2
		|| typeof arguments[0] == 'undefined'
		|| typeof arguments[1] == 'undefined' )
	{
		return null;
	}

	if ( delimiter === ''
		|| delimiter === false
		|| delimiter === null )
	{
		return false;
	}

	if ( typeof delimiter == 'function'
		|| typeof delimiter == 'object'
		|| typeof string == 'function'
		|| typeof string == 'object' )
	{
		return emptyArray;
	}

	if ( delimiter === true ) {
		delimiter = '1';
	}

	return string.toString().split ( delimiter.toString() );
}

function split( delimiter, string ) {   // Split string into array by regular expression
	//
	// +   original by: Kevin van Zonneveld (http://kevin.vanzonneveld.net)
    return explode( delimiter, string );
}
