/*
 * NOTE:
 *	some of these scripts are just copied from their original sources
 *
 * Change(s): 7/21/03 - wiseobject, initial compilation 
 */ 

function stripTags( html ) {
	var re = /<[^>]*>/g;
	return html.replace(re,"");
}

function encHTML( text ) {
	html = text.replace(/&/gi,"&amp;");
	html = html.replace(/\\/gi,"&quot;");
	html = html.replace(/</gi,"&lt;");
	html = html.replace(/>/gi,"&gt;");
	//	html = html.replace(/[:blank:]/gi,"&nbsp;");
	return html.replace(/\n/gi,"<br>")
}

function newImage( src ) {
	if ( document.images ) {
		var img = new Image();
		img.src = src;
		return img;
	}
	return null;
}

function decHTML( html ) {
	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 getObj( id ) {
	if ( document.all && !document.getElementById ) {
		return document.all[id];
	} 
	return document.getElementById(id);
}

/* 4.14.4; wioseobject <-- parse a variable in the current URL */
function getVar( key ) {
   var 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[e] == '&' ) break;
   }
   return url.substring(n+k.length,e);
}

function urlConcat( url, params ) {
	if ( url.indexOf("?") != -1 )
		return (url+"&"+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 goURL( url ) {
	self.location.href = url;
}

function trim( str ) {
	var temp = str;
	var obj = /^(\s*)([\W\w]*)(\b\s*$)/;
	if (obj.test(temp)) {
		temp = temp.replace(obj, '$2');
	}
	var obj = /  /g;
	while (temp.match(obj)) {
		temp = temp.replace(obj, "");
	}
	return temp; 
}

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 isNumeric(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
}


/* source: www.juicystudio.com */
function isEmail( 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);
}


/* source: www.juicystudio.com */
function isDate( 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());
}
