/* === 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
		
		// Set Up Titles/Footer 
		var cb_footer, currentDate, currentYear
		var GWLFootEn,GWLFootFr
		var LLFootEn,LLFootFr
		var CLFootEn,CLFootFr
		var CLFCFootEn,CLFCFootFr
		var CLREFootEn,CLREFootFr
		var LIFECOFootEn,LIFECOFootFr
		var LRGFootEn,LRGFootFr
		var PdadminFootEn, PdadminFootFr
		
		currentDate = new Date();
		currentYear = currentDate.getFullYear();
		
		// GWL
		GWLFootEn = '&copy; The Great-West Life Assurance Company 2005 - ' ;
		GWLFootFr =  '&copy; La Great-West, compagnie d&rsquo;assurance-vie, 2005 - ';
		
		// PDAdmin
		PdadminFootEn = 'Powered By <a href="http://www.pdadmin.com" target="_blank">PDAdmin</a> Group - ';
		PdadminFootFr = 'Powered By <a href="http://www.pdadmin.com" target="_blank">PDAdmin</a> Group - ';
		
		document.links[i].onclick = function () {
			// Title
			var myTitle = get_arg_val('title', this.href);
			if (myTitle == 'gwlEn') { 
				myTitle = GWLFootEn + currentYear; 
			} else if (myTitle == 'gwlFr') { 
				myTitle = GWLFootFr + currentYear; 
			} else if (myTitle == 'pdadminEn') { 
				myTitle = PdadminFootEn + currentYear; 
			} else if (myTitle == 'pdadminFr') { 
				myTitle = PdadminFootFr + currentYear; 
			} else { 
				myTitle = GWLFootEn + currentYear;
			}
			
			// Height
			var myHeight = get_arg_val('height', this.href);
			if (myHeight == false) { myHeight = "75%"; }
			
			// Height
			var myWidth = get_arg_val('width', this.href);
			if (myWidth == false) { myWidth = "75%"; }
			
			// Colorbox
			$.fn.colorbox({
				href:this.href,
				iframe:true,
				height:myHeight,
				width:myWidth,
				title:myTitle,
				overlayClose:false
			}); 
			
			return false;
		}
	}
}

/* Function for New Windows When all Else Fails with ?blank and ?popup */
function newWindow(url) {
	void window.open(url);
}