﻿function TakeSurvey_ShowComments(o,surveyID,entryID,guidQ)
{
	var args= new Function();
	args.surveyID = surveyID;
	args.entryID = entryID;
	args.guidQ = guidQ;
	window.showModalDialog("/Panels/ShowComments/default.htm", args, 'dialogWidth:65em; dialogHeight:55em; center:yes; edge:raised; resizable:yes; scroll:auto; status:yes;');
	//window.showModalDialog("/Panels/ShowComments/default.htm?surveyID="+surveyID+"&entryID="+entryID+"&guidQ="+guidQ, null, 'dialogWidth:65em; dialogHeight:55em; center:yes; edge:raised; resizable:yes; scroll:auto; status:yes;');
	return false;
}
function ShowHelp(surveyID,guidQ)
{
	window.showModalDialog("ShowHelp.aspx?surveyID="+surveyID+"&guidQ="+guidQ, null, 'dialogWidth:300px; dialogHeight:300px; center:yes; edge:raised; resizable:yes; scroll:no; status:yes;');
}
//function TakeSurvey_ArrangeIFrame(iframeID)
//{
//	try
//	{
//		top.SurveyEntries_ArrangeIFrame( window, iframeID );
//	}
//	catch(e){}
//}
function TakeSurvey_CloseWindow(clientID)
{
	var hid	= document.getElementById(clientID+"_hidCookieValue");
	if (hid.value!="")
	{
		try{ window.top.SetCookie(hid.value);	}catch(e){}
	}
	
	try{	window.top.returnValue=true;	}catch(e){}
	try{	window.top.close();				}catch(e){}
}
function TakeSurvey_Completed(openerClientID,callback)
{
	try{top.returnValue=true;}catch(e){}
	if (callback!=null && callback!="")
		try{ eval("top.opener." + callback + "(openerClientID);"); }catch(e){}
}

function TakeSurvey_GetMainPanel(o)
{
	var p=o;while(p.getAttribute("c_token")!="MainSurveyPanel")p=p.parentNode;
	return p;
}
function TakeSurvey_GetClientID(o)
{
	var p=o;while(p.getAttribute("c_clientID")==null || p.getAttribute("c_clientID")=="")p=p.parentNode;
	return p.getAttribute("c_clientID");
}
function TakeSurvey_GetQstPanel(o)
{
	var p=o;while(p.getAttribute("c_t2")!="Q")p=p.parentNode;
	return p;
}


//--------------------------------------------------
function TakeSurvey_OnClickCheckbox(o,act)
{
	var enable =
		act == ""
		||
		act == "None"
		||
		(act == "WhenChecked_EnableWholeRow" && o.checked == true)
		||
		(act == "WhenChecked_DisableWholeRow" && o.checked == false)
		;
//alert(act);
	var tr=o;while(tr.tagName!="TR")tr=tr.parentNode;
	//var a=tr.cells;
	var a = tr.getElementsByTagName("INPUT");
	for(var j=0; j<a.length; j++)
	{
		var c=a[j];
		if (c!=o)
		{
			c.disabled = !enable;
			c.style.backgroundColor = enable ? "#ffffff" : "#dcdcdc";
			
			//...clear value of any textbox
			if (!enable)
			{
				if (c.type=="text") c.value="";
			}
		}
	}
}

