function changeLocation(obj) {
	window.location = "http://ntcc.dbu.edu/" + obj;
}

function areEqual(fld1, fld2)
{
	var string1, string2;

	string1 = fld1.value;
	string2 = fld2.value;
	if (string1 != string2)
	{
		if (fld1.type == "password")
		{
			alert ("Passwords entered do not match.\nPlease retype.");
		}
		else if (fld1.type == "text")
		{
			alert ("E-mail addresses entered do not match.\nPlease retype.");
		}
		fld1.value = ""
		fld2.value = ""
		fld1.focus()
	}
}

function StripChars(theField)
{
	var strOut,i,curChar
	var theFilter;

	strOut = ""
	theFilter = "*() -./_\n\r";
	for (i=0;i < theField.length; i++)
	{		
		curChar = theField.charAt(i)
		if (theFilter.indexOf(curChar) < 0)	// if it's not in the filter, send it thru
			strOut += curChar		
	}	
	return strOut
}


function stripChar(str, chars) {
var i
var newstring = ""
for (i = 0; i < str.length; i++) {
mychar = str.charAt(i)
if (chars.indexOf(mychar) == -1)
newstring += mychar
}
return newstring
}




function AllInRange(x,y,theString)
{
	var i, curChar
	
	for (i=0; i < theString.length; i++)
	{
		curChar = theString.charAt(i)
		if (curChar < x || curChar > y) //the char is not in range
			return false
	}
	return true
}

function reformat (s)
{
    var arg;
    var sPos = 0;
    var resultString = "";

    for (var i = 1; i < reformat.arguments.length; i++) {
       arg = reformat.arguments[i];
       if (i % 2 == 1) 
           resultString += arg;
       else 
       {
           resultString += s.substring(sPos, sPos + arg);
           sPos += arg;
       }
    }
    return resultString;
}


function ValidateEmail(theField)
{
	var msg = "";
	var theString = "";
	var msgInvalid = "Please enter a valid Email Address."

	theString = theField.value;

	if (theString != "")
	{
		if ((theString.indexOf("@") < 1) || (theString.indexOf(".") >= (theString.length-2)) || (theString.indexOf(".") < 0)){
			msg = msgInvalid;
		}
		if (msg != "")
		{
			alert(msg);
			theField.value = '';
			theField.focus();
			return false;
		}else{
			return true;
		}
	}else{
		alert(msgInvalid);
		theField.value = '';
		theField.focus();
		return false;
	}
}

function ValidateUSPhone(theField)
{
	var msg = "";
	var theString = "";
	var msgInvalid = "Please enter a valid 9 digit U.S. phone number without parenthesis or dashes.\nExample: (760) 555-1212 should be 7605551212"

	theString = theField.value;

	if (theString != "")
	{
		theString = StripChars(theString)		

		if (!AllInRange("0","9",theString))
		{
			msg = msgInvalid;
		}
		else if (theString.length == 11)
		{
			 if (theString.charAt(0) != "1")	
				msg = msgInvalid
		}
		else if (theString.length != 10 && theString.length != 7)
		{
			msg = msgInvalid
		}

		if (msg == "")
		{
			if (theString.length == 10)
				theString = reformat(theString,"(",3,") ",3,"-",4);
			else if (theString.length == 7)
				theString = reformat(theString,"",3,"-",4);
			else //len == 11
				theString = reformat(theString,"",1,"(",3,") ",3,"-",4);

			theField.value = theString;
		}
		else
		{
			alert(msg);
			theField.value="";
			theField.focus();
		}
	}
}

function Require(obForm,szFields)
{
	var fields = szFields.split(",");
	for (x=0; x<obForm.elements.length; x++)
	{
		for (y=0; y<fields.length;y++)
		{
			if ((obForm.elements[x].name == fields[y]) && (obForm.elements[x].value == ""))
			{
				alert("Please make sure that all required fields are filled in before continuing.");
				obForm.elements[x].focus();
				return false;
			}
		}
	}
	return true;
}

function checkrequired(which){
var pass=true
if (document.images){
for (i=0;i<which.length;i++){
var tempobj=which.elements[i]
if (tempobj.name.substring(0,8)=="required"){
if (((tempobj.type=="text"||tempobj.type=="textarea")&&tempobj.value=='')||(tempobj.type.toString().charAt(0)=="s"&&tempobj.selectedIndex==-1)){
pass=false
break
}
}
}
}
if (!pass){
alert("The 'Page Complete' field at the bottom of the form was not selected. You may be getting this alert because you accidentally hit the ENTER key instead of TAB while trying to move to the next field. Please make sure your information is complete and resubmit this page!")
return false
}
else
return true
}

