function getElementsByAttribute(oElm, strTagName, strAttributeName, strAttributeValue)
{
	if (oElm == document)
		return $('"' + strTagName + "[" + strAttributeName + " ='" + strAttributeValue + "']" + '"');
	else
		return $('"' + oElm + " " + strTagName + "[" + strAttributeName + " ='" + strAttributeValue + "']" + '"');
}

//------------------------------------------------------------------------------
function processQuestion(QID, flag)
{
   marker = false;
   if (flag>1)
      marker = true
   else
      marker = false;
	
   if (marker)
   {
	   	$("#"+QID).css("color", "gray");
		$("#"+QID).parent().children(".inputs").children("input").attr("checked",false);
		$("#"+QID).parent().children(".inputs").children("input").attr("disabled", true);
	}
	else
	{
	   	$("#"+QID).css("color", "black");
		$("#"+QID).parent().children(".inputs").children("input").attr("checked",false);
		$("#"+QID).parent().children(".inputs").children("input").attr("disabled", false);
	}
}

//------------------------------------------------------------------------------
function enableTextField(textFieldName, flag)
{
     $("input[name='" + textFieldName + "']").attr("disabled", !flag);
}

//------------------------------------------------------------------------------
function markAnswered(inputItem)
{
	if (inputItem.type=="text")
	{
		if (inputItem.value != "")
			inputItem.setAttribute("answered", true);
		else
			inputItem.setAttribute("answered", false);
	}
	else
	{
		if (inputItem.type=="checkbox")
		{
			if ($("input[dispname='" + inputItem.getAttribute("dispname") +"']:checked").length > 0)
				$("input[dispname='" + inputItem.getAttribute("dispname") +"']").each(function() {$(this).attr("answered", true);});
			else
				$("input[dispname='" + inputItem.getAttribute("dispname") +"']").each(function() {$(this).attr("answered", false);});
		}
		else
		{
			$("input[dispname='" + inputItem.getAttribute("dispname") +"']").each(function() {$(this).attr("answered", true);});
		}
	}	
}

//------------------------------------------------------------------------------
function doSubmit()
{
	var arrElements;
	var count=0;
	var errMsg;
	var waitMsg;
	var qCurrent;
	var qLast = " ";
	var realError = false;
	
	errMsg = "<div class='header'>You missed to answer some questions!</br>"
	waitMsg = "<div class='header'>Please wait while processing your answers!</div><br><span align='center'><img src='facebox/loading.gif'></span>"
	$("#SubmitButton").attr("disabled", "disabled");
	$("input[mandatory='True'][answered='false']:enabled").each(function(i) 
		{
			qCurrent = $(this).attr("name");
			//if (qCurrent != qLast)
			//	errMsg += qCurrent + ", "; 
			qLast = qCurrent;
			$("#"+$(this).attr("name")+"_status").addClass("qError");
			$(this).click(function() 
				{
					$("#"+$(this).attr("name")+"_status").removeClass("qError").addClass("prefix");
				});
			count+=1;
		});
	
	if(count>0)
	{
		realError = true;
		if (realError)
		{
			$("#SubmitButton").removeAttr("disabled");
			errMsg += "</div><br></br><span style='font-size: 12px; font-weight: bold;'>Please answer all questions marked with <img src='images/cross.png'></span>"
			$.facebox(errMsg);
		}
	}
	if (!realError)
	{
		$("input[HasTextField='true']:checked").each(function(i) 
			{
				$(this).attr("value", $("input[name='" + $(this).attr("name") + "_text']").attr("value"));
			});
		$.facebox(waitMsg);
		document.Survey.submit();		
	}
}
