
//Auto-Tabs to next inputbox
function TabNext(obj,devent,len,next_field) {
	if (devent == "down") {
		phone_field_length=obj.value.length;
		}
	else if (devent == "up") {
		if (obj.value.length != phone_field_length) {
			phone_field_length=obj.value.length;
			if (phone_field_length == len) {
				next_field.focus();
			}
		}
	}
}

function setfocus(thisbox) {
	thisbox.focus();
}




////validation for any field that does not contain a default input (ex. askQuestion textbox)
function checkNull(objName) {
    var nullfield = objName;
    if (chkNull(objName) == false) {
        nullfield.select();
        objName.focus();
        return false;
    }
    else {
        return true;
    }
}

//helper function for checkNull()
function chkNull(objName){
	thisNull = objName.value;
	if(thisNull == "") {
		return false;
	}
	else {
		return true;
	}
}




//validation for the zip field
function checkZip(objName) {
    var zipfield = objName;
    if (chkZip(objName) == false) {
        zipfield.select();
        alert("The zip code is invalid. Please input a valid zip code");
        objName.focus();
        return false;
    }
    else {
        return true;
    }
}

//helper function for checkZip
function chkZip(objName){
	thisZip = objName.value;
	if(thisZip == "Zip") {
		return true;
	}
	else {
		if (thisZip.length < 5) {
		   return false;
		}
		if(isNaN(thisZip)) return false;
	}
}

//RETURNS INPUT INDEX
function getIndex(input) {
	var index = -1, i = 0, found = false;
	while (i < input.form.length && index == -1)
		if (input.form[i] == input)index = i;
		else i++;
	return index;
}

//LOOPS THROUGH ARRAYS CHECKING FOR THE STRING
function inArray(thisString,thisArray) {
    var len=thisArray.length;
    for(var i=0;i<len;i++){
        if(thisArray[i]==thisString)
            return i;
    }
    return -1;
}

//CHECKS IF CLASS ALREADY EXISTS
function isClassPresent(thisDoc,thisClass){
    var rgClasses=thisDoc.className.split(" ");
    return inArray(thisClass,rgClasses)>=0;
}

//CREATES CLASSES FOR EACH 'document.'
function addClass(Pq){
    var classes=Pq.className.split(" ");
    var len=arguments.length;
    for(var i=1;i<len;i++){
        var op=arguments[i].slice(0,1);
        var cls=arguments[i].slice(1);
        var idx=inArray(cls,classes);
        if(op=="-") {
            if(idx!=-1)
                classes.splice(idx,1);
        }
        else {
            if(idx==-1)
                classes.push(cls);
        }
    }
    var newClass=classes.join(" ");
    if(Pq.className!=newClass)
        Pq.className=newClass;
}

//KEEPS WHAT'S INSIDE INPUTBOXES
function keepInputText(pEvent,pDocument) {
    var bIsClean=isClassPresent(pDocument,"clean");
    if(bIsClean&&(pEvent.type=="focus"||pEvent.type=="drop")) {
        pDocument.value="";
        addClass(pDocument,"-clean");
    }
    else {
        if(pDocument.value.length==0&&pEvent.type=="blur") {
            pDocument.value=pDocument.getAttribute("title");
            addClass(pDocument,"+clean");
        }
    }
}


function validate() { 
	thisform = document.forms.regfrm;
	apos=thisform.email.value.indexOf("@");
	dotpos=thisform.email.value.lastIndexOf(".");
	lastpos=thisform.email.value.length-1;

	if(thisform.name.title == thisform.name.value) {
		alert("Please type your Name.");
		thisform.name.focus();
		return false;
	}
	else if(thisform.email.title == thisform.email.value) {
		alert("Email is required. Please type your email.");
		thisform.email.focus();
		return false;
	}
	else if(apos < 1 || dotpos - apos < 2 || lastpos - dotpos > 3 || lastpos - dotpos < 2) {
		thisform.email.select();
		alert("Invalid Email. Please try again.");
		thisform.email.focus();
		return false; 
	}	
	else if(thisform.request.value == "") {
		alert("Please type your message");
		thisform.request.focus();
		return false;
	}

	if(thisform.location.title == thisform.location.value) {
		thisform.location.value = '';
	}
	if(thisform.hear.value == "") {
		thisform.hear.value = '';
	}
	if(thisform.student.value == "") {
		thisform.student.value = '';
	}





	return true;
}

//-->