//===============================================================
//=== make question visible or hide it
//===============================================================
function TakeSurvey_ShowHide()
{
}
//===============================================================
//=== click RadioButtonList or CheckBoxList
//===============================================================
function TakeSurvey_ClickRBL(o)
{
	var panQ = TakeSurvey_GetQstPanel(o);
//alert(panQ.getAttribute("v_refreshPage"));
		
	if (o.type=="checkbox")
	{
		TakeSurvey_RadioCheck_Click(o);
	}
	else 
	{
		var txt = document.getElementById(panQ.getAttribute("v_ansCtrlID") + "_Value");
		txt.value = o.id.substring(o.id.lastIndexOf("_")+1, o.id.length);
		
		//...if current radio is already checked then uncheck it
		if(panQ.getAttribute("v_selectedID") == o.id)
		{
			panQ.setAttribute("v_selectedID", "");		//...reset ID of checked radio (none is checked)
			o.checked = false;
		}
		else
		{
			panQ.setAttribute("v_selectedID", o.id);	//...store ID of currently checked radio
		}

		var a = panQ.getAttribute("v_trails").split(",");
		for(var j=0; j<a.length; j++)
		{
			var c = document.getElementById(panQ.getAttribute("v_ansCtrlID") + "_" + a[j]);
			TakeSurvey_RadioCheck_Click(c,panQ);
		}
	}
	
	if (panQ.getAttribute("v_refreshPage") == "y")
	{
		var clientID = TakeSurvey_GetClientID(o);
		document.getElementById(clientID+"_hidCommand").value = "";
		eval(document.getElementById(clientID+"_lbCommand").href);
	}
}
function TakeSurvey_RadioCheck_Click(o)
{
	var td=o; while(td.tagName!="TD")td=td.parentNode;
	var tr=td;while(tr.tagName!="TR")tr=tr.parentNode;
	for(var k=1; k<tr.cells.length; k++)
	{
		var o2 = tr.cells[k];
		a = o2.getElementsByTagName("INPUT");		for(var j=0;j<a.length;j++)TakeSurvey_Enabled(a[j], o.checked);
		a = o2.getElementsByTagName("SELECT");		for(var j=0;j<a.length;j++)TakeSurvey_Enabled(a[j], o.checked);
		a = o2.getElementsByTagName("TEXTAREA");	for(var j=0;j<a.length;j++)TakeSurvey_Enabled(a[j], o.checked);
		a = o2.getElementsByTagName("IMG");	
		for(var j=0;j<a.length;j++)
		{
			try{ a[j].setAttribute("v_enabled", o.checked?"y":"n");			}catch(e){}
			try{ a[j].style.filter	= o.checked ? "" : "alpha(opacity=25)";	}catch(e){}
			try{ a[j].style.cursor	= o.checked ? "pointer" : "default";	}catch(e){}
			try{ a[j].alt			= o.checked ? "Select Date" : "";		}catch(e){}
		}
	}
}
function TakeSurvey_Enabled(o,enabled)
{
	o.disabled = !enabled;
	o.style.backgroundColor = enabled ? "#ffffff" : "#dcdcdc";
}


//===============================================================
//=== click RadioButton or CheckBox in InputTable
//===============================================================
function TakeSurvey_ClickRbCb(o)
{
	var td=o; while(td.tagName!="TD")td=td.parentNode;
	var tr=td;while(tr.tagName!="TR")tr=tr.parentNode;

//	var panQ = TakeSurvey_GetQstPanel(o);
//alert(panQ.getAttribute("v_refreshPage"));
		
	if (o.type=="checkbox")
	{
//		TakeSurvey_RadioCheckInInputTable_Click(o);
	}
	else 
	{
//		var txt = document.getElementById(panQ.getAttribute("v_ansCtrlID") + "_Value");
//		txt.value = o.id.substring(o.id.lastIndexOf("_")+1, o.id.length);
		
		//...if current radio is already checked then uncheck it
		if(tr.getAttribute("v_selectedID") == o.id)
		{
			tr.setAttribute("v_selectedID", "");		//...reset ID of checked radio (none is checked)
			o.checked = false;
		}
		else
		{
			tr.setAttribute("v_selectedID", o.id);	//...store ID of currently checked radio
		}

//		var a = tr.getAttribute("v_trails").split(",");
//		for(var j=0; j<a.length; j++)
//		{
//			var c = document.getElementById(tr.getAttribute("v_ansCtrlID") + "_" + a[j]);
//			TakeSurvey_RadioCheckInInputTable_Click(c,tr);
//		}

	}
	
//	if (tr.getAttribute("v_refreshPage") == "y")
//	{
//		var clientID = TakeSurvey_GetClientID(o);
//		document.getElementById(clientID+"_hidCommand").value = "";
//		eval(document.getElementById(clientID+"_lbCommand").href);
//	}
}
function TakeSurvey_RadioCheckInInputTable_Click(o)
{
	var td=o; while(td.tagName!="TD")td=td.parentNode;
	var tr=td;while(tr.tagName!="TR")tr=tr.parentNode;
	for(var k=1; k<tr.cells.length; k++)
	{
		var o2 = tr.cells[k];
		a = o2.getElementsByTagName("INPUT");	for(var j=0;j<a.length;j++)TakeSurvey_Enabled(a[j], o.checked);
		a = o2.getElementsByTagName("SELECT");	for(var j=0;j<a.length;j++)TakeSurvey_Enabled(a[j], o.checked);
		a = o2.getElementsByTagName("IMG");	
		for(var j=0;j<a.length;j++)
		{
			try{ a[j].setAttribute("v_enabled", o.checked?"y":"n");			}catch(e){}
			try{ a[j].style.filter	= o.checked ? "" : "alpha(opacity=25)";	}catch(e){}
			try{ a[j].style.cursor	= o.checked ? "pointer" : "default";	}catch(e){}
			try{ a[j].alt			= o.checked ? "Select Date" : "";		}catch(e){}
		}
	}
}

