// JavaScript Document
	function allDigits(str)
	{
		return inValidCharSet(str,"0123456789");
	}

	function noNewLines(str)
	{
		return iniNotValidCharSet(str,chr(10));
	}

/*	function ValidateDataOld() 
	{
		var CanSubmit = true;
		if  ((allDigits(document.Profile.Phone1.value)) && (allDigits(document.Profile.Phone2.value)) && (allDigits(document.Profile.Phone3.value)))
		{
			
		}
		else
		{
			alert ("You Must Enter Numeric Values For A Phone Number");
			CanSubmit = false;
		}
		if  ((allDigits(document.Profile.Fax1.value)) && (allDigits(document.Profile.Fax2.value)) && (allDigits(document.Profile.Fax3.value)))
		{
			
		}
		else
		{
			alert ("You Can Not Enter A Partial Fax Number");
			CanSubmit = false;
		}
		if (((document.Profile.Phone2.value.length < 3) || (document.Profile.Phone3.value.length < 4)) && ((document.Profile.Phone2.value.length > 0) || (document.Profile.Phone3.value.length > 0)))
		{
			alert ("You Must Enter A Full Phone Number");
			CanSubmit = false;
		}
		if (((document.Profile.Fax2.value.length < 3) || (document.Profile.Fax3.value.length < 4)) && ((document.Profile.Fax2.value.length > 0) || (document.Profile.Fax3.value.length > 0)))
		{
			alert ("You Can Not Enter A Partial  Fax Number");
			CanSubmit = false;
		}
		return CanSubmit;
	} */
	
	function ChangeFlag()
	{
		SubFlag=1;
	}
	
	function CheckNum() 
	{
		if ((window.event.keyCode >= "48" && window.event.keyCode <= "57") || (window.event.keyCode >= "96" && window.event.keyCode <= "105") || (window.event.keyCode == "8") || (window.event.keyCode == "9") || (window.event.keyCode == "37") || (window.event.keyCode == "39") || (window.event.keyCode == "46"))
		{
			return true;
		}
		else
		{
			return false;
		}
	 }
	
	function WinOpen(action, EntryiD, Type)
	{
		if (SubFlag == 0)
		{
			if (action == "NewED")
			{
				window.open('NewED.asp?W=500&DS="+Type+"', '', 'width=500,height=425');
			}
			if (action == "NewRes")
			{
				window.open('NewRes.asp?W=500&DS="+Type+"', '', 'width=500,height=350');
			}
			if (action == "NewPro")
			{
				window.open('NewPro.asp?W=500&DS="+Type+"', '', 'width=500,height=350');
			}
			if (action == "NewPub")
			{
				window.open('NewPub.asp?W=500&DS="+Type+"', '', 'width=500,height=350');
			}
			if (action == "NewTitle")
			{
				str = "window.open('NewTitle.cfm?W=500&DS="+Type+"', '', 'width=500,height=350');";
				eval (str);
			}
			if (action == "DelED")
			{
				str = "window.open('DelED.asp?W=350&EdKey="+EntryiD+"&DS="+Type+"', '', 'width=350,height=250');";
				eval (str);
			}
			if (action == "DelRes")
			{
				str = "window.open('DelRes.asp?W=350&ResKey="+EntryiD+"&DS="+Type+"', '', 'width=350,height=250');";
				eval (str);
			}
			if (action == "DelPro")
			{
				str = "window.open('DelPro.asp?W=350&ProKey="+EntryiD+"&DS="+Type+"', '', 'width=350,height=250');";
				eval (str);
			}
			if (action == "DelPub")
			{
				str = "window.open('DelPub.asp?W=350&PubKey="+EntryiD+"&DS="+Type+"', '', 'width=350,height=250');";
				eval (str);
			}
			if (action == "DelTitle")
			{
				str = "window.open('DelTitle.asp?W=350&TitleKey="+EntryiD+"&DS="+Type+"', '', 'width=350,height=250');";
				eval (str);
			}
			if (action == "NewHonors")
			{
				str = "window.open('NewHonors.asp?W=500&HonorsKey="+EntryiD+"&DS="+Type+"', '', 'width=500,height=350');";
				eval (str);
			}
			if (action == "DelHonors")
			{
				str = "window.open('DelHonors.asp?W=350&HonorsKey="+EntryiD+"&DS="+Type+"', '', 'width=350,height=250');";
				eval (str);
			}
		}
		else if (SubFlag == 1)
		{
			switch(action)
			{
				case "NewED":
				case "NewRes":
				case "NewPub":
				case "NewHonors":
				case "NewPro":
				case "NewTitle":
					str = "window.open('Changes.asp?path="+action+"&EntryiD="+EntryiD+"&DS="+Type+"', '', 'width=500,height=425');"
					break;
				case "DelED":
				case "DelRes":
				case "DelPro":
				case "DelPub":
				case "DelTitle":
				case "DelHonors":
					str = "window.open('Changes.asp?path="+action+"&EntryiD="+EntryiD+"', '', 'width=350,height=250');"
					break;
				default:
					break;
			}
					
			eval (str);
		}
	}
	
	function ValidateData() {
	    ErrStr='';
		var CanSubmit = false;
//		if  (isWhiteSpace(document.forms[0].EdSchool.value)){
//			alert ("You Must Enter A School");
//		}
//		else
//		if ((document.forms[0].EdLocation.value == "Other") && isWhiteSpace(document.forms[0].EdOL.value))		{
//			alert ("You Must Enter A Location");
//		}else
		if( isWhiteSpace(document.forms[0].EdYear.value)){
			alert("You Must Enter A Year");
		}
		else {
			document.forms[0].submit();
		}
	}
	
	function EnableDisableEdOL(){
	//alert('document.forms[0].EdLocation.value =' + document.forms[0].EdLocation.value);
		if ((document.forms[0].EdLocation.value == "Other")){
			document.forms[0].EdOL.disabled = false;
		}else{
			document.forms[0].EdOL.disabled = true;
		}
	}
	
	function ValidateHonData() {
			ErrStr='';
			var CanSubmit = false;
			if  (isWhiteSpace(document.forms[0].TypeA.value)){
				alert ("You Must Enter the Nature of Honor/Award");
			}else if( isWhiteSpace(document.forms[0].YearA.value)){
				alert("You Must Enter A Year");
			}
			else {
				document.forms[0].submit();
			}
	}
	
	function ValidateProData() {
			ErrStr='';
			var CanSubmit = false;
//			   alert("ok");
			if  (isWhiteSpace(document.forms[0].title.value)){
				alert ("You Must Enter the Title of BioSketch");
//			} else if( isWhiteSpace(document.forms[0].workdate.value)){
//				alert("You Must Enter a Date for the Work");
			} else if( isWhiteSpace(document.forms[0].workdesc.value)){
				alert("You Must Enter Details for the BioSketch");
			}
			else {
				document.forms[0].submit();
			}
	}
		
		function ValidateJobData() {
			ErrStr='';
			var CanSubmit = false;
			if  (isWhiteSpace(document.editJob.aff_title.value)){
				alert ("You Must Enter the Job Title");
			}else if( isWhiteSpace(document.editJob.aff_tier.value)){
				alert("You Must Enter the Department/Program/Institute");
			}
			else {
				document.editJob.submit();
			}
		}
		
		function ValidatePubData() {
			ErrStr='';
			//alert('in ValidatePubData()');
			var CanSubmit = false;
			if  (isWhiteSpace(document.Pub.publication.value)){
				alert ("You Must Enter the Title of the Publication.");
			}else if( isWhiteSpace(document.Pub.Year_P.value)){
				alert("Year Published is a required field.");
			}else {
				document.Pub.submit();
			}
		}
		
		function ValidateResData() {
			ErrStr='';
			var CanSubmit = false;
			//alert('in ValidateResData()');
			if  (isWhiteSpace(document.Res.topic.value)){
				alert ("You Must Enter the Topic/Title for this Research");
			}
			else {
				document.forms[0].submit();
			}
		}
		function ValidateKWData() {
			ErrStr='';
			var CanSubmit = false;
			//alert('in ValidateKWData()');
			if  (isWhiteSpace(document.KW.keywords.value)){
				;
			}
			else {
				document.forms[0].submit();
			}
		}
		
		function ValidateGncData() {
			ErrStr='';
			var CanSubmit = false;
			//alert('in ValidateGncData()');
			if  (isWhiteSpace(document.Gnc.title.value)){
				alert ("You Must Enter the Topic/Title for this Grant/Contract");
			}else if(isWhiteSpace(document.Gnc.sponsor.value)){
				alert ("You Must Enter the Sponsor for this Grant/Contract");
			}else if(isWhiteSpace(document.Gnc.gnc_type.value)){
				alert ("You Must Select the Type");
			}else if(isWhiteSpace(document.Gnc.startdate.value)){
				alert ("You Must Enter the Start Sate Year ");
			}else if(isWhiteSpace(document.Gnc.enddate.value) && 
						(isWhiteSpace(document.Gnc.current.value)) ){
				alert ("You Must either the end date or Select Present/Ongoing ");
			}else {
				document.Gnc.submit();
			}
		}
		
		
	function isWhiteSpace(str){
		if  ( (trim(str).length) ==0 )
			return true;
		else
			return false;
	}
	
	function trim(inputString) {
   // Removes leading and trailing spaces from the passed string. Also removes
   // consecutive spaces and replaces it with one space. If something besides
   // a string is passed in (null, custom object, etc.) then return the input.
   if (typeof inputString != "string") { return inputString; }
   var retValue = inputString;
   var ch = retValue.substring(0, 1);
   while (ch == " ") { // Check for spaces at the beginning of the string
      retValue = retValue.substring(1, retValue.length);
      ch = retValue.substring(0, 1);
   }
   ch = retValue.substring(retValue.length-1, retValue.length);
   while (ch == " ") { // Check for spaces at the end of the string
      retValue = retValue.substring(0, retValue.length-1);
      ch = retValue.substring(retValue.length-1, retValue.length);
   }
   while (retValue.indexOf("  ") != -1) { // Note that there are two spaces in the string - look for multiple spaces within the string
      retValue = retValue.substring(0, retValue.indexOf("  ")) + retValue.substring(retValue.indexOf("  ")+1, retValue.length); // Again, there are two spaces in each of the strings
   }
   return retValue; // Return the trimmed string back to the user
} // Ends the "trim" function

 

