//*************************************************************************//
//*************************************************************************//
//* *																	* *//
//* *	Author: Grey Cuunty Brett Lawson								* *//
//* *	Description: Contains functions that are used through out the	* *//
//* *				 Application		 								* *//
//* *	Date: 01/30/2005												* *//
//* *																	* *//
//*************************************************************************//
//*************************************************************************//

//***********************PopOut Function****************************
//Used to open windows through out the application
//Also tacks the opened windows in an array so that they can be cleaned
//up and closed at a later time
function PopOut(sURL,sTitle,iHeight,iWidth,ynScroll,ynResize,ynDependent,ynTitleBar,ynMenuBar,ynToolBar,ynStatus) {
	//check for adobe if printing labels
	if ((sURL.indexOf("MailLabels.aspx") != -1) || (sURL.indexOf("OpenPDF.aspx") != -1))
	{
		if ((m_pluginlist.indexOf("Acrobat Reader") == -1) && (m_pluginlist.indexOf("Acrobat Pro") == -1))
		{
			alert("Please install Adobe Reader 7.0 from \n 'http://www.adobe.com/products/acrobat/readstep2.html'");
			return false;
		}
	}
	
	//Try to open window
	var objWin;
	objWin = window.open(sURL, sTitle, "height="+iHeight+",width="+iWidth+",scrollbars="+ynScroll+",resizable="+ynResize+",dependent="+ynDependent+",titlebar="+ynTitleBar+",menubar="+ynMenuBar+",toolbar="+ynToolBar+",status="+ynStatus+"");
	//If successful add it to an array to track all opened windows
	if (objWin && !objWin.closed) 
	{
		if (parseInt(navigator.appVersion) >=4) objWin.window.focus();
		//add to window to array to close later
		winArray[winArray.length] = objWin;
		return true;
	}
	else
	{
		//check to see if popup was blocked
		alert('You need to disable you popup killer in order for the site to function.\n For IE GO TO Tools-->Internet Options-->Privacy. Click on Settings buttons and add http://gis.greycounty.ca .');
		hideWaitImage();
		return false;
	}
}

//***********************Sort DropDown list Functions****************************
//Parameters: HTML drop down object and a string to state what you want to sort on.
//You can sort on the Text as a float or string or on the Value as a text or string of the options in the dropdown box
function sortSelect (select, compareFunction) 
{
	if (!compareFunction)
	{
	compareFunction = compareText;
	}
	var options = new Array (select.options.length);
	for (var i = 0; i < options.length; i++)
	{
	
	options[i] = new Option (select.options[i].text, select.options[i].value, select.options[i].defaultSelected, select.options[i].selected);
	}

	//Set a variable to hold the selected option
	var selectedItem = "";
	for (var i = 0; i < select.options.length; i++)
	{
	if (select.options[i].selected)
	{
		selectedItem = select.options[i].text;
		break;
	}
	
	}
	//Sort Options
	options.sort(compareFunction);
	select.options.length = 0;
	for (var i = 0; i < options.length; i++)
	{
		select.options[i] = options[i];
	}	

	//set all option to not selected
	for (var i = 0; i < select.options.length; i++)
	{
	select.options[i].selected = false;
	select.options[i].defaultSelected = false;
	
	}

	//Select the appropriate option
	for (var i = 0; i < select.options.length; i++)
	{
	if (select.options[i].text == selectedItem)
	{
		select.options[i].selected = true;
		select.options[i].defaultSelected = true;
		break;
	}
	}

}
//Helper funtion for the sorting of dropdown boxes
//Sort on the Text of the options as a String
function compareText (option1, option2) {
  return option1.text < option2.text ? -1 :
    option1.text > option2.text ? 1 : 0;
}
//Sort on Value of the options as a String
function compareValue (option1, option2) {
  return option1.value < option2.value ? -1 :
    option1.value > option2.value ? 1 : 0;
}
//Sort on Text of the options as a Float
function compareTextAsFloat (option1, option2) {
  var value1 = parseFloat(option1.text);
  var value2 = parseFloat(option2.text);
  return value1 < value2 ? -1 :
    value1 > value2 ? 1 : 0;
}
//Sort on Value of the options as a Float
function compareValueAsFloat (option1, option2) {
  var value1 = parseFloat(option1.value);
  var value2 = parseFloat(option2.value);
  return value1 < value2 ? -1 :
    value1 > value2 ? 1 : 0;
}
//***********************Functions to change image on mouse over and out****************************
function imgRollOn(imgName,imgObject)
{
	if (document.images) {
	imgOn = eval(imgName + "on.src");
	imgObject.src = imgOn;
	}
}

//Function toggle images from Off to ON fired by onMouseOut
function imgRollOff(imgName,imgObject) {
	if (document.images) {
	imgOff = eval(imgName + "off.src");
	imgObject.src = imgOff;
	}
}

//Function to position and show wait image in pages
function showWaitImage(inLoadingImg) {
	inLoadingImg.style.top = (parseInt(cwinH) /2) - (inLoadingImg.height / 2);
    inLoadingImg.style.left = (parseInt(cwinW) / 2) - (inLoadingImg.width / 2);
	inLoadingImg.style.visibility = 'visible';
}

//Function to set the location of frames
function setURL()
{
	parent.logo.location="Logo.aspx?Application=" + Application;
	parent.tabs.location="ListBar.aspx?Application=" + Application + "&ScreenHeight=" + cwinH;
	//parent.tabs.location="tabs.aspx?Application=" + Application;
	parent.banner.location="Banner.aspx?Application=" + Application;
	//parent.main.location="map.aspx?HEIGHT=" + m_hvMapHeight + "&WIDTH=" + m_hvMapWidth + "&Application=" + Application;
	
	//Map URL
	var sURL = "Map.aspx"+
		         "?WIDTH="+m_hvMapWidth+
				 "&HEIGHT="+m_hvMapHeight+
				 "&Application="+Application;
	if (in_hvStrQuery != '')
	{
		sURL += "&QUERY="+escape(in_hvStrQuery);
	}
	if (in_hvSelect != '')
	{
		sURL += "&SELECT="+in_hvSelect;
	}
	if (in_hvBuffer != '')
	{
		sURL += "&BUFFER="+in_hvBuffer;
	}
	if (in_hvLayersToBuffer != '')
	{
		sURL += "&BUFFLAYERS="+in_hvLayersToBuffer;
	}
	if (in_LayerVisible != '')
	{
		sURL += "&LAYERINFO="+in_LayerVisible;
	}
	if (in_hvIsNewQuery != '')
	{
		sURL += "&NEWQUERY="+in_hvIsNewQuery;
	}
	
	parent.main.location = sURL;
}

//Function to set the window status
function setWindowStatus(inString)
{
	window.status = inString; 
	return true;
}
//Function to set the ini values on load
function iniValues()
{
	getInternalSize();
	setURL();
	setWindowStatus("Welcome " + m_User);
}

//Function to trim off blank spaces
function strtrim(inString) {
    //Match spaces at beginning and end of text and replace
    //with null strings
    return inString.replace(/^\s+/,'').replace(/\s+$/,'');
}



