function chRA(ra){
  var rra=ra/15.
  with (Math) {
    var Irh = floor(rra)
    var ram = (rra - Irh)*60.
    var Irm = floor(ram)
    var rasec = ram - Irm
    var Rsec = rasec*60.
    if ( Rsec == 60.0 ) {
     Rsec = 0.0
     Irm = Irm + 1
    }
    if ( Irm == 60.0 ) {
      Irm = 0.0
      Irh = Irh + 1
    }
    if ( Irh >= 24.0 ) Irh = Irh - 24.0
    if ( Irh < 10.0 ) Irh = "0"+Irh
    if ( Irm < 10.0 ) Irm = "0"+Irm
    var Rrsec = floor(Rsec*10.)/10.
    if ( Rrsec < 10.0 ) Rrsec = "0"+Rrsec
    if ( (Rrsec - floor(Rrsec)) == 0 ) Rrsec = Rrsec+".0"
  }
  var text = Irh+" "+Irm+" "+Rrsec
  return text
}
function chDEC(dec){
  with (Math) {
    var sign="+"
    var ddec=abs(dec)
    if ( dec < 0.0 ) {
      var sign="-"
    }
    var Idd = floor(ddec)
    var rdm = (ddec - Idd)*60.
    var Idm =floor(rdm)
    var Dsec = (rdm - Idm)*60.
    if ( Dsec == 60.0 ) { 
     Dsec = 0.0
     Idm = Idm + 1
    }
    if ( Idm == 60.0 ) {
      Idm = 0.0
      Idd = Idd + 1
    }
    if ( Idd < 10.0 ) Idd = "0"+Idd
    if ( Idm < 10.0 ) Idm = "0"+Idm
    var Rdsec = floor(Dsec*10.)/10.
    if ( Rdsec < 10.0 ) Rdsec = "0"+Rdsec
    if ( (Rdsec - floor(Rdsec)) == 0 ) Rdsec = Rdsec+".0"
  }
  var text = sign+Idd+" "+Idm+" "+Rdsec
  return text
}
 function rmlbl(astring) {
// removes leading blanks in a string
 max = astring.length
 for (i=0 ; i < max ; i++ ) {
   isn = astring.indexOf(" ")
   if ( isn == 0 ) {astring=astring.substring(1,astring.length)}
    else {break}
  }
  return astring
}
function rmtbl(astring) {
// removes trailing blanks in a string
 isn = astring.lastIndexOf(" ")
 if ( ( isn < 0 ) || ( isn < astring.length - 1) ) return astring
 max = astring.length
 for (i=0 ; i < max ; i++ ) {
   isn = astring.lastIndexOf(" ")
   if ( ( isn > 0 ) && ( isn == astring.length-1 ) )
         {astring=astring.substring(0,isn)}
    else {break}
 }
   return astring
} 
function splitString(mystring) {
 is_a_name=mystring.indexOf(",")
 if (is_a_name <= 1) {
  document.form1.source.value=mystring
  return true
 }else{
  ra_dec=mystring.split(",")
  ra_dec[0]=rmlbl(ra_dec[0])
  ra_dec[1]=rmlbl(ra_dec[1])
  ra_dec[0]=rmtbl(ra_dec[0])
  ra_dec[1]=rmtbl(ra_dec[1])
  rr = ra_dec[0].split(" ")
  rd = ra_dec[1].split(" ")
  for (i=0; i < rr.length ; i++ ) {
    if( isNaN(rr[i]) ) {
      alert
    (' there is something wrong with the coordinates, please check them')
    return false
    }
  }
  for (i=0; i < rd.length ; i++ ) {
    if( isNaN(rd[i]) ) {
      alert
    (' there is something wrong with the coordinates, please check them')
    return false
    }
  }
  if ( rr.length == 1 ) {
         if ( ( ra_dec[0] < 0 ) || (ra_dec[0] >= 360 ) ) {
         alert
         (' there is something wrong with the coordinates, please check them')
         return false }
         document.form1.RA.value=chRA(ra_dec[0])
         document.form1.ra.value=chRA(ra_dec[0])
    } else if (rr.length == 2 ) {
       if ( ( rr[0] < 0 ) || (rr[0] > 23 ) ||  (rr[1] < 0 ) ||  (rr[1] > 60 ))
{
         alert
         (' there is something wrong with the coordinates, please check them')
         return false }
       if ( rr[0].length == 1 ) rr[0] ="0"+rr[0]
       if ( rr[1].length == 1 ) rr[1] ="0"+rr[1]
       document.form1.RA.value=rr[0]+" "+rr[1]+" 00.0"
       document.form1.ra.value=rr[0]+" "+rr[1]+" 00.0"
    } else if (rr.length == 3 ) {
       if ( ( rr[0] < 0 ) || (rr[0] > 23 ) ||  (rr[1] < 0 ) ||  (rr[1] >= 60 )
|| ( rr[2] < 0 ) ||  (rr[2] >= 60 ))  {
         alert
         (' there is something wrong with the coordinates, please check them')
         return false }
       if ( rr[0].length == 1 ) rr[0] ="0"+rr[0]
       if ( rr[1].length == 1 ) rr[1] ="0"+rr[1]
       if ( rr[2].length == 1 ) rr[2] ="0"+rr[2]
       dot=rr[2].indexOf(".")
       if ( dot < 1 ) rr[2] +=".0"
       document.form1.RA.value=rr[0]+" "+rr[1]+" "+rr[2]
       document.form1.ra.value=rr[0]+" "+rr[1]+" "+rr[2]
    }
   if ( rd.length == 1 ) {
         if ( ( ra_dec[1] < -90 ) || (ra_dec[1] > 90 ) ) {
         alert
         (' there is something wrong with the coordinates, please check them')
         return false }
         document.form1.DEC.value=chDEC(ra_dec[1])
         document.form1.dec.value=chDEC(ra_dec[1])
    } else if (rd.length == 2 ) {
       if ( ( rd[0] < -90 ) || (rd[0] > 90 ) ||  (rd[1] < 0 ) ||  (rd[1] >= 60
)) {
         alert
         (' there is something wrong with the coordinates, please check them')
         return false }
       if ( rd[0].length == 1 ) rd[0] ="0"+rd[0]
       if ( rd[1].length == 1 ) rd[1] ="0"+rd[1]
       document.form1.DEC.value=rd[0]+" "+rd[1]+" 00.0"
       document.form1.dec.value=rd[0]+" "+rd[1]+" 00.0"
    } else if (rd.length == 3 ) {
       if ( ( rd[0] < -90 ) || (rd[0] > 90 ) ||  (rd[1] < 0 ) ||  (rd[1] > 60 ) || ( rd[2] < 0 ) ||  (rd[2] >= 60 ))  {
         alert
         (' there is something wrong with the coordinates, please check them')
         return false }
       if ( rd[0].length == 1 ) rd[0] ="0"+rd[0]
       if ( rd[1].length == 1 ) rd[1] ="0"+rd[1]
       if ( rd[2].length == 1 ) rd[2] ="0"+rd[2]
       dot=rd[2].indexOf(".")
       if ( dot < 1 ) rd[2] +=".0"
       document.form1.DEC.value=rd[0]+" "+rd[1]+" "+rd[2]
       document.form1.dec.value=rd[0]+" "+rd[1]+" "+rd[2]
    }
    return true
 }
}
 
