var submitcount = 0;

function checksubmitcount() {

    if (submitcount == 0) {
        submitcount++;
        return true;
    }
    else {
        alert("Please click only once.");
        return false;
    }

}

function checkAlert() {
    alert("Attention! This site is under maintenance now. Please come back again later. Sorry for the inconvenience caused.");
}
function MM_preloadImages() {
    var d = document; if (d.images) {
        if (!d.MM_p) d.MM_p = new Array();
        var i, j = d.MM_p.length, a = MM_preloadImages.arguments; for (i = 0; i < a.length; i++)
            if (a[i].indexOf("#") != 0) { d.MM_p[j] = new Image; d.MM_p[j++].src = a[i]; } 
    }
}
function MM_swapImgRestore() {
    var i, x, a = document.MM_sr; for (i = 0; a && i < a.length && (x = a[i]) && x.oSrc; i++) x.src = x.oSrc;
}
function MM_findObj(n, d) {
    var p, i, x; if (!d) d = document; if ((p = n.indexOf("?")) > 0 && parent.frames.length) {
        d = parent.frames[n.substring(p + 1)].document; n = n.substring(0, p);
    }
    if (!(x = d[n]) && d.all) x = d.all[n]; for (i = 0; !x && i < d.forms.length; i++) x = d.forms[i][n];
    for (i = 0; !x && d.layers && i < d.layers.length; i++) x = MM_findObj(n, d.layers[i].document);
    if (!x && d.getElementById) x = d.getElementById(n); return x;
}
function MM_swapImage() {
    var i, j = 0, x, a = MM_swapImage.arguments; document.MM_sr = new Array; for (i = 0; i < (a.length - 2); i += 3)
        if ((x = MM_findObj(a[i])) != null) { document.MM_sr[j++] = x; if (!x.oSrc) x.oSrc = x.src; x.src = a[i + 2]; }
}
function MM_jumpMenu(targ, selObj, restore) {
    var targetURL = selObj.options[selObj.selectedIndex].value;
    if (targetURL != '0') {
        eval(targ + ".location='" + targetURL + "'");
        if (restore) selObj.selectedIndex = 0;
    }
}
function checkMandatory(field, fieldName) {
    if (trim(field.value) == '') {
        alert(fieldName + ' field is required. Please specify ' + fieldName + '.');
        field.focus();
        return false;
    }
    else {
        return true;
    }
}
function validateEmail(field, fieldName) {
    var emailStr = field.value;

    if (checkEmail(emailStr) == false) {
        alert(fieldName + ' is not a valid email address. Please re-enter ' + fieldName + '.');
        field.focus();
        return false;
    }
    else {
        return true;
    }
}
function updateWordCounter(textArea, maxLength) {
    var remarksTextField = textArea;
    var wordCounterId = remarksTextField.name + '-wordCounter';
    var wordCounter = document.getElementById(wordCounterId);

    limitTextField(remarksTextField, wordCounter, maxLength);
}
function calculateLength(wordCounter, maxLength) {
    var wordCounterId = wordCounter.id;

    str = wordCounterId.split("-");

    var textAreaId = str[0];

    var textArea = document.getElementById(textAreaId);

    var newValue = maxLength - textArea.value.length;
    wordCounter.innerHTML = newValue;
}
function clearDate(dateField) {
    document.getElementById(dateField).value = '';
}
function limitTextField(textField, wordCounterField, maxLength) {
    if (textField.value.length > maxLength)
        textField.value = textField.value.substring(0, maxLength);
    else
        wordCounterField.innerHTML = maxLength - textField.value.length;
}
function trim(s) {
    return s.replace(/^\s*/, "").replace(/\s*$/, "");
}
function allowNumericOnly(textField) {
    var sText = textField.value;

    if (isNumeric(sText) == false) {
        textField.value = textField.value.substring(0, sText.length - 1);
    }
}
function formatDollarField(textField) {
    var sText = textField.value;

    textField.value = extendField(sText, 2);
}
function extendField(Q, N) {
    var P
    Q = String(Q); if (/e/i.test(Q)) { return Q }
    while ((P = Q.indexOf('.')) < 0) Q += '.'
    while (Q.length <= P + N) Q += '0'
    return Q
}
function allowDecimalOnly(textField) {
    var sText = textField.value;
    isDecimal(textField);
}
function isDecimal(textField) {
    sText = textField.value;
    var ValidChars = "0123456789.";
    var IsDecimal = true;
    var Char;
    var startCountingDecimal = false;

    var dotCounter = 0;
    var decimalCounter = 0;

    for (i = 0; i < sText.length && IsDecimal == true; i++) {
        Char = sText.charAt(i);
        if (ValidChars.indexOf(Char) == -1) {
            IsDecimal = false;
            sText = sText.substring(0, i) + sText.substring(i + 1, sText.length);
        }

        if (startCountingDecimal) {
            decimalCounter = decimalCounter + 1;
        }

        if (Char == '.') {
            dotCounter = dotCounter + 1;
            startCountingDecimal = true;
        }


        if (decimalCounter > 2) {
            IsDecimal = false;
            sText = sText.substring(0, i) + sText.substring(i + 1, sText.length);
        }

        if (dotCounter > 1) {
            IsDecimal = false;
            sText = sText.substring(0, i) + sText.substring(i + 1, sText.length);
        }
    }

    if (dotCounter > 1) {
        IsDecimal = false;
    }

    if (startCountingDecimal > 2) {
        IsDecimal = false;
    }

    if (IsDecimal == false) {
        textField.value = sText;
    }
    return false;
}
function isNumeric(sText) {
    var ValidChars = "0123456789";
    var IsNumber = true;
    var Char;

    for (i = 0; i < sText.length && IsNumber == true; i++) {
        Char = sText.charAt(i);
        if (ValidChars.indexOf(Char) == -1) {
            IsNumber = false;
        }
    }

    return IsNumber;
}
function avoidSubmitWhenEnter(e) {
    var characterCode;

    if (e && e.which) {
        e = e;
        characterCode = e.which;
    }
    else {
        e = event;
        characterCode = e.keyCode;
    }

    if (characterCode == 13) {
        return false;
    }
    else {
        return true;
    }
}
function checkEmail(emailStr) {

    if (emailStr.length == 0) {
        return true;
    }
    var emailPat = /^(.+)@(.+)$/;
    var specialChars = "\\(\\)<>@,;:\\\\\\\"\\.\\[\\]";
    var validChars = "\[^\\s" + specialChars + "\]";
    var quotedUser = "(\"[^\"]*\")";
    var ipDomainPat = /^(\d{1,3})[.](\d{1,3})[.](\d{1,3})[.](\d{1,3})$/;
    var atom = validChars + '+';
    var word = "(" + atom + "|" + quotedUser + ")";
    var userPat = new RegExp("^" + word + "(\\." + word + ")*$");
    var domainPat = new RegExp("^" + atom + "(\\." + atom + ")*$");
    var matchArray = emailStr.match(emailPat);
    if (matchArray == null) {
        return false;
    }
    var user = matchArray[1];
    var domain = matchArray[2];
    if (user.match(userPat) == null) {
        return false;
    }
    var IPArray = domain.match(ipDomainPat);
    if (IPArray != null) {
        for (var i = 1; i <= 4; i++) {
            if (IPArray[i] > 255) {
                return false;
            }
        }
        return true;
    }
    var domainArray = domain.match(domainPat);
    if (domainArray == null) {
        return false;
    }
    var atomPat = new RegExp(atom, "g");
    var domArr = domain.match(atomPat);
    var len = domArr.length;
    if ((domArr[domArr.length - 1].length < 2) ||
	  (domArr[domArr.length - 1].length > 3)) {
        return false;
    }
    if (len < 2) {
        return false;
    }
    return true;
}

