/**
 * Funcion para seleccionar el lugar de busqueda del buscador
 * de Google
 */
function changeSearcher(){
	if (document.getElementById("cse-search-box").donde[0].checked == true) {
		document.getElementById("cse-search-box").cx.value = "013833308591244027556:caerrfigtbm";
	}else if (document.getElementById("cse-search-box").donde[1].checked == true) {
		document.getElementById("cse-search-box").cx.value = "004836577997235532510:tilyuy_zz2a";
	}
}

/**
 * Funcion para seleccionar el lugar de busqueda del buscador del error
 * de Google
 */
function changeSearcherError(){
	if (document.getElementById("cse-search-box-error").donde[0].checked == true) {
		document.getElementById("cse-search-box-error").cx.value = "013833308591244027556:caerrfigtbm";
	}else if (document.getElementById("cse-search-box-error").donde[1].checked == true) {
		document.getElementById("cse-search-box-error").cx.value = "004836577997235532510:tilyuy_zz2a";
	}
}

// Variable para el submenu, guardamos el identificador del submenu a mostrar
var subMenuSectionId = null;
// Variable para guardar el id que actualmente esta pintado de azul
var paintedSectionId = null;


/**
 * Funcion para mostrar el submenu de una pestana del menu
 */
function showSubMenu(sectionId){
	if(sectionId!=undefined){
		subMenuSectionId = sectionId;
	}
	document.getElementById('subm_'+subMenuSectionId).style.display='block';
	document.getElementById('submenu_'+subMenuSectionId).style.display='block';
	if(subMenuSectionId==paintedSectionId){
		showBlue(subMenuSectionId,true);
	}else{
		showBlue(subMenuSectionId);
	}
}
 
/**
 * Funcion para esconder el submenu de una pestana del menu
 */
function hideSubMenu(sectionId){
	if(sectionId!=undefined){
		subMenuSectionId = sectionId;
	}
	document.getElementById('subm_'+subMenuSectionId).style.display='none';
	document.getElementById('submenu_'+subMenuSectionId).style.display='none';
	if(subMenuSectionId!=paintedSectionId){
		showBlack(subMenuSectionId);
	}
}

/**
 * Funcion para colorear la pestana por la que pasamos
 */
function showBlue(sectionId,noRepaint){
	document.getElementById('opt_' + sectionId).className = 'azul';
	if((paintedSectionId!='')&&(paintedSectionId!=null)&&(noRepaint!=true)){
		showBlack(paintedSectionId,true);
	}
}

/**
 * Funcion para pintar de negro la pestana por la que hemos salido
 */
function showBlack(sectionId,noRepaint){
	document.getElementById('opt_' + sectionId).className = '';
	if((paintedSectionId!='')&&(paintedSectionId!=null)&&(noRepaint!=true)){
		showBlue(paintedSectionId,true);
	}
}

function login(usuario,clave){
	$.login(usuario,clave);
}

$(document).ready(function () {

	$(document).pngFix(); 

	$('div.filtros input:radio').click( function() { $(this).parents('form').submit(); });
		
	$.channel = function(){
		var value = $.cookie($ck.user).split('#')[0]+'#'+$.cookie($ck.user).split('#')[1]+'#';
		if($.cookie($ck.user).split('#')[2]=="0"){
			$.cookie($ck.user, value+'1', { path: '/', expires: 31536000 });
		}else{
			$.cookie($ck.user, value+'0', { path: '/', expires: 31536000 });
		}
		return true;
	}

});

$.login = function(usuario,clave){
	$.ajax({
        url: '/user/login.action',
        data: 'user=' + usuario + '&password=' + clave,
        cache: false,
        async: true,
        dataType: 'script',
        global: true,
        ifModified: false,
        type: 'GET'
	});				
}

/**
 * Funcion para mostrar los eventos del canal seleccionado en el modulo de tvlisting
 */
$.changeDialHome = function(dialId, divId, sectionModuleId){
	$.ajax({
        url: '/modules/tvlistingAjax.action',
        data: 'dialId=' + dialId + '&sectionModuleId=' + sectionModuleId,
        cache: true,
        async: true,
        dataType: 'html',
        global: true,
        ifModified: false,
        success: function(d){
        	$('#'+divId).html(d)
	    },
        type: 'GET'
	});	
}

/**
 * Funcion para mostrar los eventos del canal seleccionado en el modulo de tvlisting
 */
$.changeDial = function(dialId, divId, section, sectionModuleId){
	$.ajax({
        url: '/modules/tvlistingAjax.action',
        data: 'dialId=' + dialId + '&section=' + section + '&sectionModuleId=' + sectionModuleId,
        cache: true,
        async: true,
        dataType: 'html',
        global: true,
        ifModified: false,
        success: function(d){
        	$('#'+divId).html(d)
	    },
        type: 'GET'
	});	
}

/**
 * Funcion para mostrar los eventos del canal a la hora seleccionada
 */
$.changeHourEvent = function(hour, eventId, divId){
	$.ajax({
        url: '/epg/eventsByChannel.action',
        data: 'id=' + eventId + '&hour=' + hour,
        cache: true,
        async: true,
        dataType: 'html',
        global: true,
        ifModified: false,
        success: function(d){
        	$('#'+divId).html(d)
	    },
        type: 'GET'
	});
}