
if (typeof( console ) == 'undefined') {
	console = { log: function( str ) { $('#debugDiv').append( "<pre>" + str + "</pre>" ); },
				clear: function(  ) { $('#debugDiv').html( "" ); } };
}

jQuery.log = function(message) {
	if(window.console) {
		console.log(message);
	} else {
		alert(message);
	}
};
jQuery.fn.debug = function() {
	return this.each(function(){
		jQuery.log(this);
	});
};
jQuery.get_sync = function( url, data, callback ) {
    options = {
        async: false,
        cache: false,
        success: callback,
        data: data,
        url: url,
        dataType: 'json',
        type: 'GET'
    }
    $.ajax( options );
}
jQuery.postJSON = function(url, data, callback) {
	$.post(url, data, callback, "json");
};

jQuery.fn.extend({
	check: function() {
		try {
	    	if ($(this).hasClass('nice_checkbox')) {
	          	var id = $(this).attr('id' ).substr( 0, $(this).attr('id' ).length - 2 );

	          	$(this).removeClass( 'nice_checkbox_checked' );
	          	$(this).removeClass( 'nice_checkbox_unchecked' );

	            $('#' + id ).check();
	        	$(this).addClass( 'nice_checkbox_checked' );
	            //$(this).attr( 'checked', true );
	    		$('#' + id ).change();
	        } else if ( $(this).hasClass('has_nice_checkbox') ) {
	          	var id = $(this).attr('id') + '_w';

	          	$('#' + id).removeClass( 'nice_checkbox_checked' );
	          	$('#' + id).removeClass( 'nice_checkbox_unchecked' );

	        	$('#' + id).addClass( 'nice_checkbox_checked' );
			}
			$(this).attr('checked', 'checked' );
		} catch (er) {jQuery.log( 'check err:' + er );}
	},
	uncheck: function() {
		try {
	    	if ($(this).hasClass('nice_checkbox')) {
	          	var id = $(this).attr('id' ).substr( 0, $(this).attr('id' ).length - 2 );

	          	$(this).removeClass( 'nice_checkbox_checked' );
	          	$(this).removeClass( 'nice_checkbox_unchecked' );

	    		$('#' + id ).uncheck();
	        	$(this).addClass( 'nice_checkbox_unchecked' );
	            //$(this).attr( 'checked', true );
	    		$('#' + id ).change();
	        } else if ( $(this).hasClass('has_nice_checkbox') ) {
	          	var id = $(this).attr('id') + '_w';

	          	$('#' + id).removeClass( 'nice_checkbox_checked' );
	          	$('#' + id).removeClass( 'nice_checkbox_unchecked' );

	        	$('#' + id).addClass( 'nice_checkbox_unchecked' );
			}
			$(this).attr('checked', false );
		} catch (er) {jQuery.log( 'uncheck err:' + er );}
	},
	toggleCheck: function() {
		try {
			isCh = (typeof( $(this).attr('checked') ) == 'string') ?
						$(this).attr('checked') != 'false' :
						$(this).attr('checked');

	        if (isCh) {
	        	$(this).uncheck();
	        } else {
	        	$(this).check();
	        }
		} catch (er) {}
	},
	setCheck: function( isCh ) {
        if (isCh) {
        	$(this).check();
        } else {
        	$(this).uncheck();
        }
	},
	isChecked: function() {
		try {
			return (typeof( $(this).attr('checked') ) == 'string') ?
			$(this).attr('checked') != 'false' :
			$(this).attr('checked');
		} catch (er) {}
	},
	enable: function() {
		try {
			$(this).attr('disabled', false );
			$(this).removeClass('disabled_' );
	        if ($(this).hasClass('overridden')) {
	        	var _id = '#_' + $(this).attr('id') + '_';
	            $(_id).attr('disabled', false );
	            $(_id).removeClass('disabled_' );
	        }
	        if ($(this).hasClass('niceWrapped')) {
	        	$(this).parent('.selectWrap').removeClass( 'disabled_' );
	        }
		} catch (er) {}
			$(this).removeClass('disabled_' );
	},
	disable: function() {
		try {
			$(this).attr('disabled', 'disabled' );
			$(this).addClass('disabled_' );

	        if ($(this).hasClass('overridden')) {
	        	var _id = '#_' + $(this).attr('id') + '_';
	            $(_id).attr('disabled', 'disabled');
	            $(_id).addClass('disabled_');
	        }
	        if ($(this).hasClass('niceWrapped')) {
	        	$(this).parent('.selectWrap').addClass( 'disabled_' );
	        }
		} catch (er) {}
	},
	isEnabled: function() {
		try {
			return $(this).attr('disabled') == false;
		} catch (er) {}
		try {
			return !$(this).hasClass('disabled_');
		} catch (er) {}
		return true;
	},
	isDisabled: function() {
		try {
			return $(this).attr('disabled') == 'disabled';
		} catch (er) {}
		try {
			return $(this).hasClass('disabled_');
		} catch (er) {}
		return false;
	},
	disabled: function( v ) {
	    if (typeof v == 'undefined') {
			return $(this).attr('disabled') == 'disabled';
		}
	    this.each( function() {
			try {
				if (typeof v == 'undefined') {
					return $(this).attr('disabled') == 'disabled';
				} else {
				    var id = $(this).attr('id');
					if (v) {
						$(this).addClass('disabled_');
						$('#' + id + '_lbl').addClass('disabled');
		                if ($(this).hasClass('overridden')) {
		                	var _id = '#_' + id + '_';
		                    $(_id).attr('disabled', 'disabled' );
		                    $(_id).addClass('disabled_');
		                }
				        if ($(this).hasClass('niceWrapped')) {
				        	$(this).parent('.selectWrap').addClass( 'disabled_' );
				        }
					} else {
						$(this).removeClass('disabled_' );
						$('#' + id + '_lbl').removeClass('disabled');
		                if ($(this).hasClass('overridden')) {
		                	var _id = '#_' + $(this).attr('id') + '_';
		                    $(_id).attr('disabled', false );
		                    $(_id).removeClass('disabled_' );
		                }
				        if ($(this).hasClass('niceWrapped')) {
				        	$(this).parent('.selectWrap').removeClass( 'disabled_' );
				        }
					}
					return $(this).attr('disabled', ( v ? 'disabled': false ) );
				}
			} catch (er) {}
		} );
		return $(this);
	}
});

