var fnsGalerias=function(){}
fnsGalerias.prototype.ValidoINsercionFotos=function(){
	var Titulo=$('TituloGal');
	var Categoria=$('Categoria');
	var description=$('description');
	var cuantasFotoMas=$('cuantasFotoMas');
	var matriz=Categoria.options;
	var estadoFoto=$('estadoFoto');
	if(!Titulo.value){
		alert("Please insert a name for the gallery"); Titulo.focus(); return;
	}else if(!description.value){
		alert("Please insert a description for this new gallery"); description.focus(); return;
	}if(!cuantasFotoMas.value){
		alert("Please select the number of photos to upload (max 24)");cuantasFotoMas.focus(); return;
	}else if(cuantasFotoMas.value>24){
		alert("The maximun number allowed is 24. Please choose a smaller number");cuantasFotoMas.focus(); return;
	}else if(pagi.isNumber(cuantasFotoMas)==true){
		//alert(estadoFoto.value);
		if(estadoFoto.value==1){
			
			if(this.compruboListaFotos(cuantasFotoMas.value)==true){
				
				document.Upload.action="../Groups/?group="+nombreGrupo.value+"&PhotoGallery=true&SaveGale=true";
				document.Upload.submit();
			}
		}else{
			estadoFoto.value=1;
			var rutaAr=$F('rutaSitio');
		var urlRuta = rutaAr+"php_files/clases/grupos/fnsAjax/TraigoMasFotos.php"; 
		new Ajax.Request(urlRuta, {   
			method: 'post',   
			parameters:{cuantasFotoMas:cuantasFotoMas.value,Titulo:Titulo.value,Matriz:matriz[Categoria.selectedIndex].text,Categoria:Categoria.value},
			onSuccess: function(transport) {    
				if(transport.responseText==2){
				 	var notice = $('listaCategorias');     			
				 	alert('Already Exist a Galleriw with this name in your group');  
				 	 
				}else{ 
				 	$('masfechasDatos').update(transport.responseText);   
				}
			} }
		);
		}
	}
}
fnsGalerias.prototype.compruboListaFotos=function(cantidad){
	
	for(i=0;i<cantidad;i++){
		if(!$('BroImageFileImageFotos'+i).value){
			alert("Please insert a photo for each box"); $('BroImageFileImageFotos'+i).focus(); return;
		}else{
			if(i===cantidad-1){
				return true;
			}
		}
	}
}
fnsGalerias.prototype.ValidoUpdate=function(id,idgale){
	var Imagen=$('BroImageFileImageFotos');
	var CaptionFoto=$('CaptionFoto');
	if(!Imagen.value){
		alert("Please insert the photo to upload"); Imagen.focus(); return;
	}else{		
		var rutaAr=$F('rutaSitio');
		var urlRuta = rutaAr+"php_files/clases/Galerias/fnsAjax/ActuaFoto.php"; 
		new Ajax.Request(urlRuta, {   
			method: 'post',   
			parameters:{id:id,Imagen:Imagen.value,CaptionFoto:CaptionFoto.value},
			onSuccess: function(transport) {    				
				window.setTimeout('parent.top.hidePopWin(false);',500); 
				window.setTimeout('parent.pagi.RefrescoPagina();',500);
				
			} }
		);
	}
}

fnsGalerias.prototype.BorroFotoGro=function(id,idGale){
	if(confirm("Are you sure you want to delete this photo? ")){
		var rutaAr=$F('rutaSitio');
		var urlRuta = rutaAr+"php_files/clases/Galerias/fnsAjax/BorroFoto.php"; 
	//	alert(urlRuta);
		new Ajax.Request(urlRuta, {   
			method: 'post',   
			parameters:{id:id,idGale:idGale},
			onSuccess: function(transport) {    				
			//	$('centro').update(transport.responseText);   	
			pagi.RefrescoPagina();			
			} }
		);
	}
}

