



/* Validar campos del envio a un amigo */
jQuery.fn.validarEnvio = function(form){

		//alert(form.mailDestino.value);

		if (echeck(form.mailDestino.value)==false || form.mailDestino.value==''){
			alert('La dirección email de destino no es válida');
			form.mailDestino.value = "";
			form.mailDestino.focus();
			return false;
		}

		if (echeck(form.mailOrigen.value)==false || form.mailOrigen.value==''){
			alert('La dirección email de origen no es válida');
			form.mailOrigen.value = "";
			form.mailOrigen.focus();
			return false;
		}

		if (form.nombre.value=='' || form.nombre.value=='Nombre/s'){
			alert('No ingresaste tu nombre');
			form.nombre.value = "";
			form.nombre.focus();
			return false;
		}

		return true;

}


function echeck(str) {
	var at="@"
	var dot="."
	var lat=str.indexOf(at)
	var lstr=str.length
	var ldot=str.indexOf(dot)
	if (str.indexOf(at)==-1){
		//alert("La dirección de email no es válida");
		return false
	}
	if (str.indexOf(at)==-1 || str.indexOf(at)==0 || str.indexOf(at)==lstr){
		//alert("La dirección de email no es válida");
		return false;
	}
	if (str.indexOf(dot)==-1 || str.indexOf(dot)==0 || str.indexOf(dot)==lstr){
		//alert("La dirección de email no es válida");
		return false;
	}
	if (str.indexOf(at,(lat+1))!=-1){
		//alert("La dirección de email no es válida");
		return false;
	}
	if (str.substring(lat-1,lat)==dot || str.substring(lat+1,lat+2)==dot){
		//alert("La dirección de email no es válida");
		return false;
	}
	if (str.indexOf(dot,(lat+2))==-1){
		//alert("La dirección de email no es válida");
		return false;
	}
	if (str.indexOf(" ")!=-1){
		//alert("La dirección de email no es válida");
		return false;
	}
	return true
}




/* CODIGO PARA PLAYER - Enviar Amigo */

function enviarHandle(swf)
{
	sendEvent(swf, 'outsideevent', 1);
}

function sendEvent(swf,typ,prm)
{ 
  thisMovie(swf).sendEvent(typ,prm); 
};

function thisMovie(swf)
{
  if(navigator.appName.indexOf("Microsoft") != -1) {
    return window[swf];
  } else {
    return document[swf];
  }
};

/* /CODIGO PARA PLAYER - Enviar Amigo */



function compartir(){
	document.getElementById('compartir').style.display = "block"
}

function cerrarCaja(caja)
{
	document.getElementById(caja).style.display = "none";
}
































/* DIGGS */
function cajaDiggs(IdVideo)
{
	_idClipDigg = IdVideo;
	PedidoDiggs.startRequest();
}

var PedidoDiggs =
{
	handleSuccess:function(o)
	{
		diggHtml(o.responseText);
	},

	handleFailure:function(o)
	{
		alert("ERROR: No se pudo procesar su solicitud");
	},
	
	startRequest:function()
	{
		datos = 'idclip=' + _idClipDigg;
		YAHOO.util.Connect.asyncRequest('GET', '/diggs.php?' + datos, callbackDiggs, null);
	}
}

var callbackDiggs =
{
	success: PedidoDiggs.handleSuccess,
	failure: PedidoDiggs.handleFailure,
	scope: PedidoDiggs
}

function diggHtml(html)
{
	divDiggs = document.getElementById('cajaDiggs');
	if(divDiggs)
	{
		divDiggs.innerHTML = html;
	}
}

function popupDiggsAyuda()
{
	popup = window.open('/diggsayudapopup.php','','height=392, width=787');

	x = (document.body.clientWidth/2) - (787/2);
	y = (document.body.clientHeight/2) - (392/2);
	popup.moveTo(x,y);
}

/* /DIGGS */







