﻿function MaskDate(campo, event){ 
    try{
        //var whichCode = (window.Event) ? event.which : event.keyCode;
        var whichCode = (window.addEventListener) ? event.which : event.keyCode;

        if (whichCode == 8 ) return true; //backspace
        if (whichCode == 0 ) return true;
        if (whichCode == 9 ) return true; //tecla tab
        if (whichCode == 13) return true; //tecla enter
        if (whichCode == 16) return true; //shift internet explorer
        if (whichCode == 17) return true; //control no internet explorer
        if (whichCode == 27 ) return true; //tecla esc
        if (whichCode == 34 ) return true; //tecla end
        if (whichCode == 35 ) return true;//tecla end
        if (whichCode == 36 ) return true; //tecla home
        
        if (event.preventDefault)
        { //standart browsers
		    event.preventDefault()
	    }
	    else
	    { // internet explorer
		    event.returnValue = false
        }
        
        if (campo.value.length > 9) return false;
        
        var strCheck = '0123456789';
        var key = String.fromCharCode(whichCode);  // Valor para o código da Chave
        if (strCheck.indexOf(key) == -1) return false;  // Chave inválida

        /*
        Concatenamos ao value o keycode de key, se esse for um número
        */
        campo.value += key;
        var mydata = new String(campo.value);
	    mydata = mydata.replace("/", "");
	    mydata = mydata.replace("/", "");
        
        
    	
	    if(mydata.length <= 8)
	    {
	        if (mydata.length >= 2 && mydata.length < 4)
            {
			    campo.value = mydata.substr(0,2) + '/' + mydata.substr(2, mydata.length - 2);
	        }
	        if (mydata.length >= 4)
		    {
			    campo.value = mydata.substr(0,2) + '/' + mydata.substr(2,2) + '/' + mydata.substr(4, mydata.length - 4);
		    }
	    }
    	
	    if (campo.value.length == 10)
            ValidateDate(campo);
    }
    catch(ex){}
} 

function MaskCPF(campo, event)
{
    //var whichCode = (window.Event) ? event.which : event.keyCode;
    var whichCode = (window.addEventListener) ? event.which : event.keyCode;
    if (whichCode == 8 ) return true; //backspace
    if (whichCode == 0 ) return true;
    if (whichCode == 9 ) return true; //tecla tab
    if (whichCode == 13) return true; //tecla enter
    if (whichCode == 16) return true; //shift internet explorer
    if (whichCode == 17) return true; //control no internet explorer
    if (whichCode == 27 ) return true; //tecla esc
    if (whichCode == 34 ) return true; //tecla end
    if (whichCode == 35 ) return true;//tecla end
    if (whichCode == 36 ) return true; //tecla home
    
    if (event.preventDefault)
    { //standart browsers
		event.preventDefault()
	}
	else
	{ // internet explorer
		event.returnValue = false
    }
    
    if (campo.value.length > 13) return false;
    
    var strCheck = '0123456789';
    var key = String.fromCharCode(whichCode);  // Valor para o código da Chave
    if (strCheck.indexOf(key) == -1) return false;  // Chave inválida

    /*
    Concatenamos ao value o keycode de key, se esse for um número
    */
    campo.value += key;

	var vr = new String(campo.value);
	vr = vr.replace(".", "");
	vr = vr.replace("/", "");
	vr = vr.replace("-", "");
	tam = vr.length + 1;
	if(tam <= 11)
	{
		if (tam == 4)
			campo.value = vr.substr(0, 3) + '.';
		if (tam == 7)
			campo.value = vr.substr(0, 3) + '.' + vr.substr(3, 6) + '.';
		if (tam == 11)
			campo.value = vr.substr(0, 3) + '.' + vr.substr(3, 3) + '.' + vr.substr(7, 3) + '-' + vr.substr(11, 2);
	}
	
}

function ValidarCPF(Objcpf){
    var cpf = Objcpf.value;
    exp = /\.|\-/g;
    cpf = cpf.toString().replace( exp, "" ); 
    var digitoDigitado = eval(cpf.charAt(9)+cpf.charAt(10));
    var soma1=0, soma2=0;
    var vlr =11;
    
    for(i=0;i<9;i++){
        soma1+=eval(cpf.charAt(i)*(vlr-1));
        soma2+=eval(cpf.charAt(i)*vlr);
        vlr--;
    }    
    soma1 = (((soma1*10)%11)==10 ? 0:((soma1*10)%11));
    soma2=(((soma2+(2*soma1))*10)%11);
    
    var digitoGerado=(soma1*10)+soma2;
    if(digitoGerado!=digitoDigitado)    
        alert('CPF Invalido!');        
}
function ValidateEmail(emailID) {
    
    var emailExpression = /[\w\-]*([-+.']\w+)*[\w\-]@\w+([-.]\w+)*\.\w+([-.]\w+)*/;

    emailValue = document.getElementById(emailID).value;
           
    if (emailValue.match(emailExpression))
        {
        return true;}
    else{
        
        return false;
        }
}
function AbrepopupContato(ID) {
    
    document.getElementById('iframecontato').src = "HorariosDetalheContato.aspx?id=" + ID;
    document.getElementById('iframecontato').width = 670;
    document.getElementById('iframecontato').height = 500;
    //window.open("HorariosDetalheContato.aspx?id=" + ID,"_blank","resizable=yes,toolbar=no,status=yes,menubar=yes,scrollbars=no,width=650,height=400");
    document.getElementById('iframecontato').visible = true;
}

