/**
*
*  Javascript trim, ltrim, rtrim
*  http://www.webtoolkit.info/
*
**/
 
function trim(str, chars) {
	return ltrim(rtrim(str, chars), chars);
}
 
function ltrim(str, chars) {
	chars = chars || "\\s";
	return str.replace(new RegExp("^[" + chars + "]+", "g"), "");
}
 
function rtrim(str, chars) {
	chars = chars || "\\s";
	return str.replace(new RegExp("[" + chars + "]+$", "g"), "");
}

function openQuestions(typeQuestions)
{
	var elt;
	if(document.getElementById('sm_task_id'))
	{ 
		elt = document.getElementById('sm_task_id');
		openQuestions.tabInd = elt.getAttribute("tabindex"); // required to set tabindex of results
		
		var task = document.getElementById('sm_task_id').value; 
		var questions = document.getElementById('task_questions');
		if(task!="")
		{
			var request = getHTTPObject();
			request.onreadystatechange = function() {
				var selboxes,fields,txtareas;
				
				if(request.readyState==4)
				{
					if(request.responseText==undefined) { //if nothing returned
						questions.innerHTML = ""; 
						questions.style.display = "none";
					}else{
						//this is what happens once complete
						questions.innerHTML =request.responseText;
						questions.style.display = "block";  
						
						//// Added by Yosi 29 Apr 2010 - set tabindex for quote.php
						if(openQuestions.tabInd != null)
						{
							selboxes = questions.getElementsByTagName("select");
							fields = questions.getElementsByTagName("input");
							txtareas = questions.getElementsByTagName("textarea");
							for(var i = 0; i < selboxes.length; i++)
							{
								selboxes[i].setAttribute("tabindex",openQuestions.tabInd);
							}
							for(var j = 0; j < fields.length; j++)
							{
								if(fields[j].type != "hidden")
								{
									fields[j].setAttribute("tabindex",openQuestions.tabInd);
								}
							}
							for(var k = 0; k < txtareas.length; k++)
							{
								txtareas[j].setAttribute("tabindex",openQuestions.tabInd);
							}
						}
						//// EOF: added
					}
				} 
			}; 
			request.open("GET","/ajax_sm_questions.php?sm_task_id="+task+"&type="+typeQuestions,true);
			request.send(null);
		}
		//return 0; 
   }
}
