function goTo(menu){
	window.location.href = menu.options[menu.selectedIndex].value;
}

var CLIP_WIDTH = Math.floor(screen.width > 0 ? screen.width*0.55 : 1024*0.55);
var CLIP_HEIGHT = Math.floor(CLIP_WIDTH/2.2);
function setViewport(img, x, y, width, height){
	img.style.left = -x;
	img.style.top  = -y;
	if (width !== undefined){
		img.parentNode.style.width = width;
		img.parentNode.style.height = height;
	}
}
function setClip(img){
	if(img.width == 0){
		function tryAgain(){
			setClip(img);
		}
		setTimeout(tryAgain, 500);
	}else{
		var r = img.width/img.height;
		if(img.width/img.height < CLIP_WIDTH/CLIP_HEIGHT){
			img.width = CLIP_WIDTH;
			img.height = Math.floor(CLIP_WIDTH/r);
		}else{
			img.width = Math.floor(CLIP_HEIGHT*r);
			img.height = CLIP_HEIGHT;
		}
		setViewport(img, (img.width>>1)-(CLIP_WIDTH>>1), (img.height>>1)-(CLIP_HEIGHT>>1), CLIP_WIDTH, CLIP_HEIGHT); 
		
		if(img.parentNode.style.visibility != 'visible'){
			img.parentNode.style.visibility = 'visible';
			lastTimeOut = setTimeout(automaticClaseSiguiente, 5000);
		}
	}
}

var claseActiva = 0;
var clippedImg = [false, false, false];
function zoomIn(){
	var divClipped = document.getElementById("divClipped");
	divClipped.style.overflow = "";
	//divClipped.style.border = "";
	//var imgClipped = document.getElementById("imgClipped" + claseActiva);
	//imgClipped.style.border = "4px ridge yellow";
	var conClipped = document.getElementById("conClipped");
	conClipped.style.display = "none";
	var txtClipped = document.getElementById("txtClipped");
	txtClipped.style.display = "none";
	var arrClipped = document.getElementById("arrClipped");
	arrClipped.style.display = "none";
}
function zoomOut(){
	var divClipped = document.getElementById("divClipped");
	divClipped.style.overflow = "hidden";
	//divClipped.style.border = "4px ridge yellow";
	//var imgClipped = document.getElementById("imgClipped" + claseActiva);
	//imgClipped.style.border = "";
	var conClipped = document.getElementById("conClipped");
	conClipped.style.display = "";
	var txtClipped = document.getElementById("txtClipped");
	txtClipped.style.display = "";
	var arrClipped = document.getElementById("arrClipped");
	arrClipped.style.display = "";
}
var stopScroll = false;
var lastTimeOut;
function pauseScroll(){
	stopScroll = true;
	var img = document.getElementById("pauseButton");
	img.setAttribute("class", "sprite_play");
	img.parentNode.href = "javascript:playScroll(this);";
}
function playScroll(){
	stopScroll = false;
	var img = document.getElementById("pauseButton");
	img.setAttribute("class", "sprite_pause");
	img.parentNode.href = "javascript:pauseScroll(this);";
	
	clearTimeout(lastTimeOut);
	lastTimeOut = setTimeout(automaticClaseSiguiente, 5000);
}
function automaticClaseSiguiente(){
	if(!stopScroll){
		claseSiguiente();
		lastTimeOut = setTimeout(automaticClaseSiguiente, 5000);
	}
}
function claseSiguiente(){
	var imgClipped = document.getElementById("imgClipped" + claseActiva);
	imgClipped.style.display = "none";
	var txtClipped = document.getElementById("txtClipped" + claseActiva);
	txtClipped.style.display = "none";
	
	claseActiva++;
	if(claseActiva > 2){
		claseActiva = 0;
	}
	
	var imgClipped = document.getElementById("imgClipped" + claseActiva);
	imgClipped.style.display = "";
	var txtClipped = document.getElementById("txtClipped" + claseActiva);
	txtClipped.style.display = "";

	if(!clippedImg[claseActiva]){
		setClip(document.getElementById("imgClipped" + claseActiva));
		clippedImg[claseActiva] = true;
	}

}
function claseAnterior(){
	var imgClipped = document.getElementById("imgClipped" + claseActiva);
	imgClipped.style.display = "none";
	var txtClipped = document.getElementById("txtClipped" + claseActiva);
	txtClipped.style.display = "none";
	
	claseActiva--;
	if(claseActiva < 0){
		claseActiva = 2;
	}

	var imgClipped = document.getElementById("imgClipped" + claseActiva);
	imgClipped.style.display = "";
	var txtClipped = document.getElementById("txtClipped" + claseActiva);
	txtClipped.style.display = "";

	if(!clippedImg[claseActiva]){
		setClip(document.getElementById("imgClipped" + claseActiva));
		clippedImg[claseActiva] = true;
	}

}

