//Checks if any option is selected in the drop down
//You can use this function with any drop down and custom message
function VerifyDate(date1, date2, message) {
    var tempDate1 = new Date(date1);
    var tempDate2 = new Date(date2);
    if (tempDate2 != '') {
        if (tempDate1 < tempDate2) {
            alert(message);
            return false;
        }
        else {
            return true;
        }
    }
}
function CheckEmptyString(strClientId, message)
{
    var tempDdl = document.getElementById(strClientId);
    strDDLValue = new String(tempDdl.options[tempDdl.selectedIndex].value);

    if( strDDLValue == "")
    {
        alert(message);
        return false;
    }
}
function checkMaxLength(Object, MaxLen)
{
  return (Object.value.length < MaxLen);
}
function ddlRequiredTrigger(ddlObj,strCriticalValue,changeObj)
{
	// This function is used to check a DDL for a specific
	// value that, if found, sets another object's class
	// to "SEVISCell"
	
	var strDDLValue;
	
	strDDLValue = new String(ddlObj.options[ddlObj.selectedIndex].value);
	
	if (strDDLValue == strCriticalValue)
		changeObjectClass(changeObj,'SEVISCell');
	else
		changeObjectClass(changeObj,'');
}

function changeObjectClass(cObj,strClassName)
{
	cObj.className = strClassName;
}

function trimWhitespace(string)
{
	var re= /^\s*|\s*$/g;
	return string.replace(re,"");
}

function checkAll(frmName, strIn, blnState){
	for(i = 0; i < frmName.elements.length; i++){
		if ( (frmName.elements[i].name.substr(0,strIn.length) == strIn)
			&& ( !frmName.elements[i].disabled ) )
		{
			
			frmName.elements[i].checked = true;
			
		}
	}
	return false;
}

function checkAllWithState( frmName, strIn, blnState ){
	return checkAllWithStateClearBG(frmName, strIn, blnState, false );
}

function checkAllWithStateClearBG(frmName, strIn, blnState, blnClearBG ){
	for(i = 0; i < frmName.elements.length; i++){
		if ( (frmName.elements[i].name.substr(0,strIn.length) == strIn)
			&& ( !frmName.elements[i].disabled ) )
		{
			if (blnState == 'true')
			{
				frmName.elements[i].checked = true;
			}
			else
			{
				frmName.elements[i].checked = false;
			}
			
			if ( blnClearBG )
			{
				//
				// clear the color of the row where these checkboxes are.
				strFormElementsName = new String( frmName.elements[i].name );
				strTableRowID = "TR" + strFormElementsName.substr(3); // the susbstr is the id of the row
				TableRow = document.getElementById( strTableRowID );						
				TableRow.style.backgroundColor = "";
			}
		}
	}
	
	if (blnState == 'true')
	{
		return false;
	}
	else
	{
		return true;
	}
}

function endMarkerCheckAllWithState( frmName, strIn, blnState ){
	return endMarkerCheckAllWithStateClearBG(frmName, strIn, blnState, false );
}

function endMarkerCheckAllWithStateClearBG(frmName, strIn, blnState, blnClearBG ){
	for(i = 0; i < frmName.elements.length; i++){	
		if ( (frmName.elements[i].name.substr(frmName.elements[i].name.length - strIn.length,(frmName.elements[i].name.length - 1)) == strIn)
			&& ( !frmName.elements[i].disabled ) )
		{
			if (blnState == 'true')
			{
				frmName.elements[i].checked = true;
			}
			else
			{
				frmName.elements[i].checked = false;
			}
			
			if ( blnClearBG )
			{
				//
				// clear the color of the row where these checkboxes are.
				strFormElementsName = new String( frmName.elements[i].name );
				strTableRowID = "TR" + strFormElementsName.substr(3); // the susbstr is the id of the row
				TableRow = document.getElementById( strTableRowID );						
				TableRow.style.backgroundColor = "";
			}
		}
	}
	
	if (blnState == 'true')
	{
		return false;
	}
	else
	{
		return true;
	}
}


function checkAllWithState2In(frmName, strIn, strIn2, blnState){

	
	for(i = 0; i < frmName.elements.length; i++){
		if ( (frmName.elements[i].name.substr(0,strIn.length) == strIn || frmName.elements[i].name.substr(0,strIn2.length) == strIn2)
			&& ( !frmName.elements[i].disabled ) )
		{
			if (blnState == 'true')
			{
				frmName.elements[i].checked = true;
			}
			else
			{
				frmName.elements[i].checked = false;
			}
		}
	}
	
	if (blnState == 'true')
	{
		return false;
	}
	else
	{
		return true;
	}
}