function makeMachineReadable( str )
{
	alias = str.replace( / /g, '' );
	alias = alias.replace( /Ã¥/g, 'a' ).replace( /Ã¤/g, 'a' ).replace( /[Ã¶]/g, 'o' );
	alias = alias.replace( /Ã…/g, 'A' ).replace( /Ã„/g, 'A' ).replace( /[Ã–]/g, 'O' );
	alias = alias.replace( /å/g, 'a' ).replace( /ä/g, 'a' ).replace( /ö/g, 'o' );
	alias = alias.replace( /Å/g, 'A' ).replace( /Ä/g, 'A' ).replace( /Ö/g, 'O' );

	return alias;
}

function treatJSON( str )
{
	try {
		var obj = null;
		eval( 'obj = ' + str );
		return obj;
	} catch (Err) {
		jQuery.log( Err );
		return null;
	}
}

$(document).ready( function() {
	$('.contractor').css ( {
		border:			'1px solid #000',
		background:		'#fff',
		display:		'block',
		float:			'left',
		padding:		'0px',
		textAlign:		'center',
		lineHeight:		'9px',
		fontSize:		'9px',
		height:			'9px',
		width:			'9px',
		cursor:			'pointer'
	} ).click( function() {
		if ($(this).html() == '+') { $(this).html('-'); }
		else { $(this).html('+'); }
		$(this).next().toggle();
	} );
	$('.contractor').click();

	$('.nice_checkbox_').addClass( 'nice_checkbox' ); // Aktivera då JavaScript är ok...
	$('.nice_checkbox').each( function() {
		var id = $(this).attr('id' ).substr( 0, $(this).attr('id' ).length - 2 );

		if( $('#' + id ).attr('checked') ) {
			$(this).addClass( 'nice_checkbox_checked' );
		    $(this).attr( 'checked', true );
		} else {
			$(this).addClass( 'nice_checkbox_unchecked' );
		    $(this).attr( 'checked', false );
		}

		$('#' + id).css( 'display', 'none' );
	} );

	$('.nice_checkbox').live( 'click', function() {
		var id = $(this).attr('id' ).substr( 0, $(this).attr('id' ).length - 2 );

		if( $('#' + id ).isChecked() ) {
			$(this).uncheck();
		} else {
			$(this).check();
		}
	} );


	$('#sysMsgBox').hide();
	if ($.trim( $('#sysMsgBox span').html() ) != '') {
		setMessage( $('#sysMsgBox').html() );
	}
	$('body').bind('ajaxError', function(event, request, settings) {
		setMessage( 'Fel vid laddningen av ' + settings.url + '!', 'error', false, 3000  );
	});
} );

