function fileBrowserCallBack(field_name, url, type, win) {	var connector = "../../filemanager/browser.html?Connector=connectors/php/connector.php";	var enableAutoTypeSelection = true;		var cType;	tinyfck_field = field_name;	tinyfck = win;		switch (type) {		case "image":			cType = "Image";			break;		case "flash":			cType = "Flash";			break;		case "file":			cType = "File";			break;	}		if (enableAutoTypeSelection && cType) {		connector += "&Type=" + cType;	}		window.open(connector, "tinyfck", "modal,width=600,height=400");}

$(document).ready(function() {
//	$('table tbody tr:nth-child(2n)').addClass("odd");
	$('table').each(function(table) {
		col = 0;
		$('thead th', this).each(function(col) {
			this.column = col+1;
		});
	});

	$('input.checkall').click(function() {
		var that = this;
		if(this.parentNode.column) {
			var col = this.parentNode.column;
			$table = $(this).parents("table");
			$table = $table.get();
			$('td:nth-child('+(col)+') input[@type=checkbox]', $table).each(function() { this.checked = that.checked; });

		} else {
			$('input[@type=checkbox]', this.form).each(function() { this.checked = that.checked; });
		}
	});
	
	$('input[@type=checkbox]').mouseover(function(Event) {
		if(Event.shiftKey) {
			this.click();
		}
	});
	
	$('label[@for]').mouseover(function(Event) {
		if(Event.shiftKey) {
			
			$('#' + $(this).attr("for") ).click();
		}
	});
	
	$('input').each(function() {
		$(this).addClass($(this).attr("type"));
	});

	if($.tablesorter) {
	    $("table:not(.unsortable)").tablesorter({cssAsc:'asc', cssDesc:'desc', textExtraction:"complex", headers:{0:{ sorter:false}}}); 
	}
	/*
//	PopUpCal.dateFormat = 'YMD-';
	var months = ['Jan','Feb','Mar','Apr','Mai','Jun','Jul','Aug','Sep','Okt','Nov','Des'];
	var days = ['Søn','Man','Tir','Ons','Tor','Fre','Lør'];
	var calParams = {
				dateFormat : 'YMD-',
				clearText : '',
				closeText : '',
				nextText : 'Neste',
				prevText : 'Forrige',
				monthNames : months,
				dayNames : days,
				firstDay : 1,
				minDate : new Date(2007, 1 - 1, 1)
			};
	$('input.date').calendar(calParams);
	*/
	$('#splash').each(function() {
		var $btn = $('<a>X</a>');
		$btn.addClass("close");
		$($btn).click(function() {
			$('#splash').css('display','none');
		});
		
		$(this).append($btn);
	});
	$('#splash:not(.error)').each(function() {
		if($('p.error', this).size()!=0) return;
		$(this).css("position", "absolute");
		window.setTimeout(function() {
			$('#splash').fadeOut();
		}, 3000);
	});
	/*
	$('label[for]').each(function() {
		var id = $(this).attr("for");
		var el = $('#' + id);
		$(this).hover(
			function() {
				el.addClass("hover");
			},
			function() {
				el.removeClass("hover");
			}
		);
		$(el).hover(
			function() {
				el.addClass("hover");
			},
			function() {
				el.removeClass("hover");
			}
		);
	});
	*/
	
	$("input[@name=password]:not([@type=password])").each(function() {
		var b_generate = $('<a href="#">Generer passord</a>');
		var that = this;
//		alert($(b_generate).attr('href'));
//		b_generate.each(function(el) { alert(el)});
		$(b_generate).click(function(el) {
			var input_el = that || $("input[@name=password]");
			var generated_password = generatePassword();
			if(input_el) {
				$(input_el).attr('value', generated_password);
			} else {
				alert(generated_password);
			}
			el.preventDefault();
		});

		$(this).after(b_generate);
	});
	
	$(".gallery-mini").each(function() {
		var $displayer = $(".display", this);
		var $thumbs = $(".thumbs", this);
		$thumbs.click(function(e) {
			var img = e.target;
			var full_path = img.src.replace('_thumb','');
			$displayer.attr("src", full_path);
		});
	});
		
});

if(typeof tinyMCE != "undefined") {

	tinyMCE.init({
		theme : "advanced",
		mode : "exact",
		elements : "ReportsContent",
		file_browser_callback : "fileBrowserCallBack",
		relative_urls : false,
		debug : false
	});
}

function generatePassword() {
    var passwd = '';
    var desiredlen = 6;
    var capitalprob = 10;
    var mutationprob = 15;
    var vowels = new Array(
               "a" , "a" , "a" , "e" , "e" , "e" , "i" , "i" ,
               "o" , "o" , "u" , "u" , "ae", "ai", "au", "ao",
               "ay", "ea", "ei", "ey", "ua", "ia", "ie", "io",
               "oa", "oe", "ou", "oy", "!" , "1" , "4", "3"
               );
    var cons = new Array(
             "b" , "c" , "d" , "f" , "g" , "h" , "j" , "k" ,
             "l" , "m",  "n" , "p" , "q" , "r" , "s" , "t" ,
             "v" , "w" , "x" , "z" , "cs", "ck", "ch", "cz",
             "7" , "2" , "5" , "6" , "8" , "9"
            );

      vowelnext   = Math.floor ( Math.random ( ) * 1 + 1 );
      do {
        if (vowelnext) {
            var index = Math.floor ( Math.random ( ) * vowels.length );
            nextpart = vowels[index];
        } else {
            var index = Math.floor ( Math.random ( ) * cons.length );
            nextpart = cons[index];
        }
        var rnd = Math.floor ( Math.random ( ) * 100 + 1 );
        if ( rnd < capitalprob) {
          nextpart = nextpart.toUpperCase();
        }
        passwd = passwd + nextpart;
        
        var rnd = Math.floor ( Math.random ( ) * 100 + 1 );
        if (rnd > mutationprob) {
          vowelnext = !vowelnext;
        }
      } while (passwd.length < desiredlen);
	  
  return passwd;
}
