function GetXmlHttpObject()
{
var xmlHttp=null;
try
  {
  // Firefox, Opera 8.0+, Safari
  xmlHttp=new XMLHttpRequest();
  }
catch (e)
  {
  // Internet Explorer
  try
    {
    xmlHttp=new ActiveXObject("Msxml2.XMLHTTP");
    }
  catch (e)
    {
    xmlHttp=new ActiveXObject("Microsoft.XMLHTTP");
    }
  }
return xmlHttp;
}

function isExisting(obj){
  return typeof(obj)!='undefined';
}
function validate_near_search(thisform){
	with(thisform){
	var sexCoordRegEx1 = /^[+,-]?\d{2}:\d{2}:\d{2}$/
	var sexCoordRegEx2 = /^[+,-]?\d{2}:\d{2}$/
	var sexCoordRegEx3 = /^[+,-]?[0-9]{2}:[0-9]{2}:[0-9]{2}\.?[0-9]*$/
	var decCoordRegEx = /^[+,-]?\d{0,3}\.?\d*$/
	if (bell.checked==false && rct.checked==false && crimea.checked==false){
                        alert("Must have at least one check box checked")
                        return false
        }
        else if (validate_required(RA,"Must enter RA")==false){
                RA.focus()
                return false
        }
        else if (validate_required(DEC,"Must enter DEC")==false){
                DEC.focus()
        	return false
       	}
        else if (validate_required(radius,"Must enter a search radius")==false){
                return false
        }
	else if (coordtype[0].checked){
		if ((sexCoordRegEx1.test(RA.value)==false && sexCoordRegEx2.test(RA.value)==false && sexCoordRegEx3.test(RA.value)==false))
		{
                	alert("The RA is in the wrong format it should either be HH:MM or HH:MM:SS or HH:MM:SS.XX")
			return false
		}
		else if ((sexCoordRegEx1.test(DEC.value)==false && sexCoordRegEx2.test(DEC.value)==false && sexCoordRegEx3.test(DEC.value)==false)){
			alert("The DEC is in the wrong format it should either be HH:MM or HH:MM:SS or HH:MM:SS.XX")
			return false
		}
	}
	else if (coordtype[1].checked){
		if (decCoordRegEx.test(RA.value)==false){
			alert("The RA is in the wrong format please enter it using X.XX format")
			return false
		}
		else if (decCoordRegEx.test(DEC.value)==false){
			alert("The DEC is in the wrong format please enter it using X.XX format")
			return false
		}
	}

	}
}
function validate_object_search(thisform)
{
        with (thisform)
        {
		var dateRegEx = /\d{4}-\d{2}-\d{2}/
		if (bell.checked==false && rct.checked==false && crimea.checked==false){
                        alert("Must have at least one check box checked")
                        return false
                }
		else if (dateto.value.length > 0 && dateRegEx.test(dateto.value)==false){
			alert("Must put the date in the YYYY-MM-DD format for the date to")
			return false
		}
		else if (datefrom.value.length > 0 && dateRegEx.test(datefrom.value)==false){
			alert("Must put the date in the YYYY-MM-DD format for the date from")
			return false
		}
        }
}

var checkflag = "false";
function check(field) {
        if (checkflag == "false") {
		if (field.length > 0){
                	for (i = 0; i < field.length; i++) {
                        	field[i].checked = true;
                	}
		}
		else{
			field.checked = true;
		}
                checkflag = "true";
                return "Uncheck All";
        } else {
		if (field.length > 0){
        		for (i = 0; i < field.length; i++) {
                		field[i].checked = false;
       			}
		}
		else {
			field.checked = false;
		}
        	checkflag = "false";
        	return "Check All";
        }
}
function validate_download(field) {
	var noChecked = true;
        with (field) {
		
		for(i = 0;i <= files.length;i++){
			if(files[i].checked == true){
				noChecked = false
				break
			}
		}
		if (files.checked ==true){
			noChecked = false
		}
                if (noChecked == true)
                {
                        alert("Must have at least one check box checked")
                        return false
                }
		//else if (files.length >= 1000){
		//	alert("Please select a file amount below 1000")
		//	return false
		//}
        }
}
function reset(thisform){
        with (thisform) {
                RA.value = ""
                DEC.value = ""
                radius.value = 2.0
        }
}

function validate_required(field,alerttxt)
{
        with (field)
        {
                if (value==null||value=="")
                {
                        alert(alerttxt)
                        return false
                }
                else {
                        return true
                }
        }
}

window.onload = initPage;  
// Make sure that no other javscripts assign a fuction to window.onload
// There can be only one window.onload at a time

function initPage() {
  initPopupLinks();
  // place here any other code you wish to run when the page loads.
}

function initPopupLinks()
{
  if (!document.getElementsByTagName) return true;
  var pageLinks = document.getElementsByTagName("a");
  for (var i = 0; i < pageLinks.length; i++) 
  {
    if (((pageLinks[i].className != null) && 
         (pageLinks[i].className != "")) ||
        ((pageLinks[i].parentNode.className != null) && 
         (pageLinks[i].parentNode.className != "")))
    {
      var linkClass = " " + pageLinks[i].className + " ";
      if ((linkClass == "  ") && (pageLinks[i].parentNode.className != ""))
      {
        linkClass = " " + pageLinks[i].parentNode.className + " ";
      }
      for (var theKey in popupLinkConfig) 
      {
        if (linkClass.indexOf(" " + theKey + " ") > -1)
        {
          if ((pageLinks[i].target == "") || (pageLinks[i].target == null))
          {
            pageLinks[i].target = (popupLinkConfig[theKey][0] != "") ? popupLinkConfig[theKey][0] : theKey;
          }
          pageLinks[i].settings = popupLinkConfig[theKey][1];
          pageLinks[i].onclick = popUp;
        }
      }
    }
  }
  return true;
}

function popUp()
{
  newWin = window.open(this.href, this.target, this.settings);
  newWin.focus();
  return false;
} 

var popupLinkConfig = new Array;
// Delete/copy/modify the following lines to configure your popup windows.
popupLinkConfig["popup"] = new Array ( "", "width=350,height=650,scrollbars=yes");
popupLinkConfig["glossary"] = new Array ( "help", "width=550,height=350,resizable=no,scrollbars=no");


function show(id) {
	window.onload=show;
	var d = document.getElementById(id);
	for (var i = 1; i<=10; i++) {
		if (document.getElementById('smenu'+i)) {
			document.getElementById('smenu'+i).style.display='none';
		}
	}
	if (d) {
		d.style.display='block';
	}
}
