// JavaScript Document

function MM_preloadImages() { //v3.0
  var d=document; if(d.images){ if(!d.MM_p) d.MM_p=new Array();
    var i,j=d.MM_p.length,a=MM_preloadImages.arguments; for(i=0; i<a.length; i++)
    if (a[i].indexOf("#")!=0){ d.MM_p[j]=new Image; d.MM_p[j++].src=a[i];}}
}

function MM_swapImgRestore() { //v3.0
  var i,x,a=document.MM_sr; for(i=0;a&&i<a.length&&(x=a[i])&&x.oSrc;i++) x.src=x.oSrc;
}

function MM_findObj(n, d) { //v4.01
  var p,i,x;  if(!d) d=document; if((p=n.indexOf("?"))>0&&parent.frames.length) {
    d=parent.frames[n.substring(p+1)].document; n=n.substring(0,p);}
  if(!(x=d[n])&&d.all) x=d.all[n]; for (i=0;!x&&i<d.forms.length;i++) x=d.forms[i][n];
  for(i=0;!x&&d.layers&&i<d.layers.length;i++) x=MM_findObj(n,d.layers[i].document);
  if(!x && d.getElementById) x=d.getElementById(n); return x;
}

function MM_swapImage() { //v3.0
  var i,j=0,x,a=MM_swapImage.arguments; document.MM_sr=new Array; for(i=0;i<(a.length-2);i+=3)
   if ((x=MM_findObj(a[i]))!=null){document.MM_sr[j++]=x; if(!x.oSrc) x.oSrc=x.src; x.src=a[i+2];}
}

function openWindow(url, name, width, height, resizable, scrollbar, statusbar)
{
	var screenW = Math.min(width, screen.width);
	var screenH = Math.min(height, screen.height - 80);
	var windowLeft = (screen.width - screenW)/2;
	var windowTop = (screen.height - screenH)/2;
	width     = ('undefined'==typeof width  || !width )?'':',width='+width;
	height    = ('undefined'==typeof height || !height)?'':',height='+height;
	resizable = ('undefined'==typeof resizable  || !resizable ) ? 'no' : resizable ;
	statusbar = ('undefined'==typeof statusbar  || !statusbar ) ? 'no' : statusbar ;
	scrollbar = ('undefined'==typeof scrollbar  || !scrollbar ) ? 'no' : scrollbar ;
	
	window.open(url, name, 'top='+ windowTop +',left=' + windowLeft + ',toolbar=no, scrollbars=' + scrollbar + ', resizable=' + resizable + ', status=' + statusbar + ' ' + width + height);
}

function ajax(url, params, formMethod, target){
	new Ajax.Request(
		url, {
			method: formMethod,
			parameters: params,
			onSuccess: function(transport){
				if('undefined'==typeof target || !target)
					return transport.responseText;
				else
					$(target).innerHTML = transport.responseText;
			}
		}
	);
}

function esIE(){
	if(navigator.appName=='Microsoft Internet Explorer')
		return true;
	else
		return false;
}

function timeout(cmd, tiempo){
	tiempo = tiempo*1000;
	setTimeout(cmd, tiempo);
}

function actualizar(){
	location.href = location.href;
}

function ejecutarConEnter(e, metodo){
	if(e.keyCode==13){
		eval(metodo);
		return;
	}
	return;
}

function get26Vivo(divId){
	var url = rootUrl+'/ajax/canal26vivo.php';
	ajax(url, '', 'get', divId);
}

/* deprecated 
function getVideoPlayerGrande(rootUrl, file, divId){
	var s1 = new SWFObject(rootUrl+"/lib/flvplayer.swf","single","480","360","7");
	s1.addParam("allowfullscreen","true");
	s1.addVariable("file",rootUrl+"/media/"+file);
	s1.addVariable("image",rootUrl+"/media/"+file+".jpg");
	s1.write(divId);
}*/

function getVideoPlayer(rootUrl, file, divId, width, height){
	var s1 = new SWFObject(rootUrl+"/lib/flvplayer.swf","single", width, height,"7");
	s1.addParam("allowfullscreen","true");
	s1.addVariable("file",rootUrl+"/media/"+file);
	s1.addVariable("image",rootUrl+"/media/"+file+".jpg");
	s1.write(divId);
}

function getVideoPreviewHome(id, divId){
	var url = rootUrl+'/ajax/getVideoPreviewHome.php';
	var params = 'id='+id;
	ajax(url, params, 'get', divId);
}

function getVideoPreviewRelacionado(id, divId){
	var url = rootUrl+'/ajax/getVideoPreviewRelacionado.php';
	var params = 'id='+id;
	ajax(url, params, 'get', divId);
}

