﻿// JScript File
var aspnetPrefix = "ctl00_ContentPlaceHolder1_";

//sadly, a global variable to keep track of whether or not all conditions have been met before
// submitting the AJAX request to build that bridge
var cancelAsynch = true;

//clears the text from the Search text box when user clicks inside it -- onFocus event
function clearText(textBox) 
{ 
	if(textBox.value.toUpperCase() == "SEARCH THIS SITE:")
	textBox.value = "";
}

//places the default text back into Search box when user leaves the text box -- onBlur event
function resetText(textBox) 
{
	if(textBox.value == "")
	    textBox.value = "Search this site:";
}
    
function ShowHideSpan(id)
{
	if (document.getElementById(id + "span").style.display=="block")
	{
		document.getElementById(id + "span").style.display="none";
	}
	else
	{
		document.getElementById(id + "span").style.display="block";
	}
}

function ShowSpan(id)
{
    var span = document.getElementById(id);
    if (span)
    {
        if (span.style.display != "block")
            span.style.display = "block";
        span.blur();
    }
}

function ShowHide(id)
{
	var element = document.getElementById(id);
	if (element)
	{
	    if (element.style.display=="block")
	    {
		    element.style.display="none";
	    }
	    else
	    {
		    element.style.display="block";
	    }
    }
}

//Clears text from and set focus to the text box with the given textbox id
function clearTextbox(textboxID) {
    var textbox = document.getElementById(textboxID);
    if (textbox) {
        textbox.value = "";
        textbox.focus();
    }
    return false;
}

// I have combined multiple functions into one function. This function is called
//  when the 'clear' button is clicked. 
// In addition to clearing text from all text boxes on the form except the Search text box,
//  this function also hides the Validation Div (the div that holds validations error messages)
//  and hides the results label. 
function clearAllTextBoxes(validationDivId) {
    var inputs = document.getElementsByTagName('input');
    
    //clears all text boxes
    for (var i=0; i<inputs.length;i++)
    {
        if (inputs[i].type == "text")
            if (inputs[i].id != "txtSearch")
                inputs[i].value = "";
    }
    
    //.NET creates a textarea element for multiline text boxes so
    // check for those just in case
    var textareas = document.getElementsByTagName('textarea');
    for (var i=0; i<textareas.length;i++)
    {
        textareas[i].value = "";
    }
    
    var test = document.getElementById(validationDivId);
    test.style.display = "none";
    
    //this is an asp:label control that describes the result of the submit operation.
    var resultText = document.getElementById("ctl00_ContentPlaceHolder1_result");
    if (resultText)
        resultText.style.display = "none";

    return false;
}

/* Client-side access to querystring name=value pairs
	Version 1.2.3
	22 Jun 2005
	Adam Vandenberg
*/
function QueryString(qs) { // optionally pass a querystring to parse
	this.params = new Object()
	this.get=QueryString_get
	
	if (qs == null)
		qs=location.search.substring(1,location.search.length)

	if (qs.length == 0) return

// Turn <plus> back to <space>
// See: http://www.w3.org/TR/REC-html40/interact/forms.html#h-17.13.4.1
	qs = qs.replace(/\+/g, ' ')
	var args = qs.split('&') // parse out name/value pairs separated via &
	
// split out each name=value pair
	for (var i=0;i<args.length;i++) {
		var value;
		var pair = args[i].split('=')
		var name = unescape(pair[0])

		if (pair.length == 2)
			value = unescape(pair[1])
		else
			value = name
		
		this.params[name] = value
	}
}

function QueryString_get(key, default_) {
	// This silly looking line changes UNDEFINED to NULL
	if (default_ == null) default_ = null;
	
	var value=this.params[key];
	if (value==null) value=default_;
	
	return value;
}

//reads the query string of a URL to determine the place on a page
// where the page should open to, and then opens the div located
// at that area. Method is used on BuildABridge to navigate back
// to bridgeconcepts and open a particular div. By default all the
// relevant divs are closed so clicking of them will open them up.
function navigateToHashAndOpen()
{
    var qs = new QueryString();
    var cmd = qs.get('cmd','nothing there');
    var link;
    
    if (cmd != 'nothing there')
    {
        link = document.getElementById(cmd + 'link');        
        if (link){
            eval(link.onclick());  
        }       
    }
}