/* POPUPS MODALES */
function closeModal(idModal)
{
	/* Cierra el popup */
	divModal = document.getElementById(idModal);
	divModal.style.display = 'none';
	/* /Cierra el popup */
}

function givePosition(object)
{
	var actualLeft 	= 0;
	var actualTop 	= 0;
	
	if (object.offsetParent)
	{
		actualLeft 	= object.offsetLeft;
		actualTop 	= object.offsetTop;
		
		object = object.offsetParent;
		
		while (object)
		{
			actualLeft 	+= object.offsetLeft;
			actualTop 	+= object.offsetTop;
			
			object = object.offsetParent;
		}
	}
	
	return [actualLeft, actualTop];
}

/* Enviar Recomendacion */
function popupEnviarAmigo(idclip, idtema, idcanal)
{
	renderEnviarAmigoContent(idclip, idtema, idcanal);
}

function renderEnviarAmigoContent(idclip, idtema, idcanal)
{
	var divEnviar = document.getElementById('modalRecomendar');
	divEnviar.innerHTML = '';
	
	/* Ubicacion */
	var divCajaClip = document.getElementById('muestraClip');
	position = givePosition(divCajaClip);

	divEnviar.style.top = (position[1] + 8) + 'px';
	divEnviar.style.left = (position[0] + 704) + 'px';
	
	EnviarContent.startRequest(idclip, idtema, idcanal);
	
	divEnviar.style.display = 'block';
}

var EnviarContent =
{
	handleSuccess:function(o)
	{
		RenderEnviarContent(o.responseText);
	},

	handleFailure:function(o)
	{
	},
	
	startRequest:function(idclip, idtema, idcanal)
	{
		datos = 'idclip=' + idclip + '&idtema=' + idtema + '&idcanal=' + idcanal;
		YAHOO.util.Connect.asyncRequest('POST', '/enviarcliprecomendadopopup.php', callbackEnviarContent, datos);
	}
}

var callbackEnviarContent =
{
	success: EnviarContent.handleSuccess,
	failure: EnviarContent.handleFailure,
	scope: EnviarContent
}

function sendRecomendar()
{
	/* Datos del formulario */
	idclip_data = document.getElementById('idclip').value;
	idtema_data = document.getElementById('idtema').value;
	idcanal_data = document.getElementById('idcanal').value;
	fromMail_data = document.getElementById('fromEmail').value;
	fromName_data = document.getElementById('fromName').value;
	toMail_data = document.getElementById('ERPCToEmailArea').value;
	comment_data = document.getElementById('ERPCCommentArea').value;
	
	/* Process */
	processRecomendar.startRequest(idclip_data, idtema_data, idcanal_data, fromMail_data, fromName_data, toMail_data, comment_data);
}

var processRecomendar =
{
	handleSuccess:function(o)
	{
		RenderEnviarContent(o.responseText);
	},

	handleFailure:function()
	{
	},
	
	startRequest:function(idclip, idtema, idcanal, fromMail, fromName, toMail, comment)
	{
		datos = 'idclip=' + idclip + '&idtema=' + idtema + '&idcanal=' + idcanal + '&fromEmail=' + fromMail + '&fromName=' + fromName + '&toEmail=' + toMail + '&comment=' + comment + '&validate=1';
		YAHOO.util.Connect.asyncRequest('POST', '/enviarcliprecomendadopopup.php', callbackProcessRecomendar, datos);
	}
}

var callbackProcessRecomendar =
{
	success: processRecomendar.handleSuccess,
	failure: processRecomendar.handleFailure,
	scope: processRecomendar
}

function RenderEnviarContent(html)
{
	var divEnviar = document.getElementById('modalRecomendar');
	divEnviar.innerHTML = '';
	divEnviar.innerHTML = html;
}
/* /Enviar Recomendacion */

/* Contacto */
function popupContacto()
{
	renderContactoContent();
}