function borrarRifas(){
	if (confirm('¿Estas seguro que queres borrar datos de la rifa?'))
	{
		frm = document.createElement("form");
		frm.action = "rifas.php";
		frm.method = "POST";

		frmAction = document.createElement("input");
		frmAction.setAttribute("type", "hidden");
		frmAction.setAttribute("name", "action");
		frmAction.setAttribute("value", "delete");
		frm.appendChild(frmAction);

		frm.submit();
	}
}

function borrarGaleria(time){
	frm = document.createElement("form");
	frm.action = "multimedia.php?qdelete=true";
	frm.method = "POST";

	frmAction = document.createElement("input");
	frmAction.setAttribute("type", "hidden");
	frmAction.setAttribute("name", "action");
	frmAction.setAttribute("value", "deleteGaleria");
	frm.appendChild(frmAction);

	frmTime = document.createElement("input");
	frmTime.setAttribute("type", "hidden");
	frmTime.setAttribute("name", "time");
	frmTime.setAttribute("value", time);
	frm.appendChild(frmTime);

	frm.submit();
}

function borrarNoticia(time){
	frm = document.createElement("form");
	frm.action = "noticias.php?qdelete=true";
	frm.method = "POST";

	frmAction = document.createElement("input");
	frmAction.setAttribute("type", "hidden");
	frmAction.setAttribute("name", "action");
	frmAction.setAttribute("value", "delete");
	frm.appendChild(frmAction);

	frmTime = document.createElement("input");
	frmTime.setAttribute("type", "hidden");
	frmTime.setAttribute("name", "time");
	frmTime.setAttribute("value", time);
	frm.appendChild(frmTime);

	frm.submit();
}

function borrarFoto(time){
	frm = document.createElement("form");
	frm.action = "";
	frm.method = "POST";

	frmAction = document.createElement("input");
	frmAction.setAttribute("type", "hidden");
	frmAction.setAttribute("name", "action");
	frmAction.setAttribute("value", "delete");
	frm.appendChild(frmAction);

	frmTime = document.createElement("input");
	frmTime.setAttribute("type", "hidden");
	frmTime.setAttribute("name", "time");
	frmTime.setAttribute("value", time);
	frm.appendChild(frmTime);

	frm.submit();
}

function borrarMensaje(time){
	frm = document.createElement("form");
	frm.action = "mensajes.php?qdelete=true";
	frm.method = "POST";

	frmAction = document.createElement("input");
	frmAction.setAttribute("type", "hidden");
	frmAction.setAttribute("name", "action");
	frmAction.setAttribute("value", "delete");
	frm.appendChild(frmAction);

	frmTime = document.createElement("input");
	frmTime.setAttribute("type", "hidden");
	frmTime.setAttribute("name", "time");
	frmTime.setAttribute("value", time);
	frm.appendChild(frmTime);

	frm.submit();
}

function show360(v360){
	var vista360 = document.getElementById('vista360');
	vista360.innerHTML = "<object id=swfobject classid=clsid:d27cdb6e-ae6d-11cf-96b8-444553540000 codebase=http://fpdownload.macromedia.com/pub/shockwave/cabs/flash/swflash.cab#version=4,0,0,0 width=100% height=300 align=middle><param name=allowScriptAccess value=sameDomain /><param name=movie value=vista/"+v360+".swf /><param name=quality value=medium /><param name=bgcolor value=#ffff00 /><embed id=swfembed src=vista/"+v360+".swf quality=medium bgcolor=#ffff00 width=100% height=300 name=cancha align=middle allowScriptAccess=sameDomain type=application/x-shockwave-flash pluginspage=http://www.macromedia.com/go/getflashplayer /></object>";
	
	var vermasgrande = document.getElementById('vermasgrande');
	vermasgrande.innerHTML = "<a href='javascript:extend();'>Ver mas grande</a>";
}
function extend(){
	var swfobject = document.getElementById('swfobject');
	var swfembed = document.getElementById('swfembed');
	
	swfobject.height = 500;
	swfembed.height = 500;
	
	var vermasgrande = document.getElementById('vermasgrande');
	vermasgrande.innerHTML = "<a href="+swfembed.src+">Ver en pantalla completa</a>";
}

