
//AJAX
// Variavel pasta é o caminho junto do arquivo e sua extensão, a variavel método, é o tipo de envio que você vai fornecer ao Ajax se vai ser por 'GET' ou 'POST'
// Variavel target é para que objeto com a respectiva ID deve ser escrito o código.

function loadASSUNTO(pasta,metodo,target){
	document.getElementById(target).innerHTML= 'Carregando...';
		if (window.XMLHttpRequest)
		  {// codigo para IE7+, Firefox, Chrome, Opera, Safari
		  xmlhttp=new XMLHttpRequest();
		  }
		else
		  {// codigo para o IE6, IE5
		  xmlhttp=new ActiveXObject("Microsoft.XMLHTTP");
		  }
		  xmlhttp.onreadystatechange=function()
		  {
		  if (xmlhttp.readyState==4 && xmlhttp.status==200)
			{
			document.getElementById(target).innerHTML= xmlhttp.responseText;
			}
		  }
		xmlhttp.open(metodo,pasta,true);
		xmlhttp.send();
}


function loadASSUNTO2(pasta,metodo){
		if (window.XMLHttpRequest)
		  {// codigo para IE7+, Firefox, Chrome, Opera, Safari
		  xmlhttp=new XMLHttpRequest();
		  }
		else
		  {// codigo para o IE6, IE5
		  xmlhttp=new ActiveXObject("Microsoft.XMLHTTP");
		  }
		  xmlhttp.onreadystatechange=function()
		  {
		  if (xmlhttp.readyState==4 && xmlhttp.status==200)
			{
			document.getElementById("conter").innerHTML= xmlhttp.responseText;
			}
		  }
		xmlhttp.open(metodo,pasta,true);
	   xmlhttp.send();
}


function loadASSUNTOPARENT(pasta,metodo,target){
	window.parent.document.getElementById(target).innerHTML= 'Carregando...';
		if (window.XMLHttpRequest)
		  {// codigo para IE7+, Firefox, Chrome, Opera, Safari
		  xmlhttp=new XMLHttpRequest();
		  }
		else
		  {// codigo para o IE6, IE5
		  xmlhttp=new ActiveXObject("Microsoft.XMLHTTP");
		  }
		  xmlhttp.onreadystatechange=function()
		  {
		  if (xmlhttp.readyState==4 && xmlhttp.status==200)
			{
			window.parent.document.getElementById(target).innerHTML= xmlhttp.responseText;
			}
		  }
		xmlhttp.open(metodo,pasta,true);
		xmlhttp.send();
}


function loadUPDATE(pasta,metodo){
		if (window.XMLHttpRequest)
		  {// codigo para IE7+, Firefox, Chrome, Opera, Safari
		  xmlhttp=new XMLHttpRequest();
		  }
		else
		  {// codigo para o IE6, IE5
		  xmlhttp=new ActiveXObject("Microsoft.XMLHTTP");
		  }
		  xmlhttp.onreadystatechange=function()
		  {
		  if (xmlhttp.readyState==4 && xmlhttp.status==200)
			{
			window.parent.document.getElementById("conter").innerHTML= xmlhttp.responseText;
			}
		  }
		xmlhttp.open(metodo,pasta,true);
	   xmlhttp.send();
}

//Menu abas(requer o jquery para funcionar)

function abas(id){
	
	$("#"+id).slideToggle("slow")
	
}

//Lightbox (requer o jquery para funcionar)
// O tipo é "imagem" ou "arquivo", isso vai diferenciar se vai executar uma imagem dentro do lightbox ou uma conteudo AJAX dentro dele.

// Se for imagem se coloca o caminho mais a extensão da imagem, se for arquivo se coloca o caminho do arquivo mais a extensão do mesmo.
// Ex: onClick = "abrir_lightbox('arquivo','pasta/arquivo.asp') ou onClick = "abrir_lightbox('imagem','pasta/image.jpg')"


function abrir_lightbox(tipo,local){
	
		if(tipo == "imagem"){
			$("#conter").html("<img src='"+local+" border='0' />");
		}
		
		else if(tipo == "arquivo"){
			loadASSUNTO2(local,'GET')	
		}
	
		$("#lightbox_base").fadeIn("slow",function(){$("#box_white").fadeIn("slow")});
		
}

