﻿// JScript File
function trim(obj)
{
    return obj.replace(/^\s+$/g,"");
}
function isEmail(obj, lbl)
{
    var wgia = document.getElementById(lbl);
    obj.value = trim(obj.value)
    if (obj.value != "")
    {
        var exclude=/[^@\-\.\w]|^[_@\.\-]|[\._\-]{2}|[@\.]{2}|(@)[^@]*\1/;
        var check=/@[\w\-]+\./;
        var checkend=/\.[a-zA-Z]{2,4}$/;		        
        if(((obj.value.search(exclude) != -1)||(obj.value.search(check)) == -1)||(obj.value.search(checkend) == -1))
	    {
	        wgia.style.display = 'block';
            obj.style.borderColor = 'red';
	        //obj.focus();		      
	        return false;
	    }
        else
	    {
	        wgia.style.display = 'none';
            obj.style.borderColor = '#ccc';                    			      
	        return true;
	    }        
    }
    else
    {
        wgia.style.display = 'block';
        obj.style.borderColor = 'red';
	    //obj.focus();
	    return false;
    }
}

function isTen(obj, lbl)
{        
//alert(obj.id);
var msg = document.getElementById(lbl);
obj.value = trim(obj.value);
    if (obj.value == "")
    {
        msg.style.display = 'block';
        obj.style.borderColor = 'red';
        //obj.focus();         
        return false;
    }
    else
    {
        msg.style.display = 'none';
        obj.style.borderColor = '#ccc';                               
        return true;                     
    }
}
function check(idcontrol)
{
    var ten = document.getElementById(idcontrol + "_txtName");
    var email = document.getElementById(idcontrol + "_txtEmail");
    var submit = document.getElementById(idcontrol + "_btnThem");
    if (isTen(ten,idcontrol + "_lblTen") == false)
    {
        ten.focus();
        return false;
    }
    if (isTen(email,idcontrol + "_lblchEmail")==false)
    {
        email.focus()
        return false;
    }
    if (isEmail(email, idcontrol + "_lblEmail") == false)
    {
        email.focus();
        return false;
    }
    return true;
}

