// 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;
    }
}
	

function URLEncode(valor)
{
  var plaintext = valor;
  //if (document.URLForm.RFC2396.checked) {  // OLD Browser mode
    // The Javascript escape and unescape functions do not correspond
    // with what browsers actually do...
    var SAFECHARS = "0123456789" +					// Numeric
		        "ABCDEFGHIJKLMNOPQRSTUVWXYZ" +	// Alphabetic
		        "abcdefghijklmnopqrstuvwxyz" +
		        "-_.!~*'()";					// RFC2396 Mark characters
    var HEX = "0123456789ABCDEF";

    var encoded = "";
    for (var i = 0; i < plaintext.length; i++ ) {
      var ch = plaintext.charAt(i);
        if (ch == " ") {
          encoded += "+";				// x-www-urlencoded, rather than %20
      } else if (SAFECHARS.indexOf(ch) != -1) {
          encoded += ch;
      } else {
          var charCode = ch.charCodeAt(0);
        if (charCode > 255) {
            alert( "Unicode Character '" 
                          + ch 
                          + "' cannot be encoded using standard RFC2396 encoding.\n" +
	                  "(URL encoding only supports 8-bit characters.)\n" +
			          "A space (+) will be substituted." );
	        encoded += "+";
        } else {
	        encoded += "%";
	        encoded += HEX.charAt((charCode >> 4) & 0xF);
	        encoded += HEX.charAt(charCode & 0xF);
        }
      }
    } // for

   // return encoded;
  //} else {  // Modern browser mode
   return encodeURIComponent(plaintext);
 // }
 // document.URLForm.F2.select();
	//return false;
}


//VALIDAÇÕES


// VALIDA CONTATO
function vldContato()
           {
		
          if(window.document.getElementById("str_Assunto").value == '') {
         	Sexy.alert('<h1>Alerta</h1><br/><p>Adicione o assunto!</p>');
            return false;
            }
          else if(window.document.getElementById("str_Empresa").value == '') {
           Sexy.alert('<h1>Alerta</h1><br/><p>Informe a empresa!</p>');
           return false;
          }
		  else if(window.document.getElementById("str_Nome").value == '') {
           Sexy.alert('<h1>Alerta</h1><br/><p>Informe o nome!</p>');
           return false;
            }
          else if(window.document.getElementById("str_Email").value == '') {
           Sexy.alert('<h1>Alerta</h1><br/><p>Informe o e-mail!</p>');
           return false;
          }
		  else if(isEmail(window.document.getElementById("str_Email"),'')==false) {
           Sexy.alert('<h1>Alerta</h1><br/><p>Informe um e-mail v&aacute;lido!</p>');
           return false;
          }
		  else if(window.document.getElementById("str_Mensagem").value == '') {
           Sexy.alert('<h1>Alerta</h1><br/><p>Adicione uma mensagem!</p>');
           return false;
          }
    }
	
	
function vldFornecedor()
           {
		
          if(window.document.getElementById("str_Assunto").value == '') {
         	Sexy.alert('<h1>Alerta</h1><br/><p>Adicione o assunto!</p>');
            return false;
            }
          else if(window.document.getElementById("str_Empresa").value == '') {
           Sexy.alert('<h1>Alerta</h1><br/><p>Informe a empresa!</p>');
           return false;
          }
		  else if(window.document.getElementById("str_Nome").value == '') {
           Sexy.alert('<h1>Alerta</h1><br/><p>Informe o nome!</p>');
           return false;
            }
          else if(window.document.getElementById("str_Email").value == '') {
           Sexy.alert('<h1>Alerta</h1><br/><p>Informe o e-mail!</p>');
           return false;
          }
		  else if(isEmail(window.document.getElementById("str_Email"),'')==false) {
           Sexy.alert('<h1>Alerta</h1><br/><p>Informe um e-mail v&aacute;lido!</p>');
           return false;
          }
		  else if(window.document.getElementById("str_Mensagem").value == '') {
           Sexy.alert('<h1>Alerta</h1><br/><p>Adicione uma mensagem!</p>');
           return false;
          }
    }
	
	
	
	
function vldTrabalhe(){
	if(window.document.getElementById("str_File").value == '') {
         	Sexy.alert('<h1>Alerta</h1><br/><p>Anexe seu curriculo!</p>');
            return false;
     }
}
	
