
/**
* Función que calcula el tamaño de la ventana
*/
window.size = function(){
   var w = 0;
   var h = 0;
   if(!window.innerWidth){ //IE
      if(!(document.documentElement.clientWidth == 0)){	//strict mode
         w = document.documentElement.clientWidth;
         h = document.documentElement.clientHeight;
      }else{ //quirks mode
         w = document.body.clientWidth;
         h = document.body.clientHeight;
      }
   }else{ //w3c
      w = window.innerWidth;
      h = window.innerHeight;
   }
   return {width:w, height:h};
};

/**
* Función que calcula el centro de la ventana actual o de un rectángulo de las dimensiones que se le pasen, devuelve el vértice superior izquierdo
*/
window.center = function(){
   var hWnd = (arguments[0] != null) ? arguments[0] : {width:0,height:0};
   var _x = 0;
   var _y = 0;
   var offsetX = 0;
   var offsetY = 0;	  
   if(!window.pageYOffset){ //IE	     
      if(!(document.documentElement.scrollTop == 0)){  //strict mode
         offsetY = document.documentElement.scrollTop;
         offsetX = document.documentElement.scrollLeft;
      }else{	//quirks mode
         offsetY = document.body.scrollTop;
         offsetX = document.body.scrollLeft;
      }
   }else{ //w3c
      offsetX = window.pageXOffset;
      offsetY = window.pageYOffset;
   }
   _x = ((this.size().width-hWnd.width)/2)+offsetX;
   _y = ((this.size().height-hWnd.height)/2)+offsetY;
   return {x:_x, y:_y};
};

/**
* Aplicación básica: Función "mostrarCapaCentro" que centra una capa de la cual
* sabemos el tamaño en medio de la zona visible de la página
* La capa tiene que tener estilo:
* position:absolute;display:none; width: x; height: y; z-index: Por encima de todas las capas.
* La función coge como parámetro el identificador de la capa a posicionar
*/
function mostrarCapaCentro(capaId){
	var miCapa = document.getElementById(capaId);
	if(miCapa){
		var capaW = miCapa.style.width;
		var capaH = miCapa.style.height;
		var punto = window.center({width:capaW, height:capaH});
		miCapa.style.top = punto.y + "px";
		miCapa.style.left = punto.x + "px";
		miCapa.style.display = "block";
	}
}


function loadScript(url, callback){
	var head = document.getElementsByTagName("head")[0];
	var script = document.createElement("script");
	var done = false;
	script.src = url;
	// Attach handlers for all browsers 
	script.onload = script.onreadystatechange = function(){ 
		if( !done && ( !this.readyState || this.readyState == "loaded" || this.readyState == "complete") ){ 
			done = true; 
			// Continue your code 
			callback(); 
			// Handle memory leak in IE 
			script.onload = script.onreadystatechange = null; 
			head.removeChild(script); 
		} 
	}; 
	head.appendChild(script); 
}
	
function getFileContent(f_path, f_type, f_data, f_async, secure_id){
	jQuery.ajax({
		url: f_path,
		type: f_type,
		data: f_data,
		async: f_async,
		dataType: "html",
		success: function(data) {
			$('#actions_result_' + secure_id).html(data);
		}
		/*,
		error: function(data) {
			$('#actions_result_' + secure_id).html(data);
		},
		complete: function(data) {
			$('#actions_result_' + secure_id).html(data);
		}*/
	});
}

function isMobileUser(){
  return (/iphone|ipod|ipad|android|blackberry|mini|windows\sce|palm/i.test(navigator.userAgent.toLowerCase()));  
}

function isAppleMobileDevice(){
	var iPhone = navigator.userAgent.indexOf('iPhone');
	var iPod = navigator.userAgent.indexOf('iPod');
	var iPad = navigator.userAgent.indexOf('iPad');
	return (iPhone != -1 || iPod != -1 || iPad != -1);
}

// String Aux Functions

function ucWords(string){
	var arrayWords;
	var returnString = "";
	var len;
	arrayWords = string.split(" ");
	len = arrayWords.length;
	for(i=0;i<len;i++){
		returnString = returnString + ucFirst(arrayWords[i]) + ((i != (len-1)) ? " " : "");
	}
	return returnString;
}

function ucFirst(string){
	return string.substr(0, 1).toUpperCase() + string.substr(1, string.length).toLowerCase();
}

// Search Videos
					
