function hideLoadText()
{   var e = document.getElementById("loading");
    e.style.display = 'none';
}

function hideLoadTextMobile()
{   var e = document.getElementById("loadingMobile");
    e.style.display = 'none';
}

function selectAll()
{   document.form1.TextBoxEmbed.select();
}

//Auto Input Format---->
function doFormat(popit)
//{   if (isChecked == true)
	{   var oCtl = $get('ProblemText');
		var tb = oCtl.control;
		if (tb == null)
			tb = new Sys.Preview.UI.TextBox($get('ProblemText'));
		var name = tb.get_text();
		//only redraw if not the same...
		//if (savePrev != name)
		//{   savePrev = name;
		InputFormat.FormatInput(name, document.title, onFormatInputCompleted);

        if(popit == 'true')
        {   popDrop(); //auto-populate topics...
        }
}

function onFormatInputCompleted(result)
{   if(result != null)
	{   var oCtl = $get('PreviewLabel');
		var lbl = oCtl.control;
		if (lbl == null)
			lbl = new Sys.Preview.UI.Label($get('PreviewLabel'));
		lbl.set_text(result);
	}	
}
//<----Auto Input Format

//6-28-08-->
function popDropToggle(popit)
{   onFormatInputCompleted("");
    TogglePreviewButton('show');    
    if(popit == 'true')
    {   popDrop(); //auto-populate topics...
    }
}

function doFormatToggle(popit)
{   doFormat(popit);
    TogglePreviewButton('hide');
}

function TogglePreviewButton(result)
{   var e = document.getElementById("PreviewButton");
    if(result == 'hide')
    {   e.style.visibility = 'hidden';
    }
    else
    {   e.style.visibility = 'visible';
    }
}
//<--6-28-08

//Populate Dropdown---->
function popDrop()
{   var oCtl = $get('ProblemText');
	var tb = oCtl.control;
	if (tb == null)
		tb = new Sys.Preview.UI.TextBox($get('ProblemText'));
	var name = tb.get_text();           
	InputFormat.PopulateSubjects(name, document.title, addTopics);
	//createCookie('RememberProblem',name,1); //save problem as you type so it can be restored...
}

function addTopics(value)
{   var updateList = true;
    //only update dropdownlist if the items within the list changed...
    if (document.form1.TopicDropDownList.length > 0)
    {   updateList = false;    
        for (var j = 0; j < value.length-1; j++)
        {   if (value[j] != document.form1.TopicDropDownList.options[j].text)
            {   updateList = true;
                break;         
            }
        }
    }
    if (updateList == true)
    {   clearDrop(document.form1.TopicDropDownList);
        for (var i = 0; i < value.length-1; i++)
        {   var optn = document.createElement("option");
            optn.text = value[i];
            optn.value = value[i];
            document.form1.TopicDropDownList.options.add(optn);
        }
        //use last element to set the selected index
        document.form1.TopicDropDownList.selectedIndex = value[value.length-1];
    }
}

function clearDrop(objSelect)
{   for (var i = (objSelect.options.length-1); i >= 0; i--)
    {   objSelect.options[i]=null;
    }
    //options[0]=new Option('--------------------------', '0');
}
//<----Populate Dropdown

function insertText(open, end)
{   var tArea = document.form1.ProblemText;
    //erase for some inputs (such as shapes)-->
    if(open=="rectangle[" || open=="circle[" || open=="triangle[" || open=="parallelogram[" || open=="trapezoid[" || open=="box[" || open=="cylinder[" || open=="cone[" || open=="pyramid[" || open=="sphere[" || open=="f(x)=piecewise[?_?]" || open=="tri[?,90,?,?,?,?]")
    {   tArea.value = "";
    }    
    //<--erase for some inputs (such as shapes)
    var isIE = (document.all)? true : false;
    var open = (open)? open : "";
    var end = (end)? end : "";
    if(isIE)
    {   tArea.focus();
        var curSelect = document.selection.createRange();
        if(arguments[2])
        {   curSelect.text = open + arguments[2] + "]" + curSelect.text + end;
        }
        else
        {   curSelect.text = open + curSelect.text + end;
        }
    }
    else if(!isIE && typeof tArea.selectionStart != "undefined")
    {   var selStart = tArea.value.substr(0, tArea.selectionStart);
        var selEnd = tArea.value.substr(tArea.selectionEnd, tArea.value.length);
        var curSelection = tArea.value.replace(selStart, '').replace(selEnd, '');
        if(arguments[2])
        {   tArea.value = selStart + open + arguments[2] + "]" + curSelection + end + selEnd;
        }
        else
        {   tArea.value = selStart + open + curSelection + end + selEnd;
        }
    }
    else
    {   tArea.value += (arguments[2])? open + arguments[2] + "]" + end : open + end;
    }
    //doFormat();
} 