var message = "Right Click Disabled!";

function clickIE4() {
    if (event.button == 2) {
        return false;
    }
}

function clickNS4(e) {
    if (document.layers || document.getElementById && !document.all) {
        if (e.which == 2 || e.which == 3) {
            return false;
        }
    }
}

if (document.layers) {
    document.captureEvents(Event.MOUSEDOWN);
    document.onmousedown = clickNS4;
}
else if (document.all && !document.getElementById) {
    document.onmousedown = clickIE4;
}

/*
document.oncontextmenu=new Function("return false")
*/

function hidestatus() {
    window.status = ''
    return true
}

if (document.layers)
    document.captureEvents(Event.MOUSEOVER | Event.MOUSEOUT | Event.MOUSEDOWN)

document.onmouseover = hidestatus
document.onmouseout = hidestatus
document.onmousedown = hidestatus


function startclock() {
    var thetime = new Date();

    var nhours = thetime.getHours();
    var nmins = thetime.getMinutes();
    var nsecn = thetime.getSeconds();
    var nday = thetime.getDay();
    var nmonth = thetime.getMonth();
    var ntoday = thetime.getDate();
    var nyear = thetime.getYear();
    var AorP = " ";

    if (nhours >= 12)
        AorP = "PM";
    else
        AorP = "AM";

    if (nhours >= 13)
        nhours -= 12;

    if (nhours == 0)
        nhours = 12;

    if (nsecn < 10)
        nsecn = "0" + nsecn;

    if (nmins < 10)
        nmins = "0" + nmins;

    if (nday == 0)
        nday = "Sunday";
    if (nday == 1)
        nday = "Monday";
    if (nday == 2)
        nday = "Tuesday";
    if (nday == 3)
        nday = "Wednesday";
    if (nday == 4)
        nday = "Thursday";
    if (nday == 5)
        nday = "Friday";
    if (nday == 6)
        nday = "Saturday";

    nmonth += 1;

    if (nmonth == 1)
        nmonth = "January";
    if (nmonth == 2)
        nmonth = "February";
    if (nmonth == 3)
        nmonth = "March";
    if (nmonth == 4)
        nmonth = "April";
    if (nmonth == 5)
        nmonth = "May";
    if (nmonth == 6)
        nmonth = "June";
    if (nmonth == 7)
        nmonth = "July";
    if (nmonth == 8)
        nmonth = "August";
    if (nmonth == 9)
        nmonth = "September";
    if (nmonth == 10)
        nmonth = "October";
    if (nmonth == 11)
        nmonth = "November";
    if (nmonth == 12)
        nmonth = "December";



    if (nyear <= 99)
        nyear = "19" + nyear;

    if ((nyear > 99) && (nyear < 2000))
        nyear += 1900;

    document.getElementById("clockspot").innerHTML = nday + ", " + ntoday + " " + nmonth + " " + nyear + ", " + nhours + ":" + nmins + ":" + nsecn + " " + AorP;

    setTimeout('startclock()', 1000);

}