function searchNow(strMainLink, enabledGoogleCSE){
	var videosearch = document.getElementById('videosearch').value.replace(/\s+/gi, '+').toLowerCase();
	if(trim(videosearch) != 'busca+un+video...' && trim(videosearch) != ''){
		location.href = 'http://www.latv.com/' + strMainLink + (enabledGoogleCSE ? '' : '-') + videosearch;
	}else{
		alert('Debes ingresar un termino a buscar!');
	}
	return false;			
}


/** Added for fix bug menu in IE 7 - WC - 12/11/2009 **/

if(!Array.indexOf){
	Array.prototype.indexOf = function(obj){
		for(var i=0; i<this.length; i++){
			if(this[i]==obj){
				return i;
			}
		}
		return -1;
	}
}

Array.prototype.unique = function(b) {
	var a = [], i, l = this.length;
	for( i=0; i<l; i++ ){
		if( a.indexOf( this[i], 0, b ) < 0 ){ 
			a.push( this[i] );
		}
	}	
	return a;
};

/**  End Added for fix bug menu in IE 7 **/

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];}
}

var bo_ns_id = 0;

function startIeFix()
{  
	if(isIE())
	{    
		document.write('<div id="bo_ns_id_' + bo_ns_id + '"><!-- ');  
	}
}

function endIeFix()
{  
	if(isIE())
	{    
		document.write('</div>');    
		var theObject = document.getElementById("bo_ns_id_" + bo_ns_id++);
		var theCode = theObject.innerHTML; //.toLowerCase();
		theCode = theCode.substring(4 ,9+theCode.indexOf("</object>"));
		document.write(theCode);  
	}
}

//Polls
var PollID;
var Home;

function validatePoll(form) {
	for (i=0;i<form.option.length;i++)
	{
		if(form.option[i].checked == true)
		 	return form.option[i].value;
	}
	alert("Must select an option !");
	return false;
}

function sendPollRequest(id, type, home, poll)
{

	if(home=='yes'){
		Home = true;
	}else{
		Home = false
	}	
	PollID = poll;

	var option=false;
	if(id==-1)
	{
		alert("You have already voted !");
		return false;
	}
	if(type=='vote'){
		if(Home==true){
			if(!(option=validatePoll(document.HomePoll)))		
			return false;	
		}else{
			if(!(option=validateInnerPoll(PollID)))		
			return false;
		}
	}
			
	url = 'http://www.latv.com/getpoll.asp?pollID=' + id + '&option=' + option + '&type=' + type + '&home=' + home;
	setPollContent('<center><img src="http://www.latv.com/img/siteElements/loadingLATV.gif" /></center>',PollID);
	makeRequest(url , receivePollRequest, false);
}


function receivePollRequest(aXmlRequest)
{
	if(isCompleted(aXmlRequest))
	{
		setPollContent(getResponse(aXmlRequest));
		aXmlRequest = null;
	}
}

function setPollContent(content)
{
	if(Home==true){
		var oDiv = document.getElementById('pollDIV');
	}else{
		var oDiv = document.getElementById('pollDIV_' + PollID);	
	}
	oDiv.innerHTML = content;
}


function isIE()
{	// only for Win IE 6+  
	// But not in Windows 98, Me, NT 4.0, 2000  
	var strBrwsr = navigator.userAgent.toLowerCase();  
	if(strBrwsr.indexOf("msie") > -1 && strBrwsr.indexOf("mac") < 0)
	{    
		if(parseInt(strBrwsr.charAt(strBrwsr.indexOf("msie")+5)) < 6)
		{      
			return false;    
		}    

		if(	strBrwsr.indexOf("win98") > -1 ||       
			strBrwsr.indexOf("win 9x 4.90") > -1 ||       
			strBrwsr.indexOf("winnt4.0") > -1 ||       
			strBrwsr.indexOf("windows nt 5.0") > -1)    
		{      
			return false;    
		}    
		
		return true;  
	}
	else
	{    
		return false;  
	}
}

function popup(url, width, height)
{
	 window.open(url,'','toolbar=no,location=no,directories=no,status=yes,menubar=no,scrollbars=yes,resizable=yes,width='+width+',height='+height);
}

function popupNoScroll(url, width, height)
{
	 window.open(url,'','toolbar=no,location=no,directories=no,status=yes,menubar=no,scrollbars=no,resizable=yes,width='+width+',height='+height);
}

