function NewWindow(mypage, myname, w, h, scroll) {
	var winl = (screen.width - w) / 2;
	var wint = (screen.height - h) / 2;
	winprops = 'height='+h+',width='+w+',top='+wint+',left='+winl+',scrollbars='+'yes'+',resizable'
//	alert("winprops= " + winprops);
	win = window.open(mypage, myname, winprops)
	if (parseInt(navigator.appVersion) >= 4) { 
		win.window.focus(); 
	}
}
function PrintWindow(mypage, myname, w, h) {
	var winl = (screen.width - w) / 2;
	var wint = (screen.height - h) / 2;
	winprops =
'height='+h+',width='+w+',top='+wint+',left='+winl+',scrollbars='+'yes'+',menubar='+'yes'+',toolbar='+'yes'+',resizable' 
	win = window.open(mypage, myname, winprops)
	if (parseInt(navigator.appVersion) >= 4) { 
		win.window.focus(); 
	}
}

function closeAndRefresh() {
    window.opener.location.reload();
    window.close();
}
function SubmitFrm(FormName){
//var ThisFormName = eval("document.forms." + FormName);
	FormName.submit();
}
function ShowHideBlock(BlockToShow,blockstate){
var ThisBlockState = blockstate;
BlockToShow.style.display = ThisBlockState;
}
// var good;
function checkall(formname,checkname,thestate){
var el_collection=eval("document.forms."+formname+"."+checkname)
for (c=0;c<el_collection.length;c++)
el_collection[c].checked=thestate
}
/*
UncheckOthers is a function to uncheck all checkboxes with the passed field name if their VALUE is not the same as the passed value. Used to impose radio button behavior on checkboxes.
MLK 12/01/2004
usage: onclick="UncheckOthers('MainFrm','checkbox field name','checkbox_value')"
*/
function UncheckOthers(formname,checkname,checkedval)
{
var el_collection=eval("document.forms."+formname+"."+checkname)
for (c = 0; c < el_collection.length; c++)
	{
	if (el_collection[c].value != checkedval)
		{
	el_collection[c].checked = false;
		}
	}
}
// SetRadioState will CHECK the passed radio button with a value that matches the passed value
function SetRadioState(formname,TargetRadioField,ValToCompare,DesiredState)
{
var ThisRadioSet = eval("document.forms." + formname + "." + TargetRadioField);
for (i=0; i<ThisRadioSet.length;i++)
	{
	if (ThisRadioSet[i].value == ValToCompare)
		{
		ThisRadioSet[i].checked = DesiredState
		}
	}
}
/* 
checkEmailAddress will validate the passed form field value against the regular expression below. If it doesn't pass, it alerts with the passed msg if it is defined or the default error, focuses back on the calling document with the form field selected.
onblur="javascript:checkEmailAddress(FormName.FieldName,'Please enter a valid email address')"
*/
function checkEmailAddress(field,msg) 
{
// Note: The next expression must be all on one line...
//       allow no spaces, linefeeds, or carriage returns!
var goodEmail = field.value.match(/\b(^(\S+@).+((\.com)|(\.net)|(\.edu)|(\.mil)|(\.gov)|(\.org)|(\..{2,2}))$)\b/gi);

if (!goodEmail)
	{
	if (typeof(msg) != 'undefined')
		{
   alert('' + msg);
   		}
	else
		{
   alert('The email address you entered is not valid. Please enter a valid email address.');
		}
	self.focus();
	field.select();
	field.focus();
   }
}

/* 
checkEmailAddressCf will work in cfinput tag
*/
function checkEmailAddressCf(form, ctrl, value) 
{
// Note: The next expression must be all on one line...
//       allow no spaces, linefeeds, or carriage returns!

if (value.length)
	{
	var goodEmail = value.match(/\b(^(\S+@).+((\.com)|(\.net)|(\.edu)|(\.mil)|(\.gov)|(\.org)|(\..{2,2}))$)\b/gi);

	if (!goodEmail)
		{
	 	return false
	   	}
	else
		{
		return true
		}
	}
else
	{
	return true
	}
}


