/* 
   Kairus T.I. - JavaScript File             
   Fevereiro de 2008
*/


function abrejanela(vURL,vNome,vParam) {
    window.open(vURL,vNome,vParam);
}

function validacontato() {

	if (document.fContato.txNome.value == "" || document.fContato.txNome.value.length<5) {
	   alert('Por favor, você precisa preencher o campo "Nome / Razão Social" completo!');
	   document.fContato.txNome.focus();
	   return;
	}

	if (!VerificaEmail(document.fContato.txEmail)) { return; }

	if (!ehnumerico(document.fContato.txDDD)) {
	   alert('Por favor, digite um valor numérico em "DDD".');
	   document.fContato.txDDD.focus();
	   return
	}
	if (!ehnumerico(document.fContato.txTelefone)) {
	   alert('Por favor, digite um valor numérico em "Telefone".');
	   document.fContato.txTelefone.focus();
	   return
	}

	if (document.fContato.txMensagem.value == "" || document.fContato.txMensagem.value.length<5) {
	   alert('Por favor, você precisa preencher o campo "Mensagem"!');
	   document.fContato.txMensagem.focus();
	   return;
	}

	document.fContato.submit();
	return;

}

function validadownload(vsite) {

	if (document.fDownload.txNome.value == "" || document.fDownload.txNome.value.length<5) {
           alert('Por favor, você precisa preencher o campo "Nome / Razão Social"!');
           document.fDownload.txNome.focus();
           return;
        }

        if (!ehnumerico(document.fDownload.txDDD)) {
           alert('Por favor, digite um valor numérico em "DDD".');
           document.fDownload.txDDD.focus();
           return
        }
        if (!ehnumerico(document.fDownload.txTelefone)) {
           alert('Por favor, digite um valor numérico em "Telefone".');
           document.fDownload.txTelefone.focus();
           return
        }

        if (!VerificaEmail(document.fDownload.txEmail)) { return; }

	document.fDownload.action = vsite; 
	document.fDownload.download.value='';
    document.fDownload.submit();
    return;

}

function downloadproduto(produto,versao,vNumero) {
	link='';

	if (vNumero==0) { link='/'+produto+'/'+versao+'-'+produto+'Full.zip' }
	else if (vNumero==1) { link='/'+produto+'/'+versao+'-'+produto+'Servidor.exe' }
	else if (vNumero==2) { link='/'+produto+'/'+versao+'-'+produto+'Cliente.exe' }
	else if (vNumero==3) { link='/'+produto+'/'+versao+'-'+produto+'.exe' }
	else { return; }

	document.fLicenca.download.value=link;
	document.fLicenca.action="/kairus.exe/download";
	document.fLicenca.submit();
	return;
}

function downloadproduto2(produto,versao,vNumero) {
	link='';

	if (vNumero==0) { link='/'+produto+'/'+versao+'-'+produto+'Full.zip' }
	else if (vNumero==1) { link='/'+produto+'/'+versao+'-'+produto+'Servidor.exe' }
	else if (vNumero==2) { link='/'+produto+'/'+versao+'-'+produto+'Cliente.exe' }
	else if (vNumero==3) { link='/'+produto+'/'+versao+'-'+produto+'.exe' }
	else { return; }

	document.fDownload.download.value=link;
	document.fDownload.action="/kairus.exe/download";
	document.fDownload.submit();
	return;
}

function ehnumerico(campo) {
	straux = campo.value + '#';
	i = 0;
	while (straux.charAt(i)!='#') {
	   if ((straux.charAt(i)>='0') && (straux.charAt(i)<='9'))
		  i++;
	   else {
		  return false;
	  }
   }
   if (i == 0 ) { return false; }
   return true;
}


function VerificaEmail(campo) {
  size=campo.value.length;
  i=1;
  flag=0;
  flagp=0
  retorno=true;
  while (i<=size)
  {
	  if ((campo.value.charAt(i)=="@") && (campo.value.charAt(i+1)!="")) {
		 flag=1;
	  }
	  if ((campo.value.charAt(i)==".") && (campo.value.charAt(i+1)!="")) {
		 flagp=1;
	  }
	  i++;
  }
 if ((flag==0) || (flagp==0)) {
	alert ("Por favor, digite um e-mail válido");
	campo.value="";
	campo.focus();
	retorno=false;
  }
 return retorno;

}