//===============================================================
//=== process VisibilityRules
//===============================================================
function TakeSurvey_ExecVisRule(o,ctrlID)
{
//alert(o.outerHTML + "      " + ctrlID);
}

function TakeSurvey_AskToRemoveGroup(o)
{
//	var tr = o; while(tr.tagName!="TR")tr=tr.parentNode;
//	tr.style.backgroundColor = "yellow";
	var td = o; while(td.tagName!="TD")td=td.parentNode;
	var bg = td.style.backgroundColor;
	td.style.backgroundColor = "yellow";

	if (confirm("Do you want to remove selected group?"))
	{
		return true;
	}
	td.style.backgroundColor = bg;
	return false;
}

function TakeSurvey_Print()
{
	try
	{
		window.print();
	}
	catch(e){}

	return false;
	
//	var url = appPath + "Survey/Entries/PrintEntry/default.htm";
//	window.showModalDialog(url, args, 'dialogWidth:770px; dialogHeight:600px; center:yes; edge:raised; scroll:yes; resizable:yes; status:yes;');
}

//function PrintSurvey(appPath, surveyID, itemID)
function TakeSurvey_PrintSurvey(url)
{
	var ww = window.screen.availWidth - 100;
	var hh = window.screen.availHeight - 100;
	//var url = "/Survey/TakeSurvey.aspx?clientID="+clientID+"&sessid="+g_global.sessionID+"&time="+(new Date()).getTime();
//	var url = C_GLOBALBARIABLES.CurrentProtocolAndHost + 
//			"/Survey/TakeSurvey.aspx?forcessl=y&sertoken="+st+"&sessid="+g_global.sessionID+"&time="+(new Date()).getTime();
	
	if (window.showModalDialog)
	{
		var args = new Function();
		if (window.showModalDialog(url, args, "dialogWidth:"+ww+"px; dialogHeight:"+hh+"px; center:yes; edge:raised; resizable:yes; scroll:yes; status:yes;"))
		{
//			var prm = Sys.WebForms.PageRequestManager.getInstance();
//			prm._doPostBack(clientID+"_upView", '');
		}
	}
	else
	{
		window.open(url, "_blank", "width="+ww+"px,height="+hh+"px,location=no,menubar=no,toolbar=no,resizable=yes");
	}
//	var args = new Function();
//	args.SurveyID	= surveyID;
//	args.ItemID		= itemID;

//	var url = appPath + "Survey/Entries/PrintEntry/default.htm";
//	window.showModalDialog(url, args, 'dialogWidth:770px; dialogHeight:600px; center:yes; edge:raised; scroll:yes; resizable:yes; status:yes;');
}









function CalcScores(appPath,reportUrl) //surveyID, itemID)
{
	var args = new Function();
	args.ReportUrl = appPath + reportUrl;

	var url = appPath + "LinkedProjects/Reports/ScoreAlgo/default.htm";
	window.showModalDialog(url, args, 'dialogWidth:770px; dialogHeight:600px; center:yes; edge:raised; scroll:yes; resizable:yes; status:yes;');
}
//function ShowMessageBeforeStartingReview(totalNotAnsweredQuestions)
//{
//	ok = alert("Some questions were not answered.  Pages with unanswered questions are highlighted in red at the bottom of the page.");
//}