function cargar(){
	var formulario = document.getElementById('formulario');
	formulario.style.display = "none";
	var formulario = document.getElementById('divcargando');
	divcargando.style.display = "";
}


function onEdit(inputName) {
	var imgLink = document.getElementById(inputName).value;
	if(imgLink != ""){
		showFoto(imgLink, inputName);
	}
}

function uploadFoto(inputName) {
	try{
		var imageFile = document.getElementById('fotoUpload_' + inputName).files[0];
		
		fd = new FormData();
		fd.append("foto", imageFile);
		xhr = new XMLHttpRequest();
		xhr.addEventListener("load", function(evt){showFoto(evt.target.responseText, inputName);}, false);
		xhr.addEventListener("error", function(evt){alert("Error al subir el archivo");}, false);
		xhr.addEventListener("abort", function(evt){alert("La subida fue cancelada por el usuario o el navegador");}, false);
		xhr.open("POST", "imageshack.php");
			
		document.getElementById('formFotoUpload_' + inputName).style.display = "none";
		document.getElementById('imgPrev_' + inputName).style.display = "";
		document.getElementById('imgPrev_' + inputName).innerHTML = '<img src="img/cargando.gif" width="32" height="32">';
		xhr.send(fd);
	}catch(e){}
}

function getImageShackThumbnail(url){
	aUrl=url.split(".");
	newUrl="";
	for(i=0;i<aUrl.length-1;i++){
		newUrl+=aUrl[i]+".";
	}
	newUrl+="th."+aUrl[i];
	return newUrl;
}

function showUploader(inputName){
	if (confirm('¿Estas seguro que queres borrar la foto?'))
	{
		document.getElementById(inputName).value = "";
		
		var	formFotoUpload = document.getElementById('formFotoUpload_' + inputName);
		newFileInput = document.createElement('input');

		formFotoUpload.removeChild(document.getElementById('fotoUpload_' + inputName));

		newFileInput.setAttribute('type', 'file');
		newFileInput.setAttribute('id', 'fotoUpload_' + inputName);
		newFileInput.setAttribute('onchange', 'javascript:uploadFoto(\''+inputName+'\');');

		formFotoUpload.appendChild(newFileInput);
		formFotoUpload.style.display = "";

		document.getElementById('imgPrev_' + inputName).style.display = "none";
	}
}

function showFoto(imgLink, inputName){
	document.getElementById('formFotoUpload_' + inputName).style.display = "none";
	document.getElementById(inputName).value = imgLink;
	document.getElementById('imgPrev_' + inputName).innerHTML = '<a href="javascript:showUploader(\''+inputName+'\')"><img border="1" src="'+getImageShackThumbnail(imgLink)+'" alt="Borrar"></a>';
}

var s_i;
var s_n;
var s_xhr;
var s_fd;
var s_cantidadFotos = 0;
function uploadFile() {
	imagesFiles = document.getElementById('fileToUpload').files;
	s_i = 0;
	s_n = imagesFiles.length;
	s_xhr = new Array(s_n);
	s_fd = new Array(s_n);
	for (var i = 0; i < imagesFiles.length; i++) {
		s_fd[i] = new FormData();
		s_fd[i].append("foto", imagesFiles[i]);
		s_xhr[i] = new XMLHttpRequest();
		s_xhr[i].addEventListener("load", uploadComplete, false);
		s_xhr[i].addEventListener("error", uploadFailed, false);
		s_xhr[i].addEventListener("abort", uploadCanceled, false);
		s_xhr[i].open("POST", "imageshack.php");
	}
	document.getElementById('formUpload').style.display = "none";
	document.getElementById('progressNumber').innerHTML = '0%<br><img src="img/cargando.gif" width="32" height="32">';
	s_xhr[0].send(s_fd[0]);
}

function uploadComplete(evt) {
	s_cantidadFotos++;
	document.getElementById('cantidadFotos').innerHTML = s_cantidadFotos + ' fotos | <a href="javascript:borrarFotos()">Borrar</a>';
	
	document.getElementById('fotos').value += evt.target.responseText + "\n";
	s_i = s_i+1;
	if(s_i == s_n){
		document.getElementById('progressNumber').innerHTML = "";
		document.getElementById('formUpload').style.display = "";
		document.getElementById('fileToUpload').value = "";
	}else{
		var progress = Math.floor(s_i*100/s_n);
		document.getElementById('progressNumber').innerHTML = progress + '%<br><img src="img/cargando.gif" width="32" height="32">';
		s_xhr[s_i].send(s_fd[s_i]);
	}
}

function uploadFailed(evt) {
	alert("Error al subir el archivo");
}

