// ÅÄÖ (to save it to utf8)

replacePassword = function(id, name, width, styleclass) {
	
	
	var input = '<input type="password" id="replace-password-' + id + '" name="' + name + '"';
	
	if(width) {
		input += 'style="width: ' + width + 'px;"';
	}
	
	if(width) {
		input += 'class="' + styleclass + '"';
	}
	
	input += ' />';
	
	$('#' + id).html(input);
	$('input#replace-password-' + id).focus();
	
	// Check if its first or second password box
	var number = id.split("_")[1];
	
	observePasswordInput(id, number);
}

observePasswordInput = function(id, number) {
	if(number == 1) {
		$('input#replace-password-' + id).bind('blur', function(e) {
			if($(this).attr('value').length < 6) {
				$('div#password_error'+  number).html('<img src="/img/site/validation_error.png" alt="Fel" title="Fel" /> Måste vara minst 6 tecken');
				$('input#replace-password-' + id).css({ border: '2px solid #ff0000' });
			}else{
				$('div#password_error'+  number).html('<img src="/img/site/validation_ok.png" alt="OK" title="OK" />');
				$('input#replace-password-' + id).css({ border: '2px solid #00cc00' });
			}
		});	
	}else if(number == 2) {
		$('input#replace-password-' + id).bind('keyup', function(e) {
			if($(this).attr('value') != $('input#replace-password-password_1').attr('value')) {
				$('div#password_error'+  number).html('<img src="/img/site/validation_error.png" alt="Fel" title="Fel" /> Matchar inte ovanstående lösenord');
				$('input#replace-password-' + id).css({ border: '2px solid #ff0000' });
			}else{
				$('div#password_error'+  number).html('<img src="/img/site/validation_ok.png" alt="OK" title="OK" />');
				$('input#replace-password-' + id).css({ border: '2px solid #00cc00' });
			}
		});	
	}
}

trim = function(str, charlist) {
	
    var whitespace, l = 0, i = 0;
    str += '';
    
    if (!charlist) {
        // default list
        whitespace = " \n\r\t\f\x0b\xa0\u2000\u2001\u2002\u2003\u2004\u2005\u2006\u2007\u2008\u2009\u200a\u200b\u2028\u2029\u3000";
    } else {
        // preg_quote custom list
        charlist += '';
        whitespace = charlist.replace(/([\[\]\(\)\.\?\/\*\{\}\+\$\^\:])/g, '$1');
    }
    
    l = str.length;
    for (i = 0; i < l; i++) {
        if (whitespace.indexOf(str.charAt(i)) === -1) {
            str = str.substring(i);
            break;
        }
    }
    
    l = str.length;
    for (i = l - 1; i >= 0; i--) {
        if (whitespace.indexOf(str.charAt(i)) === -1) {
            str = str.substring(0, i + 1);
            break;
        }
    }
    
    return whitespace.indexOf(str.charAt(0)) === -1 ? str : '';
}


is_numeric = function( mixed_var ) {
	
    if (mixed_var === '') {
        return false;
    }

    return !isNaN(mixed_var * 1);
}


is_object = function(mixed_var){
	
    if (mixed_var instanceof Array) {
        return false;
    } else {
        return (mixed_var !== null) && (typeof( mixed_var ) == 'object');
    }
}

checkIE = function(version) {
	if($.browser.msie && parseInt(jQuery.browser.version,10) == version) {
		return true;
	}else{
		return false;	
	}
}

redirect = function(url) {
	
	if(url.length == 0) {
		var currenturl = unescape(window.location.pathname);
		window.location.href = currenturl;	
	}else{
	
		window.location.href = url;
	}
}

