<!--
	// This javascript is common functions used within the application

	// Parse the url querystring for the specified parameter
	function PageQuery(q, delimiter)
	{
		if(q.length > 1) this.q = q.substring(1, q.length);
		else this.q = null;
		this.keyValuePairs = new Array();
		if(q)
		{
			for(var i=0; i < this.q.split(delimiter).length; i++)
			{
				this.keyValuePairs[i] = this.q.split(delimiter)[i];
			}
		}
		this.getKeyValuePairs = function() { return this.keyValuePairs; }
		this.getValue = function(s)
		{
			for(var j=0; j < this.keyValuePairs.length; j++)
			{
				if(this.keyValuePairs[j].split("=")[0] == s)
					return this.keyValuePairs[j].split("=")[1];
			}
			return false;
		}
		this.getParameters = function()
		{
			var a = new Array(this.getLength());
			for(var j=0; j < this.keyValuePairs.length; j++)
			{
				a[j] = this.keyValuePairs[j].split("=")[0];
			}
			return a;
		}
		this.getLength = function() { return this.keyValuePairs.length; } 
	}
	
	// get the url query string key value
	function queryString(key)
	{
		var page = new PageQuery(window.location.search, '&'); 
		return unescape(page.getValue(key)); 
	}
	
	// get the query string parameter (or any other key=value string) key value
	function queryParameter(query, key)
	{
		var page = new PageQuery(query, ' ');
		return unescape(page.getValue(key));
	}
	
	
	// Close the active radWindow
	function CloseWin()
	{
		var oWindow = GetRadWindow();			
		oWindow.Close();
	}


	// Get the check box control from the specified radGrid column control
    function GetCheckBox(control)
    {
        if (!control)
            return;

        for (var i = 0; i < control.childNodes.length; i++)
        {
            if (!control.childNodes[i].tagName)
                continue;

			if(control.childNodes[i].tagName == "SPAN")
            {
              if((control.childNodes[i].childNodes[0].tagName.toLowerCase() == "input") &&
                (control.childNodes[i].childNodes[0].type.toLowerCase() == "checkbox"))
              {
                return control.childNodes[i].childNodes[0];
              }
            }
            else if ((control.childNodes[i].tagName.toLowerCase() == "input") &&
                (control.childNodes[i].type.toLowerCase() == "checkbox"))
            {
                return control.childNodes[i];
            }
        }
	}
	
	
	// Get the img element from the specified radGrid column control
    function GetImgElement(control)
    {
        if (!control)
            return;

        for (var i = 0; i < control.childNodes.length; i++)
        {
            if (!control.childNodes[i].tagName)
                continue;
			if(control.childNodes[i].tagName.toLowerCase() == "span")
            {
              if((control.childNodes[i].childNodes[0].tagName.toLowerCase() == "img"))
              {
                return control.childNodes[i].childNodes[0];
              }
            }
            else if ((control.childNodes[i].tagName.toLowerCase() == "img"))
            {
                return control.childNodes[i];
            }
        }
	}  
    
    
    // Get the radio button control from the specified radGrid column control
    function GetRadioButton(control)
    {
        if (!control)
            return;

        for (var i = 0; i < control.childNodes.length; i++)
        {
            if (!control.childNodes[i].tagName)
                continue;

			if(control.childNodes[i].tagName == "SPAN")
            {
              if((control.childNodes[i].childNodes[0].tagName.toLowerCase() == "input") &&
                (control.childNodes[i].childNodes[0].type.toLowerCase() == "radio"))
              {
                return control.childNodes[i].childNodes[0];
              }
            }
            else if ((control.childNodes[i].tagName.toLowerCase() == "input") &&
                (control.childNodes[i].type.toLowerCase() == "radio"))
            {
                return control.childNodes[i];
            }
        }
    }

	
	// Get the selected HTML radio option value
	function getSelectedRadioValue(rb)
	{
		var rbVal;
		for (var i = 0; i < rb.length; i++)
		{
			if (rb[i].checked)
			{
				rbVal = rb[i].value;
				break;
			}
		}
		return rbVal;
	}
	
	// Set the specified HTML radio option to the specified value
	function setSelectedRadioValue(rb, rbVal)
	{
		for (var i = 0; i < rb.length; i++)
		{
			if (rb[i].value == rbVal)
			{
				rb[i].checked = true;
				break;
			}
		}
	}

	
	// Replace a string within a string - does not use regex
	// and will replace characters such as + that the javacript replace will not.
	function replaceSubstring(inputString, fromString, toString) {
		var temp = inputString;
		if (fromString == "") {
			return inputString;
		}
		if (toString.indexOf(fromString) == -1) { 
			while (temp.indexOf(fromString) != -1) {
				var toTheLeft = temp.substring(0, temp.indexOf(fromString));
				var toTheRight = temp.substring(temp.indexOf(fromString)+fromString.length, temp.length);
				temp = toTheLeft + toString + toTheRight;
			}
		} else { 
			var midStrings = new Array("~", "`", "_", "^", "#");
			var midStringLen = 1;
			var midString = "";

			while (midString == "") {
				for (var i=0; i < midStrings.length; i++) {
					var tempMidString = "";
					for (var j=0; j < midStringLen; j++) { tempMidString += midStrings[i]; }
					if (fromString.indexOf(tempMidString) == -1) {
					midString = tempMidString;
					i = midStrings.length + 1;
					}
				}
			}
			while (temp.indexOf(fromString) != -1) {
				var toTheLeft = temp.substring(0, temp.indexOf(fromString));
				var toTheRight = temp.substring(temp.indexOf(fromString)+fromString.length, temp.length);
				temp = toTheLeft + midString + toTheRight;
			}
			while (temp.indexOf(midString) != -1) {
				var toTheLeft = temp.substring(0, temp.indexOf(midString));
				var toTheRight = temp.substring(temp.indexOf(midString)+midString.length, temp.length);
				temp = toTheLeft + toString + toTheRight;
			}
		} 
		return temp; 
	} 
	
	
	// Executes a button click when the user presses the Enter button in a textbox
	// To use this, assign the keypess event to the textbox, and specify the button to click
	// i.e. Me.TextBox1.Attributes.Add("onkeypress", "return clickButton(event,'" + Me.Button1.ClientID + "')")
	function clickButton(e, buttonid)
	{
		var bt = document.getElementById(buttonid);
		if (typeof bt == 'object'){ 
			if(navigator.appName.indexOf("Netscape")>(-1)){ 
					if (e.keyCode == 13){ 
						bt.click(); 
						return false; 
					} 
			} 
			if (navigator.appName.indexOf("Microsoft Internet Explorer")>(-1)){ 
					if (event.keyCode == 13){ 
						bt.click(); 
						return false; 
					} 
			} 
		} 
	}
	
	
	// pauses or waits the specified milliseconds before continuing
	function pausecomp(millis) 
	{
		var date = new Date();
		var curDate = null;

		do { curDate = new Date(); } 
		while(curDate-date < millis);
	}


    // Set the focus to the control
    function setFocus(controlid)
    {
	    var el = document.getElementById(controlid);
	    if (el)
	    {
		    el.focus();
	    }
    }
    
    
    // Test routine
    function clickTest()
    {
        alert('clickTest');
    }


    // Print the current window to the printer - display the print dialog
    function printWindow()
    {
	    browserVersion = parseInt(navigator.appVersion)
	    if (browserVersion >= 4) window.print();
    }

//-->