function openPhotoMax(photo)
{
	var width = screen.availWidth;
	var height = screen.availHeight;

	window.open(
'photomax.asp?p=' + photo,
'',
'toolbar=0,location=0,directories=0,status=0,menubar=0,resizable=1,scrollbars=1,x=0,y=0,width=' + width + ',height=' + height);
}

function contactForm(address, customurl)
{
	if(customurl)
		popupNoScroll(customurl + 'contact-form/contact-form.asp?ad=' + address, 400, 500);
	else
		popupNoScroll('contact-form/contact-form.asp?ad=' + address, 400, 500);
}

function contactFormJob(address, customurl)
{
	if(customurl)
		popupNoScroll(customurl + 'contact-form/contact-form-job.asp?ad=' + address, 400, 500);
	else
		popupNoScroll('contact-form/contact-form-job.asp?ad=' + address, 400, 500);
}

function updateDaysSelect(day, month, year)
{
	var aMonths = new Array(31, 28, 31, 30, 31, 30, 31, 31, 30, 31, 30, 31);
	if(isLeapYear(year.value))
		aMonths[1] = 29;

	var iDaySelected = parseInt(day.value);
	var iMonthSelected = parseInt(month.value);

	if(iMonthSelected)
	{
		while(day.length)
			day.remove(0);

		var tmp = document.createElement('option');

		tmp.value = '';
		tmp.text = '---';

		try
		{
			day.add(tmp, null);
		}
		catch(e)
		{
			day.add(tmp);
		}

		for(var i = 1; i <= aMonths[iMonthSelected - 1]; i++)
		{
			tmp = document.createElement('option');

			tmp.value = i;
			tmp.text = i;

			try
			{
				day.add(tmp, null);
			}
			catch(e)
			{
				day.add(tmp);
			}
		}

		if(iDaySelected && iDaySelected <= aMonths[iMonthSelected - 1])
			day.value = iDaySelected;
		else
			day.value = '';

	}
}

function isLeapYear(year)
{
	year = parseInt(year);

	if(year % 4 == 0)
	{
		if(year % 100 != 0)
			return true;
		else
		{
			if(year % 400 == 0)
				return true;
			else
				return false;
		}
	}

	return false;
}

function CreateElement(obj, code)
{
	var d = document.getElementById(obj);
	d.innerHTML = code;
}

function enableButton(obj, but){
	but.disabled = !obj.checked;
}

function isEmpty(obj) {
    if (typeof obj == 'undefined' || obj === null || obj === '') return true;
    if (typeof obj == 'number' && isNaN(obj)) return true;
    if (obj instanceof Date && isNaN(Number(obj))) return true;
    return false;
}
// register check username

function checkUsername(){
	var oUsername = document.getElementById('username');
	var sUsername = oUsername.value;

	if(sUsername){
		setAnswer('load');
		makeRequest('collectFormData.asp?check=' + escape(sUsername), receiveUsername, true);
	}else{
		alert('You must write the username you want first');
		oUsername.focus();
	}
}

function receiveUsername(aXmlRequest){
	if(isCompleted(aXmlRequest))
		setAnswer(getResponse(aXmlRequest));
}

function setAnswer(sValue){
	if(sValue.toLowerCase() == 'ok')
		sValue = '<img alt="You can use this username" id="availableImg" class="img_available" src="img/siteElements/check_ok.gif" style="border:0px;"/>';
	else if(sValue.toLowerCase() == 'load')
		sValue = '<img alt="Checking availability..." id="availableImg" class="img_checking" src="img/siteElements/check_load.gif" style="border:0px;"/>';
	else
		sValue = '<img alt="This username has been already choosen" id="availableImg" class="img_error" src="img/siteElements/check_error.gif" style="border:0px;"/>';

	document.getElementById('availability').innerHTML = sValue;
}
				
function availableUsername(isUpdate) {		
	if(isUpdate == 'False'){
		availableText = document.getElementById('availability').innerHTML;				
		if(availableText == ''){
			alert('Debes verificar si el username elegido no esta en uso.');
			return false;
		}else{
			availableImg = document.getElementById('availableImg').className;
			if(availableImg == 'img_error'){
				alert('Debes elegir otro username.');
				return false;
			}
		}
	}			
	return true;
}
				
//	search controls

function checkSearchValue(){
	searchValue = document.getElementById('search').value;
	if(trim(searchValue) == ''){
		alert("Debes ingresar un termino a buscar !");
		return false;
	}
	return true;
}



