/**
 * @author nurungso
 */


function addslashes(str) {
str=str.replace(/\\/g,'\\\\');
str=str.replace(/\'/g,'\\\'');
str=str.replace(/\"/g,'\\"');
str=str.replace(/\0/g,'\\0');
return str;
}

/**
 * 배경을 검은색으로 변환 
 * @param {Object} onoff
 */

function dispBackgroundDark(onoff)
{
    if (onoff == "on") 
    {
        $('body').append('<div class="bg_dark"> </div> ');
        $('.bg_dark').css({
            'width': '100%',
            'height': $(document).height()
        });
    }
    else 
    {
        $('.bg_dark').css({
            'width': '0px',
            'height': '0px'
        });
        $('.bg_dark').remove();
    }
}







/**
 * Show Dialog .
 * @param {Object} msg
 * @param {Object} d_width
 */
function ShowMsg(msg, d_width)
{

    $('#dialog').dialog('destory');
    $('#dialog p').html(msg);
    $('#dialog').dialog({
        width: d_width,
        buttons: {
            "OK": function()
            {
                $(this).dialog('close');
            }
        }
    });
    $('#dialog').dialog('open');
}

/**
 * Show Dialog .
 * @param {Object} msg
 * @param {Object} d_width
 * @param {Object} title
 * @param {Object} button_subject
 *
 */
function ShowMessageBox()
{
    //	msg,d_width,title
    
    var len = arguments.length;
    
    var msg;
    var d_width;
    var title;
    var button_subject
    var button_options = new Object();
    
    
    msg = arguments[0];
    
    if (len > 1) 
    {
        d_width = arguments[1];
    }
    else 
    {
        d_width = 300;
    }
    
    if (len > 2) 
    {
        title = arguments[2];
    }
    else 
    {
        title = 'Title ';
    }
    
    if (len > 3) 
    {
    
        if (typeof(arguments[3]) == 'object') 
        {
        
            var v_list = new Object();
            v_list = arguments[3];
            for (var n in v_list) 
            {
                button_options[n] = v_list[n];
            }
            
        }
        else 
        {
            button_options[arguments[3]] = function()
            {
                $(this).dialog('close');
                $('#dialog').remove();
            };
        }
        
    }
    else 
    {
        button_options["OK"] = function()
        {
            $(this).dialog('close');
            $('#dialog').remove();
        };
    }
    
    $('body').append(' <div id="dialog" title="' + title + '">      <span class="ui-icon ui-icon-circle-check" style="float:left; margin:0 7px 50px 0;"></span><p>Message</p>  </div>	');
    
    
    
    
    $('#dialog p').html(msg);
    $('#dialog').dialog({
        width: d_width,
        buttons: button_options
    });
    
    $('#dialog').dialog('open');
}


/**
 * 동적으로 스크립트 load
 * @param {Object} url
 */
function setDynamicScriptAdd(url)
{
    var c = document.createElement('script');
    c.type = 'text/javascript';
    c.src = url;
    $('head')[0].appendChild(c);
}

/**
 * 동적으로 CSS Load
 * @param {Object} url
 */
function setDynamicCssAdd(url)
{
    var c = document.createElement('link');
    c.type = 'text/css';
    c.rel = 'stylesheet';
    c.href = url;
    $('head')[0].appendChild(c);
    
}



/**
 * small helper function to urldecode strings
 */
jQuery.urldecode = function(x)
{
    return decodeURIComponent(x).replace(/\+/g, ' ');
}

/**
 * small helper function to urlencode strings
 */
jQuery.urlencode = encodeURIComponent;


/**
 * This function returns the parsed url parameters of the
 * current request. Multiple values per key are supported,
 * it will always return arrays of strings for the value parts.
 */
jQuery.getQueryParameters = function(s)
{
    if (typeof s == 'undefined') 
        s = document.location.search;
    var parts = s.substr(s.indexOf('?') + 1).split('&');
    var result = {};
    for (var i = 0; i < parts.length; i++) 
    {
        var tmp = parts[i].split('=', 2);
        var key = jQuery.urldecode(tmp[0]);
        var value = jQuery.urldecode(tmp[1]);
        if (key in result) 
            result[key].push(value);
        else 
            result[key] = [value];
    }
    return result;
}

/**
 * small function to check if an array contains
 * a given item.
 */
jQuery.contains = function(arr, item)
{
    for (var i = 0; i < arr.length; i++) 
    {
        if (arr[i] == item) 
            return true;
    }
    return false;
}



$.fn.setRadio = function(val)
{
    return this.each(function()
    {
        if (this.value == val) 
        {
            this.checked = true;
        }
    });
}