function flipImage (strDivOn, strDivOff, blnState)
{
	if (blnState == 'true')
	{
			document.getElementById(strDivOn).style.display = 'block';
			document.getElementById(strDivOff).style.display = 'none';
	}
	else
	{
			document.getElementById(strDivOn).style.display = 'none';
			document.getElementById(strDivOff).style.display = 'block';
	}
}

function confirmSuppressEvent()
{
	return confirm('Are you sure you want to suppress this event?');
}

function popUpCal(field,monthNow,yearNow)
{

	window.open("subCalendar.asp?Field=" + field + "&Month=" + monthNow + "&Year=" + yearNow,"Cal","toolbar=false,directories=false,status=false,menubar=false,scrollbars=false,resizable=false,width=200,height=250")
}

function popUpHelpNoParam(fileName)
{

	window.open("fsaAtlasHelp/ToolTips/" + fileName + ".asp","ToolTips","toolbar=false,directories=false,status=false,menubar=false,resizable,width=300,height=200")
}

function popUpStudent(studentId)
{
	window.open("subQuickView.asp?sysId=" + studentId,"StudentEdit2","toolbar=false,directories=false,status=false,menubar=false,scrollbars,resizable,width=350,height=500")
}

function popUpAdvisorNotes(studentId)
{
	window.open("subAdvisorNoteList.asp?sysId=" + studentId,"NotesEdit","toolbar=false,directories=false,status=false,menubar=false,scrollbars,resizable,width=850,height=220,left=0,top=0")
}

function popUpSASNotes(eventId, noteMode)
{
	window.open("subSASNoteList.asp?EventId=" + eventId + "&Mode=" + noteMode,"SASNotesEdit","toolbar=false,directories=false,status=false,menubar=false,scrollbars,resizable,width=850,height=220,left=0,top=0")
}

function popUpEMailAlert(alertId)
{
	window.open("subViewEMailAlertDetails.asp?AlertId=" + alertId,"AlertView","toolbar=false,directories=false,status=false,menubar=false,scrollbars,resizable,width=700,height=500")
}

function popUpEMailTagGuide()
{
	window.open("ViewContentTags.aspx","TagGuide","toolbar=false,directories=false,status=false,menubar=false,scrollbars,resizable,width=400,height=500")
}

function popContentTagGuide()
{
	window.open("subViewEMailAlertTagGuide.asp","TagGuide","toolbar=false,directories=false,status=false,menubar=false,scrollbars,resizable,width=400,height=500")
}

function popUpSelectEdit(customId)
{
	window.open("CustomFieldSelectFrameSet.asp?customId=" + customId,"CustomEdit","toolbar=false,directories=false,status=false,menubar=false,scrollbars,resizable,width=450,height=400")
}

function popUpOneAdvisorNote(studentId,noteID)
{
	window.open("subEditAdvisorNote.asp?History=Y&sysId=" + studentId + "&noteId=" + noteID,"NotesEdit","toolbar=false,directories=false,status=false,menubar=false,scrollbars,resizable,width=850,height=220")
}

function popUpAddAddress(link)
{
     winwidth = 510; // width of the new window
     winheight = 660; // height of the new window
     winleft = (screen.width / 2) - (winwidth / 2); // center the window right to left
     wintop = (screen.height / 2) - (winheight / 2); // center the window top to bottom
	// the values get inserted into the features parameter of the window.open command...
     
	window.open(link,"AddressInformation","toolbar=true,directories=false,status=true,menubar=false,scrollbars= false,resizable=false," + 'top=' + wintop + ',left=' + winleft + ',height=' + winheight + ',width=' + winwidth)
}

function popUpApptReminder(noteID)
{
    window.open("ClientSchedulerPrintableAppt.asp?Id=" + noteID,"AppointmentReminder","toolbar=1,directories=false,status=false,menubar=1,scrollbars,resizable,width=700,height=250")
}

function popUpPositionCode()
{
	window.open("subChoosePositionCode.asp","NotesEdit","toolbar=false,directories=false,status=false,menubar=false,scrollbars,resizable,width=850,height=130")
}

function popUpPositionCodeNoFrames()
{
	window.open("subChoosePositionCode.asp?Frames=False","NotesEdit","toolbar=false,directories=false,status=false,menubar=false,scrollbars,resizable,width=850,height=130")
}

