var expDays = 0; // number of days the cookie should last
var exp = new Date();
exp.setTime(exp.getTime() + (expDays*24*60*60*1000));
var eChart_oldStepDesc = "";
var eChart_Step1 = "Select eChart template";
var eChart_Step2 = "Provide associated team/consumer";
var eChart_Step3 = "Provide general chart information";
var eChart_Step4 = "Provide vertical axis information";
var eChart_Step5 = "Optionally provide Instructions/Notes";
var eChart_Step6 = "Optionally provide annotation information";
var eChart_Step7 = "Review Your Selections";

var AnalysisOptionDisplayState;

var PSRSelection;

function GetCookie (name) {
  var arg = name + "=";
  var alen = arg.length;
  var clen = document.cookie.length;
  var i = 0;
  while (i < clen) {
  var j = i + alen;
  if (document.cookie.substring(i, j) == arg)
  return getCookieVal (j);
  i = document.cookie.indexOf(" ", i) + 1;
  if (i == 0) break;
  }
  return null;
}

function SetCookie (name, value) {
  var argv = SetCookie.arguments;
  var argc = SetCookie.arguments.length;
  var expires = (argc > 2) ? argv[2] : null;
  var path = (argc > 3) ? argv[3] : null;
  var domain = (argc > 4) ? argv[4] : null;
  var secure = (argc > 5) ? argv[5] : false;
  document.cookie = name + "=" + escape (value) +
  ((expires == null) ? "" : ("; expires=" + expires.toGMTString())) +
  ((path == null) ? "" : ("; path=" + path)) +
  ((domain == null) ? "" : ("; domain=" + domain)) +
  ((secure == true) ? "; secure" : "");
}

function DeleteCookie (name) {
  var exp = new Date();
  exp.setTime (exp.getTime() - 1);
  var cval = GetCookie (name);
  document.cookie = name + "=" + cval + "; expires=" + exp.toGMTString();
}

function getCookieVal(offset) {
  var endstr = document.cookie.indexOf (";", offset);
  if (endstr == -1)
  endstr = document.cookie.length;
  return unescape(document.cookie.substring(offset, endstr));
}
function saveme() {
  if (document.forms[0].save_login.checked) {
  SetCookie("login",document.forms[0].CustomerId.value, exp, "/") ;
  SetCookie("password",document.forms[0].Password.value, exp, "/") ;
//alert("login is: " + GetCookie("login"))
//alert("password is: " + GetCookie("password"))

 }
}

function loginfocus() {
  if (document.loginform) {
    document.loginform.loginID.focus();
  }
}

function PSRSelectionClick() {
	alert("entered PSRSelectionClick")
	PSRSelection = document.forms[0].m_ddlSurvey.value 
	alert(PSRSelection)
	alert(form.elements["m_lblAnalysisDetails2"])
	form.elements["m_lblAnalysisDetails2"] = PSRSelection
	alert(form.elements["m_lblAnalysisDetails2"])
	alert(document.forms[0].m_lblAnalysisDetails2.value)
	document.forms[0].m_lblAnalysisDetails2.value = PSRSelection
	alert(document.forms[0].m_lblAnalysisDetails2.value)
	alert("exited PSRSelectionClick")
	
}

function FrequencySelectionClick() {
	tag = document.getElementById('m_ddlNewReportFrequency').value;
	ShowHideAnalysisOpt(tag);
}

function ResetAnalysisOptions()
{
	var DisplayValue = GetCookie("AnalysisOptionDisplayState");
	if (DisplayValue)
	{
		document.getElementById('AnalysisOptional_img').src = (DisplayValue == "none") ? sPlus : sMinus;
		document.getElementById('AnalysisOptional').style.display = DisplayValue;
	}
	AnalysisSelectionClick();
}

// On the Common Analysis page this routine is called when the user changes their selection
//	for system-created for manually-created Status Reports
function AutoOrManualSelectionClick() {
	tag = document.getElementById('m_lstManualOrAuto').value;
	if (tag == 1)
	{
		// Manually-created is selected so remove and grey-out scheduling objects
		document.getElementById('AutoCreationSchedule').style.display = "none";
	} else
	{
		// System-created is selected so show "Monthly" scheduling objects by default
		document.getElementById('AutoCreationSchedule').style.display = "block";
	}
}

