function framebuster(){
	if(parent.frames.length!=0){
      window.top.location.href="/admin/login.aspx";
	}  
}


function OpenWindowCentered(szURL)
{
//Centers a window and removes toolbars and such
//bytSizeable:	1=True; 0=False
//alert("AvailableHeight="+ screen.availHeight);
//alert("AvailableWidth="+ screen.availWidth);
var intTop = (screen.availHeight - 450) / 2;
var intLeft = (screen.availWidth - 730) / 2;
window.open(szURL, "FaxDocument", "toolbar=no,  top=" + intTop + ", left=" + intLeft + ", location=no, directories=no, menubar=no, status=no, scrollbars=yes, resizable=1, width=730, height=400");				
//window.open(szURL, "FaxDocument", "toolbar=no,top=20,left=20,location=no,directories=no,menubar=no,status=no,scrollbars=yes,resizable=1,width=450,height=400");				
//alert("Hello!");
}


function OpenMap(szURL)
{
//Centers a window and removes toolbars and such
//bytSizeable:	1=True; 0=False
//alert("AvailableHeight="+ screen.availHeight);
//alert("AvailableWidth="+ screen.availWidth);
var intTop = (screen.availHeight - 500) / 2;
var intLeft = (screen.availWidth - 730) / 2;
window.open(szURL, "FaxDocument", "toolbar=no,  top=" + intTop + ", left=" + intLeft + ", location=no, directories=no, menubar=no, status=no, scrollbars=yes, resizable=1, width=730, height=500");				
//window.open(szURL, "FaxDocument", "toolbar=no,top=20,left=20,location=no,directories=no,menubar=no,status=no,scrollbars=yes,resizable=1,width=450,height=400");				
//alert("Hello!");
}


var submitcount=0;
function checkSubmit(){
	if (typeof Page_IsValid != 'undefined'){
	//if (Page_IsValid != null){
		//alert("Page_IsValid Exists!")
		if (Page_IsValid) {
			if (submitcount == 0) {
				submitcount++;
				return true;
			} else {
				alert("This form has already been submitted.  Thanks!");
				return false;
			}
		}
	}else{
		//alert("Page_IsValid Does Not Exist!")
		if (submitcount == 0) {
				submitcount++;
				return true;
			} else {
				alert("This form has already been submitted.  Thanks!");
				return false;
			}
	}
}

function ShowFees(AccountID, ID) {
	var h=230;
	var w=250;
	var winl = (screen.width - w) / 2;
	var wint = (screen.height - h) / 2;
	winprops = 'height='+h+',width='+w+',top='+wint+',left='+winl+',scrollbars='+scroll+',resizable=no';
	win = window.open('/Mercury/FeesSheet.aspx?AccountID=' + AccountID + '&ID=' + ID, 'EditRateFees', winprops);
}

function LoanApp(id){
		parent.location = '/loanapplication';
		}
	
function isValidEmail(emailAddress)
{
    var re = /^(([^<>()[\]\\.,;:\s@\"]+(\.[^<>()[\]\\.,;:\s@\"]+)*)|(\".+\"))@((\[[0-9]{1,3}\.[0-9]{1,3}\.[0-9]{1,3}\.[0-9]{1,3}\])|(([a-zA-Z\-0-9]+\.)+[a-zA-Z]{2,}))$/
    return re.test(emailAddress);
}

function isValidPhoneNumber(phonenumber)
{
	var passed = false;
	var re;
	
	re= /^\D?(\d{3})\D?\D?(\d{3})\D?(\d{4})$/;
	if (re.test(phonenumber) == true){
		passed = true;
	}
	
	re = /^\([1-9]\d{2}\)\s?\d{3}\-\d{4}$/;
	if (re.test(phonenumber) == true){
		passed = true;
	}
	
	re = /^([\(]{1}[0-9]{3}[\)]{1}[ |\-]{0,1}|^[0-9]{3}[\-| ])?[0-9]{3}(\-| ){1}[0-9]{4}$/;
	if (re.test(phonenumber) == true){
		passed = true;
	}
	
	return passed;
}


//==================================================================
//RTrim(string) : Returns a copy of a string without trailing spaces.
//==================================================================
function RTrim(str)
   //PURPOSE: Remove trailing blanks from our string.
   //IN: str - the string we want to RTrim
{
   // We don't want to trip JUST spaces, but also tabs,
   // line feeds, etc.  Add anything else you want to
   // "trim" here in Whitespace

   var whitespace = new String(" \t\n\r");

   var s = new String(str);

   if (whitespace.indexOf(s.charAt(s.length-1)) != -1)
   {
      // We have a string with trailing blank(s)...
 
      var i = s.length - 1;       // Get length of string

      // Iterate from the far right of string until we
      // don't have any more whitespace...
      while (i >= 0 && whitespace.indexOf(s.charAt(i)) != -1)
         i--;

      // Get the substring from the front of the string to
      // where the last non-whitespace character is...
      s = s.substring(0, i+1);
   }

   return s;
}

//==================================================================
//LTrim(string) : Returns a copy of a string without leading spaces.
//==================================================================
function LTrim(str)
   //PURPOSE: Remove leading blanks from our string.
   //IN: str - the string we want to LTrim
{
   var whitespace = new String(" \t\n\r");

   var s = new String(str);

   if (whitespace.indexOf(s.charAt(0)) != -1)
   {
      // We have a string with leading blank(s)...

      var j=0, i = s.length;

      // Iterate from the far left of string until we
      // don't have any more whitespace...
      while (j < i && whitespace.indexOf(s.charAt(j)) != -1)
         j++;

      // Get the substring from the first non-whitespace
      // character to the end of the string...

      s = s.substring(j, i);
   }
   
   return s;
}

//==================================================================
//Trim(string) : Returns a copy of a string without 
//				 leading or trailing spaces.
//==================================================================
function Trim(str)
{
	var s = RTrim(str);
	
	if (s.length > 0)
		s = LTrim(s);
		
	return s;		
}