function renderContactoContent()
{
	var divContacto = document.getElementById('modalContacto');
	divContacto.innerHTML = '';

	/* Ubicacion */
	/* No levanta lo del CSS
	divHeight = divContacto.style.minHeight;
	divHeight = divHeight.substring(0, (divHeight.length - 2));
	divHeight = divHeight * 1;

	divWidth = divContacto.style.width;
	divWidth = divWidth.substring(0, (divWidth.length - 2));
	divWidth = divWidth * 1;
	*/
	divHeight = 320;
	divWidth = 300;
	
	divContacto.style.top = (YAHOO.util.Dom.getDocumentScrollTop() + (YAHOO.util.Dom.getViewportHeight() / 2) - (divHeight / 2)) + 'px';
	divContacto.style.left = ((YAHOO.util.Dom.getViewportWidth() / 2) - (divWidth / 2)) + 'px';

	ContactoContent.startRequest();
	divContacto.style.display = 'block';
}

var ContactoContent =
{
	handleSuccess:function(o)
	{
		RenderContactoContent(o.responseText);
	},

	handleFailure:function(o)
	{
	},
	
	startRequest:function(idclip, idtema, idcanal)
	{
		YAHOO.util.Connect.asyncRequest('POST', '/contactopopup.php', callbackContactoContent, null);
	}
}

var callbackContactoContent =
{
	success: ContactoContent.handleSuccess,
	failure: ContactoContent.handleFailure,
	scope: ContactoContent
}

function sendContacto()
{
	/* Datos del formulario */
	fromMail_data = document.getElementById('fromEmail').value;
	fromName_data = document.getElementById('fromName').value;
	comment_data = document.getElementById('ECPCCommentArea').value;
	
	/* Process */
	processContacto.startRequest(fromMail_data, fromName_data, comment_data);
}

var processContacto =
{
	handleSuccess:function(o)
	{
		RenderContactoContent(o.responseText);
	},

	handleFailure:function()
	{
	},
	
	startRequest:function(fromMail, fromName, comment)
	{
		datos = 'fromEmail=' + fromMail + '&fromName=' + fromName + '&comment=' + comment + '&validate=1';
		YAHOO.util.Connect.asyncRequest('POST', '/contactopopup.php', callbackProcessContacto, datos);
	}
}

var callbackProcessContacto =
{
	success: processContacto.handleSuccess,
	failure: processContacto.handleFailure,
	scope: processContacto
}

function RenderContactoContent(html)
{
	var divContacto = document.getElementById('modalContacto');
	divContacto.innerHTML = '';
	divContacto.innerHTML = html;
}
/* /Contacto */

/* Mas Info */
function popupMasInfo(idclip)
{
	renderMasInfo(idclip);
}

function renderMasInfo(idclip)
{
	var divMasInfo = document.getElementById('modalMasInfo');
	divMasInfo.innerHTML = '';
	
	/* Ubicacion */
	var divCajaClip = document.getElementById('muestraClip');
	position = givePosition(divCajaClip);

	divMasInfo.style.top = (position[1] + 8) + 'px';
	divMasInfo.style.left = (position[0] + 704) + 'px';
	
	MasInfoContent.startRequest(idclip);
}

var MasInfoContent =
{
	handleSuccess:function(o)
	{
		RenderMasInfoContent(o.responseText);
	},

	handleFailure:function(o)
	{
	},
	
	startRequest:function(idclip, idtema, idcanal)
	{
		datos = 'idclip=' + idclip;
		YAHOO.util.Connect.asyncRequest('POST', '/masinfopopup.php', callbackMasInfoContent, datos);
	}
}

var callbackMasInfoContent =
{
	success: MasInfoContent.handleSuccess,
	failure: MasInfoContent.handleFailure,
	scope: MasInfoContent
}

function RenderMasInfoContent(html)
{
	if(html != "")
	{
		var divMasInfo = document.getElementById('modalMasInfo');
		divMasInfo.innerHTML = '';
		divMasInfo.innerHTML = html;
		divMasInfo.style.display = 'block';
	}
}
/* /Mas Info */

/* /POPUPS MODALES */

