$(document).ready(function(){
						   
	$("input[@id='valor_bsq']").bind("click",function(){
		$(this).attr("value", "");
	})
	$("a[@id='mp_1']").mouseover(function(){
		$(this).children("img").attr("src", "images/bot_energia2.jpg");
	});
	$("a[@id='mp_1']").mouseout(function(){
		$(this).children("img").attr("src", "images/bot_energia.jpg");
	});
	$("a[@id='mp_2']").mouseover(function(){
		$(this).children("img").attr("src", "images/bot_transporte2.jpg");
	});
	$("a[@id='mp_2']").mouseout(function(){
		$(this).children("img").attr("src", "images/bot_transporte.jpg");
	});
	$("a[@id='mp_3']").mouseover(function(){
		$(this).children("img").attr("src", "images/bot_espac2.jpg");
	});
	$("a[@id='mp_3']").mouseout(function(){
		$(this).children("img").attr("src", "images/bot_espac.jpg");
	});
	$("a[@id='mp_4']").mouseover(function(){					  
		$(this).children("img").attr("src", "images/bot_quimica2.jpg");
	});
	$("a[@id='mp_4']").mouseout(function(){
		$(this).children("img").attr("src", "images/bot_quimica.jpg");
	});
	$("a[@id='mp_1_intro']").mouseover(function(){
		$(this).children("img").attr("src", "images/bot_energia2.jpg");
	});
	$("a[@id='mp_1_intro']").mouseout(function(){
		$(this).children("img").attr("src", "images/bot_energia.jpg");
	});
	$("a[@id='mp_2_intro']").mouseover(function(){
		$(this).children("img").attr("src", "images/bot_transporte2.jpg");
	});
	$("a[@id='mp_2_intro']").mouseout(function(){
		$(this).children("img").attr("src", "images/bot_transporte.jpg");
	});
	$("a[@id='mp_3_intro']").mouseover(function(){
		$(this).children("img").attr("src", "images/bot_espac2.jpg");
	});
	$("a[@id='mp_3_intro']").mouseout(function(){
		$(this).children("img").attr("src", "images/bot_espac.jpg");
	});
	$("a[@id='mp_4_intro']").mouseover(function(){
		$(this).children("img").attr("src", "images/bot_quimica2.jpg");
	});
	$("a[@id='mp_4_intro']").mouseout(function(){
		$(this).children("img").attr("src", "images/bot_quimica.jpg");
	});
	$("a[@name='migas']").click(function(){
		migas(this.rev);
		return false;
	});
});

