//closes window if the opener is itself
if (window.opener != null) {
	if (window.opener.location.href == window.location.href) {
		window.close();
	}
}

//variables used for centering
var w = 800, h = 600;
if (document.all || document.layers) {
   w = screen.availWidth;
   h = screen.availHeight;
}
	
var centerX = (w-700)/2, centerY = (h-500)/2;


function confirmDelete(obj) {
	if (confirm("Are you sure?")) { obj.submit(); }
}


function replace(string,text,by) {
// Replaces text with by in string
    var strLength = string.length, txtLength = text.length;
    if ((strLength == 0) || (txtLength == 0)) return string;

    var i = string.indexOf(text);
    if ((!i) && (text != string.substring(0,txtLength))) return string;
    if (i == -1) return string;

    var newstr = string.substring(0,i) + by;

    if (i+txtLength < strLength)
        newstr += replace(string.substring(i+txtLength,strLength),text,by);

    return newstr;
}

function resizeWindow() {
    if (document.images) {
        if (windowHandle.document.images.length == 1) {
            if (document.layers) {
            	var lngWidth=windowHandle.document.images[0].width;
            	var lngHeight=windowHandle.document.images[0].height;
            	if (lngHeight>600) {
            		windowHandle.resizeTo(lngWidth+36,600);
            	} else {
            		windowHandle.resizeTo(lngWidth+36,lngHeight);
            	}
            } else {
            	if (document.all) {
            		var lngWidth=windowHandle.document.images[0].width;
            		var lngHeight=windowHandle.document.images[0].height;
            		if (lngHeight>600) {
            			windowHandle.resizeTo(lngWidth+46,600);
            		} else {
            			windowHandle.resizeTo(lngWidth+46,lngHeight+66);
            		}
            	}
            }
        } else {
            setTimeout('resizeWindow()',1000);
        }
    }
}

function MM_openBrWindow(theURL,winName,features) { //v2.0
  window.open(theURL,winName,features);
}

function emailCheck (emailStr) {
/* The following pattern is used to check if the entered e-mail address
   fits the user@domain format.  It also is used to separate the username
   from the domain. */
var emailPat=/^(.+)@(.+)$/ 
/*var emailPat=/^([a-zA-Z]\w*(\.\w+)*)@(.+)$/ */

/* The following string represents the pattern for matching all special
   characters.  We don't want to allow special characters in the address.
   These characters include ( ) < > @ , ; : \ " . [ ]    */
var specialChars="\\(\\)<>@,;:\\\\/\\\"\\[\\]\\."
/* The following string represents the range of characters allowed in a
   username or domainname.  It really states which chars aren't allowed. */
var validChars="\[^\\s" + specialChars + "\]"
/* The following pattern applies if the "user" is a quoted string (in
   which case, there are no rules about which characters are allowed
   and which aren't; anything goes).  E.g. "jiminy cricket"@disney.com
   is a legal e-mail address. */
var quotedUser="(\"[^\"]*\")"
/* The following pattern applies for domains that are IP addresses,
   rather than symbolic names.  E.g. joe@[123.124.233.4] is a legal
   e-mail address. NOTE: The square brackets are required. */
var ipDomainPat=/^\[(\d{1,3})\.(\d{1,3})\.(\d{1,3})\.(\d{1,3})\]$/
/* The following string represents an atom (basically a series of
   non-special characters.) */
var atom=validChars + '+'
/* The following string represents one word in the typical username.
   For example, in john.doe@somewhere.com, john and doe are words.
   Basically, a word is either an atom or quoted string. */
var word="(" + atom + "|" + quotedUser + ")"
// The following pattern describes the structure of the user
var userPat=new RegExp("^" + word + "(\\." + word + ")*$")
/* The following pattern describes the structure of a normal symbolic
   domain, as opposed to ipDomainPat, shown above. */
var domainPat=new RegExp("^" + atom + "(\\." + atom +")*$")


/* Finally, let's start trying to figure out if the supplied address is
   valid. */

/* Begin with the coarse pattern to simply break up user@domain into
   different pieces that are easy to analyze. */
var matchArray=emailStr.match(emailPat)
if (matchArray==null) {
  /* Too many/few @'s or something; basically, this address doesn't
     even fit the general mould of a valid e-mail address. */
	alert("The E-Mail Address you entered is not valid.")
	return false
}
var user=matchArray[1]
var domain=matchArray[2]

// See if "user" is valid
if (user.match(userPat)==null) {
    // user is not valid
    alert("Email Address: The username doesn't seem to be valid.")
    return false
}

/* if the e-mail address is at an IP address (as opposed to a symbolic
   host name) make sure the IP address is valid. */
var IPArray=domain.match(ipDomainPat)
if (IPArray!=null) {
    // this is an IP address
	  for (var i=1;i<=4;i++) {
	    if (IPArray[i]>255) {
	        alert("Email Address: Destination IP address is invalid!")
		return false
	    }
    }
    return true
}

// Domain is symbolic name
var domainArray=domain.match(domainPat)
if (domainArray==null) {
	alert("Email Address: The domain name doesn't seem to be valid.")
    return false
}

/* domain name seems valid, but now make sure that it ends in a
   three-letter word (like com, edu, gov) or a two-letter word,
   representing country (uk, nl), and that there's a hostname preceding
   the domain or country. */

/* Now we need to break up the domain to get a count of how many atoms
   it consists of. */
var atomPat=new RegExp(atom,"g")
var domArr=domain.match(atomPat)
var len=domArr.length
if (domArr[domArr.length-1].length<2 ||
    domArr[domArr.length-1].length>4) {
   // the address must end in a two letter or three letter word.
   alert("Email Address: The address must end in a three to four letter domain, or two letter country.")
   return false
}

// Make sure there's a host name preceding the domain.
if (len<2) {
   var errStr="This address is missing a hostname!"
   alert(errStr)
   return false
}

// If we've gotten this far, everything's valid!
return true;
}