function abrir_lightbox_parent(tipo,local){
	
		if(tipo == "imagem"){
			$("#conter",window.parent.document).html("<img src='"+local+" border='0' />");
		}
		
		else if(tipo == "arquivo"){
			loadASSUNTOPARENT(local,'GET','conter')	
		}
	
		$("#lightbox_base",window.parent.document).fadeIn("slow",function(){$("#box_white",window.parent.document).fadeIn("slow")});
		
}

//lightbox padrão do upload de imagens
function lightbox_upload(diretorio,rotina,id){
		
			
		$("#lightupload_base").fadeIn("slow",function(){$("#upload_box").fadeIn("slow")});
		
		loadASSUNTO('upload/upload_form.asp?Subdir='+diretorio+'&rotina='+rotina+'&ID='+id+'','GET','upsessao')
		
		
}


function fechar_lightbox(){
	
		$("#lightbox_base").fadeOut("slow",function(){$("#box_white").fadeOut("slow", function(){$("#conter").html("<p align='center' class='txt_bold_preto02'>carregando...</p>")})});
	
}

//fecha lightbox padrão do upload de imagens
function fechar_uploader(){
	
		$("#lightupload_base").fadeOut("slow",function(){$("#upload_box").fadeOut("slow")});
	
}

function fechar_uploader2(){
	
		$("#lightupload_base", window.parent.document).fadeOut("fast",function(){$("#upload_box").fadeOut("fast")});
	
}


//fecha lightbox padrão quando se está executando dentro de um iframe (geralmente feito para os rotinas do adm)
function fechar_lightbox2(){
	
	$("#lightbox_base", window.parent.document).fadeOut("slow",function(){$("#box_white", window.parent.document).fadeOut("slow",function(){$("#conter", window.parent.document).html("<p align='center' class='txt_bold_preto02'>carregando...</p>")})});
		
}

//////

//Soma

function Soma(){
	var x = document.getElementById("real2").value;
	var y = document.getElementById("real").value;
	var valorx = parseFloat(x) + parseFloat(y);
	var valor = valorx.toFixed(2)
	document.getElementById("valor_final").innerHTML='R$ '+valor;
	document.getElementById("real2").value=valor;
}

function Minus(){
	var x = document.getElementById("real2").value;
	var y = document.getElementById("real").value;
	var valorx = parseFloat(x) - parseFloat(y);
	var valor = valorx.toFixed(2)
	document.getElementById("valor_final").innerHTML='R$ '+valor;
	document.getElementById("real2").value=valor;
}


function ApagarForm(forms){
var numero;
for (numero=forms; numero>0; numero--){
	document.getElementById('nome_'+numero).value='';
}

}



//Canvas - Slice //

var img = new Image();
var i=0;

function draw() {
		
	for(var i = 0; i < 3; i++) {
	
	var pic = $("#source"+i)

	pic.removeAttr("width"); 
	pic.removeAttr("height");
	
	var pic_real_width = pic.width();
	var pic_real_height = pic.height();
	
	  var ctx = document.getElementById("canvas"+i).getContext('2d');
	    ctx.drawImage(document.getElementById("source"+i),5,5,(pic_real_width+150)/2,(pic_real_height+150)/2)
	  }
}

function draw2(vl) {
		
	for(var i = 0; i < vl; i++) {
	
	var pic = $("#source"+i)

	pic.removeAttr("width"); 
	pic.removeAttr("height");
	
	var pic_real_width = pic.width();
	var pic_real_height = pic.height();
	
	  var ctx = document.getElementById("canvas"+i).getContext('2d');
	    ctx.drawImage(document.getElementById("source"+i),-50,-80,(pic_real_width+200)/2,(pic_real_height+200)/2)
	  }
}

//Rolagem

