// JavaScript Document

function traceme(msg){
	alert(msg);
}

function popup(url){
	popupWin=window.open(url, "popup", "menubar=no,resizable=no,scrollbars=no,status=no,toolbar=no,height=660,width=990");
	//popupWin=window.open(url, "popup", "location=yes,menubar=yes,toolbar=yes,resizable=no,scrollbars=no,status=no,height=660,width=990");

	popupWin.focus();
}
function closeWindow(){

	self.close();
}

function popupCompendium(url) {
	//remove any passed query string (should be irrelevant to Milestones Compendium), including question mark query token
	var reQueryString = /\?[\w- ./?%&=]*/gi;
	var compendiumURL = url.replace(reQueryString, "");	
	

	var qs = document.location.search; // grab browser's current query string

	
	if (qs!="" && qs.indexOf('startPage')!=-1) {
	// there was a caseStudyId param, so pass it along
		var reCaseStudy = /startPage=\d\d*/i; 
		var foundCaseStudy = reCaseStudy.exec(qs); 

		if (foundCaseStudy) {			
			compendiumURL = compendiumURL + '?' + foundCaseStudy[0];
		}
	} 

	popup(compendiumURL);
}

function getStartPage(url) {
	var caseStudyId = "-1";  //initialize return value...really just for "bad" URLs

	if (url && url!="" && url.indexOf('startPage')!=-1) {
	// there was a caseStudyId param, so parse it out

		var reCaseStudy = /startPage=(\d\d*)/i; 	// pattern matches entire param (name and value) case insensitively
		var foundCaseStudy = reCaseStudy.exec(url); 	// execute RegEx match...returns array with whole match
								// in array[0] and first parenthetical match in array[1]
								// ...in this instance, the case study id, or what's between the ()
		if (foundCaseStudy) {
			caseStudyId = foundCaseStudy[1];
		}
	} 

	return caseStudyId;
}