function getFotoPreviewRelacionada(id, divId){
	var url = rootUrl+'/ajax/getFotoPreviewRelacionada.php';
	var params = 'id='+id;
	ajax(url, params, 'get', divId);
}

function getVideoPreview(id, divId){
	var url = rootUrl+'/ajax/getVideoPreview.php';
	var params = 'id='+id;
	ajax(url, params, 'get', divId);
}

function getUploadObject(rootUrl, mediaUrl, label, fileTypesLabel, fileTypes){
	var s1 = new SWFObject(rootUrl+"/inc/upload.swf", "single", "350", "40", "7");
	s1.addVariable("mediaUrl", mediaUrl);
	s1.addVariable("btnLabel", label);
	s1.addVariable("fileTypes", fileTypes);
	s1.addVariable("fileTypesLabel", fileTypesLabel);
	s1.write('uploader');
}

function toggleSubmit(){
	if($('disclaimer').checked)
		$('submit').disabled = false;
	else
		$('submit').disabled = true;
}

function mostrarTerminos(accion, e){
	var url = rootUrl+'/windows/getDisclaimer.php';
	var params = 'accionDisclaimer='+accion;
	openWindow(url+'?'+params, 'Disclaimer', '550', '400', 0, 1, 0);
	//var pos = mousePosition(e);
	//ajax(url, params, 'get', 'contDisclaimer');
	//mostrarDiv('contDisclaimer');
	//$('contDisclaimer').style.top = !esIE() ? pos[1]-270 : pos[1]+550;
}

function mousePosition(e){
	if(!esIE()){
		var x = e.pageX;
		var y = e.pageY;
	} else {
		var x = e.screenX;
		var y = e.screenY;
	}
	//var mousePositions = document.getElementById('mousePositions');
	//mousePositions.innerHTML = 'X coords: '+x+', Y coords: '+y;
	return Array(x, y);
}

function mostrarError(msg){
	$('errorMsg').innerHTML = msg;
	mostrarDiv('errorMsg');
	timeout("ocultarDiv('errorMsg')", 10);
}

function verificarUsuarioDisponible(){
	var url = rootUrl+'/ajax/verificarUsuarioDisponible.php';
	var params = 'username='+$('username').value;
	if($('username').value.length>0){
		ajax(url, params, 'get', 'usuarioDisponible');
		mostrarDiv('usuarioDisponible');
		timeout("ocultarDiv('usuarioDisponible')", 10);
	}
}

function verificarEmailDisponible(){
	var url = rootUrl+'/ajax/verificarEmailDisponible.php';
	var params = 'email='+$('email').value;
	if($('email').value.length>0){
		ajax(url, params, 'get', 'emailDisponible');
		mostrarDiv('emailDisponible');
		timeout("ocultarDiv('emailDisponible')", 10);
	}
}

function verificarEmail(){
	if(!isValidEmail($('email').value)){
		$('emailDisponible').innerHTML = '<p class="no">La dirección de email ingresada es incorrecta</p>';
		$('submit').disabled = true;
	} else {
		$('emailDisponible').innerHTML = '';
		toggleSubmit();
	}
}

function reenviarConfirmacion(){
	window.location.href="reenviarConfirmacion.html";
}

function recuperarPassword(){
	window.location.href="recuperarPassword.html";
}

function verFoto(fotoUrl, file, divId){
	$(divId).innerHTML = '<a onclick="ocultarFoto();" href="javascript:void(0);"><img src="'+fotoUrl+'/'+file+'" border="0" style="border:1px #333333 solid;" /></a>';
	mostrarDiv('contFoto');
}

function ocultarFoto(){
	ocultarDiv('contFoto');
}

function redir(url){
	location.href = url;
	return false;
}

function ocultarDiv(divId){
	$(divId).style.display = 'none';
}

function mostrarDiv(divId){
	$(divId).style.display = 'block';
}

function disableContextMenu(){
	return false;
}

function validarFormContacto(){
	if($('nombre').value<=3){
		alert('Debe escribir su nombre');
		$('nombre').focus();
		return false;
	}
	
	if($('apellido').value<=3){
		alert('Debe escribir su apellido');
		$('apellido').focus();
		return false;
	}
	
	if(!isValidEmail($('email').value)){
		alert('Debe escribir una dirección de email válida');
		$('email').focus();
		return false;
	}
	
	if($('comentario').value<=10){
		alert('Debe escribir un comentario');
		$('comentario').focus();
		return false;
	}
}