fnsGalerias.prototype.ValidoInsercionMasFotos=function(){
	var estadoFoto=$('estadoFoto');
	var cuantasfoto=$('cuantasfoto').value;
	var cuantasFotoMas=$('cuantasFotoMas');
	if(!cuantasFotoMas.value){
		alert("To insert more photos you have to select the number of photos you wish to add");cuantasFotoMas.focus(); return;
	}else if(cuantasFotoMas.value>parseInt(cuantasfoto)){
		alert("The maximun number is "+cuantasfoto+", select a smaller number");cuantasFotoMas.focus(); return;
	}else if(pagi.isNumber(cuantasFotoMas)==true){
		//alert(estadoFoto.value);
		if(estadoFoto.value==1){
			if(this.compruboListaFotos(cuantasFotoMas.value)==true){
				document.Upload.action="EdicionSeccion.php?Seccion=SaveMore";
				document.Upload.submit();
			}
		}else{
			estadoFoto.value=1;
			
			var rutaAr=$F('rutaSitio');
			var urlRuta = rutaAr+"php_files/clases/Galerias/fnsAjax/TraigoMasFotos.php"; 
		//	alert(urlRuta);
			new Ajax.Request(urlRuta, {   
				method: 'post',   
				parameters:{caso:2,cuantasFotoMas:cuantasFotoMas.value,idgale:idgale.value},
				onSuccess: function(transport) {    
					if(transport.responseText==2){
					 	var notice = $('listaCategorias');     			
					 	alert('Already Exist a Galleriw with this name in the system');  
					 	 
					}else{ 
					 	$('masfechasDatos').update(transport.responseText);   
					}
				} }
			);
		}
	}
}

fnsGalerias.prototype.crearMasFotoAdd=function(){
	var estadoFoto=$('estadoFoto');
	var cuantasfoto=$('cuantasfoto').value;
	var cuantasFotoMas=$('cuantasFotoMas');
	var idgale=$("idgale");
	if(!cuantasFotoMas.value){
		alert("To insert more photos you have to select the number of photos you wish to add");cuantasFotoMas.focus(); return;
	}else if(cuantasFotoMas.value>parseInt(cuantasfoto)){
		alert("The maximun number is "+cuantasfoto+" , select a smaller number");cuantasFotoMas.focus(); return;
	}else if(pagi.isNumber(cuantasFotoMas)==true){
		//var estadoFoto=document.getElementById('estadoFoto');
		estadoFoto.value=1;		
		var rutaAr=$F('rutaSitio');
			var urlRuta = rutaAr+"php_files/clases/Galerias/fnsAjax/TraigoMasFotos.php"; 
		//	alert(urlRuta);
			new Ajax.Request(urlRuta, {   
				method: 'post',   
				parameters:{caso:2,cuantasFotoMas:cuantasFotoMas.value,idgale:idgale.value},
				onSuccess: function(transport) {    
					if(transport.responseText==2){
					 	var notice = $('listaCategorias');     			
					 	alert('Already Exist a Galleriw with this name in your group');  
					 	 
					}else{ 
					 	$('masfechasDatos').update(transport.responseText);   
					}
				} }
			);
	}
}
fnsGalerias.prototype.crearMasFoto=function(){
	
	var Categoria=$('Categoria');
	var matriz=Categoria.options;
	var Titulo=$('TituloGal');
	var matriz=Categoria.options;
	var cuantasFotoMas=$('cuantasFotoMas');
	var estadoFoto=$('estadoFoto');
	if(!Titulo.value){
		alert("Please insert a name for the gallery"); Titulo.focus(); return;
	}else if(!cuantasFotoMas.value){
		alert("Please select the number of photos to upload (max 24)");cuantasFotoMas.focus(); return;
	}else if(cuantasFotoMas.value>24){
		alert("The maximun number allowed is 24. Please choose a smaller number");cuantasFotoMas.focus(); return;
	}else if(pagi.isNumber(cuantasFotoMas)==true){
		
		var rutaAr=$F('rutaSitio');
		var urlRuta = rutaAr+"php_files/clases/Galerias/fnsAjax/TraigoMasFotos.php"; 
		new Ajax.Request(urlRuta, {   
			method: 'post',   
			parameters:{caso:1,cuantasFotoMas:cuantasFotoMas.value,Titulo:Titulo.value,Matriz:matriz[Categoria.selectedIndex].text,Categoria:Categoria.value},
			onSuccess: function(transport) {    
				if(transport.responseText==2){
				 	var notice = $('listaCategorias');     			
				 	alert('Already Exist a Galleriw with this name in your group');  
				 	 
				}else{
				 	$('masfechasDatos').update(transport.responseText);   
				 	estadoFoto.value=1;
				}
			} }
		);
	}
}

