/*************************************************************************************************************/
//Javascript for form validations
//By Charles Bastian
//07.2009
//Hill College Web Systems Technician
//Last Updated: 1.26.2010
/*************************************************************************************************************/


function patchForAJAX(data){
	var oldValue = data;
	var newValue=oldValue;
	
	/* fix & symbols */
	var found = 0;
	while (found!=-1){
		found=oldValue.indexOf("&amp;",found)
		if(found >-1){
			newValue = oldValue.replace("&amp;",'__ampersand__');
			found++
		}
		found-1
		oldValue=newValue;
	}
	
	/* Fix Spaces */
	found=0;
	while(found!=-1){
		found=oldValue.indexOf("&nbsp;",found)
		if(found >-1){
			newValue = oldValue.replace("&nbsp;",'__space__');
			found++
		}
		found-1
		oldValue=newValue;
	}
	
	/* Fix apostrophes */
	found=0;
	while(found!=-1){
		found=oldValue.indexOf("&nbsp;",found)
		if(found >-1){
			newValue = oldValue.replace("&#39;",'__apostrophe__');
			found++
		}
		found-1
		oldValue=newValue;
	}
	
	/* Final fix for & symbols */
	found=0;
	while(found!=-1){
		found=oldValue.indexOf("&",found)
		if(found >-1){
			newValue = oldValue.replace("&",'__ampersand__');
			found++
		}
		found-1
		oldValue=newValue;
	}
	return oldValue;
}
// Usage: onkeypress="return isNumberKey(event,this);"
function isNumberKey(e,that)
{
	var charCode = (e.which) ? e.which : e.keyCode
	if ((charCode == 8) || (charCode > 47 && charCode < 58) || (charCode == 9)){
		return true;
	}else{
		return false;
	}
}

//Usage: onkeypress="return isLetterKey(event,this);"
function isLetterKey(e,that){
	var charCode = (e.which) ? e.which : e.keyCode
	if ((charCode > 64 && charCode < 91) || (charCode > 96 && charCode < 123) || (charCode == 8) || (charCode == 9)){
		return true;
	}else{
		return false;
	}
}

//Usage: onkeypress="return isStudentEmailUsernameKey(event,this);"
function isStudentEmailUsernameKey(e,that){
	var charCode = (e.which) ? e.which : e.keyCode
	if ((charCode > 64 && charCode < 91) || (charCode > 96 && charCode < 123) || (charCode == 46) || (charCode == 8) || (charCode == 9)){
		return true;
	}else{
		return false;
	}
}

//Usage: onkeypress="return isLetterOrNumberKey(event,this);"
function isLetterOrNumberKey(e,that){
	var charCode = (e.which) ? e.which : e.keyCode
	if ((charCode > 64 && charCode < 91) || (charCode > 96 && charCode < 123) || (charCode > 47 && charCode < 58) || (charCode == 8) || (charCode == 9) || (charCode == 32)){
		return true;
	}else{
		return false;
	}
}

//Usage: onkeypress="return isLetterOrSpaceKey(event,this);"
function isLetterOrSpaceKey(e,that){
	var charCode = (e.which) ? e.which : e.keyCode
	if ((charCode > 64 && charCode < 91) || (charCode > 96 && charCode < 123) || (charCode == 8) || (charCode == 9) || (charCode == 32)){
		return true;
	}else{
		return false;
	}
}

//Usage: onkeypress="return isCityStateFieldKey(event,this);"
function isCityStateFieldKey(e,that){
	var charCode = (e.which) ? e.which : e.keyCode
	if ((charCode > 64 && charCode < 91) || (charCode > 96 && charCode < 123) || (charCode == 8) || (charCode == 9) || (charCode == 32) || (charCode == 44)){
		if(charCode == 44){
			a=that.value;
			if(a.indexOf(",")!="-1"){
				return false;
			}
		}
		return true;
	}else{
		return false;
	}
}

