/**
* is_valid( TYPE, VALUE );
*
* TYPE:  string that equals one of:
*        "inst", "view", "password", "alpha", "find"
* VALUE: string to validate
*
*/
var type;
var value;
function is_valid ( type, value ) {

    /* validate the programmer's call */
    var type_type = typeof( type );
    if( !type_type.match( /^string$/ ) ) {
        alert( "Error in call to function: is_valid( TYPE, VALUE );\n" +
            "Type is invalid: " + type_type + "( \"" + type + "\" ).\n" +
            "Type must be a string.\n" +
            "(Value = \"" + value + "\" )\n"
            );
        return false;
    }

    /* make the value a string */
    var value_type = typeof( value );
    if( !value_type.match( /^string$/ ) ) {
        if( value_type.match( /^number$/ ) ) value = value.toString();
        else                                 value = ""; }

    /* validate value by type */
    if( type == "view" ) {
        if( value.match( /^(scholar|library|high-school|teen|kids)$/ ) ) return true;
        else return false; }
    if( type == "inst" ) {
        if( value.match( /^[a-z0-9]{4}.[-a-z0-9]+$/ ) ) return true;  /* special inst cookie format */
        else return false; }
    if( type == "password" ) {
        if( value.match( /^[a-zA-Z0-9]{3,12}$/ ) ) return true;  /* 3-12 characters */
        else return false; }
    if( type == "alpha" ) {
        if( value.match( /^[a-zA-Z0-9]$/ ) ) return true;  /* one character */
        else return false; }
    if( type == "find" ) {
        if( value.match( /^.+$/ ) ) return true;  /* non-null */
        else return false; }
    if( type == "status" ) {
        if( value.match( /^.+$/ ) ) return true;  /* non-null */
        else return false; }
    if( type == "path" ) {
        if( value.match( /^\/[-\/._a-zA-Z0-9]*$/ ) ) return true;  /* e.g., /scholar/uga/search/ */
        else return false; }
    if( type == "url" ) {
        if( value.match( /^[-\/:._a-zA-Z0-9%?=+&; ]+$/ ) ) return true;  /* e.g., http://www.google.com/ */
        else return false; }
    if( type == "year" ) {
        if( value.match( /^[0-9]{4}$/ ) ) return true;  /* e.g., 2007 */
        else return false; }
    if( type == "string" ) {
        if( value.match( /^.+$/ ) ) return true;  /* non-null */
        else return false; }

    /* validate the programmer's call */
    alert( "Error in call to function: is_valid( TYPE, VALUE );\n" +
        "Type is not recognized: " + type_type + "( \"" + type + "\" ).\n" +
        "(Value = \"" + value + "\" )\n" );
    
    return false;
}

function mapper() { document.getElementById("maps").setAttribute('value', 'pixel'); return true }