function isLetter(c) {
  return ( ((c>="a") && (c<="z")) || ((c>="A") && (c<="Z")) );
}
 
function isDigit(c) {
  return ( (c>="0") && (c<="9") )
}
 
function isLetterOrDigit(c) {
  return (isLetter(c) || isDigit(c))
}
function badchars(userinput) {
  if (!userinput) {alert("No input!"); return false;}
//check for non-allowed characters
  for (var k=0; k< userinput.length; k++) {
    var ch= userinput.charAt(k);
//      alert("checking "+ch+" in "+userinput);
    if (!isLetterOrDigit(ch) && (ch!=".") && (ch!="-") && (ch!="+") && (ch!=" ")&& (ch!=",")
  && (ch!="\*") && (ch!="\)") && (ch!="\(")) {
      alert("Cannot allow character "+ch+" in "+userinput);
      return false;
    }
  }
//  alert("You have entered " + userinput);
  return true;
}
 
function radeconly () {
  obj=document.form1.sourcein.value;
  isaname=obj.indexOf(",")
 if (isaname <= 1) { 
//  alert("This option does not support Object names, Please enter RA,DEC")
  return false;
 } else {return true}
}
function searchform() {
  obj=document.form1.sourcein.value;
  if (!obj) {alert("Please enter source name or RA and Dec");return false}
  if (!badchars(obj))   return false
  if (splitString(obj)) {return true}
  else{return false} 
 
}
function multiCats () {
 if (!searchform()) return
 obj=document.form1.sourcein.value;
 is_a_name=obj.indexOf(",")
 if (is_a_name <= 1) { 
   obj=document.form1.sourcein.value
   var ra  = 0
   var dec = 0
   var decdeg = 0 
 } else { 
   obj= "" 
   var ra  = document.form1.RA.value
   var dec = document.form1.DEC.value
   dd = dec.split(" ")
   var decdeg = dd[0]
 }
 if (document.form1.equinox[0].checked) { eqy = 2000 }
 else { eqy = 1950 }
 multiWindow = open("","multiwindow","border=0,width=500,height=600,scrollbars=yes,menubar=yes,resizable=yes")
 var text = "<html><head><title>Multi Catalogs access window</title>"
 text += '<body bgcolor=#eeffee><center>'
 multiWindow.document.writeln(text)
// text  = "<table border=0 width=450><tr>\n"
 text += '<td align=center>\n'
 text += '<font size=1 face="Helvetica"><font color=darkslategray size=+1>\n'
 text += "Web searches centered on \n"
 if (is_a_name <= 1) {text += "<br>Source named : "+obj}
 else {text += "<br>Ra="+ra+" Dec="+dec+"</td>"} 
 text += "</tr><tr><td valign=top>\n"
 text += "<form method=POST \n"
 text += "ACTION=/cgi-bin/tables_tasks_new target=cats>\n"
 text += "<table border=0><tr><td valign=top>\n"
 text += '<center><font size=4 face="Helvetica">'
 text += "<font color=darkslategray>ASDC Catalogs</center></font>\n"
 text += "<font size=2><select name=task size=8>\n"
 text += "<option>RadioCatalogs\n"
 text += "<option>IRCatalogs\n"
 text += "<option>OPTCatalogs\n"
 text += "<option>UVCatalogs\n"
 text += "<option selected>X-rayCatalogs\n"
 text += "<option>QORGCatalog\n"
 text += "<option>AGNCatalog\n"
 text += "<option>WGACatalog\n"
 text += "<option>2WGACatalog\n"
 text += "<option>ROSATSRCCatalog\n"
 text += "<option>RASSBSCCatalog\n"
 text += "<option>RASSFSCCatalog\n"
 text += "<option>3rdEGRETCatalog\n";
 text += "<option>BMWCatalog\n"
 text += "<option>WFCCATCatalog\n"
 text += "<option>NamesCatalog</select></font>\n"
multiWindow.document.writeln(text)
text  = '<input TYPE=hidden name=RA value=" '+ra+'">\n'
text += '<input TYPE=hidden name=DEC value="'+dec+'">\n'
text += '<input TYPE=hidden name=EQY value="'+eqy+'">\n'
text += '<input TYPE=hidden name="source" value="'+obj+'">\n'
text += '<br></td><td>\n'
text += 'Search radius (arcmin)<br><select name=radius>\n'
text += '<option>0.5<option selected>1<option>2<option>3\n'
text += '<option>5<option>10<option>20<option>30<option>60</select>\n'
text += '<br><input type=submit value=Submit></form><br></table>\n'
text += "<table border=0><tr><td valign=top align=left><form method=POST \n"
text += "ACTION=/cgi-bin/tables_tasks_new target=cats>\n"
text += '<font color=darkgreen size=2 face=Helvetica>'
text += '<input TYPE=hidden name=RA value=" '+ra+'">\n'
text += '<input TYPE=hidden name=DEC value="'+dec+'">\n'
text += '<input TYPE=hidden name=EQY value="'+eqy+'">\n'
text += '<input TYPE=hidden name="source" value="'+obj+'">\n'
text += '</td><td valign=top><font color=darkgreen size=2 face=Helvetica>\n'
text += '<input type=submit name=task value="STSCI MAST">\n'
text += '<input type=submit name=task value=Astrobrowse>\n'
text += '<input type=submit name=task value="USNO">'
text += '<input type=submit name=task value="SDSS">'
text += '<input type=submit name=task value="GSC2">'
text += '<input type=submit name=task value="2MASS">'
text += '<input type=submit name=task value="NED">\n'
text += '<input type=submit name=task value="SIMBAD">\n'
text += '<input type=submit name=task value="INTEGRAL">\n'
text += '<input type=submit name=task value="HEASARC(X-R-G)">\n'
text += '<input type=submit name=task value="VIZIER(X-R-G)">'
text += '</font><br>Search radius<select name=radius>\n'
text += '<option>0.1<option>0.2<option>0.5<option selected>1<option>2<option>3\n'
text += '<option>5<option>10<option>20<option>30</select>arcmin\n'
text += '</form></td></tr></table>\n'
multiWindow.document.writeln(text)
text  ='<font color=darkslategray face="Helvetica" size=1> \n'
text +='<font size=+1><center>Interactive Data Access</center><br>\n'
multiWindow.document.writeln(text)
text = '<center><table border=0 bgcolor=#ccffcc><tr> \n'
text +='<td align=center valign=top>\n'
text +='<font size=+1 color=navy face="Helvetica">Optical/Radio data<p>\n'
multiWindow.document.writeln(text)
text  = '<table border=0><tr><td><form method=POST '
text += 'ACTION=/cgi-bin/public_catalogs target=optic>\n'
text += '<input TYPE=image SRC=/images/eso.gif border=1 alt=Optical-DSS>\n'
text += '<INPUT type="hidden" name="source" value="'+obj+'">\n'
text += '<INPUT type="hidden" name="circleradius" value="20">\n'
text += '<INPUT type="hidden" name="overlay" value="no">\n'
text += '<INPUT type="hidden" name="displayType" value="default">\n'
text += '<INPUT type="hidden" name="ColorTable" value="default">\n'
text += '<INPUT type="hidden" name="mission" value="ESO"> \n'
text += '<input TYPE=hidden name=ra value="'+ra+'">\n'
text += '<input TYPE=hidden name=dec value="'+dec+'">\n'
text += '<input TYPE=hidden name=eqy value="'+eqy+'">\n'
text += '<input TYPE=hidden name=where value="LOCAL">\n'
text += '<input TYPE=hidden name=radius value="3">\n'
text += '<br>Image size<br><select name=radius>\n'
text += '<option>2<option selected>3<option>5<option>8<option>10\n'
text += '<option>13<option>18</select>arcmin\n'
text += '</form></td></tr>'
multiWindow.document.writeln(text)
if ( decdeg <= 2.5 ) {
  text = '<tr><td>'
  text += '<form method=POST ACTION=/cgi-bin/public_catalogs target=optic_c>\n'
  text += '<input TYPE=image SRC=/images/cosmos.gif border=1 alt=Optical-COSMOS>\n'
  text += '<br><input TYPE=radio NAME="waveband" value = "J" checked> J '
  text += '<input TYPE=radio NAME="waveband" value = "R"> R '
  text += '<input TYPE=radio NAME="waveband" value = "I"> I '
  if ( decdeg <= -17.5 ) {
    text += '<input TYPE=radio NAME="waveband" value = "E"> ESO '
  }
  if ( decdeg >= -20.5 ) { 
  text += '<input TYPE=radio NAME="waveband" value = "P"> POSS<br> '
  }
  text += '<INPUT type="hidden" name="source" value="'+obj+'">\n'
  text += '<INPUT type="hidden" name="circleradius" value="15">\n'
  text += '<INPUT type="hidden" name="overlay" value="no">\n'
  text += '<INPUT type="hidden" name="displayType" value="default">\n'
  text += '<INPUT type="hidden" name="ColorTable" value="default">\n'
  text += '<INPUT type="hidden" name="mission" value="COSMOS"> \n'
  text += '<input TYPE=hidden name=ra value="'+ra+'">\n'
  text += '<input TYPE=hidden name=dec value="'+dec+'">\n'
  text += '<input TYPE=hidden name=eqy value="'+eqy+'">\n'
  text += '<input TYPE=hidden name=where value="LOCAL">\n'
  text += '<input TYPE=hidden name=radius value="60">\n'
  text += '</form></td></tr>'
  multiWindow.document.writeln(text)
}
text  = '<tr><td><form method=POST '
text += 'ACTION=/cgi-bin/public_catalogs target=radio>\n'
text += '<p><input TYPE=image SRC=/images/radio.gif border=1 alt=Radio-NVSS>\n'
text += '<INPUT type="hidden" name="source" value="'+obj+'">\n'
text += '<INPUT TYPE="hidden" name="mission" value="NVSS">\n'
text += '<INPUT type="hidden" name="circleradius" value="0">\n'
text += '<INPUT type="hidden" name="overlay" value="no">\n'
text += '<INPUT type="hidden" name="cellradius" value="10">\n'
text += '<br>Image pixel size<br><select name=cellradius>\n'
text += '<option>3<option>5<option>7<option selected>10<option>15<option>20</select>arcsec\n'
text += '<INPUT type="hidden" name="displayType" value="default">\n'
text += '<INPUT type="hidden" name="ColorTable" value="default">\n'
text += '<input TYPE=hidden name=ra value="'+ra+'">\n'
text += '<input TYPE=hidden name=dec value="'+dec+'">\n'
text += '<input TYPE=hidden name=eqy value="'+eqy+'">\n'
text += '<input TYPE=hidden name=where value="LOCAL">\n'
text += '<input TYPE=hidden name=radius value="10">\n'
text += '<br>Image size<br><select name=radius>\n'
text += '<option>2<option>3<option>5<option>7<option>10<option selected>15\n'
text += '<option>20<option>30<option>40<option>60<option>75</select>arcmin\n'
text += '</form></td></tr></table>'
multiWindow.document.writeln(text)


text = '</td><td align=center valign=top><font size=+1 face="Helvetica"\n'
text += 'color=navy>X-ray data from ASDC\n'
text += '</font><table border=0><tr><td>\n'
text += '<form method=POST name=x \n'
text += 'ACTION=/cgi-bin/public_catalogs target=x-ray>\n'
text += '<INPUT TYPE=hidden name=mission value="">\n'
//text += '<table border=0><tr><td>\n'
text += '<a href=javascript:void(0) '
text += 'onMouseDown=document.x.mission.value="BeppoSAX";document.x.submit()>\n'
text += '<img SRC=/images/bepposax.gif border=1 alt=BeppoSAX></a>\n'
text += '</td><td><a href=javascript:void(0) '
text += 'onMouseDown=document.x.mission.value="ROSAT";document.x.submit()>\n'
text += '<img SRC=/images/rosat.gif alt=ROSAT border=1></a>\n'
text += '</td></tr><tr><td><a href=javascript:void(0) '
text += 'onMouseDown=document.x.mission.value="ASCA";document.x.submit()>\n'
text += '<img SRC=/images/asca.gif alt=ASCA border=1></a>\n'
text += '</td><td><a href=javascript:void(0) '
text += 'onMouseDown=document.x.mission.value="EINSTEIN";document.x.submit()>\n'
text += '<img SRC=/images/einstein.gif alt=EINSTEIN border=1></a>\n'
text += '</td></tr><tr><td><a href=javascript:void(0) '
text += 'onMouseDown=document.x.mission.value="EXOSAT";document.x.submit()>\n'
text += '<img SRC=/images/exosat.gif alt=EXOSAT border=1></a>\n'
text += '</td><td><a href=javascript:void(0) '
text += 'onMouseDown=document.x.mission.value="CHANDRA";document.x.submit()>\n'
text += '<img SRC=/images/chandra.gif alt=Chandra border=1></a>\n'
text += '</td></tr><tr><td><a href=javascript:void(0) '
text += 'onMouseDown=document.x.mission.value="XMM";document.x.submit()>\n'
text += '<img SRC=/images/xmm.gif alt=XMM-NEWTON border=1></a>\n'
text += '</td><td><a href=javascript:void(0) '
text += 'onMouseDown=document.x.mission.value="EGRET";document.x.submit()>\n'
text += '<img SRC=/images/egret.jpg alt=Chandra border=1></a>\n'
text += '</tr></table>\n'
text += '<input TYPE=hidden name=ra '
text += 'value="'+ra+'">\n'
text += '<input TYPE=hidden name=dec '
text += 'value="'+dec+'">\n'
text += '<input TYPE=hidden name=eqy value="'+eqy+'">\n'
text += '<input TYPE=hidden name=where value="LOCAL">\n'
text += '<input TYPE=hidden name=source value="'+obj+'">\n'
text += '<input TYPE=hidden name=sort value="RA">\n'
text += '<input TYPE=hidden name=circleradius value="0">\n'
text += '<input TYPE=hidden name=overlay value="no">\n'
text += '<input TYPE=hidden name=displayType value="default">\n'
text += '<input TYPE=hidden name=ColorTable value="default">\n'
text += '<input TYPE=hidden name=radius value="20">\n'
text += '</form></td>'
multiWindow.document.writeln(text)
multiWindow.document.writeln('</table></center>')
 var result = "<td valign=top width=20><table border=0>\n"
 result += '</table></td></tr></table><font color=navy \n'
 result += 'face="Helvetica" size=+1>\n'
 text1 ='<center><form><input type="button" name="closeme" value="Close Window"'
 text1 +='onClick="self.close()" </form></body></html>'
 multiWindow.document.writeln(result)
 multiWindow.document.writeln(text1)
 multiWindow.document.close()
 multiWindow.focus()
}
