//
// login.js
//
// javaScript functions for seqreq.html
// Rev 1.91 January 23, 2008
// Rev 1.92 February 29, 2008
// Rev 1.94 May 8, 2008
// Rev 1.96 June 17, 2008
//
// Copyright dnatools 1998-2008 all rights reserved
//

function verifySpeed() {
        errorFound = true; 
        //userValidate = document.login.userValidate.value;
        speedNum = document.login.speedNum.value;
        speed = document.login.speed.value;
        
        //window.alert("speed " + speed + "speedNum " + speedNum );

        //if ( userValidate == "1" ) {
                if ( speedNum == speed ) {
                        errorFound = true;
                        window.alert("The Speed Type is correct.");
                } else {
                        errorFound = false; 
                        window.alert("The Speed Type is not correct.\n"
                        + "Please select your PI.");
                }
        //} else {
        //        errorFound = true;
        //}
        //window.alert("errorFound " + errorFound );
        return errorFound;
}


function loadUname() {
	var unixLogin;
	unixLogin = document.passwd.unixLogin.value;

	var uname = getCookie("uname");
	//window.alert("uname " + uname );
	if ( unixLogin == "1" ) {
		document.passwd.uname.value=uname;
	} else {
		document.passwd.emailAddr.value=uname;
	}

	//window.alert("uname " + uname );
}

function setUname() {
	unixLogin = document.passwd.unixLogin.value;

	if ( unixLogin == "1" ) {
		uname = document.passwd.uname.value;
	} else {
		uname = document.passwd.emailAddr.value;
	}

	var expires = new Date();
	expires.setYear(expires.getYear() + 1);
	setCookie("uname", uname, expires, "", "", "");

	//window.alert("setUname uname " + uname + ", " + "expires " + expires  );
}


function loadPInameOhiou() {
	orgName = document.login.orgName.value;
	//window.alert("orgname " + orgName);

        var selectIndex = document.login.piVal.selectedIndex;
        var selectText = document.login.piVal.options[selectIndex].value;
        
        piname = selectText.split(":");

	//window.alert("last first " + piname[0] + " " + piname[1] );
        
        document.login.pi.value = piname[0] + "," + " " + piname[1];
        //document.login.deptS.value = piname[2];
        //document.login.phoneS.value = piname[3];
        
}


function loadLogin() {
        var selectIndex = document.passwd.USER.selectedIndex;
        var text = document.passwd.USER.options[selectIndex].value;

	unixLogin = document.passwd.unixLogin.value;

	vals = text.split(":");
	uname = vals[0];
	pw = vals[1];

	//window.alert("User is " + vals[0] +"   " +  vals[1] );

	document.passwd.password.value = pw;

	if ( unixLogin == "2" ) {
		document.passwd.emailAddr.value = uname;
		//document.passwd.emailAddr.focus();

	} else {
		document.passwd.uname.value = uname;
	}

}

function setAction() {
        var selectIndex = document.passwd.act.selectedIndex;
        var act = document.passwd.act.options[selectIndex].value;

	var action;

        //window.alert(act);

        if ( act == "dna" ) {
                action="/cgi-bin/dna/dnatools.cgi";
        }

        if ( act == "corecal" ) {
                action="/coreCal/pwlogin.php?dologin=1";
        }

	if ( act == "mcrf" ) {
		action="/MCRF/pwlogin.php?dologin=1";
	}

	if ( act == "cal-dna" ) {
		action="/cal-dna/pwlogin.php?dologin=1";
	}

	if ( act == "cal-micro" ) {
                action="/cal-micro/pwlogin.php?dologin=1";
        }

	if ( act == "cal-igert" ) {
                action="/cal-igert/pwlogin.php?dologin=1";
        }

        if ( act == "cyt" ) {
                action="/cgi-bin/cytometry/cytometry.cgi";
        }

        if ( act == "hist" ) {
                action="/cgi-bin/histology/histology.cgi";
        }

        if ( act == "islet" ) {
                action="/cgi-bin/islet/islet.cgi";
        }

        if ( act == "mass" ) {
                action="/cgi-bin/massSpec/massSpec.cgi";
        }

        if ( act == "oligo" ) {
                action="/cgi-bin/oligo/oligo.cgi";
        }

        if ( act == "peptide" ) {
                action="/cgi-bin/peptide/peptide.cgi";
        }

        if ( act == "protein" ) {
                action="/cgi-bin/protein/protein.cgi";
        }

        if ( act == "rtpcr" ) {
                action="/cgi-bin/rtpcr/rtpcr.cgi";
        }

        if ( act == "equip" ) {
                action="/cgi-bin/equipment/index.cgi";
        }
        if ( act == "store" ) {
                action="/cgi-bin/store/store.cgi";
        }
        if ( act == "roche" ) {
                action="/cgi-bin/roche/store.cgi";
        }
        if ( act == "neb" ) {
                action="/cgi-bin/neb/store.cgi";
        }
        if ( act == "invitrogen" ) {
                action="/cgi-bin/invitrogen/store.cgi";
        }
        if ( act == "biorad" ) {
                action="/cgi-bin/biorad/store.cgi";
        }

        document.passwd.action=action;
        document.passwd.actVal.value=act;

	// Set a cookie with the department they chose, so we can restore
	// it next time they come to the page
	var expires = new Date();
	expires.setYear(expires.getYear() + 1);
	setCookie("prefDept", act, expires, "", "", "");

}

function loadPiMessage() {
	var selectIndex = document.login.oncampus.selectedIndex;
	var selectText = document.login.oncampus.options[selectIndex].value;
	if ( selectText == "Off_Campus" ) {
		document.login.pi.value = "Off_Campus";
		window.alert("Off_Campus Users Do Not Need to enter a PI.");
	}
}

function loadPiMessageUtmem() {
	var selectIndex = document.login.oncampus.selectedIndex;
	var selectText = document.login.oncampus.options[selectIndex].value;
	if ( selectText == "Off_Campus" ) {
		//document.login.pi.value = "Off_Campus";
		//document.login.piemail.value = "Off_Campus";
		//window.alert("Off_Campus Users Do Not Need to enter a PI.");
	}
	if ( selectText == "on_campus" ) {
		document.login.instS.value = "The University of Tennessee";
		document.login.cityS.value = "Memphis";
		document.login.stateS.value = "TN";
		document.login.zipS.value = "38163";
	}
}




function loadPiMessageReno() {
	var selectIndex = document.login.oncampus.selectedIndex;
	var selectText = document.login.oncampus.options[selectIndex].value;
	if ( selectText == "Non-NSHE" ) {
		//document.login.pi.value = "Off_Campus";
		//document.login.piemail.value = "Off_Campus";
		//window.alert("Off_Campus Users Do Not Need to enter a PI.");
	}
	if ( selectText == "NSHE" ) {
		document.login.instS.value = "University of Nevada, Reno";
		document.login.streetS.value = "1664 N. Virginia Street";
		document.login.cityS.value = "Reno";
		document.login.stateS.value = "NV";
		document.login.zipS.value = "89557";
	}
	if ( selectText == "LasVegas" ) {
		document.login.instS.value = "University of Nevada, Las Vegas";
		document.login.streetS.value = "4505 Maryland Pkwy.";
		//document.login.streetS.value = "2040 Charleston Blvd.";
		document.login.cityS.value = "Las Vegas";
		document.login.stateS.value = "NV";
		document.login.zipS.value = "89154";
	}
}





function copyEmail() {
    email = document.login.email.value;
    document.login.emailS.value = email;
}

function makeName() {
	var formError = "false";
	orgName = document.login.orgName.value;
        formType=document.login.formType.value
	first = document.login.fname.value;
	last = document.login.lname.value;
	if ( orgName != "derc" && orgName != "sequetech" ) {
		first = first.toLowerCase();
		last = last.toLowerCase();
	}
	if ( first.length < 2 ) {
		formError = "true"
		window.alert("The First Name is less than 2 characters.");
	}
	if ( last.length < 2 ) {
		formError = "true"
		window.alert("The Last Name is less than 2 characters.");
	}
	if ( formError == "true" ) {
		//window.alert("The First or Last Name is less than 2 characters.");
	} else {
		document.login.lname.value = last;
		wholeName = first + " " + last;
		if ( formType == "2" ) {
			if ( orgName != "unr" ) {
				document.login.nameB.value = wholeName;
			}
			if ( orgName != "unr" && orgName != "murdock" ) {
				document.login.nameS.value = wholeName;
			}
		} else {
			document.login.nameS.value = wholeName;
		}
	}
}

function makeNameFirst() {
	var formError = "false";
	orgName = document.login.orgName.value;
        formType=document.login.formType.value
	first = document.login.fname.value;
	last = document.login.lname.value;
	if ( orgName != "derc" && orgName != "sequetech" ) {
		first = first.toLowerCase();
		last = last.toLowerCase();
	}
	if ( first.length < 2 ) {
		//document.login.fname.value = "";
		formError = "true"
		window.alert("The First Name is less than 2 characters.");
	}
	if ( formError == "true" ) {
		//window.alert("The First or Last Name is less than 2 characters.");
	} else {
		document.login.fname.value = first;
		wholeName = first + " " + last;
		if ( formType == "2" ) {
			if ( orgName != "unr" ) {
				document.login.nameB.value = wholeName;
			}
		} else {
			document.login.nameS.value = wholeName;
		}
	}
}