//Usage: onkeypress="return isTextBoxKey(event,this);"
function isTextBoxKey(e,that){
	var charCode = (e.which) ? e.which : e.keyCode;
	//alert(charCode);
	if ((charCode > 64 && charCode < 91) || (charCode > 96 && charCode < 123) || (charCode > 47 && charCode < 58) || (charCode == 8) || (charCode == 9) || (charCode == 32) || (charCode == 44) || (charCode == 46) || (charCode == 33) || (charCode == 63) || (charCode == 13) || (charCode == 38)){
		return true;
	}else{
		return false;
	}
}

// || (charCode == 8) || (charCode == 9)
//Usage: onkeypress="return isDateFieldKey(event,this);"
function isDateFieldKey(e,that){
	var charCode = (e.which) ? e.which : e.keyCode
	if ((charCode > 47 && charCode < 58)){
		if(that.value.length == 7){
			a=that.value;
			if(a.indexOf(".")=="-1"){
				var oldDate = that.value;
				var newDate;
				newDate = (oldDate.substr(0,2)+"."+oldDate.substr(2,2)+"."+oldDate.substr(4,4));
				that.value = newDate;
			}
			return true;
		}else if(that.value.length >= 9){
			if((charCode == 9) || (charCode == 8)){
				return true;
			}else{
				return false;
			}
		}
	}else if(charCode == 8){
		that.value = that.value.replace(".","","g");
		return true;
	}else if(charCode == 9){
		return true;
	}else{
		return false;
	}
}

//Usage: onkeypress="return isAccountFieldKey(event,this);"
function isAccountFieldKey(e,that){
	var charCode = (e.which) ? e.which : e.keyCode
	if ((charCode > 47 && charCode < 58)){
		if(that.value.length == 9){
			a=that.value;
			if(a.indexOf("-")=="-1"){
				var oldAcct = that.value;
				var newAcct;
				newAcct = (oldAcct.substr(0,2)+"-"+oldAcct.substr(2,4)+"-"+oldAcct.substr(6,4));
				that.value = newAcct;
			}
			return true;
		}else if(that.value.length >= 10){
			if((charCode == 9) || (charCode == 8)){
				return true;
			}else{
				return false;
			}
		}
	}else if(charCode == 8){
		that.value = that.value.replace("-","","g");
		return true;
	}else if(charCode == 9){
		return true;
	}else{
		return false;
	}
}

//Usage: onkeypress="return mathNumberKey(event,this);"
function mathNumberKey(e,that){
	var charCode = (e.which) ? e.which : e.keyCode
	if ((charCode > 47 && charCode < 58) || (charCode == 46) || (charCode == 45) || (charCode == 8) || (charCode == 9)){
		if(charCode == 46){
			a=that.value;
			if(a.indexOf(".")!="-1"){
				return false;
			}
		}
		return true;
	}else{
		return false;
	}
}

//Usage: onkeypress="return isGPAFieldKey(event,this);"
function isGPAFieldKey(e,that){
	var charCode = (e.which) ? e.which : e.keyCode
	if ((charCode > 47 && charCode < 58) || (charCode == 8) || (charCode == 9) || (charCode == 46)){
		if(charCode == 46){
			a=that.value;
			if(a.indexOf(".")!="-1"){
				return false;
			}
		}
		return true;
	}else{
		return false;
	}
}

//Usage: onkeypress="return isEmailFieldKey(event,this);"
function isEmailFieldKey(e,that){
	var charCode = (e.which) ? e.which : e.keyCode
	if ((charCode > 64 && charCode < 91) || (charCode > 96 && charCode < 123) || (charCode > 47 && charCode < 58) || (charCode == 8) || (charCode == 9) || (charCode == 64) || (charCode == 95) || (charCode == 46) || (charCode == 33) || (charCode == 45) || (charCode == 43) || (charCode == 94)){
		if(charCode == 64){
			a=that.value;
			if(a.indexOf("@")!="-1"){
				return false;
			}
		}
		if(charCode == 9){
			if(isEmailValid(that)!=true){
				return false;
			}
		}
		return true;
	}else{
		return false;
	}
}

