var global_config={
	newUrlImgJoomla: "/onlyJoomla/",
	urlImgJoomla: "images/",
	tweeterUser: "toti65bis",
	tweetsCant:"10"
};

var conf =  
{  
    APIKey: '2_Y82PzwJ_chSFImHXaIDJClnLyJzmk-VFOavSsaNTzl6m901s_NNxRAS0xJ3bd3_N'  
};  

var page_data={
		errors: new Array(),
		warnings: new Array(),
		messages: new Array()
};
$(document).ready(function(){
	updateUrlJoomla();
	updateError();
	showMessages();
	updateBarraPosition();
	addEventsLogin("#barra form.login div.input");
	addEventsLogin("#topSearch form");
	addEventsLogin("#blogContent #blog #coment_form form");
	addEventsLogin("#rightHome div.search div form");
	addEventsLogin("#content #login form div.input");
	adjustGralContent();
});
function adjustGralContent(){
	if ($("#rigthContent").size()>0){
		if (($("#rigthContent").height()+230)>$("#gralContent").height()){
			$("#gralContent").css("height",$("#rigthContent").height()+230);
		}
		
	}
}

$(window).resize(function(){
	updateBarraPosition();
});

function addEventsLogin(selector){
	$(selector + " input").each(function(){
		$(this).focus(function(){
			if ($(this).attr('login')==''){
				$(selector + " input[type=text]").each(function(){
					$(this).attr('login',$(this).val());
					$(this).val('');
				})
				$(selector + " input[type=password]").each(function(){
					$(this).attr('login',$(this).val());
					$(this).val('');
				})
			}
			
			if ($(this).attr('search')==''){
				$(selector + " input").each(function(){
					$(this).attr('search',$(this).val());
					$(this).val('');
				})
			}
		});
		$(this).blur(function(){
			if ($(this).attr('login')!=''){
				values='';
				$(selector + " input").each(function(){
						values+=$.trim($(this).val());
				});
				if (values==''){
					$(selector + " input[type=text]").each(function(){
							$(this).val($(this).attr('login'));
							$(this).attr('login','');
					});
					$(selector + " input[type=password]").each(function(){
						$(this).val($(this).attr('login'));
						$(this).attr('login','');
					});
				} 
			}
			
			if ($(this).attr('search')!=''){
				values='';
				$(selector + " input").each(function(){
					values+=$.trim($(this).val());
				});
				if (values==''){
					$(selector + " input").each(function(){
						$(this).val($(this).attr('search'));
						$(this).attr('search','');
					});
				} 
			}
			
		});
	});
	
}


function updateBarraPosition(){
	$("#barra").css("left", parseInt(($(window).width()-900)/2));
	$("#barra").css("top", parseInt(($(window).height()-38)));
}
function updateError(){
	$(".error-message").each(function(){
		page_data.errors.push($(this).html());
	});
}
function showModalPopupPublish(image,title,width,height){
	$('#bannerInstitutional').css('visibility','hidden');
            $("embed").css("display","none"); 
	$( "#modalPopup" ).html("<p><img src='img/"+image+"' border='0' /></p>");
	$( "#modalPopup" ).css("padding-left","6px");
	$( "#modalPopup" ).css("padding-top","13px");
	$( "#modalPopup" ).attr("title",title);
	$( "#modalPopup" ).dialog({
		autoOpen: true,
		show: "blind",
		hide: "explode",
		modal: true,
		height: height,
		width: width,
		resizable: false,
		close: function(){
                       $("embed").css("display","block");
                       $('#bannerInstitutional').css('visibility','visible');
               
                     }

	});
	$( "#modalPopup" ).css("height",height);

	
        
}

function showModalPromotion(image,title,width,height){
	$('#bannerInstitutional').css('visibility','hidden');
	$("embed").css("display","none");
	$( "#modalPopup" ).html("");
	$( "#modalPopup" ).attr("title","");
	$(".ui-dialog-title").html("");
	$( "#modalPopup" ).html("<p><img src='/img/"+image+"' border='0' /></p>");
	$( "#modalPopup" ).css("padding-left","6px");
	$( "#modalPopup" ).css("padding-top","13px");
	$( "#modalPopup" ).attr("title",title);
	$(".ui-dialog-title").html(title);
	$( "#modalPopup" ).dialog({
	autoOpen: true,
	show: "blind",
	hide: "explode",
	modal: true,
	height: height,
	width: width,
	resizable: false,
	close: function(){
	$("embed").css("display","block");
	$('#bannerInstitutional').css('visibility','visible');
	}
	});
	$( "#modalPopup" ).css("height",height);
	} 

function showMessages(){
	if (page_data.errors.length>0){
		message="<ul>";
		for(i=0; i < page_data.errors.length; i++){
			message=message+ "<li>"+page_data.errors[i]+"</li>";
		}
		showModalPopup(message+"<ul>","Error");
	}
	if (page_data.warnings.length>0){
		message="";
		for(i=0; i < page_data.errors.length; i++){
			message=message+ page_data.warnings[i]+"<br/>";
		}
		showModalPopup(message,"Advertencia");
	}
	if (page_data.messages.length>0){
		message="";
		for(i=0; i < page_data.messages.length; i++){
			message=message+ page_data.messages[i]+"<br/>";
		}
		showModalPopup(message,"Informacion");
	}
}
function updateUrlJoomla(){
	$("img").each(function(){
		if($(this).attr("src").indexOf(global_config.urlImgJoomla)==0){
			$(this).attr("src",global_config.newUrlImgJoomla+$(this).attr("src"));
		}
	});
}
function selectRange(obj){
	$(this).select();
}
function findValue(li) {
	if( li == null ) return alert("No match!");
 
	// if coming from an AJAX call, let's use the CityId as the value
	if( !!li.extra ) var sValue = li.extra[0];
 
	// otherwise, let's just display the value in the text box
	else var sValue = li.selectValue;
 
	alert("The value you selected was: " + sValue);
}
 
function selectItem(li) {
	findValue(li);
}
 
function formatItem(row) {
	return row[0] + " (id: " + row[1] + ")";
}

var _gaq = _gaq || [];
_gaq.push(['_setAccount', 'UA-21283302-1']);
_gaq.push(['_trackPageview']);

(function() {
  var ga = document.createElement('script'); ga.type = 'text/javascript'; ga.async = true;
  ga.src = ('https:' == document.location.protocol ? 'https://ssl' : 'http://www') + '.google-analytics.com/ga.js';
  var s = document.getElementsByTagName('script')[0]; s.parentNode.insertBefore(ga, s);
})();
