// ULR Site
if (document.location.hostname == "localhost") {
	var pathsite = "http://localhost/ttn/";
} else {
	var pathsite = "http://www.titinet.com.br/";	
}

function hideImage(){
		$("#box-popin-sombra").hide();
		$("#box-popin-oculta").hide();
}

function hideObject(obje){
	$("#"+obje).css("display","block");
}

function showLoading(obj){
	
	var iwidth = $("#"+obj).width();
	var iheight = $("#"+obj).height();
	
	$("#"+obj).css({"width":""+iwidth+"px", "height":""+iheight+"px"});	
	$("#"+obj).html("<p><img src=\""+pathsite+"img/ajax-loader.gif\" alt=\"Loading...\" /></p>");
	$("#"+obj + " p").css({"margin-left":""+parseInt((iwidth/2)-16)+"px","margin-top":""+parseInt((iheight/2)-16)+"px"});
	$("#"+obj).show();
	
}

function displayImage(credito,legend,image){
	
	var iwidth = $(document).width();
	var iheight = $(document).height();
	
	$("#box-popin-oculta").css({"width":""+iwidth+"px", "height":""+iheight+"px"});
	$("#box-popin-oculta").html("<p><img src=\""+pathsite+"img/ajax-loader.gif\" alt=\"Loading...\" /></p>");
	$("#box-popin-oculta p").css({"margin-left":""+parseInt(iwidth/2)+"px","margin-top":""+parseInt((iheight/2)-300)+"px"});

	$("#box-popin-credito").html(credito);
	$("#box-popin-image").html("<img src=\""+image+"\" id=\"popin-image\" alt=\""+legend+"\" /><span id=\"box-popin-legend\">"+legend+"</span>");
	
	$("#box-popin-oculta p").remove();
	
	$("#box-popin-sombra").css({"left":""+parseInt((iwidth/2)-300)+"px","top":""+parseInt((iheight/2)-500)+"px","display":"block"});
	$("#box-popin-oculta").show();
	
}

/*Aumentar/Diminuir Fonte*/
//Specify affected tags. Add or remove from list:
var tgs = new Array( 'div' );

//Specify spectrum of different font sizes:
var szs = new Array( 'xx-small','x-small','small','medium','large','x-large','xx-large' );
var startSz = 2;

function ts( trgt,inc ) {
	if (!document.getElementById) return
	
	var d = document,cEl = null,sz = startSz,i,j,cTags;
	
	sz += inc;
	if ( sz < 0 ) sz = 0;
	if ( sz > 6 ) sz = 6;
		
	startSz = sz;
		
	if ( !( cEl = d.getElementById( trgt ) ) ) cEl = d.getElementsByTagName( trgt )[ 0 ];
		
	cEl.style.fontSize = szs[ sz ];
		
	for ( i = 0; i < tgs.length; i++ ) {
		cTags = cEl.getElementsByTagName( tgs[ i ] );
		for ( j = 0; j < cTags.length; j++ ) cTags[ j ].style.fontSize = szs[ sz ];
	}
}

/* Avaliar Notícia */
function newsAssess(notcod,note){
	
	$("#avalie").html("avaliando...");
	
	$.get(pathsite+"newsAssess.asp", { notcod: notcod, note: note },
		function(resultado){
			$("#avalie").html(resultado);
	});

}

function abaMoreNews(aba,op){
	
	showLoading('morenews');
	
	$("#opmais a").removeClass();
	$("#"+aba).addClass("selected");
	
	$.post("moreNews.asp",{op:op},
		function(resultado){
			$("#morenews").html(resultado);
		});
}

