// JavaScript Document

function MM_swapImgRestore() { //v3.0
  var i,x,a=document.MM_sr; for(i=0;a&&i<a.length&&(x=a[i])&&x.oSrc;i++) x.src=x.oSrc;
}
function MM_preloadImages() { //v3.0
  var d=document; if(d.images){ if(!d.MM_p) d.MM_p=new Array();
    var i,j=d.MM_p.length,a=MM_preloadImages.arguments; for(i=0; i<a.length; i++)
    if (a[i].indexOf("#")!=0){ d.MM_p[j]=new Image; d.MM_p[j++].src=a[i];}}
}

function MM_findObj(n, d) { //v4.01
  var p,i,x;  if(!d) d=document; if((p=n.indexOf("?"))>0&&parent.frames.length) {
    d=parent.frames[n.substring(p+1)].document; n=n.substring(0,p);}
  if(!(x=d[n])&&d.all) x=d.all[n]; for (i=0;!x&&i<d.forms.length;i++) x=d.forms[i][n];
  for(i=0;!x&&d.layers&&i<d.layers.length;i++) x=MM_findObj(n,d.layers[i].document);
  if(!x && d.getElementById) x=d.getElementById(n); return x;
}

function MM_swapImage() { //v3.0
  var i,j=0,x,a=MM_swapImage.arguments; document.MM_sr=new Array; for(i=0;i<(a.length-2);i+=3)
   if ((x=MM_findObj(a[i]))!=null){document.MM_sr[j++]=x; if(!x.oSrc) x.oSrc=x.src; x.src=a[i+2];}
}



//ROLL OVER CAMPOS
function limpa(valor, campo,tipo) {
          if (tipo == "a") {
              if (valor == "Nome") {
                  document.getElementById(campo).value = "";
            }
        }
        if (tipo == "b") {
            if (valor == "E-mail") {
                document.getElementById(campo).value = "";
            }
        }
    }
	    function preenche(valor, campo, tipo) {
        if (tipo == "a") {
            if (valor == "") {
                document.getElementById(campo).value = "Nome";
            }
        }
        if (tipo == "b") {
            if (valor == "") {
                document.getElementById(campo).value = "E-mail";
            }
        }
    }

//ROLL OVER CAMPOS


// VALIDAÇÕES

	
	
	
	function isNumeric(iCampo,iNomeCampo) {
	while(iCampo.value.indexOf('.') != -1) {iCampo.value = iCampo.value.replace('.','')}
	while(iCampo.value.indexOf(' ') != -1) {iCampo.value = iCampo.value.replace(' ','')}
	while(iCampo.value.indexOf('-') != -1) {iCampo.value = iCampo.value.replace('-','')}
	if (isNaN(iCampo.value) == true) {
		alert('Utilize apenas numeros para ' + iNomeCampo);
		/* iCampo.focus(); iCampo.select(); */ return false;
	}
}

function isNumerico(iCampo,iNomeCampo) {
	if (isNaN(iCampo.value) == true) {
		alert('Utilize apenas numeros para ' + iNomeCampo);
		/* iCampo.focus(); iCampo.select(); */ return false;
	}
}

function isEmail(iCampo,iNomeCampo) {
	var str = iCampo.value;
		alert(str);
	var r1 = new RegExp("(@.*@)|(\\.\\.)|(@\\.)|(^\\.)");
	var r2 = new RegExp("^.+\\@(\\[?)[a-zA-Z0-9\\-\\.]+\\.([a-zA-Z]{2,3}|[0-9]{1,3})(\\]?)$");
	if ( (!r1.test(str) && r2.test(str)) ) {
		return true;
	} else {
		/* iCampo.focus(); iCampo.select(); */
		//alert(iNomeCampo+" invalido.");
		return false;
	}
	return true;
}

function EhIgual(campo) { /* Verifica se todos os valores são iguais */
	var i = 0
	var j = 1
	var igual = true;
	/* Todos os caracteres devem ser diferentes */
	while (i < campo.length-1 && igual == true) {
		while (j < campo.length && igual == true) {
			if (campo.charAt(i) != campo.charAt(j)) {
				igual = false;
			}
			else j++;
		}
		i++;
	}
	return igual;
}

function isVazio(iCampo,iNomeCampo) {
	if (iCampo.value == false) {
		alert(iNomeCampo + ' e obrigatorio.');
		iCampo.focus();
		return false;
	}
	return true;
}

