function toggleComments(question)
{
  if (document.getElementById("q_open0"))
  {
    if (question == 0)
    {
   		document.getElementById("q_open0").style.display = "block";
   		document.getElementById("q_closed0").style.display = "none";
      switchEditors(document.getElementById("q_open0"));
    }
    else
    {
   		document.getElementById("q_open0").style.display = "none";
   		document.getElementById("q_closed0").style.display = "block";
    }
    for (var i=2; i<=6; i++) 
    {
      if (document.getElementById("q_open"+i)) 
      {
        if (question == i)
        {
       		document.getElementById("q_open"+i).style.display = "block";
       		document.getElementById("q_closed"+i).style.display = "none";
          switchEditors(document.getElementById("q_open"+i));
        }
        else
        {
       		document.getElementById("q_open"+i).style.display = "none";
       		document.getElementById("q_closed"+i).style.display = "block";
        }
      }
    }
    return false;
  }
  return true;
}

function switchEditors(oNode)
{
  if (!document.all)
  {
    var i=0;
    for (i=0;i<oNode.childNodes.length;i++)
    {
      childNode = oNode.childNodes.item(i);
      editor = FCKeditorAPI.GetInstance(childNode.name);
      if (editor && editor.EditorDocument && editor.EditMode == FCK_EDITMODE_WYSIWYG)
      {
        editor.EditorDocument.designMode = "on";
      }
      switchEditors(childNode,"on");
    }
  }
}

function getCookie(c_name)
{
  if (document.cookie.length>0)
  {
    c_start=document.cookie.indexOf(c_name + "=");
    if (c_start!=-1)
    { 
      c_start=c_start + c_name.length+1 ;
      c_end=document.cookie.indexOf(";",c_start);
      if (c_end==-1) c_end=document.cookie.length;
      return unescape(document.cookie.substring(c_start,c_end));
    } 
  }
  return "";
}


function openWindow(page)
{
  var myWindow=window.open(page,'Questionnaire','width=640,height=480,scrollbars=yes')
  myWindow.focus()
  
}

function checkQuestionnaire()
{
  var thisURL = self.location.href;
  var posID = thisURL.indexOf("?questionnaire=");
  var uniqueID = "";

  if (posID > 0)
  {
    uniqueID = thisURL.substr(posID+15);
    if (getCookie("QUESTIONNAIRE") != uniqueID && uniqueID.length == 35)
    {
      openWindow("/questionnaire.cfm?unique_id="+uniqueID);
    }
  }
}

checkQuestionnaire();

function addTabs(){
	//$("#home_consultations_wrapper").addClass("addTabs")
	$("#home_responses").append("<a href='' class='viewResponses'>View links to recent Responses to External Consultations.</a>")
	$("#home_consultations").append("<a href='' class='viewConsultations'>View links to all current FRC and FRC operating body consultations.</a>")

	$(".currentQuicklinks").hide()
	$(".responseQuicklinks").hide()
}

function openLinkPanel(viewPanel){
	if(viewPanel == "viewConsultations"){
		$(".currentQuicklinks .closeButton").remove()
		$(".currentQuicklinks").show()
		$(".currentQuicklinks").addClass("openPanel")
		$(".currentQuicklinks").prepend("<a href='' class='closeButton'>close</a>")
		$("body").height(  $("body").height() + ($(".currentQuicklinks").height() -200))
		
	}else if(viewPanel == "viewResponses"){
		$(".responseQuicklinks .closeButton").remove()
		$(".responseQuicklinks").show()
		$(".responseQuicklinks").addClass("openPanel")
		$(".responseQuicklinks").prepend("<a href='' class='closeButton'>close</a>")
		
		$("body").height(  $("body").height() + ($(".responseQuicklinks").height() -200))
	}

}
function closeLinkPanel(){
	//$(".currentQuicklinks").hide()
	//$(".responseQuicklinks").hide()
}

$(document).ready(function(){
	addTabs();
})
$(".viewConsultations").live("click", function(){
	openLinkPanel("viewConsultations")
	$(".responseQuicklinks").hide()
	$(".responseQuicklinks .closeButton").remove()
	return false
	})
$(".viewResponses").live("click", function(){
	openLinkPanel("viewResponses")
	$(".currentQuicklinks").hide()
	$(".currentQuicklinks .closeButton").remove()
	return false
	})
$("closeButton").live("click", function(){
	closeLinkPanel()
	return false
})