function chkEmail() {
        formType=document.login.formType.value
        orgName=document.login.orgName.value
	email = document.login.email.value;
	//email = email.toLowerCase();
	//email = document.login.email.value;
	if ( email.length < 3 ) {
		formError = "true"
		window.alert("The Email field is less than 3 characters.");
	}
	if ( orgName == "murdock" && formType == "2" ) {
		document.login.emailB.value = document.login.email.value;
		document.login.emailS.value = document.login.email.value;
	}
	if ( orgName == "csu" && formType == "2" ) {
		document.login.emailB.value = document.login.email.value;
		document.login.emailS.value = document.login.email.value;
	}
	if ( orgName == "tocore" && formType == "2" ) {
		document.login.emailB.value = document.login.email.value;
	}
	if ( orgName == "genewiz" && formType == "2" ) {
		document.login.emailB.value = document.login.email.value;
		document.login.newUser.value = document.login.email.value;
	}
	if ( orgName == "roswell" && formType == "5" ) {
		document.login.emailS.value = document.login.email.value;
	}
	if ( orgName == "harvard" && formType == "5" ) {
		document.login.emailS.value = document.login.email.value;
	}
	if ( orgName == "derc" && formType == "5" ) {
		document.login.emailS.value = document.login.email.value;
	}
	if ( orgName == "utmem" && formType == "5" ) {
		document.login.emailS.value = document.login.email.value;
	}
	if ( orgName == "laragen" && formType == "5" ) {
		document.login.emailS.value = document.login.email.value;
	}
	if ( orgName == "reno" && formType == "5" ) {
		document.login.emailS.value = document.login.email.value;
	}
	if ( orgName == "osu" ) {
		document.login.emailB.value = document.login.email.value;
	}
}

function chkLogin() {
	orgName = document.login.orgName.value;


	newUser = document.login.newUser.value;
	if ( orgName != "derc" ) {
		newUser = newUser.toLowerCase();
	}
	document.login.newUser.value = newUser;

	if ( newUser.length < 2 ) {
		formError = "true"
		window.alert("The Login Name is less than 2 characters.");
	}

	if ( orgName == "dow" ) {
		document.login.piUID.value = newUser;
	}

	if ( orgName == "sequetech" ) {
		document.login.email.value = newUser;
		//chkLogin2();
	}
}


function chkLogin2() {

	newUser = document.login.newUser.value;
	newUser2 = document.login.newUser2.value;
	if ( newUser != newUser2 ) {
		formError = "true"
		window.alert("The two Login Names DO NOT match.");
	}

}

function chkPass1() {
	pass1 = document.login.pass1.value;
	if ( pass1.length < 6 ) {
		//formError = "true"
		window.alert("The password is less than 6 characters.");
	}
}

function chkPassword() {
	pass1 = document.login.pass1.value;
	pass2 = document.login.pass2.value;
	if ( pass1 != pass2 ) {
		window.alert("The two passwords are not the same:\n"
		+ pass1
		+ "\n"
		+ pass2);
	} else {
		if ( pass2.length < 6 ) {
			//formError = "true"
			window.alert("The password is less than 6 characters.");
		}
		document.login.startup.value = pass2;
	}
}

function chkPassword2() {
	var passError = "false";
	pass1 = document.login.pass1.value;
	pass2 = document.login.pass2.value;
	if ( pass1 != pass2 ) {
		passError = "true";
		window.alert("The two passwords are not the same:\n"
		+ pass1
		+ "\n"
		+ pass2);
	} else {
		document.login.startup.value = pass2;
	}
	return passError;
}

function chkDept() {
	deptS = document.login.deptS.value;
        orgName=document.login.orgName.value
        formType=document.login.formType.value

	if ( orgName == "mit" ) {
		if ( deptS.length < 1 ) {
			window.alert("Please enter a Deptment Name.");
		}
	} else {
		if ( formType != "2" ) {
			if ( deptS.length < 3 ) {
				window.alert("The Dept field is less than 3 characters.");
			}
		}
	}
}
function chkDeptB() {
	deptB = document.login.deptB.value;
        formType=document.login.formType.value
		if ( formType != "2" ) {
		if ( deptB.length < 2 ) {
			window.alert("The Dept field is less than 3 characters.");
		}
	}
}

function chkPhone() {
	phoneRetVal = true;
	phoneS = document.login.phoneS.value;
	if ( phoneS.length < 3 ) {
		window.alert("The Phone field is less than 3 characters.");
	}
	phoneRetVal = isAPhone(phoneS);
	if ( phoneRetVal == false ) {
		window.alert("The Phone field has an error.");
		formError = "true"
	}
}
function chkPhoneB() {
	phoneRetVal = true;
	phoneB = document.login.phoneB.value;
	if ( phoneB.length < 3 ) {
		window.alert("The Phone field is less than 3 characters.");
	}
	phoneRetVal = isAPhone(phoneB);
	if ( phoneRetVal == false ) {
		window.alert("The Phone field has an error.");
		formError = "true"
	}
}

function chkPi() {
	pi = document.login.pi.value;
	if ( pi.length < 2 ) {
		window.alert("The PI field is less than 2 characters.");
	}
}

function chkPi2() {
	pi = document.login.pi.value;
	if ( pi.length < 3 ) {
		window.alert("The PI field is less than 3 characters.");
	}
}



function chkPiUtx() {
	pi = document.login.pi.value;

        if (pi) {
                aCharExists=1
                for (var i=0; i<pi.length; i++){
                        if (pi.charAt(i) == ",") {
                                aCharExists=0
                        }
                }
        }

	//window.alert("aCharExists and pi, " + aCharExists + " " + pi );

	if ( pi.length < 2 ) {
		window.alert("Please enter a PI Name. Format:  Last, First");

	} else {
		if ( aCharExists == 0 ) {
			piName = pi.split(",");
			pf = piName[0];
			pl = piName[1];
			if ( pf.length < 2 ) {
				window.alert("Please enter a Valid PI Last Name. Format: Last, First");
			}
			if ( pl.length < 2 ) {
				window.alert("Please enter a Valid PI First Name. Format: Last, First");
			}
		} else {
			window.alert("Please separate the PI Name with a comma. Format:  Last, First");
		}
	}
}




function chkSite() {
	instS = document.login.instS.value;
	if ( instS.length < 3 ) {
		window.alert("The Site field is less than 3 characters.");
	}
}

function chkBldg() {
	streetS = document.login.streetS.value;
	if ( streetS.length < 3 ) {
		window.alert("The Bldg field is less than 3 characters.");
	}
}

function chkRoom() {
	streetS2 = document.login.streetS2.value;
	if ( streetS2.length < 3 ) {
		window.alert("The Room field is less than 3 characters.");
	}
}


function chkInst() {
	instS = document.login.instS.value;
	if ( instS.length < 3 ) {
		window.alert("The Institution field has an error.");
	}
}
function chkInstB() {
	instB = document.login.instB.value;
	if ( instB.length < 3 ) {
		window.alert("The Institution field has an error.");
	}
}

function chkStreet() {
	streetS = document.login.streetS.value;
	if ( streetS.length < 3 ) {
		window.alert("The Address-1 field has an error.");
	}
}
function chkStreetB() {
	streetB = document.login.streetB.value;
	if ( streetB.length < 3 ) {
		window.alert("The Address-1 field has an error.");
	}
}

function chkCity() {
	cityS = document.login.cityS.value;
	if ( cityS.length < 2 ) {
		window.alert("The City field has an error.");
	}
}
function chkCityB() {
	cityB = document.login.cityB.value;
	if ( cityB.length < 2 ) {
		window.alert("The City field has an error.");
	}
}

function chkState() {
	stateS = document.login.stateS.value;
	if ( stateS.length < 2 ) {
		window.alert("The State field has an error.");
	}
}
function chkStateB() {
	stateB = document.login.stateB.value;
	if ( stateB.length < 2 ) {
		window.alert("The State field has an error.");
	}
}

function chkZip() {
	zipS = document.login.zipS.value;
	if ( zipS.length < 4 ) {
		window.alert("The Zip field has an error.");
	}
}
function chkZipB() {
	zipB = document.login.zipB.value;
	if ( zipB.length < 4 ) {
		window.alert("The Zip field has an error.");
	}
}

function chkPiEmail() {
	piemail = document.login.piemail.value;
	if ( piemail.length < 3 ) {
		window.alert("The PI Email field has an error.");
	}
}

function chkPiid() {
	piid = document.login.piid.value;
	if ( piid.length < 5 ) {
		window.alert("The Client_ID field has an error.");
	}
}


// sloan
function chkCC() {
	var formError = "false";
	costCenter = document.login.costCenter.value;

	if ( costCenter.length == 4 ) {
		modCC = costCenter + "0";
		document.login.costCenter.value=modCC;
	}

	if (( costCenter.length < 4 || costCenter.length > 5 ) && ( costCenter != 516 )) {
		formError = "true";
		window.alert("Error, The Cost Center Number Requires Five Digits.");
	}

	if ( costCenter == 516 ) {
		modCC = "0" + costCenter + "0";
		document.login.costCenter.value=modCC;
	}
	return formError;
}

function chkOrg() {
	var selectIndex = document.login.oncampus.selectedIndex;
	var oncampus = document.login.oncampus.options[selectIndex].value;

	if ( oncampus == "Other" ) {
		first = document.login.fname.value;
		last = document.login.lname.value;

		first = first.toLowerCase();
		last = last.toLowerCase();
		wholeName = last +", " + first;

		document.login.pi.value = wholeName;
	}
}


function makeSloan() {
	var formError = "false";
	orgName = document.login.orgName.value;

	first = document.login.fname.value;
	last = document.login.lname.value;

	first = first.toLowerCase();
	last = last.toLowerCase();

	// get first initial
	fn = first.charAt(0);

	if ( last.length <= 7 ) {
		wholeName = last + fn;
	}
	if ( last.length > 7 ) {
		// get first 7 characters of last name
		partName = "";
                for (var i=0; i<7; i++){
			pn = last.charAt(i);
			partName = partName + pn;
                }
		wholeName = partName + fn;
	}

	document.login.newUser.value = wholeName;
}





function doCopy() {
    document.login.nameB.value = document.login.nameS.value;
    document.login.instB.value = document.login.instS.value;
    document.login.deptB.value = document.login.deptS.value;
    document.login.streetB.value = document.login.streetS.value;
    document.login.streetB2.value = document.login.streetS2.value;
    document.login.cityB.value = document.login.cityS.value;
    document.login.stateB.value = document.login.stateS.value;
    document.login.zipB.value = document.login.zipS.value;
    document.login.phoneB.value = document.login.phoneS.value;
    document.login.faxB.value = document.login.faxS.value;
    document.login.emailB.value = document.login.emailS.value;
}

