﻿function clearText(elementName) {
    document.getElementById(elementName).value = '';
}

function getValue(varname)
{
	// First, we load the URL into a variable
  	var url = window.location.href;
  	// Next, split the url by the ?
  	var qparts = url.split("?");
  	// Check that there is a querystring, return "" if not
  	if (qparts.length <= 1)
  	{
  		return "";
  	}
  	// Then find the querystring, everything after the ?
  	var query = qparts[1];
  	// Split the query string into variables (separates by &s)
  	var vars = query.split("&");
  	// Initialize the value with "" as default
  	var value = "";
  	// Iterate through vars, checking each one for varname
  	for (i=0;i<vars.length;i++)
  	{
    		// Split the variable by =, which splits name and value
    		var parts = vars[i].split("=");
    		// Check if the correct variable
    		if (parts[0] == varname)
    		{
      			// Load value into variable
      			value = parts[1];
      			// End the loop
      			break;
    		}
  	}
  	// Convert escape code
  	value = unescape(value);
  	// Convert "+"s to " "s
  	value.replace(/\+/g," ");
  	// Return the value
  	return value;
}

function popup(page, width, height, menubar, toolbar, directories, location, status, scrollbars, resizable) {
    var str =  "toolbar=" + toolbar + ",menubar=" + menubar + ",directories=" + directories + ",location=" + location + ",status=" + status + ",scrollbars=" + scrollbars + ",width="+ width + ",height=" + height + ",resizable=" + resizable;
    winsecure=window.open(page, "", str, true);
	if (document.getElementById) winsecure.moveTo(Math.round((screen.width-width)/2) , Math.round((screen.height-height)/2));
	winsecure.focus();
	winsecure.opener = this;
}

function goBack(numPages) {
    history.go(-numPages)
}

function hideInstructions() {
    document.getElementById("divInstructions").style.display = 'none';
}

function setDivHeight(divName, height, ffReducer, ieReducer) {
    var windowheight = height;
    var div = document.getElementById(divName);
    if (window.innerHeight != null)
    {
        windowheight = window.innerHeight - ffReducer;
    }
    else if (document.body.clientHeight != null)
    {
        windowheight = document.documentElement.clientHeight - ieReducer;
    }
    div.style.height = windowheight + "px";
}

function disableAutoComplete() {
    if (document.getElementsByTagName)
    {
        var inputElements = document.getElementsByTagName("input");
        for (i=0; inputElements[i]; i++)
        inputElements[i].setAttribute("autocomplete","off");
    }
}

function IsNumeric(sText){
    var ValidChars = "-0123456789.";
    var IsNumber=true;
    var Char;

    for (i = 0; i < sText.length && IsNumber == true; i++) 
    { 
        Char = sText.charAt(i); 
        if (ValidChars.indexOf(Char) == -1) 
        {
            IsNumber = false;
        }
    }
    return IsNumber;
}

/*function insertFlash(page)
{
    var flashContent = ""
    var flashInfo = getFlashVersion();
    
    if (flashInfo["major"] > 0)
    {
        var flashDiv = document.getElementById("message");
        
        if (page == "index")
        {
            flashContent = '<object classid="clsid:d27cdb6e-ae6d-11cf-96b8-444553540000" codebase="http://fpdownload.macromedia.com/pub/shockwave/cabs/flash/swflash.cab#version=8,0,0,0" width="437" height="201" id="homepage5" align="middle"><param name="allowScriptAccess" value="sameDomain" /><param name="movie" value="_flash/homepage6.swf" /><param name="quality" value="high" /><param name="bgcolor" value="#ffcc00" /><param name="wmode" value="transparent" /><embed src="_flash/homepage6.swf" wmode="transparent" quality="high" bgcolor="#ffcc00" width="437" height="201" name="homepage5" align="middle" allowScriptAccess="sameDomain" type="application/x-shockwave-flash" pluginspage="http://www.macromedia.com/go/getflashplayer" /></object>'
        } 
        else if (page == "map")
        {
            flashContent = '<object classid="clsid:d27cdb6e-ae6d-11cf-96b8-444553540000" codebase="http://fpdownload.macromedia.com/pub/shockwave/cabs/flash/swflash.cab#version=8,0,0,0" width="180" height="334" id="demo5" align="middle"><param name="allowScriptAccess" value="sameDomain" /><param name="movie" value="_flash/demo5.swf" /><param name="quality" value="high" /><param name="bgcolor" value="#ffffff" /><embed src="_flash/demo5.swf" quality="high" bgcolor="#ffffff" width="180" height="334" name="demo5" align="middle" allowScriptAccess="sameDomain" type="application/x-shockwave-flash" pluginspage="http://www.macromedia.com/go/getflashplayer" /></object>'
        }
	    flashDiv.innerHTML = flashContent;
    }
}
*/
function getFlashVersion()
{
    var flashVersion = new Array();
    
    flashVersion["major"] = 0;
    flashVersion["build"] = 0;
    
    if (navigator.plugins && typeof navigator.plugins["Shockwave Flash"] == "object")
    {
        var description = navigator.plugins["Shockwave Flash"].description;
        
        if (description != null)
        {
            var versionString = description.replace(/^.*\s+(\S+\s+\S+$)/, "$1");
            
            flashVersion["major"] = parseInt(versionString.replace(/^(.*)\..*$/, "$1"));
            flashVersion["build"] = parseInt(versionString.replace(/^.*r(.*)$/, "$1"));
        }
    }
    else if (typeof window.ActiveXObject != "undefined")
    {
        try
        {
            var flashObject = new ActiveXObject("ShockwaveFlash.ShockwaveFlash");
            var description = flashObject.GetVariable("$version");
            
            if (description != null)
            {
                var versionNumbers = description.replace(/^\S+\s+(.*)$/, "$1").split(",");
                
                flashVersion["major"] = parseInt(versionNumbers[0]);
                flashVersion["build"] = parseInt(versionNumbers[2]);
            }
        }
        catch(error)
        {}
    }
    
    return flashVersion;
}

function highLightInstructions(element, color) {
    var i = document.getElementById(element);
    i.setAttribute("class", color);
    i.setAttribute("className", color);
}

function setACZIndex() {
    var test = document.getElementById('autoComplete1_completionListElem');
    if (test != undefined) {
        test.style.zIndex = 6000;
    }
}