function syncSelectBox(parent, child, isSubselectOptional, childVal)
{
    $("body").append("<select style='display:none' id='" + parent + child + "'></select>");
    $('#' + parent + child).html($("#" + child + " option"));

    var parentValue = $('#' + parent).attr('value');
    $('#' + child).html($("#" + parent + child + " .pid_" + parentValue).clone());
    if (isSubselectOptional) $('#' + child).prepend("<option value=''></option>");

    childVal = (typeof childVal == "undefined") ? "" : childVal;
    $("#" + child + ' option[value="' + childVal + '"]').attr('selected', 'selected');

    $('#' + parent).change( function() {
        var parentValue = $('#' + parent).attr('value');
        $('#' + child).html($("#" + parent + child + " .pid_" + parentValue).clone());
        if (isSubselectOptional) $('#' + child).prepend("<option value='' selected></option>");
        $('#' + child).trigger("change");
        $('#' + child).focus();
    });
}

function nl2br (str) {
    var breakTag = '<br/>';
    return (str + '').replace(/([^>\r\n]?)(\r\n|\n\r|\r|\n)/g, '$1' + breakTag + '$2');
}

;(function($){
    $.escapeHTML = function(val) {
        return $("<div/>").text(val).html();
    };
})(jQuery);


function zenToHanNum(from) {
    var han = ['1','2','3','4','5','6','7','8','9','0'];
    var zen = ['１','２','３','４','５','６','７','８','９','０'];
    var to = [];
    for( var i = 0 ; i < from.length ; i++ ) {
        for(var j = 0 ; j < zen.length ; j++ ) {
            if (from.charAt(i) == zen[j]) {
                to.push( han[j] );
                break;
            }
        }
        if (j == zen.length ) {
            to.push( from.charAt(i) );
        }
    }
    return to.join('');
}


/*
Sleep by Mark Hughes (AKA huzi8t9)
http://www.360Gamer.net/

Usage:
	$.sleep ( 3, function()
	{
		alert ( "I slept for 3 seconds!" );
	});
Use at free will, distribute free of charge
*/
;(function($)
{
    var _sleeptimer;
    $.sleep = function( time2sleep, callback )
    {
        $.sleep._sleeptimer = time2sleep;
        $.sleep._cback = callback;
        $.sleep.timer = setInterval('$.sleep.count()', 1000);
    }
    $.extend ($.sleep, {
        current_i : 1,
        _sleeptimer : 0,
        _cback : null,
        timer : null,
        count : function()
        {
            if ( $.sleep.current_i === $.sleep._sleeptimer )
            {
                clearInterval($.sleep.timer);
                $.sleep._cback.call(this);
            }
            $.sleep.current_i++;
        }
    });
})(jQuery);