function doCopyB() {
    document.login.nameS.value = document.login.nameB.value;
    document.login.instS.value = document.login.instB.value;
    document.login.deptS.value = document.login.deptB.value;
    document.login.streetS.value = document.login.streetB.value;
    document.login.streetS2.value = document.login.streetB2.value;
    document.login.cityS.value = document.login.cityB.value;
    document.login.stateS.value = document.login.stateB.value;
    document.login.zipS.value = document.login.zipB.value;
    document.login.phoneS.value = document.login.phoneB.value;
    document.login.faxS.value = document.login.faxB.value;
    document.login.emailS.value = document.login.emailB.value;
}

function doCopy3() {
    document.login.nameB.value = document.login.nameS.value;
    document.login.deptB.value = document.login.deptS.value;
    document.login.phoneB.value = document.login.phoneS.value;
}

function doCopy4() {
    document.login.nameB.value = document.login.nameS.value;
    document.login.instB.value = document.login.instS.value;
    document.login.streetB.value = document.login.streetS.value;
    document.login.streetB2.value = document.login.streetS2.value;
    document.login.phoneB.value = document.login.phoneS.value;
    document.login.faxB.value = document.login.faxS.value;
}

function clearBillTo() {
    document.login.nameB.value = "";
    document.login.instB.value = "";
    document.login.deptB.value = "";
    document.login.streetB.value = "";
    document.login.streetB2.value = "";
    document.login.cityB.value = "";
    document.login.stateB.value = "";
    document.login.zipB.value = "";
    document.login.phoneB.value = "";
    document.login.faxB.value = "";
    document.login.emailB.value = "";
}

function clearShipTo() {
    document.login.nameS.value = "";
    document.login.instS.value = "";
    document.login.deptS.value = "";
    document.login.streetS.value = "";
    document.login.streetS2.value = "";
    document.login.cityS.value = "";
    document.login.stateS.value = "";
    document.login.zipS.value = "";
    document.login.phoneS.value = "";
    document.login.faxS.value = "";
    document.login.emailS.value = "";
}

function clearBillTo3() {
    document.login.nameB.value = "";
    document.login.deptB.value = "";
    document.login.phoneB.value = "";
}

function clearBillTo4() {
    document.login.nameB.value = "";
    document.login.instB.value = "";
    document.login.streetB.value = "";
    document.login.streetB2.value = "";
    document.login.phoneB.value = "";
    document.login.faxB.value = "";
}

function verify() {
	//var errfound = true
	var errFound = true;
	var fError = "false";
	var lError = "false";
	var passVal = "false";
	var formError = "false";
        formType=document.login.formType.value
        orgName=document.login.orgName.value

	//makeName();

        aCharExists=0
        aCharExists2=0
        entry=document.login.fname.value
        entry2=document.login.lname.value
        if (entry) {
                aCharExists=1
                for (var i=0; i<entry.length; i++){
                        if ((entry.charAt(i) == " ")||
                        (entry.charAt(i) == "!")||
                        (entry.charAt(i) == "@")||
                        (entry.charAt(i) == "#")||
                        (entry.charAt(i) == "\$")||
                        (entry.charAt(i) == "%")||
                        (entry.charAt(i) == "^")||
                        (entry.charAt(i) == "&")||
                        (entry.charAt(i) == "*")||
                        (entry.charAt(i) == "(")||
                        (entry.charAt(i) == ")")||
                        (entry.charAt(i) == "=")||
                        (entry.charAt(i) == "|")||
                        (entry.charAt(i) == " ")||
                        (entry.charAt(i) == "-")||
                        (entry.charAt(i) == "'")||
                        (entry.charAt(i) == "\\")||
                        (entry.charAt(i) == "`")||
                        (entry.charAt(i) == "~")||
                        (entry.charAt(i) == ":")||
                        (entry.charAt(i) == ";")||
                        (entry.charAt(i) == "<")||
                        (entry.charAt(i) == ">")||
                        (entry.charAt(i) == ",")||
                        (entry.charAt(i) == "?")||
                        (entry.charAt(i) == "/")) {
                                aCharExists=0
                        }
                }
        }
        if (entry2) {
                aCharExists2=1
                for (var i=0; i<entry2.length; i++){
                        if ((entry2.charAt(i) == " ")||
                        (entry2.charAt(i) == "!")||
                        (entry2.charAt(i) == "@")||
                        (entry2.charAt(i) == "#")||
                        (entry.charAt(i) == "\$")||
                        (entry2.charAt(i) == "%")||
                        (entry2.charAt(i) == "^")||
                        (entry2.charAt(i) == "&")||
                        (entry2.charAt(i) == "*")||
                        (entry2.charAt(i) == "(")||
                        (entry2.charAt(i) == ")")||
                        (entry2.charAt(i) == "=")||
                        (entry2.charAt(i) == "|")||
                        (entry.charAt(i) == " ")||
                        (entry.charAt(i) == "-")||
                        (entry.charAt(i) == "'")||
                        (entry2.charAt(i) == "\\")||
                        (entry2.charAt(i) == "`")||
                        (entry2.charAt(i) == "~")||
                        (entry2.charAt(i) == ":")||
                        (entry2.charAt(i) == ";")||
                        (entry2.charAt(i) == "<")||
                        (entry2.charAt(i) == ">")||
                        (entry2.charAt(i) == ".")||
                        (entry2.charAt(i) == ",")||
                        (entry2.charAt(i) == "?")||
                        (entry2.charAt(i) == "/")) {
                                aCharExists2=0
                        }
                }
        }
        if (!aCharExists2) {
	window.alert("Please do not use spaces and invalid characters in the Last Name.")
		lError = "true";
        }
        if (!aCharExists) {
	window.alert("Please do not use spaces and invalid characters in the First Name.")
		fError = "true";
        }

	formError = chkFormType(formType);
	//window.alert("formError is " + formError);
	//window.alert("formType is " + formType);

	passVal = chkPassword2();

	if (( passVal == "true" )||
	    (fError == "true") ||
	    (formError == "true") ||
	    (lError == "true")) {

		errFound = false;
	}
	//window.alert(errFound);

	if ( errFound == true ) {

		var msg = "Necessary Fields are filled in.";

        	if ( ! (confirm (msg))) {
			errFound = false;
        	} else {
			errFound = true;
        	}
	}

	return errFound;
}//end of verify

function chkFormType2(formVal) {
	//var formVal;
	var formError;
	formError = chkFormType(formVal);
	//window.alert("formType is " + formVal);
	if ( formError == "false" ) {
		window.alert("Necessary Fields are filled in.");
	} else {
		window.alert("All fields are NOT filled in.");
	}

}