function popUpHelpWindow(link)
{
     winwidth = 700; // width of the new window
     winheight = 575; // height of the new window
     winleft = (screen.width / 2) - (winwidth / 2); // center the window right to left
     wintop = (screen.height / 2) - (winheight / 2); // center the window top to bottom
	// the values get inserted into the features parameter of the window.open command...
     
	window.open(link,"HelpSystem","toolbar=true,directories=false,status=true,menubar=false,scrollbars,resizable," + 'top=' + wintop + ',left=' + winleft + ',height=' + winheight + ',width=' + winwidth)
}

function popUpFormBlastWindow(link)
{
     winwidth = 850; // width of the new window
     winheight = 645; // height of the new window
     winleft = (screen.width / 2) - (winwidth / 2); // center the window right to left
     wintop = (screen.height / 2) - (winheight / 2); // center the window top to bottom
	// the values get inserted into the features parameter of the window.open command...
     
	window.open(link,"EmailBlast","toolbar=false,directories=false,status=false,menubar=false,scrollbars,resizable," + 'top=' + wintop + ',left=' + winleft + ',height=' + winheight + ',width=' + winwidth)
}

function popUpFormLetterWindow(link)
{
     winwidth = 750; // width of the new window
     winheight = 425; // height of the new window
     winleft = (screen.width / 2) - (winwidth / 2); // center the window right to left
     wintop = (screen.height / 2) - (winheight / 2); // center the window top to bottom
	// the values get inserted into the features parameter of the window.open command...
     
	window.open(link,"FormLetter","toolbar=false,directories=false,status=false,menubar=false,scrollbars,resizable," + 'top=' + wintop + ',left=' + winleft + ',height=' + winheight + ',width=' + winwidth)
}
 function OpenPopUp(link)
    {
        //document.getElementById("BatchGuid").value=batchGuid;
        window.open(link);
     
    }
function popUpAbout(link)
{
    winwidth = 500; // width of the new window
    winheight = 384; // height of the new window
	var browseWidth, browseHeight;
    
	if ( typeof( window.innerWidth ) == 'number' ) 
	{
		//Non-IE
		browseWidth=window.innerWidth;
		browseHeight=window.innerHeight;
	}
	else if (document.layers)
	{
		browseWidth=window.outerWidth;
		browseHeight=window.outerHeight;
	}
	else if (document.all)
	{
		browseWidth=document.body.offsetWidth;
		browseHeight=document.body.offsetHeight;
	}

     winleft = (browseWidth/2) - (winwidth / 2); // center the window right to left
     wintop = (browseHeight) - (winheight / 2); // center the window top to bottom
     
	window.open(link,null,"toolbar=no,directories=no,status=no,menubar=no,scrollbars=no,resizable=no,titlebar=no," + 'top=' + wintop + ',left=' + winleft + ',height=' + winheight + ',width=' + winwidth)

}

function fillMultiLineOptionalDDL(objText,objSelect)
{
	objText.value = objSelect.options[objSelect.selectedIndex].value;
}

function fillCityOfBirth(objText,objSelect)
{
	objText.value = objSelect.options[objSelect.selectedIndex].value;
}

function fillJCode(objText,objSelect)
{
	objText.value = objSelect.value;
}

function fillJCodeOD(objText,objSelect)
{
	var strSubject;
	var strArray;

	strSubject = objSelect.value;
	strArray = strSubject.split("!!!!");

	objText.value = strArray[0];	
}

function closeAdvisorNotes()
{
	// reload\refresh the window that opened you
	 window.opener.location.reload();
}

function guessCity(objText,objSelect)
{
	var i, blnFound, subStringVal
	
	blnNotFound = true;
		
	for (i=0;i<objSelect.length;i++)
	{
		subStringVal = objSelect.options[i].text;
		subStringVal = subStringVal.substring(0,objText.value.length);
	
		if ((objText.value.toUpperCase() == subStringVal.toUpperCase()) && blnNotFound)
		{
			objSelect.options[i].selected = true;
			blnNotFound = false;
		}
		
		if (blnNotFound)
		{
			objSelect.options[0].selected = true;
		}
		
		if (objText.value == "")
		{
			objSelect.options[0].selected = true;
		}
	}
}