function emailCheck2 (emailObj) {
	if (emailObj.value == "") { return true; }
	if (emailCheck(emailObj.value) == false) { 
	emailObj.style.backgroundColor = "yellow"; return false; }
	emailObj.style.backgroundColor = "white";
	return true;
}

function clearField(toggle,fieldtoclear) {

	if (toggle == false) {
	fieldtoclear.value = "";
	fieldtoclear.focus();
	}


}

function compareEmail(obj) {
	if (obj.Contact_Email.value!=obj.Contact_Email1.value) {
		alert("Email Confirmation does not match email address. Try again.");
		obj.Contact_Email.value="";
		obj.Contact_Email1.value="";
		obj.Contact_Email.focus();
	}
}


function comparePassword(obj) {
	if (obj.Account_Password.value!=obj.Account_Confirm.value) {
		alert("Confirmation does not match password. Try again.");
		obj.Account_Password.value="";
		obj.Account_Confirm.value="";
		obj.Account_Password.focus();
	}
}


function chkLength(obj,len) {
	obj.style.backgroundColor = "white";
	if (obj.value.length < len) {
		alert(obj.name + " must be " + len + " characters or longer!");
		obj.style.backgroundColor = "yellow";
		
		return false;
 	}
 	return true;
}

function chkLengthDigit(obj,len) {
	obj.style.backgroundColor = "white";
	if (isNaN(obj.value)) {
		alert(obj.name + " must only contain digits!");
		obj.style.backgroundColor = "yellow";		
		return false;	
	}
	if (obj.value.length < len) {
		alert(obj.name + " must be " + len + " digits!");
		obj.style.backgroundColor = "yellow";		
		return false;
 	}
 	return true;
}

function errorField(toggle,fieldtofocus) {

	if (toggle == false) {
	fieldtofocus.focus();
	}
}

function register(msg,loc) {

	if ((msg == undefined) || (msg=='')){ msg = "You must be a registered and validated user to access this link.  Please click OK to login or register."; }
	if (loc == undefined) {loc = "../login.asp"; }

	if (confirm(msg)) { window.location = loc; }
	
}

function MM_validateForm() { //v4.0
  var i,p,q,nm,test,num,min,max,errors='',args=MM_validateForm.arguments;
 
  
  for (i=0; i<(args.length-2); i+=3) { test=args[i+2]; val=MM_findObj(args[i]);
    if (val) { nm=val.name; if ((val=val.value)!="") {
      if (test.indexOf('isEmail')!=-1) { p=val.indexOf('@');
        if (p<1 || p==(val.length-1)) errors+='- '+nm+' must contain an e-mail address.\n';
      } else if (test!='R') {
        if (test.indexOf('noEmail')!=-1) { p=val.indexOf('@');
          if (p>1) errors+='- '+nm+' must NOT contain an e-mail address.\n';
        } else {
          if (isNaN(val)) errors+='- '+nm+' must contain a number.\n';
          if (test.indexOf('inRange') != -1) { p=test.indexOf(':');
            min=test.substring(8,p); max=test.substring(p+1);
            if (val<min || max<val) errors+='- '+nm+' must contain a number between '+min+' and '+max+'.\n';
    } } } } else if (test.charAt(0) == 'R') errors += '\n- '+nm+' is required.'; }
  } if (errors) alert('All required fields must be completed in full before continuing.' + errors);
  document.MM_returnValue = (errors == '');
}

function MM_findObj(n, d) { //v4.0
  var p,i,x;  if(!d) d=document; if((p=n.indexOf("?"))>0&&parent.frames.length) {
    d=parent.frames[n.substring(p+1)].document; n=n.substring(0,p);}
  if(!(x=d[n])&&d.all) x=d.all[n]; for (i=0;!x&&i<d.forms.length;i++) x=d.forms[i][n];
  for(i=0;!x&&d.layers&&i<d.layers.length;i++) x=MM_findObj(n,d.layers[i].document);
  if(!x && document.getElementById) x=document.getElementById(n); return x;
}