function chkFormType(formVal) {
	//var formVal;
	var formError = "false";
	var chkError = "false";
	nameRetVal = true;
	deptRetVal = true;
	phoneRetVal = true;

	instRetVal = true;
	bldgRetVal = true;
	roomRetVal = true;
	faxRetVal = true;
	piRetVal = true;

	instVal = true;
	streetVal = true;
	cityVal = true;
	stateVal = true;
	zipVal = true;
	piVal = true;
	piemailVal = true;
	emailVal = true;
	piidVal = true;
	oncampusVal = true;
	orgName = document.login.orgName.value;

	//window.alert("length" + " " + deptS.length);

	//validate the Login Info

		newUser = document.login.newUser.value;
		pass1 = document.login.pass1.value;
		pass2 = document.login.pass2.value;
		email = document.login.email.value;
		if ( email.length < 3 ) {
			formError = "true"
			//window.alert("The Email field is less than 3 characters.");
		}
		if ( newUser.length < 2 ) {
			formError = "true"
			//window.alert("The Login Name is less than 2 characters.");
			//break;
		}

		if ( orgName == "sequetech" ) {
			chkLogin2();
		}

		if ( pass1.length < 6 ) {
			formError = "true"
			//window.alert("The Password is less than 6 characters.");
		}
		if ( pass2.length < 6 ) {
			formError = "true"
			//window.alert("The Password is less than 6 characters.");
		}
		email = document.login.email.value;
		emailVal = isAString2(email);
		newUser = document.login.newUser.value;

		//isAString2 allows @ in name
		newUserVal = isAString2(newUser);

		pass1 = document.login.pass1.value;
		pass1Val = isASpace(pass1);
		pass2 = document.login.pass2.value;
		pass2Val = isASpace(pass2);
		if ( emailVal == false ) {
			window.alert("The Email field has an error.");
			formError = "true"
		}
		if ( newUserVal == false ) {
			window.alert("The Login Name field has an error.");
			formError = "true"
		}
		if ( pass1Val == false ) {
			//window.alert("The Password Name field has an error.");
			formError = "true"
		}
		if ( pass2Val == false ) {
			//window.alert("The Password-2 Name field has an error.");
			formError = "true"
		}
	//end of validate the Login Info

	//only test formTypes if the login info is error free
	if ( formError  == "false" ) {

	if ( formVal  == 3 ) {

		nameS = document.login.nameS.value;
		deptS = document.login.deptS.value;
		phoneS = document.login.phoneS.value;
		pi = document.login.pi.value;


		if ( nameS.length < 5 ) {
			formError = "true"
			chkError = "true"
			window.alert("The Name field has less than five characters.");
		}
		if ( deptS.length < 3 ) {
			formError = "true"
			chkError = "true"
			window.alert("The Department field has less than three characters.");
		}
		if ( phoneS.length < 3 ) {
			formError = "true"
			chkError = "true"
			window.alert("The Phone field has less than three characters.");
		}

		if ( orgName == "utx" ) {
			//chkPiUtx();

			pi = document.login.pi.value;

			 if (pi) {
			         aCharExists=1
			         for (var i=0; i<pi.length; i++){
			                 if (pi.charAt(i) == ",") {
			                         aCharExists=0
			                        }
			         }
			 }

			//window.alert("aCharExists and pi, " + aCharExists + " " + pi );

			if ( pi.length < 2 ) {
				window.alert("Please enter a PI Name. Format:  Last, First");

			} else {
				if ( aCharExists == 0 ) {
					piName = pi.split(",");
					pf = piName[0];
					pl = piName[1];
					if ( pf.length < 2 ) {
						formError = "true"
						chkError = "true"
						window.alert("Please enter a Valid PI Last Name. Format: Last, First");
					}
					if ( pl.length < 2 ) {
						formError = "true"
						chkError = "true"
						window.alert("Please enter a Valid PI First Name. Format: Last, First");
					}
				} else {
					formError = "true"
					chkError = "true"
					window.alert("Please separate the PI Name with a comma. Format:  Last, First");
				}
			}


		} else {
			if ( pi.length < 2 ) {
				formError = "true"
				chkError = "true"
				window.alert("The PI field has less than two characters.");
			}
		}

		if ( chkError  == "false" ) {
	    		nameVal = document.login.nameS.value;
			nameRetVal = isAString(nameVal);

    			deptVal = document.login.deptS.value;
			deptRetVal = isAString(deptVal);

    			phoneVal = document.login.phoneS.value;
			phoneRetVal = isAPhone(phoneVal);

    			piVal = document.login.pi.value;
			piRetVal = isAString(piVal);


			if ( nameRetVal == false ) {
				formError = "true"
			}
			if ( deptRetVal == false ) {
				window.alert("The Department field has an error.");
				formError = "true"
			}
			if ( phoneRetVal == false ) {
				window.alert("The Phone field has an error.");
				formError = "true"
			}
			if ( piRetVal == false ) {
				window.alert("The PI field has an error.");
				formError = "true"
			}
		}//end of chkError is false
	}//end of formType3

	if ( formVal  == 6 ) {
		nameS = document.login.nameS.value;
		deptS = document.login.deptS.value;
		phoneS = document.login.phoneS.value;

		if ( nameS.length < 5 ) {
			formError = "true"
			chkError = "true"
			window.alert("The Name field has less than five characters.");
		}
		if ( deptS.length < 3 ) {
			formError = "true"
			chkError = "true"
			window.alert("The Department field has less than three characters.");
		}
		if ( phoneS.length < 3 ) {
			formError = "true"
			chkError = "true"
			window.alert("The Phone field has less than three characters.");
		}

		if ( chkError  == "false" ) {
	    		nameVal = document.login.nameS.value;
			nameRetVal = isAString(nameVal);
    			deptVal = document.login.deptS.value;
			deptRetVal = isAString(deptVal);
    			phoneVal = document.login.phoneS.value;
			phoneRetVal = isAPhone(phoneVal);
			if ( nameRetVal == false ) {
				window.alert("The Name field has an error.");
				formError = "true"
			}
			if ( deptRetVal == false ) {
				window.alert("The Dept field has an error.");
				formError = "true"
			}
			if ( phoneRetVal == false ) {
				window.alert("The Phone field has an error.");
				formError = "true"
			}
		}//end of chkError is false
	}//end of formType6

	if ( formVal  == 4 ) {
		nameS = document.login.nameS.value;
		deptS = document.login.deptS.value;
		phoneS = document.login.phoneS.value;

		instS = document.login.instS.value;
		streetS = document.login.streetS.value;
		streetS2 = document.login.streetS2.value;
		faxS = document.login.faxS.value;
		pi = document.login.pi.value;

		if ( nameS.length < 5 ) {
			formError = "true"
			chkError = "true"
			window.alert("The Name field has less than five characters.");
		}
		if ( deptS.length < 3 ) {
			formError = "true"
			chkError = "true"
			window.alert("The Department field has less than three characters.");
		}
		if ( instS.length < 3 ) {
			formError = "true"
			chkError = "true"
			window.alert("The Site Location field has less than three characters.");
		}
		if ( streetS.length < 3 ) {
			formError = "true"
			chkError = "true"
			window.alert("The Bldg field has less than three characters.");
		}
		if ( streetS2.length < 3 ) {
			formError = "true"
			chkError = "true"
			window.alert("The Room field has less than three characters.");
		}
		if ( phoneS.length < 3 ) {
			formError = "true"
			chkError = "true"
			window.alert("The Phone field has less than three characters.");
		}
		//if ( faxS.length < 3 ) {
		//	formError = "true"
		//	window.alert("The FAX field has an error.");
		//}
		if ( pi.length < 2 ) {
			formError = "true"
			chkError = "true"
			window.alert("The PI field has less than two characters.");
		}

		if ( chkError  == "false" ) {
	    		nameVal = document.login.nameS.value;
			nameRetVal = isAString(nameVal);

    			deptVal = document.login.deptS.value;
			deptRetVal = isAString(deptVal);

    			phoneVal = document.login.phoneS.value;
			phoneRetVal = isAPhone(phoneVal);

    			instS = document.login.instS.value;
			instVal = isAString(instS);

    			bldgVal = document.login.streetS.value;
			bldgRetVal = isAString(bldgVal);

    			roomVal = document.login.streetS2.value;
			roomRetVal = isAString(roomVal);

			if ( faxS.length > 0 ) {
    				faxVal = document.login.faxS.value;
				faxRetVal = isAPhone(faxVal);
			}

    			piVal = document.login.pi.value;
			piRetVal = isAString(piVal);

			if ( nameRetVal == false ) {
				window.alert("The Name field has an error.");
				formError = "true"
			}
			if ( deptRetVal == false ) {
				window.alert("The Dept field has an error.");
				formError = "true"
			}
			if ( phoneRetVal == false ) {
				window.alert("The Phone field has an error.");
				formError = "true"
			}
			if ( instRetVal == false ) {
				window.alert("The Inst field has an error.");
				formError = "true"
			}
			if ( bldgRetVal == false ) {
				window.alert("The Bldg field has an error.");
				formError = "true"
			}
			if ( roomRetVal == false ) {
				window.alert("The Room field has an error.");
				formError = "true"
			}
			if ( faxRetVal == false ) {
				window.alert("The FAX field has an error.");
				formError = "true"
			}
			if ( piRetVal == false ) {
				window.alert("The PI field has an error.");
				formError = "true"
			}
		}//end of chkError is false
	}//end of formType4

	// harvard janson utmem
	if ( formVal  == 5 ) {
		orgName = document.login.orgName.value;
		//window.alert("fromVal 5 " +  orgName);

		nameS = document.login.nameS.value;
		deptS = document.login.deptS.value;
		phoneS = document.login.phoneS.value;

		instS = document.login.instS.value;
		pi = document.login.pi.value;
		piemail = document.login.piemail.value;
		streetS = document.login.streetS.value;
		cityS = document.login.cityS.value;
		stateS = document.login.stateS.value;
		zipS = document.login.zipS.value;
		oncampus = document.login.oncampus.value;
		//piid = document.login.piid.value;

	var selectIndex = document.login.oncampus.selectedIndex;
	var selectText = document.login.oncampus.options[selectIndex].value;
		if ( selectText == "Invalid" ) {
			window.alert("The Affiliation field has an error.");
			formError = "true"
		}

		if ( nameS.length < 5 ) {
			formError = "true"
			chkError = "true"
			window.alert("The Name field has less than five characters.");
		}
		if ( instS.length < 3 ) {
			formError = "true"
			chkError = "true"
			window.alert("The Institution field has less than three characters.");
		}
		if ( deptS.length < 3 ) {
			formError = "true"
			chkError = "true"
			window.alert("The Department field has less than three characters.");
		}
		if ( streetS.length < 3 ) {
			formError = "true"
			chkError = "true"
			window.alert("The Address-1 field has less than three characters.");
		}
		if ( cityS.length < 2 ) {
			formError = "true"
			chkError = "true"
			window.alert("The City field has less than two characters.");
		}
		if ( stateS.length < 2 ) {
			formError = "true"
			chkError = "true"
			window.alert("The State field has less than two characters.");
		}
		if ( zipS.length < 4 ) {
			formError = "true"
			chkError = "true"
			window.alert("The Zip field has less than four characters.");
		}
		if ( phoneS.length < 3 ) {
			formError = "true"
			chkError = "true"
			window.alert("The Phone field has less than three characters.");
		}
		if ( pi.length < 3 ) {
			formError = "true"
			chkError = "true"
			window.alert("The PI field has less than three characters.");
		}
		if ( piemail.length < 3 ) {
			formError = "true"
			chkError = "true"
			window.alert("The PI Email has less than three characters.");
		}
		//if ( piid.length < 3 ) {
		//	formError = "true"
		//	chkError = "true"
		//	window.alert("The Client_ID Email has less than three characters.");
		//}

		if ( orgName == "utmem" ) {
			if ( selectText == "on_campus" ) {

				piName = document.login.pi.value;
				piEmail = document.login.piemail.value;

				if ( piName == "Off_Campus" || piEmail == "Off_Campus" ) {
					window.alert("Please enter a PI name and email address.");
					formError = "true"
				}
			}

		}

		if ( orgName == "harvard" ) {
			//window.alert("janson fromVal 5 " +  orgName);

			Index=document.login.idVal.options.selectedIndex;
			pif = document.login.idVal.options[Index].value;
        
			vals = pif.split("_");
			first = vals[1];
			last = vals[2];

			firstLast =first + " " + last;
			piName = document.login.pi.value;

			if ( firstLast != piName ) {
				formError = "true";
				chkError = "true";
				window.alert("The PI text box name " + piName + " does not match the PI List Name "  + firstLast);
			}

		}


		if ( chkError  == "false" ) {
			streetVal = isAString(streetS);
			cityVal = isAString(cityS);
			stateVal = isAString(stateS);
			zipVal = isAString(zipS);
			piVal = isAString(pi);
			piemailVal = isAString2(piemail);
			//piidVal = isAString2(piid);

    			nameVal = document.login.nameS.value;
			nameRetVal = isAString(nameVal);

    			deptVal = document.login.deptS.value;
			deptRetVal = isAString(deptVal);

    			phoneVal = document.login.phoneS.value;
			phoneRetVal = isAPhone(phoneVal);

    			instS = document.login.instS.value;
			instVal = isAString(instS);

			if ( nameRetVal == false ) {
				window.alert("The Name field has an error.");
				formError = "true"
			}
			if ( deptRetVal == false ) {
				window.alert("The Dept field has an error.");
				formError = "true"
			}
			if ( phoneRetVal == false ) {
				window.alert("The Phone field has an error.");
				formError = "true"
			}

			if ( instVal == false ) {
				window.alert("The Institution field has an error.");
				formError = "true"
			}

			if ( streetVal == false ) {
				window.alert("The Address-1 field has an error.");
				formError = "true"
			}
			if ( cityVal == false ) {
				window.alert("The City field has an error.");
				formError = "true"
			}
			if ( stateVal == false ) {
				window.alert("The State field has an error.");
				formError = "true"
			}
			if ( zipVal == false ) {
				window.alert("The Zip field has an error.");
				formError = "true"
			}
			if ( piVal == false ) {
				window.alert("The PI field has an error.");
				formError = "true"
			}
			if ( piemailVal == false ) {
				window.alert("The PI Email field has an error.");
				formError = "true"
			}
			//if ( piidVal == false ) {
			//	window.alert("The Client_ID field has an error.");
			//	formError = "true"
			//}
		}//end of chkError is false
	}//end of formType5

	// sloan
	if ( formVal  == 7 ) {
		orgName=document.login.orgName.value;
		if ( orgName == "uchsc" ) {
			speedNum=document.login.speedNum.value;
			speed=document.login.speed.value;
			oncampus=document.login.oncampus.value;
			if ( speedNum != speed ) {
				formError = "true"
				chkError = "true"
window.alert("The Speed Type does not match the PI.\n"
+ "If the PI is listed multiple times, try selecting the other listing.");
			} else {
				//window.alert("The Speed Type matches the PI.");
			}

			if (( oncampus == "UCHSC" ) && (speed == "Industry" )) {
				formError = "true"
				chkError = "true"
				window.alert("The Speed Type is incorrect, please re-select a PI.");
			}
			if (( oncampus == "UCHSC" ) && (speed == "Other-Campus" )) {
				formError = "true"
				chkError = "true"
				window.alert("The Speed Type is incorrect, please re-select a PI.");
			}

		}//end of uchsc


		if ( orgName == "derc" ) {
			speedNum=document.login.speedNum.value;
			speed=document.login.speed.value;
			oncampus=document.login.oncampus.value;

			if (( oncampus == "UCHSC" || oncampus == "DERC" ) && (speed == "Other" )) {
				formError = "true"
				chkError = "true"
				window.alert("The PI is incorrect, please re-select a PI.");
			}

		}//end of derc




		nameS = document.login.nameS.value;
		deptS = document.login.deptS.value;
		phoneS = document.login.phoneS.value;

		streetS = document.login.streetS.value;
		streetS2 = document.login.streetS2.value;
		faxS = document.login.faxS.value;
		pi = document.login.pi.value;

if ( orgName != "uchsc" ) {
	var selectIndex = document.login.oncampus.selectedIndex;
	var oncampus = document.login.oncampus.options[selectIndex].value;
}

		if ( orgName == "sloan" ) {
			if ( oncampus == "on_campus" ) {
				ccError = "false"
				ccError = chkCC();
				if ( ccError == "true" ) {
					window.alert("The Cost Center field has an error.");
					formError = "true"
				}
			}
			if ( oncampus == "Other" ) {
				document.login.costCenter.value="na";
			}

		}

		//umdnj

		if ( nameS.length < 5 ) {
			formError = "true"
			chkError = "true"
			window.alert("The Name field has less than five characters.");
		}
		if ( orgName != "uchsc" ) {
			if ( orgName == "mit" ) {
				if ( deptS.length < 1 ) {
					formError = "true"
					chkError = "true"
					window.alert("Please enter a Department name.");
				}
			} else {
				if ( deptS.length < 3 ) {
					formError = "true"
					chkError = "true"
					window.alert("The Department field has less than three characters.");
				}
			}
		}
		if ( oncampus == "Invalid" ) {
			formError = "true"
			chkError = "true"
			window.alert("The Site Location field has an error.");
		}
		if ( phoneS.length < 3 ) {
			formError = "true"
			chkError = "true"
			window.alert("The Phone field has less than three characters.");
		}
		if ( pi.length < 2 ) {
			formError = "true"
			chkError = "true"
			window.alert("The PI field has less than two characters.");
		}
		if ( pi == "undefined" ) {
			formError = "true"
			chkError = "true"
			window.alert("The PI field has an undefined value.");
		}

		if ( chkError  == "false" ) {

			if ( streetS.length > 0 ) {
    				bldgVal = document.login.streetS.value;
				bldgRetVal = isAString(bldgVal);
			}

			if ( streetS2.length > 0 ) {
    				roomVal = document.login.streetS2.value;
				roomRetVal = isAString(roomVal);
			}

			if ( faxS.length > 0 ) {
    				faxVal = document.login.faxS.value;
				faxRetVal = isAPhone(faxVal);
			}

    			nameVal = document.login.nameS.value;
			nameRetVal = isAString(nameVal);

			if ( orgName != "uchsc" ) {
    				deptVal = document.login.deptS.value;
				deptRetVal = isAString(deptVal);
			}

    			phoneVal = document.login.phoneS.value;
			phoneRetVal = isAPhone(phoneVal);

    			piVal = document.login.pi.value;
			piRetVal = isAString(piVal);

			if ( nameRetVal == false ) {
				window.alert("The Name field has an error.");
				formError = "true"
			}
			if ( deptRetVal == false ) {
				window.alert("The Dept field has an error.");
				formError = "true"
			}
			if ( phoneRetVal == false ) {
				window.alert("The Phone field has an error.");
				formError = "true"
			}
			if ( bldgRetVal == false ) {
				window.alert("The Bldg field has an error.");
				formError = "true"
			}
			if ( roomRetVal == false ) {
				window.alert("The Room field has an error.");
				formError = "true"
			}
			if ( faxRetVal == false ) {
				window.alert("The FAX field has an error.");
				formError = "true"
			}
			if ( piRetVal == false ) {
				window.alert("The PI field has an error.");
				formError = "true"
			}
		}//end of chkError is false
	}//end of formType7

	if ( formVal  == 2 ) {
		//tufts jlt2
		//window.alert("In chkForm");
		//window.alert("orgName " + orgName);
		//orgName = document.login.orgName.value;

		nameB = document.login.nameB.value;
		instB = document.login.instB.value;
		deptB = document.login.deptB.value;
		streetB = document.login.streetB.value;
		streetB2 = document.login.streetB2.value;
		cityB = document.login.cityB.value;
		stateB = document.login.stateB.value;
		zipB = document.login.zipB.value;
		phoneB = document.login.phoneB.value;
		emailB = document.login.emailB.value;

		nameS = document.login.nameS.value;
		instS = document.login.instS.value;
		streetS = document.login.streetS.value;
		cityS = document.login.cityS.value;
		stateS = document.login.stateS.value;
		zipS = document.login.zipS.value;
		phoneS = document.login.phoneS.value;
		emailS = document.login.emailS.value;




		if ( orgName != "tocore" && orgName != "sequetech" && orgName != "uchsc" ) {
			pi = document.login.pi.value;
			//oncampus = document.login.oncampus.value;

			var selectIndex = document.login.oncampus.selectedIndex;
			var oncampus = document.login.oncampus.options[selectIndex].value;
			if ( oncampus == "Invalid" ) {
				window.alert("The Bill-to Affiliation field has an error.");
				formError = "true"
			}
		}

		if ( orgName == "uchsc" ) {
			oncampus=document.login.oncampus.value;
			pi = document.login.pi.value;
			//window.alert("PI " + pi + " oncampus " + oncampus );
		}

		if ( nameB.length < 5 ) {
			formError = "true"
			chkError = "true"
			window.alert("The Name Bill-to field has less than five characters.");
		}

		if ( orgName == "tufts" ) {

			if ( oncampus == "Tufts" || oncampus == "NEMC" ) {
				if ( pi.length < 2 ) {
					formError = "true"
					chkError = "true"
					window.alert("The PI field has less than three characters.");
				}
				if ( phoneB.length < 3 ) {
					formError = "true"
					chkError = "true"
					window.alert("The Bill-to Phone field has less than three characters.");
				}
				if ( emailB.length < 3 ) {
					formError = "true"
					chkError = "true"
					window.alert("The Bill-to Email has less than three characters.");
				}
			}

			if ( oncampus == "NEMC" ) {
				if ( deptB.length < 3 ) {
					formError = "true"
					chkError = "true"
					window.alert("The Bill-to Dept field has less than three characters.");
				}
				if ( streetB2.length < 1 ) {
					formError = "true"
					chkError = "true"
					window.alert("The Addr 2/Box field has less than three characters.");
				}
			}

		} else {


		if ( instB.length < 3 ) {
			formError = "true"
			chkError = "true"
			window.alert("The Bill-to Institution field has less than three characters.");
		}

		if ( orgName != "tocore" && orgName != "uchsc" && orgName != "ucalgary" && orgName != "unr" && orgName != "sequetech" && orgName != "tufts" && orgName != "genewiz" ) {
			if ( deptB.length < 3 ) {
				formError = "true"
				chkError = "true"
				window.alert("The Bill-to Department field has less than three characters.");
			}
		}
		if ( streetB.length < 3 ) {
			formError = "true"
			chkError = "true"
			window.alert("The Bill-to Address-1 field has less than three characters.");
		}
		if ( cityB.length < 2 ) {
			formError = "true"
			chkError = "true"
			window.alert("The Bill-to City field has less than two characters.");
		}
		if ( stateB.length < 2 ) {
			formError = "true"
			chkError = "true"
			window.alert("The Bill-to State field has less than two characters.");
		}
		if ( zipB.length < 4 ) {
			formError = "true"
			chkError = "true"
			window.alert("The Bill-to Zip field has less than four characters.");
		}
		if ( phoneB.length < 3 && orgName != "ucalgary" && orgName != "sequetech" ) {
			formError = "true"
			chkError = "true"
			window.alert("The Bill-to Phone field has less than three characters.");
		}
		if ( orgName != "tocore" && orgName != "sequetech" ) {
			if ( pi.length < 3 ) {
				formError = "true"
				chkError = "true"
				window.alert("The PI field has less than three characters.");
			}
		}
		if ( emailB.length < 3 && orgName != "ucalgary" && orgName != "sequetech" ) {
			formError = "true"
			chkError = "true"
			window.alert("The Bill-to Email has less than three characters.");
		}

			if ( orgName == "ucalgary" ) {

				if ( nameS.length < 5 ) {
					formError = "true"
					chkError = "true"
					window.alert("The Name in the Shipping-Info field has less than five characters.");
				}

				if ( instS.length < 3 ) {
					formError = "true"
					chkError = "true"
					window.alert("The Shipping-Info Institution field has less than three characters.");
				}
				if ( streetS.length < 3 ) {
					formError = "true"
					chkError = "true"
					window.alert("The Shipping-Info Address-1 field has less than three characters.");
				}
				if ( cityS.length < 2 ) {
					formError = "true"
					chkError = "true"
					window.alert("The Shipping-Info City field has less than two characters.");
				}
				if ( stateS.length < 2 ) {
					formError = "true"
					chkError = "true"
					window.alert("The Shipping-Info State field has less than two characters.");
				}
				if ( zipS.length < 4 ) {
					formError = "true"
					chkError = "true"
					window.alert("The Shipping-Info Zip field has less than four characters.");
				}
				if ( phoneS.length < 3 ) {
					formError = "true"
					chkError = "true"
					window.alert("The Shipping-Info Phone field has less than three characters.");
				}
				if ( emailS.length < 3 ) {
					formError = "true"
					chkError = "true"
					window.alert("The Shipping-Info Email has less than three characters.");
				}
			}

			if ( orgName == "unr" ) {

				if ( nameS.length < 5 ) {
					formError = "true"
					chkError = "true"
					window.alert("The Name in the PI-Info field has less than five characters.");
				}

				if ( instS.length < 3 ) {
					formError = "true"
					chkError = "true"
					window.alert("The PI-Info Institution field has less than three characters.");
				}
				if ( streetS.length < 3 ) {
					formError = "true"
					chkError = "true"
					window.alert("The PI-Info Address-1 field has less than three characters.");
				}
				if ( cityS.length < 2 ) {
					formError = "true"
					chkError = "true"
					window.alert("The PI-Info City field has less than two characters.");
				}
				if ( stateS.length < 2 ) {
					formError = "true"
					chkError = "true"
					window.alert("The PI-Info State field has less than two characters.");
				}
				if ( zipS.length < 4 ) {
					formError = "true"
					chkError = "true"
					window.alert("The PI-Info Zip field has less than four characters.");
				}
				if ( phoneS.length < 3 ) {
					formError = "true"
					chkError = "true"
					window.alert("The PI-Info Phone field has less than three characters.");
				}
				if ( emailS.length < 3 ) {
					formError = "true"
					chkError = "true"
					window.alert("The PI-Info Email has less than three characters.");
				}

			}//end of orgName == unr

		}//end of orgName != tufts



		if ( chkError  == "false" ) {
			streetVal = isAString(streetB);
			cityVal = isAString(cityB);
			stateVal = isAString(stateB);
			zipVal = isAString(zipB);
			emailVal = isAString2(emailB);

			if ( orgName != "tocore" && orgName != "uchsc" && orgName != "sequetech" ) {
				piVal = isAString(pi);
    				deptVal = document.login.deptB.value;
				deptRetVal = isAString(deptVal);
			}
			if ( orgName == "uchsc" ) {
				piVal = isAString(pi);
			}

    			nameVal = document.login.nameB.value;
			nameRetVal = isAString(nameVal);

    			phoneVal = document.login.phoneB.value;
			phoneRetVal = isAPhone(phoneVal);

    			instB = document.login.instB.value;
			instVal = isAString(instB);

			if ( nameRetVal == false ) {
				window.alert("The Bill-to Name field has an error.");
				formError = "true"
			}

			if ( phoneRetVal == false ) {
				window.alert("The Bill-to Phone field has an error.");
				formError = "true"
			}

			if ( piVal == false ) {
				window.alert("The PI field has an error.");
				formError = "true"
			}
			if ( emailVal == false && orgName != "sequetech" ) {
				window.alert("The Bill-to Email field has an error.");
				formError = "true"
			}

		if ( orgName == "tufts" && oncampus == "Other" ) {
			if ( instVal == false ) {
				window.alert("The Bill-to Institution field has an error.");
				formError = "true"
			}

			if ( streetVal == false ) {
				window.alert("The Bill-to Address-1 field has an error.");
				formError = "true"
			}
			if ( cityVal == false ) {
				window.alert("The Bill-to City field has an error.");
				formError = "true"
			}
			if ( stateVal == false ) {
				window.alert("The Bill-to State field has an error.");
				formError = "true"
			}
			if ( zipVal == false ) {
				window.alert("The Bill-to Zip field has an error.");
				formError = "true"
			}

		}// end of orgName == tufts

		if ( oncampus != "Tufts" && oncampus !="NEMC" ) {

			if ( deptRetVal == false ) {
	if ( orgName != "genewiz" && orgName != "tufts" && orgName != "ucalgary" && orgName != "unr" ) {
				window.alert("The Dept field has an error.");
				formError = "true"
				}
			}
			if ( instVal == false ) {
				window.alert("The Institution field has an error.");
				formError = "true"
			}

			if ( streetVal == false ) {
				window.alert("The Address-1 field has an error.");
				formError = "true"
			}
			if ( cityVal == false ) {
				window.alert("The City field has an error.");
				formError = "true"
			}
			if ( stateVal == false ) {
				window.alert("The State field has an error.");
				formError = "true"
			}
			if ( zipVal == false ) {
				window.alert("The Zip field has an error.");
				formError = "true"
			}
		}// end of orgName == tufts

		}//end of chkError is false
	}//end of formType2

	}//end of formError is false

	return formError;
}//end of chkFormType

