var chars_num   = "0123456789";
var chars_eng   = "ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz";
var chars_heb   = "אבגדהוזחטיכלמנסעפצקרשתץךףםן";
var chars_signs = "!@#$%^*-_=+ '";

function trim (str)
{ 
    while (str.substring(0, 1) == " ")
        str = str.substring(1, str.length);
    while (str.substring(str.length - 1, str.length) == " ")
        str = str.substring(0, str.length - 1);
   return str;
}

function isEmpty (control)
{
    str = trim(control.value);
    if (str.length < 1)
    {
        //control.select();
        return true;
    }
    return false;
}

function isSize (control, size)
{
    str = trim(control.value);
    if (str.length < size)
    {
        //control.select();
        return false;
    }
    return true;
}

function isEqual (control1, control2)
{
    str1 = trim(control1.value);
    str2 = trim(control2.value);
    if (str1 != str2)
    {
        //control2.select();
        return false;
    }
    return true;
}

function isEmail (control)
{
    str = trim(control.value);
    if ((str.indexOf(" ") != -1) ||
        (str.indexOf("@") == -1) ||
        (str.indexOf("@") < 2))
    {
        //control.select();
        return false;
    }
    return true;
}

function isURL (control)
{
    str = trim(control.value);
    if (str.indexOf("http://") != 0)
    {
        //control.select();
        return false;
    }
    return true;
}

function isValidChars (control, chars)
{
    if (chars == '*')
        chars = chars_num + chars_eng + chars_heb + chars_signs;

    str = trim(control.value);

    for (i = 0; i < str.length; ++i)
    {
        chr = str.substr(i, 1);
        if (chars.indexOf(chr) == -1)
        {
            //control.select();
            return false;
        }
    }
    return true;
}

function isImage (control)
{
    str = trim(control.value);
    
    if ((str.toLowerCase().indexOf('.gif') == -1) &&
        (str.toLowerCase().indexOf('.jpg') == -1) &&
        (str.toLowerCase().indexOf('.jpeg') == -1) &&
        (str.toLowerCase().indexOf('.bmp') == -1) &&
        (str.toLowerCase().indexOf('.png') == -1))
    {
        //control.select();
        return false;
    }
    return true;
}

function isAttachment (control)
{
    str = trim(control.value);
    
    if ((!isImage(control)) &&
        (str.toLowerCase().indexOf('.htm') == -1) &&
        (str.toLowerCase().indexOf('.html') == -1) &&
        (str.toLowerCase().indexOf('.twl') == -1))
    {
        //control.select();
        return false;
    }
    return true;
}


function isOptionChecked (control)
{
    for (var i = 0; i < control.length; ++i)
        if (control[i].checked)
	   	    return true;

    return false;
}
