
function Interatividade() {

	this.changeFoto = function(obj, id, foto){
		td = tags($(obj).parentNode.parentNode, "td");
		for(i in td){
			td[i].className="";
		}
		$(obj).parentNode.className = "foto-selecionada";
		$("foto"+id).setAttribute("src","/images_complements/"+foto);
	}

	this.avaliar = function(obj) {
		$("avaliacoes").innerHTML = '<img src="../img/loader-snake.gif" /> Aguarde o resultado...';
		parans = "";
		parans = ajax.addParameter(parans,"idnoticia",$("idnoticia").value);
		nota = obj.getAttribute("title");
		parans = ajax.addParameter(parans,"nota",nota);
		ajax.Request({
				url:"avaliate.php",
				div:"avaliacoes",
				parameters:parans,
				pack:"/classes",
				method:"GET",
				cache:false
				});
	}
	
	this.cadastraParticipante = function(id){
		$("enviar"+id).value = "Cadastrando...";
		$("enviar"+id).disabled = true;
		ajax.Request({
				url:$("formulario"+id).getAttribute("action"),
				parameters: ajax.getInputs("formulario"+id),
				div:"result"+id,
				method:"POST",
				cache:false
		});
	}
	
	this.searchNoticia = function(obj){
		$(obj).innerHTML = "Aguarde...";
		input = tags($(obj).parentNode, "input");
		form = input.item(0).parentNode.parentNode;
		if(input[0].value != "" && input[0].value.length > 3){
			form.submit();
		}else{
			alert("Preencha o campo de pesquisa deve ter mais de 3 caracteres!");
			$(obj).innerHTML = "Pesquisar";
		}
	}
	
	this.searchVideo = function(obj){
		$(obj).innerHTML = "Aguarde...";
		input = tags($(obj).parentNode, "input");
		if(input[0].value != "" && input[0].value.length > 3){
			$("searchvideo").submit();
		}else{
			alert("Preencha o campo de pesquisa dever ter mais de 3 caracteres!");
			$(obj).innerHTML = "Buscar";
		}
	}
	
	this.changeStar = function(obj,e) {
		stars = tags(obj.parentNode,"a");		
		for(i in stars) {			
			if (e.type=="mouseover") {			
				stars[i].className = (i<obj.innerHTML) ? "bluestar":"";
			} else {
				stars[i].className = "";				
			}
		}
	}
	
	this.textSize = function (type,obj) {

		texto = $(obj);	

		size = parseInt((texto.style.fontSize!="") ? texto.style.fontSize:"13px");	

		texto.style.fontSize = (type=="+" && size<16) ? (++size)+"px": ((size>11 && type=="-") ? (--size)+"px":size+"px");	

	}
	
	this.sendComment = function(obj) {
	
		object = $(obj);
		
		object.innerHTML = "Enviando...";

		ajax.Request({

			url:"/classes/save.comment.php",

			parameters:ajax.getInputs("formComment")+'&idnoticia='+$('idnoticia').value,

			div:"statusbar",

			method:"post"			

			});				
	}
	
	this.sendComment2 = function(obj) {
	
		obj = $(obj);
		
		obj.innerHTML = "Enviando...";

		ajax.Request({

			url:"/classes/save.comment2.php",

			parameters:ajax.getInputs("formComment2")+'&idnoticia='+$('idnoticia').value,

			div:"result",

			method:"post"			

			});				
	}
	
	this.saveComplements = function (obj){
	
		photos = tags("complemento_photos","input");
		
		var hasPhoto = false;
		
		for(var i = 0; i < photos.length; i++){
		
			if(photos.item(i).getAttribute("type")=="file" && photos.item(i).value!= ""){
			
				hasPhoto = true;
				
				break;
				
			}
			
		}
		
		if(document.all){
		
			photos = tags("complemento_photos","img");
			
			hasPhoto = false;
			
			for(var i = 0; i < photos.length; i++){
			
				if(photos.item(i).getAttribute("src").indexOf("loadbar.gif") == -1){
				
					hasPhoto = true;
					
					break;
					
				}
				
			}
		}

		videos = tags("complemento_videos","input");
		
		var hasVideo = false;
		
		for(var i = 0; i < videos.length; i++){
		
			if(videos.item(i).getAttribute("type")=="text" && videos.item(i).value!= "" && videos.item(i).id.substring(0,3) == "url" ){
			
				hasVideo = true;
				
				break;
				
			}
			
		}
		
		$(obj).value = "Enviando...";
	
		ajax.Request({
		
			url:"save.Complement.php",
			
			pack:"/classes",
			
			parameters: ajax.getInputs("formComplements")+'&idnoticia='+$('idnoticia').value+'&hasPhoto='+hasPhoto+'&hasVideo='+hasVideo,
			
			div:"result_complement",
			
			method: "POST"
		});
	
	}
		
	this.getComments = function () {	
		$("result_comment").innerHTML = '<img src="../img/loader-snake.gif" /> Aguarde ...';
		var id = $("idnoticia").value;		
		var parans = ajax.addParameter(parans,"id",id);		
		ajax.Request({
			url:"getComments.php",
			pack:"/classes",
			div:"result_comment",
			method:"GET",
			parameters: parans,
			cache: true
		});
	}
	
	this.getFormComplements = function(id) {
		
		$("complements").style.display = "block";
		
		$("complements").innerHTML = '<img src="../img/loader-snake.gif" /> Aguarde ...';
		
		parans = "";
		
		parans = ajax.addParameter(parans, "idnoticia",id);
	
		ajax.Request({
			url:"getFormComplements.php",
			pack:"/classes",
			div:"complements",
			method:"post",
			cache:true,
			parameters:parans
		});
	
	}
	
	this.getFormEmail = function(id){
		$("enviaremail").style.display = "block";
		$("enviaremail").innerHTML = '<img src="/img/loader-snake.gif" /> Aguarde ...';
		parans="";
		parans = ajax.addParameter(parans, "idnoticia", id);
		ajax.Request({
			url:"getFormEmail.php",
			pack:"/classes",
			div:"enviaremail",
			method:"GET",
			cache:true,
			parameters: parans
		});
		window.top.location = "#enviaremail";
	}
	
	this.getFormError = function(id) {
	
		$("error").style.display = "block";
		
		$("error").innerHTML = '<img src="/img/loader-snake.gif" /> Aguarde ...';
		
		parans="";
		
		parans = ajax.addParameter(parans, "idnoticia", id);
		
		ajax.Request({
			url:"getFormError.php",
			pack:"/classes",
			div:"error",
			method:"GET",
			cache:true,
			parameters: parans
		});
	
	}
	
	this.getCompText = function (){

		if($("ckb_comp_text").checked){
			
			$("complemento_texto").style.display = "block";
			
			ajax.Request({
				url:"getCompText.php",
				pack:"/classes",
				div:"complemento_texto",
				cache:true
			});
			
		}else{
			$("complemento_texto").innerHTML = "";
			$("complemento_texto").style.display = "none";
		}
	
	}
	
	this.getCompVideos = function (){

		if($("ckb_comp_videos").checked){
			
			$("complemento_videos").style.display = "block";
			
			ajax.Request({
				url:"getCompVideos.php",
				pack:"/classes",
				div:"complemento_videos",
				cache:true
			});
			
		}else{
			$("complemento_videos").innerHTML = "";
			$("complemento_videos").style.display = "none";
		}
	
	}
	
	this.getCompPhotos = function (){

		if($("ckb_comp_photos").checked){
			
			$("complemento_photos").style.display = "block";
			
			ajax.Request({
				url:"getCompPhotos.php",
				pack:"/classes",
				div:"complemento_photos",
				cache:true
			});
			
		}else{
			$("complemento_photos").innerHTML = "";
			$("complemento_photos").style.display = "none";
		}
	
	}
	
	this.uploadPhoto = function(obj) {
		var leng = 'upload_photo'.length;
		var quant = obj.name.length - leng;
		var id_photo = obj.name.substr(leng, quant);
		tags($(obj).parentNode,"img").item(0).className="";	
		$(obj).className="ocult";
		var upload = document.createElement("input");		
		upload.type="file";
		if(document.all){
			upload = obj;
		}else{
			upload = obj.cloneNode(false);
		}
		upload.name="photo";
		upload.id="photo";
		
		id = document.createElement("input");
		id.name = "id";
		id.id = "id";
		id.value = id_photo;
		
		$("uploadphoto").innerHTML = "";
		$("uploadphoto").appendChild(upload);	
		$("uploadphoto").appendChild(id);	
		$("uploadphoto").submit();		
		upload.style.visibility="hidden";
		id.style.visibility="hidden";
		//$("uploading").value = true;
	}

	
	this.addPhoto = function() {
		for(var i =1; i<=12; i++){
			li = $("photo"+i).parentNode;
			if(document.all){
				if(tags(li, "input").length == 0 && tags(li,"img").item(0).src=="../img/loadbar.gif"){
					li.innerHTML = 
						'<label for="upload_photo'+i+'" class="bold">Foto: </label>'+
						'<input onchange="interatividade.uploadPhoto(this);" size="50" style="width:350px;height: 20px;" type="file" name="upload_photo'+i+'" id="upload_photo'+i+'" />'+
						'<img id="photo'+i+'" name="photo'+i+'" class="ocult" src="../img/loadbar.gif" />'+
						'<a class="event" style="margin-left: 2px;" href="javascript:void(0);" onclick="interatividade.removePhoto('+i+');">remover</a><br />'+
						'<label for="desc'+i+'">Descri&ccedil;&atilde;o: </label><input class="desc_photo" type="text" name="desc'+i+'" id="desc'+i+'" />';
				}
			}
			if($("upload_photo"+i).value=="" && $("upload_photo"+i).parentNode.className=="ocult"){
				$("upload_photo"+i).parentNode.className="";
				if(!document.all){
					tags($("upload_photo"+i).parentNode,"a").item(0).style.marginLeft = "-10px";
				}
				$("upload_photo"+i).className="";
				break;
			}
		}
		hasTwelve = 0;
		for(var i =1; i<=12; i++){
			if($("upload_photo"+i).parentNode.className!="ocult"){
				++hasTwelve;
			}
		}
		if(hasTwelve==12){
			$("add").innerHTML = "";
		}
	}

	this.removePhoto = function(opc) {
		var photo = document.getElementById("photo"+opc);
		li = photo.parentNode;
		li.innerHTML = 
					'<label for="upload_photo'+opc+'" class="bold">Foto: </label>'+
					'<input onchange="interatividade.uploadPhoto(this);" size="50" style="width:350px;height: 20px;" type="file" name="upload_photo'+opc+'" id="upload_photo'+opc+'" />'+
					'<img id="photo'+opc+'" name="photo'+opc+'" class="ocult" src="../img/loadbar.gif" />'+
					'<a class="event" style="margin-left: '+((!document.all)?'-11px':'2px')+';" href="javascript:void(0);" onclick="interatividade.removePhoto('+opc+');">remover</a><br />'+
					'<label for="desc'+opc+'">Descri&ccedil;&atilde;o: </label><input class="desc_photo" type="text" name="desc'+opc+'" id="desc'+opc+'" />';
		li.className="ocult";
		$("add").innerHTML = "adicionar uma foto";
		
	}
	
	
	this.addVideo = function(){
		var container = $("list_videos");
		var count = $("count_videos");
		var del = $("del_videos");
		var id = parseInt(count.value)+1;
		li = document.createElement("li");
		li.style.paddingBottom = "10px";
		
		label1 = document.createElement("label");
		label1.setAttribute("for","url_video"+id);
		label1.innerHTML="<b>URL:</b> ";
		li.appendChild(label1);
		
		opc = document.createElement("input");
		opc.setAttribute("type","text");
		opc.setAttribute("id","url_video"+id);
		opc.setAttribute("name", "url_video"+id);
		opc.style.width = "350px";
		li.appendChild(opc);
		
		br = document.createElement("br");
		li.appendChild(br);
		
		label2 = document.createElement("label");
		label2.setAttribute("for","desc_video"+id);
		label2.innerHTML="Descri&ccedil;&atilde;o: ";
		li.appendChild(label2);
		
		opc2 = document.createElement("input");
		opc2.setAttribute("type","text");
		opc2.setAttribute("id","desc_video"+id);
		opc2.setAttribute("name", "desc_video"+id);
		opc2.style.width = "317px";
		li.appendChild(opc2);
		
		a = document.createElement("a");
		a.setAttribute("href","javascript:void(0);");
		a.style.font = "normal 12px arial";
		a.style.marginLeft = "0";
		a.style.textDecoration = "underline";
		a.setAttribute("onclick","interatividade.removeVideo('"+id+"')");
		if(document.all){
			a.onclick = function remove(){				
				objeto = document.getElementById("url_video"+id);
				objeto.parentNode.style.display = "none";
				$("del_videos").value = parseInt($("del_videos").value)+1;
				objeto.parentNode.innerHTML = "";
				var count = $("count_videos");
				var del = $("del_videos");
				if(parseInt(count.value)-parseInt(del.value)<4)
					$("maiorq_videos").style.display = "none";
			}
		}
		a.innerHTML = "remover";
		li.appendChild(a);
		
		container.appendChild(li);
		count.value = id;
		if(parseInt(count.value)-parseInt(del.value)==4){
			$("add_video").innerHTML = "";
		}
	}
	
	this.removeVideo = function(id){
	
		objeto = document.getElementById("url_video"+id);
		objeto.parentNode.style.display = "none";
		$("del_videos").value = parseInt($("del_videos").value)+1;
		objeto.parentNode.innerHTML = "";
		var count = $("count_videos");
		var del = $("del_videos");
		$("add_video").innerHTML = "adicionar um video";
	
	}
	
	this.cancelError = function() {
	
		$('error').innerHTML = "";
		$("error").style.display="none";
	
	}
	
	this.cancelComplements = function() {
	
		$('complements').innerHTML = "";
		$("complementsa").style.display="none";
	
	}
	
	this.cancelComplements = function() {
	
		$("complements").innerHTML = "";
		$("complements").style.display="none";
	
	}
	
	this.ocult = function(id) {
		$(id).innerHTML = "";
		$(id).style.display="none;"
	}
	
	this.enviarEmail = function (){
		$("enviar").innerHTML = "Enviando..."
		ajax.Request({
			url:$("formemail").getAttribute("action"),
			pack:"/classes",
			div:"result_mail",
			method:"GET",
			cache: true,
			parameters: ajax.getInputs("formemail")+"&url="+window.top.location
		});
	}
	
	this.saveError = function (){
	
		ajax.Request({
			url:"save.error.php",
			pack:"/classes",
			div:"result_error",
			method:"POST",
			cache: true,
			parameters: ajax.getInputs("formError")
		});
	
	}
	
	this.getAllEnquetes = function(obj){
	
		system.storeLastModified("principal");
		
		$("principal").innerHTML = '<img class="block" style="margin: 10px auto; text-align: center;" src="../img/loader.gif" />';
	
		obj = $(obj);
		
		obj.innerHTML = "";
		
		slideshow.pause();
		
		ajax.Request({
			url:"getAllEnquetes.php",
			div:"principal",
			pack:"/classes",
			method:"POST",
			cache:true
		});
	
	}
	
	this.goBack = function(){
	
		$("principal").innerHTML = '<img class="block" style="margin: 10px auto; text-align: center;" src="../img/loader.gif" />';
	
		system.restoreLastModified("principal");
		
		slideshow.play();
	
	}
	
	this.getParcial = function(){
		
		id = $("idenquete").value;
				
		var parans = ajax.addParameter(parans, "id", id);
		
		ajax.Request({
		
			url:"getParcial.php",
			
			div: "container_enquete",
			
			pack:"/classes",
			
			method:"GET",
			
			parameters:parans
			
		});
	
	}
	
	this.votar = function(obj){
	
		var opcoes = tags("enquete","input");
		
		check = false;
		
		for(var i=0;i<opcoes.length;i++) {			

			if (opcoes.item(i).getAttribute("type")=="radio") {

				if (opcoes.item(i).checked) {				

					check = true;

					selected = opcoes.item(i).value;

					break;

				}

			}		

		}		

		if (!check) {			

			alert("Selecione uma opção!");

			return false;		

		}
		
		obj = $(obj);
		
		obj.innerHTML = "Enviando...";

		parans = "";
		
		parans = ajax.addParameter(parans, "selected",selected);
	
		ajax.Request({
		
			url:$("enquete").getAttribute("action"),
			
			parameters:parans,
			
			div:"container_enquete",
			
			method:"get"
		
		});

	}
	
	this.changeBorderColor = function(obj, value){
		var objeto = $(obj);
		
		if(value=="true"){
			objeto.style.border = "2px solid #00CCFF";
		}else{
			objeto.style.border = "";
		}
	}


}

interatividade = new Interatividade();