﻿function SurveyProps_GetClientID(o)
{
	var p=o; while(p.getAttribute("c_clientID")==null)p=p.parentNode;
	return p.getAttribute("c_clientID");
}
//---------------------------------------------------
function SurveyProps_ClickCheckBox(o)
{
	var clientID = SurveyProps_GetClientID(o);
	document.getElementById( clientID + "_" + o.getAttribute("c_hidID") ).value = o.checked ? "y" : "n";
}
//---------------------------------------------------
function SurveyProps_SetColor(o)
{
	var clientID = SurveyProps_GetClientID(o);
	var args = new Function();
	args.color = o.style.backgroundColor;
	var bg = showModalDialog( "/Panels/SelectColor/SelectColor.aspx", args, "font-family:Verdana; font-size:12; dialogWidth:520px; dialogHeight:290px; help:no; status:no; resizable:no;  scroll:no;" );
	if (bg != null)
	{
		o.style.backgroundColor = bg;
		document.getElementById( clientID + "_" + o.getAttribute("c_hidID") ).value = bg;
	};
}
//---------------------------------------------------
function SurveyProps_DDLChanged(o)
{
	var clientID = SurveyProps_GetClientID(o);
	document.getElementById( clientID + "_" + o.getAttribute("c_hidID") ).value = o.value;
}



//---------------------------------------------------
//--- RefreshParams
//---------------------------------------------------
function SurveyProps_RefreshParams(clientID)
{
	var tbl=document.getElementById(clientID+"_tblParams");
	while(tbl.rows.length>1) tbl.deleteRow(1);
	var divXml = document.getElementById(clientID+"_divParamsXml");
	var a=divXml.childNodes;
	for(var j=0; j<a.length; j++)
	{
		var param = a[j];
		var tr = g_global.InsertRow(tbl);
		var td, img;
		
		tr.setAttribute("c_index",j);
		
		SurveyProps_AddCell(tr, "150px",  50, param, "c_name");
		SurveyProps_AddCell(tr, "350px", 200, param, "c_value");
		td = g_global.InsertCell(tr);
		img = document.createElement("IMG");	td.appendChild(img);
		img.style.width = "16";
		img.style.height = "16";
		img.src = "/images/16x16/del.gif";
		img.onclick = SurveyProps_DelParam;
	}
	SurveyProps_SetParamsXml(clientID);
}
//---------------------------------------------------
//--- AddParam
//---------------------------------------------------
function SurveyProps_AddParam(o)
{
	var clientID = SurveyProps_GetClientID(o);
	var divXml = document.getElementById(clientID+"_divParamsXml");
	var param = document.createElement("DIV");
	divXml.appendChild(param);
	param.setAttribute("c_name"," ");
	param.setAttribute("c_value"," ");
	param.setAttribute("c_isEmpty","y");

	SurveyProps_RefreshParams(clientID);
}
//---------------------------------------------------
//--- AddCell
//---------------------------------------------------
function SurveyProps_AddCell(tr,width,maxLen,param,attrName)
{
	var v = unescape(param.getAttribute(attrName));
	if (attrName=="c_value" && v==" " && param.getAttribute("c_isEmpty")!="n")
	{
		v = "";
	}
	var td = g_global.InsertCell(tr);
	var txt = document.createElement("INPUT");	td.appendChild(txt);
	txt.type			= "text";
	txt.style.width		= width;
	txt.style.border	= "solid 1px #0000aa";
	txt.style.backgroundImage = "url(/images/small-grid.gif)";
	txt.maxLength		= maxLen;
	txt.value			= v;
	txt.setAttribute("c_attr",attrName);
	txt.onchange		= SurveyProps_TxtChanged;
	return td;
}
//---------------------------------------------------
//--- TxtChanged
//---------------------------------------------------
function SurveyProps_TxtChanged(e)
{
	//::::::::::::::::::::::::::::: IE, NC, FF, Opera, Safari, IE(Mac)
	var ev = (e) ? e : window.event;
	var o = (ev.srcElement) ? ev.srcElement : ev.target;
	if (o.nodeType == 3) o = o.parentNode;	// defeat Safari bug
	//::::::::::::::::::::::::::::: 
	var clientID = SurveyProps_GetClientID(o);
	tr = o; while(tr.nodeName!="TR")tr=tr.parentNode;
	var divXml = document.getElementById(clientID+"_divParamsXml");
	var param = divXml.childNodes[tr.getAttribute("c_index")];
	var v = o.value;
	param.setAttribute("c_isEmpty", v==""?"y":"n");
	if (v=="") v=" ";
	param.setAttribute(o.getAttribute("c_attr"), escape(v));
	SurveyProps_SetParamsXml(clientID);
}
//---------------------------------------------------
//--- SetParamsXml
//---------------------------------------------------
function SurveyProps_SetParamsXml(clientID)
{
	var divXml = document.getElementById(clientID+"_divParamsXml");
	document.getElementById(clientID+"_hidParamsXml").value = divXml.innerHTML;
}
//---------------------------------------------------
//--- DelParam
//---------------------------------------------------
function SurveyProps_DelParam(e)
{
	//::::::::::::::::::::::::::::: IE, NC, FF, Opera, Safari, IE(Mac)
	var ev = (e) ? e : window.event;
	var o = (ev.srcElement) ? ev.srcElement : ev.target;
	if (o.nodeType == 3) o = o.parentNode;	// defeat Safari bug
	//::::::::::::::::::::::::::::: 
	var tr = o; while(tr.nodeName!="TR")tr=tr.parentNode;
	try
	{
		for(var j=0; j<tr.cells.length; j++)
		{
			var c=tr.cells[j];
			c.setAttribute("c_bgcolor",c.style.backgroundColor);
			c.style.backgroundColor = "gold";
		}
	}catch(e){}

	if (confirm("Do you want to delete selected parameter?"))
	{
		var clientID = SurveyProps_GetClientID(o);
		var divXml = document.getElementById(clientID+"_divParamsXml");
		var param = divXml.childNodes[tr.getAttribute("c_index")];
		divXml.removeChild(param);
		SurveyProps_RefreshParams(clientID);
	}
	else
	{
		try
		{
			for(var j=0; j<tr.cells.length; j++)
			{
				var c=tr.cells[j];
				c.style.backgroundColor = c.getAttribute("c_bgcolor");
			}
		}catch(e){}
	}
}













