/*	common funcions
 *
 *	all rights reserved
 *	Ondrej Verbo (c) 2009
 */

function updateClock() {
	if (!document.getElementById('clock'))
		return true;

	var currentTime = new Date ( );

	var currentHours = currentTime.getHours ( );
	var currentMinutes = currentTime.getMinutes ( );
	var currentSeconds = currentTime.getSeconds ( );

	// Pad the minutes and seconds with leading zeros, if required
	currentMinutes = ( currentMinutes < 10 ? "0" : "" ) + currentMinutes;
	currentSeconds = ( currentSeconds < 10 ? "0" : "" ) + currentSeconds;

	// Compose the string for display
	var currentTimeString = currentHours + ":" + currentMinutes + ":" + currentSeconds;

	// Update the time display
	document.getElementById('clock').firstChild.nodeValue = currentTimeString;
}

function stristr( haystack, needle, bool ) {
	// http://kevin.vanzonneveld.net
	// +   original by: Kevin van Zonneveld (http://kevin.vanzonneveld.net)
	// +   bugfxied by: Onno Marsman
	// *     example 1: stristr('Kevin van Zonneveld', 'Van');
	// *     returns 1: 'van Zonneveld'
	// *     example 2: stristr('Kevin van Zonneveld', 'VAN', true);
	// *     returns 2: 'Kevin '

	var pos = 0;

	haystack += '';
	pos = haystack.toLowerCase().indexOf( (needle+'').toLowerCase() );

	if( pos == -1 ){
		return false;
	} else {
		if( bool ) {
			return haystack.substr( 0, pos );
		} else {
			return haystack.slice( pos );
		}
	}
}

function str_replace( srch, rplc, sbj, cnt ) {
	//	original by: Ondrej Verbo
	//	all rights reserved
	//	imitation of php function str_replace

	var pos = 0;

	sbj += '';
	pos = sbj.toLowerCase().indexOf( (srch+'').toLowerCase() );

	if( pos == -1 ) {
		return false;
	} else {
		var len = srch.length;

		var bg = sbj.substr(0, pos);
		var ot = sbj.slice(pos + len);

		return bg + rplc + ot;
	}
}