function validChar(entry) {
	nameRetVal = true;
	deptRetVal = true;
	phoneRetVal = true;

	if ( entry == "name" ) {
    		nameVal = document.login.nameS.value;
		nameRetVal = isAString(nameVal);
	}
	if ( entry == "lab" ) {
    		deptVal = document.login.deptS.value;
		deptRetVal = isAString(deptVal);
	}
	if ( entry == "phone" ) {
    		phoneVal = document.login.phoneS.value;
		phoneRetVal = isAPhone(phoneVal);
	}




	if ( nameRetVal == false ) {
		window.alert("The Name has a bad character.");
	}
	if ( deptRetVal == false ) {
		window.alert("The Deptartment Name has a bad character.");
	}
	if ( phoneRetVal == false ) {
		window.alert("The Phone Number has a bad character.");
	}
}

function isAPhone(entry) {
	//window.alert(entry);
	answer=true;
    if (entry.length == 0) {
        answer=false;
    }
    for (var i=0; i<entry.length; i++){
        if ((entry.charAt(i) != "0")&&
            (entry.charAt(i) != "1")&&
            (entry.charAt(i) != "2")&&
            (entry.charAt(i) != "3")&&
            (entry.charAt(i) != "4")&&
            (entry.charAt(i) != "5")&&
            (entry.charAt(i) != "6")&&
            (entry.charAt(i) != "7")&&
            (entry.charAt(i) != "8")&&
            (entry.charAt(i) != "9")&&
            (entry.charAt(i) != "(")&&
            (entry.charAt(i) != ")")&&
            (entry.charAt(i) != " ")&&
            (entry.charAt(i) != "-")&&
            (entry.charAt(i) != "E")&&
            (entry.charAt(i) != "e")&&
            (entry.charAt(i) != "X")&&
            (entry.charAt(i) != "x")&&
            (entry.charAt(i) != "t")) {
                answer=false;
            }
    }
    return answer;
}