function ReportFrequencySelectionClick() {
	tag = document.getElementById('m_ddlNewReportFrequency').value;
	var Frequency_Daily = 20;
	var Frequency_Weekly = 30;
	var Frequency_Monthly = 40;
	var Frequency_Quarterly = 50;
	var Frequency_Annually = 60;

	if (tag == Frequency_Daily)
	{
		document.getElementById('FreqWeekly_Days').style.display = "none";
		document.getElementById('FreqMonthly_Days').style.display = "none";
		document.getElementById('FreqQuarterly_Days').style.display = "none";
		document.getElementById('FreqYearly_Days').style.display = "none";
	}
	else if (tag == Frequency_Weekly)
	{
		document.getElementById('FreqWeekly_Days').style.display = "block";
		document.getElementById('FreqMonthly_Days').style.display = "none";
		document.getElementById('FreqQuarterly_Days').style.display = "none";
		document.getElementById('FreqYearly_Days').style.display = "none";
	}
	else if (tag == Frequency_Monthly)
	{
		document.getElementById('FreqWeekly_Days').style.display = "none";
		document.getElementById('FreqMonthly_Days').style.display = "block";
		document.getElementById('FreqQuarterly_Days').style.display = "none";
		document.getElementById('FreqYearly_Days').style.display = "none";
	}
	else if (tag == Frequency_Quarterly)
	{
		document.getElementById('FreqWeekly_Days').style.display = "none";
		document.getElementById('FreqMonthly_Days').style.display = "none";
		document.getElementById('FreqQuarterly_Days').style.display = "block";
		document.getElementById('FreqYearly_Days').style.display = "none";
	}
	else if (tag == Frequency_Annually)
	{
		document.getElementById('FreqWeekly_Days').style.display = "none";
		document.getElementById('FreqMonthly_Days').style.display = "none";
		document.getElementById('FreqQuarterly_Days').style.display = "none";
		document.getElementById('FreqYearly_Days').style.display = "block";
	}
}

// When the user selects a new Analysis Item this routine is called and
//	will show/hide the necessary ancillary selections
function AnalysisSelectionClick() {
	tag = document.getElementById('m_lstAnalysis').value;
	ShowHideAnalysisOpt(tag);
}

