/* Common JavaScripts for the GuideStar website. */


/* Functions for mouseovers. Mouseover images must end with '1.gif', mouseout images must end with '0.gif'. */
function turn_on(img) {
	new_src = img.src.replace('0.gif','1.gif');
	img.src = new_src;
}

function turn_off(img) {
	new_src = img.src.replace('1.gif','0.gif');
	img.src = new_src;
}

function clearOtherPopups(popup) {
	if(popup != 'home_main_img_1') { $('home_main_img_1').style.display = 'none'; }
	if(popup != 'home_main_img_2') { $('home_main_img_2').style.display = 'none'; }
	if(popup != 'home_main_img_3') { $('home_main_img_3').style.display = 'none'; }
}

function toggle_promo(newPromo) {
	if(document.all) {
		new Effect.toggle(newPromo, 'appear', { duration:0.5, beforeStart:clearOtherPopups(newPromo) });
	} else {
		new Effect.toggle(newPromo, 'slide', { duration:0.5, beforeStart:clearOtherPopups(newPromo) });
	}
}

//functions for layering people report
function show_layer(element_id)
{
	// find element by id and change display style to "show"
	var element = document.getElementById(element_id);
	if ( element )
	{
		element.style.visibility = "visible";
	}
	
	return false;
}

function hide_layer(element_id)
{
	var element = document.getElementById(element_id);
	if ( element )
	{
		element.style.visibility = "hidden";
	}

	return false;
}

//functions for layering messaging
function show_message(background_id,container_id,msg_id)
{
	var background = document.getElementById(background_id);
	var container = document.getElementById(container_id);
	var message = document.getElementById(msg_id);
	
	if ( background != null && container != null && message != null )
	{
        message.style.display = "block";	    
		background.style.visibility = "visible";
	}
	
	return false;
}

function hide_message(background_id,container_id)
{
	var background = document.getElementById(background_id);
	var container = document.getElementById(container_id);
	
	if ( background != null && container != null )
	{  
		background.style.visibility = "hidden";

        // Turn off display of all the child nodes of the container div, if they have the class set to body
        if (container != null)
        {
            var child_divs = container.childNodes;
            for( var i=0; i < child_divs.length; i++ )
            { 
                if( ( child_divs[i].id != null ) && ( child_divs[i].id != "") )
                {
                    var msg_div = document.getElementById(child_divs[i].id);
                    if ( msg_div != null && msg_div.className == "body" )
                    {
                        msg_div.style.display = "none";
                    }
                }
            }
        }	 
	}
	
	return false;
}

function savedsearch_has_nondefault_text(sender, args)
{
  if(args.Value=="Enter a name for this search.")
  {
    args.IsValid = false;
    return false;
  }
  else
  {
    args.IsValid = true;
    return true;
  }
}

function trim(stringToTrim) 
{
	return stringToTrim.replace(/^\s+|\s+$/g,"");
}

// redirect parent window and close, if parent exists, else just follow link
function redirectParent(url)
{
  if (window.opener != null)
  {
    window.opener.location.href=url;
    window.close();
  }
  else
  {
    window.location.href=url;
  }
}
