

function showToolsCover() {
    $(".tools_cover > a").css({'color':'black'});
    $(".tools_cover").show();
}

function hideAll () {
    $("#toolsMenu").hide();
    $("#toolsTipAFriend").hide();
    $("#toolsMenu").hide();
    $(".tools_cover").hide();
}

$(document).ready(function () {
    $(".tools > a").click(function () {
       $("#toolsMenu").slideToggle("slow");
       showToolsCover();  
    })
    
    $(".tools_cover > a").click(function () {
         hideAll();
   })
});

$(document).ready(function () {
      $("#showTipAFriend").click(function () {
         $("#toolsTipAFriend").slideToggle("slow");
      });
});

$(document).ready(function () {
    $(".toggle").click(function () {

        var elementID = "collapse-expand-"+ $(this).attr("id");
        var imgTagId = "img-"+$(this).attr("id");
        var imgTagSrc = $("#"+imgTagId).attr("src");

        //fetch the suffix and prefix of the imgsrc so we can alter the image name...
        var urlPrefix = imgTagSrc.slice(0,imgTagSrc.lastIndexOf("/")+1);
        var urlSuffix = imgTagSrc.slice(imgTagSrc.lastIndexOf("/")+1);

        //Check which image we are using and preform the appropriate switch...
        if(urlSuffix == "collapse.png") {
          urlSuffix = "expand.png";
        }
        else {
           urlSuffix = "collapse.png";
        }

        //Perform the src switch...
        $("#"+imgTagId).attr("src",urlPrefix+urlSuffix);
        //...and add the toogle.
        $("#"+elementID).slideToggle("slow");
    });
});


$(document).ready(function () {

    var cookiesString = document.cookie;
    var pos = cookiesString.indexOf("currentArticleUrl=");
    var value = "";

    if(pos != -1) {
       var start = pos+18;
       var end = cookiesString.indexOf(";",start);
       if(end == -1) {
         end = cookiesString.length;  
       }
       value = cookiesString.substring(start,end);
       value = decodeURIComponent(value);
    }

    if(value != "") {
        document.getElementById("articleUrl").value=value;
    }
});


/* Function for altering the form submit url to match the sites correct external url */


$(document).ready( function () {
    if(searchActionUrl) {
        $("#article_search").attr("action", searchActionUrl);     
    }
});





/*
----------------------------------------------------------
JS FOR THE COMPARISON TOOL
----------------------------------------------------------
*/

String.prototype.trim = function () {
    return this.replace(/^\s*/, "").replace(/\s*$/, "");
}

function submitform()
{
  document.forms["selectionForm"].myAction.value="selectionChanged";
  document.forms["selectionForm"].submit();
}

function submitcheckboxform()
{
  document.forms["checkBoxForm"].submit();
}


function submitselectionform()
{
    document.forms["selectionForm"].action="";
    document.forms["selectionForm"].submit();
}


function beep() {
   java.awt.Toolkit.getDefaultToolkit().beep();
}

function checkInArray(array,value)
{
    for (var i=0;i<array.length;i=i+1)
    {
        if (array[i].value=value)
            return true;
    }

    return false;
}

// -------------------------------------------------------------------
// hasOptions(obj)
//  Utility function to determine if a select object has an options array
// -------------------------------------------------------------------
function hasOptions(obj) {
	if (obj!=null && obj.options!=null) { return true; }
	return false;
}

function moveOption( fromID, toID, idx )
{
   if (isNaN(parseInt(idx)))
   {
      var i = document.getElementById( fromID ).selectedIndex;
   }
   else
   {
      var i = idx;
   }

   var o = document.getElementById( fromID ).options[ i ];
   var theOpt = new Option( o.text, o.value, false, false );
   document.getElementById( toID ).options[document.getElementById( toID ).options.length] = theOpt;
   document.getElementById( fromID ).options[ i ] = null;
}

function copyOption( fromID, toID, idx )
{
   if (isNaN(parseInt(idx)))
   {
      var i = document.getElementById( fromID ).selectedIndex;
   }
   else
   {
      var i = idx;
   }

   var o = document.getElementById( fromID ).options[ i ];
   var theOpt = new Option( o.text, o.value, false, false );
   document.getElementById( toID ).options[document.getElementById( toID ).options.length] = theOpt;
   //document.getElementById( fromID ).options[ i ] = null;
}


