this.window.name="main";

function swapImage(imgName,imgURL){
    if (imgURL.length>0) {
        document.images[imgName].src = imgURL;
    }
}

function maildecode(coded) {
    coded = coded.replace('%','@');
    decoded = coded.replace('|','.');
    document.write('<a href=mailto:' + decoded  + '>' + decoded + '</a>');
}

function maildecode(coded) {
    coded = coded.replace('%','@');
    decoded = coded.replace('|','.');
    if (maildecode.arguments.length>1) {
        text=maildecode.arguments[1];
    } else {
        text = decoded;
    }
    document.write('<a href=mailto:' + decoded  + '>' + text + '</a>');
}

function validateEmail(teststring) {
    atplace=teststring.indexOf('@');
    dotplace=teststring.lastIndexOf('.');
    if (teststring.length <1) {
        alert ("You must enter an Email address");
        return false;
    }
    if  ( ((atplace == -1) || (dotplace == -1)) || (atplace > dotplace)) {
        alert ("Email address is invalid.");
        return false;
    }
    return true;
}

function validateLogin(form) {
    with (form) {
        if (!validateEmail(email.value)) {
            email.focus();
            return false;
        }
    }
    return true;
}

function notValidEmail (teststring) {
    atplace=teststring.indexOf('@');
    dotplace=teststring.lastIndexOf('.');
    if (teststring.length <1) {
        alert ("You must enter an Email address");
        return true;
    }
    if  ( ((atplace == -1) || (dotplace == -1)) || (atplace > dotplace)) {
        alert ("Email address is invalid.\nCorrect Example: 'bob@bobdomain.com'");
        return true;
    }
    return false;
}

function mklnk(url,lnk,b) {
    pre='';
    xtr='';
    if (b > 0) { pre = 'http://'; } 
    if (b==2) { xtr = 'target="_blank"'; }
    document.write('<a href=' + pre + url + ' ' + xtr  + '>' + lnk + '</a>');
}

function mkLinkNl(url,lnk) {
    document.write('<a href="' + url + '" class="nl">' + lnk + '</a>');
}

function catOut(id) {
    if (document.getElementById) {
        document.getElementById(id).style.backgroundColor = '#ffffe9';
    }
}

function catOver(id) {
    if (document.getElementById) {
        document.getElementById(id).style.backgroundColor = '#f3f3dd';
    }
}

var oldBck = "#ffffff";
function dynamicRowBkgOut(element) {
    element.style.backgroundColor = oldBck;
}

function dynamicRowBkgOver(element) {
    oldBck = element.style.backgroundColor;
    element.style.backgroundColor = "#f3f3dd";
}

var ns6 = document.getElementById&&!document.all

function restrictinput(maxlength, e, placeholder){
    if (window.event&&event.srcElement.value.length>=maxlength) {
        return false;
    } else if (e.target&&e.target==eval(placeholder)&&e.target.value.length>=maxlength){
        var pressedkey=/[a-zA-Z0-9\.\,\/]/ //detect alphanumeric keys
        if (pressedkey.test(String.fromCharCode(e.which)))
            e.stopPropagation()
        }
    }

    function countlimit(maxlength, e, placeholder){
        var theField = eval(placeholder)
        var lengthleft = maxlength-theField.value.length
        var placeholderobj = document.all? document.all[placeholder] : document.getElementById(placeholder)
        if (window.event||e.target&&e.target == eval(placeholder)){
        if (lengthleft<0) {
            theField.value = theField.value.substring(0,maxlength)
        }
        placeholderobj.innerHTML=lengthleft
    }
}

function setLimit(maxlength, placeholder){
    var theField = eval(placeholder)
    var lengthleft = maxlength - theField.value.length
    var placeholderobj = document.all? document.all[placeholder] : document.getElementById(placeholder)
    placeholderobj.innerHTML = lengthleft
}

function displaylimit(theField, thelimit){
    var limit_text='<b class="txt1_ob"><span id="' + theField + '">' + thelimit + '</span></b> characters remaining'
    if (document.all||ns6)
        document.write(limit_text)
    if (document.all){
        eval(theField).onkeypress=function(){ return restrictinput(thelimit, event, theField)}
        eval(theField).onkeyup=function(){ countlimit(thelimit, event, theField)}
    } else if (ns6) {
        document.body.addEventListener('keypress', function(event) { restrictinput(thelimit,event,theField) }, true);
        document.body.addEventListener('keyup', function(event) { countlimit(thelimit,event,theField) }, true);
    }
    setLimit(thelimit, theField);
}
