﻿var rnd = Math.random();
var isFirefox;
var isIE;
function getAjax()
{
	var XmlHttp;
	try
	{
		XmlHttp = new ActiveXObject("Msxml2.XMLHTTP");
	}
	catch(e)
	{
		try
		{
			XmlHttp = new ActiveXObject("Microsoft.XMLHTTP");
		} 
		catch(oc)
		{
			XmlHttp = null;
		}
	}
	if(!XmlHttp && typeof XMLHttpRequest != "undefined") 
	{
		XmlHttp = new XMLHttpRequest();
	}
	return XmlHttp;
}
function sniffBrowserType() {
	isFirefox = ( navigator.appName == "Netscape" );
	isIE = (navigator.appName == "Microsoft Internet Explorer" ); 
}
function getElement( id ) 
{
	if( isIE ) {
		return document.all[ id ];
	}
	else {
		return document.getElementById( id );
	}
}
function showLoadScreen(div)
{
	var loading = "<div style=\"text-align:center;color:red;\"><h5>Cargando...</h5></div>";

	tmpDivNumRecibo = getElement( div );
	tmpDivNumRecibo.innerHTML = loading;
}
function getGaleria(Div, idGal)
{
	rnd++;
	url = 'galeriaOVA.aspx?idx='+idGal;
	//alert(url);
	req1 = getAjax();
	req1.onreadystatechange = function(){
		if( req1.readyState == 4 && req1.status == 200 ) {
			obj = getElement( Div );
			obj.innerHTML = req1.responseText;
		}
	}
	req1.open( 'GET', url, true );
	req1.send( null );
}
function getVideo(Div, Idioma)
{
	rnd++;
	var loading = "";
	if (Idioma == 'es')
	loading = "<iframe src=\"video1/index.html\" style=\"width:650px; height:420px; border-width:0; border-style:solid; overflow:hidden;\"></iframe>";
	else
	loading = "<iframe src=\"video2/index.html\" style=\"width:650px; height:420px; border-width:0; border-style:solid; overflow:hidden;\"></iframe>";
	tmpDivNumRecibo = getElement( Div );
	tmpDivNumRecibo.innerHTML = loading;
}
function getVideo2(Div, RutaVideo)
{
	rnd++;
	var loading = "";
	loading = "<iframe src=\""+RutaVideo+"\" style=\"width:650px; height:420px; border-width:0; border-style:solid; overflow:hidden;\"></iframe>";
	tmpDivNumRecibo = getElement( Div );
	tmpDivNumRecibo.innerHTML = loading;
}

$(document).ready(function() {	
	//select all the a tag with name equal to modal
	$('a[name=modal]').click(function(e) {
		//Cancel the link behavior
		e.preventDefault();
		
		//Get the A tag
		var id = $(this).attr('href');
		var idRef = $(this).attr('idRef');
		var tipoEnlace = $(this).attr('tipoEnlace');
		showLoadScreen('divCajaModal');
		if (tipoEnlace == "Galeria") getGaleria('divCajaModal',idRef);
		if (tipoEnlace == "Video") getVideo('divCajaModal',idRef);
		if (tipoEnlace == "Video2") getVideo2('divCajaModal',idRef);
	
		//Get the screen height and width
		var maskHeight = $(document).height();
		var maskWidth = $(window).width();
	
		//Set heigth and width to mask to fill up the whole screen
		$('#mask').css({'width':maskWidth,'height':maskHeight});
		
		//transition effect		
		$('#mask').fadeIn(1000);	
		$('#mask').fadeTo("slow",0.8);	
	
		//Get the window height and width
		var winH = $(window).height();
		var winW = $(window).width();
              
		//Set the popup window to center
		$(id).css('top',  winH/2-$(id).height()/2);
		$(id).css('left', winW/2-$(id).width()/2);
	
		//transition effect
		$(id).fadeIn(2000); 
	
	});
	
	//if close button is clicked
	$('.window .close').click(function (e) {
		//Cancel the link behavior
		e.preventDefault();
		
		$('#mask').hide();
		$('.window').hide();
		showLoadScreen('divCajaModal');
	});		
	
	//if mask is clicked
	$('#mask').click(function () {
		$(this).hide();
		$('.window').hide();
		showLoadScreen('divCajaModal');
	});			
	
});