function ConfirmSave(o)
{
	var clientID = TakeSurvey_GetClientID(o);
	var ss = document.getElementById(clientID+"_hidMsg_Save").value;
	if (ss == "")
		ss = "Are you sure you want to save your responses? Notice that you may change and submit this questionnaire later.\n\n" +
			"Click OK to save and close window, or click Cancel to continue answering the questionnaire.";
	return confirm(ss);
}

function ConfirmToSubmitWithoutReview(clientID)
{
	if (ConfirmSubmition(clientID))//GetConfirmForSubmit(clientID))
	{
		document.getElementById(clientID+"_hidMode").value = "ReviewAnswers";
		document.getElementById(clientID+"_lbSubmit").click();
	}
}
function ConfirmToGoToReviewPage(clientID)
{
	var ss = document.getElementById(clientID+"_hidMsg_BeforeReview").value;
	if (ss == "")
		ss = "You did not answer all required questions and need to Review your answers.\n\n" +
			"Click [OK] to go to Review page.  Click [Cancel] to continue working on the survey.";
	if (confirm(ss))
	{
		document.getElementById(clientID+"_hidCommand").value = "GoToReviewPage";
		eval(unescape(document.getElementById(clientID+"_lbCommand").href)); //click();
	}
}
function ConfirmSubmition(clientID)
{
//	var ok = GetConfirmForSubmit(clientID);
//	return ok==true;
//}
//function GetConfirmForSubmit(clientID)
//{
	if (document.getElementById(clientID+"_hidIsAnonymous").value == "y")
	{
		return confirm("Do you want to SUBMIT your form?");
	}
	else
	{
		var ss = document.getElementById(clientID+"_hidMsg_Submit").value;
		if (ss == "")
			ss = "Are you sure you have completed the survey and wish to submit?\n" + 
				"Once you submit a survey, you cannot revise or update the survey later. \n\n" + 
				"Click [OK] to submit the survey.  Click [Cancel] to continue working on the survey.";
		return confirm(ss);
	}
}
function ShowMessageOnLoadReviewPage(clientID)
{
	var ss = document.getElementById(clientID+"_hidMsg_OnLoadReview").value;
	if (ss == "")
		ss = "Some questions were not answered. Pages with unanswered questions are highlighted in red at the bottom of the page.";
	alert(ss);
}


/*
function ConfirmSubmition1(clientID)
{
	var ss = document.getElementById(clientID+"_hidMsg_Submit1").value;
		if (ss == "")
			ss = "Are you sure you have completed the survey and wish to submit?\n" + 
				"Once you submit a survey, you cannot revise or update the survey later. \n\n" + 
				"Click [OK] to submit the survey.  Click [Cancel] to continue working on the survey.";
		return confirm(ss);
}
function ConfirmSubmition(clientID)
{
}
*/


function ConfirmSubmit(o,nn)
{
	if (nn=0)
	{
		return confirm("Do you want to SUBMIT your form?");
	}
	else
	{
		var clientID = TakeSurvey_GetClientID(o);
		var ss = document.getElementById(clientID+"_hidMsg_Submit1").value;
		if (ss == "")
			ss = "Are you sure you have completed the survey and wish to submit?\n" + 
				"Once you submit a survey, you cannot revise or update the survey later. \n\n" + 
				"Click [OK] to submit the survey.  Click [Cancel] to continue working on the survey.";
		return confirm(ss);
	}
}
function ConfirmCancel(o)
{
	var ok;
	var clientID = TakeSurvey_GetClientID(o);
	var ss = document.getElementById(clientID+"_hidMsg_Cancel").value;
	if (ss == "")
		ss = "Do you want to Cancel this survey and close window without saving your responses?";
	ok = confirm(ss);
	if (ok)
	{
		top.SurveyMode = "";
	}
	return ok;
}
function ConfirmCancelEmbedded(o)
{
	var clientID = TakeSurvey_GetClientID(o);
	var ss = document.getElementById(clientID+"_hidMsg_Cancel").value;
	if (ss == "")
		ss = "Do you want to Cancel this survey and close window without saving your responses?";
	var ok = confirm(ss);
	if (ok)
	{
		top.SurveyMode = "";
	}
	return ok;
}
function __EditCustomizableText(o)
{
	event.returnValue=false;
	event.cancelBubble=true;

	var args = new Function();
	var lb = document.getElementById('lbRefresh');
	args.refType	= o.customizing_refType;
	args.refID		= o.customizing_refID;
	args.controlID	= o.customizing_clientID;
	args.text		= o.innerHTML; //eval('o.'+o.customizing_textprop);
	
	o.runtimeStyle.backgroundColor = 'yellow';
	if (window.showModalDialog('../Panels/CustomizeText/default.htm', args, 'dialogWidth:550px; dialogHeight:400px; center:yes; edge:raised; resizable:yes; scroll:no; status:yes;'))
	{
		lb.click();
	}
	o.runtimeStyle.backgroundColor = '';
}
function SetCancelMessage(clientID)
{
	try{top.msg_x = document.getElementById(clientID + "_hidMsg_Cancel").value;}catch(e){}
}