function isASpace(entry) {
	//window.alert(entry);
	answer=true;
    if (entry.length == 0) {
        answer=false;
    }
    for (var i=0; i<entry.length; i++){
        if (entry.charAt(i) == " "){
                answer=false;
            }
    }
    return answer;
}



function isAString(entry) {
	//window.alert(entry);
	answer=true;
    if (entry.length == 0) {
        answer=false;
    }
    for (var i=0; i<entry.length; i++){
        if ((entry.charAt(i) == "!")||
            (entry.charAt(i) == "@")||
            (entry.charAt(i) == "#")||
            (entry.charAt(i) == "$")||
            (entry.charAt(i) == "%")||
            (entry.charAt(i) == "^")||
            (entry.charAt(i) == "&")||
            (entry.charAt(i) == "*")||
            (entry.charAt(i) == "(")||
            (entry.charAt(i) == ")")||
            (entry.charAt(i) == "=")||
            (entry.charAt(i) == ">")||
            (entry.charAt(i) == "<")||
            (entry.charAt(i) == "|")||
            (entry.charAt(i) == "\\")||
            (entry.charAt(i) == "`")||
            (entry.charAt(i) == "~")||
            (entry.charAt(i) == ":")||
            (entry.charAt(i) == ";")||
            (entry.charAt(i) == "?")||
            (entry.charAt(i) == "/")) {
                answer=false;
            }
    }
    return answer;
}

function isAString2(entry) {
	//window.alert(entry);
	answer=true;
    if (entry.length == 0) {
        answer=false;
    }
    for (var i=0; i<entry.length; i++){
        if ((entry.charAt(i) == "!")||
            (entry.charAt(i) == "#")||
            (entry.charAt(i) == "$")||
            (entry.charAt(i) == "%")||
            (entry.charAt(i) == "^")||
            (entry.charAt(i) == "&")||
            (entry.charAt(i) == "*")||
            (entry.charAt(i) == "(")||
            (entry.charAt(i) == ")")||
            (entry.charAt(i) == "=")||
            (entry.charAt(i) == ">")||
            (entry.charAt(i) == "<")||
            (entry.charAt(i) == "|")||
            (entry.charAt(i) == "\\")||
            (entry.charAt(i) == "`")||
            (entry.charAt(i) == "~")||
            (entry.charAt(i) == ":")||
            (entry.charAt(i) == ";")||
            (entry.charAt(i) == ",")||
            (entry.charAt(i) == "?")||
            (entry.charAt(i) == "/")) {
                answer=false;
            }
    }
    return answer;
}

