/*
	Funções padrões para os sites
	
	Criada em 25/04/2007 por Rafael Gomes Alcantara
	Email: rafael.gomes@ithink.com.br
	iThink Professional Services
	www.ithink.com.br
*/

function procWidth(obj){
	var curwidth = 0;
	if (obj.offsetParent){
		curwidth = obj.offsetWidth;
	}else if (obj.x){
		curwidth = obj.width;
	}
	return curwidth;
}

function procHeight(obj){
	var curheight = 0;
	if (obj.offsetParent){
		curheight = obj.offsetHeight;
	}else if (obj.x){
		curheight = obj.height;
	}
	return curheight;
}

function procPosX(obj){
	var curleft = 0;
	if (obj.offsetParent){
		while (obj.offsetParent){
			curleft += obj.offsetLeft
			obj = obj.offsetParent;
		}
	}else if (obj.x){
		curleft += obj.x;
	}
	return curleft;
}

function procPosY(obj){
	var curtop = 0;
	if (obj.offsetParent){
		while (obj.offsetParent){
			curtop += obj.offsetTop
			obj = obj.offsetParent;
		}
	}else if (obj.y){
		curtop += obj.y;
	}
	return curtop;
}


function posicao(obj, reference, dist) {
	var newX = procPosX(reference);
	var newY = procPosY(reference);
	var newWidth = procWidth(reference);
	var newHeight = procHeight(reference);
	
	if(obj.id.substring(10,11) > 1){
		obj.style.left = newX + newWidth - 15;
	}else{
		obj.style.left = newX + newWidth;
	}
	obj.style.top = newY + dist;
}

var totPatroFAQ = 0;
function abriPerg(pRep){
	var _rep = document.getElementById(pRep);
	//
	for(var i=1; i<=totPatroFAQ ;i++){
		var tmpRep = document.getElementById("rep"+i);
		//
		if(tmpRep != null){
			tmpRep.style.display = "none";
		}
	}
	_rep.style.display = "block";
	
}

function OpenPopup(arq, width, height, scroll){    
	 var URL = arq 
	 var W = width 
	 var H = height 
	 var S = scroll 
	 var Wpopupsize =(W/2); 
	 var Hpopupsize =(H/2); 
	 var CenterPopUpX = (screen.width/2)-(Wpopupsize); 
	 var CenterPopUpY = (screen.height/2)-(Hpopupsize)-20; 
	 var pos = "left="+CenterPopUpX+",top="+CenterPopUpY; 
	 var desktop = window.open( ""+URL, "_blank", "width="+W+",height="+H+",toolbar=no,location=no,status=no,menubar=no,scrollbars="+S+",resizable=no,"+pos); 
}

function videoMP(pDiv, pCaminho, pLargura, pAltura){
	var video = document.getElementById(pDiv);
	var _caminho = pCaminho;
	var _largura = pLargura;
	var _altura = pAltura;
	//
	objeto="<object type='video/x-ms-wmv' data='"+_caminho+"' width='"+_largura+"' height='"+_altura+"'>";
	objeto+="<param name='src' value='"+_caminho+"' />";
	objeto+="<param name='autostart' value='true' />";
	objeto+="<param name='controller' value='true' />";
	objeto+="</object>";
	video.innerHTML = objeto;
}

function changeType(pLi, pPosition, pFormat){
	var _li = pLi.parentNode;
	var _position = pPosition;
	var _format = pFormat;
	//
	$("#tipos li").removeClass("listaTipoS");
	$("#tipos li").addClass("listaTipo");
	$(_li).addClass("listaTipoS");
	//
	$.ajax({
	   type: "GET",
	   url: "type.formato.php",
	   data: "position="+_position+"&format="+_format,
	   success: function(formato){
	     $("#ficha").html(formato);	   }
	 });
}

