

function closeSelect(){
	$("#searchSelect").css({'visibility': 'hidden'});
}

function checkCloseSelect(){
	if ($("#searchSelect").css('visibility') == 'visible'){
	 	closeSelect();
	}
}

function openSelect(){
	if ($("#searchSelect").css('visibility') == 'visible'){
		closeSelect();
		$("body").unbind("click");
	} else {
		var top = $("#selectField").offset().top+21-$("body").offset().top;
		var left = $("#selectField").offset().left;
		var w = $("#selectField").width()+10;
		$("#searchSelect").css({'width': w, 'left': left, 'top': top, 'visibility': 'visible'});
		$('body').bind('mouseup', function() {
			checkCloseSelect();
		});
	}
}

function makeSelection(v){
	$("#selectField").val(v);
	$("#searchSelect").css({'visibility': 'hidden'});
}

function showEventDescription(event){
	if ($('#' + event +' .description').css('display') == 'none'){
		$('#' + event +' .description').show('fast');
	} else {
		$('#' + event +' .description').hide('fast');
	}
}

function showCategories(color, chk){
	if (chk.checked == true){
		$('#calendarEvents' + ' .' + color).show('fast');
	} else {
		$('#calendarEvents' + ' .' + color).hide('fast');
	}
}

jQuery.fn.center = function () { 
    this.css("position","absolute"); 
    this.css("top", ( $(window).height() - this.height() ) / 2+$(window).scrollTop() - 30 + "px"); 
    this.css("left", ( $(window).width() - this.width() ) / 2+$(window).scrollLeft() + "px"); 
    return this; 
} 

function showSettings(){
	document.getElementById('hiddenSettings').style.display= 'none';	
	document.getElementById('Settings').style.display= '';	
}

function hideSettings(){
	document.getElementById('hiddenSettings').style.display= '';	
	document.getElementById('Settings').style.display= 'none';	
}



function submitForm(type){

	if(type == '1'){
		$("#searchform").attr("target", "_blank");
		$("#searchform").attr("action", "http://ester-rr.nlib.ee/search*est/X");
		$("#SEARCH").removeAttr("disabled");
		$("#SEARCH").val($("#query").val());
		$("#searchscope").removeAttr("disabled");
		$("#searchscope").val('1');

		$("#SUBMIT").removeAttr("disabled");
		$("#op").attr("disabled", "disabled");
		$("#query").attr("disabled", "disabled");

		$("#type").attr("disabled", "disabled");
		$("#id").attr("disabled", "disabled");
		$("#selectField").attr("disabled", "disabled");
		$("#searchform").submit();
		$("#query").removeAttr("disabled");
		$("#selectField").removeAttr("disabled");



	}else if (type == '2'){
		$("#searchform").attr("target", "_blank");
		$("#searchform").attr("action", "http://ise.elnet.ee/search*est/X");
		$("#SEARCH").removeAttr("disabled");
		$("#SEARCH").val($("#query").val());
		$("#searchscope").removeAttr("disabled");
		$("#searchscope").val('2');
		$("#SUBMIT").removeAttr("disabled");
		$("#op").attr("disabled", "disabled");
		$("#query").attr("disabled", "disabled");

		$("#type").attr("disabled", "disabled");
		$("#id").attr("disabled", "disabled");
		$("#searchform").submit();
		$("#query").removeAttr("disabled");
	}else if (type == '3'){

	window.open('http://digar.nlib.ee/digar/lihtotsing?m=s&q=' + $('#query').val());

	}else if (type == '4'){
		$("#searchform").attr("action", "index.php");
		$("#searchform").removeAttr("target");
		$("#op").removeAttr("disabled");
		$("#type").removeAttr("disabled");
		$("#query").removeAttr("disabled");
		$("id").removeAttr("disabled");
		$("#op").val('search');
		$("#type").val('nonews');
		$("#SEARCH").attr("disabled", "disabled");
		$("#searchscope").attr("disabled", "disabled");
		$("#SUBMIT").attr("disabled", "disabled");
		$("#searchform").submit();
	}else if (type == '5'){
		$("#searchform").attr("action", "index.php");
		$("#searchform").removeAttr("target");
		$("#op").removeAttr("disabled");
		$("#type").removeAttr("disabled");
		$("#query").removeAttr("disabled");

		$("#op").val('news_search');
		$("#id").attr("disabled", "disabled");
		$("#SEARCH").attr("disabled", "disabled");
		$("#searchscope").attr("disabled", "disabled");
		$("#SUBMIT").attr("disabled", "disabled");
		$("#searchform").submit();
	}else if (type == '6'){
		$("#searchform").attr("action", "index.php");
		$("#searchform").removeAttr("target");
		$("#op").val('search_person');
		$("#type").val('search');
		$("#id").val('10634');
		$("#SEARCH").attr("disabled", "disabled");
		$("#searchscope").attr("disabled", "disabled");
		$("#SUBMIT").attr("disabled", "disabled");
		$("#searchform").submit();
	}
}
function submitenter()
{
var keycode;
if (window.event) keycode = window.event.keyCode;
else if (e) keycode = e.which;
else return true;

if (keycode == 13)
   {
   myfield.form.submit();
   return false;
   }
else
   return true;
}




jQuery.preloadImages = function()
{
	for(var i = 0; i<arguments.length; i++)
	{
		jQuery("<img>").attr("src", arguments[i]);
	}
}

$(function() {
	// set up rollover
	$("img.rollover").hover(
		function()
		{
			this.src = this.src.replace("_off","_on");
		},
		function()
		{
			this.src = this.src.replace("_on","_off");
		}
	);
});

function show_shop_div(value){

// Value = 1 person
// Value = 2 company 
// Value = 3 Receiver and payer are different
	if(value == 1){
		$("#client_person").show()
		$("#client_person :input").removeAttr('disabled');

		$("#client_company").hide()
		$("#client_company :input").attr("disabled", true);
	}
	if(value == 2){
		$("#client_person").hide()
		$("#client_person :input").attr("disabled", true);

		$("#client_company").show()
		$("#client_company :input").removeAttr('disabled');
	}
	if(value == 3){

			$("#ocompany").removeAttr('checked');
		if($('#operson:checked').val()!= null) {
			$("#other_person").show()
			$("#other_person :input").removeAttr('disabled');

			$("#other_company").hide()
			$("#other_company :input").attr("disabled", true);
		}else{

			$("#other_person").hide()
			$("#other_person :input").attr("disabled", true);
			$("#other_company").hide()
			$("#other_company :input").attr("disabled", true);
		}
	}
	if(value == 4){
			$("#operson").removeAttr('checked');
		if($('#ocompany:checked').val()!= null) {
			$("#other_company").show()
			$("#other_company :input").removeAttr('disabled');

			$("#other_person").hide()
			$("#other_person :input").attr("disabled", true);
		}else{
			$("#other_company").hide()
			$("#other_company :input").attr("disabled", true);
			$("#other_person").hide()
			$("#other_person :input").attr("disabled", true);
		}
	}

}

function validate(form,value){

$("#cart_info #op").val(value);
$("#cart_info").submit();

}