function getPIname() {
	var selectIndex = document.login.PINAME.selectedIndex;
	var selectText = document.login.PINAME.options[selectIndex].value;

	piname = selectText.split(":");

	document.login.piemail.value = piname[0];
	document.login.pi.value = piname[1];
	document.login.piid.value = piname[2];

}

function loadPInameUtx() {
	var selectIndex = document.login.piVal.selectedIndex;
	var selectText = document.login.piVal.options[selectIndex].value;

	piname = selectText.split(":");

	document.login.pi.value = piname[0] + "," + " " + piname[1];
	document.login.deptS.value = piname[2];
	document.login.piPhone.value = piname[3];
	document.login.piemail.value = piname[4];

	document.login.oncampus.options.selectedIndex=0;

	//document.login.pi.value = selectText;
}

function loadPInameUmo() {
	var selectIndex = document.login.piVal.selectedIndex;
	var selectText = document.login.piVal.options[selectIndex].value;

	piname = selectText.split(":");

	document.login.piid.value = piname[0];
	document.login.pi.value = piname[1] + " " + piname[2];

	//document.login.pi.value = selectText;
}

function loadPInameLaragen() {
	var selectIndex = document.login.piVal.selectedIndex;
	var selectText = document.login.piVal.options[selectIndex].value;

	piname = selectText.split(":");

	document.login.piLast.value = piname[0];
	document.login.piFirst.value = piname[1];
	document.login.piemail.value = piname[2];

	document.login.pi.value = "piname[0], piname[1]";
}

function loadPInameLaragenText() {
	piFirst = document.login.piFirst.value;
	piLast = document.login.piLast.value;

        document.login.pi.value = piLast + "," + " " + piFirst;
}

function loadPInameDfci() {
	var selectIndex = document.login.piVal.selectedIndex;
	var selectText = document.login.piVal.options[selectIndex].value;

	piname = selectText.split(":");

	document.login.pi.value = piname[0];
	document.login.grantAdmin.value = piname[1];
	document.login.grantModify.value = "no";
}


function loadPInameCdc() {

        //window.alert("hi");

        var selectIndex = document.login.piVal.selectedIndex;
        var selectText = document.login.piVal.options[selectIndex].value;

        piname = selectText.split(":");

        //window.alert("last first " + piname[0] + " " + piname[1] );

        document.login.pi.value = piname[1] + "," + " " + piname[2];
        document.login.piUID.value = piname[0];
        document.login.piemail.value = piname[3];

}


function amPiReno() {

        //window.alert("hi");

	fname = document.login.fname.value;
	lname = document.login.lname.value;
	email = document.login.email.value;

        document.login.pi.value = lname + "," + " " + fname;
        document.login.piUID.value = "assign";
        document.login.piemail.value = email;

}


function amPi() {

        //window.alert("hi");

	fname = document.login.fname.value;
	lname = document.login.lname.value;
	email = document.login.email.value;

        document.login.pi.value = lname + "," + " " + fname;
        document.login.piUID.value = "assign";
        document.login.piemail.value = email;

}





function loadSpeedDerc() {
	var selectIndex = document.login.oncampus.selectedIndex;
	var selectText = document.login.oncampus.options[selectIndex].value;

	if ( selectText == "Other" ) {
		document.login.speedNum.value = "Other";
		document.login.speed.value = "Other";
		document.login.pi.value = "Other";
		document.login.piVal.options.selectedIndex=0;
	}
	if ( selectText == "Industry" ) {
		document.login.speedNum.value = "Industry";
		document.login.speed.value = "Industry";
		document.login.pi.value = "Industry";
		document.login.piVal.options.selectedIndex=0;
	}
	if ( selectText == "Other-Campus" ) {
		document.login.speedNum.value = "Other-Campus";
		document.login.speed.value = "Other-Campus";
		document.login.pi.value = "Other-Campus";
		document.login.piVal.options.selectedIndex=0;
	}

}

function loadAffiPI() {
	orgName = document.login.orgName.value;

	if ( orgName == "murdock" ) {

		var selectIndex = document.login.oncampus.selectedIndex;
		var selectText = document.login.oncampus.options[selectIndex].value;

		first = document.login.fname.value;
		last = document.login.lname.value;
		wholeName = last + " " + first;

		if ( selectText == "on_campus" ) {
			document.login.phoneS.value = "(406) 243-";
			document.login.phoneB.value = "(406) 243-";
			document.login.instB.value = "University of Montana";
			document.login.cityB.value = "Missoula";
			document.login.stateB.value = "Montana";
			document.login.zipB.value = "59812";
		}
		if ( selectText == "Off_Campus" ) {
			document.login.stateB.value = "Montana";
		}
		if ( selectText == "Other" ) {
			document.login.pi.value = wholeName;
		}
	}
}

function doDerc() {
	//window.alert("derc");

	if (document.login.dercMember[0].checked) {
		document.login.oncampus.options.selectedIndex=2;
	} else {
		document.login.oncampus.options.selectedIndex=0;
	}
}

function loadPInamederc() {
	var selectIndex = document.login.piVal.selectedIndex;
	var selectText = document.login.piVal.options[selectIndex].value;

	piname = selectText.split(":");

	document.login.speed.value = piname[0];
	document.login.pi.value = piname[1];
	document.login.oncampus.options.selectedIndex=1;
}

function loadPInameuchsc() {
	var selectIndex = document.login.piVal.selectedIndex;
	var selectText = document.login.piVal.options[selectIndex].value;

	piname = selectText.split(":");

	document.login.speedNum.value = piname[0];
	document.login.pi.value = piname[1];
	//document.login.oncampus.options.selectedIndex=1;
}

function loadDept() {
	var selectIndex = document.login.deptVal.selectedIndex;
	var selectText = document.login.deptVal.options[selectIndex].value;

	piname = selectText.split(":");

	document.login.deptS.value = piname[0];
	document.login.pi.value = piname[1];
}

function loadSpeed() {
	var selectIndex = document.login.oncampus.selectedIndex;
	var selectText = document.login.oncampus.options[selectIndex].value;

	if ( selectText == "Industry" ) {
		document.login.speedNum.value = "Industry";
		document.login.speed.value = "Industry";
		document.login.pi.value = "Industry";
		document.login.piVal.options.selectedIndex=0;
	}
	if ( selectText == "Other-Campus" ) {
		document.login.speedNum.value = "Other-Campus";
		document.login.speed.value = "Other-Campus";
		document.login.pi.value = "Other-Campus";
		document.login.piVal.options.selectedIndex=0;
	}

}

function chkPi3() {
	var selectIndex = document.login.piVal.selectedIndex;
	var pi = document.login.piVal.options[selectIndex].value;

	PI = document.login.pi.value;

	if ( PI != pi ) {
		window.alert("The PI field does not match the Select List PI.");
		document.login.pi.value = pi;
	}
}


function chkPI() {
	var formError = true;
	pi = document.login.pi.value;

	if ( pi.length < 3 ) {
		formError = false;
		window.alert("The PI name needs more than 3 characters.");
	}

	piVal = document.login.pi.value;
	piRetVal = isAString(piVal);

	if ( piRetVal == false ) {
		window.alert("The PI field has an error.");
		formError = false;
	}

	return formError;
}

function makePIID() {
	var piError = false;
	orgName = document.login.orgName.value;
	piError = chkPI();
	if ( piError == true ) {
		if ( orgName == "laragen" ) {
			makePiId3();
		} else {
			makePiId();
		}
	}
}

function makePiId() {
	pi = document.login.pi.value;
	PI = pi.toLowerCase();
	// make into a number
	curpiid = document.login.curpiid.value - 0;
	//curpiid = curpiid - 0;
	newpiid = curpiid + 1;
	var npi = "";
	var k = 0;

	for (var i=0; i<PI.length; i++){
		if (PI.charAt(i) != " ") {
			if ( k < 3 ) {
				npi = npi + PI.charAt(i);
			}
			k++;
		}
	}
	//window.alert("npi is " + npi);
	//window.alert("newpiid is " + newpiid);

	clientid = npi + curpiid;
	document.login.piid.value = clientid;
	document.login.newpiid.value = newpiid;
}


function makePiId3() {
	pi = document.login.pi.value;
	PI = pi.toLowerCase();

	//window.alert("npi is " + PI);

	// make into a number
	curpiid = document.login.curpiid.value - 0;
	newpiid = curpiid + 1;
	document.login.newpiid.value = newpiid;

	var npi = "";
	var rpi = "";
	var id = "100";
	var xpi = 0;
	var k = 0;

	num = document.login.num.value;

	for (var i=0; i<PI.length; i++){
		if (PI.charAt(i) != " ") {
			if ( k < 3 ) {
				npi = npi + PI.charAt(i);
			}
			k++;
		}
	}
	//window.alert("npi is " + npi);

	for (var i=0; i<num; i++){
		rpi = "";
		k = 0;
		info = 'info' + i;
		val = document.login.elements[info].value;

		piname = val.split(":");
		tname = piname[3].toLowerCase();
		for (var j=0; j<tname.length; j++){
			if (tname.charAt(j) != " ") {
				if ( k < 3 ) {
					rpi = rpi + tname.charAt(j);
				}
				k++;
			}
		}
		if ( npi == rpi ) {
			xpi++;
			//window.alert("npi" + " " + npi + ", rpi" + " " + rpi + ", xpi" + " " + xpi);
		}
	}
	xpi++;

	//window.alert(xpi);
	if ( xpi < 10 ) {
		id = "00";
	}
	if ( xpi > 9 && xpi < 100 ) {
		id = "0";
	}

	//clientid = npi + id + xpi;
	clientid = npi + curpiid;

	document.login.piid.value = clientid;

	//window.alert("clientid " + clientid + ", newpiid " + newpiid );
}






