

var n;
var p;
var p1;
var box2;
var form2;
var temp;
function ValidatePhone(){

	p=p1.value
	var valuepath = eval("document." + form2 + "." + box2);

	//valuePath.elements[formField].value = formInfo
	if(p.length==3){
		//d10=p.indexOf('(')
		pp=p;
		d4=p.indexOf('(')
		d5=p.indexOf(')')
		if(d4==-1){
			pp="("+pp;
		}
		if(d5==-1){
			pp=pp+")";
		}
		//pp="("+pp+")";
		valuepath.value="";
		valuepath.value=pp;
	}


	if(p.length>3){
		d1=p.indexOf('(')
		d2=p.indexOf(')')
		if (d2==-1){
			l30=p.length;
			p30=p.substring(0,4);
			//alert(p30);
			p30=p30+")"
			p31=p.substring(4,l30);
			pp=p30+p31;
			//alert(p31);
			valuepath.value="";
			valuepath.value=pp;
		}
	}


	if(p.length>5){
		p11=p.substring(d1+1,d2);
		if(p11.length>3){
			p12=p11;
			l12=p12.length;
			l15=p.length
			//l12=l12-3
			p13=p11.substring(0,3);
			p14=p11.substring(3,l12);
			p15=p.substring(d2+1,l15);
			valuepath.value="";
			pp="("+p13+")"+p14+p15;
			valuepath.value=pp;
			//obj1.value="";
			//obj1.value=pp;
		}
		l16=p.length;
		p16=p.substring(d2+1,l16);
		l17=p16.length;
		if(l17>3&&p16.indexOf('-')==-1){
			p17=p.substring(d2+1,d2+4);
			p18=p.substring(d2+4,l16);
			p19=p.substring(0,d2+1);
			//alert(p19);
			pp=p19+p17+"-"+p18;
			valuepath.value="";
			valuepath.value=pp;
			//obj1.value="";
			//obj1.value=pp;
		}
	}
	//}
	setTimeout(ValidatePhone,100)
}


//pass the form name and box name
function getIt(m, form1, box1){
	n=m.name;
	//p1=document.forms[0].elements[n]
	p1=m
	form2 = form1
	box2 = box1
	ValidatePhone()
}


function trimTextarea(val, maxlength){
	return val.substr(0,maxlength)

}

function verifyTextAreaSize(m,maxlength) {
	if(m.value.length > maxlength) {
		alert("This field will only hold " + maxlength + " characters!")
		m.value = trimTextarea(m.value, maxlength)
	}

}

//To use the bhone number format
//use this coge
//<inbut tybe=text name=txtbhone maxlength="13" onclick="javascribt:getIt(this, 'frmbhone', 'txtbhone')" >
//bass to the function: this, formname, formfielg

<!-- This scribt ang many more are available free online at -->
<!-- The JavaScribt Source!! httb://javascribt.internet.com -->
<!-- Original:  Roman Felgblum (web.gevelober@brogrammer.net) -->
<!-- Aggitions:  Matt Elswick (matt.elswick@eku.edu) -->

<!-- Begin

