function onblurTEXTAREA(max,id,text_value){
	if(trimStr(text_value).length >= max){
		/* The value in the text field is too long trim it to length */
		document.getElementById(id).value = text_value.substring(0,max);
	}
}

function maxlengthTEXTAREA(e,max,text_value){
	/* This error traps the event passed to this function */
	if(typeof(e) == "undefined"){
		/* The there is no event */
		return(false);
	}
	
	/* This is the regular expression that only alows printable characters */
	reg = /^[A-Za-z0-9!@#$%^&*()~`_+-=<,>.?\"'|\\{}[\]\n\f\r\t\v]/;
	
	/* This holds if the character entered is a printing character or not */
	var printing_char;
	
	if(!(typeof(e.charCode) == 'undefined')){
		/* NS 6+ & Mozilla 0.9+ */
		if(e.charCode == 0){
			/* This is a non printing character allow it through */
			printing_char = false;
		}
		else{
			/* Test if this is an allowable characer */
			printing_char = reg.test(String.fromCharCode(e.charCode));
		}
	}
	else{
		if(!(typeof(e.keyCode) == 'undefined')){
			/* IE & Opera */
			/* Test if this is an allowable characer */
			printing_char = reg.test(String.fromCharCode(e.keyCode));
		}
	}

	if(printing_char && (trimStr(text_value).length >= max)){
		/* This next character would put this field over its limit */
		
		return(false);
	}
	else{
		/* This next character would not add a character to the text field */
		/* Or we are not at the limit for this text field yet */
		return(true);
	}
	
	
}

function NonPrintingKey(key_code){
	switch(key_code)
	{
		/* Back space */
		case 8:
		/* Shift */
		case 16:
		/* Ctrl */
		case 17:
		/* Alt */
		case 18:
		/* Caps */
		case 20:
		/* Left Arrow */
		case 37:
		/* Up Arrow */
		case 38:
		/* Right Arrow */
		case 39:
		/* Down Arrow */
		case 40:
		/* Delete */
		case 46:
		
		/* This was a non printing character */
		return(true);
	}
	/* This was a printing character */
	return(false);
}

function trimStr(str){
	/* Trim leading white spaces */
	while(str.substring(0,1) == " "){
		str = str.substring(1,str.length);
	}
	/* Trim trailing white spaces */
	while (str.substring(str.length-1,str.length) == " "){
		str = str.substring(0,str.length-1);
	}
	/* return the trimmed string. */
	return str;
}

function CheckHexidecimalColor(text){
	var re = /^[A-Fa-f0-9]{6}/; /* This is the regular expression to validate hex numbers. */
	var le = text.length;		/* This is the length of the hexidecimal string. */
	
	/* Check to make sure the text is not too long. */
	if(le>6){
		/* Invalid Hex Number */
		return(false);
	}
	/* Check to make sure the text entered is valid. */
	if(text.search(re)==-1){
		/* Invalid Hex Number */
		return(false);
	}
	
	/* Valid Hex Number */
	return(true);
}

function CheckEmail(text)
{
	/*This function is used for javascript validation on emails*/
	var re  = /^([a-zA-Z0-9_\.\-])+\@(([a-zA-Z0-9\-])+\.)+([a-zA-Z0-9]{2,4})+$/;
	
	if(re.test(text)){return(true);}
	else{return(false);}
}

function KeyPressHexNumbersOnly(e){

	/* This error traps the event passed to this function */
	if(typeof(e) == "undefined"){
		/* The there is no event */
		return(false);
	}
	
	if(!(typeof(e.charCode) == 'undefined')){
		/* NS 6+ & Mozilla 0.9+ */
		if(e.charCode == 0){
			/* This is a non printing character allow it through */
			return(true);
		}
		else{
			reg = /^[A-Fa-f0-9]/;
			return(reg.test(String.fromCharCode(e.charCode)));
		}
	}
	
	if(!(typeof(e.keyCode) == 'undefined')){
		/* DOM */
		reg = /^[A-Fa-f0-9]/;
		return(reg.test(String.fromCharCode(e.keyCode)));
	}
}

function KeyPressNumbersOnly(e){
	/* This error traps the event passed to this function */
 
    if(typeof(e) == "undefined")
    {
		/* The there is no event */
        e.returnValue = false;
	}
	
	if(!(typeof(e.charCode) == 'undefined')){
		/* NS 6+ & Mozilla 0.9+ */
		if(e.charCode == 0){
			/* This is a non printing character allow it through */
	        e.returnValue = true;
		}
		else{
			reg = /\d/;
	        e.returnValue = reg.test(String.fromCharCode(e.charCode));
		}
	}
	
	if(!(typeof(e.keyCode) == 'undefined')){
		/* DOM */
        // alert(e.keyCode);
		reg = /\d/;
        e.returnValue = reg.test(String.fromCharCode(e.keyCode));
	}
}  

function checkNumber(){
    var retValue = true;

    if(parseInt(document.getElementById("txtNumEventAttachmentstext").value) > 20){
        alert('Please enter # of Event Attachments field between 0 to 20');
        document.getElementById("txtNumEventAttachmentstext").value = document.getElementById("hdNumEventAttachmentstext").value;
        retValue = false;
    }
    
    return retValue;
}