function setMessage( msg, msgType, doStay, timeOut )
{
	if (typeof(msgType) == 'undefined') {
		msgType = 'notice';
	}
	if (typeof(doStay) == 'undefined') {
		doStay = false;
	}
	if (typeof(timeOut) == 'undefined') {
    	if (msgType == 'notice') {
				timeOut = 2000;
        } else {
				timeOut = 5000;
        }
    }

    jQuery.noticeAdd({
        text:		msg,
        stay:		doStay,
        stayTime:	timeOut,
        type:		msgType
    });
}

function loadIntoFancy( data, loadCallback )
{
    $('#fancy_ajax').css( 'position', 'absolute' );
    $('<div />').attr('id', 'fancy_ajax_')
    	.css( { width: '100%', height: '100%', overflow: 'auto', 'overflow-x': 'hidden',
    			position: 'absolute', top: '0px', left: $('#fancy_outer').css('width') } )
        .html( data )
        .insertAfter( '#fancy_ajax' );
    $('#fancy_ajax').animate( {
    	left: '-' + $('#fancy_outer').css('width')
    }, 'normal', 'linear', function() {
    	$('#fancy_ajax').remove();
    } );
    $('#fancy_ajax_').animate( {
    	left: '0px'
    }, 'slow', 'linear', function() {
        if (typeof( $('#fancy_ajax').attr('id') ) != 'undefined' ) {
        	$('#fancy_ajax').remove();
        }
        $('#fancy_ajax_').attr('id', 'fancy_ajax');
        if (typeof( addEffects ) == 'function') {
    			addEffects( '#fancy_ajax' );
        }
        if ( typeof(loadCallback) == 'function' ) {
            loadCallback();
		}
    } );
}

$.fn.ajaxSubmit = function(e, callback, validate_callback) {
	/* Change a form's submission type to ajax */
	this.submit(function(){
	    try {
	        if ( typeof( validate_callback ) == 'function' ) {
	            if ( ! validate_callback( this ) ) {
	                return false;
				}
			}
			var params = {};
			$(this)
			.find("input[checked], input[type='text'], input[type='hidden'], input[type='password'], input[type='submit'], option[selected], textarea")
			.filter(":isEnabled")
			.each(function() {
				params[ this.name || this.id || this.parentNode.name || this.parentNode.id ] = this.value;
			});
			$("body").addClass("curWait");

			$.postJSON(this.getAttribute("action") + "?ajax", params, callback);
		} catch (e) {
            alert (e);
		}
		return false;
	});

	return this;
}

