
function Launch(page, width, height) { 
	OpenWin = this.open(page, "kirupa", "toolbar=no, menubar=no ,location=no, scrollbars=no, resizable=yes, width=" + width + ", height=" + height + ", top=" + (screen.height/2 - height/2) + ", left=" + (screen.width/2 - width/2) + "\""); 
} 
function dispHide(divId, opcao){
	var	divId = document.getElementById(divId);
	if(opcao=='none' || opcao=='block')
		divId.style.display=opcao;
	else{
		if(divId.style.display=='' || divId.style.display=='block')
			divId.style.display='none'
		else 
			divId.style.display='block'
	}
		/*alert(divId.style.display);*/
}


function validaFormCurr(){
	arrayNoEmpty = new Array("info_pessoal[nome]", 
								"info_pessoal[sexo]", 
								"info_pessoal[nascDia]",
								"info_pessoal[nascMes]",
								"info_pessoal[nascAno]",
								"info_pessoal[cpf]",
								"info_pessoal[estCivil]",
								"info_pessoal[endereco]",
								"info_pessoal[bairro]",
								"info_pessoal[cep]",
								"info_pessoal[cidade]",
								"info_pessoal[uf]",
								"info_pessoal[dddTelMain]",
								"info_pessoal[telMain]",
								"info_pessoal[chkDeficiencia]",
								"info_pessoal[chkAcessorio]",
								"profissional[interesse]",
								"profissional[cargo]");
	arrayNoEmptyName = new Array("Nome", 
								"Sexo", 
								"Dia Nascimento",
								"Mês  Nascimento",
								"Ano  Nascimento",
								"Cpf",
								"Estado Civil",
								"Endereco",
								"Bairro",
								"Cep",
								"Cidade",
								"Uf",
								"Ddd",
								"Telefone",
								"Deficiência",
								"Acessório",
								"Interesse",
								"Cargo");
	for(i=0; i<arrayNoEmpty.length; i++){
		if(document.getElementById(arrayNoEmpty[i]).value==''){
			alert('O campo "'+arrayNoEmptyName[i]+'" é um Campo Obrigatório');
			document.getElementById(arrayNoEmpty[i]).focus();
			return false;
		}
	}
	cpfValida = document.getElementById(arrayNoEmpty[5])
	var invalid, s;
	invalid = /^\w+([\.-]?\w+)*@\w+([\.-]?\w+)*(\.\w{2,4})+$/;

	var s;
	// inicio de verificacao de cnpj ou cpf
	if (cpfValida.value.length == 0) {
		alert("O CNPJ/CPF é um campo obrigatório !");
		cpfValida.focus();
		return false;	}
		
	s = limpa_string(cpfValida.value);


	// checa se é cpf
	if (s.length == 11) {
		if (valida_CPF(cpfValida.value) == false ) {
			alert("O CPF não é válido !");
			cpfValida.focus();
			return false;	
		}
	 }
	 
	 // checa se é cgc
	else 
		if (s.length == 14 || s.length == 15) {
			if (valida_CGC(cpfValida.value) == false ) {
				alert("O CNPJ não é válido !");
				cpfValida.focus();
				return false;	}
				}
			else {
				alert("O CPF/CNPJ não é válido !");
				cpfValida.focus();
				return false;
			}
	if(document.getElementById('info_pessoal[email]').value!=''){
		validaMail('info_pessoal[email]');
		if(mailValido==0)
			return false;
	}

		//return false;
}			
function validaMail(docId){
	mailValido = 1;
	if (!(/^\w+([\.-]?\w+)*@\w+([\.-]?\w+)*(\.\w{2,3})+$/.test(document.getElementById(docId).value))) 
    { 
		alert("E-mail Inválido");
		document.getElementById(docId).focus();
		mailValido = 0; 
		return false;
	}else
		mailValido = 1; 
}

