function strip_tag( html ) {
	var re = /<[^>]*>/g;
	return html.replace(re,"");
}

function html( text ) {
	var s = text.replace(/&/gi,"&amp;");
	s = s.replace(/\\/gi,"&quot;");
	s = s.replace(/</gi,"&lt;");
	s = s.replace(/>/gi,"&gt;");
	//	html = html.replace(/[:blank:]/gi,"&nbsp;");
	return s.replace(/\n/gi,"<br>")
}

function plain_text( html ) {
	var text = html.replace(/<br>/gi,"\n");
	text = text.replace(/<li>/gi,"\n");
	text = text.replace(/<ul>/gi,"\n");
	text = text.replace(/&amp;/gi,"&");
	text = text.replace(/&quot;/gi,"\"");
	text = text.replace(/&lt;/gi,"<");
	return stripTags(text.replace(/&gt;/gi,">"));
}

function get_o( id ) {
	if ( document.all && !document.getElementById ) {
		return document.all[id];
	} 
	return document.getElementById(id);
}

function get_var( key, url ) {
	if ( !url )
		url = location.href;
	var k = key+"=";
	var n = url.indexOf(k);
	if ( n == -1 ) 
   		return "";
	var e;
	for ( e = n+k.length; e < url.length; e ++ ) {
		if ( url.charAt(e) == '&' ) break;
	}
	return url.substring(n+k.length,e);
}

function set_var( key, val, url ) {
	if ( !url )
		url = location.href;
	var k = key+"=";
	var n = url.indexOf(k);
	if ( n == -1 )
   		return url_concat(url,key+"="+escape(val));
	var e;
	for ( e = n+k.length; e < url.length; e ++ ) {
		if ( url.charAt(e) == '&' ) break;
	}
	url = url.substring(0,n)+url.substring(e+1,url.length);
  	return url_concat(url,key+"="+escape(val));
}

function url_concat( url, params ) {
	if ( url.indexOf("?") == -1 )
		return (url+"?"+params);
	if ( url.charAt(url.length-1) != '&' )
		params = "&"+params;
	return (url+params);
}

function popup( url ) {
	sealWin=window.open(url,"win",'toolbar=0,location=0,directories=0,status=1,menubar=1,scrollbars=1,resizable=1,width=650,height=475');
	self.name = "mainWin"; 
}

function go_url( url ) {
	self.location.href = url;
}

function trim( str ) {
	return ltrim(rtrim(str));
}

function replace( s, target_s, replacement_s ) {
	return s.split(target_s).join(replacement_s);
}

function rtrim(str){
	var whitespace = new String(" \t\n\r");
	var s = new String(str);
	if (whitespace.indexOf(s.charAt(0)) != -1) {
		var j=0, i = s.length;
		while (j < i && whitespace.indexOf(s.charAt(j)) != -1)
			j++;
		s = s.substring(j, i);
	}
	return s;
}

function ltrim(str){
	var whitespace = new String(" \t\n\r");
	var s = new String(str);
	if (whitespace.indexOf(s.charAt(s.length-1)) != -1) {
		var i = s.length - 1; // Get length of string
		while (i >= 0 && whitespace.indexOf(s.charAt(i)) != -1)
			i--;
		s = s.substring(0, i+1);
	}
	return s;
}

function is_numeric( s ) {
	var elmstr = trim(s + "");
	if (elmstr == ""){
		return false
	}
	for (var i = 0; i < elmstr.length; i++) {
		if (elmstr.charAt(i) < "0" || elmstr.charAt(i) > "9") {
			return false
		} 
	}
	return true
}


// credits: www.juicystudio.com 
function is_email( str )
{
        // Rules for the email regular expression:
        // The start of the email must have at least one character 
        // before the @ sign
        // There may be either a . or a -, but not together before the @ sign
        // There must be an @ sign
        // At least once character must follow the @ sign
        // There may be either a . or a -, but not together in the address
        // The address must end with a . followed by at least 2 characters
        return /^\w+([\.-]?\w+)*@\w+([\.-]?\w+)*(\.\w{2,})+$/.test(str);
}


// credits: www.juicystudio.com 
function is_date( str )
{
        // Rules for the date regular expression:
        // The format of the date is:
        // dd/mm/yyyy
        // Days: Valid between 1 and 31
        // The first digit may either be a 3 followed by a 0 or a 1 
        // or it could be a 0 followed by 1 to 9, or a 1 or 2, 
        // followed by any digit.
        // Then follows a backslash
        // Months: Valid between 1 and 12
        // The month may be a 0 followed by 1 to 9, or a 1 followed by 
        // either a 0, 1 or 2. 
        // Then follows a backslash
        // The year must comprise of any 4 digits.
        return /^(3[01]|0[1-9]|[12]\d)\/(0[1-9]|1[012])\/\d{4}/.test(str);
}


function clock() {
	var time = new Date();
	var hour = time.getHours();
	var minute = time.getMinutes();
	var second = time.getSeconds();
	var temp = "" + ((hour > 12) ? hour - 12 : hour);
	if (hour == 0) 
		temp = "12";
	temp += ((minute < 10) ? ":0" : ":") + minute;
	temp += ((second < 10) ? ":0" : ":") + second;
	temp += (hour >= 12) ? " P.M." : " A.M.";
	return temp;
}

function today() {
	today = new Date();
	var monthname=new Array("Jan","Feb","Mar","Apr","May","Jun","Jul","Aug","Sep","Oct","Nov","Dec");
	return (monthname[today.getMonth()]+" "+today.getDate()+", "+today.getFullYear()+" "+clock());
}
