// ###########################################################
// function getInsideWindowWidth()
// This function returns the indise width of the browser
// window in pixels.

function getInsideWindowWidth() {
        if (window.innerWidth) return window.innerWidth
		else return document.body.clientWidth }

// end getInsideWindowWidth()

// ###########################################################
// function getInsideWindowHeight()
// This function returns the indise height of the browser
// window in pixels.

function getInsideWindowHeight() {
        if (window.innerHeight) return window.innerHeight
		else return document.body.clientHeight }

// end getInsideWindowHeight()

// ###########################################################
// function findWidth(objectID)
// This function receives a DHTML layer object ID, and returns
// the element's width value in pixels.

function findWidth(objectID) {

	var dom = findDOM(objectID,0);
	if (dom.offsetWidth) 
		return dom.offsetWidth;
	if (dom.clip.width)
		return dom.clip.width;
	return (null);
	
}
// end function findWidth(objectID)

// ###########################################################
// function findHeight(objectID)
// This function receives a DHTML layer object ID, and returns
// the element's height value in pixels.

function findHeight(objectID) {

	var dom = findDOM(objectID,0);
	if (dom.offsetHeight) 
		return dom.offsetHeight;
	if (dom.clip.height)
		return dom.clip.height;
	return (null);
	
}
// end function findWidth(objectID)

// ###########################################################
// function shiftTo(obj,x,y)
// This function receives a DHTML layer object ID, and an x/y 
// coordinate. The object is moved to the specified x/y
// location within the browser window.

function shiftTo(objID, x, y) {
	objRef = findDOM(objID,1);
	objRef.left = x;
	objRef.top = y;
}
// end function shiftTo(obj,x,y)

// ###########################################################
// function hideObject(objID)
// This function receives an object ID, creates the
// appropriate object reference based on browser type, and sets
// the object's visibility attribute to "hidden".

function hideObject(objID) {

	objRef = findDOM(objID,1);
	objRef.visibility = 'hidden';
}
// end function hideObject(objID)

// ###########################################################
// function showObject(objID)
// This function receives an object ID, creates the
// appropriate object reference based on browser type, and sets
// the object's visibility attribute to "visible".

function showObject(objID) {

	objRef = findDOM(objID,1);
	objRef.visibility = 'visible';
}
// end function showObject(objID)

// ###########################################################
// function popCenter(obj)
// This function receives a DHTML object and pops it up in the
// center of the window the object resides on.

function popCenter(obj) {

	// find object's dimensions...
	objWidth = findWidth(obj);
	objHeight = findHeight(obj);
	
	// determine centerpoint for object placement...
	x = Math.round((getInsideWindowWidth()-objWidth)/2);
    y = Math.round((getInsideWindowHeight()-objHeight)/2);
	
	// move object to x/y coord and display it...
    shiftTo(obj,x,y);
    showObject(obj);
	
} // end function popCenter(obj)


popWin = null;

function popWindow(src, nm, w, h, scrolling, resizing) {
	if (popWin!=null) {
    	if (!popWin.closed) {
        	loc = popWin.location + ' ';
            if (loc.indexOf(src)==-1) popWin.close();
            else {
            	popWin.focus();
                return;
            }
        }
	}
    x = Math.round((screen.availWidth-w)/2);
    y = Math.round((screen.availHeight-h)/2);
    isScroll = (scrolling) ? 'yes' : 'no';
    if (scrolling=='yes') w+=16;
    resz = (resizing) ? 'yes' : 'no';
    popWin = window.open(src,nm,'toolbar=no,location=no,directories=no,status=no,scrollbars='+isScroll+',resizable='+resz+',copyhistory=no,width='+w+',height='+h+',left='+x+',top='+y+',screenX='+x+',screenY='+y);
} // end function popWindow()


// open or close an individual help string
function openCloseHelp(divId)
{
	// help is open.  Close it
	if (document.getElementById(divId + 'Help').style.display == "")  { 
		// When an element's style.display is set to 'none', element is hidden and subsequent elements in flow fill in area normally occupied by this element.		
		document.getElementById(divId + 'Help').style.display = "none"; 
	} 
	else // help is closed.  Open it
	{  
		// When an element's style.display is set to '' (empty string, or not 'none'), 
		// element is displayed and subsequent elements in flow are displayed after this element.		
		document.getElementById(divId + 'Help').style.display = ""; 
	}
}


function checkLoginSet(theForm)
{
	if (theForm.adminUser.value == "")
	{
		alert("Please set a username.");
		return false;
	}

	if (theForm.adminPassword.value == "")
	{
		alert("Please set a password.");
		return false;
	}
	
	if (theForm.adminPassword.value != theForm.confirm_password.value)
	{
		alert("The passwords do not match");
		return false;
	}
	
	return true;
}

function checkInputs(theForm)
{
	var errorString = "";

	// check that a host is specified
	if (theForm.appServerMachine.value == "")
	{
		errorString = "You must specify the name of the ArcIMS host machine.";
	}

	// check that a port is specified
	if (theForm.appServerClientPort.value == "")
	{
		errorString = errorString + "\nYou must specify the name of the ArcIMS client port.";
	}

	// check that the capabilities directory is set is specified
	if (theForm.capabilitiesDir.value == "")
	{
		errorString = errorString + "\nYou must specify the path for the capabilities directory.";
	}
	
	// check that the capabilities directory only uses forward slashes.
	if (theForm.capabilitiesDir.value.indexOf("\\") != -1)
	{	
		var newString = "";
		
		for (i = 0; i < theForm.capabilitiesDir.value.length; i++)
		{
			if (theForm.capabilitiesDir.value.substr(i,1) == "\\")
			{
				newString = newString + "/";
			}
			else
			{
				newString = newString + theForm.capabilitiesDir.value.substr(i,1);
			}
			
		}
		theForm.capabilitiesDir.value = newString;	
	}

	// check that a default service is specified
	if (theForm.defaultService.value == "")
	{
		errorString = errorString + "\nYou must specify the name of a service that will be used as the default service.";
	}
	
	if (errorString != "")
	{
		alert(errorString);
		return false;
	}
	
	return true;
}


function mapLoading(status)
{	
	if (status == 'loadingOff') {
		document.getElementById('mapLoading').style.display = "none"; 
		document.getElementById('mapLoaded').style.display = ""; 
	} 
	else if (status == 'loadingOn') {
		document.getElementById('mapLoading').style.display = ""; 
		document.getElementById('mapLoaded').style.display = "none"; 	
	}

}