function migas(id){	
	$("#load").fadeOut(200,function(){
			$("#load").html("<p style='padding:20px;'><img src='images/progress.gif' alt='Cargando' /> Cargando</p>");
			$("#load").show();
		});
	var hash = "#"+id;
	hash = hash.replace(/^.*#/, '');
	// moves to a new page. 
	// pageload is called at once. 
	return false;
}

function createCookie(name,value,days) {
  if (days) {
    var date = new Date();
    date.setTime(date.getTime()+(days*24*60*60*1000));
    var expires = "; expires="+date.toGMTString();
  }
  else expires = "";
  document.cookie = name+"="+value+expires+"; path=/";
}

function readCookie(name) {
  var nameEQ = name + "=";
  var ca = document.cookie.split(';');
  for(var i=0;i < ca.length;i++) {
    var c = ca[i];
    while (c.charAt(0)==' ') c = c.substring(1,c.length);
    if (c.indexOf(nameEQ) == 0) return c.substring(nameEQ.length,c.length);
  }
  return null;
}

window.onunload = function(e) {
  //var title = getActiveStyleSheet();
  //createCookie("style", title, 365);
}

// Funciones validar formulario -----------------------------------------------
function enviadatos(){
	if(validate()){
		$.ajax({
		  type: "GET",
		  url: 'contactar.asp',
		  data: 'nombre='+$('#nombre').val()+'&apellidos=' + $('#apellidos').val()+'&email=' + $('#email').val()+'&telefono=' + $('#telefono').val()+'&comentarios=' + $('#comentarios').val(),
		  success: function(msg){
			alert( "Datos enviados: " + msg );
		  }
		});
	}
}	

function vermensaje(quien,mensaje,cssfondo,csscontenedor,ancho,alto,vel_dimension,vel_fade){
	
	$(quien).modal({
		close:false, 
		overlayId:cssfondo,
		containerId:csscontenedor, 
		onOpen: function (dialog) {
			if(alto=="auto")$("#confirmModalContainer").css("height",(alto));
			else $("#confirmModalContainer").css("height",(alto+"px"));
			$("#confirmModalContainer").css("width",(ancho+"px"));
			$("#confirmModalContainer").css("margin-left",("-"+(ancho/2)+"px"));
			dialog.overlay.fadeIn(vel_fade, function () {
				dialog.container.slideDown(vel_dimension, function () {
				  dialog.data.fadeIn(vel_dimension); // See Other Notes below regarding
										 // data display property and
										 // iframe details
				});
			});
		},
		onClose: function (dialog) {
			dialog.data.fadeOut(vel_fade, function () {
				dialog.container.slideUp(vel_dimension, function () {
					dialog.overlay.fadeOut(vel_dimension, function () {
						$.modal.close(); // must call this to have SimpleModal
						// re-insert the data correctly and
						// clean up the dialog elements
					});
				});
			});
		},
		onShow: function (dialog) {
			dialog.data.find('.message').append(mensaje);
			
	
			// if the user clicks "yes"
			dialog.data.find('.yes').click(function () {
				// call the callback
				if ($.isFunction(callback)) {
					callback.apply();
				}
				// close the dialog
				$.modal.close().fadeOut(vel_fade);
			});
			}
	});	
}

function validate2(dtype, param){
	switch(dtype){
		case "email":
			regex = /^[\w]+(\.[\w]+)*@([\w\-]+\.)+[a-zA-Z]{2,7}$/ ;
		break;
		case "letters":
			regex = /^[a-zA-Z]+$/;
		break;
		case "username":
			regex = /^[a-zA-Z]+[a-zA-Z0-9\.\_]*[a-zA-Z0-9]+$/;
		break;
		case "url":
			regex = /(ftp|http|https):\/\/(\w+:{0,1}\w*@)?(\S+)(:[0-9]+)?(\/|\/([\w#!:.?+=&%@!\-\/]))?/;
		break;
		case "digits":
			regex = /^[\d]+$/;
		break;
	}
	return regex.test(param);
}

function carganivel(valor){
	if(valor!="0"){
		$.ajax({
		  type: "GET",
		  url: 'busca_seccion.asp',
		  data: 'id_secc='+valor,
		  success: function(msg){
			if(msg!=""){
				var cadena='<label for="seccion2">Secci&oacute;n Nivel 2 <select name="seccion2" id="seccion2" class="textoform" onchange="carganivel2('+valor+',this.value);"><option value="0" selected>Escoja una seccion</option>'+msg+'</select></label>';
				$("#secc2").html(cadena);
				$("#secc3").html("");
				$("#secc4").html("");
				$("#secc5").html("");
			}else{
				$("#secc2").html("");
				$("#secc3").html("");
				$("#secc4").html("");
				$("#secc5").html("");
			}
		  }
		});	
	}
	//if(document.MainForm.Exercise.options.selectedIndex==0){
};

function carganivel2(valor1,valor2){
	if(valor2!="0"){
		$.ajax({
		  type: "GET",
		  url: 'busca_seccion.asp',
		  data: 'id_secc='+valor1+'&id_secc2='+valor2,
		  success: function(msg){
			if(msg!=""){
				var cadena='<label for="seccion3">Secci&oacute;n Nivel 3 <select name="seccion3" id="seccion3" class="textoform" onchange="carganivel3('+valor1+','+valor2+',this.value);"><option value="0" selected>Escoja una seccion</option>'+msg+'</select></label>';
				$("#secc3").html(cadena);
				$("#secc4").html("");
				$("#secc5").html("");
			}else{
				$("#secc3").html("");
				$("#secc4").html("");
				$("#secc5").html("");
			}
		  }
		});	
	}
};

function carganivel3(valor1,valor2,valor3){
	if(valor3!="0"){
		$.ajax({
		  type: "GET",
		  url: 'busca_seccion.asp',
		  data: "id_secc="+valor1+"&id_secc2="+valor2+"&id_secc3="+valor3,
		  success: function(msg){
			if(msg!=""){
				var cadena='<label for="seccion4">Secci&oacute;n Nivel 4 <select name="seccion4" id="seccion4" class="textoform"  onchange="carganivel4('+valor1+','+valor2+','+valor3+',this.value);"><option value="0" selected>Escoja una seccion</option>'+msg+'</select></label>';
				$("#secc4").html(cadena);
				$("#secc5").html("");
			}else{
				$("#secc4").html("");
				$("#secc5").html("");
			}
		  }
		});	
	}
};

function carganivel4(valor1,valor2,valor3,valor4){
	var cadena='<label for="seccion5"><input type="hidden" name="seccion5" name="seccion5" value="algo"></label>';
	$("#secc5").html(cadena);
};


function confirma(formObj) { 

    if(confirm("Va a eliminar un registro\n \n")) 
		return true;
	else
		return false;
}