var is = new Is();
var bollaBalloonWidth;
function maketheBalloon(id, width, message) {
    bollaBalloonWidth = width;
    var theString = '<STYLE TYPE="text/css">#' + id + '{width:' + width + ';}</STYLE>';
    theString += '<DIV CLASS="txt_balloon" id="' + id + '">' + message + '</DIV>';
    document.write(theString);
}

function makeItVisible(id, event) {
    if (is.nav4up) {
        document.layers[id].left = event.pageX + 10;
        document.layers[id].top = event.pageY + 10; ;
        document.layers[id].visibility = "show";
    }
    else {
        document.all[id].style.pixelLeft = (document.body.scrollLeft + event.clientX) + 10;
        document.all[id].style.pixelTop = (document.body.scrollTop + event.clientY) + 10;
        document.all[id].style.visibility = "visible";
    }
}

function makeItVisibleLeft(id, event) {
    if (is.nav4up) {
        document.layers[id].left = event.pageX + 10;
        document.layers[id].top = event.pageY + 10; ;
        document.layers[id].visibility = "show";
    }
    else {
        document.all[id].style.pixelLeft = (document.body.scrollLeft + event.clientX) - bollaBalloonWidth;
        document.all[id].style.pixelTop = (document.body.scrollTop + event.clientY) + 10;
        document.all[id].style.visibility = "visible";
    }
}

function makeItVisibleCustom(id, event, plusAmt, minusAmt) {
    if (is.nav4up) {
        document.layers[id].left = event.pageX + 10;
        document.layers[id].top = event.pageY + 10; ;
        document.layers[id].visibility = "show";
    }
    else {
        document.all[id].style.pixelLeft = (document.body.scrollLeft + event.clientX) + plusAmt - minusAmt;
        document.all[id].style.pixelTop = (document.body.scrollTop + event.clientY) + 10;
        document.all[id].style.visibility = "visible";
    }
}

function hideHelp(id) {
    is.nav4up ? document.layers[id].visibility = "hide" : document.all[id].style.visibility = "hidden";
}

function Is() {
    var agt = navigator.userAgent.toLowerCase()
    this.major = parseInt(navigator.appVersion)

    this.nav = ((agt.indexOf('mozilla') != -1) && ((agt.indexOf('spoofer') == -1)
                && (agt.indexOf('compatible') == -1)))
    this.nav4 = (this.nav && (this.major == 4))
    this.nav4up = this.nav && (this.major >= 4)

    this.ie = (agt.indexOf("msie") != -1)
    this.ie4 = (this.ie && (this.major == 4))
    this.ie4up = this.ie && (this.major >= 4)
}