var timer_id;
function scroll_iframe(frm,inc,dir) {
  if (timer_id) clearTimeout(timer_id);
  if (window.frames[frm]) {
    if (dir == "v") window.frames[frm].scrollBy(0, inc);
	else window.frames[frm].scrollBy(inc, 0);
	timer_id = setTimeout("scroll_iframe('" + frm + "'," + inc + ",'" + dir + "')", 20);
  }
  
}

function stopScroll() { if (timer_id) clearTimeout(timer_id); }


// Revelar rolagem //

function chave(id){
			if (id==0) {
					window.parent.document.getElementById("valor").style.display="none";	
			}
			
			else if(id==1) {
					window.parent.document.getElementById("valor").style.display="";
			}
		}




//Consulta de formulário da Busca


function Consultar(caminho){
	var CAMPO = document.form1.CAMPO.value;
	var PALAV = document.form1.PALAVRA.value;
	var TAM = PALAV.length;	
	var geral = "CAMPO="+CAMPO+"&PALAVRA="+PALAV+""

	var ERRO = "";
		if(CAMPO == ""){
		window.alert("Selecione o campo a pesquisar.");
		ERRO = "1";
		}
			if(TAM < 1 && CAMPO != "ESTADO"){
			window.alert("A palavra chave a pesquisar deve ter no mínimo 1 caractere.");
			ERRO = "1";
			}
			if(ERRO == ""){
				
				loadASSUNTO(''+caminho+'?'+geral+'&CONSULTAR=OK','GET','conteudo');
				//document.form1.submit();
		}
}

//Consulta de formulário da Busca com adicionais
function ConsultarAD(caminho,variaveis){
		var CAMPO = document.form1.CAMPO.value;
		var PALAV = document.form1.PALAVRA.value;
		
		
		var TAM = PALAV.length;	
		var adcional = "CAMPO="+CAMPO+"&PALAVRA="+PALAV+"&"+variaveis+""
		
	var ERRO = "";
		if(CAMPO == ""){
		window.alert("Selecione o campo a pesquisar.");
		ERRO = "1";
		}
			if(TAM < 1 && CAMPO != "ESTADO"){
			window.alert("A palavra chave a pesquisar deve ter no mínimo 1 caractere.");
			ERRO = "1";
			}
			if(ERRO == ""){
				
				loadASSUNTO(caminho+'?'+adcional+'&CONSULTAR=OK','GET','conteudo');
				//document.form1.submit();
		}
}

//

//Método de Exclus~sao do cadastros

function Excluir(arquivo,ID,VARIAVEL){
	
	
	if(confirm("Você tem certeza que deseja excluir este registro ?")){
	var IDACAO = window.document.getElementById(ID).value;
		
		$("#consulta").attr("src",""+arquivo+"?ACAO=DELETE&"+VARIAVEL+"="+IDACAO+"")
		
		//consulta.location.href = ""+arquivo+"?ACAO=DELETE&IDCATEGFOTO="+IDCATEGFOTO+"";
		
	}
}

//Carregamento de Categoria Um dia especial

function CarregaCateg(evento,categoria){
	if (evento != ""){
		$("#consulta").attr("src","usuarios/rotinas_usuarios.asp?ACAO=CATEGLIST&evento="+evento+"&categoria="+categoria+"");
	}else{
		window.alert("Selecione um evento para prosseguir");
	}
}

// Grava Legenda da Galeria

function GRAVAR_LEGENDA(pagina,variaveis){
	
window.document.getElementById('consulta').src=''+pagina+'&'+variaveis+''
}


// EXCLUIR REGISTRO DO MENU SERVIÇOS

	function DELETA_SERV(pagina,variavel,nomcampo){
		
		var check = $("#"+nomcampo+":checked").val();
		
	$("#"+nomcampo+":checked").each	(
		function() {
			check = this.value+"|"+check;
		}
	  );
		
		
		if(confirm("Você tem certeza que deseja excluir os registros selecionados ?")){	
			//alert(''+pagina+'&'+variavel+'='+check+'')
			loadASSUNTO(''+pagina+'&'+variavel+'='+check+'','POST','conteudo')
		}
			
	}




function redimensionar_caixa(){
		var tamanho = $("#interna_center").height();
		$("#interna_left").height(tamanho);
		$("#interna_right").height(tamanho);
}
