var codigoimagen  = '';
var nombrearchivo = '';
var nombrefoto		= '';
var emailfoto			= '';
var nombremarco 	= 'marco01';
var pagina 				= 1;

var foto1="";	var nombre1="";
var foto2="";	var nombre2="";
var foto3="";	var nombre3="";
var foto4="";	var nombre4="";
var foto5="";	var nombre5="";
var foto6="";	var nombre6="";
var foto7="";	var nombre7="";
var foto8="";	var nombre8="";
var foto9="";	var nombre9="";
var foto10="";var nombre10="";
var foto11="";var nombre11="";
var foto12="";var nombre12="";


function traeFoto() {
	//obtener variable codigoimagen	
	codigoimagen = cogerVariable('c');
	if(codigoimagen!="" && isNumeric(codigoimagen)) {
		var pars = 'c='+codigoimagen;
		var url = 'php/data_foto.php?';		
		var myAjax = new Ajax.Request(
		url, 
		{
			method: 'get', 
			parameters: pars, 
			onComplete: poneFoto,
			onFailure: ErrorFunc
		});
	} else {
		alert('codigo invalido');
		window.location = 'subi_tu_foto_gal.htm';
	}		
}

function poneFoto(requester)
{
	//recupero todo en variables
	var result = requester.responseXML.getElementsByTagName("resultadosGenerales")[0].attributes.getNamedItem("resultado").nodeValue;
	if(result) {
		var xml_foto = requester.responseXML.getElementsByTagName("resultadosGenerales")[0];		
		nombrearchivo	= xml_foto.getElementsByTagName("foto")[0].childNodes[0].nodeValue;		
		nombrefoto	 	= xml_foto.getElementsByTagName("nombre")[0].childNodes[0].nodeValue;			
		emailfoto		 	= xml_foto.getElementsByTagName("email")[0].childNodes[0].nodeValue;				
		$('fotousuario').src = "fotos/"+nombrearchivo;	
	}	else {
		alert('codigo invalido');
		window.location = 'dibujos_galeria.htm';		
	}	
}

function poneMarco(marco) 
{
	$('marco').src = "img/fotos/marcos/"+marco+'.png';
	nombremarco = marco;
	$('guardar').show();
	$('envia').hide();
}

function pasaPagina() 
{
	if(pagina==1) {
		$('pag01').hide();
		$('pag02').show();
		pagina=2;
	} else {
		$('pag02').hide();
		$('pag01').show();
		pagina=1;
	}
}

function procesarFoto() {
	//obtener variable codigoimagen
	if(nombremarco=="")
		alert('debes seleccionar un marco');
	else {			
		var pars = '&c='+codigoimagen+'&a='+nombrearchivo+'&m='+nombremarco;		
		var url = 'php/alta_foto.php?';				
		var myAjax = new Ajax.Request(		
		url, 
		{
			method: 'get', 
			parameters: pars, 
			onComplete: vuelveAlta,
			onFailure: ErrorFunc
		});
	}	
}

function getFoto()
{
	window.location = 'download.php?file=album/'+nombrearchivo;		
}

function vuelveAlta(requester) 
{
	$('guardar').hide();
	$('envia').show();
}

function ErrorFunc()
{
	alert('hubo un error intente nuevamente');
}

function enviaEmail() {
	if($F('anombre').length==0 || $F('aemail').length==0)
		alert('Debes completar ambos campos');
	else
		if(!checkEmail($F('aemail')))
			alert('Debes ingresar un email valido');	
		else {	
			var pars = '&anombre='+$F('anombre')+'&aemail='+$F('aemail')+'&nombre='+nombrefoto+'&email='+emailfoto+'&archivo='+nombrearchivo;					
			var url = 'php/alta_emailfoto.php?';		
			var myAjax = new Ajax.Request(
			url, 
			{
				method: 'get', 
				parameters: pars, 
				onComplete: poneGracias,
				onFailure: ErrorFunc
			});
	}
}

function poneGracias() 
{
	$('anombre').value = '';
	$('aemail').value = '';
	$('gracias').show();
	$('envia').hide();	
}

function mandarOtro()
{
	$('anombre').value = '';
	$('aemail').value = '';
	$('envia').show();
	$('gracias').hide();
}