function guessJCode(objText,objSelect)
{
	var i, blnFound, subStringVal
	
	blnNotFound = true;
		
	for (i=0;i<objSelect.length;i++)
	{
		subStringVal = objSelect.options[i].value;
		subStringVal = subStringVal.substring(0,objText.value.length);
	
		if ((objText.value.toUpperCase() == subStringVal.toUpperCase()) && blnNotFound)
		{
			objSelect.options[i].selected = true;
			blnNotFound = false;
		}
		
		if (blnNotFound)
		{
			objSelect.options[0].selected = true;
		}
		
		if (objText.value == "")
		{
			objSelect.options[0].selected = true;
		}
	}
}

function SubjectFieldFillOD(objText,objSelect){
	
	if (objSelect.value != "")
	{
		var strSubject;
		var strArray;

		strSubject = objSelect.value;
		strArray = strSubject.split("!!!!");

		objText.value = strArray[1];
	}
	else
	{
		objText.value = "";
	}
}

function valJCode(objText,objSelect)
{
	var i, blnFound, subStringVal
	
	blnNotFound = true;
		
	for (i=0;i<objSelect.length;i++)
	{
		subStringVal = objSelect.options[i].value;
	
		if ((objText.value.toUpperCase() == subStringVal.toUpperCase()) && blnNotFound)
		{
			objSelect.options[i].selected = true;
			blnNotFound = false;
		}
		
	}
	
	if (blnNotFound)
	{
		alert("The J Code must be containted in select list");
		return false;
	}
	else
	{
		return true;
	}
	
}

function valJCodeOD(objText,objSelect)
{
	var i, blnFound, subStringVal
	var strSubject;
	var strArray;
	
	blnNotFound = true;
		
	for (i=0;i<objSelect.length;i++)
	{

		strSubject = objSelect.options[i].value;
		strArray = strSubject.split("!!!!");
	
		subStringVal = strArray[0];
		//subStringVal = strSubject;
		
		if ((objText.value.toUpperCase() == subStringVal.toUpperCase()) && blnNotFound)
		{
			objSelect.options[i].selected = true;
			blnNotFound = false;
		}
		
	}
	
	if (blnNotFound)
	{
		alert("The J Code must be containted in select list");
		return false;
	}
	else
	{
		return true;
	}
	
}

function valJobCode(objText,objSelect)
{
	var i, blnFound, subStringVal
	
	blnNotFound = true;
		
	for (i=0;i<objSelect.length;i++)
	{
		subStringVal = objSelect.options[i].value;
	
		if ((objText.value.toUpperCase() == subStringVal.toUpperCase()) && blnNotFound)
		{
			objSelect.options[i].selected = true;
			blnNotFound = false;
		}
		
	}
	
	if (blnNotFound)
	{
		alert("The DS-2019 Job Code must be containted in select list");
		return false;
	}
	else
	{
		return true;
	}
	
}


function fillCityOnFocus(objText,objSelect)
{

	if (objSelect.options[objSelect.selectedIndex].text !== "")
	{
		objText.value = objSelect.options[objSelect.selectedIndex].text;
	}
}

function fillJCodeOnFocus(objText,objSelect)
{

	if (objSelect.value !== "")
	{
		objText.value = objSelect.value;
	}
}

function fillJCodeOnFocusOD(objText,objSelect)
{
	var strSubject;
	var strArray;

	strSubject = objSelect.value;
	strArray = strSubject.split("!!!!");

	if (strArray[0] !== "")
	{	
		objText.value = strArray[0];
	}
}

function isHidden(objName)
{
	if (objName.type.toUpperCase() != 'HIDDEN')
	{
		return true;
	}
	else
	{
		return false;
	}
}

//This is the function that should be used to validate dates - it allows the user to specify the name of the field
//in the pop up box
function valDate(objName,txtName)
{
	if ( objName.value != "" )
	{
		if ( objName.value.toUpperCase() != "{NULL}" )
		{
			var re = new RegExp(/^\d?\d[\/]\d?\d[\/]\d\d\d\d$/)
	
			objName.value = trimWhitespace(objName.value)
			if (objName.value.search(re) == -1)
			{
				alert("The date entered into " + txtName + " must be formatted mm/dd/yyyy");
				if (isHidden(objName))
				{
					objName.focus();
				}
				return false;
			}
			else
			{
				if (chkdate(objName) == false)
				{
					alert("The date entered into " + txtName + " is invalid");
					if (isHidden(objName))
					{
						objName.focus();
					}
					return false;
				}
				else
				{
					var REYear = new RegExp(/[\/]\d*$/);
					var pos = objName.value.search(REYear);
					var myYear = objName.value.substring(pos+1,pos+5);
					if (myYear<1900) 
					{		
						alert("The date entered cannot be less than 1/1/1900.");
						if (isHidden(objName))
						{
							objName.focus();
						}
						return false;
					}
					else
					{
						return true;
					}
				}
			}
		}
		else
		{
			return true;
		}
	} 
	else 
	{
		return true;
	}
}