//function to check if the fields given in an array have some value entered or not
// labels array is used to display the error message
function checkMandatoryFields(fieldsArr, labelsArr )
{
//alert("hello");
	var ErrorStr="";
	for(var i=0;i<fieldsArr.length;i++)
	{
		var type = eval("document.all."+fieldsArr[i]+".type")
//		type=type.toLowerCase();
alert("type=" + type);
		if(type=="text" ||type=="file" ||type=="textarea")
		{
			var len = eval("trim(document.all."+fieldsArr[i]+".value).length")
			if(!len)
			{
				ErrorStr=ErrorStr+"Please Enter "+labelsArr[i] +"\n";
			}
		}
/*
		else if(type=="select-one")
		{
			var len = eval("document.all."+fieldsArr[i]+".value")
			if(len==0)
			{
				ErrorStr=ErrorStr+"Please Select "+labelsArr[i] +"\n";
			}
		}
*/
		else if(type=="select-multiple")
		{
		var selectobj = eval("document.all."+fieldsArr[i]);
		if(selectobj.selectedIndex==-1)
			{
				ErrorStr=ErrorStr+"Please Select "+labelsArr[i] +"\n";
			}
		}
	}
	return 	ErrorStr;		
}
function selectFinal(formname, targ) {
 var finalObj = eval("document.forms."+formname+"."+targ);
	for (i=finalObj.length-1; i>=0; i--) {
finalObj.options[i].selected = true;
	}
}
function moveVals(n, formname, obj, targ) {
 var fromObj = eval("document.forms."+formname+"."+obj);
 var to = eval("document.forms."+formname+"."+targ);
	if (n == 1 || n == 2) {
		var indTo = to.length-1;
		for (i=fromObj.length-1; i>=0; i--) {
			if (n==1 || fromObj.options[i].selected) {
				indTo++;
				to.options[indTo] = new Option(fromObj.options[i].text, fromObj.options[i].value);
				to.options[indTo].selected = true;
				fromObj.options[i] = null;
			}
		}
	} else if (n == 3 || n == 4) {
		var indFrom = fromObj.length-1;
		for (i=to.length-1; i>=0; i--) {
			if (n==4 || to.options[i].selected) {
				indFrom++;
				fromObj.options[indFrom] = new Option(to.options[i].text, to.options[i].value);
				to.options[i] = null;
			}
		}
	}
}
function selectAllVals(formname, targ) {
 	var to = eval("document.forms."+formname+"."+targ);
	var toLength = to.length;
	var indTo = to.length-1;
	
	if (toLength > 0)
		{
		for (i=0; i<=indTo; i++) {
			to.options[i].selected = true;
			}
		}
	}

/* SetFrmVal will set the value for the FormName.FrmField to passed val. If optional final argument is passed and is "Yes", it will submit the form.
*/
function SetFrmVal(FormName, FieldName, val, DoSub)
{
var DoSubVal = DoSub;
var SVal = val;
var SForm = eval("document.forms."+FormName);
var SField = eval("document.forms."+FormName+"."+FieldName);
// alert('val is ' + val + ' and SField = ' + SField);
	SField.value = SVal;
if (DoSubVal == 'Yes')
	{
	SForm.submit();
	}
}

function openURL(nwindow, mypage, myname, w, h, scroll)
{
	if(nwindow == "1")
	{
	//alert("should open new window");
	NewWindow(mypage, myname, w, h, scroll);
	}
	else
	{
	//alert("should not open new window");
	window.location = mypage;
	//return true;
	}
}

function openURL2(nwindow, mypage, myname, myattributes)
{
	if(nwindow == "1")
	{
	//alert("should open new window");
	window.open(mypage, myname, myattributes)
	}
	else
	{
	//alert("should not open new window");
	window.location = mypage;
	//return true;
	}
}

function goURL(thisurl) { 
   window.location = thisurl;
} 


function submitenter(searchphrase,e)
{
var keycode;
if (window.event) keycode = window.event.keyCode;
else if (e) keycode = e.which;
else return true;

if (keycode == 13)
   {
   finalForm = SimpleSearch;
   finalForm.PHRASE_1.value = searchphrase;
   finalForm.submit();
   return false;
   }
else
   return true;
}

function noenter() 
  {
  return !(window.event && window.event.keyCode == 13); 
  }
  
function searchSubmit(searchphrase)
	{
	finalForm = SimpleSearch;
	finalForm.PHRASE_1.value = searchphrase;
	finalForm.submit();
	}
	
function ownerSubmit3(thisform,thisprocess)
	{
	finalForm = eval("document.forms."+thisform);
	//alert ("finalform" + finalForm);
	finalForm.process.value = thisprocess;
	finalForm.submit();
	}
	
function populateAddress(details) 
	{ 
	var myString = details.options[details.selectedIndex].value;
	var mySplitResult = myString.split("|");
	
	document.getElementById("HasSameAddressAs").value = mySplitResult[0];
	document.getElementById("Street_Number").value = mySplitResult[1];
	document.getElementById("Street_Direction").value = mySplitResult[2];
	document.getElementById("Street_Name").value = mySplitResult[3];
	document.getElementById("Apt_Number").value = mySplitResult[4];
	document.getElementById("City").value = mySplitResult[5];
	document.getElementById("State").value = mySplitResult[6];
	document.getElementById("Postal_Code").value = mySplitResult[7];
	document.getElementById("AreaCodeH").value = mySplitResult[8];
	document.getElementById("ExchangeH").value = mySplitResult[9];
	document.getElementById("Extension_1H").value = mySplitResult[1];
	}	
	