function makePiId2() {
	pi = document.login.pi.value;
	PI = pi.toLowerCase();
	var npi = "";
	var rpi = "";
	var id = "100";
	var xpi = 0;
	var k = 0;

	num = document.login.num.value;

	for (var i=0; i<PI.length; i++){
		if (PI.charAt(i) != " ") {
			if ( k < 3 ) {
				npi = npi + PI.charAt(i);
			}
			k++;
		}
	}
	//window.alert("npi is " + npi);

	for (var i=0; i<num; i++){
		rpi = "";
		k = 0;
		info = 'info' + i;
		val = document.login.elements[info].value;

		piname = val.split(":");
		tname = piname[3].toLowerCase();
		for (var j=0; j<tname.length; j++){
			if (tname.charAt(j) != " ") {
				if ( k < 3 ) {
					rpi = rpi + tname.charAt(j);
				}
				k++;
			}
		}
		if ( npi == rpi ) {
			xpi++;
//window.alert("npi" + " " + npi + ", rpi" + " " + rpi + ", xpi" + " " + xpi);
		}
	}
	xpi++;
	clientid = npi + id + xpi;
	document.login.piid.value = clientid;
}

function searchPI() {
	var piError = false;
	piError = chkPI();
	if ( piError == true ) {
		orgName = document.login.orgName.value;

		makePiId();

		pi = document.login.pi.value;
		PI = pi.toLowerCase();
		num = document.login.num.value;

		//window.alert("PI is " + pi + num );

		for (var i=0; i<num; i++){
			info = 'info' + i;
			val = document.login.elements[info].value;

			piname = val.split(":");

			if ( piname[0].toLowerCase() == PI ) {
				document.login.phoneS.value = piname[11];
				document.login.instS.value = piname[4];
				document.login.faxS.value = piname[12];
				document.login.deptS.value = piname[5];
				document.login.emailS.value = piname[13];
				document.login.streetB.value = piname[14];
				document.login.streetB2.value = piname[15];
				//document.login.piid.value = piname[3];
				document.login.streetS.value = piname[6];
				document.login.piemail.value = piname[1];
				document.login.streetS2.value = piname[7];
				document.login.cityS.value = piname[8];
				document.login.stateS.value = piname[9];
				document.login.zipS.value = piname[10];


				//document.login.nameS.value = i;
				break;
			}
		}

	}

}

function searchPIID() {
	var piError = false;
	var piidFound = false;
	//piError = chkPI();
	//if ( piError == true ) {

		//makePiId();

		piid = document.login.piid.value;

		pi = document.login.pi.value;
		PI = pi.toLowerCase();
		num = document.login.num.value;

		//window.alert("PI is " + pi + num );

		for (var i=0; i<num; i++){
			info = 'info' + i;
			val = document.login.elements[info].value;

			piname = val.split(":");

			if ( piname[3] == piid ) {
				document.login.pi.value = piname[0];
				document.login.phoneS.value = piname[11];
				document.login.instS.value = piname[4];
				document.login.faxS.value = piname[12];
				document.login.deptS.value = piname[5];
				document.login.emailS.value = piname[13];
				document.login.streetB.value = piname[14];
				document.login.streetB2.value = piname[15];
				//document.login.piid.value = piname[3];
				document.login.streetS.value = piname[6];
				document.login.piemail.value = piname[1];
				document.login.streetS2.value = piname[7];
				document.login.cityS.value = piname[8];
				document.login.stateS.value = piname[9];
				document.login.zipS.value = piname[10];


				piidFound = true;
				//document.login.nameS.value = i;
				break;
			}
		}
		if ( piidFound == false ) {
			window.alert("The Client_ID was not found, please enter the Location information manually.");
		}

	//}

}

function loadUnr() {
        Index=document.login.idVal.options.selectedIndex;
        pif = document.login.idVal.options[Index].value;
        
        vals = pif.split(":");
        affi = vals[0];
        first = vals[14];
        last = vals[15];
        //det = vals[17];

	if ( affi == "UNR-campus" ) {
		document.login.oncampus.selectedIndex=1;
	}
	if ( affi == "Inside-NV" ) {
		document.login.oncampus.selectedIndex=2;
	}
	if ( affi == "Outside-NV" ) {
		document.login.oncampus.selectedIndex=3;
	}

	firstLast =first + ", " + last;
        document.login.pi.value = firstLast;

        firstB = vals[1];
        lastB = vals[2];
	nameB =firstB + ", " + lastB;
	document.login.nameB.value = nameB;

        firstS = vals[14];
        lastS = vals[15];
	nameS =firstS + ", " + lastS;
	document.login.nameS.value = nameS;


	document.login.instB.value = vals[3];
	document.login.deptB.value = vals[4];
	document.login.streetB.value = vals[5];
	document.login.streetB2.value = vals[6];
	document.login.cityB.value = vals[7];
	document.login.stateB.value = vals[8];
	document.login.zipB.value = vals[9];
	document.login.phoneB.value = vals[10];
	document.login.extB.value = vals[11];
	document.login.faxB.value = vals[12];
	document.login.emailB.value = vals[13];


	document.login.instS.value = vals[16];
	document.login.deptS.value = vals[17];
	document.login.streetS.value = vals[18];
	document.login.streetS2.value = vals[19];
	document.login.cityS.value = vals[20];
	document.login.stateS.value = vals[21];
	document.login.zipS.value = vals[22];
	document.login.phoneS.value = vals[23];
	document.login.extS.value = vals[24];
	document.login.faxS.value = vals[25];
	document.login.emailS.value = vals[26];


	//document.login.streetB.value = piname[16];
	//document.login.street2B.value = piname[17];



}

function loadHarvard() { 
        Index=document.login.idVal.options.selectedIndex;
        pif = document.login.idVal.options[Index].value;
        
        vals = pif.split("_");
        uid = vals[0];
        first = vals[1];
        last = vals[2];
        det = vals[3];
        member = vals[4];

	firstLast =first + " " + last;

        document.login.pi.value = firstLast;

	searchPIharvard(uid);
}

function searchPIharvard(PIUID) {
        num=document.login.num.value

	//pi = document.login.pi.value;
	//PI = pi.toLowerCase();

	//window.alert("PI is " + PIUID );
	//window.alert("num is " + num );

	for (var i=0; i<num; i++){
		info = 'info' + i;
		val = document.login.elements[info].value;

		piname = val.split(":");

		if ( piname[0] == PIUID ) {

			document.login.member.value = piname[3];
			document.login.piUID.value = piname[4];

			document.login.instS.value = piname[6];
			document.login.deptS.value = piname[7];
			document.login.streetB.value = piname[16];
			//document.login.street2B.value = piname[17];
			document.login.streetS.value = piname[8];
			document.login.streetS2.value = piname[9];
			document.login.cityS.value = piname[10];
			document.login.stateS.value = piname[11];
			document.login.zipS.value = piname[12];
			document.login.phoneS.value = piname[13];
			document.login.faxS.value = piname[14];
			//document.login.emailS.value = piname[15];
			//document.login.piid.value = piname[20];


			//document.login.nameS.value = i;
			break;
		}
	}
}





function loadPrefDept() {
	// Read the dept cookie and set the dept dropdown to be
	// the last choice they made

	//document.passwd.uname.focus();

	var prefDept = getCookie("prefDept");

	for (var i=0; i < document.passwd.act.options.length; i++) {
		if (document.passwd.act.options[i].value == prefDept) {
			document.passwd.act.selectedIndex = i;
		}
	}

	setAction();

}

/**
 * Sets a Cookie with the given name and value.
 *
 * name       Name of the cookie
 * value      Value of the cookie
 * [expires]  Expiration date of the cookie (default: end of current session)
 * [path]     Path where the cookie is valid (default: path of calling document)
 * [domain]   Domain where the cookie is valid
 *              (default: domain of calling document)
 * [secure]   Boolean value indicating if the cookie transmission requires a
 *              secure transmission
 */
function setCookie(name, value, expires, path, domain, secure)
{
    document.cookie= name + "=" + escape(value) +
        ((expires) ? "; expires=" + expires.toGMTString() : "") +
        ((path) ? "; path=" + path : "") +
        ((domain) ? "; domain=" + domain : "") +
        ((secure) ? "; secure" : "");

//window.alert("setCookie name " + name + ", value " + value + ", expires " + expires + ", path " + path + ", domain " + domain + ", secure " + secure );
//window.alert(document.cookie);

}

/**
 * Gets the value of the specified cookie.
 *
 * name  Name of the desired cookie.
 *
 * Returns a string containing value of specified cookie,
 *   or null if cookie does not exist.
 */
function getCookie(name)
{

	//window.alert(document.cookie);

    var dc = document.cookie;
    var prefix = name + "=";
    var begin = dc.indexOf("; " + prefix);
	//window.alert("prefix " + prefix + ", begin " + begin );

    if (begin == -1)
    {
        begin = dc.indexOf(prefix);
        if (begin != 0) return null;
    }
    else
    {
        begin += 2;
    }

    var end = document.cookie.indexOf(";", begin);
    if (end == -1)
    {
        end = dc.length;
    }
	//window.alert("uname " + prefix + " " + begin + " " + end );
    return unescape(dc.substring(begin + prefix.length, end));
}

/**
 * Deletes the specified cookie.
 *
 * name      name of the cookie
 * [path]    path of the cookie (must be same as path used to create cookie)
 * [domain]  domain of the cookie (must be same as domain used to create cookie)
 */
function deleteCookie(name, path, domain)
{
    if (getCookie(name))
    {
        document.cookie = name + "=" + 
            ((path) ? "; path=" + path : "") +
            ((domain) ? "; domain=" + domain : "") +
            "; expires=Thu, 01-Jan-70 00:00:01 GMT";
    }
}

