///////////////////////////////////////////////////////////////////////////////////////////////
function CheckTypes(){
        this.EMTPY = 0;
        this.EMAIL = 2;
}
var CHK_TYPES = new CheckTypes();
///////////////////////////////////////////////////////////////////////////////////////////////
arControls = Array();
arControls.push(Array("txtName", CHK_TYPES.EMPTY, 'Please, enter your name.'));
arControls.push(Array("txtPhone", CHK_TYPES.EMPTY, 'Please, enter your phone.'));
arControls.push(Array("txtEMail", CHK_TYPES.EMAIL, 'Please, enter your email.'));
arControls.push(Array("txtMessage", CHK_TYPES.EMPTY, 'Please, enter your message.'));
///////////////////////////////////////////////////////////////////////////////////////////////
function HighlightField(oField){
        oField.setAttribute('sOldCssText', oField.style.cssText);
        oField.style.cssText = "background-color:#FFDDDD;" + oField.style.cssText;
        try{
                if(oField.select) oField.select();
                if(oField.focus) oField.focus();
        }catch(e){}
}
///////////////////////////////////////////////////////////////////////////////////////////////
function ResetFieldStyle(oField){
        if(oField.hasAttribute('sOldCssText')){
                oField.style.cssText = oField.getAttribute('sOldCssText');
        }
}
function CheckSubmit(frmForm, sOnSubmit){
        var i;

        if(typeof(arControls) != 'undefined'){
                for(i = 0; i < arControls.length; i++){
                        if(!CheckValue(document.getElementById(arControls[i][0]), arControls[i][1], arControls[i][2])){
                                return false;
                        }
                }
        }
        if(typeof(sOnSubmit) == 'undefined' || sOnSubmit == ""){
                document.getElementById(frmForm).submit();
        }else{
                if(eval(sOnSubmit) == true){
                        document.getElementById(frmForm).submit();
                }else{
                        return false;
                }
        }
}
/////////////////////////////////////////////////////////////////////////
function CheckValue(oControl, nCheckType, sErr, bHideError){

        if(nCheckType == CHK_TYPES.EMPTY){
                if(oControl.value.replace(/\s+/, "") == ""){
                        if(!bHideError){
                                alert(sErr);
                                HighlightField(oControl);
                        }
                        return false;
                }else{
                        return true;
                }
        }else if(nCheckType == CHK_TYPES.EMAIL){
                sEMail = oControl.value.replace(/\s+/, "");
                var sFilter  = /^([a-zA-Z0-9_\.\-])+\@(([a-zA-Z0-9\-])+\.)+([a-zA-Z0-9]{2,4})+$/;
                if(sFilter.test(sEMail)){
                        return true;
                }else{
                        if(!bHideError){
                                alert(sErr);
                                HighlightField(oControl);
                        }
                        return false;
                }
        }else{
                alert('Invalid Check Type!');
                return false;
        }
}