function ShowHideAnalysisOpt(AnalysisId) {
	var Analysis_PSRScores = 100;
	var Analysis_PSRSummary = 103;
	var Analysis_PSRMissingScores = 106;
	var Analysis_PSRMnAvMx = 107;
	var Analysis_PSRCompletedbyFreq = 109;
	var Analysis_PSRCompleted = 102;
	var Analysis_PSRStandards = 101;
	var Analysis_PSRTeams = 105;
	var Analysis_eChartSummary = 104;
	var Analysis_NewsletterDefn = 108;
	var Analysis_BestPSRStandards = 115;

	if (AnalysisId == Analysis_PSRScores)
	{
		document.getElementById('IncludeStandardsOpt').style.display = "block";
		document.getElementById('NumberToConsiderOpt').style.display = "none";
		document.getElementById('ChartSizeOpt').style.display = "block";
		document.getElementById('AnnotationLocationOpt').style.display = "block";
		document.getElementById('ShowOutOfRangeOpt').style.display = "none";
		document.getElementById('FrequencyOpt').style.display = "block";
		// do NOT display a "none option" message 
		document.getElementById('m_txtNoAnalysisOptions').style.display = "none";
	} else if (AnalysisId == Analysis_PSRSummary) {
		document.getElementById('IncludeStandardsOpt').style.display = "none";
		document.getElementById('NumberToConsiderOpt').style.display = "none";
		document.getElementById('ChartSizeOpt').style.display = "none";
		document.getElementById('AnnotationLocationOpt').style.display = "none";
		document.getElementById('ShowOutOfRangeOpt').style.display = "none";
		document.getElementById('FrequencyOpt').style.display = "none";

		// need to display a "none option" message here
		document.getElementById('m_txtNoAnalysisOptions').style.display = "block";
	} else if (AnalysisId == Analysis_PSRMissingScores) {
		document.getElementById('IncludeStandardsOpt').style.display = "none";
		document.getElementById('NumberToConsiderOpt').style.display = "none";
		document.getElementById('ChartSizeOpt').style.display = "none";
		document.getElementById('AnnotationLocationOpt').style.display = "none";
		document.getElementById('ShowOutOfRangeOpt').style.display = "none";
		document.getElementById('FrequencyOpt').style.display = "none";

		// need to display a "none option" message here
		document.getElementById('m_txtNoAnalysisOptions').style.display = "block";
	} else if (AnalysisId == Analysis_PSRMnAvMx) {
		document.getElementById('IncludeStandardsOpt').style.display = "none";
		document.getElementById('NumberToConsiderOpt').style.display = "none";
		document.getElementById('ChartSizeOpt').style.display = "block";
		document.getElementById('AnnotationLocationOpt').style.display = "block";
		document.getElementById('ShowOutOfRangeOpt').style.display = "none";
		document.getElementById('FrequencyOpt').style.display = "none";

		// do NOT display a "none option" message 
		document.getElementById('m_txtNoAnalysisOptions').style.display = "none";
	} else if (AnalysisId == Analysis_PSRCompletedbyFreq) {
		document.getElementById('IncludeStandardsOpt').style.display = "none";
		document.getElementById('NumberToConsiderOpt').style.display = "none";
		document.getElementById('ChartSizeOpt').style.display = "block";
		document.getElementById('AnnotationLocationOpt').style.display = "block";
		document.getElementById('ShowOutOfRangeOpt').style.display = "none";
		document.getElementById('FrequencyOpt').style.display = "block";

		// do NOT display a "none option" message 
		document.getElementById('m_txtNoAnalysisOptions').style.display = "none";
	} else if (AnalysisId == Analysis_PSRCompleted) {
		document.getElementById('IncludeStandardsOpt').style.display = "none";
		document.getElementById('NumberToConsiderOpt').style.display = "none";
		document.getElementById('ChartSizeOpt').style.display = "block";
		document.getElementById('AnnotationLocationOpt').style.display = "block";
		document.getElementById('ShowOutOfRangeOpt').style.display = "none";
		document.getElementById('FrequencyOpt').style.display = "none";

		// do NOT display a "none option" message 
		document.getElementById('m_txtNoAnalysisOptions').style.display = "none";
	} else if ((AnalysisId == Analysis_PSRStandards) || (AnalysisId == Analysis_BestPSRStandards)) {
		document.getElementById('IncludeStandardsOpt').style.display = "block";
		document.getElementById('NumberToConsiderOpt').style.display = "block";
		document.getElementById('ChartSizeOpt').style.display = "block";
		document.getElementById('AnnotationLocationOpt').style.display = "block";
		document.getElementById('ShowOutOfRangeOpt').style.display = "none";
		document.getElementById('FrequencyOpt').style.display = "none";

		// do NOT display a "none option" message 
		document.getElementById('m_txtNoAnalysisOptions').style.display = "none";
	} else if (AnalysisId == Analysis_PSRTeams) {
		document.getElementById('IncludeStandardsOpt').style.display = "none";
		document.getElementById('NumberToConsiderOpt').style.display = "none";
		document.getElementById('ChartSizeOpt').style.display = "none";
		document.getElementById('AnnotationLocationOpt').style.display = "none";
		document.getElementById('ShowOutOfRangeOpt').style.display = "none";
		document.getElementById('FrequencyOpt').style.display = "none";

		// need to display a "none option" message here
		document.getElementById('m_txtNoAnalysisOptions').style.display = "block";
	} else if (AnalysisId == Analysis_eChartSummary) {
		document.getElementById('IncludeStandardsOpt').style.display = "none";
		document.getElementById('NumberToConsiderOpt').style.display = "none";
		document.getElementById('ChartSizeOpt').style.display = "none";
		document.getElementById('AnnotationLocationOpt').style.display = "none";
		document.getElementById('ShowOutOfRangeOpt').style.display = "block";
		document.getElementById('FrequencyOpt').style.display = "none";

		// do NOT display a "none option" message 
		document.getElementById('m_txtNoAnalysisOptions').style.display = "none";
	} else if (AnalysisId == Analysis_NewsletterDefn) {
		document.getElementById('IncludeStandardsOpt').style.display = "none";
		document.getElementById('NumberToConsiderOpt').style.display = "none";
		document.getElementById('ChartSizeOpt').style.display = "none";
		document.getElementById('AnnotationLocationOpt').style.display = "none";
		document.getElementById('ShowOutOfRangeOpt').style.display = "none";
		document.getElementById('FrequencyOpt').style.display = "none";

		// need to display a "none option" message here
		document.getElementById('m_txtNoAnalysisOptions').style.display = "block";
	}		
}

function eChartAdd_OnClick(step) {
	alert("entered eChartAdd_OnClick()")
}