$.fn.selectbox_all = function() {
	$('select').wrap('<div class="selectWrap"></div>')
	    .after('<span class="textField">&nbsp;</span>')
	    .addClass( 'niceWrapped' )
		.change( function() {
		    sel		= $('#' + $(this).attr('id') + ' option:selected');
		    wrap    = $(this).parent('.selectWrap');

			wrap.children('.textField').text( sel.text() );
		} )
		.focus(	function() { if ($(this).isEnabled()) $(this).parent('.selectWrap').addClass( 'focus' ); } )
		.blur(	function() { $(this).parent('.selectWrap').removeClass( 'focus' ); } )
		.keyup( function(e) {
		    id		= $(this).attr('id');
		    wrap    = $(this).parent('.selectWrap');
		    txt     = $('#' + id + ' option:selected').text();

		    wrap.children('.textField').text( txt );
		} )
		.mousedown( function() {
		  	if ($(this).isEnabled())
			  	$(this).parent('.selectWrap').addClass( 'pushed' ).addClass( 'pushed_' );
		}).mouseup( function() {
			$(this).parent('.selectWrap').removeClass( 'pushed' ).removeClass( 'pushed_' );
		}).mouseout( function( e ) {
			$(this).parent('.selectWrap').removeClass( 'pushed' );
		}).mouseover( function( e ) {
			if ($(this).parent('.selectWrap').hasClass( 'pushed_' )) {
			  	$(this).parent('.selectWrap').addClass( 'pushed' );
			}
		});
	$('.textField').click( function() {
	    if ($(this).siblings('select').isEnabled()) {
		    id = $(this).siblings('select').attr('id');
		    $('#' + id).focus();
		}
	} );
	$('.textField').each( function() {
	    id = $(this).siblings('select').attr('id');
	    $(this).text( $('#' + id + ' option:selected').text() );
	} );
	$('.selectWrap').each( function() {
	    id = $(this).children('select').attr('id');
	    $(this).attr( 'id', id + '_wrap' );
	} );
}
$.fn.selectbox = function() {
	$(this).wrap('<div class="selectWrap"></div>')
	    .after('<span class="textField">&nbsp;</span>')
	    .addClass( 'niceWrapped' )
		.change( function() {
		    sel		= $('#' + $(this).attr('id') + ' option:selected');
		    wrap    = $(this).parent('.selectWrap');

			wrap.children('.textField').text( sel.text() );
		} )
		.focus(	function() { if ($(this).isEnabled()) $(this).parent('.selectWrap').addClass( 'focus' ); } )
		.blur(	function() { $(this).parent('.selectWrap').removeClass( 'focus' ); } )
		.keyup( function(e) {
		    if ($(this).isEnabled()) {
			    id		= $(this).attr('id');
			    wrap    = $(this).parent('.selectWrap');
			    txt     = $('#' + id + ' option:selected').text();

			    wrap.children('.textField').text( txt );
			}
		} )
		.mousedown( function() {
		    if ($(this).isEnabled()) {
		  		$(this).parent('.selectWrap').addClass( 'pushed' ).addClass( 'pushed_' );
		  		$(this).parent('.selectWrap').children( 'select' ).mousedown( );
			}
		}).mouseup( function() {
			$(this).parent('.selectWrap').removeClass( 'pushed' ).removeClass( 'pushed_' );
		}).mouseout( function( e ) {
			$(this).parent('.selectWrap').removeClass( 'pushed' );
		}).mouseover( function( e ) {
			if ($(this).parent('.selectWrap').hasClass( 'pushed_' )) {
			  	$(this).parent('.selectWrap').addClass( 'pushed' );
			}
		});
	$(this).siblings('.textField').click( function() {
	    sel = $(this).siblings('select');
	    //console.log( 'tf:' +sel.isEnabled() );
	    if (sel.isEnabled()) {
		    id = sel.attr('id');
		    $('#' + id).focus();
		} else {
		    $(this).parent('.selectWrap').removeClass( 'focus' );
		}
	} );
	$(this).siblings('.textField').each( function() {
	    id = $(this).siblings('select').attr('id');
	    $(this).text( $('#' + id + ' option:selected').text() );
	} );
	$(this).parent('.selectWrap').each( function() {
	    id = $(this).children('select').attr('id');
	    $(this).attr( 'id', id + '_wrap' );
	} );
}
$.fn.selectbox_reset = function() {
	return this.each( function() {
	    id		= $(this).attr('id');
	    wrap    = $(this).parent('.selectWrap');
	    txt     = $('#' + id + ' option:selected').text();

	    wrap.children('.textField').text( txt );
	} );
}