function checkCPF(pCPF){
	var _cpf = pCPF.replace(/[.-]/gi,"");
	var numeros, digitos, soma, i, resultado, digitos_iguais;
	digitos_iguais = 1;
	if (_cpf.length < 11){
		return false;
	}	    
	for (i = 0; i < _cpf.length - 1; i++){
		if (_cpf.charAt(i) != _cpf.charAt(i + 1)){
          digitos_iguais = 0;
          break;
	    }
	}
	if (!digitos_iguais){
	    numeros = _cpf.substring(0,9);
	    digitos = _cpf.substring(9);
	    soma = 0;
	    for (i = 10; i > 1; i--){
			soma += numeros.charAt(10 - i) * i;
		}	          
	    resultado = soma % 11 < 2 ? 0 : 11 - soma % 11;
	    if (resultado != digitos.charAt(0)){
			 return false;
		}	         
	    numeros = _cpf.substring(0,10);
	    soma = 0;
	    for (i = 11; i > 1; i--){
			soma += numeros.charAt(11 - i) * i;
		}	         
	    resultado = soma % 11 < 2 ? 0 : 11 - soma % 11;
	    if (resultado != digitos.charAt(1)){
			return false;
		}
	    return true;
	}else{
		return false;	  	
	}
}

function ckRelaCadastro() {
	var f = document.getElementById("f");
	//
	if(f.saveContato_user_firstName.value.length < 2) {
		alert('Entre com seu nome');
		return false;
	}
	if(f.saveContato_user_lastName.value.length < 2) {
		alert('Entre com seu sobrenome');
		return false;
	}
	if(f.previewSaveQuiz_sexo.value == "-1") {
		alert('Selecione o sexo');
		return false;
	}
	if(f.previewSaveQuiz_sexo.value == "-1") {
		alert('Selecione o sexo');
		return false;
	}
	if(f.saveContato_user_cpf.value.length < 2) {
		alert('Entre com um CPF');
		return false;
	}
	if(!checkCPF(f.saveContato_user_cpf.value)) {
		alert('Entre com um CPF válido');
		return false;
	}
	if(f.saveContato_user_empresa.value.length < 2){
		alert('Entre com uma Empresa');
		return false;
	}
	if(f.saveContato_cargo.value == "-1") {
		alert('Selecione um Cargo');
		return false;
	}
	if(f.previewSaveQuiz_user_areaId.value == "-1") {
		alert('Selecione um Área');
		return false;
	}
	if(f.previewSaveQuiz_user_experiencia.value == "-1") {
		alert('Selecione um Experiência');
		return false;
	}
	if( !(/^[\w-\.]+@([\w-]+\.)+[\w-]{2,4}$/i.test(f.saveContato_user_username.value)) ) {
		alert('Entre com um email válido');
		return false;
	}	
	if(f.saveContato_user_password.value.length < 2){
		alert('Entre com uma Senha');
		return false;
	}
	if(f.saveContato_user_password.value != f.saveContato_user_confirmPassword.value){
		alert('Confirme a senha');
		return false;
	}
	if(f.saveContato_user_passwordHint.value.length < 2){
		alert('Entre com a Dica Senha');
		return false;
	}
	f.signup_user_email.value = f.saveContato_user_username.value;
	return true;
}


function ckAgencia() {
	if(document.f.agencia.value.length < 2) {
		alert('Entre com o nome de sua agência');
		return false;
	}
	if(document.f.contato.value.length < 2) {
		alert('Entre com o contato');
		return false;
	}
	if(document.f.ddd.value != document.f.ddd.value.match(/\d{2,3}/g)) {
		alert('Entre com o DDD');
		return false;
	}
	if(document.f.numero.value != document.f.numero.value.match(/\d{7,8}/g)) {
		alert('Entre com o telefone');
		return false;
	}
	if(document.f.email.value != document.f.email.value.match(/(\w\.?-?)+@{1}(\w\.?-?)+(\.\w{2,4}){1,3}/g)) {
		alert('Entre com seu email');
		return false;
	}
	return true;
}

function ckLogin() {
	var txtLogin = document.getElementById("txtLogin");
	var pwdSenha =  document.getElementById("pwdSenha");	
	//
	if(txtLogin.value.length < 2) {
		alert('Entre com seu login');
		return false;
	}
	if(pwdSenha.value.length < 2) {
		alert('Entre com seu senha');
		return false;
	}
}

function abashow(what) {
	var aba = document.getElementById(what);
	//
	aba.style.display='block';
}

function abahide(what) {
	var aba = document.getElementById(what);
	//
	aba.style.display='none';
}
//-------------------------- FLASH DESTAQUE SOME --------------------------//
function someFlash() {
	$("#flashBannerContainer").hide();
}

	setTimeout('someFlash()', 10000);