function eChartAdd_OnMouseOver(step) {
	document.images["m_imgStep" + step].src = "../images/interface/circle" + step + "lt.jpg";
	eChart_oldStepDesc = document.getElementById("m_lblstepDesc").innerHTML;
	document.getElementById("m_lblstepDesc").innerHTML = eval( "eChart_Step" + step);
}
function eChartAdd_OnMouseOut(step) {
	document.images["m_imgStep" + step].src = "../images/interface/circle" + step + ".jpg";
	document.getElementById("m_lblstepDesc").innerHTML = eChart_oldStepDesc;
}

function SelectDeselectAll(selectFlag) { 
	var frm=document.forms[0]; 
	for (i=0;i<frm.length; i++){ 
		if (frm.elements[i].type=="checkbox")
		{
			if (selectFlag==true) { 
				frm.elements[i].checked=true;
			} else { 
				frm.elements[i].checked=false;
			}
		}
	}
}

function ResetDropDownList(MyList, MyField)
{
	document.getElementById(MyList).selectedIndex = 0;
	document.getElementById(MyField).value = "";
}

function SaveSelect(MyList, MyField)
{
	document.getElementById(MyField).value = document.getElementById(MyList).options[document.getElementById(MyList).selectedIndex].value;
}

function ClearField(MyField)
{
	document.getElementById(MyField).value = "";
}

function MoveListItem(FromList, ToList, FullMember)
{

//alert(FromList);
//alert(ToList);
//alert(FullMember);
//	alert(document.forms[0][FromList].count);
}

function check_login() {
	var lc = GetCookie("login")
	var ps = GetCookie("password")

	if(lc != "") {
		if(ps != "") { 
			document.forms[0].CustomerId.value = lc
			document.forms[0].Password.value = ps
			document.forms[0].submit()
		}
	}
}

function go_back()
{
	window.history.go(-1);
}

function close()
{
	window.close();
}

function ImagePopup(strImage)
{
	if (strImage == null)
		alert("Unknown Id found in Add operation.  Please contact web administrator.");
	window.open("../visitor/ImagePopup.aspx?str=" + strImage, "ImagePoup", "top=40, left=40, width=600, height=425");
}

function MoreInfoPopup(ID)
{
	if (ID == null)
		alert("Unknown Id found in Add operation.  Please contact web administrator.");
	window.open("../PSR/PSRMoreInfo.aspx?ID=" + ID, "MoreInfoPoup", "top=40, left=40, width=270, height=300");
}

function HoNOSMoreInfoPopup(ID)
{
	if (ID == null)
		alert("Unknown Id found in Add operation.  Please contact web administrator.");
	window.open("../honos/HoNOSMoreInfo.aspx?ID=" + ID, "HoNOSMoreInfoPoup", "top=40, left=40, width=370, height=400");
}

function FormMoreInfoPopup(ID)
{
	if (ID == null)
		alert("Unknown Id found in PSRAdd.aspx.  Please contact web administrator.");
	window.open("../SIR/SIRMoreInfo.aspx?ID=" + ID, "FormMoreInfoPoup", "top=40, left=40, width=270, height=300");
}

function ChartDescPopup()
{

	var ID;
	var pick;
	pick = document.forms[0].m_lstAnalysis.selectedIndex;
	if (pick >= 0)
	{
		ID = document.forms[0].m_lstAnalysis.options[pick].value;
		window.open("../Analysis/ChartMoreInfo.aspx?ID=" + ID, "ChartMoreInfoPoup", "top=40, left=40, width=600, height=670, scrollbars=yes");
	}
	else
		alert("Must select a valid Chart.");
}

function fillInDetail(){
//    tag = document.getElementById(whichEl);

	alert("entered fillInDetail")
//	var newValue = "New value"
//	document.forms[0].m_lblAnalysisDetails.value = "...new..."
	alert("exit fillInDetail-" + document.forms[0].m_lblAnalysisDetails.text)
	alert("exit fillInDetail-")
}

///////////////////////////////////////////////////////////////////////////////
// These are for the Privacy Policy popup windows                            //
///////////////////////////////////////////////////////////////////////////////


// This is the popup window for the Privacy Policy page from links on the home level pages only.
function windowprivacyhome() {
  window.open('privacy_policy.htm','privacy','width=248,height=146,menubar=no,toolbar=no,location=no,scrollbars=no,resizable=yes,status=no,directories=no');
}

// This is the popup window for the Privacy Policy page from links on the internal pages.
function windowprivacy() {
  window.open('../privacy_policy.htm','privacy','width=248,height=146,menubar=no,toolbar=no,location=no,scrollbars=no,resizable=yes,status=no,directories=no');
}

