/****************************************************************
* file: 	zero.js
* author:	toy
* date:		27jan10
* re:		general js utils
*
* rev history
* [toy 27jan10]		orig version
*****************************************************************/
function checkLogin(theForm) {
    errmsg = "";
    fieldname = "";
    flag = false;
    sectionname = "";

    if ((document.getElementById("username").value == "") || (document.getElementById("username").value == "username")) {
        errmsg += "- Username is required.\n";
    }

    if ((document.getElementById("password").value == "") || (document.getElementById("password").value == "password")) {
        errmsg += "- Password is required.\n";
    }

    if (errmsg != "") {
        intro = "There were some issues with your submission: \n";
        alert(intro + errmsg);
        return false;
    }

    return true;
}

/* AJAX */
function LoadPage(filename){
    jQuery.ajax({
        url: filename,
        cache: false,
        success: function(html) {jQuery("#results").html(html);}
    });
}

/*
function $() {
    var elements = new Array();
    for (var i = 0; i < arguments.length; i++) {
        var element = arguments[i];
        if (typeof element == 'string')
            element = document.getElementById(element);
        if (arguments.length == 1)
            return element;
        elements.push(element);
    }
    return elements;
}
*/

// DO NOT ERASE OR DELETE!!!!
function displayPopupDivORIG(e) {

    var posx = 0;
    var posy = 0;
    if (!e) { var e = window.event };

    // determine target DIV
    var targ = e.target ? e.target : e.srcElement;

    // calculate mouse coordinates
    if (e.pageX || e.pageY) {
        posx = e.pageX;
        posy = e.pageY;
    }
    else if (e.clientX || e.clientY) {
        posx = e.clientX;
        posy = e.clientY;
        // check for scroll offsets in IE 6
        if (document.documentElement.scrollLeft || document.documentElement.scrollTop) {
            posx += document.documentElement.scrollLeft;
            posy += document.documentElement.scrollTop;
        }
    }

    // assign attributes to pop-up DIV element and append it to web document tree
    var div = document.getElementById('popup');
    if (!div) {
        var div = document.createElement('div');
        div.setAttribute('id', 'popup');
        div.className = 'popupdiv';
        div.appendChild(document.createTextNode('This is a sample content for pop-up DIV element.'));
        document.getElementsByTagName('body')[0].appendChild(div);
    }
    // move pop-up DIV element
    div.style.top = posy + 5 + 'px';
    div.style.left = posx + 5 + 'px';
}

function displayPopupDiv(e) {

    var posx = 0;
    var posy = 0;
    if (!e) { var e = window.event };

    // determine target DIV
    var targ = e.target ? e.target : e.srcElement;

    // calculate mouse coordinates
    if (e.pageX || e.pageY) {
        posx = e.pageX;
        posy = e.pageY;
    }
    else if (e.clientX || e.clientY) {
        posx = e.clientX;
        posy = e.clientY;
        // check for scroll offsets in IE 6
        if (document.documentElement.scrollLeft || document.documentElement.scrollTop) {
            posx += document.documentElement.scrollLeft;
            posy += document.documentElement.scrollTop;
        }
    }

    // assign attributes to pop-up DIV element and append it to web document tree
    var div = document.getElementById('popup');
    if (!div) {
        var div = document.createElement('div');
        div.setAttribute('id', 'popup');
        div.className = 'popupdiv';
        div.appendChild(document.createTextNode('This is a sample content for pop-up DIV element.'));
        document.getElementsByTagName('body')[0].appendChild(div);
    }
    // move pop-up DIV element
    div.style.top = posy + 5 + 'px';
    div.style.left = posx + 5 + 'px';
}

// remove pop-up DIV element
function hidePopupDiv() {
    var div = document.getElementById('popup');
    if (!div) { return };
    div.parentNode.removeChild(div);
}

// activate pop-up DIV elements
function activatePopupDivs() {
    var divs = document.getElementsByTagName('div');
    if (!divs) { return };
    for (var i = 0; i < divs.length; i++) {
        if (divs[i].className == 'thumbnailI') {
            // display pop-up DIV element
            divs[i].onclick = displayPopupDiv;
            
            // hide pop-up DIV element
            divs[i].onmouseout = hidePopupDiv;
        }
    }
}

// activate pop-up DIV elements when web page has been loaded
/*
window.onload = function() {
    if (document.getElementById && document.createElement && document.createTextNode) {
        activatePopupDivs();
    }
}
*/


function findPos(obj) {
    var curleft = curtop = 0;

    // check if browser supports offsetParent
    if (obj.offsetParent) {
        do {
            curleft += obj.offsetLeft;
            curtop += obj.offsetTop;
        } while (obj = obj.offsetParent);
    }
    return [curleft, curtop];
}

function deleteText(e) {
    e.value="";
}

var maxAdNo = 2;
var adNo;
var myAd = new Array()
myAd[0] = '<img src="/images/banner1.jpg" width="240" height="261" border="0">'
myAd[1] = '<img src="/images/banner2.jpg" width="240" height="261" border="0">'

<!-- STEP TWO: Copy this code into the BODY of your HTML document  -->
// adNo = Math.round(Math.random() * maxAdNo)
adNo = (adNo == 0 ? 1 : 0);
//document.write(myAd[adNo]);

