
function Len(me)
{
    var lValue = Trim(me.value);
    
    return lValue.length;
}

function Trim(str)
{
   return str.replace(/^\s*|\s*$/g,"");
}

function iif(Expression, TruePart, FalsePart)
{
    return (Expression ? TruePart : FalsePart);
}

function getKeyCode(e)
{
	if (window.event)
	   return window.event.keyCode;
	else if (e)
	   return e.which;
	else
	   return null;
}

function keyRestrict(e, validchars) { 
	var key = '';
	var keychar = '';
		
	key = getKeyCode(e);
	
	if (key == null) {
		return true;
	}
	
	keychar = String.fromCharCode(key);
	keychar = keychar.toLowerCase();
	
	if (validchars == 0) {
		validchars = '1234567890'; 
	}
	
	validchars = validchars.toLowerCase();
	
	if (validchars.indexOf(keychar) != -1) {
		return true;
	}
	
	if (key == null || key == 0 || key == 8 || key == 9 || key == 13 || key == 27) {
		return true;
	}
	
	return false;
}

function PhoneFormat(me)
{
	if (me.value.length > 0) {
		var tValue = me.value.replace(new RegExp("-", "gi"), "");
		
		tValue = tValue.substring(0, 3) + '-' + tValue.substring(3, 6) + '-' + tValue.substring(6);
		me.value = tValue;
	}
}

function checkEmail(email) {
	if (/^\w+([\.-]?\w+)*@\w+([\.-]?\w+)*(\.\w{2,3})+$/.test(email)) {
		return true
	}
	
	return (false)
}

function ValidateEmail(str) 
{
    var aPos = str.indexOf(".");
    var dPos = str.indexOf("@");

    if (aPos == -1 || dPos == -1)
        return false; //if not exist
    else if (aPos == 1 || dPos == 1)
        return false; //not first char
    else if ((dPos - aPos) == 1 || (aPos - dPos) == 1)
        return false; //if not exist
    else if ((str.length - 1) == aPos || (str.length - 1) == dPos)
        return false; //last position
    else if (str.substring(str.length - 2) == "@." || str.substring(str.length - 2) == ".@")
        return false; //last position
    else
    {
        var eExtension = str.substring(dPos);
        
        aPos = eExtension.indexOf(".");
        if (aPos == -1) 
            return false; //if not exist
        else
            return true;
    }
}