//----------- To add OnLoad events (stack) -------------------
function addDocumentLoadEvent( func ) {
      var oldonload = window.onload;
      if (typeof window.onload != 'function') {
            window.onload = func;
      } else {
            window.onload = function() {
                  oldonload();
                  func();
            }
      }
}

//---------- Displays Loading Message and hides Transaction Message ----
function Processing()
{
	if(document.getElementById("Loading"))
		document.getElementById("Loading").style.display = "inline";

	if(document.getElementById("TransMsg"))
		document.getElementById("TransMsg").style.display = "none";
}

//------- Displays Message after Transaction ---------

function DisplayTransMessage( msg )
{
	if(document.getElementById("Loading"))
		document.getElementById("Loading").style.display = "none";

	if(document.getElementById("TransMsg"))
	{
		if(msg.length > 0)
		{
			document.getElementById("TransMsg").style.display = "inline";
			document.getElementById("TransMsg").innerHTML = msg;
		}
		else
			document.getElementById("TransMsg").style.display = "none";
	}
}

function DisplayMsg(id, msg)
{
    document.getElementById(id).style.display = "block";
    document.getElementById(id).innerHTML = msg;
}

function HideMsg( id )
{
	if(document.getElementById(id))
		document.getElementById(id).style.display = "none";
}

function SetFocus( id )
{
	try
	{
		document.getElementById(id).focus();
	}
	catch (e)
	{
	}
}

function ValidateBlank(ClientID, msg, msgElementId)
{ 
    if(document.getElementById(ClientID).value != "")
    {
        HideMsg(msgElementId);
        return 0;  
    }  
    else
    {
	   DisplayMsg( msgElementId,  msg + " is required.");
	   //SetFocus( ClientID );
       return 1;
    }   
}

function ValidEmail(src) {
  var regex = /^[a-zA-Z0-9._-]+@([a-zA-Z0-9.-]+\.)+[a-zA-Z0-9.-]{2,4}$/;
  return regex.test(src);
  }

function trim(str, chars) {
    return ltrim(rtrim(str, chars), chars);
}

function ltrim(str, chars) {
    chars = chars || "\\s";
    return str.replace(new RegExp("^[" + chars + "]+", "g"), "");
}

function rtrim(str, chars) {
    chars = chars || "\\s";
    return str.replace(new RegExp("[" + chars + "]+$", "g"), "");
}



//Begin
function textCounter1(field, cntfield, maxlimit) 
{
	var remaining = eval(maxlimit - field.value.length);
	
	if (field.value.length > maxlimit) // if too long...trim it!
	{
		field.value = field.value.substring(0, maxlimit);
	}
	// otherwise, update 'characters left' counter
	else
	{
		if(remaining < 1)
			document.getElementById(cntfield).innerHTML = "<font color=\"#FF0000\"><b>" + remaining + "</b></font>";
		else
			document.getElementById(cntfield).innerHTML = "<font color=\"#3A763A\"><b>" + remaining + "</b></font>";
	}
}
//  End -->

//Begin
function textCounter2(field,cntfield,maxlimit) 
{
	if (field.value.length > maxlimit) // if too long...trim it!
		field.value = field.value.substring(0, maxlimit);
	// otherwise, update 'characters left' counter
	else
		cntfield.value = maxlimit - field.value.length;
}
//  End -->

//Bookmarking webpage
function bookmark(title,url){
	if(window.sidebar) 
          window.sidebar.addPanel(title,url,"");
	else if(window.opera && window.print){
          var elem = document.createElement('a');
          elem.setAttribute('href',url);
          elem.setAttribute('title',title);
          elem.setAttribute('rel','sidebar');
          elem.click();
	}
	else if(os == "ie")
          window.external.AddFavorite(url,title);
}

function PopSignOps()
{
	var signOpsPagePath = document.getElementById("ancSignOps").href;
	if(!window.logop)
	{
		var logop = window.open(signOpsPagePath, "logop", "status=0,location=0,menubar=0,scrollbars=0,resizable=1,width=300,height=20,top=200,left=400");
		logop.focus();
	}
	else
	{
		window.logop.focus();
	}
}