/*GALERIA*/
function traeData(orden) 
{
	$(document.body).startWaiting('bigWaiting');
	var pars = '';
	var url = 'php/data_galeriafotos.php?orden='+orden;
	var myAjax = new Ajax.Request(
	url, 
	{
		method: 'get', 
		parameters: pars, 
		onComplete: poneDatosResultados,
		onFailure: ErrorFunc
	});		
}

function poneDatosResultados(requester)
{
	$(document.body).stopWaiting();
		
	//recupero todo en variables
	var xml_fotos = requester.responseXML.getElementsByTagName("resultadosGenerales")[0];		
	
	if(xml_fotos.getElementsByTagName("nombre1").length > 0)
		nombre1 = xml_fotos.getElementsByTagName("nombre1")[0].childNodes[0].nodeValue;		
	if(xml_fotos.getElementsByTagName("nombre2").length > 0)
		nombre2 = xml_fotos.getElementsByTagName("nombre2")[0].childNodes[0].nodeValue;		
	if(xml_fotos.getElementsByTagName("nombre3").length > 0)
		nombre3 = xml_fotos.getElementsByTagName("nombre3")[0].childNodes[0].nodeValue;			
	if(xml_fotos.getElementsByTagName("nombre4").length > 0)
		nombre4 = xml_fotos.getElementsByTagName("nombre4")[0].childNodes[0].nodeValue;		
	if(xml_fotos.getElementsByTagName("nombre5").length > 0)
		nombre5 = xml_fotos.getElementsByTagName("nombre5")[0].childNodes[0].nodeValue;		
	if(xml_fotos.getElementsByTagName("nombre6").length > 0)
		nombre6 = xml_fotos.getElementsByTagName("nombre6")[0].childNodes[0].nodeValue;		
	if(xml_fotos.getElementsByTagName("nombre7").length > 0)
		nombre7 = xml_fotos.getElementsByTagName("nombre7")[0].childNodes[0].nodeValue;		
	if(xml_fotos.getElementsByTagName("nombre8").length > 0)
		nombre8 = xml_fotos.getElementsByTagName("nombre8")[0].childNodes[0].nodeValue;		
	if(xml_fotos.getElementsByTagName("nombre9").length > 0)
		nombre9 = xml_fotos.getElementsByTagName("nombre9")[0].childNodes[0].nodeValue;		
	if(xml_fotos.getElementsByTagName("nombre10").length > 0)
		nombre10 = xml_fotos.getElementsByTagName("nombre10")[0].childNodes[0].nodeValue;		
	if(xml_fotos.getElementsByTagName("nombre11").length > 0)
		nombre11 = xml_fotos.getElementsByTagName("nombre11")[0].childNodes[0].nodeValue;		
	if(xml_fotos.getElementsByTagName("nombre12").length > 0)
		nombre12 = xml_fotos.getElementsByTagName("nombre12")[0].childNodes[0].nodeValue;													
	
	if(xml_fotos.getElementsByTagName("foto1").length > 0)		
		foto1 = xml_fotos.getElementsByTagName("foto1")[0].childNodes[0].nodeValue;					
	if(xml_fotos.getElementsByTagName("foto2").length > 0)
		foto2 = xml_fotos.getElementsByTagName("foto2")[0].childNodes[0].nodeValue;			
	if(xml_fotos.getElementsByTagName("foto3").length > 0)
		foto3 = xml_fotos.getElementsByTagName("foto3")[0].childNodes[0].nodeValue;			
	if(xml_fotos.getElementsByTagName("foto4").length > 0)
		foto4 = xml_fotos.getElementsByTagName("foto4")[0].childNodes[0].nodeValue;			
	if(xml_fotos.getElementsByTagName("foto5").length > 0)
		foto5 = xml_fotos.getElementsByTagName("foto5")[0].childNodes[0].nodeValue;			
	if(xml_fotos.getElementsByTagName("foto6").length > 0)
		foto6 = xml_fotos.getElementsByTagName("foto6")[0].childNodes[0].nodeValue;			
	if(xml_fotos.getElementsByTagName("foto7").length > 0)
		foto7 = xml_fotos.getElementsByTagName("foto7")[0].childNodes[0].nodeValue;			
	if(xml_fotos.getElementsByTagName("foto8").length > 0)
		foto8 = xml_fotos.getElementsByTagName("foto8")[0].childNodes[0].nodeValue;			
	if(xml_fotos.getElementsByTagName("foto9").length > 0)
		foto9 = xml_fotos.getElementsByTagName("foto9")[0].childNodes[0].nodeValue;			
	if(xml_fotos.getElementsByTagName("foto10").length > 0)
		foto10 = xml_fotos.getElementsByTagName("foto10")[0].childNodes[0].nodeValue;			
	if(xml_fotos.getElementsByTagName("foto11").length > 0)
		foto11 = xml_fotos.getElementsByTagName("foto11")[0].childNodes[0].nodeValue;			
	if(xml_fotos.getElementsByTagName("foto12").length > 0)
		foto12 = xml_fotos.getElementsByTagName("foto12")[0].childNodes[0].nodeValue;			
	
	if(foto1!='') $('img1').src="fotos/"+foto1;	
	if(foto2!='') $('img2').src="fotos/"+foto2;	
	if(foto3!='') $('img3').src="fotos/"+foto3;	
	if(foto4!='') $('img4').src="fotos/"+foto4;	
	if(foto5!='') $('img5').src="fotos/"+foto5;	
	if(foto6!='') $('img6').src="fotos/"+foto6;	
	if(foto7!='') $('img7').src="fotos/"+foto7;	
	if(foto8!='') $('img8').src="fotos/"+foto8;	
	if(foto9!='') $('img9').src="fotos/"+foto9;	
	if(foto10!='') $('img10').src="fotos/"+foto10;	
	if(foto11!='') $('img11').src="fotos/"+foto11;	
	if(foto12!='') $('img12').src="fotos/"+foto12;	

	if(nombre1!='') $('nombre1').innerHTML='<a href="#" onclick="bajarFoto(1)" class="textoresaltoGaleria">'+nombre1.substring(0,20)+'</a>';		
	if(nombre2!='') $('nombre2').innerHTML='<a href="#" onclick="bajarFoto(2)" class="textoresaltoGaleria">'+nombre2.substring(0,20)+'</a>';				
	if(nombre3!='') $('nombre3').innerHTML='<a href="#" onclick="bajarFoto(3)" class="textoresaltoGaleria">'+nombre3.substring(0,20)+'</a>';		
	if(nombre4!='') $('nombre4').innerHTML='<a href="#" onclick="bajarFoto(4)" class="textoresaltoGaleria">'+nombre4.substring(0,20)+'</a>';		
	if(nombre5!='') $('nombre5').innerHTML='<a href="#" onclick="bajarFoto(5)" class="textoresaltoGaleria">'+nombre5.substring(0,20)+'</a>';		
	if(nombre6!='') $('nombre6').innerHTML='<a href="#" onclick="bajarFoto(6)" class="textoresaltoGaleria">'+nombre6.substring(0,20)+'</a>';		
	if(nombre7!='') $('nombre7').innerHTML='<a href="#" onclick="bajarFoto(7)" class="textoresaltoGaleria">'+nombre7.substring(0,20)+'</a>';		
	if(nombre8!='') $('nombre8').innerHTML='<a href="#" onclick="bajarFoto(8)" class="textoresaltoGaleria">'+nombre8.substring(0,20)+'</a>';		
	if(nombre9!='') $('nombre9').innerHTML='<a href="#" onclick="bajarFoto(9)" class="textoresaltoGaleria">'+nombre9.substring(0,20)+'</a>';		
	if(nombre10!='') $('nombre10').innerHTML='<a href="#" onclick="bajarFoto(10)" class="textoresaltoGaleria">'+nombre10.substring(0,20)+'</a>';		
	if(nombre11!='') $('nombre11').innerHTML='<a href="#" onclick="bajarFoto(11)" class="textoresaltoGaleria">'+nombre11.substring(0,20)+'</a>';		
	if(nombre12!='') $('nombre12').innerHTML='<a href="#" onclick="bajarFoto(12)" class="textoresaltoGaleria">'+nombre12.substring(0,20)+'</a>';		
}

function bajarFoto(num) 
{
	if(num==1) varurl = foto1;		
	if(num==2) varurl = foto2;		
	if(num==3) varurl = foto3;		
	if(num==4) varurl = foto4;		
	if(num==5) varurl = foto5;		
	if(num==6) varurl = foto6;		
	if(num==7) varurl = foto7;		
	if(num==8) varurl = foto8;		
	if(num==9) varurl = foto9;		
	if(num==10) varurl = foto10;		
	if(num==11) varurl = foto11;		
	if(num==12) varurl = foto12;			
	
	window.location = 'download.php?file=album/'+varurl;	
}