function votarEnquete(enq,action){
	
	var iPoll = enq;
	var iVoto = $(":checked").val();
	var boolValid = false;
	
	if (action == 1) {
		
		$('#frm_enquete input:radio').each(function() {
			if ( $(this).is(':checked') ) {
				boolValid = true;
			}
		});
		
		if (boolValid == true) {
			
			$.post("confirmPoll.asp",{poll:iPoll,voto:iVoto,action:action},
																	 
				function(resultado){
					
					$("#showenquete").html(resultado);
					
				});
			
			$("#enqueteerror").css({"visibility":"hidden"});
			
		} else {
			
			$("#enqueteerror").html("<b>Selecione uma das opções!</b>");
			$("#enqueteerror").css({"visibility":"visible"});
			
		}
		
	} else {
		
		$.post("confirmPoll.asp",{poll:iPoll,action:action},
																	 
				function(resultado){
					
					$("#showenquete").html(resultado);
					
				});
	};
	
}

/* Homepage | Favoritos */
function defineHome(objh){
	if (navigator.appName.indexOf("Microsoft") != -1){
		objh.style.behavior='url(#default#homepage)';
		objh.setHomePage('http://www.titinet.com.br/') 
	}
	else {
		 alert("Será aberta uma nova janela explicando como Adicionar nosso site aos seus Favoritos!");
		 window.open("http://br.mozdev.org/firefox/pagina-inicial");
	}
}

function addFavorito(){
    var url      = pathsite;
    var title    = "Titinet - O mundo das celebridades!";
    if (window.sidebar) window.sidebar.addPanel(title, url,"");
    else if(window.opera && window.print){
        var mbm = document.createElement('a');
        mbm.setAttribute('rel','sidebar');
        mbm.setAttribute('href',url);
        mbm.setAttribute('title',title);
        mbm.click();
    }
    else if(document.all){window.external.AddFavorite(url, title);}
}

/* Recarregar Select com lista de Cidades*/
function getState(){
	
	var estado = $("#estado").val();
	
	$("#cidade").html("<option value=\"0\">recarregando...</option>");
	
	$.post(pathsite+"getState.asp", { estado: estado},
		function(resultado){
			$("#cidade").html(resultado);
			$("#cidade").attr({disabled:""});
	});

}

/* Enviar Comentário */
function getComent(){
	
	var verificaEmail = /^[\w-]+(\.[\w-]+)*@(([A-Za-z\d][A-Za-z\d-]{0,61}[A-Za-z\d]\.)+[A-Za-z]{2,6}|\[\d{1,3}(\.\d{1,3}){3}\])$/;
	var nome = $("#nome").val();
	var email = $("#cemail").val();
	var estado = $("#estado").val();
	var cidade = $("#cidade").val();
	var comentario = $("#comentario").val();
	var codpost = $("#codpost").val();
	var tipcoment = $("#tipcoment").val();
	var erromessage = "Preencha os campos abaixo corretamente:\n"
	var status = true;
	
	if(!nome) {
	
		erromessage += "- Nome;\n";
		status = false;
	
	}
	
	if(!email) {
	
		erromessage += "- E-mail;\n";
		status = false;
	
	} else {
		
		if(!verificaEmail.test(email)) {
		
			erromessage += "- E-mail inválido;\n";
			status = false;
		
		}
		
	}
	
	if(estado == 0) {
	
		erromessage += "- Estado;\n";
		status = false;
	
	}

	if(cidade == 0) {
	
		erromessage += "- Cidade;\n";
		status = false;
	
	}

	if(!comentario) {
	
		erromessage += "- Comentário;\n";
		status = false;
	
	}
	
	if (status == false){
		
		alert(erromessage);
		return false;
		
	} else {

		$("#btnenviar").attr("disabled","disabled");
		$("#btnenviar").attr("value","Enviando...");
		$("frmcomentario").submit();
		
	}
	
}

// Exibir Pop-up
function WindOpen(janurl,codreg,iwidth,iheight){
	
	window.open(pathsite+janurl+'?c=' + codreg, 'janOpen', 'toolbar=no,location=no,scrollbars=yes,width='+iwidth+',height='+iheight+',resizable=no,left=60,top=90');
	
}

