// JavaScript Document
var popupStatus = 0;

//-----------------------------------FUNCIONES DE RESULTADOS --------------------------------------------------
function LOAD()
{
	
}

function btnCertificado_Click(id_resultado,id_prueba)
{
	window.location = ("pdf.php?ref="+id_resultado+"&ref2="+id_prueba);
}

function btnCamara_Click(video,tiempo)
{
	document.getElementById('td_video').innerHTML="<iframe src ='video.php?video="+video+"&tiempo="+tiempo+"' scrolling='no' frameborder='0' width='382' height='274' align='middle'></iframe>";
}

function Mostrar_Individual(dorsal)
{

	param="evento="+document.getElementById('cmbEventos').value+"&prueba="+document.getElementById('cmbPrueba').value+"&ver=individual&valor="+dorsal;
	
	abrir('filtro_resultados','filtro_resultados','resultados.php',param);
}

function btnVer_Click(pag)
{	
	var cantidad="";
	var pagina="";
	var valor_cantidad="";
	var valor_pagina="";
	var valor_filtro="";
	
	ver=document.getElementById('cmbTipo').value;
	
	cantidad=document.getElementById("cmbRxP");
	if (cantidad!=null) valor_cantidad="&cantidad="+document.getElementById('cmbRxP').value;
	if (pag!=undefined) valor_pagina="&pagina="+pag;
		
	switch(ver) 
	{
		case 'general':
			valor_filtro="&valor=-1";
			break;
		case 'individual':
			valor_filtro="&valor="+trim(document.getElementById('valor_ind').value);
			break;
		case 'grupo':
			valor_filtro="&valor="+document.getElementById('cmbGrupo').value;
			break;
		case 'categoria':
			valor_filtro="&valor="+document.getElementById('cmbCategoria').value;
			break; 
		case 'sexo':
			valor_filtro="&valor="+document.getElementById('cmbSexo').value;
			break; 
	}
	
	if (valor_filtro=="&valor=0"||valor_filtro=="&valor=")
	{
	}
	else
	{
		param="evento="+document.getElementById('cmbEventos').value+"&prueba="+document.getElementById('cmbPrueba').value+"&ver="+ver+valor_cantidad+valor_pagina+valor_filtro;

		$("#filtro_resultados").ajaxStart(function(){
		   $("#filtro_resultados").html("<table border='0' width='100%'><tr><td align='left' height='10'></td><td align='center'></td><td align='left'></td></tr><tr><td align='left'></td><td align='center'><img src='../img/cargando.gif' width='50' height='50'/><br><span class='cabecera_resultados'>Cargando resultados...</span></td><td align='left'></td></tr></table>")
		 });
		
		$.ajax({
			type: "POST",
			url: "resultados.php",
			data: param,
			success: function(res){
					if (res!=""){
						res = res.substr(2,res.length-2);
						$("#filtro_resultados").fadeIn('slow');
						$("#filtro_resultados").html(res);
						$("#filtro_resultados").unbind("ajaxStart");
					}
				}
		 });
	}
}

function CuponFoto(prueba,foto){	
	var email = document.getElementById('txt_email');
	if(emailValidator(email, "Ingrese una direccion de email valida", "error")){ 
		var cod_prueba;
		var cod_foto= Mid(foto,0,4);
		var rnd1 = rand(9);
		
		prueba = prueba+'';		
		if (prueba.length==1){cod_prueba="00"+''+prueba;}
		if (prueba.length==2){cod_prueba="0"+''+prueba;}
		if (prueba.length==3){cod_prueba=prueba;}
		
		var cod_cupon = cod_prueba+''+cod_foto+''+rnd1;
		var param = "accion=generar_cupon&email="+email.value+"&prueba="+prueba+"&foto="+foto+"&cod_cupon="+cod_cupon;
		
		$.ajax({
			type: "POST",
			url: "../clasifotos/pedidos.php",
			data: param,
			success: function(res){
					if (res!=""){
						window.location="http://www.inscribiteya.com/especiales/clasifotos/cupon.php?cod_cupon="+cod_cupon;
					}
					else{
						alert("Ha ocurrido un error inesperado. Favor intente nuevamente mas tarde.");
					}
					disablePopup();
				}
		 });
	}
}

