﻿// JScript File

function getElement(elName){
    var e = document.getElementById(elName);
    if (!e){
        e =document.getElementById("ctl00_" + elName);
        if (!e){
            e =document.getElementById("ctl00_ContentPlaceHolder1_" + elName);
        }
    }
    return(e);
}

function HighlightButton(e){

    if (e.target){
        var src = e.target;
    }
    else{
        var	src = e.srcElement;
    }

    var ext="gif";
    if (src.getAttribute("imext")) {
        ext=src.getAttribute("imext");
    }
    if (ext==null) ext="gif";

    src.src = "images/" + src.getAttribute("btnbase") + "_high." + ext;
    
}

function UnHighlightButton(e){

    if (e.target){
        var src = e.target;
    }
    else{
        var	src = e.srcElement;
    }

    var ext="gif";
    if (src.getAttribute("imext")) ext=src.getAttribute("imext");
    if (ext==null) ext="gif";

    src.src = "images/" + src.getAttribute("btnbase") + "." + ext;
    return;
}


function trim(sString){
//javascript trim function.
	var sValue = sString;

	if(typeof(sString) != "string")
		return (sString.toString());
				
	while(sValue.substring(0,1) == " " || sValue.substring(0,1) == String.fromCharCode(160)){
		sValue = sValue.substr(1);
	}
	while (sValue.substring( (sValue.length - 1) , (sValue.length) ) == " "){
		sValue = sValue.substring(0 , (sValue.length - 1) );
	}
	return sValue;
}

function fnIsAllowableCharCode(){
	if (!window.event.srcElement.AllowableCharCode) return false;
	var sAllowCharCodes = window.event.srcElement.AllowableCharCode.toString();
	var arrCharCodes = sAllowCharCodes.split(",");
	if (event.keyCode==8) return(true)// always allow backspace
	for(var i=0; i<arrCharCodes.length; i++) {
		if (parseInt(arrCharCodes[i]) == event.keyCode) return true;
	}
	return false;
}
function fnIsAllowableChar(){
	if (!window.event.srcElement.AllowableChar) return false;
	var sAllowChars = window.event.srcElement.AllowableChar.toString();
	var arrChars = sAllowChars.split(",");
	if (event.keyCode==8) return(true)// always allow backspace 
	for(var i=0; i<arrChars.length; i++) {
		var sChar=arrChars[i].toString();
		if (parseInt(sChar.charCodeAt(0)) == event.keyCode) return true;
	}
	return false;
}


function fnFilterKeys() {
//
//	noChar			- no a-z, A-Z
//	noNum			- no 0 - 9
//	noUpperAscii		- no keys with ascii code greater than 128
//	noPunctuation		- no non-alpha keys, such as <!--`~!@#$%^&*()-_=+\|]}[{'";:/?.,-->
//	noCutCopy			- no ctrl-c, ctrl-C, ctrl-x, ctrl-X
//	noPaste			- no ctrl-v, ctrl-V
//	noSpace			- no spacebar
//	AllowableChar		- a comma separated list of characters that supercede the other rules
//	AllowableCharCode	- a comma separated list of ascii codes for characters that supercede the other rules
//	e.g. noChar="1" AllowableChar="a,A,b,B,c,C" AllowableCharCode="13,37"  //44=Comma, 13=Enter key, 37=% key
//   ex: <input name="ID" onkeypress="if (fnFilterKeys()) fnDefaultAction();" noChar='1' AllowableCharCode="13" AllowableChar="%,#,$">

	var Key = event.keyCode;
	var	src = window.event.srcElement;
	if (fnIsAllowableCharCode()) return(true);
	if (fnIsAllowableChar()) return(true);

	// if Home or End
	if (Key == 35 || Key ==36) return(true);
	
	if ( (src.noNum == "1" && (Key < 65 || Key > 122 || (Key > 90 && Key < 97))) ||
	     (src.noChar == "1" && (Key < 48 || Key >57)) ||  
	     (src.noUpperAscii == "1" && (Key < 65 || Key > 90)) ||
	     (src.noPunctuation == "1" && (Key < 48 || (Key > 57 && Key < 65) || (Key > 90 && Key < 97) || Key > 122)) ||
	     (src.noCutCopy == "1" && event.ctrlKey && (Key == 67 || Key == 88 || Key == 99 || Key == 120)) || // Ctrl C, Ctrl X
	     (src.noPaste == "1" && event.ctrlKey && (Key == 86 ||  Key == 118)) ||	// Ctrl V
	     (src.noSpace == "1" && Key == 32)) {
			event.returnValue = false;
			return(false);
	}
	return(true);
}