function limpa_string(S){
	// Deixa so' os digitos no numero
	var Digitos = "0123456789";
	var temp = new Array();
	var digito = "";
	var numFinal = "";
	var a =	0;
	for (var i=0; i<S.length; i++)	{
		digito = S.charAt(i);
		if (Digitos.indexOf(digito)>=0)	{
			temp[a]=digito	
			a++;
		}

	} //for
	if(temp.length==15)
		ini = 1;
	else
		ini = 0;
	for(d=ini; d<temp.length; d++)	{
		numFinal += temp[d]
	}
	return numFinal
}
// fim da funcao
function valida_CPF(s)	{
	var i;
	s = limpa_string(s);
	var c = s.substr(0,9);
	var dv = s.substr(9,2);
	var d1 = 0;
	for (i = 0; i < 9; i++)
	{
		d1 += c.charAt(i)*(10-i);
	}
        if (d1 == 0) return false;
	d1 = 11 - (d1 % 11);
	if (d1 > 9) d1 = 0;
	if (dv.charAt(0) != d1)
	{
		return false;
	}

	d1 *= 2;
	for (i = 0; i < 9; i++)
	{
		d1 += c.charAt(i)*(11-i);
	}
	d1 = 11 - (d1 % 11);
	if (d1 > 9) d1 = 0;
	if (dv.charAt(1) != d1)
	{
		return false;
	}
        return true;
}

function valida_CGC(s)
{
	var i;
	s = limpa_string(s);
	var c = s.substr(0,12);
	var dv = s.substr(12,2);
	var d1 = 0;
	for (i = 0; i < 12; i++)
	{
		d1 += c.charAt(11-i)*(2+(i % 8));
	}
        if (d1 == 0) return false;
        d1 = 11 - (d1 % 11);
	if (d1 > 9) d1 = 0;
	if (dv.charAt(0) != d1)
	{
		return false;
	}

	d1 *= 2;
	for (i = 0; i < 12; i++)
	{
		d1 += c.charAt(11-i)*(2+((i+1) % 8));
	}
	d1 = 11 - (d1 % 11);
	if (d1 > 9) d1 = 0;
	if (dv.charAt(1) != d1)
	{
		return false;
	}
	return true;
}

function FormataCPF_CNPJ( el ) 
{ 
	vr = el.value; 
    tam = vr.length;

	if(tam==11){
		if ( vr.indexOf(".") == -1 ) 
		{ 
			if ( tam <= 3 ) 
				el.value = vr; 

			if ( (tam > 3) && (tam <= 7) ) 
				el.value = vr.substr( 0, 3 ) + '.' + vr.substr( 4, tam ); 

			if ( (tam >= 8) && (tam <= 11) ) 
				el.value = vr.substr( 0, 3 ) + '.' + vr.substr( 3, 3 ) + '.' + vr.substr( 5, 3 ) + '-'; 

			if ( (tam >= 11) && (tam <= 18) ) 
				el.value = vr.substr( 0, 3 ) + '.' + vr.substr( 3, 3 ) + '.' + vr.substr( 6, 3 ) + '-' + vr.substr( 9, 2 ); 
		} 
	}else{
		if(tam==14){
			  if ( vr.indexOf(".") == -1 ) 
			  { 
			  if ( tam <= 2 ) 
					  el.value = vr; 
			  if ( (tam > 2) && (tam <= 6) ) 
					  el.value = vr.substr( 0, 2 ) + '.' + vr.substr( 2, tam ); 
			  if ( (tam >= 7) && (tam <= 10) ) 
					  el.value = vr.substr( 0, 2 ) + '.' + vr.substr( 2, 3 ) + '.' 
			+ vr.substr( 5, 3 ) + '/'; 
			  if ( (tam >= 11) && (tam <= 18) ) 
					 el.value = vr.substr( 0, 2 ) + '.' + vr.substr( 2, 3 ) + '.' + 
			vr.substr( 5, 3 ) + '/' + vr.substr( 8, 4 ) + '-' + vr.substr( 12, 2 ) ; 
			  } 
		}else if(tam==15)
				el.value = vr.substr( 0, 3 ) + '.' + vr.substr( 3, 3 ) + '.' + vr.substr( 6, 3 ) + '/' + vr.substr( 9, 4 ) + '-' + vr.substr( 13, 2 ) ; 
		else return false;
	}
	return true;
} 
function soNumeros(){
	if (event.keyCode < 45 || event.keyCode > 57 || event.keyCode==32 ||event.keyCode==40 || event.keyCode==41 || event.keyCode>=44 && event.keyCode<=47)
		event.returnValue = false;
}

