var imagendeusuario = "";
var gifelegido = "1";
var emoticon = "";

function subeFoto() {		
	$('imagen').action = 'php/alta_fotoemoticon.php';
	$('imagen').target = 'upload_target';
	$('imagen').submit();
	$('formu').hide();
	$('procesando').show();
}

function vuelveDelSubeFoto(result) 
{
	if(result!="2") {
		imagendeusuario = result;
		$('imguser').src = 'fotos/'+result;
		$('formu').show();
		$('procesando').hide();
		
		$('nombre').value = '';
		$('email').value = '';
		$('guardar').show();
		$('form').hide();
		$('gracias').hide();
		
	}		
}

//funcoines del reausltado
function guardarEmoticon() 
{
	var pars = '&j='+imagendeusuario+'&g='+gifelegido;
	var url = 'php/alta_gifanimado.php?';
	var myAjax = new Ajax.Request(
	url, 
	{
		method: 'get', 
		parameters: pars, 
		onComplete: poneDatosResultados,
		onFailure: ErrorFunc
	});
}

function poneDatosResultados(requester)
{
	emoticon = requester.responseText
	$('guardar').hide();
	$('form').show();
}

function bajarArchivo()
{
	location.href = 'download.php?file=emoticon/'+emoticon;
}

function cambiaMarco(num) {
	$('marco').src='img/emoticon/gif/'+num+'.gif';
	gifelegido = num;
}

function enviaEmail() {
	if($F('nombre').length==0 || $F('email').length==0)
		alert('Debes completar ambos campos');
	else
		if(!checkEmail($F('email')))
			alert('Debes ingresar un email valido');	
		else {	
			var pars = '&nombre='+$F('nombre')+'&email='+$F('email')+'&archivo='+emoticon;								
			var url = 'php/alta_emailemoticon.php?';		
			var myAjax = new Ajax.Request(
			url, 
			{
				method: 'get', 
				parameters: pars, 
				onComplete: poneGracias,
				onFailure: ErrorFunc
			});
	}
}

function poneGracias() 
{
	$('nombre').value = '';
	$('email').value = '';
	$('gracias').show();
	$('form').hide();	
}

function mandarOtro()
{
	$('nombre').value = '';
	$('email').value = '';
	$('form').show();
	$('gracias').hide();
}

function ErrorFunc()
{
	alert('hubo un error intente nuevamente');
}