function emp_login_limpar(){
	var doc = document.forms[0];
	doc["_ctl0:txtnome"].value=''
	doc["_ctl0:txtsenha"].value=''
}

function ValidaCampoOnExit(field){
	var doc = document.forms[0];	
	var result
	result =true
	if (field.id.indexOf("txtData")>0){
		if (check_date(field, false) == false){
			field.style.backgroundColor='red';				
			doc["txtMsgErro"].value="Data incorreta"
			result = false;
		}else{
			field.style.backgroundColor='White';
			doc["txtMsgErro"].value=""
			result = !isEmpty(field);
		}
	}else{
		if (field.id.indexOf("txtInt")>0){
			if(isEmpty(field)){
				field.style.backgroundColor='red';
				doc["txtMsgErro"].value="Valor incorreto"				
				result = false;
			}else{
				field.style.backgroundColor='White';
				doc["txtMsgErro"].value=""			
				result = true;
			}
		}
		else{
			if (field.id.indexOf("txtDec")>0){
				if (field.value==''){				
					result=true;
				}else{
					if(validateNumeric(field.value) == false){
						field.style.backgroundColor='red';
						doc["txtMsgErro"].value="Valor incorreto"				
						result = false;
					}else{
						field.style.backgroundColor='White';
						doc["txtMsgErro"].value=""			
						result = true;
					}
				
				}
			}		
		}
	}
	if (result==true){
		if (field.id.indexOf("rtxt")>0 || field.id.indexOf("rddl")>0){
			if(isEmpty(field)){
				field.style.backgroundColor='red';
				doc["txtMsgErro"].value="Campo obrigatório"				
				result = false;				
			}else{
				field.style.backgroundColor='White';
				doc["txtMsgErro"].value=""			
				result = true;
			}			
		}
		return true;
	}
	//alert(doc.elements.count)
}

function Keypress(field){
	if (field.id.indexOf("txtData")>0){
		DataOnly()
	}else{
		if (field.id.indexOf("txtInt")>0){
			NumericDataOnly()
		}else{
			if (field.id.indexOf("txtDec")>0){
				decimalOnly(field, event, true)
			}		
		}
	}
}

function Valida(){
	var doc = document.forms[0]
	var ok
	if (doc["txtMsgErro"].value!=''){
		doc["txtMsgErro"].value = 'Preencha os campos em vermelho corretamente'
		return false;
	}else{		
		for (i = 0; i < doc.elements.length; i++)
		{
			if (doc.elements[i].id.indexOf("rtxt")>0){
				if (doc.elements[i].value==""){
					doc.elements[i].style.backgroundColor='red';
					doc["txtMsgErro"].value = 'Campo obrigatório'
					return false;					
				}else{
					doc.elements[i].backgroundColor='white';
					doc["txtMsgErro"].value = ''
				}			
			}else if (doc.elements[i].id.indexOf("rddl")>0){
				if (doc.elements[i].value==""){
					doc.elements[i].style.backgroundColor='red';
					doc["txtMsgErro"].value = 'Campo obrigatório'
					return false;					
				}else{
					doc.elements[i].backgroundColor='white';
					doc["txtMsgErro"].value = ''					
				}																																	
			}
		}
		return true;
	}
}

function NumericDataOnly()
{
   var key = window.event.keyCode;

   if ( (key > 47 && key < 58) || key==8)
      return;
   else
      window.event.returnValue = null;
}

function DataOnly()
{
   var key = window.event.keyCode;

   if ( (key >= 47 && key < 58) || key==8 )
      return;
   else
      window.event.returnValue = null;
}

function isEmpty(field){
	if (field.id.indexOf("rtxt")>0 || field.id.indexOf("rddl")>0){
		if (field.value==""){
			return true;
		}else{
			return false;
		}	
	}else{
		return false;
	}
}

function decimalOnly(myfield, e, dec)
{
	var key;
	var keychar;
	var strnumbers;
	if (dec==true){
		strnumbers ='1234567890,'
	}else{
		strnumbers ='1234567890'
	}

	if (window.event)
		key = window.event.keyCode;
	else if (e)
		key = e.which;
	else
	return true;
	keychar = String.fromCharCode(key);

	// control keys
	if ((key==null) || (key==0) || (key==8) || 
		(key==9) || (key==13) || (key==27) )
	return true;

	// numbers
	else if (((strnumbers).indexOf(keychar) > -1))
		return true;
	else
		window.event.returnValue = null;
}

function  validateNumeric(strValue){
  var objRegExp  =  /(^-?\d\d*\,\d*$)|(^-?\d\d*$)|(^-?\,\d\d*$)/;

  //check for numeric characters
  return objRegExp.test(strValue);
}

function validaCPF(field) {
	var doc = document.forms[0]
	var cpf = field.value
    erro = new String;
    if (cpf.length < 11) erro += "Sao necessarios 11 digitos para verificacao do CPF! \n\n"; 
	var nonNumbers = /\D/;
    if (nonNumbers.test(cpf)) erro += "A verificacao de CPF suporta apenas numeros! \n\n"; 
    if (cpf == "00000000000" || cpf == "11111111111" || cpf == "22222222222" || cpf == "33333333333" || cpf == "44444444444" || cpf == "55555555555" || cpf == "66666666666" || cpf == "77777777777" || cpf == "88888888888" || cpf == "99999999999"){
		erro += "Numero de CPF invalido!"
    }
    var a = [];
    var b = new Number;
    var c = 11;
    for (i=0; i<11; i++){
		a[i] = cpf.charAt(i);
		if (i < 9) b += (a[i] * --c);
    }
    if ((x = b % 11) < 2) { a[9] = 0 } else { a[9] = 11-x }
    b = 0;
    c = 11;
    for (y=0; y<10; y++) b += (a[y] * c--); 
	if ((x = b % 11) < 2) { a[10] = 0; } else { a[10] = 11-x; }
    if ((cpf.charAt(9) != a[9]) || (cpf.charAt(10) != a[10])){
		erro +="CPF inválido!";
    }
    if (erro.length > 0){
		doc["txtMsgErro"].value=erro
		field.style.backgroundColor='red';
		//alert(erro);
        return false;
    }else{
		doc["txtMsgErro"].value=""
		field.style.backgroundColor='White';	    
    }
    
    return true;
}
function openPopup(url) {
    myPopup = window.open(url,'newwindow','width=700,height=400,scrollbars=1,alwaysRaised=yes, resizable=yes');        
    if (!myPopup.opener)
         myPopup.opener = self; 
    
}		
function calcularTotal(valor){
	var sdesc = valor.value;	
	desc = parseFloat(sdesc.replace(/,/,"."));
	var spreco = document.getElementById("_ctl0_lblpreco").innerHTML;
	var preco = parseFloat(spreco.replace(/,/,"."));
	var total = preco - (preco * desc / 100);
	stotal = total.toFixed(2)
	//var stotal = addCommas(total);
	document.getElementById("_ctl0_lblTotal").innerHTML = stotal.replace(".",",");
}
function limpaTotal(){
	document.getElementById("_ctl0_lbltotal").innerHTML = "";
}