// some controls and strings functions

		function validateEmail(val){
			var reg=/(^[a-zA-Z0-9._-]{1,30})@([a-zA-Z0-9.-]{1,30}$)/;
			if(reg.test(val)){
				return true;
			}else{
				return false;
			}
		}
		
		function validateName(val){
			if(val == '' || !val){
				return false;
			}else{
				return true;
			}
		}
		
		function validateComment(comment, enabledNull, minLong, maxLong){
			var cantCar = comment.length;
			if(comment == "" || comment == "Dejanos tu comentario!"){
				if(enabledNull){
					return true;
				}else{
					return false;
				}
			}else{
				if(cantCar >= minLong && cantCar <= maxLong) return true;
				else return false;
			}
		}
			
		function trim(s){
			s = s.replace(/\s+/gi,' '); //sacar espacios repetidos dejando solo uno
			s = s.replace(/^\s+|\s+$/gi,''); //sacar espacios blanco principio y final				
			return s;
		}
		
		
// share functions


	
	function shareContent(){
		var nameTo = trim(document.getElementById("nameTo").value);
		var nameFrom = trim(document.getElementById("nameFrom").value);
		var emailTo = trim(document.getElementById("emailTo").value);
		var message =  trim(document.getElementById("message").value);
		var linkToShare = document.getElementById("linkToShare").innerHTML;		// this value is taking from span id="linkToShare" in share.asp
		
		if(!validateName(nameFrom)){
			alert('Debes ingresar tu nombre.');
			document.getElementById('shareDataForm').nameFrom.focus();
			return false;
		}
		
		if(!validateName(nameTo)){
			alert('Debes ingresar el nombre del destino.');
			document.getElementById('shareDataForm').nameTo.focus();
			return false;
		}
		
		if(!validateEmail(emailTo)){
			alert('Debes ingresar el email del destino.');
			document.getElementById('shareDataForm').emailTo.focus();
			return false;
		}
		
		/*
		if(!validateComment(message, false, 10, 1000)){
			alert('Debes ingresar tu comentario; al menos ' + 10 + ' caracteres; y como maximo  ' + 1000 + '.');
			document.getElementById('shareDataForm').message.focus();
			return false;
		}
		*/
						
		var urlToLoad = 'http://www.latv.com/actions/shares_ops.php?nameTo=' + escape(nameTo) + '&emailTo=' + emailTo + '&nameFrom=' + escape(nameFrom) + '&message=' + escape(message) + '&linkToShare=' + escape(linkToShare);
		
		//alert(urlToLoad);
		
		loadcontent(urlToLoad, 'resultShare');
		document.getElementById('shareForm').style.display = 'none';
		return false;
	}
	
	
	
	
	//		comments functions
	
	function setText(obj, opt, defaultTxt){
		if(opt){
			if(trim(obj.value) == defaultTxt){
				obj.value = '';
			}
		}else{
			if(trim(obj.value) == ''){
				obj.value = defaultTxt;
			}
		}
	}
	
	
	function commentVote(voteType, commentID){
		containerResult = 'voteContainer' + voteType + '_' + commentID;
		loadcontent(WEBSITE_URL + '/actions/comments_ops.php?action=vote&voteType=' + voteType + '&commentID=' + commentID, containerResult);
		return false;
	}
			
		
	function responseDivEnabled(val){
		if(val){
			document.getElementById('responseMeDiv').style.visibility = 'visible';
		}else{
			document.getElementById('responseMeDiv').style.visibility = 'hidden';
		}
	}
	
	function setResponseTo(commentID, commentName, commentContent){
		document.getElementById('responseToComment').value = commentID;
		document.getElementById('commentDataForm').subjectsComment[1].checked = true;
		responseDivEnabled(false);
		document.getElementById('responseMessage').style.display = 'block';
		document.getElementById('responseMessage').style.visibility = 'visible';
		
		document.getElementById('responseMessageNameTo').innerHTML = commentName;
		document.getElementById('responseMessageComment').innerHTML = commentContent;
		
		allocatePage('responseMessage', 'onclick');
		document.getElementById('commentDataForm').commentFrom.focus();
		return false;
	}
		
	function allocatePage(divToAllocate, event){
		var Xnew;
		var Ynew;
		
		if(event == 'onclick'){
			if (document.getElementById) { 
				Xnew = document.getElementById(divToAllocate).offsetLeft;
				Ynew = document.getElementById(divToAllocate).offsetTop;
			} else if (document.all) {
				Xnew = document.all.getElementById(divToAllocate).offsetLeft;
				Ynew = document.all.getElementById(divToAllocate).offsetTop;
			} else if (document.layers) { 
				Xnew = document.layers[divToAllocate].pageX;
				Ynew = document.layers[divToAllocate].pageY;
			} else 
				alert('Su navegador no está soportado.');
		}else{
			//event = 'onload'
			var divToAllocateCoords = document.getElementById(divToAllocate);
			Xnew = getDimensions(divToAllocateCoords).x;
			Ynew = getDimensions(divToAllocateCoords).y;
		}
		/*
		var yTmp = -2;
		while (yTmp < Ynew){
			setTimeout("window.scrollTo(" + Xnew + ", " + yTmp + ")", 100);
		}
		*/
		window.scrollTo(Xnew, Ynew-2);		// padding-top:2px;
	}
	
	function viewResponses(opt, commentID){
		if(opt){
			document.getElementById('responseHide_' + commentID).style.visibility = 'visible';
			document.getElementById('responseHide_' + commentID).style.display = 'block';
			
			document.getElementById('responseView_' + commentID).style.visibility = 'hidden';
			document.getElementById('responseView_' + commentID).style.display = 'none';
			
			document.getElementById('responsesTable_' + commentID).style.visibility = 'visible';
			document.getElementById('responsesTable_' + commentID).style.display = 'block';
			
		}else{
			document.getElementById('responseView_' + commentID).style.visibility = 'visible';
			document.getElementById('responseView_' + commentID).style.display = 'block';
			
			document.getElementById('responseHide_' + commentID).style.visibility = 'hidden';
			document.getElementById('responseHide_' + commentID).style.display = 'none';
			
			document.getElementById('responsesTable_' + commentID).style.visibility = 'hidden';
			document.getElementById('responsesTable_' + commentID).style.display = 'none';
		}
	}
	
	function viewComments(opt){
		document.getElementById('commentsHide').style.visibility = opt ? 'visible' : 'hidden';
		document.getElementById('commentsHide').style.display = opt ? 'block' : 'none';
		
		document.getElementById('commentsView').style.visibility = opt ? 'hidden' : 'visible';
		document.getElementById('commentsView').style.display = opt ? 'none' : 'block';
		
		document.getElementById('commentsContainer').style.visibility = opt ? 'visible' : 'hidden';
		document.getElementById('commentsContainer').style.display = opt ? 'block' : 'none';
		
		//mostrar / ocultar div paginador
		document.getElementById('commentsPaginator').style.visibility = opt ? 'visible' : 'hidden';
		document.getElementById('commentsPaginator').style.display = opt ? 'block' : 'none';
	}
	
	
	function saveComment(){
		var commentFrom = trim(document.getElementById("commentFrom").value);
		var commentEmail = trim(document.getElementById("commentEmail").value);
		var comment = trim(document.getElementById("comment").value);
		
		var captcha = trim(document.getElementById("captcha").value);
		var captchaQuestion = trim(document.getElementById("captchaQuestion").value);
		var captchaSecureData = trim(document.getElementById("captchaSecureData").value);
		
		var responseMe = 0;	//	aviso de respuesta OFF
		var commentInFacebook = 0; // NO enviar comentario a facebook
		
		var element_TYPE = trim(document.getElementById("element_TYPE").value);	// artist, show, foto
		var element_ID = trim(document.getElementById("element_ID").value);	// id del artist, show, foto
		var element_NAME = trim(document.getElementById("element_NAME").value);	// nombre/title del artist, show, foto
		
		var MailTo = trim(document.getElementById("MailTo").value);
		var MailSubject = trim(document.getElementById("MailSubject").value);
		
		var responseToComment = document.getElementById("responseToComment").value;
		
		for (i=0;i<document.getElementById('commentDataForm').subjectsComment.length;i++) {
			if (document.getElementById('commentDataForm').subjectsComment[i].checked) {
				subjectComment = document.getElementById('commentDataForm').subjectsComment[i].value;
			}
		}
		
		if(responseToComment > 0){
			subjectComment = "response";
		}
		
		if(subjectComment == 'comment'){
			if (document.getElementById('commentDataForm').responseMe.checked) {
				responseMe = 1;	//	aviso de respuesta ON
			}
		}

		if (document.getElementById('commentDataForm').commentInFacebook.value == 1) {
			commentInFacebook = 1;	//	copiar el comentario en facebook
		}
			
		if(!validateName(commentFrom)){
			alert('Debes ingresar tu nombre.');
			document.getElementById('commentDataForm').commentFrom.focus();
			return false;
		}
		
		if(!validateEmail(commentEmail)){
			alert('Debes ingresar tu email.');
			document.getElementById('commentDataForm').commentEmail.focus();
			return false;
		}
		
		if(!validateComment(comment, false, 10, 1000)){
			alert('Debes ingresar tu comentario; al menos ' + 10 + ' caracteres; y como maximo  ' + 1000 + '.');
			document.getElementById('commentDataForm').comment.focus();
			return false;
		}
		
		if(captchaQuestion == '' || !captchaQuestion){
			alert('Debes contestar la pregunta.');
			document.getElementById('commentDataForm').captchaQuestion.focus();
			return false;
		}
		
		var urlToLoad = 'http://www.latv.com/actions/comments_ops.php?submit=true';
		
		urlToLoad = addParamether(urlToLoad, 'commentFrom', escape(commentFrom));
		urlToLoad = addParamether(urlToLoad, 'commentEmail', commentEmail);
		urlToLoad = addParamether(urlToLoad, 'comment', escape(comment));
		urlToLoad = addParamether(urlToLoad, 'subjectComment', subjectComment);
		urlToLoad = addParamether(urlToLoad, 'responseMe', responseMe);
		urlToLoad = addParamether(urlToLoad, 'element_TYPE', element_TYPE);
		urlToLoad = addParamether(urlToLoad, 'element_ID', element_ID);
		urlToLoad = addParamether(urlToLoad, 'element_NAME', element_NAME);
		urlToLoad = addParamether(urlToLoad, 'MailTo', MailTo);
		urlToLoad = addParamether(urlToLoad, 'MailSubject', MailSubject);
		urlToLoad = addParamether(urlToLoad, 'responseToComment', responseToComment);
		urlToLoad = addParamether(urlToLoad, 'captchaQuestion', captchaQuestion);
		urlToLoad = addParamether(urlToLoad, 'captchaSecureData', captchaSecureData);
		
		//alert(urlToLoad);
		if(captcha != ''){
			alert('ERROR. Algo raro hay con tu envio. Bye!');
		}else{
			loadcontent(urlToLoad, 'resultComment');
			document.getElementById('commentForm').style.display = 'none';
			document.getElementById('resultComment').style.display = 'block';
						
			if(commentInFacebook){
			
				f_message = comment;
				f_message_title = document.title;
				f_message_link = document.getElementById("f_message_link").value;
				f_message_description = document.getElementById("f_message_description").value;
				f_message_image_url = document.getElementById("f_message_image_url").value;
				f_message_image_href = document.getElementById("f_message_image_href").value;
				
				setCommentInFacebook(f_message, f_message_title, f_message_link, f_message_description, f_message_image_url, f_message_image_href);			
			}
			
		}
		
		// clean form
		document.getElementById("commentFrom").value = '';	
		document.getElementById("commentEmail").value = '';
		document.getElementById("comment").value = 'Dejanos tu comentario!';
		document.getElementById("captchaQuestion").value = '';
		
		return false;
	}
	
	function addParamether(urlToAdd, paramNameToAdd, paramValueToAdd){
		var isFirstParam = true;
		var newURL = '';
		
		for(i=0;i<urlToAdd.length;i++){
			if(urlToAdd.charAt(i)=="?") 
				isFirstParam = false;
		}
		
		newURL = urlToAdd + ((isFirstParam) ? '?' : '&') + paramNameToAdd + '=' + paramValueToAdd;
		return newURL;
	}
	
	getDimensions = function(oElement) {
		var x, y, w, h;
		x = y = w = h = 0;
		if (document.getBoxObjectFor) { // Mozilla
			var oBox = document.getBoxObjectFor(oElement);
			x = oBox.x-1;
			w = oBox.width;
			y = oBox.y-1;
			h = oBox.height;
		}else if (oElement.getBoundingClientRect) { // IE
			var oRect = oElement.getBoundingClientRect();
			x = oRect.left-2;
			w = oElement.clientWidth;
			y = oRect.top-2;
			h = oElement.clientHeight;
		}
		return {x: x, y: y, w: w, h: h};
	}
	
	
	// shows galleries contact form validation
	
	function contactNow(){
		var nameTo = trim(document.getElementById("nameTo").value);
		var nameFrom = trim(document.getElementById("nameFrom").value);
		var emailTo = trim(document.getElementById("emailTo").value);
		var emailFrom = trim(document.getElementById("emailFrom").value);
		
		var message =  trim(document.getElementById("message").value);

		if(!validateName(nameFrom)){
			alert('Debes ingresar tu nombre.');
			document.getElementById('contactDataForm').nameFrom.focus();
			return false;
		}

		if(!validateEmail(emailFrom)){
			alert('Debes ingresar tu email.');
			document.getElementById('contactDataForm').emailFrom.focus();
			return false;
		}
		
		if(!validateComment(message, false, 10, 1000)){
			alert('Debes ingresar tu comentario; al menos ' + 10 + ' caracteres; y como maximo  ' + 1000 + '.');
			document.getElementById('contactDataForm').message.focus();
			return false;
		}						
						
		var urlToLoad = 'http://www.latv.com/actions/contacts_ops.php?nameTo=' + escape(nameTo) + '&emailTo=' + emailTo + '&nameFrom=' + escape(nameFrom) + '&emailFrom=' + emailFrom + '&message=' + escape(message);
		
		//alert(urlToLoad);	
				
		// clean form inputs for future contacts
		document.getElementById("nameTo").value = "";
		document.getElementById("nameFrom").value = "";
		document.getElementById("emailTo").value = ""
		document.getElementById("emailFrom").value = "";
		
		loadcontent(urlToLoad, 'resultContact');
		document.getElementById('showsContactForm').style.display = 'none';
		return false;
	}

	function checkFacebook(){					
		if(parseInt(document.getElementById('commentInFacebook').value)){
			document.getElementById('commentInFacebook').value = 0;
			document.getElementById('facebookButton').style.backgroundImage = 'url(img/siteElements/facebook-activate.jpg)';							
		}else{
			document.getElementById('commentInFacebook').value = 1;
			document.getElementById('facebookButton').style.backgroundImage = 'url(img/siteElements/facebook-deactivate.jpg)';
		}
		return false;
	}

	// comentar en facebook
	function setCommentInFacebook(f_message, f_message_title, f_message_link, f_message_description, f_message_image_url, f_message_image_href){
		FB.ui(
				{
					method: 'stream.publish',
					message: f_message,
					attachment: {
						name: f_message_title,
						caption: 'Checa esto en LATV',
						description: (f_message_description),
						href: f_message_link,
						media: [{ 'type': 'image', 'src': f_message_image_url, 'href': f_message_image_href }]
					},
					action_links: [{ text: 'Unetenos', href: 'http://www.facebook.com/pages/LATV/22585467017' }],
					user_message_prompt: 'Comparte el Contenido de LATV con tus Amigos!!'
				},
				function(response){
					if (response && response.post_id){
						//alert('Post was published.');
					}else{
						//alert('Post was not published.');
					}
				}
		);
	}


    function updateFBMetaInfo ( _currentURL, _title, _imageURL)    {
        metatags = document.getElementsByTagName("meta");
        for (i = 0; i < metatags.length; i++)    {
            var property = metatags[i].getAttribute("property");
            var content = metatags[i].getAttribute("content");
            if (property == "og:title" && _title)    {
                  metatags[i].setAttribute("content", _title);
            }
            if (property == "og:image" && _imageURL)    {
                  metatags[i].setAttribute("content", _imageURL);
            }
            if (property == "og:url" && _currentURL)    {
                  metatags[i].setAttribute("content", _currentURL);
            }
        }
    }


 
	// comentar en facebook
	function shareEventsInFacebook(f_message, f_message_title, f_message_link, f_message_description, f_message_image_url, f_message_image_href){
 
		FB.ui(
				{
					method: 'stream.publish',
					message: f_message,
					attachment: {
						name: f_message_title,
						caption: 'Checa esto en LATV',
						description: (f_message_description),
						href: f_message_link,
						media: [{ 'type': 'image', 'src': f_message_image_url, 'href': f_message_image_href }]
					},
					action_links: [{ text: 'Unetenos', href: 'http://www.facebook.com/pages/LATV/22585467017' }],
					user_message_prompt: 'Compartelo con tus Amigos!!'
				},
				function(response){
					if (response && response.post_id){
						//alert('Post was published.');
					}else{
						//alert('Post was not published.');
					}
				}
		);
	}