fnsGalerias.prototype.ValidoINsercionFotos=function(){
	var Titulo=$('TituloGal');
	var description=$('description');
	var cuantasFotoMas=$('cuantasFotoMas');
	var estadoFoto=$('estadoFoto');
	var Categoria=$('Categoria');
	var matriz=Categoria.options;
	if(!Titulo.value){
		alert("Please insert a name for the gallery"); Titulo.focus(); return;
	}else if(!description.value){
		alert("Please insert a description for this new gallery"); description.focus(); return;
	}if(!cuantasFotoMas.value){
		alert("Please select the number of photos to upload (max 24)");cuantasFotoMas.focus(); return;
	}else if(cuantasFotoMas.value>24){
		alert("The maximun number allowed is 24. Please choose a smaller number");cuantasFotoMas.focus(); return;
	}else if(isNumber(cuantasFotoMas)==true){
		//alert(estadoFoto.value);
		if(estadoFoto.value==1){
			if(this.compruboListaFotos(cuantasFotoMas.value)==true){
				/*sajax_request_type = "POST";
				var datos;
				datos=Titulo.value;
				x_ComprueboNombreGaleria(datos,ComprueboNombreSubmit);SaveGale*/
				document.Upload.action="index.php?SaveGale=true";
				document.Upload.submit();
			}
		}else{
			var rutaAr=$F('rutaSitio');
		var urlRuta = rutaAr+"php_files/clases/Galerias/fnsAjax/TraigoMasFotos.php"; 
		new Ajax.Request(urlRuta, {   
			method: 'post',   
			parameters:{caso:1,cuantasFotoMas:cuantasFotoMas.value,Titulo:Titulo.value,Matriz:matriz[Categoria.selectedIndex].text,Categoria:Categoria.value},
			onSuccess: function(transport) {    
				if(transport.responseText==2){
				 	var notice = $('listaCategorias');     			
				 	alert('Already Exist a Galleriw with this name in your group');  
				 	 
				}else{
				 	$('masfechasDatos').update(transport.responseText);   
				 	estadoFoto.value=1;
				}
			} }
		);
		}
	}
}
var fnsGale=new fnsGalerias();

function InsertoCategoriaGale(caso){
	switch(caso){
		case 1:
			var titulo=$('titulo');
			var datos;
			sajax_request_type = "POST";
			datos=1+"##"+titulo.value;
			x_InsertarEditarCategoria(datos,VolverAlgunLado);
		break;
		
		case 2:
			var titulo=$('titulo');
			var idCate=$('idCate');
			var datos;
			sajax_request_type = "POST";
			datos=2+"##"+titulo.value+"##"+idCate.value;
			x_InsertarEditarCategoria(datos,VolverAlgunLado);
		break;
	}
}

function BorroSecGalle(id,caso){
	switch(caso){
		case "Cate":
			if(confirm("If you delete this category all Galleries inside will be deleted. Continue?")){
				var datos;
				sajax_request_type = "POST";
				datos=1+"##"+id;
				x_BorroGales(datos,VolverAlgunLado);
			}
		break;
	}
}