/*	Usage: if(emailValid(item.name) == true)
/*			or
/*			if(emailValid(that)!=true){
/*				return false;
/*			}
 */
function isEmailValid(that){
	var reg = /^([A-Za-z0-9_\-\.\+\^\!])+\@([A-Za-z0-9_\-\.\+\^\!])+\.([A-Za-z]{2,4})$/;
	var address = that.value;
	if(reg.test(address) == false) {
		that.value = "";
		return false;
	}else{
		return true;
	}
}

//Usage: onkeypress="return isMoneyFieldKey(event,this);"
function isMoneyFieldKey(e,that){
	var charCode = (e.which) ? e.which : e.keyCode
	if ((charCode > 47 && charCode < 58) || (charCode == 8) || (charCode == 9) || (charCode == 46)){
		if(charCode == 46){
			a=that.value;
			if(a.indexOf(".")!="-1"){
				return false;
			}
		}
		return true;
	}else{
		return false;
	}
}
function formatCurrency(e,that){
	var i = parseFloat(that.value);
	if(isNaN(i)) { i = 0.00; }
	var minus = '';
	if(i < 0) { minus = '-'; }
	i = Math.abs(i);
	i = parseInt((i + .005) * 100);
	i = i / 100;
	s = new String(i);
	if(s.indexOf('.') < 0) { s += '.00'; }
	if(s.indexOf('.') == (s.length - 2)) { s += '0'; }
	s = minus + s;
	that.value=s;
}

/*************************************************************************************************************/

var message="";

function clickIE(){
	if (document.all){
		(message);
		return false;
	}
}

function clickNS(e){
	if(document.layers||(document.getElementById&&!document.all)){
		if(e.which==2||e.which==3){
			(message);
			return false;
		}
	}
}
if (document.layers){
	document.captureEvents(Event.MOUSEDOWN);
	document.onmousedown=clickNS;
}else{
	document.onmouseup=clickNS;
	document.oncontextmenu=clickIE;
}

document.oncontextmenu=new Function("return false");

//Usage: onkeypress="return checkCharCode(event,this);"
function checkCharCode(e,that){
	var charCode = (e.which) ? e.which : e.keyCode
	alert(charCode);
}

function itemGrabber(that){
	var item = document.getElementById(that);
	return item;
}

function testField(e,that){
	//var charCode = (e.which) ? e.which : e.keyCode;
	//alert(charCode);
	var evtobj=window.event? event : e;
	var unicode=evtobj.charCode? evtobj.charCode : evtobj.keyCode
			alert(evtobj);
	if (evtobj.altKey || evtobj.ctrlKey || evtobj.shiftKey){
		alert("you pressed one of the 'Alt', 'Ctrl', or 'Shift' keys");
	}else if(evtobj.altKey){
		
	}else{
		alert(unicode);
	}
	return false;
}
/*************************************** mysql date/time stuff for secure area athletics ****************************************/
function isMySqlDate(e,that)
{
	var charCode = (e.which) ? e.which : e.keyCode
	if ((charCode == 8) || (charCode > 47 && charCode < 58) || (charCode == 9) || (charCode == 45)){
		return true;
	}else{
		return false;
	}
}
function isMySqlTime(e,that)
{
	var charCode = (e.which) ? e.which : e.keyCode
	if ((charCode == 8) || (charCode > 47 && charCode < 58) || (charCode == 9) || (charCode == 58)){
		return true;
	}else{
		return false;
	}
}
function isMySqlDateTime(e,that)
{
	var charCode = (e.which) ? e.which : e.keyCode
	//alert(charCode);
	if ((charCode == 8) || (charCode > 47 && charCode < 58) || (charCode == 9) || (charCode == 58) || (charCode == 45) || (charCode == 32)){
		return true;
	}else{
		return false;
	}
}