function FormataCEP(cepF){
	var cep = cepF.value;
	if(cep.length==8) 
	cep = cep.substr(0,5)+'-'+cep.substr(5,8);	
	return cepF.value = cep;
}
function formataClubinho(){
		arrayNoEmpty = new Array("contato[nome]", 
								"contato[nick]", 
								"contato[email]", 
								"contato[senha]", 
								"contato[nascDia]", 
								"contato[nascMes]", 
								"contato[nascAno]", 
								"contato[endereco]", 
								"contato[end_bairro]", 
								"contato[cidade]", 
								"contato[uf]" 
								);
	arrayNoEmptyName = new Array("Nome", 
								"Nick", 
								"E-Mail", 
								"Senha",
								"Dia Nascimento",
								"Mês Nascimento",
								"Ano Nascimento",
								"Endereço",
								"Bairro",
								"Cidade",
								"Uf"
								);
	for(i=0; i<arrayNoEmpty.length; i++){
		if(document.getElementById(arrayNoEmpty[i]).value==''){
			alert('O campo "'+arrayNoEmptyName[i]+'" é um Campo Obrigatório');
			document.getElementById(arrayNoEmpty[i]).focus();
			return false;
		}
	}
	validaMail('contato[email]');
		if(mailValido==0)
			return false;

}
function addCargoVerif(tipo){
	if(tipo=='' || tipo=='vaga'){
		vaga_cargo = document.getElementById('vaga_cargo');
		if(vaga_cargo.value == ''){
			alert('Preencha o Campo Cargo');
			vaga_cargo.focus();
			return false;
		}
	}else if(tipo=='cargo'){
		vaga_cargo = document.getElementById('cargo_nome');
		if(vaga_cargo.value == ''){
			alert('Preencha o Campo Cargo');
			vaga_cargo.focus();
			return false;
		}
	}
	//vaga_qtd
	//vaga_obs

}

var xmlhttp
	function loadXMLDoc(url, idWrite, tRequest, opcao, divLoad)
	{
		carrega=0
		if(tRequest!="GET" || tRequest!="POST")
			tRequest = "GET";
		element	 =  document.getElementById(idWrite);
		 if(opcao!='alert'){
			if(divLoad==null && carrega!=1){
				element.innerHTML  = "<div style='text-align:center; position:absolute; z-index:200; margin-top:80px; margin-left:400px;'><img src='images/loading.gif'> CARREGANDO...</div>";
				carrega=1;
			//<div style=\"color:#FF0000; background-color:#FFFFFF; width: 700px; height: 300px; margin:0 auto; text-align:center;\">Carregando...</div>";   
			}else {
				if(carrega!=1){
					element.innerHTML  = divLoad;
					carrega=1;
				}
			}

		 }
	// code for Mozilla, etc.
	if (window.XMLHttpRequest)
	  {
	  xmlhttp=new XMLHttpRequest()
	  xmlhttp.onreadystatechange=function(){
		if (xmlhttp.readyState==4)
		{
				// if OK
				if (xmlhttp.status==200)
				{
				  if(opcao=='alert')			
					  alert(unescape(xmlhttp.responseText.replace(/\+/g," ")));
					else{
						texto = unescape(xmlhttp.responseText.replace(/\+/g," "));
						element.innerHTML=texto;
						carrega=0;
					}
				}
				else
				{
					alert("Problem Ao Tentar Abrir Arquivo:" + xmlhttp.statusText)
				}
		  }
	  }
	  xmlhttp.open(tRequest,url,true)
	  xmlhttp.send(null)
	  }
	// code for IE
	else if (window.ActiveXObject)
	  {
	  xmlhttp=new ActiveXObject("Microsoft.XMLHTTP")
		if (xmlhttp)
		{
		xmlhttp.onreadystatechange=function(){
		if (xmlhttp.readyState==4)
		{
				// if OK
				if (xmlhttp.status==200)
				{
					retorno = (xmlhttp.responseText)
					if(opcao=='alert')			
						alert(unescape(xmlhttp.responseText.replace(/\+/g," ")));
					else{
						texto = unescape(xmlhttp.responseText.replace(/\+/g," "));
						element.innerHTML=texto;
					}
						

				  //alert(element.innerHTML);
				}
				else
				{
					alert("Problem Ao Tentar Abrir Arquivo:" + xmlhttp.statusText)
				}
		  }
	  }
		xmlhttp.open(tRequest,url,true)
		if(tRequest=="POST")
			xmlhttp.setRequestHeader("Content-Type", "application/x-www-form-urlencoded");
		xmlhttp.send()
		}
	  }
	}