/*
//--------------- old
function Radio_Click(oSrc,val,txtID)
{
	try
	{	
		var p=TakeSurvey_GetMainPanel(oSrc);
		var c=document.getElementById(p.c_clientID+"_"+txtID);	
		c.value = val;	
		c.fireEvent("onchange"); 
		
		//TakeSurvey_RadioCheck_Clicked(oSrc);
	}catch(e){}
}
//--------------- old
function CheckBox_Click(oSrc,ansID,numItems)
{
	try
	{	
		var p=TakeSurvey_GetMainPanel(oSrc);
		var o=document.getElementById(p.c_clientID+"_"+ansID+"_Value");

		var ss="";
		for(var j=0; j<numItems; j++)
		{
			var c = document.getElementById(p.c_clientID+"_"+ansID+"_"+j);
			if (c.tagName=="INPUT" && c.type=="checkbox")
			{
				if (c.checked==true)
					ss+=(ss==""?"":",") + j;
			}
		}
		o.value=ss;
		o.fireEvent("onchange");
		
		//TakeSurvey_RadioCheck_Clicked(oSrc);
	}catch(e){}
}
//--------------- old
function TakeSurvey_RadioCheck_Clicked(c)
{
//alert(c.outerHTML);
	var td=c;while(td.tagName!="TD")td=td.parentNode;
	td = td.nextSibling.nextSibling;
//alert(td==null);
	if (td!=null)
	{
		var tb = td.childNodes[0];
//alert(tb==null);
		tb.disabled = !c.checked;
		tb.style.backgroundColor = c.checked ? "#ffffff" : "#dcdcdc";
	}
}

//	var a;
//	var ct = td.getAttribute("v_ct");
//	var ind = 1*td.getAttribute("v_ind");
	


	if(panQ==null)panQ = TakeSurvey_GetQstPanel(o);
	var ctrlID = panQ.getAttribute("v_ansCtrlID") + "_" + ind;
	if		(ct == "TextBox")	ctrlID += "_txt";
	else if (ct == "Integer")	ctrlID += "_int";
	else if (ct == "Decimal")	ctrlID += "_dec";
	else if (ct == "DateTime")	ctrlID += "_
	var o2 = document.getElementById( ctrlID );  //c.parentNode.getAttribute("v_ctrlID") );
	
//alert(ct + "     " + c.getAttribute("v_ctrlID"));
	if (ct == "TextBox" || ct == "Integer" || ct == "Decimal")
	{
		TakeSurvey_Enabled(o2, o.checked);
	}
	else if (ct == "DateTime")
	{
		a = o2.getElementsByTagName("INPUT");	for(var j=0;j<a.length;j++)TakeSurvey_Enabled(a[j], o.checked);
		a = o2.getElementsByTagName("SELECT");	for(var j=0;j<a.length;j++)TakeSurvey_Enabled(a[j], o.checked);
		a = o2.getElementsByTagName("IMG");	
		for(var j=0;j<a.length;j++)
		{
			try{ a[j].setAttribute("v_enabled", o.checked?"y":"n");			}catch(e){}
			try{ a[j].style.filter	= o.checked ? "" : "alpha(opacity=25)";	}catch(e){}
			try{ a[j].style.cursor	= o.checked ? "pointer" : "default";	}catch(e){}
			try{ a[j].alt			= o.checked ? "Select Date" : "";		}catch(e){}
		}
	}

*/
