function parseUri (str) { var keys = ["source","protocol","authority","userInfo","user","password","host","port","relative","path","directory","file","query","anchor"]; var uri_re = /^(?:([^:\/?#]+):)?(?:\/\/((?:(([^:@]*)(?::([^:@]*))?)?@)?([^:\/?#]*)(?::(\d*))?))?((((?:[^?#\/]*\/)*)([^?#]*))(?:\?([^#]*))?(?:#(.*))?)/; var m = uri_re.exec(str); var uri = {}; for (i=0; i<14; i++) { uri[keys[i]] = m[i] || ""; } uri["queries"] = {}; uri["query"].replace(/(?:^|&)([^&=]*)=?([^&]*)/g, function ($0, $1, $2) { if ($1) { uri["queries"][$1] = $2; } }) return uri; }; var scripts = document.getElementsByTagName('script'); var index = scripts.length - 1; var currentScript = scripts[index]; var uri = parseUri(currentScript.src); if (uri["queries"]["p"] != undefined) { var ref = escape(window.location.href); var sub = (uri["queries"]["sub"]==undefined)? "":uri["queries"]["sub"]; document.write(""); }