﻿
$(function(){
	$("#wrapper").minmax();
	$("#wrapper").resize(function(){
		$(this).minmax();
	});
	//stripTables();
	$("span").Tooltip({delay:1000});
	//if(!jQuery.browser.msie)
		//$("#wrapper").height($("html").height());
		
		
	$(".districtSelect").ajaxSelect({
			"dest":".municipalitySelect", 
			"titles":{
				"lt":"title",
				"en":"titleEn"
				},
			"url":"view/user/templates/portlets/fetcher.vv?c=AdministrativeUnitPeer&m=listMunicipalitiesByDistrict"
	});


	$(".studyField").ajaxSelect({
			"dest":".studySubfield", 
			"titles":{
				"lt":"title",
				"en":"titleEn"
				},
			"url":"view/user/templates/portlets/fetcher.vv?c=ProgramPeer&m=listEducationSubFields"
	});

	$("#studyField").ajaxSelect({
			"dest":"#direction", 
			"titles":{
				"lt":"title",
				"en":"titleEn"
				},
			"url":"view/user/templates/portlets/fetcher.vv?c=ProgramPeer&m=listDirectionsByStudyField",
			"defaultValue" : ""
	});

	$("#studyFieldA").ajaxSelect({
			"dest":"#direction", 
			"titles":{
				"lt":"title",
				"en":"titleEn"
				},
			"url":"view/user/templates/portlets/fetcher.vv?c=ProgramPeer&m=listDirectionsByStudyField2",
			"defaultValue" : ""
	});
	

	$("#groupSelect").ajaxSelect({
			"dest":"#typeSelect", 
			"titles":{
				"lt":"title",
				"en":"titleEn"
				},
			"url":"view/user/templates/portlets/fetcher.vv?c=InstitutionPeer&m=listTypes"
	});
	
	var colleft = $("#col_left");
	var wrapper = $("#wrapper");
	var l = colleft.height()+85;
	var w = wrapper.height();
	//alert(l + ":" + w);
	if(l > w)
	{
		wrapper.height(colleft.height()+85);
		//alert(wrapper.height());
		$("#content_left_shadow").height(colleft.height()-85);
		$("#col_right").css("padding-bottom", "0px");
		$("#row_container").css("padding-bottom", "0px");
	}
	if(currentLanguage == "lt")
	{
	$('.selectable_date').calendar({
		clearText: 'Trinti',
		closeText: 'X',
		prevText: 'Prieš',
		nextText: 'Vėliau',
		currentText: 'Dabar',
		dayNames: ['S', 'P', 'A', 'T', 'K', 'Pn', 'Š'],
		monthNames: ['Sausis', 'Vasaris', 'Kovas', 'Balandis', 'Gegužė', 'Birželis', 'Liepa', 'Rugpjūtis', 'Rugsėjis', 'Spalis', 'Lapkritis', 'Gruodis'],
		dateFormat: 'YMD-',
		firstDay: 1,
		appendText: '',
		yearRange:'-100:+50'
	});
	}else{$('.selectable_date').calendar();}
	
		
	$("select#choosable").dxCombobox();
	
	$("#handicapped").click(function(){changeFontSize(1);});
	$("#back").click(function(){currentFontSize = defaultFontSize;});
	
	//$.hotkeys.add('h', function(){ location.href="index.htm";});
	$(document).bind('keydown','Ctrl+h', function(){ location.href="index.htm";});
	$(document).bind('keydown','tab', function(){ changeFontSize(1);location.href="index.htm?purpose=for_handicapped";});
	$(document).bind('keydown','esc', function(){ currentFontSize = defaultFontSize;location.href="index.htm?purpose=back";});
	$(document).bind('keydown','Ctrl+a', function(){ 
		changeFontSize(1);
	});
	$(document).bind('keydown','Ctrl+s', function(){ 
		changeFontSize(-1);
	});
	$(document).bind('keydown','Ctrl+r', function(){ location.href="profesijos.htm";});
	$(document).bind('keydown','Ctrl+k', function(){ location.href="kvalifikacijos.htm";});
	$(document).bind('keydown','Ctrl+g', function(){ location.href="programos.htm";});
	$(document).bind('keydown','Ctrl+i', function(){ location.href="svietimo_ir_mokslo_institucijos.htm";});

	$(".item_data tr").each(function(i){
		var tr = $(this);
		//alert($("td", tr).text());
		if($.trim($("td", tr).text()) == "")
			tr.remove();
	});

	var toCleanUp = $("form :input").not(":submit").not(":reset").not(":hidden").not("select").not(":checkbox").not(":radio").not(":button").not("input[@name='qualificationTitle']");

	toCleanUp.val("");
	
	var selectList = $("form select").not("#user");
	$("option", selectList).removeAttr("selected");
	$("option:first", selectList).attr("selected", "selected");
	//$("form select option:first").attr("selected", "selected");
	$(".reset").click(function(){
		toCleanUp.val("");
		var selects = $("form select");
		$("option", selects).removeAttr("selected");
		$("option:first", selects).attr("selected", "selected");
	});
});



function stripTables()
{
	$("div[@id!='proxy']/table").each(function(i){
		stripTable($(this));
	});
	
	$("div[@id='proxy']//table").each(function(i){
		$(this).addClass("bordered");
	});
	
}

function stripTable(table)
{
	var coef = 1;
	if($("thead", table).is("thead") == false) coef = 0;
	$("tbody/tr", table).each(function(i){
		if(i%2==coef)
			$(this).addClass("alternateRow");
		else $(this).addClass("normalRow");
	});
}

