
function QueryStringDict(inLocation) { // Same as script.cs.
	if(!inLocation.search) return null;
	var qs = decodeURIComponent(inLocation.search);
	if(qs) {
		var qsDict = {};
		qs = qs.substring(1, qs.length).split('&');
		for(var i = 0; i < qs.length; i++) {
			var kvp = qs[i].split('=');
			qsDict[kvp[0]] = kvp[1];
		}
		return qsDict;
	}
	return null;
}

function MailTo(anchor, name, innerHtml /* opt */) {
	var email = name + "@" + "pdfediting.com";
	anchor.href = "mail" + "to" + ":" + email;
	anchor.innerHTML = innerHtml == undefined ? email : innerHtml;
}

function MM_preloadImages() { //v3.0
  var d=document; if(d.images){ if(!d.MM_p) d.MM_p=new Array();
    var i,j=d.MM_p.length,a=MM_preloadImages.arguments; for(i=0; i<a.length; i++)
    if (a[i].indexOf("#")!=0){ d.MM_p[j]=new Image; d.MM_p[j++].src=a[i];}}
}

function MM_swapImgRestore() { //v3.0
  var i,x,a=document.MM_sr; for(i=0;a&&i<a.length&&(x=a[i])&&x.oSrc;i++) x.src=x.oSrc;
}

function MM_findObj(n, d) { //v4.01
  var p,i,x;  if(!d) d=document; if((p=n.indexOf("?"))>0&&parent.frames.length) {
    d=parent.frames[n.substring(p+1)].document; n=n.substring(0,p);}
  if(!(x=d[n])&&d.all) x=d.all[n]; for (i=0;!x&&i<d.forms.length;i++) x=d.forms[i][n];
  for(i=0;!x&&d.layers&&i<d.layers.length;i++) x=MM_findObj(n,d.layers[i].document);
  if(!x && d.getElementById) x=d.getElementById(n); return x;
}

function MM_swapImage() { //v3.0
  var i,j=0,x,a=MM_swapImage.arguments; document.MM_sr=new Array; for(i=0;i<(a.length-2);i+=3)
   if ((x=MM_findObj(a[i]))!=null){document.MM_sr[j++]=x; if(!x.oSrc) x.oSrc=x.src; x.src=a[i+2];}
}

function isEmail(string) {
	if (string.search(/^\w+((-\w+)|(\.\w+))*\@[A-Za-z0-9]+((\.|-)[A-Za-z0-9]+)*\.[A-Za-z0-9]+$/) != -1)
		return true;
	else
		return false;
}

// Social Bookmarking
function SocBookListItem(serviceName, serviceUrl) {
	var s = serviceUrl.replace("%URL%", encodeURIComponent(document.location.href));
	s = s.replace("%TITLE%", encodeURIComponent(document.title));
	document.write("<li id='Li" + serviceName + "'><a rel='nofollow' href='" + s + "' onclick='window.open(this.href); return false;'>" + serviceName + "</a></li>");
}

// Cookies
function MakeID() {
    var id = (new Date()).getTime();
    id = id + "_" + Math.random();
    return id;
}

function MySetCookie(inName, inValue) {
	if (inValue == "") inValue = "empty_value";
	var date = new Date();
	date.setFullYear(date.getFullYear() + 10);
	document.cookie = inName + "=" + escape(inValue) + "; expires=" + date.toGMTString();
}

function MySetCookieTemp(inName, inValue) {
	if (inValue == "") inValue = "empty_value";
	document.cookie = inName + "=" + escape(inValue);
}

function MyGetCookie(inName) {
	var theValue = "";
	var theCookie = document.cookie.split("; ");
	for (var i = 0; i < theCookie.length; i++) {
		var theCrumb = theCookie[i].split("=");
		if (inName == theCrumb[0]) {
			theValue = unescape(theCrumb[1]);
			break;
		}
	}
	if (theValue == "empty_value") theValue = "";
	return theValue;
}

// Copy and paste auto attribution.
function AutoAttrib(){
	var attribution = "<i>Source</i>: <a href='" + document.location + "'>" + document.location + "</a>";
	var c1 = document.createElement('span');
	document.body.appendChild(c1);
	if(window.getSelection) { // FF, Opera, Safari, Chrome
		var selection = window.getSelection();
		if (selection.isCollapsed) return true;
		var range = selection.getRangeAt(0);
		c1.appendChild(range.cloneContents());
		var link = document.createElement('p');
		link.innerHTML = attribution;
		c1.appendChild(link);
		selection.selectAllChildren(c1);
		window.setTimeout(function () {
			c1.parentNode.removeChild(c1);
			if(selection.setBaseAndExtent) selection.setBaseAndExtent(range.startContainer,range.startOffset,range.endContainer,range.endOffset);
			else selection.addRange(range); // FF, Opera
		}, 0);
	} else { // IE
		var oldLeft = document.documentElement.scrollLeft || document.body.scrollLeft;
		var oldTop = document.documentElement.scrollTop || document.body.scrollTop;		
		var range = document.selection.createRange();
		c1.innerHTML = range.htmlText + "<p>" + attribution + "</p>";
		var textRange = document.body.createTextRange();
		textRange.moveToElementText(c1);
		textRange.select();
		window.setTimeout(function () {
			c1.parentNode.removeChild(c1);
			if (range.text != "") {
				document.documentElement.scrollLeft = document.body.scrollLeft = oldLeft;
				document.documentElement.scrollTop = document.body.scrollTop = oldTop;
				range.select();
			}
        }, 0);
	}
	return true;
}