function isCPF(iCampo,iNomeCampo){
	if (isNumeric(iCampo,iNomeCampo)==false) {return false;};
	if (EhIgual(iCampo.value)==true) { 
		/* iCampo.focus(); */
		alert(iNomeCampo + ' é invalido.');
		return false; 
	}
	x=0; 
	soma=0; 
	dig1=0; 
	dig2=0; 
	texto=""; 
	iCampo1="";
	len = iCampo.value.length; 
	x = len -1;
	for (var i=0; i <= len - 3; i++) {
		y = iCampo.value.substring(i,i+1); 
		soma = soma + ( y * x);
		x = x - 1; 
		texto = texto + y;
	}
	dig1 = 11 - (soma % 11);
	if (dig1 == 10) dig1=0 ; 
	if (dig1 == 11) dig1=0 ;
	iCampo1 = iCampo.value.substring(0,len - 2) + dig1 ;
	x = 11; soma=0;
	for (var i=0; i <= len - 2; i++) {
		soma = soma + (iCampo1.substring(i,i+1) * x); 
		x = x - 1;
	}
	dig2= 11 - (soma % 11);
	if (dig2 == 10) dig2=0; 
	if (dig2 == 11) dig2=0;
	if ((dig1 + "" + dig2) == iCampo.value.substring(len,len-2)) {
		return true;
	}
	/* iCampo.focus(); */
	alert(iNomeCampo + ' e invalido.');
	return false; 
}

function isCNPJ(iCampo, iNomeCampo) {
	if (EhIgual(iCampo.value)==true) { 
		iCampo.focus();
		alert(iNomeCampo + ' e invalido.');
		return false; 
	}
	dac1 = 0; 
	dac2 = 0; 
	dac = ""; 
	dact = ""; 
	sum = 0;
	iCampo1="";
	dac = iCampo.value.substring(iCampo.value.length-2, iCampo.value.length);
	iCampo1 = iCampo.value.substring(0,iCampo.value.length-2);
	for (i=iCampo1.length-1, j=2; i >= 0 ; i--, j++) {	
		j = (j == 10) ? 2 : j; 
		sum += (iCampo1.substring(i, i+1) * j); 
	}
	dac1 = ((sum * 10) % 11); 
	dac1 = (dac1 == 10) ? 0 : dac1; 
	sum = 0;
	for (i=iCampo1.length-1, j=3; i >= 0 ; i--, j++){	
		j = (j == 10) ? 2 : j; 
		sum += (iCampo1.substring(i, i+1) * j); 
	}
	sum  += (dac1 * 2); 
	dac2 = ((sum * 10) % 11); 
	dac2 = (dac2 == 10) ? 0 : dac2; 
	dact = dac1+""+dac2;
	if (dact == dac) {
		return true;
	} else {	
		iCampo.focus();
		alert(iNomeCampo + ' e invalido.');
		return false; 
	}
}

function isData(strData,dataObj,alertData) {
	var exprData = new RegExp("(0[1-9]|[12][0-9]|3[01])/(0[1-9]|1[012])/(19|20)[0-9]{2}", "gi");

	ret = exprData.exec(strData);

	if(strData == '' || ret == null){
		alert(alertData); /* dataObj.focus() */ ;return false;
	} else {
		arrData = strData.split('/');
		testData = new Date(arrData[2], arrData[1]-1, arrData[0], 0, 0, 0, 0);

		if((testData.getDate()==arrData[0])&&
			 ((testData.getMonth())==(arrData[1]-1))&&
				(testData.getFullYear()==arrData[2])){
		} else {
			alert(alertData); /* dataObj.focus();dataObj.select(); */ return false;
		}
	}
}
function prc_campo(campo, qtd, valor) {
    if (valor.length == qtd) {
        document.getElementById(campo).focus();
    }


}

var isNav4, isNav, isIE;
if (parseInt(navigator.appVersion.charAt(0)) >= 4) {
    isNav = (navigator.appName == "Netscape") ? true : false;
    isIE = (navigator.appName.indexOf("Microsoft") != -1) ? true : false;
}
if (navigator.appName == "Netscape") {
    isNav4 = (parseInt(navigator.appVersion.charAt(0)) == 4);
}
function onlynum(e) {
    var keyNumber = (isIE) ? event.keyCode : e.which;
    if (((keyNumber < 48) || (keyNumber > 57)) && (keyNumber != 13) && (keyNumber != "0") &&

(keyNumber != 8) && (keyNumber != 44)) {
        if (isIE) event.keyCode = 0;
        return false;
    }
}
	
	

//VALIDAÇÕES


// VALIDA CONTATO
function validaContato()
           {
			   var nform = document.formContato;
			   
          if(nform.cNome.value == '') {
           alert('Preencha seu nome!');
           nform.cNome.focus();
           return false;
            }
          if(nform.cEmail.value == '') {
           alert('Inform seu e-mail');
           nform.cEmail.focus();
           return false;
          }
		  if(nform.cDddTelefone.value == '') {
           alert('Informe o DDD!');
           nform.cDddTelefone.focus();
           return false;
            }
          if(nform.cTelefone.value == '') {
           alert('Inform seu telefone');
           nform.cTelefone.focus();
           return false;
          }
		  if(nform.cMensagem.value == '') {
           alert('Deixe sua mensagem');
           nform.cMensagem.focus();
           return false;
          }
            }
			