/* $Id: utils.js 1845 2010-06-15 14:55:20Z ttn206 $ */

/* --------------------------- SEARCH BOX --------------------------- */

$(document).ready(function() {
	var DEFAULT_SEARCH_TEXT = "Search...";
	
	$("#searchField").focus(function() {
		$("#searchBar").animate({marginTop:"0px"},500);
		$("#searchBtn").animate({marginTop:"0px"},500);
		$("#searchTypes").fadeIn("normal");
		if ($(this).val() == DEFAULT_SEARCH_TEXT) $(this).val('');
	});

	$("#searchField").blur(function() {
		$("#searchTypes").fadeOut("normal");
		$("#searchBar").animate({marginTop:"13px"},500);
		$("#searchBtn").animate({marginTop:"13px"},500);
		if ($(this).val() == '') $(this).val(DEFAULT_SEARCH_TEXT);
	});
	
	$("#searchTypes li a").click(function() {
		$(this).addClass("searchTypeSelected");
		$(this).parent().siblings().children().removeClass("searchTypeSelected");
		$(".nyuSearch form").attr("action", $(this).attr("href"));
		$('#searchField').focus();
		return false;
	});
	
	$("#searchForm").submit(function() {
		if ($("#searchField").val() == DEFAULT_SEARCH_TEXT)
			$("#searchField").val('');
		return true;
	});
}); 

/* --------------------------- EXPANDABLES AND FAQs -------------------------- */

$(document).ready(function(){
    
    $(".question").click(function () {
      $(this).next(".answer").slideToggle("normal");
      var imageSrc = $(this).find("img").attr("src");
      	if (imageSrc == "/common/images/plusSign.gif"){
      		$(this).find("img").attr({src:"/common/images/minusSign.gif"});
      		$(this).css({'font-weight': 'bold'});
      	}
      	if (imageSrc == "/common/images/minusSign.gif"){
      		$(this).find("img").attr({src:"/common/images/plusSign.gif"});
      		$(this).css({'font-weight': 'normal'});
      	}
      	if (imageSrc == "/common/images/arrowGrayRight.gif"){
      		$(this).find("img").attr({src:"/common/images/arrowGreenDown.gif"});
      		$(this).css({'font-weight': 'bold'});
      	}
      	if (imageSrc == "/common/images/arrowGreenDown.gif"){
      		$(this).find("img").attr({src:"/common/images/arrowGrayRight.gif"});
      		$(this).css({'font-weight': 'normal'});
      	}
    });

  });


/* --------------------------- cpTemps FAQ --------------------------------- */
// change button & boldness
// NO LONGER USED (9-23-09) Will Remove when developers change up the related components

function changeBtn(formSection, img_id, img_id2)
{
	if(document.getElementById(img_id).src.search("arrowGrayRight") != -1)
	{
	    document.getElementById(img_id).src = '/common/images/arrowGreenDown.gif';		
	    document.getElementById(img_id2).style.fontWeight = 'bold';
	}
	else
	{
	    document.getElementById(img_id).src = '/common/images/arrowGrayRight.gif';
	    document.getElementById(img_id2).style.fontWeight = 'normal';	    
	}
}

function changeBtna(formSectiona, img_ida, img_id2a)
{
	if(document.getElementById(img_ida).src.search("plusSign") != -1)
	{
	    document.getElementById(img_ida).src = '/common/images/minusSign.gif';		
	    document.getElementById(img_id2a).style.fontWeight = 'bold';
	}
	else
	{	
	    document.getElementById(img_ida).src = '/common/images/plusSign.gif';
	    document.getElementById(img_id2a).style.fontWeight = 'normal';	    
	}
}


/* --------------------------- Striped Tables ------------------------------- */
  // this function is needed to work around 
  // a bug in IE related to element attributes
  function hasClass(obj) {
     var result = false;
     if (obj.getAttributeNode("class") != null) {
         result = obj.getAttributeNode("class").value;
     }
     return result;
  }   

 function stripe(id) {

    // the flag we'll use to keep track of 
    // whether the current row is odd or even
    var even = false;
  
    // if arguments are provided to specify the colours
    // of the even & odd rows, then use the them;
    // otherwise use the following defaults:
    var evenColor = arguments[1] ? arguments[1] : "#fff";
    var oddColor = arguments[2] ? arguments[2] : "#eee";
  
    // obtain a reference to the desired table
    // if no such table exists, abort
    var table = document.getElementById(id);
    if (! table) { return; }
    
    // by definition, tables can have more than one tbody
    // element, so we'll have to get the list of child
    // &lt;tbody&gt;s 
    var tbodies = table.getElementsByTagName("tbody");

    // and iterate through them...
    for (var h = 0; h < tbodies.length; h++) {
    
     // find all the &lt;tr&gt; elements... 
      var trs = tbodies[h].getElementsByTagName("tr");
      
      // ... and iterate through them
      for (var i = 0; i < trs.length; i++) {

        // avoid rows that have a class attribute
        // or backgroundColor style
        if (! hasClass(trs[i]) &&
            ! trs[i].style.backgroundColor) {
 		  
          // get all the cells in this row...
          var tds = trs[i].getElementsByTagName("td");
        
          // and iterate through them...
          for (var j = 0; j < tds.length; j++) {
        
            var mytd = tds[j];

            // avoid cells that have a class attribute
            // or backgroundColor style
            if (! hasClass(mytd) &&
                ! mytd.style.backgroundColor) {
        
              mytd.style.backgroundColor =
                even ? evenColor : oddColor;
            
            }
          }
        }
        // flip from odd to even, or vice-versa
        even =  ! even;
      }
    }
  }
 
 /* --------------------------- Browser Update ------------------------------- */
 var $buoop = {} 
 $buoop.ol = window.onload; 
 window.onload=function(){ 
  if ($buoop.ol) $buoop.ol(); 
  var e = document.createElement("script"); 
  e.setAttribute("type", "text/javascript"); 
  e.setAttribute("src", "/common/js/browserUpdate.js"); 
  document.body.appendChild(e); 
 }
