//panel animation control ==========================================================

panel_reset = false;
var loader_image_gif = '<div class="ajax_loader"><img src="_lib/img/ajax-loader.gif" /></div>';

function panel_out() {
	// alert('firing panel out...');
	
	$('#slide_panel').animate(
		{
			left: -127
			// style: '',
			// className: '',
			// opacity: 0.4,
			// backgroundColor: ''
		},
		'slow'
	);
	
	if(panel_reset) { $("#subcategories").BlindRight(); } 
	panel_reset = false;
	
	$('#categories').animate({ opacity: 0 },'fast');
	// This seems to work
	// $('#subcategories').css('backgroundColor', 'transparent');

	// $('#subcategories').animate({ backgroundColor: 'transparent' },'fast');
	
}

function panel_in(){
	
	// alert('firing panel_in()');
	
	// if(panel_reset)
	// {
	// 	$('#slide_panel').animate(
	// 		{
	// 			left: 30,
	// 			// style: '',
	// 			// className: '',
	// 			opacity: 1,
	// 			// backgroundColor: ''
	// 		},
	// 		'slow'
	// 	);	
	// }
	// else
	// {
		$('#slide_panel').animate(
			{
				left: 30
				// style: '',
				// className: '',
				// opacity: 0.4,
				// backgroundColor: ''
			},
			'fast'
		);
	// }

	// $("#subcategories").BlindLeft();
	// BlindLeft, BlindRight, BlindToggleHorizontally	
	
	$('#categories').animate({ opacity: 1 },'slow');
	// This seems to work
	// $('#subcategories').css('backgroundColor', '#FFF');
	
	// $('#subcategories').animate({ backgroundColor: '#FFF' },'slow');
	
}

