/*******************************************************************
 *	Cookie Functions
 *******************************************************************/
// Check for a cookie's existance
function getCookie(name) {
	var nameEQ = name + "=";
	var ca = document.cookie.split(';');

	for(var i=0;i < ca.length;i++) {
		var c = ca[i];
		while (c.charAt(0)==' ') c = c.substring(1,c.length);
		if (c.indexOf(nameEQ) == 0) return c.substring(nameEQ.length,c.length);
	}
	return null;
}
// Create a new cookie
function setCookie(name, value, expires, path, domain, secure) {
	var expDate		= new Date(expires);
	var curCookie	= name + "=" + escape(value) +
		((expires) ? "; expires=" + expDate.toGMTString() : "") +
		((path) ? "; path=" + path : "") +
		((domain) ? "; domain=" + domain : "") +
		((secure) ? "; secure" : "");
	document.cookie = curCookie;
}
// Delete an existing cookie
function deleteCookie(name, path, domain) {
	if (getCookie(name)) {
		var curCookie	= name + "=" +
			((path) ? "; path=" + path : "") +
			((domain) ? "; domain=" + domain : "") +
			"; expires=Thu, 01-Jan-70 00:00:01 GMT";
		document.cookie = curCookie;
	}
}

// Play a CVP video
function microPlay(url,override) {
	if(isAdPlaying) {	//prevent changing video during ad playback
		return;
	}

	if (url.match(/^\/video/)) {
		cvp_playVideo(url,override);
	} else if (url.match(/index.html/)) {	//for the occasion where there is a link to a doc on the site
		window.location.href=url;
	}

	return true;
}

// Create local versions of any variables appended to the URL string
function getURLVars() {
	// Check for hash variables as they take precedence over search string variables
	if (window.location.hash.length != 0 && window.location.hash != '#') {
		var url_vars = window.location.hash;
	// Check for search string variables
	} else if (window.location.search.length != 0) {
		var url_vars = window.location.search;
	// No URL variables exists, so stop processing
	} else {
		return;
	}
	// Remove unnecessary characters
	url_vars = url_vars.replace(/\?/,'');
	url_vars = url_vars.replace(/\#/,'');
	var searchAttributes = url_vars.split('&');
	for (var i=0; i<searchAttributes.length; i++) {
		var items = searchAttributes[i].split('=');
		// Set the variables if they already exist.  If it's not defined, ignore it.
		if ( typeof( window[ items[0] ] ) != "undefined" ) {
			eval(items[0]+" = '"+items[1]+"';");
		}
	}
}

// Pop up a printable version of the article
function GetPrintURL()
{
	var myURL;
	var newURL;

	myURL = window.location;
	myURL = String(myURL);
	newURL = myURL + '?RenderForPrint=1';

	window.open(newURL, "mywindow","location=0,status=1,scrollbars=1,width=700,height=800");
}