﻿// JScript File
/* Added by hoangkc */
function WaterMark(id, value)
{
    var inputText = document.getElementById(id);
    if (inputText)
    {
        inputText.waterMark = value;
        inputText.onfocus = function ()
        {
            if (this.value == this.waterMark) this.value = "";
            else this.select();
        }

        inputText.onblur = function ()
        {
            if (this.value == "") this.value = this.waterMark;
        }
    }
}
function TopMenuActive(id, index)
{
    var divMenu = document.getElementById(id);
    if (divMenu)
    {
        var arr = divMenu.getElementsByTagName("a");
        if (index >= 0 && index < arr.length)
            arr[index].className = "selected";
    }
}

function ShowChildMenu(id, left)
{
    var div = $("#" + id);
    div.show();
    if(!isNaN(left)) div.css("left",left+"px");
}

$(document).ready(function ()
{
    $("#divMenuDropBox").mouseleave(function ()
    {
        $(this).hide();
    });
    $("#divMenuDropBoxOfficeAdmin_Employer").mouseleave(function ()
    {
        $(this).hide();
    });
    $("#divMenuDropBoxOfficeAdmin_Employee").mouseleave(function ()
    {
        $(this).hide();
    });
    $("#divMenuDropBoxOfficeAdmin_Request").mouseleave(function ()
    {
        $(this).hide();
    });
    $("#divMenuDropBox_Message").mouseleave(function ()
    {
        $(this).hide();
    });
    $("#divMenuDropBoxOfficeAdmin_Article").mouseleave(function ()
    {
        $(this).hide();
    });
})

/* End of added by hoangkc */

function isTimeFormat(source, args)
{
    var strval = args.Value;
    var strval1;

    //minimum lenght is 6. example 1:2 AM
    if (strval.length < 6)
    {
        args.IsValid = false;
        return;
    }

    //Maximum length is 8. example 10:45 AM
    if (strval.lenght > 8)
    {
        args.IsValid = false;
        return;

    }

    //Removing all space
    strval = trimAllSpace(strval);

    //Checking AM/PM
    if (strval.charAt(strval.length - 1) != "M" && strval.charAt(
      strval.length - 1) != "m")
    {
        args.IsValid = false;
        return;


    }
    else if (strval.charAt(strval.length - 2) != 'A' && strval.charAt(
      strval.length - 2) != 'a' && strval.charAt(
      strval.length - 2) != 'p' && strval.charAt(strval.length - 2) != 'P')
    {
        args.IsValid = false;
        return;


    }

    //Give one space before AM/PM

    strval1 = strval.substring(0, strval.length - 2);
    strval1 = strval1 + ' ' + strval.substring(strval.length - 2, strval.length)

    strval = strval1;

    var pos1 = strval.indexOf(':');
    document.Form1.TextBox1.value = strval;

    if (pos1 < 0)
    {
        args.IsValid = false;
        return;

    }
    else if (pos1 > 2 || pos1 < 1)
    {

        args.IsValid = false;
        return;

    }

    //Checking hours
    var horval = trimString(strval.substring(0, pos1));

    if (horval == -100)
    {
        args.IsValid = false;
        return;

    }

    if (horval > 12)
    {
        args.IsValid = false;
        return;

    }
    else if (horval < 0)
    {

        args.IsValid = false;
        return;

    }
    //Completes checking hours.

    //Checking minutes.
    var minval = trimString(strval.substring(pos1 + 1, pos1 + 3));

    if (minval == -100)
    {

        args.IsValid = false;
        return;

    }

    if (minval > 59)
    {
        args.IsValid = false;
        return;

    }
    else if (minval < 0)
    {

        args.IsValid = false;
        return;

    }

    //Checking minutes completed.  

    //Checking one space after the mintues 
    minpos = pos1 + minval.length + 1;
    if (strval.charAt(minpos) != ' ')
    {
        args.IsValid = false;
        return;

    }


    args.IsValid = true;

}