function validateZIP(field) {
	if (field.value.length!=5){
		alert("Please enter your 5 digit zip code.");
		field.value='';
		field.focus();
		return false;
	}
	for(i=0;i<field.value.length;i++){
		if(isNaN(field.value.charAt(i))){
			alert("Please enter a valid zip!");
			field.value='';
			field.focus();
			return false;
		}
	}
}

function checkRadio(obj){
	singleoption=-1;
	waiveroption=-1;
	for(i=0;i<obj.SingleRegType.length;i++){
		if(obj.SingleRegType[i].checked){
			singleoption=i;
		}
	}
	
	if(singleoption==-1){
		alert("Please go back to the top to choose a registration type.")
		return false
		
		
	}
	
	for(i=0;i<obj.Waiver.length;i++){
		if(obj.Waiver[i].checked){
			waiveroption=i;
		}
	}
	
	if(waiveroption==-1){
		alert("You haven't chosen an agreement");
		return false		
	}
}

function isDigit (c)
{   return ((c >= "0") && (c <= "9"))
}
function isNumber(theField){
	var i
	var obj
	obj=theField.value
	if(obj!=""){
		for(i=0; i<obj.length; i++){
			var c=obj.charAt(i);
			if (!isDigit(c)){
				alert("Please enter numbers only.");
				theField.value = '';
				theField.focus();
       	 		return false;
			}
		}
		return true;
	}
} 


function isLength(field,field_name) {
	if (field.length != "")
	{
		if (field.length<4) {
			msg = "Please enter at least 4 numbers or letters."
			alert(msg);
			field_name.value="";
			field_name.focus();
			return false;
		}
		return true;
	}
}

/**
 * DHTML date validation script. Courtesy of SmartWebby.com (http://www.smartwebby.com/dhtml/)
 */
// Declaring valid date character, minimum year and maximum year
var dtCh= "/";
var minYear=1900;
var maxYear=2100;

function isInteger(s){
	var i;
    for (i = 0; i < s.length; i++){   
        // Check that current character is number.
        var c = s.charAt(i);
        if (((c < "0") || (c > "9"))) return false;
    }
    // All characters are numbers.
    return true;
}

function stripCharsInBag(s, bag){
	var i;
    var returnString = "";
    // Search through string's characters one by one.
    // If character is not in bag, append to returnString.
    for (i = 0; i < s.length; i++){   
        var c = s.charAt(i);
        if (bag.indexOf(c) == -1) returnString += c;
    }
    return returnString;
}

function daysInFebruary (year){
	// February has 29 days in any year evenly divisible by four,
    // EXCEPT for centurial years which are not also divisible by 400.
    return (((year % 4 == 0) && ( (!(year % 100 == 0)) || (year % 400 == 0))) ? 29 : 28 );
}
function DaysArray(n) {
	for (var i = 1; i <= n; i++) {
		this[i] = 31
		if (i==4 || i==6 || i==9 || i==11) {this[i] = 30}
		if (i==2) {this[i] = 29}
   } 
   return this
}

function isDate(dtStr){
	var daysInMonth = DaysArray(12)
	var pos1=dtStr.indexOf(dtCh)
	var pos2=dtStr.indexOf(dtCh,pos1+1)
	var strMonth=dtStr.substring(0,pos1)
	var strDay=dtStr.substring(pos1+1,pos2)
	var strYear=dtStr.substring(pos2+1)
	strYr=strYear
	if (strDay.charAt(0)=="0" && strDay.length>1) strDay=strDay.substring(1)
	if (strMonth.charAt(0)=="0" && strMonth.length>1) strMonth=strMonth.substring(1)
	for (var i = 1; i <= 3; i++) {
		if (strYr.charAt(0)=="0" && strYr.length>1) strYr=strYr.substring(1)
	}
	month=parseInt(strMonth)
	day=parseInt(strDay)
	year=parseInt(strYr)
	if (pos1==-1 || pos2==-1){
		alert("The date format should be : mm/dd/yyyy")
		return false
	}
	if (strMonth.length<1 || month<1 || month>12){
		alert("Please enter a valid month")
		return false
	}
	if (strDay.length<1 || day<1 || day>31 || (month==2 && day>daysInFebruary(year)) || day > daysInMonth[month]){
		alert("Please enter a valid day")
		return false
	}
	if (strYear.length != 4 || year==0 || year<minYear || year>maxYear){
		alert("Please enter a valid 4 digit year between "+minYear+" and "+maxYear)
		return false
	}
	if (dtStr.indexOf(dtCh,pos2+1)!=-1 || isInteger(stripCharsInBag(dtStr, dtCh))==false){
		alert("Please enter a valid date")
		return false
	}
return true
}

function checkDate(obj){
	var dt=obj
	if (isDate(dt.value)==false){
		dt.value =""
		dt.focus()		
		return false
	}
    return true
 }