/**
*
*  UTF-8 data encode / decode
*  http://www.webtoolkit.info/
*
**/

var Utf8 = {
	// public method for url encoding
	encode : function (string) {
		string = string.replace(/\r\n/g,"\n");
		var utftext = "";

		for (var n = 0; n < string.length; n++) {
			var c = string.charCodeAt(n);

			if (c < 128) {
				utftext += String.fromCharCode(c);
			} else if((c > 127) && (c < 2048)) {
				utftext += String.fromCharCode((c >> 6) | 192);
				utftext += String.fromCharCode((c & 63) | 128);
			} else {
				utftext += String.fromCharCode((c >> 12) | 224);
				utftext += String.fromCharCode(((c >> 6) & 63) | 128);
				utftext += String.fromCharCode((c & 63) | 128);
			}
		}
		return utftext;
	},

	// public method for url decoding
	decode : function (utftext) {
		var string = "";
		var i = 0;
		var c = c1 = c2 = 0;

		while ( i < utftext.length ) {
			c = utftext.charCodeAt(i);

			if (c < 128) {
				string += String.fromCharCode(c);
				i++;
			} else if((c > 191) && (c < 224)) {
				c2 = utftext.charCodeAt(i+1);
				string += String.fromCharCode(((c & 31) << 6) | (c2 & 63));
				i += 2;
			} else {
				c2 = utftext.charCodeAt(i+1);
				c3 = utftext.charCodeAt(i+2);
				string += String.fromCharCode(((c & 15) << 12) | ((c2 & 63) << 6) | (c3 & 63));
				i += 3;
			}
		}
		return string;
	}
}

