browser = 0;
bname = navigator.appName;
bversion = parseInt(navigator.appVersion);
if ((bname.indexOf("Netscape") != -1  && bversion >= 3)|| (bname.indexOf("Microsoft") != -1 && bversion > 3)) {
 browser = 1;
}

function GetSize() {
	var Cook=document.cookie;
	var i,ret,f;
	i=Cook.indexOf('NewsSize=');
	if (!i||i<0) i=0;
	f=Cook.indexOf('.',i);
	if (!f||f<0) f=0;
	//Cook=Cook.substring(i+9,f-i+1);
	Cook=Cook.substring(i+9,f);
	if (f<=i) Cook = "";
	if (Cook)ret = Cook.split('x');
	return ret;
}
function Janela(page) {
	x=680;y=450;
	wx=100;wy=100;
	ret=GetSize();
	if (ret) {
		if(ret[0]) x = ret[0];
		if(ret[1]) y = ret[1];
		if(ret[2]) wx = ret[2];
		if(ret[3]) wy = ret[3];
	}
	param="menubar=no,scrollbars=yes,personalbar=no,toolbar=no,location=no,directories=no,resizable=1,width="+x+",height="+y;
	z = new String(navigator.appVersion);
	z = parseInt(z.substring(0,1));
	if (z >3) {
		if (document.layers)
			param+=",screenX="+wx+",screenY="+wy;
		else if (document.all) param+=",left="+wx+",top="+wy;
	}
	janela=open(page,"asd",param);	
	if (browser) janela.focus();	
}
function Janela2(page) {
	x=500;y=500;
	wx=100;wy=100;
	ret=GetSize();
	if (ret) {
		if(ret[0]) x = ret[0];
		if(ret[1]) y = ret[1];
		if(ret[2]) wx = ret[2];
		if(ret[3]) wy = ret[3];
	}
	param="menubar=no,scrollbars=yes,personalbar=no,toolbar=no,location=no,directories=no,resizable=1,width="+500+",height="+y;
	z = new String(navigator.appVersion);
	z = parseInt(z.substring(0,1));
	if (z >3) {
		if (document.layers)
			param+=",screenX="+wx+",screenY="+wy;
		else if (document.all) param+=",left="+wx+",top="+wy;
	}
	janela=open(page,"asd",param);	
	if (browser) janela.focus();	
}
function miniJanela(page) {
	x=200;y=25;
	wx=200;wy=300;
	ret=GetSize();
	if (ret) {
		if(ret[0]) x = ret[0];
		if(ret[1]) y = ret[1];
		if(ret[2]) wx = ret[2];
		if(ret[3]) wy = ret[3];
	}
	param="menubar=no,scrollbars=no,personalbar=no,toolbar=no,location=no,directories=no,resizable=1,width="+200+",height="+25;
	z = new String(navigator.appVersion);
	z = parseInt(z.substring(0,1));
	if (z >3) {
		if (document.layers)
			param+=",screenX="+wx+",screenY="+wy;
		else if (document.all) param+=",left="+wx+",top="+wy;
	}
	janela=open(page,"asd",param);	
	if (browser) janela.focus();	
}

function miniJanela2(page) {
	x=200;y=25;
	wx=200;wy=300;
	ret=GetSize();
	if (ret) {
		if(ret[0]) x = ret[0];
		if(ret[1]) y = ret[1];
		if(ret[2]) wx = ret[2];
		if(ret[3]) wy = ret[3];
	}
	param="menubar=no,scrollbars=no,personalbar=no,toolbar=no,location=no,directories=no,resizable=1,width="+300+",height="+30;
	z = new String(navigator.appVersion);
	z = parseInt(z.substring(0,1));
	if (z >3) {
		if (document.layers)
			param+=",screenX="+wx+",screenY="+wy;
		else if (document.all) param+=",left="+wx+",top="+wy;
	}
	janela=open(page,"asd",param);	
	if (browser) janela.focus();	
}

function zeracampo(campo)
{
	campo.value = "";
}

function voltacampobuscacliente(campo)
{
	if(campo.value == ""){
		campo.value = "Buscar Cliente";
	}
	return;
}

function voltacampobuscausuario(campo)
{
	if(campo.value == ""){
		campo.value = "Buscar Usuário";
	}
	return;
}

function voltacampobuscaproduto(campo)
{
	if(campo.value == ""){
		campo.value = "Buscar Produto";
	}
	return;
}


