String.prototype.trim = function() {
	var x=this;
	x=trimString(x);
	 return x;
}

function trimString(sString)
{
	sTrimmedString = "";
	if (sString != "")
	{
		var iStart = 0;
		var iEnd = sString.length - 1;
		//var sWhitespace = " \t\f\n\r\v";
		var sWhitespace = " \t\f\n\r";
	  
		while (sWhitespace.indexOf(sString.charAt(iStart)) != -1)
		{
			iStart++;
			if (iStart > iEnd)
				break;
		}
	  
		// If the string not just whitespace
		if (iStart <= iEnd)
		{
			while (sWhitespace.indexOf(sString.charAt(iEnd)) != -1)
			iEnd--;
			sTrimmedString = sString.substring(iStart,++iEnd);
		}
	}
	return sTrimmedString;
}
function popup(url,name,prop){
	Hwnd = window.open(url,name,prop);
	Hwnd.focus();

}

function popUp1(url, win_name, width, height)
{
	popWin	=	window.open(url, win_name, "toolbar=no, location=no, directories=no, status=no, menubar=no, resizable=YES, copyhistory=no, scrollbars=Yes, width=" + width + ", height=" + height + ", top=50, left=50");
	popWin.focus();
}

//------------------------------------------------------------------------------
function goTo(url)
{
	exit=false;
	document.location.href=url;
}

//------------------------------------------------------------------------------
function showMsg(msg, elem, select)
{
	alert(msg);
	elem.focus();
	if (select)
	{
		elem.select();
	}	
}

//------------------------------------------------------------------------------
function isAlpha(s){
	alpha="ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz'- ";
	for (i = 0; i < s.length; i++){
		var c = s.charAt(i);
		if(!(alpha.indexOf(c)>=0)){
			return false;
		}
	}
	return true;
}

//------------------------------------------------------------------------------
function isAlphaNumeric(s){	
	alpha="ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789., ";
	for (i = 0; i < s.length; i++){   
		var c = s.charAt(i);
		if(!(alpha.indexOf(c)>=0)){
			return false
		}
	}
	return true;
}

//------------------------------------------------------------------------------
function isAlphaNumericAndSpecial(s){	
	alpha="ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789.#&- ";
	for (i = 0; i < s.length; i++){   
		var c = s.charAt(i);
		if(!(alpha.indexOf(c)>=0)){
			return false
		}
	}
	return true;
}

//------------------------------------------------------------------------------
function isPhone(s){	
	alpha="1234567890 ._-()";
	for (i = 0; i < s.length; i++){   
		var c = s.charAt(i);					
		if(!(alpha.indexOf(c)>=0)){
			return false
		}
	}
	return true;
}

//------------------------------------------------------------------------------
function getNumericPhone(s){	
	alpha=" ._-()";
	str=""
	for (i = 0; i < s.length; i++){   
		var c = s.charAt(i);					
		if(!(alpha.indexOf(c)>=0)){
			str+=c;
		}
	}
	return str;
}

//------------------------------------------------------------------------------
function setCookie( cookieName, cookieValue, lifeTime, path, domain, isSecure ) 
{	
	if( !cookieName ) { return false; }
	if( lifeTime == "delete" ) { lifeTime = -10; } //this is in the past. Expires immediately.

	/* This next line sets the cookie but does not overwrite other cookies.
	syntax: cookieName=cookieValue[;expires=dataAsString[;path=pathAsString[;domain=domainAsString[;secure]]]]
	Because of the way that document.cookie behaves, writing this here is equivalent to writing
	document.cookie = whatIAmWritingNow + "; " + document.cookie; */
	document.cookie = escape( cookieName ) + "=" + escape( cookieValue ) +
		( lifeTime ? ";expires=" + ( new Date( ( new Date() ).getTime() + ( 1000 * lifeTime ) ) ).toGMTString() : "" ) +
		( path ? ";path=" + path : "") + ( domain ? ";domain=" + domain : "") + 
		( isSecure ? ";secure" : "");
	//check if the cookie has been set/deleted as required
	
	if( lifeTime < 0 ) { if( typeof( retrieveCookie( cookieName ) ) == "string" ) { return false; } return true; }
	if( typeof( retrieveCookie( cookieName ) ) == "string" ) { return true; } return false;
}

//------------------------------------------------------------------------------
function retrieveCookie( cookieName ) 
{
	/* retrieved in the format
	cookieName4=value; cookieName3=value; cookieName2=value; cookieName1=value
	only cookies for this domain and path will be retrieved */
	var cookieJar = document.cookie.split( "; " );
	for( var x = 0; x < cookieJar.length; x++ ) {
		var oneCookie = cookieJar[x].split( "=" );
		if( oneCookie[0] == escape( cookieName ) ) { return unescape( oneCookie[1] ); }
	}
	return null;
}
//------------------------------------------------------------------------------
var previd = "";
function showhideDiv(id,ancpos)
{
	if(previd!="")
		$('#'+previd).hide();
	previd = id;
	var anc = $('#'+ancpos);
	var offset = anc.offset();
	var divid = $('#'+id);
	divid.css({position:"absolute",width:"400px",padding:"10px",color:"#000",border:"0px solid #548C37",left:offset.left-10 ,top:offset.top-0});
	divid.show();
	}
//------------------------------------------------------------------------------
function closeDiv(id)
{
	var divid = $('#'+id);
	divid.hide();
}
//------------------------------------------------------------------------------
function getURL()
{
	url		=	document.location.href;
	x		=	url.indexOf(".");
	x		=	url.indexOf("/",x);
	return url.substring(0,x);
}
//------------------------------------------------------------------------------
function replaceAll(a,b,c)
{
	var ret="";
	var i=0;
	if(a.indexOf(b)==-1)
		return a;
	for (i=0;i<a.length;)
	{
		oldi=i;
		if((i=a.indexOf(b,oldi))==-1)
		{
			ret+=a.substring(oldi);
			break;
		}
		else
		{
			ret+=a.substring(oldi,i)+c;
			i+=b.length;
		}
	}
	return ret;
}
//------------------------------------------------------------------------------
var previd1 = "";
function showhideDiv1(id,ancpos)
{
	if(previd1!="")
		$('#'+previd1).hide();
	previd1 = id;
	var anc = $('#'+ancpos);
	var offset = anc.offset();
	var divid = $('#'+id);
	divid.css({position:"absolute",width:"423px",padding:"10px",color:"#000",border:"2px solid #548C37",left:offset.left-370 ,top:offset.top-23});
	divid.show();
	}