function retornaAlert(mensagem){
	alert(mensagem);
}
function url_encode(str) { 
	var hex_chars = "0123456789ABCDEF"; 
	var noEncode = /^([a-zA-Z0-9\_\-\.])$/; 
	var n, strCode, hex1, hex2, strEncode = ""; 

	for(n = 0; n < str.length; n++) { 
		if (noEncode.test(str.charAt(n))) { 
			strEncode += str.charAt(n); 
		} else { 
			strCode = str.charCodeAt(n); 
			hex1 = hex_chars.charAt(Math.floor(strCode / 16)); 
			hex2 = hex_chars.charAt(strCode % 16); 
			strEncode += "%" + (hex1 + hex2); 
		} 
	} 
	return strEncode; 
}
function url_decode(str) { 
	var n, strCode, strDecode = ""; 

	for (n = 0; n < str.length; n++) { 
		if (str.charAt(n) == "%") { 
			strCode = str.charAt(n + 1) + str.charAt(n + 2); 
			strDecode += String.fromCharCode(parseInt(strCode, 16)); 
			n += 2; 
		} else { 
			strDecode += str.charAt(n); 
		} 
	} 

	return strDecode; 
}
function fechaJanela(){
	window.close()
}
var http_request = false;
function makePOSTRequest(url, parameters) {
  http_request = false;
  if (window.XMLHttpRequest) { // Mozilla, Safari,...
	 http_request = new XMLHttpRequest();
	 if (http_request.overrideMimeType) {
		http_request.overrideMimeType('text/xml');
	 }
  } else if (window.ActiveXObject) { // IE
	 try {
		http_request = new ActiveXObject("Msxml2.XMLHTTP");
	 } catch (e) {
		try {
		   http_request = new ActiveXObject("Microsoft.XMLHTTP");
		} catch (e) {}
	 }
  }
  if (!http_request) {
	 alert('Cannot create XMLHTTP instance');
	 return false;
  }
  
  http_request.onreadystatechange = alertContents;
  http_request.open('POST', url, true);
  http_request.setRequestHeader("Content-type", "application/x-www-form-urlencoded");
  http_request.setRequestHeader("Content-length", parameters.length);
  http_request.setRequestHeader("Connection", "close");
  http_request.send(parameters);
}

function alertContents() {
  if (http_request.readyState == 4) {
	 if (http_request.status == 200) {
		//alert(http_request.responseText);
		result = http_request.responseText;
		texto = unescape(result.replace(/\+/g," "));
		document.getElementById('myspan').innerHTML=texto;
	 } else {
		alert('There was a problem with the request.');
	 }
  }
}
function formContato(form) {
	validaMail('contato[email]'); 
	if(mailValido==1){
		var poststr = "contato[nome]=" + encodeURI(document.getElementById("contato[nome]").value ) + 
					  "&contato[email]=" + encodeURI( document.getElementById("contato[email]").value ) + 
					  "&contato[comentario]=" + encodeURI( document.getElementById("contato[comentario]").value ) + 
					  "&contato[recebe_news]=" + encodeURI(document.getElementById("contato[recebe_news]").value);

		///alert(poststr);
		makePOSTRequest(form, poststr);
	}
}
function mudaCssClass(divId, classe){
	document.getElementById(divId).className = classe;
}

function formRepresAdd(url){
	selUf = document.getElementById('representante[uf]'); 
	if(selUf.value==''){
		alert('Selecione um Estado'); 
		selUf.focus(); 
		return false;
	}
	else{
		validaMail('representante[email]');
		if(mailValido==1){
			var poststr = "";
			for (i=0;i<document.formAddRepr.length;i++){
				poststr += document.formAddRepr[i].name+'='+encodeURI(document.formAddRepr[i].value);
				if(i<(document.formAddRepr.length-1)){
					poststr += '&'
				}
			}
			makePOSTRequest(url, poststr);		
		}
	}
}