/* === Dynamic Converter === */

/* Function For Getting URL Variables */
function get_arg_val(arg, querystring) {
	var url = querystring;
	if (url.match(arg) != null) {
		var itm = url.split(arg+"=");
		itm = itm[1].split("&");
		itm = itm[0];
		return itm;
	}
	else return false;
}

/* Function for Fixing @ Symbol */
function fix_at_public(href) {
	var temp = href.replace('/_at_public/', '/@public/');
	return temp;
}

for (i=0; i<document.links.length; i++) { 
	document.links[i].href = fix_at_public(document.links[i].href);
	if (document.links[i].href.indexOf("javascript") != -1) {
		/* Do Nothing */
	} else if (document.links[i].href.indexOf("#") != -1) {
		/* For Bookmarks */
		var baseurl = window.location.href.split("#")[0];
		var anchorurl = document.links[i].href.split("#")[1];
		document.links[i].target = "_self"; 
		document.links[i].href = baseurl + "#" + anchorurl; 
	}  else if (document.links[i].href.indexOf("?blank") != -1 || document.links[i].href.indexOf("&blank") != -1) {
		/* For New Windows With Dimensions */
		if (document.links[i].href.indexOf("&height") != -1) {
			// Function To Display New Window
			document.links[i].onclick = function() {
				/* For New Windows using Dimensions */
				var height, width, top, left, settings; 
				height = get_arg_val('height', this.href);
				width = get_arg_val('width', this.href);
				top = (screen.height - height) / 2;
				left = (screen.width - width) / 2;
				if (top < 0) top = 0;
				if (left < 0) left = 0;
				settings = "height=" + height + " ,width=" + width + " ,top=" + top + " ,left=" + left;
				settings += " , location=1, status=1, toolbar=1, menubar=1, scrollbars=1, resizable=1";
				window.open(this.href, 'mypopup', settings); 
				return false; };
		} else {
			// For New Windows not using Dimensions
			document.links[i].target = "_blank";
		}
	} else if (document.links[i].href.indexOf("?popup") != -1 || document.links[i].href.indexOf("&popup") != -1) {
		/* For PopUps */
		document.links[i].onclick = function() {
			/* For New Windows using Dimensions */
			var height, width, top, left, settings; 
			height = get_arg_val('height', this.href);
			width = get_arg_val('width', this.href);
			top = (screen.height - height) / 2;
			left = (screen.width - width) / 2;
			if (top < 0) top = 0;
			if (left < 0) left = 0;
			settings = "height=" + height + " ,width=" + width + " ,top=" + top + " ,left=" + left;
			settings += " ,status=0, toolbar=0, menubar=1, scrollbars=1, resizable=1";
			window.open(this.href, 'mypopup', settings); 
			return false; };
	} else if (document.links[i].href.indexOf("?colorbox") != -1 || document.links[i].href.indexOf("&colorbox") != -1) {
		/* For Colorbox */
		document.links[i].className = "colorbox";
	}
}

/* Function for New Windows When all Else Fails with ?blank and ?popup */
function newWindow(url) {
	void window.open(url);
}