// Enviar News por E-mail
function NewsEmail(formData,jqForm,options) {

	var verificaEmail = /^[\w-]+(\.[\w-]+)*@(([A-Za-z\d][A-Za-z\d-]{0,61}[A-Za-z\d]\.)+[A-Za-z]{2,6}|\[\d{1,3}(\.\d{1,3}){3}\])$/;
	var nemail = $('input[@name=nemail]').fieldValue();
	var ncod = $('input[@name=ncod]').fieldValue();
	var status = "";
	
	if(!nemail[0]) {
	
		status += 'Informe um e-mail!';
	
	} else {
		
		if(!verificaEmail.test(nemail)) {
		
			status+='E-mail inválido';
		
		}
		
	}
	
	if(status!="") {
		
		alert(status);
		$("#nemail").focus();
		return false;
		
	} else {
			  
		$("#frm_enviar").submit(function() {
			var options = {
				//target: "#resposta", // destino: onde ser exibida a resposta da pgina requisitada, no caso a div #resposta
				url: pathsite+"newsEmail.asp", // aqui a pgina que ser requisitada
				type: "post", // metodo de envio, post ou get
				
				success: function(resposta) {
					
					alert(resposta);
					$("#nemail").val("");
					
				}
				
			}
			
			$(this).ajaxSubmit(options);
			
			return false;
			
		});
		
		
		
	}

}

/* -------------------------
Formulário de Contato
----------------------------*/
function ValidateFormContato() {

	var verificaEmail = /^[\w-]+(\.[\w-]+)*@(([A-Za-z\d][A-Za-z\d-]{0,61}[A-Za-z\d]\.)+[A-Za-z]{2,6}|\[\d{1,3}(\.\d{1,3}){3}\])$/;
	var nome = $('input[@name=nome]').fieldValue();
	var email = $('input[@name=email]').fieldValue();
	var estado = $('select[@name=estado]').fieldValue();
	var cidade = $('select[@name=cidade]').fieldValue();
	var assunto = $('input[@name=assunto]').fieldValue();
	var mensagem = $('textarea[@name=mensagem]').fieldValue();
	var status = "";
	
	if(!nome[0]) {
	
		status += '<li>O nome está vazio</li>';
	
	}
	
	if(!email[0]) {
	
		status += '<li>E-mail vazio</li>';
	
	} else {
		
		if(!verificaEmail.test(email)) {
		
			status+='<li>E-mail inv&aacute;lido</li>';
		
		}
		
	}
	
	if(!estado[0]) {
	
		status += '<li>Selecione seu estado</li>';
	}
	
	if(!assunto[0]) {
	
		status += '<li>O campo assunto est&aacute; vazio</li>';
	}
	
	if(!mensagem[0]) {
	
		status += '<li>O campo mensagem est&aacute; vazio</li>';
	}
	
	if(status!="") {
		
		$("#boxtips").html("<h1>Erro</h1><ul>"+status+"</ul>");
		$("#boxtips").show()
		return false;
		
	} else {
		
		$("#boxtips").hide();
		$("#btnenviar").attr("disabled","disabled");
		$("#btnenviar").attr("value","Enviando...");
		$("#formcontato").attr("action",pathsite+"sendEmail.asp"); 
		$("#formcontato").submit();
		$("#btnenviar").removeAttr("disabled");
		
	}

}

function GetCity(){
	$("#cidade").html("<option value=\"0\">carregando...</option>");

	$.get("getState.asp",
		  
		  {estado:$("#estado").val()},
		  
		  function(resultado){
			  
			  $("#cidade").removeAttr("disabled");
			  $("#cidade").html(resultado);
			  
			}	
	);

}

function tipsBox(dvobj,itipo){
	
		switch(itipo){				
			case 1: // Exibe
				$("#"+dvobj).css("display","block");
				break;
				
			case 2:// Oculta
				$("#"+dvobj).css("display","none");
				break;
		}
}

function expandedImage(urlimg,credimg,legimg){
	
	jQuery("#gallerycredit").html(credimg);
	jQuery("#gallerylegenda").html(legimg);
	jQuery("#expandedimage").attr({ 
			  src: urlimg,
			  title: legimg,
			  alt: credimg	
			});

}