var kLib = {
	substr: function( str, start, len ) {
	    if ( ( typeof(len) == 'number' ) && ( len < 0 ) ) {
	        len = str.length + len;
		}
	    return str.substr( start, len );
	},
	ucfirst: function( str ) {
	    return str.substr(0,1).toUpperCase() + str.substr(1);
	},
	s2b: function( str ) {
		return str == 'true';
	},
	b2s: function( bool ) {
		return bool ? 'true' : 'false';
	},
	createCookie: function(name,value,days) {
		if (days) {
			var date = new Date();
			date.setTime(date.getTime()+(days*24*60*60*1000));
			var expires = "; expires="+date.toGMTString();
		}
		else var expires = "";
		document.cookie = name+"="+value+expires+"; path=/";
	},
	readCookie: function(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;
	},
	eraseCookie: function(name) {
		kLib.createCookie(name,"",-1);
	},

	strtotime: function( str, now ) {
	    // Convert string representation of date and time to a timestamp
	    //
	    // version: 902.2516
	    // discuss at: http://phpjs.org/functions/strtotime
	    // +   original by: Caio Ariede (http://caioariede.com)
	    // +   improved by: Kevin van Zonneveld (http://kevin.vanzonneveld.net)
	    // +      input by: David
	    // +   improved by: Caio Ariede (http://caioariede.com)
	    // %        note 1: Examples all have a fixed timestamp to prevent tests to fail because of variable time(zones)
	    // *     example 1: strtotime('+1 day', 1129633200);
	    // *     returns 1: 1129719600
	    // *     example 2: strtotime('+1 week 2 days 4 hours 2 seconds', 1129633200);
	    // *     returns 2: 1130425202
	    // *     example 3: strtotime('last month', 1129633200);
	    // *     returns 3: 1127041200
	    // *     example 4: strtotime('2009-05-04 08:30:00');
	    // *     returns 4: 1241418600
	    var i, match, s, strTmp = '', parse = '';

	    strTmp = str;
	    strTmp = strTmp.replace(/\s{2,}|^\s|\s$/g, ' '); // unecessary spaces
	    strTmp = strTmp.replace(/[\t\r\n]/g, ''); // unecessary chars

	    if (strTmp == 'now') {
	        return (new Date()).getTime();
	    } else if (!isNaN(parse = Date.parse(strTmp))) {
	        return parse/1000;
	    } else if (now) {
	        now = new Date(now);
	    } else {
	        now = new Date();
	    }

	    strTmp = strTmp.toLowerCase();

	    var process = function (m) {
	        var ago = (m[2] && m[2] == 'ago');
	        var num = (num = m[0] == 'last' ? -1 : 1) * (ago ? -1 : 1);

	        switch (m[0]) {
	            case 'last':
	            case 'next':
	                switch (m[1].substring(0, 3)) {
	                    case 'yea':
	                        now.setFullYear(now.getFullYear() + num);
	                        break;
	                    case 'mon':
	                        now.setMonth(now.getMonth() + num);
	                        break;
	                    case 'wee':
	                        now.setDate(now.getDate() + (num * 7));
	                        break;
	                    case 'day':
	                        now.setDate(now.getDate() + num);
	                        break;
	                    case 'hou':
	                        now.setHours(now.getHours() + num);
	                        break;
	                    case 'min':
	                        now.setMinutes(now.getMinutes() + num);
	                        break;
	                    case 'sec':
	                        now.setSeconds(now.getSeconds() + num);
	                        break;
	                    default:
	                        var day;
	                        if (typeof (day = __is_day[m[1].substring(0, 3)]) != 'undefined') {
	                            var diff = day - now.getDay();
	                            if (diff == 0) {
	                                diff = 7 * num;
	                            } else if (diff > 0) {
	                                if (m[0] == 'last') diff -= 7;
	                            } else {
	                                if (m[0] == 'next') diff += 7;
	                            }

	                            now.setDate(now.getDate() + diff);
	                        }
	                }

	                break;

	            default:
	                if (/\d+/.test(m[0])) {
	                    num *= parseInt(m[0]);

	                    switch (m[1].substring(0, 3)) {
	                        case 'yea':
	                            now.setFullYear(now.getFullYear() + num);
	                            break;
	                        case 'mon':
	                            now.setMonth(now.getMonth() + num);
	                            break;
	                        case 'wee':
	                            now.setDate(now.getDate() + (num * 7));
	                            break;
	                        case 'day':
	                            now.setDate(now.getDate() + num);
	                            break;
	                        case 'hou':
	                            now.setHours(now.getHours() + num);
	                            break;
	                        case 'min':
	                            now.setMinutes(now.getMinutes() + num);
	                            break;
	                        case 'sec':
	                            now.setSeconds(now.getSeconds() + num);
	                            break;
	                    }
	                } else {
	                    return false;
	                }

	                break;
	        }

	        return true;
	    }

	    var __is =
	    {
	        day:
	        {
	            'sun': 0,
	            'mon': 1,
	            'tue': 2,
	            'wed': 3,
	            'thu': 4,
	            'fri': 5,
	            'sat': 6
	        },
	        mon:
	        {
	            'jan': 0,
	            'feb': 1,
	            'mar': 2,
	            'apr': 3,
	            'may': 4,
	            'jun': 5,
	            'jul': 6,
	            'aug': 7,
	            'sep': 8,
	            'oct': 9,
	            'nov': 10,
	            'dec': 11
	        }
	    }

	    match = strTmp.match(/^(\d{2,4}-\d{2}-\d{2})(\s\d{1,2}:\d{1,2}(:\d{1,2})?)?$/);

	    if (match != null) {
	        if (!match[2]) {
	            match[2] = '00:00:00';
	        } else if (!match[3]) {
	            match[2] += ':00';
	        }

	        s = match[1].split(/-/g);

	        for (i in __is.mon) {
	            if (__is.mon[i] == s[1] - 1) {
	                s[1] = i;
	            }
	        }

	        return strtotime(s[2] + ' ' + s[1] + ' ' + s[0] + ' ' + match[2]);
	    }

	    var regex = '([+-]?\\d+\\s'
	    + '(years?|months?|weeks?|days?|hours?|min|minutes?|sec|seconds?'
	    + '|sun\.?|sunday|mon\.?|monday|tue\.?|tuesday|wed\.?|wednesday'
	    + '|thu\.?|thursday|fri\.?|friday|sat\.?|saturday)'
	    + '|(last|next)\\s'
	    + '(years?|months?|weeks?|days?|hours?|min|minutes?|sec|seconds?'
	    + '|sun\.?|sunday|mon\.?|monday|tue\.?|tuesday|wed\.?|wednesday'
	    + '|thu\.?|thursday|fri\.?|friday|sat\.?|saturday))'
	    + '(\\sago)?';

	    match = strTmp.match(new RegExp(regex, 'g'));

	    if (match == null) {
	        return false;
	    }

	    for (i in match) {
	    	try {
		        if (!process(match[i].split(' '))) {
		            return false;
		        }
			} catch (e) {
				try {
			        if (!process(match[match[i]].split(' '))) {
			            return false;
			        }
				} catch (e) {}
			}
	    }

	    return (now);
	},
	strtotime_format: function( format, time ) {
		ts =  kLib.strtotime( format, time.replace(/-/g,' ') );
		var date = new Date( ts );
		month	= date.getMonth() + 1;	if ( month < 10 )	{ month	= '0' + month;	}
		day		= date.getDate();		if ( day < 10 )		{ day	= '0' + day;	}
		return '' + date.getFullYear() + '-' + month + '-' + day;
	}
}


