/*
 * VMS Version 1.0 (BETA)
 * written by ThiHa ZAN
 * core functions
 */

var timerID  =  null;
var childMenus = ["events", "users", "info", "community"];

var reEmail = /^[A-Za-z0-9\._-]+@+[A-Za-z0-9\._-]+\.+[a-z]{2,3}$/gi;
var reAlphaNumeric = /[A-Za-z0-9_]/gi;
var reNumeric = /^[0-9]/gi;

if (parent.frames.length != 0) {
    parent.location=window.location;
}



/*
 * @function;
 * @desc: void <b>chBgList</b> (HTMLelement, bool mouseover) <br />change background color of the list (white and grey);
 * @param: HTMLobject, bool - 1=mouseover, 0=mouseout;
 * @return: void;
 */
function chBg(o,m)
{
    if (m==1) {
		o.style.backgroundColor = "#dddddd";
	}else if (m==0) {
		o.style.backgroundColor = "#ffffff";
	}else if (m==2) {
		o.style.backgroundColor = "#66FF66";
	}else if (m==3) {
		o.style.backgroundColor = "#99FFCC";
	}else if (m==4) {
		o.style.backgroundColor = "#FFCCFF";
	}else if (m==5) {
		o.style.backgroundColor = "#CCCCCC";

	}
	 
}


/*
 * @function;
 * @desc: change (swap) image (default _0 image with _1 image);
 * @param: HTMLobject - image, [string - image uri (optional)];
 * @return: void;
 */
function chImg()
{
    var a = chImg.arguments;
    o = a[0];

    if (a.length == 1) { // replace _0 with _1 or _1 with _0
        o.src = (o.src.indexOf("_0") != -1) ? o.src.replace(/_0/i, "_1") : o.src.replace(/_1/i, "_0");
    } else { // replace any image provided
        o.src = a[1];
    }
}


/*
 * @function;
 * @desc: clear timer;
 * @param: void;
 * @return: void;
 */
function clrTimer()
{
    if (timerID) {
        window.clearTimeout(timerID);
    }
}


function confirmPW(f) {
    if (f.newpw.value == "") {
        f.newpw.style.backgroundColor = "#ddd";
        wErr("Please enter new password and confirm it.");
        return false
    } else if (f.newpw.value.length < 4) {
        f.newpw.style.backgroundColor = "#ddd";
        wErr("Your password is too short. Please enter at least 4 characters.");
        return false;
    } else if (f.newpw.value != f.confirmpw.value) {
        f.newpw.style.backgroundColor = "#ddd";
        f.confirmpw.style.backgroundColor = "#ddd";
        wErr("Password Does Not Match");
        return false;
    } else {
        return true;
    }
}

/*
 * @function;
 * @desc: get the object for the given name;
 * @param: string - name of the object;
 * @return: HTML object;
 */
function getObj(n)
{
    var i, x=null, d=document;
    if (!(x=d[n]) && d.all) {
        x = d.all[n];
    }
    for (i=0; !x&&i<d.forms.length; i++) {
        x = d.forms[i][n];
    }
    if (!x && d.getElementById) {
        x = d.getElementById(n);
    }
    return x;
}


/*
 * @function;
 * @desc: hide all menus;
 * @param: void;
 * @return: void;
 */
function hideAllMenus() {
    var o;

    clrTimer();
    for (c=0; c<childMenus.length; c++) {
        if (o = getObj(childMenus[c])) {
            o.style.visibility = "hidden";
        }
    }
}


/*
 * @function;
 * @desc: hide all menu with delay;
 * @param: void;
 * @return: void;
 */
function hideMenu() {
    timerID = window.setTimeout("hideAllMenus()",1000);
}


/*
 * @function;
 * @desc: reload current page
 * @param: void;
 * @return: void;
 */
function reloadWin() {
    history.go(0);
}


/*
 * @function;
 * @desc: show Event;
 * @param: int id;
 * @return: void;
 */
function showEvent(eid)
{
    window.location = "showEvent.asp?eid="+eid;
}


/*
 * @function;
 * @desc: show event on a day;
 * @param: int - day, int - month, int - year;
 * @return: void;
 */
function showDayEvents(d,m,y)
{
    window.location = "listEvents.asp?d="+d+"&m="+m+"&y="+y;
}


/*
 * @function;
 * @desc: show Event call from pop;
 * @param: int id;
 * @return: void;
 */
function showEventPop(eid)
{
    opener.location = "showEvent.asp?eid="+eid;
}


/*
 * @function;
 * @desc: show a floating menu;
 * @param: string - id of the floating menu;
 * @return: void;
 */
function showMenu(id) {
    hideAllMenus();
    getObj(id).style.visibility = "visible";
}


/*
 * @function;
 * @desc: window showing summary of events on a day;
 * @param: void;
 * @return: void;
 */
function showSummary(str)
{
    win = window.open("showSummary.asp?" + str,"summary","left=25,top=50,height=500,width=700,toolbar=no,location=no,directories=no,status=no,menubar=no,scrollbars=yes,resizable=yes,titlebar=yes");
    win.close();
    win = window.open("showSummary.asp?" + str,"summary","left=25,top=50,height=500,width=700,toolbar=no,location=no,directories=no,status=no,menubar=no,scrollbars=yes,resizable=yes,titlebar=yes");
    if (!win.opener) {
        win.opener = self;
    }
}

/*
 * @function;
 * @desc: show user details;
 * @param: string - user id;
 * @return: void;
 */
function showUser(uid)
{
    window.location = "showUser.asp?uid="+uid;
}

function verifyEmail(f) {
    if (f.email.value != "") {
        if (reEmail.test(f.email.value)) {
            return true;
        } else {
            f.email.style.backgroundColor = "#ddd";
            wErr("Please enter valid Email Address.");
            return false;
        }
    } else {

       f.email.style.backgroundColor = "#ddd";
       wErr("Please Enter New Email Address.");
       return false
    }
}


function verifyEvent(f)
{
    return true;
}

function verifyUidPw (f) {
    if (f.uid.value == "") {
        f.uid.style.backgroundColor = "#dddddd";
        wErr("Please enter your User ID");
        return false;
    } else if (f.pw.value == "") {
        f.uid.style.backgroundColor = "#ffffff";
        f.pw.style.backgroundColor = "#dddddd";
        wErr("Please enter your Password");
        return false;
    } else {
        getObj("jschk").value = 1;
        return true;
    }
}

function verifyUidEmail (f) {
    if (f.uid.value == "") {
        f.uid.style.backgroundColor = "#dddddd";
        wErr("Please enter your User ID");
        return false;

    } else if (f.email.value == "") {
        f.uid.style.backgroundColor = "#ffffff";
        f.email.style.backgroundColor = "#dddddd";
        wErr("Please enter your Email Address.");
        return false

    } else if (reEmail.test(f.email.value)) {
        return true;

    } else {
        f.uid.style.backgroundColor = "#ffffff";
        f.email.style.backgroundColor = "#dddddd";
        wErr("Please enter valid Email Address.");
        return false;
    }
}

function verifyUser(f) {
    return true;
}


/*
 * @function;
 * @desc: hide all menu with delay;
 * @param: string - id of the html Object, string - HTML code to be written;
 * @return: void;
 */
function wObj(id,s)
{
    if ((o=getObj(id))!= null) {
        o.innerHTML = s;
    }
}


/*
 * @function;
 * @desc: hide all menu with delay;
 * @param: void;
 * @return: void;
 */
function wErr(s)
{
    wObj("ERR",s);
}