//---------------------------------------------------
//--- RefreshFilters
//---------------------------------------------------
function SurveyProps_RefreshFilters(clientID)
{
	var tbl=document.getElementById(clientID+"_tblFilters");
	while(tbl.rows.length>1) tbl.deleteRow(1);
	var divXml = document.getElementById(clientID+"_divFiltersXml");
//alert(divXml.outerHTML);

	var a=divXml.childNodes;
	for(var j=0; j<a.length; j++)
	{
		var param = a[j];
		var tr = g_global.InsertRow(tbl);
		var td, img;
		
		tr.setAttribute("c_index",j);
		//...		
		SurveyProps_AddCell2(tr, param, "c_exp",	"10px");
		SurveyProps_AddCell2(tr, param, "c_name",	"250px",  50 );
		SurveyProps_AddCell2(tr, param, "c_type",	"120px");
//		SurveyProps_AddCell2(tr, param, "c_showInList");
		//...
		td = g_global.InsertCell(tr);
		td.appendChild( document.createTextNode(" ") );
		//...
		td = g_global.InsertCell(tr);
		img = document.createElement("IMG");	td.appendChild(img);
		img.style.width = "16";
		img.style.height = "16";
		img.src = "/images/16x16/del.gif";
		img.onclick = SurveyProps_DelFilter;
		//...
		SurveyProps_RefreshFilterDetails(clientID,param,tbl,j);
	}
	SurveyProps_SetFiltersXml(clientID);
}
//---------------------------------------------------
//--- SurveyProps_AppendTextBox
//---------------------------------------------------
function SurveyProps_AppendTextBox(cont,maxLen,width,border,fontSize)
{
	var txt2 = document.createElement("INPUT");	cont.appendChild(txt2);
	txt2.type = "text";
	if (maxLen	!= null) try{ txt2.maxLength	= maxLen; }catch(e){}
	if (width	!= null) try{ txt2.style.width	= width; }catch(e){}
	if (border	!= null) try{ txt2.style.border = border; }catch(e){}
	if (fontSize!= null) try{ txt2.style.fontSize = fontSize; }catch(e){}
	return txt2;
}
//---------------------------------------------------
//--- RefreshFilterDetails
//---------------------------------------------------
function SurveyProps_RefreshFilterDetails(clientID,param,tbl,ind)
{
	var exp = param.getAttribute("c_exp");
	if (exp!="y")
		return;
		
	var tr = g_global.InsertRow(tbl);
	tr.setAttribute("c_index",ind);
	var td, img;
	var div2,tbl2,tr2,td2;
	var type = param.getAttribute("c_type");

	td = g_global.InsertCell(tr);
	td.appendChild( document.createTextNode(" ") );
	
	td = g_global.InsertCell(tr);
	td.colSpan = 3;
	
	tbl2 = document.createElement("TABLE");	td.appendChild(tbl2);
	tbl2.cellPadding = 2;
	tbl2.cellSpacing = 0;
	tr2 = g_global.InsertRow(tbl2);
	//.............................
	//...Items
	//.............................
	var txt2;
	var divP;
	var p,l2;
//alert(param.outerHTML);
	td2 = g_global.InsertCell(tr2);
	if (type == "TextBox")
	{
		var maxLen = ""; try{maxLen= param.getAttribute("txt_maxLength");}catch(e){}if(maxLen==null)maxLen="";
		var width  = ""; try{width = param.getAttribute("txt_width");}catch(e){}	if(width==null)width="";
		maxLen = unescape(maxLen);
		width = unescape(width);

		tr2.setAttribute("c_index",ind);
		
		//...max length
		td2.appendChild( document.createTextNode("Max length:") );
		txt2 = SurveyProps_AppendTextBox(td2,3,"30px",null,"9pt");
		txt2.setAttribute("c_attr", "txt_maxLength");
		txt2.setAttribute("c_refreshAfterChange", "y");
		txt2.onchange = SurveyProps_TxtChanged2;
		txt2.value = maxLen;
		td2.appendChild( document.createTextNode(" ") );
		td2.appendChild( document.createTextNode(" ") );
		td2.appendChild( document.createTextNode(" ") );
		td2.appendChild( document.createTextNode(" ") );
		td2.appendChild( document.createTextNode(" ") );
		
		//...width
		td2.appendChild( document.createTextNode("Width:") );
		txt2 = SurveyProps_AppendTextBox(td2,4,"40px",null,"9pt");
		txt2.setAttribute("c_attr", "txt_width");
		txt2.setAttribute("c_refreshAfterChange", "y");
		txt2.onchange = SurveyProps_TxtChanged2;
		txt2.value = width;
		td2.appendChild( document.createTextNode("px") );
		
		//...Preview TextBox
		tr2 = g_global.InsertRow(tbl2);	//tr2.setAttribute("c_index",ind);
		td2 = g_global.InsertCell(tr2);
		td2.appendChild( document.createTextNode("Preview:") );
		divP = document.createElement("DIV"); 
		td2.appendChild(divP);
		txt2 = SurveyProps_AppendTextBox(divP,maxLen,width,"solid 1px #999999","9pt");
		txt2.style.backgroundImage = "url(/images/small-grid.gif)";
		//txt2.onchange	= SurveyProps_ItemsChanged2;
		//txt2.setAttribute("c_index",ind);
	}
	else if (type == "Function")
	{
//alert(document.getElementById(clientID+"_divFunctions").outerHTML);
		var a = document.getElementById(clientID+"_divFunctions").childNodes;
		if (a.length == 0)
		{
			td2.appendChild( document.createTextNode("No custom functions defined for current survey:") );
			td2.style.color = "red";
		}
		else
		{
			var v = param.getAttribute("c_value");
			td2.appendChild( document.createTextNode("Select function:") );
			//...
			tr2 = g_global.InsertRow(tbl2);
			td2 = g_global.InsertCell(tr2);
			p = document.createElement("SELECT"); td2.appendChild(p);
			var ok = false;
			for(var j=0; j<a.length; j++)
			{
				var func = a[j];
				var fid	 = func.getAttribute("c_id");
				var name = func.getAttribute("c_name");
				//var path = func.getAttribute("c_path");
				var opt  = document.createElement("OPTION");	p.options.add(opt);
				opt.text = name;
				opt.value = fid;
				if (fid==v){ opt.selected = true; ok=true; }
			}
			if (!ok)
			{
				p.options[0].selected = true;
				param.setAttribute("c_value", p.options[0].value);
//alert(param.outerHTML);
			}
			p.onchange = SurveyProps_FunctionChanged2;
		}
	}
	else
	{
		td2.style.width = "300px";
		td2.appendChild( document.createTextNode("Enter items for selected control (one item per line) in either format: TEXT=VALUE or [[TEXT]]=VALUE:") );
		txt2 = document.createElement("TEXTAREA");	td2.appendChild(txt2);
		txt2.style.width = "300px";
		txt2.style.height = "100px";
		txt2.style.backgroundImage = "url(/images/small-grid.gif)";
		txt2.style.border = "solid 1px #999999";
		txt2.style.fontSize = "9px";
		txt2.onchange	= SurveyProps_ItemsChanged2;
		txt2.setAttribute("c_index",ind);
		//...image Arrow
		td2 = g_global.InsertCell(tr2);
		img = document.createElement("IMG");	td2.appendChild(img);
		img.src = "/images/arrBigRight2.gif";
		img.style.width = "17";
		img.style.height = "126";
		//.............................
		//...Preview
		//.............................
		td2 = g_global.InsertCell(tr2);
		td2.vAlign = "top";
		td2.appendChild( document.createTextNode("Preview:") );
		divP = document.createElement("DIV"); 
		td2.appendChild(divP);
	
		if (type=="DropDownList" || type=="ListBox")
		{
			p = document.createElement("SELECT");
			if (type=="ListBox") p.size = 5;
		}
		else if (type=="CheckBoxList" || type=="RadioButtonList")
		{
			p = document.createElement("TABLE");
		}
		divP.appendChild(p);

		var tblErr = document.createElement("TABLE");
		td2.appendChild( tblErr );
		var arr = param.childNodes;
		var ssItems="";
	//alert(type + "     " + param.outerHTML);
		var nn = 0;
		for(var j=0; j<arr.length; j++)
		{
			nn++;
			var item = arr[j];
			var txt = item.getAttribute("c_text");
			var val = item.getAttribute("c_value");
			var err = g_global.Trim( item.getAttribute("c_error") );
			ssItems += (ssItems==""?"":"\n") + txt + " = " + val;
			
			if (err!="")
			{
				txt = "Line " + nn + " (Error)";
			}

			var ccc;
			if (type=="DropDownList" || type=="ListBox")
			{
				ccc = document.createElement("OPTION");
				ccc.text = txt;
				ccc.value = val;
				p.options.add(ccc);
			}
			else if (type=="CheckBoxList" || type=="RadioButtonList")
			{
				var tr3 = g_global.InsertRow( p );
				var td3 = g_global.InsertCell( tr3 );
					td3.style.width = 16;
				var cb3 = document.createElement("INPUT");
				if (type=="CheckBoxList")
				{
					cb3.type = "checkbox";
				}
				else
				{
					cb3.type = "radio";
					cb3.name = "lstradio"+ind;
				}
				td3.appendChild( cb3 );
				ccc = g_global.InsertCell( tr3 );
				ccc.appendChild( document.createTextNode(txt) );
			}
			
			if (err!="")
			{
				ccc.style.color = "red";
				var trErr = g_global.InsertRow(tblErr);
				trErr.style.color = "red";
				var tdErr = g_global.InsertCell(trErr);
				g_global.InsertImage( tdErr, "/images/16x16/evError.gif", 16, 16 );
				tdErr.vAlign = "top";
				tdErr = g_global.InsertCell(trErr);
				tdErr.appendChild( document.createTextNode( txt + ": " + err) );
			}
		}
		txt2.value = ssItems;
	}
}
//---------------------------------------------------
//--- AddFilter
//---------------------------------------------------
function SurveyProps_AddFilter(o)
{
	var clientID = SurveyProps_GetClientID(o);
	var divXml = document.getElementById(clientID+"_divFiltersXml");
	var param = document.createElement("DIV");
	divXml.appendChild(param);
	param.setAttribute("c_exp","n");
	param.setAttribute("c_name"," ");
	param.setAttribute("c_type","DropDownList");
	param.setAttribute("c_showInList","y");
//	param.setAttribute("c_value"," ");
//	param.setAttribute("c_isEmpty","y");

	SurveyProps_RefreshFilters(clientID);
}
//---------------------------------------------------
//--- AddCell2
//---------------------------------------------------
function SurveyProps_AddCell2(tr,param,attrName, width,maxLen)
{
	var td = g_global.InsertCell(tr);
	
	if (attrName == "c_exp")
	{
		var exp = param.getAttribute("c_exp");
		td.align = "center";
		td.style.width = width;
		img = document.createElement("IMG");	td.appendChild(img);
		img.style.width = "16";
		img.style.height = "16";
		img.src = "/images/16x16/" + (exp=="y" ? "minus.gif" : "plus.gif");
		img.onclick = SurveyProps_PMClick;
		img.style.cursor = "hand";
	}
	else if (attrName == "c_name")
	{
		var v = unescape(param.getAttribute(attrName));
		if (attrName=="c_value" && v==" " && param.getAttribute("c_isEmpty")!="n")
		{
			v = "";
		}
		var txt = document.createElement("INPUT");	td.appendChild(txt);
		txt.type			= "text";
		txt.style.width		= width;
		txt.style.border	= "solid 1px #0000aa";
		txt.style.backgroundImage = "url(/images/small-grid.gif)";
		txt.maxLength		= maxLen;
		txt.value			= v;
		txt.setAttribute("c_attr",attrName);
		txt.onchange		= SurveyProps_TxtChanged2;
	}
	else if (attrName == "c_type")
	{
		td.style.width		= width;
		var v = unescape(param.getAttribute(attrName));
		if (v!="DropDownList" && v!="RadioButtonList" && v!="CheckBoxList" && 
			v!="ListBox" && v!="TextBox" && v!="Function")
		{
			v = "DropDownList";
		}
		var sel = document.createElement("SELECT");	td.appendChild(sel);
		SurveyProps_AddOption(sel,"CheckBoxList",	"CheckBoxList",		v);
		SurveyProps_AddOption(sel,"DropDownList",	"DropDownList",		v);
		SurveyProps_AddOption(sel,"ListBox",		"ListBox",			v);
		SurveyProps_AddOption(sel,"RadioButtonList","RadioButtonList",	v);
		SurveyProps_AddOption(sel,"TextBox",		"TextBox",			v);
		SurveyProps_AddOption(sel,"Function (if available)",		"Function",			v);
		sel.onchange = SurveyProps_SelectionChanged2;
		sel.style.width = "220px";
	}
	else if (attrName == "c_showInList")
	{
		var ch = param.getAttribute("c_showInList");
		td.align = "center";
		img = document.createElement("IMG");	td.appendChild(img);
		img.style.width = "16";
		img.style.height = "16";
		img.src = "/images/16x16/" + (ch=="y"?"Check1.gif":"Uncheck.gif");
		img.onclick = SurveyProps_CheckFilter;
		img.style.cursor = "hand";
	}
	return td;
}
//---------------------------------------------------
//--- AddOption
//---------------------------------------------------
function SurveyProps_AddOption(sel,txt,val,valSelected)
{
	var opt = document.createElement("OPTION");
	sel.options.add(opt);
	opt.text = txt;
	opt.value= val;
	opt.selected = val==valSelected;
}
//---------------------------------------------------
//--- TxtChanged2
//---------------------------------------------------
function SurveyProps_TxtChanged2(e)
{
	//::::::::::::::::::::::::::::: IE, NC, FF, Opera, Safari, IE(Mac)
	var ev = (e) ? e : window.event;
	var o = (ev.srcElement) ? ev.srcElement : ev.target;
	if (o.nodeType == 3) o = o.parentNode;	// defeat Safari bug
	//::::::::::::::::::::::::::::: 
	var clientID = SurveyProps_GetClientID(o);
	tr = o; while(tr.nodeName!="TR")tr=tr.parentNode;
	var divXml = document.getElementById(clientID+"_divFiltersXml");
	var param = divXml.childNodes[tr.getAttribute("c_index")];
	var v = o.value;
	param.setAttribute("c_isEmpty", v==""?"y":"n");
	if (v=="") v=" ";
	param.setAttribute(o.getAttribute("c_attr"), escape(v));
	SurveyProps_SetFiltersXml(clientID);
	if (o.getAttribute("c_refreshAfterChange")=="y")
		SurveyProps_RefreshFilters(clientID);
}
/*
//---------------------------------------------------
//--- ItemsBlur2
//---------------------------------------------------
function SurveyProps_ItemsBlur2(e)
{
	//::::::::::::::::::::::::::::: IE, NC, FF, Opera, Safari, IE(Mac)
	var ev = (e) ? e : window.event;
	var o = (ev.srcElement) ? ev.srcElement : ev.target;
	if (o.nodeType == 3) o = o.parentNode;	// defeat Safari bug
	//::::::::::::::::::::::::::::: 
	if (o.getAttribute("c_changed")=="y")
		return SurveyProps_DoChangeItems2(o);
	else
		return true;
}
*/
//---------------------------------------------------
//--- ItemsChanged2
//---------------------------------------------------
function SurveyProps_ItemsChanged2(e)
{
	//::::::::::::::::::::::::::::: IE, NC, FF, Opera, Safari, IE(Mac)
	var ev = (e) ? e : window.event;
	var o = (ev.srcElement) ? ev.srcElement : ev.target;
	if (o.nodeType == 3) o = o.parentNode;	// defeat Safari bug
	//::::::::::::::::::::::::::::: 
	var clientID = SurveyProps_GetClientID(o);
	var divXml = document.getElementById(clientID+"_divFiltersXml");
	var param = divXml.childNodes[o.getAttribute("c_index")];
	var arr = o.value.split("\n");
	var txt,val,err,ss,i1;
	while(param.childNodes.length > 0)param.removeChild(param.childNodes[0]);
	for(var j=0; j<arr.length; j++)
	{
		txt = "";
		val = "";
		err = "";
		ss = arr[j];
		ss = g_global.Replace(ss,"\r","");
		ss = g_global.Trim(ss);
		i1=ss.indexOf("[[");
		if (i1==0)
		{
			ss = ss.substr(i1+2);
			i1 = ss.indexOf("]]");
			if (i1==-1)
			{
				txt = ss;
				err = "No ending brackets ]].";
			}
			else
			{
				txt = ss.substr(0,i1);
				ss=ss.substr(i1+2);
				i1=ss.indexOf("=");
				if (i1==-1)	err = "Can not find sign '='.";
			}
		}
		else
		{
			txt = ss;
			i1=ss.indexOf("=");
			if (i1==-1)
				err = "Can not find sign '='.";
			else
				txt = ss.substr(0,i1);
		}
		
		if (err=="")
		{
			txt = g_global.Trim(txt);
			if (txt=="")	
				err = "TEXT can not be empty.";
			else
			{
				val = ss.substr(i1+1);	
				val = g_global.Trim(val);
				if (val=="") err = "VALUE can not be empty.";
			}
		}
		var c = document.createElement("SPAN");		param.appendChild(c);		
		c.setAttribute("c_text", txt + " ");
		c.setAttribute("c_value", val + " ");
		c.setAttribute("c_error", err + " ");
	}
	SurveyProps_SetFiltersXml(clientID);
	SurveyProps_RefreshFilters(clientID);
//	o.setAttribute("c_changed","y");
//	return SurveyProps_DoChangeItems2(o);
}
/*
//---------------------------------------------------
//--- ItemsChanged2
//---------------------------------------------------
function SurveyProps_DoChangeItems2(o)
{
	var clientID = SurveyProps_GetClientID(o);
	var divXml = document.getElementById(clientID+"_divFiltersXml");
	var param = divXml.childNodes[o.getAttribute("c_index")];
	var arr = o.value.split("\n");
	while(param.childNodes.length > 0)param.removeChild(param.childNodes[0]);
	for(var j=0; j<arr.length; j++)
	{
		var txt,val,ss,i1;
		ss = arr[j];
		ss = g_global.Replace(ss,"\r","");
		i1=ss.indexOf("[[");
		if (i1==0)
		{
			ss = ss.substr(i1+2);
			i1 = ss.indexOf("]]");
			if (i1==-1){return SurveyProps_ShowError(o, "Error in line " + (j+1) + ":\nline contains starting square-brackets [[ but not ending one ]].");}
			txt = ss.substr(0,i1);
			ss=ss.substr(i1+2);
			i1=ss.indexOf("=");
			if (i1==-1){return SurveyProps_ShowError(o, "Error in line " + (j+1) + ":\nCan not find sign '='.");}
		}
		else
		{
			i1=ss.indexOf("=");
			if (i1==-1){return SurveyProps_ShowError(o, "Error in line " + (j+1) + ":\nCan not find sign '='.");}
			txt = ss.substr(0,i1);
		}
		
		txt = g_global.Trim(txt);
		if (txt==""){return SurveyProps_ShowError(o, "Error in line " + (j+1) + ":\nTEXT can not be empty.");}
		
		val = ss.substr(i1+1);	
		val = g_global.Trim(val);
		if (val==""){return SurveyProps_ShowError(o, "Error in line " + (j+1) + ":\nVALUE can not be empty.");}
		
		var c = document.createElement("SPAN");		param.appendChild(c);		
		c.setAttribute("c_text", txt);
		c.setAttribute("c_value", val);
	}
	SurveyProps_SetFiltersXml(clientID);
	SurveyProps_RefreshFilters(clientID);
	o.setAttribute("c_changed","y");
	return true;
}
*/
/*
//---------------------------------------------------
//--- ShowError
//---------------------------------------------------
function SurveyProps_ShowError(o,msg)
{
//o.focus();
//o.select();
//o.click();
//return false;

	try{tb.focus();}catch(e){}
	try{tb.select();}catch(e){}
	try{tb.click();}catch(e){}
	alert(msg);
	return false;
}
*/
//---------------------------------------------------
//--- SetFiltersXml
//---------------------------------------------------
function SurveyProps_SetFiltersXml(clientID)
{
	var divXml = document.getElementById(clientID+"_divFiltersXml");
	document.getElementById(clientID+"_hidFiltersXml").value = divXml.innerHTML;
}
//---------------------------------------------------
//--- DelFilter
//---------------------------------------------------
function SurveyProps_DelFilter(e)
{
	//::::::::::::::::::::::::::::: IE, NC, FF, Opera, Safari, IE(Mac)
	var ev = (e) ? e : window.event;
	var o = (ev.srcElement) ? ev.srcElement : ev.target;
	if (o.nodeType == 3) o = o.parentNode;	// defeat Safari bug
	//::::::::::::::::::::::::::::: 
	var tr = o; while(tr.nodeName!="TR")tr=tr.parentNode;
	try
	{
		for(var j=0; j<tr.cells.length; j++)
		{
			var c=tr.cells[j];
			c.setAttribute("c_bgcolor",c.style.backgroundColor);
			c.style.backgroundColor = "gold";
		}
	}catch(e){}

	if (confirm("Do you want to delete selected filter?"))
	{
		var clientID = SurveyProps_GetClientID(o);
		var divXml = document.getElementById(clientID+"_divFiltersXml");
		var param = divXml.childNodes[tr.getAttribute("c_index")];
		divXml.removeChild(param);
		SurveyProps_RefreshFilters(clientID);
	}
	else
	{
		try
		{
			for(var j=0; j<tr.cells.length; j++)
			{
				var c=tr.cells[j];
				c.style.backgroundColor = c.getAttribute("c_bgcolor");
			}
		}catch(e){}
	}
}
//---------------------------------------------------
//--- CheckFilter
//---------------------------------------------------
function SurveyProps_CheckFilter(e)
{
	//::::::::::::::::::::::::::::: IE, NC, FF, Opera, Safari, IE(Mac)
	var ev = (e) ? e : window.event;
	var o = (ev.srcElement) ? ev.srcElement : ev.target;
	if (o.nodeType == 3) o = o.parentNode;	// defeat Safari bug
	//::::::::::::::::::::::::::::: 
	var tr = o; while(tr.nodeName!="TR")tr=tr.parentNode;
	var clientID = SurveyProps_GetClientID(o);
	var divXml = document.getElementById(clientID+"_divFiltersXml");
	var param = divXml.childNodes[tr.getAttribute("c_index")];
	var ch = param.getAttribute("c_showInList");
	param.setAttribute("c_showInList", ch=="y"?"n":"y");
	SurveyProps_RefreshFilters(clientID);
}
//---------------------------------------------------
//--- PMClick
//---------------------------------------------------
function SurveyProps_PMClick(e)
{
	//::::::::::::::::::::::::::::: IE, NC, FF, Opera, Safari, IE(Mac)
	var ev = (e) ? e : window.event;
	var o = (ev.srcElement) ? ev.srcElement : ev.target;
	if (o.nodeType == 3) o = o.parentNode;	// defeat Safari bug
	//::::::::::::::::::::::::::::: 
	var tr = o; while(tr.nodeName!="TR")tr=tr.parentNode;
	var clientID = SurveyProps_GetClientID(o);
	var divXml = document.getElementById(clientID+"_divFiltersXml");
	var param = divXml.childNodes[tr.getAttribute("c_index")];
	var exp = param.getAttribute("c_exp");
	param.setAttribute("c_exp", exp=="y"?"n":"y");
	SurveyProps_RefreshFilters(clientID);
}
//---------------------------------------------------
//--- SurveyProps_SelectionChanged2
//---------------------------------------------------
function SurveyProps_SelectionChanged2(e)
{
	//::::::::::::::::::::::::::::: IE, NC, FF, Opera, Safari, IE(Mac)
	var ev = (e) ? e : window.event;
	var o = (ev.srcElement) ? ev.srcElement : ev.target;
	if (o.nodeType == 3) o = o.parentNode;	// defeat Safari bug
	//::::::::::::::::::::::::::::: 
	var tr = o; while(tr.nodeName!="TR")tr=tr.parentNode;
	var clientID = SurveyProps_GetClientID(o);
	var divXml = document.getElementById(clientID+"_divFiltersXml");
	var param = divXml.childNodes[tr.getAttribute("c_index")];
	//var v = param.getAttribute("c_type");
	param.setAttribute("c_type", o.value);
	SurveyProps_RefreshFilters(clientID);
}
//---------------------------------------------------
//--- SurveyProps_FunctionChanged2
//---------------------------------------------------
function SurveyProps_FunctionChanged2(e)
{
	var ev = g_global.GetEvent(e);
	var o = ev.srcElement;
	//::::::::::::::::::::::::::::: 
	var clientID = SurveyProps_GetClientID(o);
	var divXml = document.getElementById(clientID+"_divFiltersXml");

	var tag = o; while(tag.getAttribute("c_index")==null || tag.getAttribute("c_index")=="")tag=tag.parentNode;
	var param = divXml.childNodes[tag.getAttribute("c_index")];
	
	param.setAttribute("c_value", o.value);
	SurveyProps_RefreshFilters(clientID);
}

//---------------------------------------------------
function SurveyProps_ShowHideCmdButton(o)
{
	var clientID = SurveyProps_GetClientID(o);
	SurveyProps_RefreshCmdButtonsText(clientID);
}
//---------------------------------------------------
function SurveyProps_RefreshCmdButtonsText(clientID)
{
	var a="Save,SaveCont,Submit,Cancel".split(",");
	for(var j=0; j<a.length; j++)
	{
		var tbl= $get(clientID+"_tblShowButton_"+a[j]);
		var cb = $get(clientID+"_cbShow"+a[j]);
		tbl.style.display = cb.checked ? "block" : "none";
		//var txt= $get(clientID+"_txtButton_"+a[j]);
		//txt.disabled = !cb.checked;
		//txt.style.backgroundColor = cb.checked ? "#ffffff" : "#dcdcdc";
	}
}
