﻿/* Querystring helper
- Call with a query string key to retrieve the value (or blank, if it's got no value). Null if not found
ie: ?id=1&flag   queryString("id") == "1"    queryString("flag") == ""
- Call with no args to return an object containing all pairs (each key is a property. If the key has no value, the property will be null)
ie: ?id=1&flag   queryString() == {id:"1", flag:null}
- Call with null to retrieve the first item on the querystring:
ie: ?somecode&id=1   queryString(null) == "somecode"   queryString("id") == 1
*/
jQuery.queryString = function (name) {
	if (name === undefined) {
		if (!location.search) return {};
		var parts = location.search.substr(1).split('&');
		var ret = {};
		for (var x = 0; x < parts.length; x++) {
			var cutat = parts[x].indexOf('=');
			if (cutat == -1) ret[parts[x]] = null;
			else ret[parts[x].substr(0, cutat)] = decodeURIComponent(parts[x].substr(cutat + 1));
		}
		return ret;
	}
	else if (name === null) {
		if (!location.search) return null;
		var m = /\?(.*?)(?:&|$)/.exec(location.search);
		return m == null ? null : decodeURIComponent(m[1]);
	}
	else {
		if (!location.search) return null;
		var rx = new RegExp("[?&]" + name + "(?:=(.*?)(?:&|$))?", "i");
		var m = rx.exec(location.search);
		return m == null ? null : decodeURIComponent(m[1]);
	}
}

function CosmosWriteFlash(containerID, movieURL, swfWidth, swfHeight, flashVars) {
	jQuery('#' + containerID).flash(
		{ src: movieURL, width: swfWidth, height: swfHeight, flashvars: flashVars, scale: "noscale", wmode: "opaque" },
		{ version: 8, update: false },
		function (htmlOptions) { this.innerHTML = jQuery.fn.flash.transform(htmlOptions); }
	);
}

//Form
/*$(function () {
	$("#contactViaEmail").click(NewsletterPopup);
	$("#contactViaPhone").click(NewsletterPopup);
	$("#contactViaNone").click(NewsletterPopup);
	function NewsletterPopup() {
		if ($("#contactViaEmail")[0].checked) {
			$("#phoneAsterisk").css("display", "none");
			$("#emailAsterisk").css("display", "");
		}
		else if ($("#contactViaPhone")[0].checked) {
			$("#phoneAsterisk").css("display", "");
			$("#emailAsterisk").css("display", "none");
		}
		else {
			$("#phoneAsterisk").css("display", "none");
			$("#emailAsterisk").css("display", "none");
		}
	}
	NewsletterPopup();
});*/
