ns4 = (document.layers)? true:false
ie4 = (document.all)? true:false
var currentVisible = "";

// Show/Hide functions for non-pointer layer/objects
var RM_OffsetX = -250;
var RM_OffsetY = 0;
function showHideLayer(evt, layerName, vis) {
	var obj;
	var v = vis;
	var startNum = "";


	if ((obj=MM_findObj(layerName))) {
      if (obj.style) {
	    obj=obj.style;
        obj.left = (event.clientX + document.body.scrollLeft + RM_OffsetX+50);
	    obj.top = (event.clientY  + document.body.scrollTop + RM_OffsetY);
	    v=(v=='show')?'visible':(v='hide')?'hidden':v;
	  } else {
	     var x = evt.pageX + RM_OffsetX;
	     var y = evt.pageY + RM_OffsetY;
		 obj.pageX = x;
		 obj.pageY = y;
	  }
	  obj.visibility=v;
    }

}
function MM_findObj(n, d) { //v4.01
  var p,i,x;  if(!d) d=document; if((p=n.indexOf("?"))>0&&parent.frames.length) {
    d=parent.frames[n.substring(p+1)].document; n=n.substring(0,p);}
  if(!(x=d[n])&&d.all) x=d.all[n]; for (i=0;!x&&i<d.forms.length;i++) x=d.forms[i][n];
  for(i=0;!x&&d.layers&&i<d.layers.length;i++) x=MM_findObj(n,d.layers[i].document);
  if(!x && d.getElementById) x=d.getElementById(n); return x;
}

function MM_showHideLayers() { //v3.0
  var i,p,v,obj,args=MM_showHideLayers.arguments;
  for (i=0; i<(args.length-2); i+=3) if ((obj=MM_findObj(args[i]))!=null) { v=args[i+2];
    if (obj.style) { obj=obj.style; v=(v=='show')?'visible':(v='hide')?'hidden':v; }
    obj.visibility=v; }
}

function hideLayer() {
  var i,args=hideLayer.arguments;
  for(i=0; i<=(args.length-1); i++)
  hide(args[i]);
}

function showLayer() {
  var i,args=showLayer.arguments;
  for(i=0; i<=(args.length-1); i++)
  show(args[i]);
}

function show(id)
{
	if (ns4) document.layers[id].visibility = "show"
	else if (ie4) document.all[id].style.display = "block"
	else document.getElementById(id).style.visibility = "visible"
}

function hide(id)
{
	if (ns4) document.layers[id].visibility = "hide"
	else if (ie4) document.all[id].style.display = "none"
	else document.getElementById(id).style.visibility = "hidden"
}

function updateForm(fieldName, fieldValue) {
	formName="AnswerQs";
	document.forms[formName].elements[fieldName].value=fieldValue;
}

function changeSelection(val)
{
  if(ie4)
  {
    if(currentVisible != "")
    {
      hide(currentVisible);
      currentVisible = "";
    }
    var spanId = "span" + val;
    if(document.all[spanId])
    {
	    document.all[spanId].style.display = "inline";
	    currentVisible = spanId;
	    var selId = "scndLvlCQ" + val;
	    if(document.AnswerQs.elements[selId])
	    {
	      document.AnswerQs.elements[selId].selectedIndex = 0;
	    }
	  }
  }
}

function viewXml(formName) {
	eval('document.'+formName+'.submit()');
}

function getAction(formName) {
	if (!document.forms[formName]) {
		return false;
	}
	eval('document.'+formName+'.action="Dialoging.asp"');
	return true;
}

function getKCAction(formName) {
	if (!document.forms[formName]) {
		return false;
	}
	document.forms[formName].action = "f_kcdetails.asp"
	return true;
}

function getHookKCAction(formName) {
	if (!document.forms[formName]) {
		return false;
	}
	document.forms[formName].action = "HookKC.asp"
	return true;
}

function getFindSimilarAction(formName) {
	if (!document.forms[formName]) {
		return false;
	}
	document.forms[formName].action = "summary.asp"
	return true;
}

function getResultsAction(formName) {
	if (!document.forms[formName]) {
		return false;
	}
	document.forms[formName].action = "dialogresults.asp"
	return true;
}

function setActionParameters(formName, actionName, actionArgument) {
	// Check if the form exists
	if (!document.forms[formName]) {
		return false;
	}
	document.forms[formName].argument.value=actionArgument;
	document.forms[formName].AllowedActionName.value=actionName;
	return setParameters (formName);
}

