function php_urlencode(str) {
    str = escape(str);
    return str.replace(/[*+\/@]|%20/g,function (s) {switch (s) {case "*":s = "%2A";break;case "+":s = "%2B";break;case "/":s = "%2F";break;case "@":s = "%40";break;case "%20":s = "+";break;}return s;});
}

function utf8_encode(argString) {
    var string = (argString+'').replace(/\r\n/g, "\n").replace(/\r/g, "\n");

    var utftext = "";
    var start, end;
    var stringl = 0;

    start = end = 0;
    stringl = string.length;
    for (var n = 0; n < stringl; n++) {
        var c1 = string.charCodeAt(n);
        var enc = null;

        if (c1 < 128) {
            end++;
        } else if((c1 > 127) && (c1 < 2048)) {
            enc = String.fromCharCode((c1 >> 6) | 192) + String.fromCharCode((c1 & 63) | 128);
        } else {
            enc = String.fromCharCode((c1 >> 12) | 224) + String.fromCharCode(((c1 >> 6) & 63) | 128) + String.fromCharCode((c1 & 63) | 128);
        }
        if (enc !== null) {
            if (end > start) {
                utftext += string.substring(start, end);
            }
            utftext += enc;
            start = end = n+1;
        }
    }

    if (end > start) {
        utftext += string.substring(start, string.length);
    }

    return utftext;
}

function sendPdfForm(url) {

    var htmlCode = document.getElementById('pdf-htmlcode');

    if (htmlCode && htmlCode.value=='')
    {
        // ---------------------------------------------------------------
        // Change the relative images URL to absolute one
        
        $('img').each(function(){
            var cur_src = $(this).attr('src');
            if (cur_src.substr(0, 7) != 'http://') {
                $(this).attr('src', url + cur_src);
                //alert($(this).attr('src'));
            }
        });
        // ---------------------------------------------------------------

        var content = innerXHTML(document.documentElement);
        htmlCode.value = utf8_encode(content);
    }
    document.forms["pdf-form"].submit();
}