
function MM_reloadPage(init) {  //reloads the window if Nav4 resized
  if (init==true) with (navigator) {if ((appName=="Netscape")&&(parseInt(appVersion)==4)) {
    document.MM_pgW=innerWidth; document.MM_pgH=innerHeight; onresize=MM_reloadPage; }}
  else if (innerWidth!=document.MM_pgW || innerHeight!=document.MM_pgH) location.reload();
}
MM_reloadPage(true);

function MM_findObj(n, d) { //v4.01
  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 && d.getElementById) x=d.getElementById(n); return x;
}

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') { num = parseFloat(val);
        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 (num<min || max<num) errors+='- '+nm+' must contain a number between '+min+' and '+max+'.\n';
    } } } else if (test.charAt(0) == 'R') errors += '- '+nm+' is required.\n'; }
  } if (errors) alert('The following error(s) occurred:\n'+errors);
  document.MM_returnValue = (errors == '');
}

function postBack() {
	valid=true;

	document.MM_returnValue=true
	var req = new Array(
		new Array('UserName', 'User ID'),
		new Array('Password1', 'Password'),
		new Array('Password2', 'Password 2'),
		new Array('userType', 'Profession'),
		new Array('FirstName', 'First Name'),
		new Array('LastName', 'Last Name'),
		'Address',
		'City',
		'State',
		'Zip',
		'Phone',
		'Email'
	);
	
	for (i=0;i<req.length;i++){
		if (isArray(req[i])){
			if (!MM_Valid(req[i][0], req[i][1])){ document.MM_returnValue=false; return false; }
		} else {
			if (!MM_Valid(req[i], req[i])){ document.MM_returnValue=false; return false; }
		}
	}
	// now the formats
	if (!validatePhoneFormat()){
		alert("Phone Number is in incorrect format. (###-###-#### ####)");
		document.MM_returnValue=false;
		return false;
	}
	if (!validateFaxFormat()){
		alert("Fax Number is in incorrect format. (###-###-#### ####)")
		document.MM_returnValue=false;
		return false;
	}
	if (!validateEmailFormat()){
		alert("Email is in incorrect format. (name@organization.ext)")
		document.MM_returnValue=false;
		return false;
	}
	//
	var pw1 = MM_findObj("Password1");
	var pw2 = MM_findObj("Password2");
	if (pw1.value != pw2.value && (pw1.value.length>0 && pw2.value.length>0)){
		alert("Passwords do not match.")
		document.MM_returnValue=false;
		return false;
	}
}

function isArray(obj) {
   if (obj.constructor.toString().indexOf("Array") == -1)
      return false;
   else
      return true;
}

function MM_Valid (obj_name, name)
{
  obj= MM_findObj(obj_name);
  if (obj != null){
	if (obj.value.length > 0)
	{
		//return document.MM_returnValue = true;
		document.MM_returnValue = true;
		return true;
	}
	else
	{
		if (name ==  null) name = obj_name;
		alert (name + " is empty!");
		//return document.MM_returnValue = false;
		document.MM_returnValue = false;
		return false;
	}
  } else { 
	return true;
  }
}

function validatePhoneFormat(){
	var P= MM_findObj("Phone");
	if(P.value.length>0) {
		var v = P.value.toString();
		var re = new RegExp(/^\d{3}-\d{3}-\d{4}( \d*)?$/);	
		return v.match(re);
	}
	return true;
}

function validateFaxFormat(){
	var F= MM_findObj("Fax")
	if(F.value.length>0){
		var v = F.value.toString();
		var re = new RegExp(/^\d{3}-\d{3}-\d{4}( \d*)?$/);	
		return v.match(re);
	}
	return true;
}

function validateEmailFormat(){
	var E= MM_findObj("Email");
	var POS;
	if(E.value.length>0) {
		if(E.value.indexOf('@') == -1) {
			return false;
		}else{
			var tempArray4=E.value.split("@")			
			if(!tempArray4[0].length>0 || !tempArray4[1].length>0) {
				return false;
			}	else{
				POS1=E.value.indexOf('.')
				if(POS1==-1) {
					return false;
				}else{
					var tempArray5=tempArray4[1].split(".")
					if(!tempArray5[0].length>0 ||!tempArray5[1].length>0 ) {
						return false;
					}
				}	

			}
		}
	}
	return true;
}

function MM_openBrWindow(theURL,winName,features) { //v2.0
	window.open(theURL,winName,features);
}

function openCourseWindow(theURL) { //v2.0
	// name this window as main
	window.name = 'main';

	var winName = 'course';
	var scw = 0;
	var sch = 0;
	if (navigator.appName == 'Microsoft Internet Explorer' && (navigator.platform.substring(0,3) == 'Win')) {
		var scw=screen.width-10;
		var sch=screen.height-52;
		corningWindow=window.open (theURL, winName, "toolbar=no,location=no,scrollbars=no,left=0,top=0,width=" + scw + ",height=" + sch);
	}
	else if (navigator.appName == 'Netscape' || navigator.platform == 'MacPPC') {
		var scw=screen.width;
		var sch=screen.height;
		corningWindow=window.open (theURL, winName, "toolbar=no,location=no,scrollbars=no,screenX=0,screenY=0,outerWidth=" + scw + ",outerHeight=" + sch);
	}
	else {
		var scw=screen.width;
		var sch=screen.height;
		corningWindow=window.open (theURL, winName, "toolbar=no,location=no,scrollbars=no,screenX=0,screenY=0,outerWidth=" + scw + ",outerHeight=" + sch);
	}
	corningWindow.focus();
	return corningWindow;
}



