﻿/**********************************

This file is based on jquery

**********************************/

function hasValidValue(obj) {

    var objectTagName = obj.get(0).tagName.toUpperCase();

    //if input --> validate input value as num. of characters > 0
    if (objectTagName.toUpperCase() == "INPUT") {
        if ($.trim(obj.val()).length > 0)
            return true;
    }

    //if select --> validate selected value != -1
    //if select --> has selected items (if list box, it can have items but none of those selected) length > 0
    if (objectTagName.toUpperCase() == "SELECT") {
        if (obj.find(" :selected").length > 0 && $.trim(obj.find(" :selected").val()) != "-1") {
            return true;
        }
    }

    obj.focus();
    return false;
}



function isValidEmail(obj) {
    var re = /^([a-zA-Z0-9_\.\-])+\@(([a-zA-Z0-9\-])+\.)+([a-zA-Z0-9]{2,4})+$/;
    if (obj.val().match(re)) {
        return true;
    }

    obj.focus();
    return false;
}


function isValidAddr(obj) {
//    var re = /^\d{1,}\s[a-zA-z\s]+$/;

//    if (obj.val().match(re) && obj.val().length > 5)
//        return true;

//    obj.focus();
//    return false;



    eval("var re='([0-9A-Za-z\-\ \.\#\,\\']{" + obj.val().length + "})'")
    if (obj.val().match(re) && obj.val().length > 5)
        return true;

    obj.focus();
    return false;
}


function isValidName(obj) {
    eval("var re='([A-Za-z\-\ \\']{" + obj.val().length + "})'");
    
    if (obj.val().match(re) && obj.val().length > 1)
        return true;

    obj.focus();
    return false;
}


function hasSelectedObject(objList) {

    var hasSelectedObj = false;

    for (var i = 0; i < objList.length; i++) {
        if (objList[i].is(":checked")) {
            hasSelectedObj = true;
            break;
        }
    }

    return hasSelectedObj;
}


function hasSpace(obj) {
    var re = '([\ ]+)';

    if (obj.val().match(re))
        return true;

    obj.focus();
    return false;
}


function hasNumericValue(obj) {
    if (obj.val().toString().match(/^\d*$/)) {
        return true;
    }

    obj.focus();
    return false;
}