//  check form
function CheckForm(idform)
{
    //  update & declare
    var check = true;
    var form = $(idform);
    var e = form.getElements();
    var c = e.length;

    //  loop all the elements
    for (var i=0; i<c; i++)
    {
        var id = e[i];
        var n  = id.name;
        var v  = id.value.strip();
        var a  = id.alt;
        var t  = id.type;
        
        //  check for textboxes
        if (t == "checkbox" && !id.checked) v = '';
    
        //  check for isset the alt tag
        if (isSet(a))
        {
            //  update a if needed
            if (a.startsWith('null') && v.blank() == false) a = a.substr(4);
            
            //  default checks
            if      (a == "notempty")   { if (v.blank())     check = setWarning(id); else resetWarning(id); }
            else if (a == "email")      { if (!isEmail(v))   check = setWarning(id); else resetWarning(id); }
            else if (a == "phone")      { if (!isPhone(v))   check = setWarning(id); else resetWarning(id); }
            else if (a == "zipcode")    { if (!isZipcode(v)) check = setWarning(id); else resetWarning(id); }
        }
    }
    
    //  return
    return (check);
}

//  utility functions
function isSet(id)          { if (id == null) return (false); return(typeof(id) != 'undefined'); }
function setWarning(e)      { e.style.background = '#FEE0E0'; return (false); }
function resetWarning(e)    { e.style.background = ''; }

//  check functions
function isEmail(s)     { return (/^.+\@(\[?)[a-zA-Z0-9\-\.]+\.([a-zA-Z]{2,3}|[0-9]{1,3})(\]?)$/.test(s)); }
function isPhone(s)     { return (/^[0-9]{10}$/.test(s)); }
function isInt(s)       { return (/^[0-9]+$/.test(s)); }
function isZipcode(s)   { return (/^[0-9]{4}\s{0,1}[a-zA-Z]{2}$/.test(s)); }
