// JavaScript Document

<!--
	function expand(param)
	{
		document.getElementById(param).style.display=(document.getElementById(param).style.display=="none")?"":"none";
	}	
	
	function FormatNumber(num, format, shortformat) {
    var length = num.value.length;
    e = window.event;

    if (typeof (e.keyCode) == 'number') {
        //DOM
        e = e.keyCode;
    }
    else if (typeof (e.which) == 'number') {
        //NS 4 compatible
        e = e.which;
    }
    else if (typeof (e.charCode) == 'number') {
        //also NS 6+, Mozilla 0.9+
        e = e.charCode;
    } else {
        //total failure, we have no way of obtaining the key code
        return;
    }

    //allow postback for carriage return when APN has more than 4 gidits
    // (5 including a "-").
    // forget about it, currently it works when a full APN is entered.
    /*
    if (e == 13 && length >= 5)  
    {
    alert(length);
    //__dopostback("btnSearch", "");   
    document.forms[0].submit();
    }*/

    if (e == 8)  //backspace
    {
    }
    //else {
        /*if (length > format.length) {
            num.value = Left(num.value, format.length);
        }*/
        else {
            FormatAnyNumber(num, format, shortformat);
        }
    //}
}


function FormatAnyNumber(num, format, shortformat) {
    if (format == null) {
        format = "(###) ###-#### ";
    }
    if (shortformat == null) {
        var shortformat = "";
    }

    var validchars = "0123456789";
    var tempstring = "";
    var returnstring = "";
    var extension = "";
    var tempstringpointer = 0;
    var returnstringpointer = 0;
    count = 0;

    var length = num.value.length;

    if (length > format.length) {
        length = format.length;
        num.value = Left(num.value, format.length);
    };

    for (var x = 0; x < length; x++) {
        if (validchars.indexOf(num.value.charAt(x)) != -1) {
            tempstring = tempstring + num.value.charAt(x);
        };
    };
    if (num.value.length > format.length) {
        length = format.length;
        extension = num.value.substr(format.length, (num.value.length - format.length));
    };

    for (x = 0; x < shortformat.length; x++) {
        if (shortformat.substr(x, 1) == "#") {
            count++;
        };
    }
    if (tempstring.length <= count) {
        format = shortformat;
    };
    for (x = 0; x < format.length; x++) {
        if (tempstringpointer <= tempstring.length) {
            if (format.substr(x, 1) == "#") {
                returnstring = returnstring + tempstring.substr(tempstringpointer, 1);
                tempstringpointer++;
            } else {
                returnstring = returnstring + format.substr(x, 1);
            }
        }

    }
    returnstring = returnstring + extension;
    num.value = returnstring;
}

	
//-->