//ThangLH
function DelTextbox(ClientID)
{
    var strVal = document.getElementById(ClientID.id).value;
    if (strVal != '')
    {
        document.getElementById(ClientID.id).value = '';
    }
}
//Check valid of 
function ValidatorCboTxtPair(cboClientId, txtClientID)
{
    if ((document.getElementById(cboClientId).value != "Please select ...")
            && (document.getElementById(cboClientId).value != "Others"))
        return true;
    else if (Trim(document.getElementById(txtClientID).value) != '')
        return true;
    else
        return false;
}
//Set default button
function ButtonDefault(e, btnClientId)
{
    var evt = e ? e : window.event;
    var bt = document.getElementById(btnClientId);
    if (bt)
    {
        if (evt.keyCode == 13)
        {
            bt.click();
            return false;
        }
    }
}
function clickButton(buttonid)
{
    var bt = document.getElementById(buttonid);
    if (bt)
    {
        bt.click();
    }
    return true;
}

//Check from date <= to date (MM/DD/YYYY)
function CheckFromEndDate(txtFromClientID, txtEndClientID)
{
    var strFromDate = document.getElementById(txtFromClientID).value;
    var strEndDate = document.getElementById(txtEndClientID).value;
    var intCurrentFrom;
    var intCurrentEnd;
    //var intPos;
    if ((strFromDate != '') && (strEndDate != ''))
    {
        //Year
        intCurrentFrom = strFromDate.substring(6); //Start YYYY
        intCurrentEnd = strEndDate.substring(6); //End YYYY
        if (intCurrentEnd > intCurrentFrom)
            return true;
        else
        {
            if (intCurrentEnd < intCurrentFrom)
                return false;
            //"="
            else
            {
                //Month
                intCurrentFrom = strFromDate.substring(0, 2); //Start MM
                intCurrentEnd = strEndDate.substring(0, 2); //End MM
                if (intCurrentEnd > intCurrentFrom)
                    return true;
                else
                {
                    if (intCurrentEnd < intCurrentFrom)
                        return false;
                    //"="
                    else
                    {
                        //Day
                        intCurrentFrom = strFromDate.substring(3, 5); //Start DD
                        intCurrentEnd = strEndDate.substring(3, 5); //End DD
                        if (intCurrentEnd >= intCurrentFrom)
                            return true;
                        else
                        {
                            return false;
                        }
                    }
                }
            }
        }
    }
    else
        return true;
}
function RedirectDfault(strPath)
{
    alert('fck');
    //window.location = strPath;
    return true;
}


//Trang 
// Check valid for 
function ValidatorCboTxtPair_v2(cbo, txt)
{
    if (Trim(document.getElementById(txt).value) == '')
    {
        if (document.getElementById(cbo).value != "Please select ..."
                    && document.getElementById(cbo).value != "Others")
            return true;
        else return false;
    }
    else
    {
        if (document.getElementById(cbo).value != "Please select ..."
                    && document.getElementById(cbo).value != "Others")
            return false;
        else return true;
    }
}

//Check valid inputs from textbox and checkbox
function CheckBox_TextBoxValidator(chk, txt)
{
    if (document.getElementById(chk).checked)
    {
        if (document.getElementById(txt).value != '')
            return true;
        else
            return false;
    }
    else return true;
}
//Check valid for checkbox
function Validate_CheckBox(chk)
{
    if (document.getElementById(chk).checked)
    {
        return true;
    }
    else return false;
}

//Trim string 
//Trim left string
function leftTrim(sString)
{
    while (sString.substring(0, 1) == ' ')
    {
        sString = sString.substring(1, sString.length);
    }
    return sString;
}

//Trim right string 
function rightTrim(sString)
{
    while (sString.substring(sString.length - 1, sString.length) == ' ')
    {
        sString = sString.substring(0, sString.length - 1);
    }
    return sString;
}

//Trim both left and right string 
function Trim(sString)
{
    while (sString.substring(0, 1) == ' ')
    {
        sString = sString.substring(1, sString.length);
    }
    while (sString.substring(sString.length - 1, sString.length) == ' ')
    {
        sString = sString.substring(0, sString.length - 1);
    }
    return sString;
}