function uploadCanceled(evt) {
	alert("La subida fue cancelada por el usuario o el navegador");
}

function borrarFotos(){
	s_cantidadFotos = 0;
	document.getElementById('cantidadFotos').innerHTML = s_cantidadFotos + " fotos";
	document.getElementById('fotos').value = "";
}

function show(foto, tipo){
	var imgdiv = document.getElementById('imgdiv');
	
	if(tipo == 1){
		imgdiv.innerHTML = '<iframe title="YouTube video player" class="youtube-player" type="text/html" style="display: none;" onload="javascript:onLoadResize(this, 30);" width="4" height="3" src="http://www.youtube.com/embed/'+foto+'" frameborder="0" allowFullScreen></iframe><img name="loader" src="img/cargando.gif" width="32" height="32">';
	}else{
		imgdiv.innerHTML = '<a href="'+foto+'"><img border="2" src="'+foto+'" style="display: none;" onload="javascript:onLoadResize(this, 70);"><img name="loader" src="img/cargando.gif" width="32" height="32"></a>';
	}
}

function crearGaleria(cantFotos){
	var galeria = document.getElementById("divGaleria");
	
	var cantFotosPorPagina = Math.floor((screen.width - 40) * 0.006);
	var cantPaginas = Math.ceil(cantFotos / cantFotosPorPagina);
	fotosCantidadPage = cantPaginas;
	
	var iFoto = 0;
	var iPagina = -1;
	var divPagina = new Array(cantPaginas);
	var tablePagina = null;
	var tbodyPagina = null;
	
	for(i=0; 0<galeria.childNodes.length; i++){
		var obj = galeria.childNodes[0];
		if(obj.nodeName == 'DIV'){
			if(iFoto % cantFotosPorPagina == 0){
				iPagina++;
				divPagina[iPagina] = document.createElement("div");
				divPagina[iPagina].setAttribute("align", "center");
				divPagina[iPagina].setAttribute("id", "FotosPagina_" + iPagina);
				if(iPagina != 0)
					divPagina[iPagina].style.display = "none";
					
				tablePagina = document.createElement("table");
				tbodyPagina = document.createElement("tbody");
				tablePagina.appendChild(tbodyPagina);
				tbodyPagina.appendChild(document.createElement("tr"));
				
				divPagina[iPagina].appendChild(tablePagina);
			}
			var tdFoto = document.createElement("td");
			tdFoto.setAttribute("valign", "top");
			tdFoto.appendChild(obj);
			tbodyPagina.firstChild.appendChild(tdFoto);
			iFoto++;
		}else{
			galeria.removeChild(obj);
		}
	}
	
	var tableGaleria = document.createElement("table");
	tableGaleria.width = "95%"
	var tbodyGaleria = document.createElement("tbody");
	tableGaleria.appendChild(tbodyGaleria);
	var tr1Galeria = document.createElement("tr");
	var tdCountGaleria = document.createElement("td");
	tdCountGaleria.setAttribute("id", "tdCountGaleria");
	tdCountGaleria.setAttribute("align", "center");
	tdCountGaleria.innerHTML = "1/" + cantPaginas;
	var tr2Galeria = document.createElement("tr");
	var tdPreviousGaleria = document.createElement("td");
	tdPreviousGaleria.width = "1";
	var tdGaleria = document.createElement("td");
	var tdNextGaleria = document.createElement("td");

	tdNextGaleria.width = "1";
	
	tbodyGaleria.appendChild(tr1Galeria);
	tbodyGaleria.appendChild(tr2Galeria);
	
	if(cantPaginas > 1){
		tr1Galeria.appendChild(document.createElement("td"));
		tr1Galeria.appendChild(tdCountGaleria);
		tr1Galeria.appendChild(document.createElement("td"));
	}
	tr2Galeria.appendChild(tdPreviousGaleria);
	tr2Galeria.appendChild(tdGaleria);
	tr2Galeria.appendChild(tdNextGaleria);

	if(cantPaginas > 1){
		var imgPrevious = document.createElement("div");
		imgPrevious.setAttribute("class", "sprite_izq");
		var aPrevious = document.createElement("a");
		aPrevious.setAttribute("href", "javascript:showPreviousDiv();");
		aPrevious.appendChild(imgPrevious);
		tdPreviousGaleria.appendChild(aPrevious);
	}
	
	for (i=0; i<divPagina.length; i++){
		tdGaleria.appendChild(divPagina[i]);
	}

	if(cantPaginas > 1){
		var imgNext = document.createElement("div");
		imgNext.setAttribute("class", "sprite_der");
		var aNext = document.createElement("a");
		aNext.setAttribute("href", "javascript:showNextDiv();");
		aNext.appendChild(imgNext);
		tdNextGaleria.appendChild(aNext);
	}
	
	galeria.appendChild(tableGaleria);
}