function setParameters(formName) {
	// Check to make sure that the form exists and all required fields are valid.
	if (!document.forms[formName]) {
		return false;
	}
	document.forms[formName].dialogID.value = dialogID;
	document.forms[formName].debugLevel.value = debugLevel;
	//document.forms[formName].interface.value = interface;
	document.forms[formName].sessionID.value = sessionID;
	document.forms[formName].dialogState.value = dialogState;
	document.forms[formName].extraXML.value = extraXML;
	if(document.forms[formName].prevIterExtraXML)
	{
	  document.forms[formName].prevIterExtraXML.value = prevIterExtraXML;
	}
	document.forms[formName].numKCs.value = numKCs;
	document.forms[formName].NoQsSet.value = nNoQsSet;
	document.forms[formName].KCsSet.value = nKCsSet;
	document.forms[formName].strictness.value = strictness;
  if(document.forms[formName].prevIterRequest)
  {
    document.forms[formName].prevIterRequest.value = prevIterRequest;
  }
	if(document.forms[formName].VisibleStateXML)
	{
	  document.forms[formName].VisibleStateXML.value = VisibleStateXML;
	}
  return true;
}

function isAnInt(string)
{
	var validChars = "-+0123456789 ";
	if((string==null)||(string=="")) return true;
	var len = string.length;
	for(i=0;i<len;i++)
	{
		if(validChars.indexOf(string.charAt(i)) == -1)
		{
		  alert("\"" + string + "\" is not a valid integer.");
		  return false;
		}
	}
	return true;
}

function isAFloat(string)
{
	var validChars = "-+.0123456789 ";
	if((string==null)||(string=="")) return true;
	var len = string.length;
	for(i=0;i<len;i++)
	{
		if(validChars.indexOf(string.charAt(i)) == -1)
		{
		  alert("\"" + string + "\" is not a valid float.");
      return false;
    }
	}
	return true;
}

function isAMonth(string)
{
  if(!isIntInRange(string, 1, 12))
  {
    alert("\"" + string + "\" is not a valid month.");
    return false;
  }
  return true;
}

function isADay(string)
{
  if(!isIntInRange(string, 1, 31))
  {
    alert("\"" + string + "\" is not a valid day.");
    return false;
  }
  return true;
}

function isAYear(string)
{
  if(!isIntInRange(string, 0, 9999))
  {
    alert("\"" + string + "\" is not a valid year.");
    return false;
  }
  return true;
}

function isIntInRange(string, nMin, nMax)
{
  var nVal;
	if((string==null)||(string=="")) return true;
	if(isAnInt(string))
	{
	  nVal = parseInt(string);
	  if(nVal >= nMin && nVal <= nMax) return true;
	}
	return false;
}


function isWhitespace(string)
{
	var whiteSpace = " \t\r\n";
	var len = string.length;
	if((string==null)||(string=="")) return true;
	for(i=0;i<len;i++)
	{
		if(whiteSpace.indexOf(string.charAt(i)) == -1) return false;
	}
	return true;
}

function validateAnswers(eForm)
{
  var bFormIsEmpty = true;
  var x, y, z;

  for(var i = 0; i < eForm.length; i++)
  {
    if(eForm.elements[i].name.substr(0,2) == "tq")
    {
      x = eForm.elements[i].name.lastIndexOf("question");
      if(x  > 2)
      {
	if(eForm.elements[eForm.elements[i].name][0].checked)
	{
           z = eForm.elements[i].name.substr(2,x-2);
	   y = "confirmed_" + z;
           z = "select_" + z;
           if(!((eForm.elements[y] && !isWhitespace(eForm.elements[y].value)) || (eForm.elements[z] && !isWhitespace(eForm.elements[z].value))))
           {
	     if(eForm.elements[y])
	     {
	       alert("If you said 'yes' to a question, please type in some text or select from the list.");
             }
             else
             {
	       alert("If you said 'yes' to a question, please type in some text.");
             }
             return false;
           }
        }
      }
    }
    if(eForm.elements[i].name.substr(0,6) == "select")
    {
      if(!isWhitespace(eForm.elements[i].value)) bFormIsEmpty = false;
    }
    else if(eForm.elements[i].name.substr(0,9) == "confirmed")
    {
      if(!isWhitespace(eForm.elements[i].value)) bFormIsEmpty = false;
    }
  }
  if(!isWhitespace(eForm.userQuery.value)) bFormIsEmpty = false;

  if(bFormIsEmpty)
  {
    alert("Please answer at least one question.");
  }

  return(!bFormIsEmpty);
}

function clearAllForms()
{
  var formslen = document.forms.length;
  for(var i=0;i<formslen;i++)
  {
    document.forms[i].reset();
  }
}

