//***************CONSTANTES******************
const style_error = "style_error";
const style_ok = "style_ok";
const ddl_null_value = "--"
//*******************************************



//VALIDACION DE CONTROLES EN JAVASCRIPT
function ValidaTXT(txt) {
		
		if (txt.value=="") {
			txt.className=style_error;
			return false;
		}
		else {
			txt.className=style_ok;
			return true;
		}
		
	}

function ValidaDDL(ddl) {
		
		if (ddl.value==ddl_null_value) {
			ddl.className=style_error;
			return false;
		}
		else {
			ddl.className=style_ok;
			return true;
		}
		
	}

	
function ValidaRadio(group, id_td) {

		valor = false;
		sel_opt = -1;
		for (i=group.length-1; i > -1; i--) {
			if (group[i].checked) {
				sel_opt = i;
				i = -1;
				valor= true;
			}
		}
		
		for (i=group.length-1; i > -1; i--) {
			if (sel_opt > -1) {
				document.getElementById("p"+id_td+"_"+i).className=style_ok;
			}
			else {
				document.getElementById("p"+id_td+"_"+i).className=style_error;
			}
		}

		return valor;
		
	}


function ValidaEmail(txtMail, allow_null){
       
       
       	
       		
	    
        if (echeck(txtMail.value, allow_null)==false){
                txtMail.className=style_error;
                return false;
        }
        txtMail.className=style_ok;
        return true;
        
}
 	

function echeck(str, allow_null) {

        var at="@"
        var dot="."
        var lat=str.indexOf(at)
        var lstr=str.length
        var ldot=str.indexOf(dot)
        
       	if (allow_null==true) {
			if (str.length==0) {
				return true
			}
		}  
        if (str.indexOf(at)==-1){
           return false
        }

        if (str.indexOf(at)==-1 || str.indexOf(at)==0 || str.indexOf(at)==lstr){
           return false
        }

        if (str.indexOf(dot)==-1 || str.indexOf(dot)==0 || str.indexOf(dot)==lstr){
            return false
        }

         if (str.indexOf(at,(lat+1))!=-1){
            return false
         }

         if (str.substring(lat-1,lat)==dot || str.substring(lat+1,lat+2)==dot){
            return false
         }

         if (str.indexOf(dot,(lat+2))==-1){
            return false
         }

         if (str.indexOf(" ")!=-1){
            return false
         }

          return true
          
}