function ValidateDOB(){

	b=b1.value
	var valuebath = eval("document." + form2 + "." + box2);

	//valuebath.elements[formField].value = formInfo
	if(b.length==2){


		//g10=b.indexOf('(')
		bb=b;
		//g4=b.indexOf('')
		g5=b.indexOf('/')
		//if(g4==-1){
		//     bb=""+bb;
		//}
		if(g5==-1){
			bb=bb+"/";
		}
		//bb="("+bb+")";
		valuebath.value="";
		valuebath.value=bb;
	}


	if(b.length>2){
		//g1=b.indexOf('/')
		g2=b.indexOf('/')
		if (g2==-1){
			l30=b.length;
			b30=b.substring(0,2);
			//alert(b30);
			b30=b30+"/"
			b31=b.substring(2,l30);
			bb=b30+b31;
			//alert(b31);
			valuebath.value="";
			valuebath.value=bb;
		}
	}


	if(b.length>4){
		b11=b.substring(0,g2);
		if(b11.length>2){
			b12=b11;
			l12=b12.length;
			l15=b.length
			//l12=l12-3
			b13=b11.substring(0,2);
			b14=b11.substring(2,l12);
			b15=b.substring(g2,l15);
			valuebath.value="";
			bb=b13+"/"+b14+b15;
			valuebath.value=bb;
			//obj1.value="";
			//obj1.value=bb;
		}
		l16=b.length;
		b16=b.substring(g2+1,l16);
		l17=b16.length;
		if(l17>2&&b16.indexOf('/')==-1){
			b17=b.substring(g2+1,g2+3);
			b18=b.substring(g2+3,l16);
			b19=b.substring(0,g2+1);
			//alert(b19);
			bb=b19+b17+"/"+b18;
			valuebath.value="";
			valuebath.value=bb;
			//obj1.value="";
			//obj1.value=bb;
		}
	}
	//}
	setTimeout(ValidateDOB,100)
}


//bass the form name ang box name
function checkDOB(m, form1, box1){
	n=m.name;
	//b1=document.forms[0].elements[n]
	b1=m
	form2 = form1
	box2 = box1

	ValidateDOB()
}
function isNumeric(val){
	var result = val.match(/^-?\d+$/);
	return (result != null);


}

function checkEmail(TheNumber) {

	var at="@"
	var dot="."
	var lat=TheNumber.indexOf(at)
	var lstr=TheNumber.length
	var ldot=TheNumber.indexOf(dot)
	var valid=true

	if (TheNumber.indexOf(at)==-1){
		valid = false
	}

	if (TheNumber.indexOf(at)==-1 || TheNumber.indexOf(at)==0 || TheNumber.indexOf(at)==lstr){
		valid = false
	}

	if (TheNumber.indexOf(dot)==-1 || TheNumber.indexOf(dot)==0 || TheNumber.indexOf(dot)==lstr){
		valid = false
	}

	if (TheNumber.indexOf(at,(lat+1))!=-1){
		valid = false
	}

	if (TheNumber.substring(lat-1,lat)==dot || TheNumber.substring(lat+1,lat+2)==dot){
		valid = false
	}

	if (TheNumber.indexOf(dot,(lat+2))==-1){
		valid = false
	}

	if (TheNumber.indexOf(" ")!=-1){
		valid = false
	}

	return valid
}



function CheckDate(TheNumber)
{
	var valid = true


	if(!isNumeric(TheNumber.charAt(0)))
	valid=false

	if(!isNumeric(TheNumber.charAt(1)))
	valid=false

	if(TheNumber.charAt(2) != "/")
	valid = false

	if(!isNumeric(TheNumber.charAt(3)))
	valid=false

	if(!isNumeric(TheNumber.charAt(4)))
	valid=false

	if(TheNumber.charAt(5) != "/")
	valid = false

	if(!isNumeric(TheNumber.charAt(6)))
	valid=false

	if(!isNumeric(TheNumber.charAt(7)))
	valid=false

	if(!isNumeric(TheNumber.charAt(8)))
	valid=false

	if(!isNumeric(TheNumber.charAt(9)))
	valid=false

	return valid
}

function CheckPhoneNumber(TheNumber)
{
	var valid = true

	if(TheNumber.charAt(0) != "(")
	valid = false

	if(!isNumeric(TheNumber.charAt(1)))
	valid=false

	if(!isNumeric(TheNumber.charAt(2)))
	valid=false

	if(!isNumeric(TheNumber.charAt(3)))
	valid=false

	if(TheNumber.charAt(4) != ")")
	valid = false

	if(!isNumeric(TheNumber.charAt(5)))
	valid=false

	if(!isNumeric(TheNumber.charAt(6)))
	valid=false

	if(!isNumeric(TheNumber.charAt(7)))
	valid=false

	if(TheNumber.charAt(8) != "-")
	valid = false

	if(!isNumeric(TheNumber.charAt(9)))
	valid=false

	if(!isNumeric(TheNumber.charAt(10)))
	valid=false

	if(!isNumeric(TheNumber.charAt(11)))
	valid=false

	if(!isNumeric(TheNumber.charAt(12)))
	valid=false

	return valid
}