function CaptureState(gHTMLElementStateInfo)
{
  var i,collDIV,strVisibleDIV="";
  collDIV=document.getElementsByTagName("DIV")

  for (i=0;i<collDIV.length;i++)
  {
	  if (collDIV(i).style.display=="none")
	  {
		  if (strVisibleDIV.length!=0)
			  strVisibleDIV=strVisibleDIV + "|";
		  strVisibleDIV=strVisibleDIV + collDIV(i).id
	  }
  }
  gHTMLElementStateInfo.value=strVisibleDIV;

  if(document.all.invisiblespans)
  {
    document.all.invisiblespans.value = currentVisible;
  }
}

function isMemberOf(divid,arrayVisibleDIV)
{
  var i;
  var boolFound;
  boolFound=false
  for (i=0;i<arrayVisibleDIV.length;i++)
  {
  	if (arrayVisibleDIV[i]==divid)
  	{
  		boolFound=true;
  	}
  }
  return boolFound;
}

function RestoreState(gHTMLElementStateInfo)
{
  var strInVisibleDIV,arrayInVisibleDIV;
  var i,divid,collDIV;
  var VisibleDIVLookupTable;


  //get the invisible divs from the form field and make an array of it.
  strInVisibleDIV=gHTMLElementStateInfo.value


  if (!isblank(strInVisibleDIV))
  {
  	arrayInVisibleDIV=strInVisibleDIV.split("|");
  	collDIV=document.all.tags("DIV")

  	for (i=0;i<collDIV.length;i++)
  	{
  		divid=collDIV(i).id;


  		if(!isblank(divid))
  		{

  			if (isMemberOf(divid,arrayInVisibleDIV))
				{
  				hide(divid);
				}
	  		else
		  	{
		  		show(divid);
		  	}
	  	}
  	}
  }

  if(document.all.invisiblespans)
  {
    currentVisible = document.all.invisiblespans.value;
    if(currentVisible != "")
	    document.all[currentVisible].style.display = "inline";
  }

}

/*
Text Link/Image Map Tooltip Script-
© Dynamic Drive (www.dynamicdrive.com)
For full source code, installation instructions,
100's more DHTML scripts, and Terms Of
Use, visit dynamicdrive.com
*/

if (!document.layers&&!document.all)
	event="test"

function showtip(current,e,text){
	if (document.all){
		thetitle=text.split('<br>')
		if (thetitle.length>1){
			thetitles=''
			for (i=0;i<thetitle.length;i++)
				thetitles+=thetitle[i]
			current.title=thetitles
		}
		else
			current.title=text
	}
	else if (document.layers){
		document.tooltip.document.write('<layer bgColor="#ffffcc" style="border:1px solid black;font-size:12px;">'+text+'</layer>')
		document.tooltip.document.close()
		document.tooltip.left=e.pageX+5
		document.tooltip.top=e.pageY+5
		document.tooltip.visibility="show"
	}
}

function hidetip(){
	if (document.layers)
		document.tooltip.visibility="hidden"
}

function isblank(s) {
	for(var i=0; i<s.length; i++) {
		var c = s.charAt(i);
		if((c != ' ') && (c != '\n') && (c != '\t')) return false;
	}
	return true;
}
function MM_submit(searchWithinResults)
{
    f=MM_findObj(searchWithinResults);fillInDialogState(f);if(ie4){CaptureState(document.all.invisibleDIV);}
    if(f.text.value == 'Type your keywords here') f.text.value='';
}

function clearTextBox(t)
{
	if (cflag)
	{
		return;
	}
	else
	{
		if(t.value == defaultText)
		{
			t.value = "";
			if (t.style)
			{
				t.style.color = '#000000';
			}
		}
	}
	cflag = 1;
}
function ValidateErrorMessage(text)
{
	if (text == null || text == "" || isblank(text) )
	{
		alert("In order to continue, please enter your error message.");
		return false;
	}
	else
	{
		return true;
	}
}

function answerLinksQuestion(theLinksForm, theCaptureStateElement, questionId, answerValue)
{

	//fillInDialogState(theLinksForm);
	if(ie4){
		CaptureState(theCaptureStateElement);
	}
	theLinksForm.id.value= questionId;
	theLinksForm.answerValue.value=answerValue;
	return true;
	//return theLinksForm.submit();
}


function verifySearchWithin(f) {
	searchString = f.text.value;
	if (searchString == null || searchString == "" || isblank(searchString) || searchString == 'Type your keywords here') {
	alert("Please enter your search within query in the text box")
	f.text.value = 'Type your keywords here';
	return false;
	}
	return true;
	//return fillInDialogState(f);
	if(ie4)CaptureState(document.all.invisibleDIV);
	}