function ComprueboNombreSubmit(valor){
	if(valor==1){
		$('ErrorNombre').innerHTML ="This Category Name already exists";
	}else if(valor==2){
		document.Upload.action="?SaveGale=true";
		document.Upload.submit();
	}
}
function compruboListaFotos(cantidad){
	
	for(i=0;i<cantidad;i++){
		if(!$('BroImageFileImageFotos'+i).value){
			alert("Please insert a photo for each box"); $('BroImageFileImageFotos'+i).focus(); return;
		}else{
			if(i===cantidad-1){
				return true;
			}
		}
	}
}
function crearMasFoto(){
	var cuantasFotoMas=$('cuantasFotoMas');
	if(!cuantasFotoMas.value){
		alert("Please select the number of photos to upload (max 24)");cuantasFotoMas.focus(); return;
	}else if(cuantasFotoMas.value>24){
		alert("The maximun number allowed is 24. Please choose a smaller number");cuantasFotoMas.focus(); return;
	}else if(isNumber(cuantasFotoMas)==true){
		var estadoFoto=$('estadoFoto');
		estadoFoto.value=1;
		sajax_request_type = "POST";
		var datos;
		datos=cuantasFotoMas.value;
		x_TraigoMasFotos(datos,mostrarResultadoFoto);
	}
}

function mostrarResultadoFoto(datos){
	$('masfechasDatos').innerHTML =datos;
}

function isNumber(elem) {
	var str = elem.value;
	var re = /^[-]?\d*\.?\d*$/;
	str = str.toString( );
	if (!str.match(re)) {
		alert("Enter only numbers into this field.");
		return false;
	}
	return true;
}

function BorroFoto(id){
	if(confirm("Are you sure you want to delete this photo? ")){
		sajax_request_type = "POST";
		var datos;
		datos=2+"##"+id;
		x_BorroGales(datos,pagi.RefrescoPagina);
	}
}

function ValidoUpdate(id,idgale){
	var BroImageFileImageFotos=$('BroImageFileImageFotos');
	var CaptionFoto=$('CaptionFoto');
	if(!BroImageFileImageFotos.value){
		alert("Please insert the photo to upload"); BroImageFileImageFotos.focus(); return;
	}else{
		sajax_request_type = "POST";
		var datos;
		datos=3+"##"+id+"##"+BroImageFileImageFotos.value+"##"+CaptionFoto.value+"##"+idgale;
		x_InsertarEditarCategoria(datos,VolverAlgunLado);
	}
}
function crearMasFotoAdd(){
	var estadoFoto=$('estadoFoto');
	var cuantasfoto=$('cuantasfoto').value;
	var cuantasFotoMas=$('cuantasFotoMas');
	if(!cuantasFotoMas.value){
		alert("To insert more photos you have to select the number of photos you wish to add");cuantasFotoMas.focus(); return;
	}else if(cuantasFotoMas.value>parseInt(cuantasfoto)){
		alert("The maximun number is "+cuantasfoto+" , select a smaller number");cuantasFotoMas.focus(); return;
	}else if(isNumber(cuantasFotoMas)==true){
		var estadoFoto=$('estadoFoto');
		estadoFoto.value=1;
		sajax_request_type = "POST";
		var datos;
		datos=cuantasFotoMas.value;
		x_TraigoMasFotos(datos,mostrarResultadoFoto);
	}
}
function ValidoInsercionMasFotos(){
	var estadoFoto=$('estadoFoto');
	var cuantasfoto=$('cuantasfoto').value;
	var cuantasFotoMas=$('cuantasFotoMas');
	if(!cuantasFotoMas.value){
		alert("To insert more photos you have to select the number of photos you wish to add");cuantasFotoMas.focus(); return;
	}else if(cuantasFotoMas.value>parseInt(cuantasfoto)){
		alert("The maximun number is "+cuantasfoto+", select a smaller number");cuantasFotoMas.focus(); return;
	}else if(isNumber(cuantasFotoMas)==true){
		//alert(estadoFoto.value);
		if(estadoFoto.value==1){
			if(compruboListaFotos(cuantasFotoMas.value)==true){
				document.Upload.action="?AddFoto=true";
				document.Upload.submit();
			}
		}else{
			estadoFoto.value=1;
			sajax_request_type = "POST";
			var datos;
			datos=cuantasFotoMas.value;
			x_TraigoMasFotos(datos,mostrarResultadoFoto);
		}
	}
}