var fotosActualPage = 0;
var fotosCantidadPage = 0;
function showNextDiv(){
	var div = document.getElementById("FotosPagina_" + fotosActualPage);
	div.style.display = "none";
	
	fotosActualPage++;
	
	if(fotosActualPage >= fotosCantidadPage){
		fotosActualPage = 0;
	}
	if(fotosActualPage < 0){
		fotosActualPage = fotosCantidadPage-1;
	}
	
	var div = document.getElementById("FotosPagina_" + fotosActualPage);
	div.style.display = "";
	
	var tdCountGaleria = document.getElementById("tdCountGaleria");
	tdCountGaleria.innerHTML = fotosActualPage+1 + "/" + fotosCantidadPage;
}
function showPreviousDiv(){
	var div = document.getElementById("FotosPagina_" + fotosActualPage);
	div.style.display = "none";
	
	fotosActualPage--;
	
	if(fotosActualPage >= fotosCantidadPage){
		fotosActualPage = 0;
	}
	if(fotosActualPage < 0){
		fotosActualPage = fotosCantidadPage-1;
	}
	
	var div = document.getElementById("FotosPagina_" + fotosActualPage);
	div.style.display = "";
	
	var tdCountGaleria = document.getElementById("tdCountGaleria");
	tdCountGaleria.innerHTML = fotosActualPage+1 + "/" + fotosCantidadPage;
}


function onLoadResize(obj, p){
	if(p > 0){
		if(obj.width > 0){
			var r = obj.width/obj.height;
			var imgWidth = Math.floor(screen.width > 0 ? screen.width*p/100 : 1024*p/100);
			var imgHeight = Math.floor(imgWidth/r);
			obj.width = imgWidth;
			obj.height = imgHeight;
		}else{
			obj.width = Math.floor(screen.width > 0 ? screen.width*p/100 : 1024*p/100);
		}
	}
	onLoadRemoveLoader(obj);
}

function onLoadRemoveLoader(obj){
	obj.style.display = '';
	for (i=0; i<obj.parentNode.childNodes.length; i++){
		if(obj.parentNode.childNodes[i].name == 'loader')
			obj.parentNode.removeChild(obj.parentNode.childNodes[i]);
	}
}

function toggleFacebook(){
	var publishFacebook = document.getElementById('publishFacebook');
	if(publishFacebook.value == 0){
		publishFacebook.value = 1;
		document.getElementById('sprite_publishFacebook').className = "sprite_facebook";
	}else{
		publishFacebook.value = 0;
		document.getElementById('sprite_publishFacebook').className = "sprite_facebook_hidden";
	}
}
function toggleTwitter(){
	var publishTwitter = document.getElementById('publishTwitter');
	if(publishTwitter.value == 0){
		publishTwitter.value = 1;
		document.getElementById('sprite_publishTwitter').className = "sprite_twitter";
	}else{
		publishTwitter.value = 0;
		document.getElementById('sprite_publishTwitter').className = "sprite_twitter_hidden";
	}
}

function getYoutubeID(url){
    var urlparts = url.split('?');
    if (urlparts.length > 1) {
        var parameters = urlparts[1].split('&');
        for (var i = 0; i < parameters.length; i++) {
            var paramparts = parameters[i].split('=');
            if (paramparts.length > 1 && unescape(paramparts[0]) == 'v') {
                return unescape(paramparts[1]);
            }
        }
    }
}

function enterYoutubeLink(textbox){
	var id = getYoutubeID(textbox.value);
	if(id){
		document.getElementById('imgyoutube').innerHTML = '<img border="2" src="http://img.youtube.com/vi/'+id+'/2.jpg" style="display: none;" onload="javascript:onLoadRemoveLoader(this);"><img name="loader" src="img/cargando.gif" width="32" height="32">';
	}else{
		document.getElementById('imgyoutube').innerHTML = '';
	}
}

function alignFacebookAd(){
	var facebookAd = document.getElementById('facebookAd');
	facebookAd.style.left = (screen.width >> 1) - 250;
	facebookAd.style.top = 150;
}

function hideFacebookAd(){
	document.getElementById('facebookAd').style.display = "none";
	document.cookie = "hideFacebookAd=true; expires=31-Dec-2015 23:59:59 GMT";
}