function autoSave(btnval,btnlbl,thisprocess, mypage, myname, w, h, scroll)
	{
		var changeCheck = document.getElementById("changeField");
		if(changeCheck.value == "1")
			{
			objectSubmit(btnval,btnlbl,thisprocess);
			}
		else
			{
			NewWindow(mypage, myname, w, h, scroll);
			}
	}
		

function setClassName(objId, className) {
    	document.getElementById(objId).className = className;
}


/* this code is saved for future reference
function moveTeachers(n) {
	
	if (n == 1 || n == 2) {
		var indTo = this.form.ClassTeachers.length-1;
		for (i=this.form.PotentialClassTeachers.length-1; i>=0; i--) {
			if (n==1 || document.forms.ClassFrm.PotentialClassTeachers.options[i].selected) {
				indTo++;
				//name
				var newText = document.forms.ClassFrm.PotentialClassTeachers.options[i].text;
				
				//date from
				var newFromDateText = '';
				var newFromDateValue = '';
				var newMonthF = '';
				var newDayF = '';
				var newYearF = '';
				
				var newMonthFidx = ClassFrm.Start_Month_T.selectedIndex;
				if (newMonthFidx>0) {				
					newMonthF = ClassFrm.Start_Month_T.options[newMonthFidx].value;
					}
					
				var newDayFidx = ClassFrm.Start_Day_T.selectedIndex;
				if (newDayFidx>0) {				
					newDayF = ClassFrm.Start_Day_T.options[newDayFidx].value;
					}
					
				var newYearFidx = ClassFrm.Start_Year_T.selectedIndex;
				if (newYearFidx>0) {				
					newYearF = ClassFrm.Start_Year_T.options[newYearFidx].value;
					}
				
				if ((newMonthF.length>0) & (newDayF.length>0) & (newYearF.length>0)) {
					newFromDateText = ' (' + newMonthF + '/' + newDayF + '/' + newYearF + '-';
					newFromDateValue = '**' + newMonthF + '/' + newDayF + '/' + newYearF;
					}
					
				//date to
				var newToDateText = '';
				var newToDateValue = '';
				var newMonthT = '';
				var newDayT = '';
				var newYearT = '';
				
				var newMonthTidx = ClassFrm.End_Month_T.selectedIndex;
				if (newMonthTidx>0) {				
					newMonthT = ClassFrm.End_Month_T.options[newMonthTidx].value;
					}
					
				var newDayTidx = ClassFrm.End_Day_T.selectedIndex;
				if (newDayTidx>0) {				
					newDayT = ClassFrm.End_Day_T.options[newDayTidx].value;
					}
					
				var newYearTidx = ClassFrm.End_Year_T.selectedIndex;
				if (newYearTidx>0) {				
					newYearT = ClassFrm.End_Year_T.options[newYearTidx].value;
					}
				
				if ((newFromDateValue.length>0) & (newMonthT.length>0) & (newDayT.length>0) & (newYearT.length>0)) {
					newToDateText = newMonthT + '/' + newDayT + '/' + newYearT + ')';
					newToDateValue =  '***' + newMonthT + '/' + newDayT + '/' + newYearT;
					}	
				
				newText = newText + newFromDateText + newToDateText;
				
				newValue = document.forms.ClassFrm.PotentialClassTeachers.options[i].value;
				newValue = newValue + newFromDateValue + newToDateValue;
				
				document.forms.ClassFrm.ClassTeachers.options[indTo] = new Option(newText,newValue);
				document.forms.ClassFrm.ClassTeachers.options[indTo].selected = true;
				document.forms.ClassFrm.PotentialClassTeachers.options[i] = null;
			}
		}
	} else if (n == 3 || n == 4) {
		var indFrom = document.forms.ClassFrm.PotentialClassTeachers.length-1;
		for (i=document.forms.ClassFrm.ClassTeachers.length-1; i>=0; i--) {
			if (n==4 || document.forms.ClassFrm.ClassTeachers.options[i].selected) {
				indFrom++;
				
				newText = document.forms.ClassFrm.ClassTeachers.options[i].text;
				indDateMarker = newText.indexOf(' (');
				if (indDateMarker>=1) {
					newText = newText.substring(0,indDateMarker);
				}
				
				newValue = document.forms.ClassFrm.ClassTeachers.options[i].value;
				
				document.forms.ClassFrm.PotentialClassTeachers.options[indFrom] = new Option(newText, newValue);
				document.forms.ClassFrm.ClassTeachers.options[i] = null;
				
			}
		}
	}
}*/