function Mid(str, start, len){
    if (start < 0 || len < 0) return "";
    var iEnd, iLen = String(str).length;
    if (start + len > iLen)
          iEnd = iLen;
    else
          iEnd = start + len;
    return String(str).substring(start,iEnd);
}

function rand (n){
  return (Math.floor(Math.random()*n+1));
}
		
function VerFoto(archivo,prueba,foto){
	centerPopup(450,500);
	loadPopup();
	$("#Popup").html("<table width='100%' align='center' border='0' cellspacing='0' cellpadding='2'><tr><td align='left'><img src='../clasifotos/img/logo_clasifotos.png'/></td><td align='right'><img src='../clasifotos/img/logo_clasifotos_new.png'/></td></tr><tr><td colspan='2' align='center' class='texto_clasifotos'><b>Recibi esta foto en tu mail y en alta calidad <i>3000x4000px (A2)</i>!!</b> <a href='../clasifotos/img/ejemplo_enduro.jpg' title='Ejemplo foto'  target='_blank' class='clasifotos_ejemplo'>[ver ejemplo]</a></td></tr><tr><td colspan='2' align='center'><div id='div_precio'><img src='../clasifotos/img/precio.png'/></div><img src='"+archivo+"' width='400' height='300'/></td></tr><tr><td colspan='2' align='center'><table width='100%' align='center' border='0' cellspacing='0' cellpadding='2'><tr><td width='65%' align='right' class='texto_clasifotos'><i><b>Email:</i></b> <input name='txt_email' id='txt_email' style='width:200px; height:20px' type='text'></td><td align='left'><img style='cursor:pointer' src='../clasifotos/img/btn_cupon.png' onclick='CuponFoto("+prueba+",&quot;"+foto+"&quot;)'/></td></tr></table></td></tr></table>");
}

function centerPopup(h, w){
	var windowWidth = document.documentElement.clientWidth;
	var windowHeight = document.documentElement.clientHeight;
	var popupHeight = h;
	var popupWidth = w;

	$("#Popup").css({
		"position": "absolute",
		"height": h+"px",
		"width": w+"px",
		"left": windowWidth/2-popupWidth/2,
		"top": windowHeight/2-popupHeight/2+$(document).scrollTop()
	});
	
	$("#backgroundPopup").css({
		"height": windowHeight
	});
	
}

function loadPopup(){
	if(popupStatus==0){
		$("#backgroundPopup").css({
			"opacity": "0.7"
		});
		$("#backgroundPopup").fadeIn("300");
		$("#Popup").fadeIn("300");
		popupStatus = 1;
	}
}

function disablePopup(){
	if(popupStatus==1){
		$("#backgroundPopup").fadeOut("400");
		$("#Popup").fadeOut("400");
		popupStatus = 0;
	}
}

function cmbEvento_Change(obj,ev,mo,yr) 
{
	window.location = ("?ev="+ev+"&mo="+mo+"&yr="+yr+"&evento="+obj.value);
}

function cmbPrueba_Change(obj,ev,mo,yr)
{
	window.location = ("?ev="+ev+"&mo="+mo+"&yr="+yr+"&evento="+g('cmbEventos').value+"&prueba="+obj.value);
}

