var agent = navigator.userAgent.toLowerCase()
var is_ns  = ((agent.indexOf('mozilla') != -1) && (agent.indexOf('spoofer') == -1) && (agent.indexOf('compatible') == -1)
                && (agent.indexOf('opera') == -1) && (agent.indexOf('webtv') == -1) && (agent.indexOf('hotjava') == -1))
var is_ie = ((agent.indexOf("msie") != -1) && (agent.indexOf("opera") == -1))
var is_opera = (agent.indexOf("opera") != -1);

function optionAdd(_objSelect,_text,_value) {
    if (is_ie) {
        var _objOption = document.createElement("OPTION");
        _objOption.text = _text;
        _objOption.value = _value;
        _objSelect.add(_objOption);
    }else if (is_ns || is_opera) {
        var _nextOption = _objSelect.options.length;
        _objOption = new Option(_text,_value);
        _objSelect.options[_nextOption] = _objOption
    }
}

function optionDelete(objSelect,_start,_length) {
    if (_start == null || _start < 0)
        _start = 0;
    if (_length == null || _length < 0 || _length == 0)
        _elements = objSelect.length;
    else
        _elements = (_length > (objSelect.length - _start))?objSelect.length - _start:_start + _length;
    for (i=_start;i<_elements;i++)
        objSelect.options[_start] = null;
}

function optionSelect(_objSelect,_index) {
    _index = (_index == null || _index >= _objSelect.length)?0:_index;
    if (is_ie || is_opera)
        _objSelect.selectedIndex = _index
    if (is_ns)
        _objSelect.options[_index].selected = true
}

function arrayFind(arr,val) {
    for (var i=0;i<arr.length;i++) {
        if (arr[i] == val)
            return i;
    }
    return -1;
}

function showit(wwidth,wheight,wname) {
    if (wwidth == 0 || wheight == 0)
        showPlace = open("",wname);
    else
        showPlace = open("",wname,"width="+wwidth+",height="+wheight+",resizable=no,scrollbars=no");
}

function email_is_valid(_email) {
    email_re1 = /(@.*@)|(\.\.)|(@\.)|(\.@)|(^\.)|(\.$)/
    email_re2 = /^([a-zA-Z0-9_\-\.]+)@((\[[0-9]{1,3}\.[0-9]{1,3}\.[0-9]{1,3}\.)|(([a-zA-Z0-9\-]+\.)+))([a-zA-Z]{2,4}|[0-9]{1,3})(\]?)$/
    if (_email == "" || email_re1.exec(_email) || !email_re2.exec(_email))
        return false
    return true
}

function areYouSure() {
    if (confirm("Are you sure?"))
        return true;
    return false;
}

//trim - Strip whitespace from the beginning and end of a string
function trim(_inStr) {
    _outStr = _inStr.replace(/(^\s+)|(\s+$)/g,"");
    return _outStr;
}

//ltrim - Strip whitespace from the beginning of a string
function ltrim(_inStr) {
    _outStr = _inStr.replace(/^\s+/g,"");
    return _outStr;
}

//rtrim - Remove trailing whitespace
function rtrim(_inStr) {
    _outStr = _inStr.replace(/\s+$/g,"");
    return _outStr;
}

function CheckLoginData(_fObj)
{ 

    if((trim(_fObj.UserName.value) == "") || (trim(_fObj.UserPassword.value) == ""))
    {
        alert("Please input username and password !")
        return false;
    }else
        return true;
}
