﻿function addMouseoverShowHide(controlElement, showHideElement, closeElement)
{
	if($jq(controlElement) != null && $jq(showHideElement) != null)
	{
		$jq(controlElement).mouseover(function() {
			$jq(showHideElement).show();
		});
	    
		$jq(closeElement).click(function() {
		   $jq(showHideElement).hide();
		});
    }
}

function addSelectedRadioButtonShowHide()
{
	var jsonRadioButtons = _allRadioButtons;

	for(var i = 0; i < jsonRadioButtons.radioButtons.length; i++)
	{
		var currentRadioButton = jsonRadioButtons.radioButtons[i];

		if(currentRadioButton != null)
		{		
			var radioButton = $jq(currentRadioButton.radioButtonID); 

			radioButton.click(function() {		
				radioButtonClick();
			});
		}
	}
	
	radioButtonClick();
}

function radioButtonClick()
{
	var jsonRadioButtons = _allRadioButtons;

	for(var i = 0; i < jsonRadioButtons.radioButtons.length; i++)
	{
		if(jsonRadioButtons.radioButtons[i] != null)
		{
			var radioButtonID = jsonRadioButtons.radioButtons[i].radioButtonID;
			var showElement = jsonRadioButtons.radioButtons[i].showElement;
			var fieldSetElement = jsonRadioButtons.radioButtons[i].fieldSetElement;
			var fieldSetCssClass = jsonRadioButtons.radioButtons[i].fieldSetCssClass;
									
			if(radioButtonID != null)
			{
				var selected = $jq(radioButtonID).is(':checked');
			
				if(showElement != null && showElement != "")
				{		
					if(selected)
					{
						$jq(showElement).show();
					}
					else
					{
						$jq(showElement).hide();
					}
				}
				
				if(fieldSetElement != null && fieldSetElement != '' && fieldSetCssClass != null && fieldSetCssClass != '')
				{
					if(selected)
					{
						$jq(fieldSetElement).addClass(fieldSetCssClass);
					}
					else
					{
						$jq(fieldSetElement).removeClass(fieldSetCssClass);
					}
				}
			}
		}
	}
}

function addWaterMark(control, message)
{
	$jq(control).watermark(message);
}

function closeLightBox()
{
	if(parent.location != document.location)
	{
		parent.closeLightBox();
	}
	else
	{
		window.close();
	}
}

function refreshLightBox(url, width, height)
{
	if(parent.location != document.location)
	{
		parent.reloadLightBox(url, width, height);
	}
	else
	{
		document.location = url;
	}
}

function scrollToResult(resultsTable, anchor)
{
	var resultsTableElement = $jq(resultsTable);
	var anchorElement = $jq(anchor);
	
	if(resultsTableElement != null && anchorElement != null)
	{
		resultsTableElement.scrollTo(anchorElement, 0);
	}
}

function resizeColumns()
{
	$jq(window).resize(function() { 
		doColumnResize(); 
	});
	
	doColumnResize();
}

function doColumnResize()
{
	var width = $jq('th.titleCol').width();
	
	$jq('td.titleCol').each(function(){
		$jq(this).width(width);
	});
	
	if($jq.browser.safari)
	{
		var emptyColWidth = '13px';
		
		if($jq.os.name == "mac")
		{
			emptyColWidth = '14px';
		}
	
		$jq('td.emptyCol').each(function(){
			$jq(this).width(emptyColWidth);
		});
	}
}

/*****Result page*******/
var _displayPanel = false;

var _resultsPageLoading = false;

function addResultsRequestHandlers()
{
	_resultsPageLoading = true;

	Sys.WebForms.PageRequestManager.getInstance().add_beginRequest(beginRequestHandler);
	Sys.WebForms.PageRequestManager.getInstance().add_endRequest(endRequestHandler);	
}
function showResults(buttonid)
{
	__doPostBack(buttonid, '');
}

function beginRequestHandler(sender, args)
{
	if(_resultsPageLoading)
	{
		_displayPanel = true;
		
		showLoadingPanel();
		
		// only show the loading panel when the search is being performed.  Not when there sorting, or other postbacks
		_resultsPageLoading = false;
	}
}
function endRequestHandler(sender, args)
{
	_displayPanel = false;
	showLoadingPanel();
}

function showLoadingPanel()
{
	if(_displayPanel)
	{
		document.getElementById("LoadingPanel").style.display = 'block';
	}
	else
	{
		document.getElementById("LoadingPanel").style.display = 'none';
	}
}
/*** Search Box/Default.aspx page ****/
function showSearchBox(buttonid)
{
	__doPostBack(buttonid, '');
}