function deleteOption( fromID, idx )
{
   if (isNaN(parseInt(idx)))
   {
      var i = document.getElementById( fromID ).selectedIndex;
   }
   else
   {
      var i = idx;
   }

   var o = document.getElementById( fromID ).options[ i ];
   var theOpt = new Option( o.text, o.value, false, false );
   //document.getElementById( toID ).options[document.getElementById( toID ).options.length] = theOpt;
   document.getElementById( fromID ).options[ i ] = null;
}


function moveOption2( fromID, idx)
{
   if (isNaN(parseInt(idx)))
   {
      var i = document.getElementById( fromID ).selectedIndex;
   }
   else
   {
      var i = idx;
   }

   var o = document.getElementById( fromID ).options[ i ];
   var theOpt = new Option( o.text, o.value, false, false );
   //document.getElementById( toID ).options[document.getElementById( toID ).options.length] = theOpt;
   document.getElementById( fromID ).options[ i ] = null;
}


function moveOptions( fromID, toID )
{
   for (var x = document.getElementById( fromID ).options.length - 1; x >= 0 ; x--)
   {
      if (document.getElementById( fromID ).options[x].selected == true)
      {
         moveOption( fromID, toID, x );
      }
   }
}

function copyOptions( fromID, toID )
{
   trim(toID);

   for (var x = document.getElementById( fromID ).options.length - 1; x >= 0 ; x--)
   {

      var option=document.getElementById(fromID).options[x].value;
      if (document.getElementById( fromID ).options[x].selected == true && !exists(toID,option) &&!beginsWith(option,"-"))
      {
         copyOption( fromID, toID, x );
      }
   }
}

function exists( fromID, option )
{
   for (var x = document.getElementById( fromID ).options.length - 1; x >= 0 ; x--)
   {
      if (document.getElementById( fromID ).options[x].value == option)
      {
        return true;
      }

   }
      return false;
}

function beginsWith( option, beginChar )
{
    var string=option;

    if(string.substr(0, 1)==beginChar)
    {
        return true;
    }
    else
        return false;

}


function trim( toID)
{
   for (var x = document.getElementById( toID ).options.length - 1; x >= 0 ; x--)
   {
       value=document.getElementById( toID ).options[x].value;
       //document.write(value.toString().substr(0, 1));
       //document.write(value);
       if (value == "blank")
      {
        //document.write("isEqual");
        document.getElementById( toID ).options[x] = null;
      }
      //else
//        document.write("isNotEqual");


   }
}

function deleteOptions( fromID )
{
   for (var x = document.getElementById( fromID ).options.length - 1; x >= 0 ; x--)
   {
      if (document.getElementById( fromID ).options[x].selected == true)
      {
         deleteOption( fromID, x );
      }
   }
}


function copyAllOptions( fromID, toID )
{
   for (var x = 0; x <document.getElementById( fromID ).options.length ; x++)
   {
         copyOption( fromID, toID, x );
   }
}

function clear( fromID)
{
    document.selectionForm.multiselect.options.length=0;
}

function checkAll(field, state,value)
{

      for (i = 0; i < field.length; i++)
          if (field[i].value==value)
          {
              for(i++;field[i].value.substr(0, 1).toLowerCase()=="q";i++)
              {
                field[i].checked=state;
              }
          }
}

/* FUNCTIONS FOR THE COMPARISON TOOL TEMPLATE FORM*/

function selectAll()
{
    for (var x = document.getElementById("multiselect2").options.length - 1; x >= 0 ; x--)
    {
        document.getElementById("multiselect2").options[x].selected=true;
    }

}


function submit()
{

    document.getElementById("selectionForm").submit();
    //document.selectionForm.submit();
}

function selectAllOptions(selStr)
{
  var selObj = document.getElementById(selStr);
  for (var i=0; i<selObj.options.length; i++) {
    selObj.options[i].selected = true;
  }
}