function SecuritySenha(val, tamanho) {
	document.getElementById('mensagem').innerHTML = "Baixo";
 	document.getElementById('d_baixa').style.background = '#E4EBF1';
 	document.getElementById('d_media').style.background = '#E4EBF1';
 	document.getElementById('d_alta').style.background = '#E4EBF1';
 
	if( val.length >= tamanho && val.search(/[a-z]/) != -1 && val.search(/[A-Z]/) != -1 && val.search(/[0-9]/) != -1 
		||val.length >= tamanho && val.search(/[a-z]/) != -1 && val.search(/[A-Z]/) != -1 && val.search(/[@!#$%&*+=?|-]/) 
		||val.length >= tamanho && val.search(/[a-z]/) != -1 && val.search(/[@!#$%&*+=?|-]/) != -1 && val.search(/[0-9]/) 
		||val.length >= tamanho  && val.search(/[@!#$%&*+=?|-]/) != -1 && val.search(/[A-Z]/) != -1 && val.search(/[0-9]/) )
		{
				document.getElementById('mensagem').innerHTML = "Alto";
  			document.getElementById('d_baixa').style.background = 'green';
 				document.getElementById('d_media').style.background = 'green';
 				document.getElementById('d_alta').style.background = 'green';
  		
  	} 
  	else{
  		if( val.length >= tamanho && val.search(/[a-z]/) != -1 && val.search(/[A-Z]/) != -1 
  			||val.length >= tamanho && val.search(/[a-z]/) != -1 && val.search(/[0-9]/) != -1 
  			||val.length >= tamanho && val.search(/[a-z]/) != -1 && val.search(/[@!#$%&*+=?|-]/) != -1
				||val.length >= tamanho && val.search(/[A-Z]/) != -1 && val.search(/[0-9]/) != -1
				||val.length >= tamanho && val.search(/[A-Z]/) != -1 && val.search(/[@!#$%&*+=?|-]/) != -1
				||val.length >= tamanho && val.search(/[0-9]/) != -1 && val.search(/[@!#$%&*+=?|-]/) != -1){

				document.getElementById('mensagem').innerHTML = "Médio";
 				document.getElementById('d_baixa').style.background = 'yellow';
 				document.getElementById('d_media').style.background = 'yellow';
 				document.getElementById('d_alta').style.background = '#E4EBF1';
  				
  			} 
  			else {
  				if(val.length >= tamanho)
  				{
	  				document.getElementById('mensagem').innerHTML = "Baixo";
  					document.getElementById('d_baixa').style.background = 'red';
 						document.getElementById('d_media').style.background = '#E4EBF1';
 						document.getElementById('d_alta').style.background = '#E4EBF1';
  					
  				}
  		}
  	}
  }
  
   function caixaAlta(campo){
		campo.value = campo.value.toUpperCase();  
   }
     
	function caixaBaixa(campo){
		campo.value = campo.value.toLowerCase();
   }
 
 	function campoFocus(campo){
		campo.style.background = '#F8FECD';
   }
 	function campoUnFocus(campo){
		campo.style.background = '#FFFFFF';
   }   
 	function campoErro(campo){
		campo.style.background = '#FADEDE';
   }     
 	function campoFocusOrc(campo){
		campo.style.background = '#FFFFFF';
   }
 	function campoUnFocusOrc(campo){
		campo.style.background = '#EAEBEC';
   }     
   
function validaP1(form){
	
	if(form.nome.value.length < 10){
		alert('Informe seu nome completo!');
		form.nome.focus();
		campoErro(form.nome);
		return false;
	}
	if((form.ddd.value.length < 2) || (parseInt(form.ddd.value) < 10) || (parseInt(form.ddd.value) > 99)){
		alert('O DDD inserido não é valido!');
		form.ddd.focus();
		campoErro(form.ddd);
		return false;
	}	
	if((form.celular.value.length < 8)){
		alert('O celular inserido não é valido!');
		form.celular.focus();
		campoErro(form.celular);
		return false;
	}		
	
	if(!(confirm('Você leu as instruções para continuar?'))){
		return false;
	}
	return true;
}
 
function mascara_cep(cep){
    var mytel = '';
    mytel = mytel + cep.value;
    if (mytel.length == 2) {
        mytel = mytel + '.';
        cep.value = mytel;
    }
    if (mytel.length == 6) {
        mytel = mytel + '-';
        cep.value = mytel;
    }
    if (mytel.length == 10) {
    }
}	

function mascara_telefone(tel)
{
    var mytel = '';
    mytel = mytel + tel.value;
    if (mytel.length == 0) {
        mytel = mytel + '(';
        tel.value = mytel;
    }
    if (mytel.length == 3) {
        mytel = mytel + ')';
        tel.value = mytel;
    }
    if (mytel.length == 8) {
        mytel = mytel + '-';
        tel.value = mytel;
    }
    if (mytel.length == 13) {
    }
}

function mascara_data(data)
{
    var mytel = '';
    mytel = mytel + data.value;
    if (mytel.length == 2) {
        mytel = mytel + '/';
        data.value = mytel;
    }
    if (mytel.length == 5) {
        mytel = mytel + '/';
        data.value = mytel;
    }
}


function confirmBox(msg,location){
	if(confirm(msg)) {
	location.href=location;}
}


//Mascara de Valores
function currencyFormat(fld, milSep, decSep, e) {
	var sep = 0;
	var key = '';
	var i = j = 0;
	var len = len2 = 0;
	var strCheck = '0123456789';
	var aux = aux2 = '';
	var whichCode = (window.Event) ? e.which : e.keyCode;
	if ((whichCode == 13)||(whichCode == 8)||(whichCode == 46)||(whichCode == 37)||(whichCode == 39)||(whichCode == 0)) return true;  // Enter
	key = String.fromCharCode(whichCode);  // Get key value from key code
	if (strCheck.indexOf(key) == -1) return false;  // Not a valid key
	len = fld.value.length;
	for(i = 0; i < len; i++)
	if ((fld.value.charAt(i) != '0') && (fld.value.charAt(i) != decSep)) break;
	aux = '';
	for(; i < len; i++)
	if (strCheck.indexOf(fld.value.charAt(i))!=-1) aux += fld.value.charAt(i);
	aux += key;
	len = aux.length;
	if (len == 0) fld.value = '';
	if (len == 1) fld.value = '0'+ decSep + '0' + aux;
	if (len == 2) fld.value = '0'+ decSep + aux;
	if (len > 2) {
	aux2 = '';
	for (j = 0, i = len - 3; i >= 0; i--) {
	if (j == 3) {
	aux2 += milSep;
	j = 0;
	}
	aux2 += aux.charAt(i);
	j++;
	}
	fld.value = '';
	len2 = aux2.length;
	for (i = len2 - 1; i >= 0; i--)
	fld.value += aux2.charAt(i);
	fld.value += decSep + aux.substr(len - 2, len);
	}
	return false;
}