function panel_gate(trig){
	// alert('got ' + trig.href);

	var trigger = trig.href;

	// if( $(trig).attr('href') =="#services_index" ) // this does not work in ie 7 .. detecting the presence of #services_index instead
	if(trigger.search(/#services_index/) != -1){
		
		// alert('in the panel_gate() if()');
		
		$("#subcategories").BlindLeft();
		
		// bc_reset(); // reset the breadcrumbs
		
		// send send in the slide panel showing only the cat list
		panel_reset = true;
		panel_in(); 
			
		//$('#slide_panel').show();
	}else{	
		
		// alert('in the panel_gate() else');
		
		$('#slide_panel').hide();
		// $('#slide_panel').attr({ left: -110 } );
		// alert('done running hide');
	}
}

// data loaders ==========================================================
function golink(url)
{
	window.open(url,'findit_launched');
	// window.open('url to open','window name','attribute1,attribute2')
	// Below is a list of the attributes you can use:
	//    1. width=300 :: Use this to define the width of the new window.
	//    2. height=200 :: Use this to define the height of the new window.
	//    3. resizable=yes or no :: Use this to control whether or not you want the user to be able to resize the window.
	//    4. scrollbars=yes or no :: This lets you decide whether or not to have scrollbars on the window.
	//    5. toolbar=yes or no :: Whether or not the new window should have the browser navigation bar at the top (The back, foward, stop buttons..etc.).
	//    6. location=yes or no :: Whether or not you wish to show the location box with the current url (The place to type http://address).
	//    7. directories=yes or no :: Whether or not the window should show the extra buttons. (what's cool, personal buttons, etc...).
	//    8. status=yes or no :: Whether or not to show the window status bar at the bottom of the window.
	//    9. menubar=yes or no :: Whether or not to show the menus at the top of the window (File, Edit, etc...).
	//   10. copyhistory=yes or no :: Whether or not to copy the old browser window's history list to the new window. 
}

function download_file(id)
{
	// pass the id into mod_download_file.php which increments the files hit count
	// window.open("http://seaborn.csuchico.edu/vpbf/findit/_lib/php/mod_download_file.php?fid=" + id,'file_download');
}


function tab_load_department(id){
	// load this id in to the departmet tab area
	load_department_detail(id);
	// switch to the department tab
	$('#tab_container').triggerTab(2);
}

function tab_load_documents(id) {
	// load this id in to the departmet tab area
	load_department_forms(id);
	// switch to the department tab
	$('#tab_container').triggerTab(4);
	var opts = $('.department_select_option').get();
	for(i=0;i<opts.length;i++) {
	  opts[i].selected = false;
	}
	var ds = $('#department_select_option_'+id).get() ;
	ds[0].selected=true;
	$('#search_header').html(ds[0].innerHTML);
        
}


function load_department_detail(id)
{
	// alert( 'laoding department ' + id);
	
	$.ajax({
		type: "POST",
		url: '_lib/php/mod_dept_detail.php',
		data: 'id=' + id,
		dataType: "html",
		timeout: 30000,
		error: function(request,estring,exception) { 
			// alert('An error occured while loading the department you chose. Please try again later.'); 
			var mess = ajax_error(request,estring,exception);
			report(mess,{inject:'#master_error_report',type:'sticky'});
		},
		success: function(data){
			// $('#department_detail').fadeOut('slow');
			$('#department_detail').html('');
			$('#department_detail').html(data);
			$('#department_detail').fadeIn('slow');
		},
		complete: function(arg1,arg2){
			//alert( 'complete() reports -> args:['+arg1+'],['+arg2+']'); 
		}
	});
}

function load_department_forms(id,el)
{	
	$.ajax({
		type: "POST",
		url: '_lib/php/mod_dept_forms.php',
		data: 'id=' + id,
		dataType: "html",
		timeout: 30000,
		error: function(request,estring,exception) { 
			// alert('A fatal error occured while loading the forms for the department you chose. Please try again later.'); 
			var mess = ajax_error(request,estring,exception);
			report(mess,{inject:'#master_error_report',type:'sticky'});
	
		},
        beforeSend: function(httpReq) {
              $('#department_forms').html(loader_image_gif);
              //$('#doc_search_header').html(loader_image_gif);
        },
		success: function(data){
			// $('#department_forms').fadeOut('slow');
			$('#department_forms').html('');
			$('#department_forms').html(data);
			$('#department_forms').fadeIn('slow');
            if(el != undefined) {
              $('#search_header').html(el.innerHTML);
            }
		},
		complete: function(arg1,arg2){
			//alert( 'complete() reports -> args:['+arg1+'],['+arg2+']'); 
			//filter_documents_doctypes(true)
			apply_doctypes('departments');
		}
	});
}

function search(form)
{
	// get the search_text
	var query = (form == 'home_search') ? document.getElementById('home_search_text').value : document.getElementById('main_search_text').value; 
	// var query = $('#search_text').attr('value'); // returns undefined if blank ... hurmph!
	
	blank_error_msg = 'I can&rsquo;t search a blank query ... sorry';
	
	if(query.replace(/^\s+$/,'') != ''){ // if search is not blank

		locations = '';
		if(form == 'home_search'){ // if at home form -> create the locations string and fill the form fields (checkboxes) of the main search form

			$('.home_search_section').each(function(){

				if(this.checked){
					locations += this.value + ',';
					$('#main_' + this.value).attr({checked: 'checked'}); // check the target forms control			
				}
				else if(!this.checked){ // uncheck the target forms control
					// check the main search form also
					$('#main_' + this.value).attr({checked: ''});
				}	

			});
			
		}else{ // juast create the locations string

			$('.main_search_section').each(function(){
				if(this.checked){
					locations += this.value + ',';
				}	
			});

		}
		
		if(form == 'home_search'){ // if @ home form set the search string in the main search form and trigger the search tab
			$('#main_search_text').attr({value: query}); 
			$('#tab_container').triggerTab(5);
		}
			
		locations = locations.substring(0,(locations.length - 1)); // trim off the last ","
		
		// perform the search -> send the query return the results into '#search_results'
		args = 'q=' + query + '&s=' + locations;

		$.ajax({
			type: "POST",
			url: '_lib/php/mod_search.php',
			data: args,
			dataType: "json",
			timeout: 30000,
			error: function(request,estring,exception) { 
				var mess = ajax_error(request,estring,exception);
				report(mess,{inject:'#master_error_report',type:'sticky'});
			},
            beforeSend: function(httpReq) {
	              $('#dept_results').html(loader_image_gif);
			      $('#docu_results').html(loader_image_gif);
            },
			success: function(data){
			
				// extract json vars
				var ret = data.op[0].ret; 
				var msg = data.op[0].msg; 
				var department_results = data.op[1].dept;
				var document_results = data.op[2].docu;
				var filter_results = data.op[3].filter;
				// report the error message returned from the server 
				if(!ret) { 
					report(msg,{cls:'apperr', type:'sticky', inject: 'search_message'}); 
				}
				else { // load the results into the search results panel
					report(msg,{cls: 'message', inject: 'search_message'}); 
					$('#dept_results').html(department_results);
					$('#docu_results').html(document_results);
                                        $('#filter_area').html(filter_results);
				}
			},
			complete: function(arg1,arg2){
				//alert( 'complete() reports -> args:['+arg1+'],['+arg2+']'); 
				apply_doctypes('search');
			}
		});
	} else {	
		if(form == 'home_search') report(blank_error_msg,{cls: 'apperr', inject: 'home_search_message'}); 
		else report(blank_error_msg,{cls: 'apperr', inject: 'search_message'});
	}

}

function clear_search(form){
	// clear the search text
	$('#'+form+'_text').attr({value: ''});
	$('.'+form+'_section').each(function(){
		this.checked = false;
	});
	
	//var reset_html = '<div class="hint"><img src="_lib/img/icon_hint.jpg" alt="foo" class="leftfloat" height="40" width="40"><p>Input what you are looking for into the form above, click on the &ldquo;Find It!&rdquo; button when your ready to search.</p><p>Options:</p><ul><li>You can limit your search by choosing only a specific area to search in by using the <strong>Departments, Forms & Procedures and Services</strong> checkboxes</li><li>You can search for individual words or phrases by enclosinging the phrase inside quotes &ldquo;like this&rdquo;. </li></ul></div>';
	var reset_html = '';
	// reset the search pane
	$('#dept_results').html(reset_html);
	$('#docu_results').html('');	
}

function load_services(c_num,el){
	// load the service area with the services for category "s"
	$.ajax({
		type: "POST",
		url: '_lib/php/mod_load_services.php',
		data: 'for_cat=' + c_num,
		dataType: "html",
		timeout: 30000,
		error: function(request,estring,exception){ 
			// alert('An error occured while loading the service list for the categry you chose. Please try again later.'); 
			var mess = ajax_error(request,estring,exception);
			report(mess,{inject:'#master_error_report',type:'sticky'});
		},
        beforeSend: function(httpReq) {
            //var please_wait = '<p id="ajax_loader_wait_message">Please wait.</p>';
			$('#cat_services_list').html(loader_image_gif);
	        //$('#filter_area').html(img_tag);   
        },
		success: function(data){
			$('#cat_services_list').html(data);
		},
		complete: function(arg1,arg2){
			//alert( 'complete() reports -> args:['+arg1+'],['+arg2+']'); 
		}
	});
	
	// alert('loading services for category ' + c_num);
	//panel_out();

	// get teh text to send into load_bc_cat(), etc...
	var service = $(el).html();

	// set the instruction to match the chosen service
	//$('#service_departments').html('<div class="hint"><img src="_lib/img/icon_hint.jpg" width="40" height="40" alt="foo" class="leftfloat" /><p>Choose a service from the <strong>' + service + '</strong> list.</p></div>');
	// set the instruction to match the chosen service
	//$('#service_documents').html('<div class="hint"><img src="_lib/img/icon_hint.jpg" width="40" height="40" alt="foo" class="leftfloat" /><p>Choose a service from the <strong>' + service + '</strong> list.</p></div>');


	// set the category name breadcrumb to be the same as the text of the anchor tag that triggered load_service()
	load_bc_cat(service);

}

function load_atoz(){
	// reset the breadcrumb text .. hide it!
	$('#bc_cat').fadeOut('slow').html('');
	$('#bc_service').fadeOut('slow').html('');

	// load the service area with the services for category "s"
	$.ajax({
		type: "POST",
		url: '_lib/php/mod_load_all_services.php',
		data: null,
		dataType: "html",
		timeout: 30000,
		error: function(request,estring,exception){ 
			// alert('An error occured while loading the service list. Please try again later.'); 
            var mess = ajax_error(request,estring,exception);
			report(mess,{inject:'#master_error_report',type:'sticky'});
		},
        beforeSend: function(httpReq) {
           //var please_wait = '<p id="ajax_loader_wait_message">Please wait.</p>';
		   //('#cat_services_list').html(loader_image_gif);
	       //$('#filter_area').html(img_tag);   
        },
		success: function(data){
			// load the service list into the panel
			//$('#cat_services_list').html('');
			$('#cat_services_list').html(data);
			$('#cat_services_list').fadeIn('fast');
		},
		complete: function(arg1,arg2){
			//alert( 'complete() reports -> args:['+arg1+'],['+arg2+']'); 
		}
	});
}

function get_service_members(s_num,el){
	//panel_out();  // Chad
	// set the category name breadcrumb to be the same as the text of the anchor tag that triggered load_service()
	load_bc_service($(el).html());
	
	// load the service area with the services for category "s"
	$.ajax({
		type: "POST",
		url: '_lib/php/mod_service_members.php',
		data: 'sid=' + s_num + '&sname=' + $(el).html(), // being lazy here!
		dataType: "json",
		timeout: 30000,
		error: function(request,estring,exception) { 
			// alert('An error occured while loading the service list. Please try again later.'); 
			var mess = ajax_error(request,estring,exception);
			report(mess,{inject:'#master_error_report',type:'sticky'});
		},
        beforeSend: function(httpReq) {
			$('#service_departments').html(loader_image_gif);
            $('#service_documents').html(loader_image_gif); 
        },
		success: function(data){
			
			var ret = data.op[0].ret; 
			var msg = data.op[0].msg; 
			var department_results = data.op[1].dept;
			var document_results = data.op[2].docu;
			
			// report the error message returned from the server 
			if(!ret) { 
				report(msg,{cls:'apperr', type:'sticky', inject: 'service_member_messgae'}); 
			} else { // load the results into the correct areas
				
				// just discard the message for now
				// report(msg,{cls: 'message', inject: 'service_member_messgae'}); 
				
				$('#service_departments').html('');
				$('#service_departments').html(department_results);
				$('#service_departments').fadeIn('fast');
				
				$('#service_documents').html('');
				$('#service_documents').html(document_results);
				$('#service_documents').fadeIn('fast');
			}
		},
		complete: function(arg1,arg2){
			//alert( 'complete() reports -> args:['+arg1+'],['+arg2+']'); 
		}
	});
	
}

// reset the breadcrumbs and open the category panel
function bc_reset(){
	// alert('firing bc_reset()');
	panel_in();
	
	// reset the document display area.
	//$('#service_departments').html('<div class="hint"><img src="_lib/img/icon_hint.jpg" width="40" height="40" alt="foo" class="leftfloat" /><p>Choose a category from the <strong>Service Categories</strong> list.</p></div>');
	// reset the document display area.
	//$('#service_documents').html('<div class="hint"><img src="_lib/img/icon_hint.jpg" width="40" height="40" alt="foo" class="leftfloat" /><p>Choose a category from the <strong>Service Categories</strong> list.</p></div>');
	
	$('#bc_cat').fadeOut('slow').html('');
	$('#bc_service').fadeOut('slow').html('');
}

// breadcrumb functions ===================================================

// beacuse of rushed execution phase (read no pre programming planning!) the following two functions share this global!
// last_cat_text = '';

function load_bc_cat(cat_text){
	// set the last_cat_text var
	// last_cat_text = cat_text; 	
	// set the cat html -> 	fade it in
	$('#bc_cat').html(' &nbsp;&gt;&nbsp; ' + cat_text).show();
	// reset the service breadcrumb
	$('#bc_service').fadeOut('slow').html('');
}

function load_bc_service(svs_text){
	// $('#cat_services_list > h2').html();
	// check for setting the services breadcrumb without a category breadcrumb ... fix if you need to
	// if($('#bc_cat').html() == '') $('#bc_cat').html(' &nbsp;&gt;&nbsp; ' + last_cat_text).show();
	if($('#bc_cat').html() == '') $('#bc_cat').html(' &nbsp;&gt;&nbsp; ' + $('#cat_services_list > h2').html()).show();
	// set the services breadcrumb
	$('#bc_service').html(' &nbsp;&gt;&nbsp; ' + svs_text).show();	
}


function searchIn(form,whereStr,search_id)
{
	// get the search_text
	var query = (form == 'home_search') ? document.getElementById('home_search_text').value : document.getElementById('main_search_text').value; 
	// var query = $('#search_text').attr('value'); // returns undefined if blank ... hurmph!
	
	blank_error_msg = 'I can&rsquo;t search a blank query ... sorry';
	
	if(query.replace(/^\s+$/,'') != ''){ // if search is not blank
		locations = ''; 
		if(form == 'home_search'){ // if at home form -> create the locations string and fill the form fields (checkboxes) of the main search form
			$('.home_search_section').each(function(){
				if(this.checked){
					locations += this.value + ',';
					$('#main_' + this.value).attr({checked: 'checked'}); // check the target forms control			
				}
				else if(!this.checked){ // uncheck the target forms control
					// check the main search form also
					$('#main_' + this.value).attr({checked: ''});
				}	
			});
		}else{ // juast create the locations string
			$('.main_search_section').each(function(){
				if(this.checked){
					locations += this.value + ',';
				}	
			});
		}
		
		if(form == 'home_search'){ // if @ home form set the search string in the main search form and trigger the search tab
			$('#main_search_text').attr({value: query}); 
			$('#tab_container').triggerTab(5);
		}
			
		locations = locations.substring(0,(locations.length - 1)); // trim off the last ","
		
		// perform the search -> send the query return the results into '#search_results'
                args = '';
                if(whereStr == 'department') {
		  args = 'q=' + query + '&s=' + locations+"&did="+search_id;
                } else if(whereStr == 'service') {
                  args = 'q=' + query + '&s=' + locations+"&sid="+search_id;
                } else {
                  args = 'q=' + query + '&s=' + locations;
                }

		$.ajax({
			type: "POST",
			url: '_lib/php/mod_search.php',
			data: args,
			dataType: "json",
			timeout: 30000,
			error: function(request,estring,exception) { 
				// alert( 'A fatal error ocurred while searching. Please try again later.'); 
                                var mess = ajax_error(request,estring,exception);
			        report(mess,{inject:'#master_error_report',type:'sticky'});
			},
            beforeSend: function(httpReq) {
		        //var please_wait = '<p id="ajax_loader_wait_message">Please wait.</p>';
				$('#dept_results').html(loader_image_gif);
		        $('#docu_results').html(loader_image_gif);
			    //$('#filter_area').html(img_tag);   
            },
			success: function(data){
				// extract json vars
				var ret = data.op[0].ret; 
				var msg = data.op[0].msg; 
				var department_results = data.op[1].dept;
				var document_results = data.op[2].docu;
				
				// report the error message returned from the server 
				if(!ret) { 
					report(msg,{cls:'apperr', type:'sticky', inject: 'search_message'}); 
				}
				else { // load the results into the search results panel
					report(msg,{cls: 'message', inject: 'search_message'}); 
					$('#dept_results').html(department_results);
					$('#docu_results').html(document_results);
				}
			},
			complete: function(arg1,arg2){
				//alert( 'complete() reports -> args:['+arg1+'],['+arg2+']'); 
			}
		});
	} else {	
		if(form == 'home_search') report(blank_error_msg,{cls: 'apperr', inject: 'home_search_message'}); 
		else report(blank_error_msg,{cls: 'apperr', inject: 'search_message'});
	}

}

/**
    This toggles document search descriptions
*/
function manage_descriptions() {
    if($.cookie('descriptions') == 'show') {
	    $('.doc_description').hide();
	    $.cookie('descriptions','hide');
        $(".show_hide_descriptions").html("show descriptions");
        $('.description_show').show();
        $('.description_message').html("view description");
    } else {
	    $.cookie('descriptions','show');
	    $('.doc_description').show();
        $(".show_hide_descriptions").html("hide descriptions");
        $('.description_show').hide();
        $('.description_message').html("hide description");
    }
}

function reset_department_filter() {
   $('.documents_filter_entry').show();
   $('.category_filter').hide();
}

function toggle_description(el_name,toggler_name) {
   var s = $('#'+toggler_name).get();
   var e = s[0];
   
   // If it hasn't been clicked yet, usually that means you
   // want to show it.
   if(e.descriptionToggle == undefined) {
      e.descriptionToggle = 'show';
   }
   
   if(e.descriptionToggle == 'show') {
      $('#'+el_name).show(); 
      $('#'+toggler_name).html("hide description");
      e.descriptionToggle = 'hide';
   } else {
      $('#'+el_name).hide();
      $('#'+toggler_name).html("view description");
      e.descriptionToggle = 'show';
   }
}

function filter_doctypes(all,context) {
	
	var tArray = $('.'+context+'_doctype_filter').get();
	$('.'+context+'_filter_entry').hide();

	for(i=0;i<tArray.length;i++) {
		if(tArray[i].checked) {
			$('.'+context+'_doctype_'+tArray[i].value).show();
		}
	}

	if(all) {
		var b = $('.'+context+'_doctype_filter_all').get();
		if(b[0].checked == true) {
			for(t=0;t<tArray.length;t++) {
				if(tArray[t].value != 'all' ) {
					tArray[t].checked = false;
				}
			}
			$('.'+context+'_filter_entry').show();
		} else {
			$('.'+context+'_filter_entry').hide();
		}
	} else {
		var b = $('.'+context+'_doctype_filter_all').get();
		b[0].checked = false;
	}

	checkFilterError(context);
}

function checkFilterError(context){
	
	switch(context){
		case 'search':
			var outputArea = '#docu_results';
		break;
		
		case 'departments':
			var outputArea = '#department_forms';
		break;

		default:
			alert(sprintf('Scope creep error: No error handler defined for context %1$s',context));
	}

	// remove any leftover filter items message
	var filterErrorHandle = sprintf('%s .filter_no_items_message',outputArea); 	// console.log(filterErrorHandle);
	$(filterErrorHandle).remove();
	
	// check the size of the visible *_filter_entries; show error message if all entries are filterd
	if($('.'+context+'_filter_entry:visible').length == 0){	
		switch(context){
			case 'search': 		
				var allTrigger = '.search_doctype_filter_all';
				// figure out if we need an error message for this context
				var needMessage = ($('#docu_results .hint').length == 0 && $('.search_doctype_filter_all:checked').length == 0) ? true : false;
			break;
			
			case 'departments':
				var allTrigger = '.departments_doctype_filter_all';
				// figure out if we need an error message for this context
				var needMessage = ($('#department_forms .hint').length == 0 && $('.departments_doctype_filter_all:checked').length == 0) ? true : false;
			break;			
		}
				
		// if an output area is defined and this is not a serach error or hint present then show the filter error message		
		if(needMessage){
			$(outputArea).append(sprintf('<p class="filter_no_items_message actioncall">No results found with your current filter settings.<br /> Would you like to <a href="javascript:void 0;" onclick="$(\'%s\').trigger(\'click\');">see all results</a>?</p>',allTrigger));
		}		
	}	
}

function apply_doctypes(context) {
     //var b = $('.search_doctype_filter_all').get();
	 //b[0].checked = true;
	 
	 var f = $('.'+context+'_doctype_filter').get();
	 for(i=0;i<f.length;i++) {
	    if(f[i].value == 'all' && f[i].checked == true) {
	       filter_doctypes(true,context);
	       break;
	    } 
	    if(f[i].value != 'all') {
	       filter_doctypes(false,context);
	       break;
	    }
	 }
	 //filter_search_doctypes(true);
}

/**
    This context switching is how it really needs to be done
    everywhere.
*/
function activate_doctype_filter(id,context) {
	  if(context == 'departments') {
	     var allFilters = $('.departments_doctype_filter').get();
	     for(m=0;m<allFilters.length;m++) {
	        allFilters[m].checked = false;
	     }
	     var a = $('.departments_doctype_filter_all').get();
	     a[0].checked = false;
	     var d = $('.departments_doctype_filter_'+id).get();
	     d[0].checked = true;
	     filter_doctypes(false,'departments');
	  } 
	  if(context == 'search') {
	     var allFilters = $('.search_doctype_filter').get();
	     for(m=0;m<allFilters.length;m++) {
	        allFilters[m].checked = false;
	     }
	     var a = $('.search_doctype_filter_all').get();
	     a[0].checked = false;
	     var d = $('.search_doctype_filter_'+id).get();
	     d[0].checked = true;
	     filter_doctypes(false,'search');
	  } 
}

function get_department_selection() {
	  var sel = $('.department_select_option').get();
	  var deptId = 0;
	  for(n=0;n<sel.length;n++) {
	     if(sel[n].selected == true) {
	        load_department_forms(sel[n].value,sel[n]);
	        break;  // we don't need to finish
	     }
	  }
}

function department_forms_select(select_el) {
    var e = select_el.options[select_el.selectedIndex];
	load_department_forms(e.value,e);
}

