//This Javascript library is being used in all of the pages as an include
// ==========================================================================
// Author : Holger
// ==========================================================================
function sa_bwcheck(){ 
  this.ver=navigator.appVersion
  this.agent=navigator.userAgent
  this.dom=document.getElementById?1:0
  this.opera5=this.agent.indexOf("Opera 5")>-1
  this.ie5=(this.ver.indexOf("MSIE 5")>-1 && this.dom && !this.opera5)?1:0; 
  this.ie6=(this.ver.indexOf("MSIE 6")>-1 && this.dom && !this.opera5)?1:0;
  this.ie4=(document.all && !this.dom && !this.opera5)?1:0;
  this.ie=this.ie4||this.ie5||this.ie6
  this.mac=this.agent.indexOf("Mac")>-1
  this.ns6=(this.dom && parseInt(this.ver) >= 5) ?1:0; 
  this.ns4=(document.layers && !this.dom)?1:0;
  this.bw=(this.ie6||this.ie5||this.ie4||this.ns4||this.ns6||this.opera5)
  return this
}
bw=new sa_bwcheck() //Browsercheck object

// NS4 resize bug fix
if (bw.ns4) {var origWidth = window.innerWidth;var origHeight = window.innerHeight; window.onresize = reDo;}
function reDo() {if (window.innerWidth != origWidth || window.innerHeight != origHeight) location.reload();}

function hoverMenu(obj, color, colorBg, cursor) {
	if (!bw.ns4){ 
		if (colorBg != '')
			obj.style.backgroundColor = colorBg;
		if (cursor != '')
			obj.style.cursor = cursor;
		if (obj.children)
			obj.children[0].style.color = color;
	}
}
//Used for setting the bg colors of Coordinates and Regions
function setClr(id, color)
{
  if (bw.ie) document.all[id].style.backgroundColor=color;
  if (bw.ns4) document.layer['id'].bgColor=color;
  if (bw.ns6 || bw.opera)
    document.getElementById(id).style.backgroundColor=color;
} 
// This function contains the Code to Show and hide the 
// any DIV - id that is passes as a parameter along
//with the state 
function ShowHideControls(DivID, iState) // 1 visible, 0 hidden
{
    if(document.layers)	   //NN4+
    {
       //document.layers[DivID].visibility = iState ? "show" : "hide";
       document.layers[DivID].display = iState ? "" : "none";
    }
    else if(document.getElementById)	  //gecko(NN6) + IE 5+
    {
        var obj = document.getElementById(DivID);
        //obj.style.visibility = iState ? "visible" : "hidden";
        obj.style.display = iState ? "" : "none";
    }
    else if(document.all)	// IE 4
    {
        //document.all[DivID].style.visibility = iState ? "visible" : "hidden";
        document.all[DivID].style.display = iState ? "" : "none";
    }
}
//Launches a new Browser Widow with specific requirements
function OpenURL(url) 
{
	var scr_w = screen.availWidth - 200;
	var scr_h = screen.availHeight - 160;
	var winconf = "height=" + scr_h + ",width=" + scr_w + ",left=75,toolbar=no, menubar=no, scrollbars=yes, resizable=yes, location=no, directories=no, status=yes";
	hWnd = window.open(url,'MARiS',config=winconf);
	hWnd.focus();
}
//Checks for all numeric attributes and validates coordinates
function IsNumeric(oElement)
   //  check for valid numer\ic strings
   {
	var strString = oElement.value;
	var strValidChars = "0123456789.-";
	var strChar;
	var blnResult = true;

    if ((strString.length == 0) || (strString.length > 8))
    {
      return false;
	}
    //  test strString consists of valid characters listed above
    for (i = 0; i < strString.length && blnResult == true; i++)
       {
       strChar = strString.charAt(i);
        if (strValidChars.indexOf(strChar) == -1)
         {
          blnResult = false;
          alert("Please Enter a Valid Numeric Character.");
         }
      }
    if(oElement.id == "txtNorth" || oElement.id == "txtSouth")
    {
		if((oElement.value < -89.00) || (oElement.value > 90.00))
		{
          blnResult = false;
          alert("Please Enter a Valid Coordinate.");		
		}
    }
    else if(oElement.id == "txtEast" || oElement.id == "txtWest")
    {
		if((oElement.value < -179.00 ) || (oElement.value > 180.00))
		{
          blnResult = false;
          alert("Please Enter a Valid Coordinate.");		
		}    
    }
    else if(oElement.id == "txtNorthMinutes" || oElement.id == "txtSouthMinutes" || oElement.id == "txtEastMinutes" || oElement.id == "txtWestMinutes")
    {
		if((oElement.value < 0) || (oElement.value > 59))
		{
		  blnResult = false;
          alert("Please Enter a Valid Coordinate.");		
		}
    }
   return blnResult;
   }
   
   
   //Checks for Positive Numneric Values
	function IsNumericPositive(oElement)
   //  check for valid numer\ic strings
   {
		var strString = oElement.value;
		var strValidChars = "0123456789.";
		var strChar;
		var blnResult = true;
		if ((strString.length == 0) || (strString.length >= 6))
		{
		return false;
		}
		//  test strString consists of valid characters listed above
		for (i = 0; i < strString.length && blnResult == true; i++)
		{
		strChar = strString.charAt(i);
			if (strValidChars.indexOf(strChar) == -1)
			{
			blnResult = false;
			alert("Please Enter a Valid Numeric Character.");
			}
		}
   return blnResult;
   }
   
   //Checks whether atleast one field is checked
  		function IsFieldsChecked(oElement,hidElement)
		{
			var i;
			var ctrl;
			var limit;
			var blnResult;
			limit = document.getElementById(hidElement)
 			for(i=0;i<limit.value;i++)
			{
				ctrl =  document.getElementById(oElement + i);
				if (ctrl != null)
					if(ctrl.checked)
					{
						blnResult = true;
						break;
					}
					else
					{
						blnResult = false;
						continue;
					}
			} 
		return blnResult;
		}
