/**************************************************************
 *	PROGRAMADO POR: Javier Rico Motos 
 *	EMAIL: jrico@signo-net.com 
 *	WEB: http://www.signo-net.com 
 *	© Todos los derechos reservados 
 ***************************************************************/ 

var ESPERA_AVISOS = 5000;
var IE = document.all?true:false;

function seleccionaTodosCheckbox(cb){
	var f = document.getElementById("formDatos");
	var actual;

	for (var i = 0; i < f.elements.length; i++) {
		actual = f.elements[i];
		if(actual.type == 'checkbox'){
			if(cb.checked)
				actual.checked = true;
			else
				actual.checked = false;
		}
	}
}

function inicializaTodo(){
	//Inputs Date
	if(typeof jQuery.fn.datePicker == "function"){
		$('input.inputDate').datePicker();
	}
	//Tablas
	$('.tablaFormato tr td').hover(function(e){
		$(this).parent('tr').find('td').addClass("hover");
	},function(e){
		$(this).parent('tr').find('td').removeClass("hover");
	});
	//Avisos y errores
	/*
	setTimeout(function(){
		$('div.avisos').slideUp('slow');
		//$('div.errores').slideUp('slow');
	}, ESPERA_AVISOS);
	*/
	//Textarea autogrow
	if(typeof jQuery.fn.autogrow == "function"){
		$('.formulario textarea').autogrow({
			maxHeight: 200,
			minHeight: 80,
			lineHeight: 16
		});
	}
	if(typeof recargaListado == "object"){
		recargaListado.init();
		recargaListado.config.oncomplete = inicializaTodo;
	}
	if(typeof formularioAjax == "object"){
		formularioAjax.init();
	}
	//Menu
	efectosMenu();
	//disporama superior
	diaporamaCabecera();
	//Aviso ZuinqStudio
	avisoZuinqStudio();
}

function efectosMenu(){
	jQuery('#web #superior ul li a').hover(function(e){
		jQuery('#web #superior ul li').removeClass('sobre');
		jQuery(this)
			.parent('li')
			.addClass('sobre')
			.animate({top:'-7px',paddingBottom:'3px'}, 120);
		
		
	}, function(e){
		jQuery('#web #superior ul li')
			.removeClass('sobre');
		if(!jQuery(this).parent('li').hasClass('actual')){
			jQuery(this).parent('li').animate({top:'-10px',paddingBottom:'6px'}, 120);
		}
	});
}

function diaporamaCabecera(){
	setInterval("diaporamaIphone('iphone')", 3000);
	setInterval("diaporamaIphone('pantalla')", 3000);
	setInterval("diaporamaIphone('windowsphone')", 3000);
	setInterval("diaporamaIphone('android')", 3000);
}

function diaporamaIphone(tipo){
	var actual = jQuery('#'+tipo+' img.actual');
	
	actual.fadeOut('slow', function(){
				jQuery(this).removeClass('actual');
			});
	if(actual.next('img').length == 0){
		jQuery('#'+tipo+' img:first').addClass('actual').fadeIn('slow');
	}else{
		actual.next('img').addClass('actual').fadeIn('slow');
	}
}

function avisoZuinqStudio(){
	jQuery('#cerrarAvisoZuinqStudio')
		.css({cursor: 'pointer', textDecoration: 'underline'})
		.hover(function(){
			jQuery(this).css({textDecoration:'none'});
		}, function(){
			jQuery(this).css({textDecoration:'underline'});
		})
		.click(function(e){
			jQuery('#avisoZuinqStudio').fadeOut();
			cookies.setCookie('avisoZuinq', 'hide');
		});
	jQuery('#avisoZuinqStudio').hide();
	//Miramos la cookie
	var cookie = cookies.getCookie('avisoZuinq');
	if(cookie == null){
		jQuery('#avisoZuinqStudio').fadeIn();
	}
}

$(function(){
	inicializaTodo();
});



var cookies = {
	setCookie : function(name, value, seconds) {
 
		if (typeof(seconds) != 'undefined') {
			var date = new Date();
			date.setTime(date.getTime() + (seconds*1000));
			var expires = "; expires=" + date.toGMTString();
		}
		else {
			var expires = "";
		}
 
		document.cookie = name+"="+value+expires+"; path=/";
	},
 
	getCookie : function(name) {
 
		name = name + "=";
		var carray = document.cookie.split(';');
 
		for(var i=0;i < carray.length;i++) {
			var c = carray[i];
			while (c.charAt(0)==' ') c = c.substring(1,c.length);
			if (c.indexOf(name) == 0) return c.substring(name.length,c.length);
		}
 
		return null;
	},
 
	deleteCookie : function (name) {
		this.setCookie(name, "", -1);
	}
 
};