/* Validation routines for Add/Edit Research Forms*/

function chkInfoLen(){
	if(document.Pro.workdesc.value.length > 2000){
		document.Pro.workdesc.value = document.Pro.workdesc.value.substring(0, 2000);
		alert('This field exceeds the maximum charcters allowed; extra characters are truncated, please review your text.');
		document.Pro.workdesc.focus();
	}
}

function chkResTitleLen(){
	if(document.Res.topic.value.length > 250){
		document.Res.topic.value = document.Res.topic.value.substring(0, 250);
		alert('The Research Title exceeds the 250 chars, extra characters are truncated, please review your text.');
		document.Res.topic.focus();
	}
}

function chkReasonLen(){

	if(document.forms[0].NatureA.value.length > 255){
		document.forms[0].NatureA.value = document.forms[0].NatureA.value.substring(0, 254);
		alert('The Reason Conferred exceeds the 255 chars, extra characters are truncated, please review your text. ');
		document.forms[0].NatureA.focus();
	}
}
function chkDescLen(){

	if(document.forms[0].workdesc.value.length > 2000){
		document.forms[0].workdesc.value = document.forms[0].workdesc.value.substring(0, 1999);
		alert('The Reason Conferred exceeds the 2000 chars, extra characters are truncated, please review your text. ');
		document.forms[0].workdesc.focus();
	}
}
function chkTitleLen(){
	if(document.Gnc.title.value.length > 350){
		document.Gnc.title.value = document.Gnc.title.value.substring(0, 350);
		alert('The Title exceeds the 350 chars, extra characters are truncated, please review your text.');
		document.Gnc.title.value.focus();
	}
}