function valDateNo1900(objName,txtName)
{
	if ( objName.value != "" )
	{
		var re = new RegExp(/^\d?\d[\/]\d?\d[\/]\d\d\d\d$/)

		if (objName.value.search(re) == -1)
		{
			alert("The date entered into " + txtName + " must be formatted mm/dd/yyyy");
			return false;
		}
		else
		{
			if (chkdate(objName) == false)
			{
				alert("The date entered into " + txtName + " is invalid");
				if (isHidden(objName))
				{
					objName.focus();
				}
				return false;
			}
			else
			{
				return true;
				
			}
		}
	} 
	else 
	{
	
		return true;
	}
}


//This is a function I got on the internet to check dates - it returns a boolean if the date is valid or not
function chkdate(objName) {
var strDatestyle = "US"; //United States date style
//var strDatestyle = "EU";  //European date style
var strDate;
var strDateArray;
var strDay;
var strMonth;
var strYear;
var intday;
var intMonth;
var intYear;
var booFound = false;
var datefield = objName;
var strSeparatorArray = new Array("-"," ","/",".");
var intElementNr;
var err = 0;
var strMonthArray = new Array(12);
strMonthArray[0] = "Jan";
strMonthArray[1] = "Feb";
strMonthArray[2] = "Mar";
strMonthArray[3] = "Apr";
strMonthArray[4] = "May";
strMonthArray[5] = "Jun";
strMonthArray[6] = "Jul";
strMonthArray[7] = "Aug";
strMonthArray[8] = "Sep";
strMonthArray[9] = "Oct";
strMonthArray[10] = "Nov";
strMonthArray[11] = "Dec";
strDate = datefield.value;
if (strDate.length < 1) {
return true;
}
for (intElementNr = 0; intElementNr < strSeparatorArray.length; intElementNr++) {
if (strDate.indexOf(strSeparatorArray[intElementNr]) != -1) {
strDateArray = strDate.split(strSeparatorArray[intElementNr]);
if (strDateArray.length != 3) {
err = 1;
return false;
}
else {
strDay = strDateArray[0];
strMonth = strDateArray[1];
strYear = strDateArray[2];
}
booFound = true;
   }
}
if (booFound == false) {
if (strDate.length>5) {
strDay = strDate.substr(0, 2);
strMonth = strDate.substr(2, 2);
strYear = strDate.substr(4);
   }
}
if (strYear.length == 2) {
strYear = '20' + strYear;
}
// US style
if (strDatestyle == "US") {
strTemp = strDay;
strDay = strMonth;
strMonth = strTemp;
}
intday = parseInt(strDay, 10);
if (isNaN(intday)) {
err = 2;
return false;
}
intMonth = parseInt(strMonth, 10);
if (isNaN(intMonth)) {
for (i = 0;i<12;i++) {
if (strMonth.toUpperCase() == strMonthArray[i].toUpperCase()) {
intMonth = i+1;
strMonth = strMonthArray[i];
i = 12;
   }
}
if (isNaN(intMonth)) {
err = 3;
return false;
   }
}
intYear = parseInt(strYear, 10);
if (isNaN(intYear)) {
err = 4;
return false;
}
if (intMonth>12 || intMonth<1) {
err = 5;
return false;
}
if ((intMonth == 1 || intMonth == 3 || intMonth == 5 || intMonth == 7 || intMonth == 8 || intMonth == 10 || intMonth == 12) && (intday > 31 || intday < 1)) {
err = 6;
return false;
}
if ((intMonth == 4 || intMonth == 6 || intMonth == 9 || intMonth == 11) && (intday > 30 || intday < 1)) {
err = 7;
return false;
}
if (intMonth == 2) {
if (intday < 1) {
err = 8;
return false;
}
if (LeapYear(intYear) == true) {
if (intday > 29) {
err = 9;
return false;
}
}
else {
if (intday > 28) {
err = 10;
return false;
}
}
}
//if (strDatestyle == "US") {
//datefield.value = strMonthArray[intMonth-1] + " " + intday+" " + strYear;
//}
//else {
//datefield.value = intday + " " + strMonthArray[intMonth-1] + " " + strYear;
//}
return true;
}
function LeapYear(intYear) {
if (intYear % 100 == 0) {
if (intYear % 400 == 0) { return true; }
}
else {
if ((intYear % 4) == 0) { return true; }
}
return false;
}