function cmbTipo_Change(obj)
{
	switch(obj.value)
	{
		case '0':
			document.getElementById('filtro_resultados').innerHTML="";
			document.getElementById('opciones_grupo').style.display = "none";
			document.getElementById('opciones_categoria').style.display = "none";
			document.getElementById('opciones_sexo').style.display = "none";
			document.getElementById('opciones_individual').style.display = "none";
			document.getElementById('boton_ver').innerHTML="";
			break;
		case 'general':
			document.getElementById('filtro_resultados').innerHTML="";
			document.getElementById('opciones_grupo').style.display = "none";
			document.getElementById('opciones_categoria').style.display = "none";
			document.getElementById('opciones_sexo').style.display = "none";
			document.getElementById('opciones_individual').style.display = "none";
			document.getElementById('boton_ver').innerHTML="<img src='../img/ver.jpg' border='0' style='cursor:pointer' onclick='btnVer_Click()'/>&nbsp;&nbsp;";
			break;
		case 'individual':
			document.getElementById('filtro_resultados').innerHTML="";
			document.getElementById('opciones_grupo').style.display = "none";
			document.getElementById('opciones_categoria').style.display = "none";
			document.getElementById('opciones_sexo').style.display = "none";
			document.getElementById('opciones_individual').style.display = "";
			document.getElementById('boton_ver').innerHTML="<img src='../img/ver.jpg' border='0' style='cursor:pointer' onclick='btnVer_Click()'/>&nbsp;&nbsp;";
			break;
		case 'grupo':
			document.getElementById('filtro_resultados').innerHTML="";
			document.getElementById('opciones_categoria').style.display = "none";
			document.getElementById('opciones_sexo').style.display = "none";
			document.getElementById('opciones_individual').style.display = "none";
			document.getElementById('opciones_grupo').style.display = "";
			document.getElementById('boton_ver').innerHTML="<img src='../img/ver.jpg' border='0' style='cursor:pointer' onclick='btnVer_Click()'/>&nbsp;&nbsp;";
			break;
		case 'categoria':
			document.getElementById('filtro_resultados').innerHTML="";
			document.getElementById('opciones_sexo').style.display = "none";
			document.getElementById('opciones_grupo').style.display = "none";
			document.getElementById('opciones_individual').style.display = "none";
			document.getElementById('opciones_categoria').style.display = "";
			document.getElementById('boton_ver').innerHTML="<img src='../img/ver.jpg' border='0' style='cursor:pointer' onclick='btnVer_Click()'/>&nbsp;&nbsp;";
			break; 
		case 'sexo':
			document.getElementById('filtro_resultados').innerHTML="";
			document.getElementById('opciones_grupo').style.display = "none";
			document.getElementById('opciones_categoria').style.display = "none";
			document.getElementById('opciones_individual').style.display = "none";
			document.getElementById('opciones_sexo').style.display = "";
			document.getElementById('boton_ver').innerHTML="<img src='../img/ver.jpg' border='0' style='cursor:pointer' onclick='btnVer_Click()'/>&nbsp;&nbsp;";
			break; 
	}
}




function g(id)
{
	return document.getElementById(id);
}
//-----------------------------------FIN FUNCIONES DE RESULTADOS -----------------------------------------------

// --------------------------------- FUNCION PARA MOUSE OVER --------------------------------------------------
function OVER(id)
{
var valor = id;

switch(valor)
	{
		case "inicio":
		{
			document.images["inicio"].src="../img/botonera/inicio_1.jpg";
			break;
		}
		case "somos":
		{
			document.images["somos"].src="../img/botonera/somos_1.jpg";
			break;
		}
		case "servicio":
		{
			document.images["servicio"].src="../img/botonera/servicio_1.jpg";
			break;
		}
		case "clientes":
		{
			document.images["clientes"].src="../img/botonera/clientes_1.jpg";
			break;
		}
		case "calendario":
		{
			document.images["calendario"].src="../img/botonera/calendario_1.jpg";
			break;
		}
		case "resultados":
		{
			
			break;
		}
		case "contacto":
		{
			document.images["contacto"].src="../img/botonera/contacto_1.jpg";
			break;
		}
	}

}
//--------------------------------------------------------------------------------------------------------

// --------------------------------- FUNCION PARA MOUSE OUT --------------------------------------------------
function OUT(id)
{
var valor = id;

switch(valor)
	{
		case "inicio":
		{
			document.images["inicio"].src="../img/botonera/inicio_3.jpg";
			break;
		}
		case "somos":
		{
			document.images["somos"].src="../img/botonera/somos_3.jpg";
			break;
		}
		case "servicio":
		{
			document.images["servicio"].src="../img/botonera/servicio_3.jpg";
			break;
		}
		case "clientes":
		{
			document.images["clientes"].src="../img/botonera/clientes_3.jpg";
			break;
		}
		case "calendario":
		{
			document.images["calendario"].src="../img/botonera/calendario_3.jpg";
			break;
		}
		case "resultados":
		{
			
			break;
		}
		case "contacto":
		{
			document.images["contacto"].src="../img/botonera/contacto_3.jpg";
			break;
		}
	}

}
//-------------------------------------------------------------------------------------------------------------