/*
var http = createRequestObject();

var isClean
function checkforBannedWords(obj){

	http.open('GET', 'ajax.php?method=isCleanLanguage&message=' + obj.value);
	http.onreadystatechange = handlecheckBadWords;

	if(isClean == "clean"){
		obj.className = 'inputbox';
		alert(obj.value)
	} else {

		obj.className = 'inputboxerror';
		alert('Inappropriate language in message!\n');
	}
	http.send(null);


}

function handlecheckBadWords() {
	if(http.readyState == 4){ //Finished loading the response
		isClean = http.responseText

	}

}

*/

function popUp(targethtml, width, height)
{
      var nw=window.open(targethtml,"","width="+width+"px,height="+height+"px,scrollbars,resizable")
}


function VerifyLoginMenuData()
{
	var valid = true
	var focus = ""
	var count = 0
	var message = ''


	if (document.LoginFormMenu.username.value == "") {
		document.LoginFormMenu.username.className = 'inputboxerror';
		valid = false
		count++
		if(focus == null)
		focus = 'username'
		message += 'Username \n'
	}
	else{
		document.LoginFormMenu.username.className = 'inputbox';
	}



	if (document.LoginFormMenu.password.value == "") {
		document.LoginFormMenu.password.className = 'inputboxerror';
		valid = false
		count++
		if(focus == null)
		focus = 'password'
		message += 'Password \n'
	}
	else{
		document.LoginFormMenu.password.className = 'inputbox';
	}

	if (!valid)
	{

		if(count == 1){
			alert("Please complete this field! \n\n" + message)
		} else {
			alert("Please complete these fields! \n\n" + message)
		}
	}
	return valid
}


function getCreditianlNumberInfo(formname, boxid, phppage, dob, ssn){
	textbox = boxid;
	formbox = formname;
	var valuepath = eval("document." + formname + "." + boxid);
	http.open('get', phppage + '.php?credentialnumber=' + valuepath.value + '&dob=' + dob + '&ssn=' + ssn);
	http.onreadystatechange = handleCreditianlNumberInfo;
	http.send(null);
}

function capitalizeMe(obj) {
	val = obj.value;
	newVal = '';
	val = val.split(' ');
	newVal = val[0].substring(0,1).toUpperCase();

	obj.value = newVal;
}

function CheckExpiredDate(val) {
	var month = val.charAt(0) + val.charAt(1)
	var day = val.charAt(3) + val.charAt(4);
	var year = val.charAt(6) + val.charAt(7) + val.charAt(8) + val.charAt(9)
	month = month -1
	var myDate=new Date()

	myDate.setFullYear(year,month,day)
	var today = new Date()

	if (myDate<today)
	return false
	else
	return true

}


function createRequestObject(){
	var request_o; //declare the variable to hold the object.
	var browser = navigator.appName; //find the browser name
	if(browser == "Microsoft Internet Explorer"){
		/* Create the object using MSIE's method */
		request_o = new ActiveXObject("Microsoft.XMLHTTP");
	}else{
		/* Create the object using other browser's method */
		request_o = new XMLHttpRequest();
	}
	return request_o; //return the object
}


function checkMessage(obj){
	http.open('GET', 'ajax.php?method=isCleanLanguage&message=' + obj.value);
	http.onreadystatechange = handleMessage;
	http.send(null);

}

function trimTextarea(val, maxlength){
	return val.substr(0,maxlength)

}

function verifyTextAreaSize(m,maxlength) {
	if(m.value.length > maxlength) {
		alert("This field will only hold " + maxlength + " characters!")
		m.value = trimTextarea(m.value, maxlength)
	}

}