/* [inicia Ajax] */
function fncAjax(){
	try{
		xmlhttp = new XMLHttpRequest();
	}catch(ee){
		try{
			xmlhttp = new ActiveXObject("Msxml2.XMLHTTP");
		}catch(e){
			try{
				xmlhttp = new ActiveXObject("Microsoft.XMLHTTP");
			}catch(E){
				xmlhttp = false;
			}
		}
	}
	return;
}
/* [campos obrigatórios] */
var varEnv = false;
function fncObrigatorios(objObrig, Alerta){
	if(varEnv) return false;
	for(var f=0; f<objObrig.length; f++){
		var campo = objObrig[f].split(":");
		if(document.getElementById(campo[0])){
			fncRetSpc(document.getElementById(campo[0]));
			if(!document.getElementById(campo[0]).value){
				if(Alerta) window.alert("Os campos marcados com asterisco são de preenchimento obrigatório.");
				document.getElementById(campo[0]).focus();
				return false;
			}
			if(campo[1] && !fncValidaMail(document.getElementById(campo[0]))){
				if(Alerta) window.alert("O e-mail está incorreto.");
				document.getElementById(campo[0]).select();
				return false;
			}
		}
	}
	varEnv = true;
	return true;
}
/* [campos apenas com números - uso: onKeyPress="return fncNumeros(event);"] */
function fncNumeros(e){
	var whichCode = (window.Event)? e.which : e.keyCode;
	if(whichCode>=48 && whichCode<=57 || whichCode==8 || whichCode==9 || whichCode==32 || whichCode==45) return true;
	return true; // TODO trocar para false quando descobrir problema no IE //
}
/* [retira espaços do inicio] */
function fncRetSpc(obj){
	var ret = obj.value;
	if(ret.indexOf(" ")==0){
		do{
			ret = ret.substr(1);
		}while(ret.indexOf(" ")==0)
		obj.value = ret;
	}
	return;
}
/* [valida e-mail] */
function fncValidaMail(obj){
	var re_mail = /^([a-zA-Z0-9_\.\-])+\@(([a-zA-Z0-9\-])+\.)+([a-zA-Z])+$/; 
	if (!re_mail.test(obj.value)) return false;
	return true;
}
/* [funções do menu lateral] */
function fncURL(id) {
	top.location.href = "index.php?pgID="+id;
	return;
}
/* [galeria de imagens e vídeos] */
function fncVidGal(tipo) {
	fncAjax();
	xmlhttp.open("GET", tipo+"-verifica.php", true);
	xmlhttp.onreadystatechange = function(){
		if(xmlhttp.readyState == 4){
			var data = xmlhttp.responseText.split("|");
			top.location.href = data[0]==1 ? "index.php?canal="+tipo+"&pgID="+data[1] : "index.php?pgID="+tipo;
		}
	}
	xmlhttp.send(null);
	return;
}
/* [manual do expositor] */
function fncManual() {
	fncAjax();
	xmlhttp.open("GET", "manual-verifica.php", true);
	xmlhttp.onreadystatechange = function(){
		if(xmlhttp.readyState == 4){
			var data = xmlhttp.responseText;
			top.location.href = data ? (data.substr(0,7) == "http://" ? data : "http://"+data) : "index.php?pgID=expositores-manual"
		}
	}
	xmlhttp.send(null);
	return;
}