function checkPassword( auto )
{
    if (typeof(auto) == 'undefined') {
    	auto = false;
    }
    var res = false;

	$('#passwordStatus,#passwordStatus2').css( 'background', "url('" + path + "/images/ui/icons/icon_ok_16.png')" );

    if ($('#password').val() != '') {
        last_strength		= strength		= passwordStrength( $('#password').val(), $('#name').val() );
        last_strength_str	= strength_str;
        $('#passwordInfo').html( strength_str );
        if (strength <= 0) {
            $('#passwordInfo').css( { color: '#F00', fontWeight: 'bold' /*, display: 'block'*/ } );
            $('#passwordStatus').css( 'background', "url('" + path + "/images/ui/icons/icon_error_16.png')" );
        } else if (strength == 1) {
            $('#passwordInfo').css( { color: '#AC0', fontWeight: 'bold' /*, display: 'block'*/ } );
            $('#passwordStatus').css( 'background', "url('" + path + "/images/ui/icons/icon_warning_16.png')" );
            if (!auto) {
            	res = !yesNoDialog( "Ditt lösenord är godkänt, men har en låg säkerhetsnivå.\n" +
                				"Det är rekommenderat att du anger ett säkrare lösenord.\n" +
                                "Vill du göra det?" + "\n" +
								"Tips: Lägg till specialtecken, såsom ! + - _ . , ? etc." );
            } else {
            	res = true;
            }
        } else if (strength == 2) {
            $('#passwordInfo').css( { color: '#0A0', fontWeight: 'bold', display: 'block' } );
            $('#passwordStatus').css( 'background', "url('" + path + "/images/ui/icons/icon_ok_16.png')" );
            res = true;
        }
        $('#passwordStatus').attr( 'title', strength_str );

        if ($('#password').val() != $('#password2').val()) {
            $('#passwordStatus2').css( 'background', "url('" + path + "/images/ui/icons/icon_error_16.png')" );
            $('#passwordStatus2').attr( 'title', 'Lösenorden är inte identiska' );
            res = false;
        } // å ä ö
    }

    return res;
}

function fancy_close( )
{
	$('#fancy_close').click();
}

function markErroredField( id )
{
	$('#' + id + ',#' + id + '_lbl').addClass('hasError');
}
function clearErroredFields( )
{
	$('.hasError').removeClass('hasError');
}

function yesNoDialog( str )
{
/*@cc_on @*/
/*@if (@_win32 && @_jscript_version>=5)

	str = str.replace( "\n", chr(10)+chr(13) );
    execScript('n = msgbox("'+str+'","4132")', "vbscript");
    return(n == 6);

@end @*/

	str = str + "\n(Ok = Ja, Avbryt/Cancel = Nej)";
	return confirm( str );
}