//Function used to raise alert box if a field does not contain a integer between 1-30
function valOtherParam(objName)
{

	if (isNaN(objName.value) == true)
	{
		alert("All fields in this screen must be filled with an integer between 1-30");
		if (isHidden(objName))
		{
			objName.focus();
		}
		return false;
	}
	else
	{
		if (parseInt(objName.value) < 1 || parseInt(objName.value) > 30)
		{
			alert("All fields in this screen must be filled with an integer between 1-30");
			if (isHidden(objName))
			{
				objName.focus();
			}
			return false;		
		}
		else
		{
			return true;
		}
	}

}

function valNoResChars(objName,txtName)
{
	var re = new RegExp(/^[\w\s]*$/)

	if (objName.value.search(re) == -1 && objName.value != "")
	{
			alert("The data in " + txtName + " contains reserved characters - please correct.");
			if (isHidden(objName))
			{
				objName.focus();
			}
			return false;		
		}
		else
		{
			return true;
		}

}

function valNoQuotes(objName,txtName)
{
	var re = new RegExp(/^[^'"]*$/)

	if (objName.value.search(re) == -1 && objName.value != "")
	{
			alert("The data in " + txtName + " contains quotes - please correct.");
			if (isHidden(objName))
			{
				objName.focus();
			}
			return false;		
		}
		else
		{
			return true;
		}

}

function valNoResCharsExPer(objName,txtName)
{
	var re = new RegExp(/^[\w\s\%']*$/)
	
	if (objName.value.search(re) == -1 && objName.value != "")
	{
			alert("The data in " + txtName + " contains reserved characters - please correct.");
			if (isHidden(objName))
			{
				objName.focus();
			}
			return false;		
		}
		else
		{
			return true;
		}

}

function valNoResCharsNoSpaces(objName,txtName)
{
	var re = new RegExp(/^\w*$/)

	if (objName.value.search(re) == -1 && objName.value != "")
	{
			alert("The data in " + txtName + " contains reserved characters - please correct.");
			if (isHidden(objName))
			{
				objName.focus();
			}
			return false;		
		}
		else
		{
			return true;
		}

}

function valNoResCharsExSlash(objName,txtName)
{
	var re = new RegExp(/^[\s\w\/]*$/)

	if (objName.value.search(re) == -1 && objName.value != "")
	{
			alert("The data in " + txtName + " contains reserved characters - please correct.");
			if (isHidden(objName))
			{
				objName.focus();
			}
			return false;		
		}
		else
		{
			return true;
		}

}

function valTextArea(objName,size,txtName)
{
    var extra = 0;  
    if (navigator.appName=="Netscape" && parseInt(navigator.appVersion)>=5) 
    {     
        var index = objName.value.indexOf('\n');     
        while(index != -1) {       
            extra += 1;       
            index = objName.value.indexOf('\n',index+1);     
        }  
    }  

    if (objName.value.length + extra > size)
	{
			alert("The data in " + txtName + " field is longer than the allowed limit of " + size + " characters.");
			if (isHidden(objName))
			{
				objName.focus();
			}
			return false;		
	}
	else
	{
		return true;
	}

}

function valInteger(objName,txtName)
{
	var re = new RegExp(/^\d*$/)

	if (objName.value.search(re) == -1 && objName.value != "")
	{
			alert("The data in " + txtName + " must be an integer and contain only numeric characters - please correct.");
			if (isHidden(objName))
			{
				objName.focus();
			}
			return false;		
		}
		else
		{
			return true;
		}

}


function valReqText(objName,txtName)
{
    if (objName.value.length <= 0)
    {
        alert(txtName + " must contain some text - please correct.");
		if (isHidden(objName))
		{
			objName.focus();
		}
        return false;
    }
    else
    {
        return true;
    }
}


function valReqTextOption(objName,txtName)
{
    if (objName.value.length <= 0)
    {
        if (confirm("SEVIS requires that " + txtName + " contain some text - please correct."))
        {
		if (isHidden(objName))
		{
			objName.focus();
		}   
          return false;
        }
        else
        {
            return true;
        }
    
    }
    else
    {
        return true;
    }
}


function valLength(object, maxlength, name)
{
    var length = object.value.length;
    if(length != 0 && length != maxlength) {
        alert('The value in ' + name + ' must be exactly ' + maxlength + ' characters long');
		if (isHidden(object))
		{
			object.focus();
		}
        return false;
    } else {
        return true;
    }
}

function valIntLength(object, maxlength, name)
{
    if(!valInteger(object, name)) {
        return false;
    }

    return valLength(object, maxlength, name);
}


function valDouble(objName,txtName)
{
	var re = new RegExp(/^\d*[.]{0,1}\d*$/)

	if (objName.value.search(re) == -1 && objName.value != "")
	{
			alert("The data in " + txtName + " must be a number - please correct.");
			if (isHidden(objName))
			{
				objName.focus();
			} 
			return false;		
		}
		else
		{
			return true;
		}

}

function valSevisUserId(objName,txtName)
{
	var re = new RegExp(/((([a-zA-Z]{6})|([a-zA-Z]{1}-[a-zA-Z]{4})|([a-zA-Z]{2}-[a-zA-Z]{3})|([a-zA-Z]{3}-[a-zA-Z]{2})|([a-zA-Z]{4}-[a-zA-Z]{1})|([a-zA-Z]{5}-))\d{4})/)
	var re2 = new RegExp(/((([a-zA-Z]{5})|([a-zA-Z]{1}-[a-zA-Z]{3})|([a-zA-Z]{2}-[a-zA-Z]{2})|([a-zA-Z]{3}-[a-zA-Z]{1})|([a-zA-Z]{4}-))\d{5})/)
	var re3 = new RegExp(/((([a-zA-Z]{4})|([a-zA-Z]{1}-[a-zA-Z]{2})|([a-zA-Z]{2}-[a-zA-Z]{1})|([a-zA-Z]{3}-))\d{6})/)
	var re4 = new RegExp(/((([a-zA-Z]{3})|([a-zA-Z]{1}-[a-zA-Z]{1})|([a-zA-Z]{2}-))\d{7})/)

	if (objName.value.search(re) == -1 && objName.value.search(re2) == -1 && objName.value.search(re3) == -1 && objName.value.search(re4) == -1 && objName.value != "")
	{
		if (confirm("To the best of our current knowledge the SEVIS User Id entered into " + txtName + " does not conform to the SEVP specifications.  We suggest that you correct this User Id.  Press OK to correct."))
		{
			return false;
		}
		else
		{
			return true;
		}
	}
	else
	{
		return true;
	}

}


function valSevisSchoolCode(objName,txtName)
{
	var re = new RegExp(/[A-Z]{3}214F\d{8}/)

	if (objName.value.search(re) == -1 && objName.value != "")
	{
		if (confirm("To the best of our current knowledge the SEVIS School Code entered into " + txtName + " does not conform to the SEVP specifications.  We suggest that you correct this School Code.  Press OK to correct."))
		{
			return false;
		}
		else
		{
			return true;
		}
	}
	else
	{
		return true;
	}

}

function valSevisProgramNumber(objName,txtName)
{
	var re = new RegExp(/(P-[1-4]-\d{5})|(G-[1-6]-\d{5})/)

	if (objName.value.search(re) == -1 && objName.value != "")
	{
		if (confirm("To the best of our current knowledge the SEVIS Program Number entered into " + txtName + " does not conform to the SEVP specifications.  We suggest that you correct this Program Number.  Press OK to correct."))
		{
			return false;
		}
		else
		{
			return true;
		}
	}
	else
	{
		return true;
	}

}


function webDemoAlert()
{
	alert("This function has been disabled for the Web Demo");
}

function webDemoSEVISAlert()
{
	alert("You may not add a new profile for this idividual because they are SEVIS Active and this is the web demo.");
}

function confirmDelete(type, destination)
{
    if (confirm("Are you sure you want to delete this " + type + "?"))
    {
        window.location.href=destination;
    }
}

function codeDropChange(codeFieldName, selectFieldName) 
{
    var strCode = eval('document.MainForm.' + selectFieldName + '.value');
    strCodeArray = strCode.split('!!!!');
    //eval('document.MainForm.' + selectFieldName + '.value = strCodeArray[1]');
    eval('document.MainForm.' + codeFieldName + '.value = strCodeArray[0]');

    return;
}

function diffDateAfter(startDate, endDate, startName, endName)
{
    var blnOK;
    if (Date.parse(startDate.value) < Date.parse(endDate.value))
    {
        blnOK = true;
    }
    else
    {
        if (confirm(endName + " should be after " + startName + ".  It is likely that SEVIS will not accept this event. Click OK to correct the dates."))
        {
			if (isHidden(startDate))
			{
				startDate.focus();
			} 
               blnOK = false;
        }
        else
        {
            blnOK = true;
        }
    }
    return blnOK;
}

function valDateAfterToday(objName, txtName)
{
    var blnOK;
    var now = new Date();
    var dat = new Date(Date.parse(objName.value));

    if ((now.getYear() == dat.getYear()) &&
        (now.getMonth() == dat.getMonth()) &&
        (now.getDate() == dat.getDate()))
    {
    	
        blnOK = true;
    }
    else if (now > dat)
    {
        if (confirm(txtName + " is before today's date. It is likely that SEVIS will not accept this event.  Click OK to correct the date."))
        {
			if (isHidden(objName))
			{
				objName.focus();
			}    
            blnOK = false;
        }
        else
        {
            blnOK = true;
        }
    
    }
    else
    {
    	blnOK = true;
    }
    
    return blnOK;
}

// =================================================
// JavaScript function to display hover message for Wizard Menu
// =================================================

function Is ()
{   // convert all characters to lowercase to simplify testing
    var agt=navigator.userAgent.toLowerCase()

    // *** BROWSER VERSION ***
    this.major = parseInt(navigator.appVersion)

    this.nav  = ((agt.indexOf('mozilla')!=-1) && ((agt.indexOf('spoofer')==-1)
                && (agt.indexOf('compatible') == -1)))
    this.nav4 = (this.nav && (this.major == 4))
    this.nav4up = this.nav && (this.major >= 4)

    this.ie   = (agt.indexOf("msie") != -1)
    this.ie4  = (this.ie && (this.major == 4))
    this.ie4up  = this.ie  && (this.major >= 4)
}

function maketheBalloon(id, width, message)
{
   var theString = '<STYLE TYPE="text/css">#'+id+'{width:'+width+';}</STYLE>';
   theString+='<DIV CLASS="balloon" id="'+id+'">'+message+'</DIV>';
   document.write(theString);
}

function makeItVisible(id, event)
{

	if (is.nav4up) {
		document.layers[id].left = event.pageX + 10;
		document.layers[id].top = event.pageY + 10;
		document.layers[id].visibility="show";
	}
	else {
		document.all[id].style.pixelLeft = (document.body.scrollLeft +event.clientX) + 10;
		document.all[id].style.pixelTop = (document.body.scrollTop + event.clientY) + 10;
		document.all[id].style.visibility="visible";
	}

}

function hideHelp(id)
{
	is.nav4up ? document.layers[id].visibility="hide" : document.all[id].style.visibility="hidden";
}

// End of JavaScript for WizardMenu

// JavaScript for application log out
function LogOut()
{
    if (confirm("You are about to Log Out of SEVIS Connection ?"))
    {
		if (window.top != window.self) 
		{
			window.top.location = 'logout.asp';
		}
		else
		{
			top.location = 'logout.asp';
		}
    }
    else
    {
        parent.location.reload();
    }
}

// Javascript for Rollover button
function MM_preloadImages() { //v3.0
  var d=document; if(d.images){ if(!d.MM_p) d.MM_p=new Array();
    var i,j=d.MM_p.length,a=MM_preloadImages.arguments; for(i=0; i<a.length; i++)
    if (a[i].indexOf("#")!=0){ d.MM_p[j]=new Image; d.MM_p[j++].src=a[i];}}
}

function MM_swapImgRestore() { //v3.0
  var i,x,a=document.MM_sr; for(i=0;a&&i<a.length&&(x=a[i])&&x.oSrc;i++) x.src=x.oSrc;
}

function MM_findObj(n, d) { //v4.0
  var p,i,x;  if(!d) d=document; if((p=n.indexOf("?"))>0&&parent.frames.length) {
    d=parent.frames[n.substring(p+1)].document; n=n.substring(0,p);}
  if(!(x=d[n])&&d.all) x=d.all[n]; for (i=0;!x&&i<d.forms.length;i++) x=d.forms[i][n];
  for(i=0;!x&&d.layers&&i<d.layers.length;i++) x=MM_findObj(n,d.layers[i].document);
  if(!x && document.getElementById) x=document.getElementById(n); return x;
}

function MM_swapImage() { //v3.0
  var i,j=0,x,a=MM_swapImage.arguments; document.MM_sr=new Array; for(i=0;i<(a.length-2);i+=3)
   if ((x=MM_findObj(a[i]))!=null){document.MM_sr[j++]=x; if(!x.oSrc) x.oSrc=x.src; x.src=a[i+2];}
}
