// ASTRO - JavaScript Document
// Functions: Print, Search Box, Image Rollover, Image Rotator, DIV Expand/Collapse, IE Square Border Fix



// ^^^^^^^^^^^^^^^^^^^ Start Print ^^^^^^^^^^^^^^^^^^^
var gAutoPrint = true; // Tells whether to automatically call the print function.
function printSpecial()
{
if (document.getElementById != null)
{
var html = '<HTML>\n<HEAD>\n<link rel=stylesheet type=text/css media=screen href=/_design/css/print.css>';

if (document.getElementsByTagName != null)
{
var headTags
//var headTags = document.getElementsByTagName("head");
//if (headTags.length > 0)
//html += headTags[0].innerHTML;
}

html += '\n</HEAD>\n<BODY>\n';

var printReadyElem0 = document.getElementById("header");
var divTag0 = '<span class=section_title>'
var printReadyElem01 = document.getElementById("section_title");
var divTag0X = '</span>'
var divTag2 = '<DIV class=content>'
var printReadyElem1 = document.getElementById("content");
var divTagX = '</DIV>'
var divTag3= '<DIV id=lastUpdated>'
var divTag4= '<DIV id=footer>'
var printReadyElem2 = document.getElementById("lastUpdated")
var printReadyElem3 = document.getElementById("footer");

if (printReadyElem1 != null)
{
//	printReadyElem0.innerHTML + 
html +=  divTag2 + printReadyElem1.innerHTML + divTagX + divTag3 + printReadyElem2.innerHTML + "<br>" + printReadyElem3.innerHTML + divTagX;
//divTag0 + printReadyElem01.innerHTML + divTag0X +

//html += ""
//html += printReadyElem2.innerHTML;
}
else
{
alert("Could not find the printReady function");
return;
}

html += '\n</BO>\n</HT>';

var printWin = window.open("","printSpecial");
printWin.document.open();
printWin.document.write(html);
printWin.document.close();
if (gAutoPrint)
printWin.print();
}
else
{
alert("The print ready feature is only available if you are using an browser. Please update your browswer.");
}
}
// ^^^^^^^^^^^^^^^^^^^ End Print ^^^^^^^^^^^^^^^^^^^



// ^^^^^^^^^^^^^^^^^^^ Start Search Box ^^^^^^^^^^^^^^^^^^^
// Text in the Search Box
function clearDefaultandCSS(el) {
	if (el.defaultValue==el.value) el.value = ""
	// If Dynamic Style is supported, clear the style
	//if (el.style) el.style.cssText = ""
}
// Fearch Box
function postSearch() {
	location.replace("/Search/Default.aspx?txtsearch=" + this.searchfrm.txtSearch.value)
}
// ^^^^^^^^^^^^^^^^^^^ End Search Box ^^^^^^^^^^^^^^^^^^^



// ^^^^^^^^^^^^^^^^^^^ Start Image Rollover ^^^^^^^^^^^^^^^^^^^
function MM_swapImgRestore() { //v3.0
  var i,x,a=document.MM_sr; for(i=0;a&&i<a.length&&(x=a[i])&&x.oSrc;i++) x.src=x.oSrc;
}
function MM_preloadImages() { //v3.0
  var d=document; if(d.images){ if(!d.MM_p) d.MM_p=new Array();
    var i,j=d.MM_p.length,a=MM_preloadImages.arguments; for(i=0; i<a.length; i++)
    if (a[i].indexOf("#")!=0){ d.MM_p[j]=new Image; d.MM_p[j++].src=a[i];}}
}
function MM_findObj(n, d) { //v4.01
  var p,i,x;  if(!d) d=document; if((p=n.indexOf("?"))>0&&parent.frames.length) {
    d=parent.frames[n.substring(p+1)].document; n=n.substring(0,p);}
  if(!(x=d[n])&&d.all) x=d.all[n]; for (i=0;!x&&i<d.forms.length;i++) x=d.forms[i][n];
  for(i=0;!x&&d.layers&&i<d.layers.length;i++) x=MM_findObj(n,d.layers[i].document);
  if(!x && d.getElementById) x=d.getElementById(n); return x;
}
function MM_swapImage() { //v3.0
  var i,j=0,x,a=MM_swapImage.arguments; document.MM_sr=new Array; for(i=0;i<(a.length-2);i+=3)
   if ((x=MM_findObj(a[i]))!=null){document.MM_sr[j++]=x; if(!x.oSrc) x.oSrc=x.src; x.src=a[i+2];}
}
// ^^^^^^^^^^^^^^^^^^^ End Image Rollover ^^^^^^^^^^^^^^^^^^^



// ^^^^^^^^^^^^^^^^^^^ Start Image Rotation ^^^^^^^^^^^^^^^^^^^
// Start Header Images
	function random_imglink_header(){
	var astroimg=new Array()
	astroimg[1]="/_design/images/page_rotator/A.jpg"
	astroimg[2]="/_design/images/page_rotator/A.jpg"
	astroimg[3]="/_design/images/page_rotator/C.jpg"
	astroimg[4]="/_design/images/page_rotator/D.jpg"
	astroimg[5]="/_design/images/page_rotator/E.jpg"
	astroimg[6]="/_design/images/page_rotator/H.jpg"
	astroimg[7]="/_design/images/page_rotator/G.jpg"
	astroimg[8]="/_design/images/page_rotator/H.jpg"
	
	var astrolinks=new Array()
	astrolinks[1]="http://www.astro.org/Patients/"
	astrolinks[2]="http://www.astro.org/Patients/"
	astrolinks[3]="http://www.astro.org/Meetings/UpcomingMeetings/HeadAndNeck/index.asp"
	astrolinks[4]="http://www.astro.org/Patients/"
	astrolinks[5]="http://www.astro.org/Shop/"
	astrolinks[6]="http://astro.org/Meetings/UpcomingMeetings/"
	astrolinks[7]="http://www.astro.org/Patients/"
	astrolinks[8]="http://astro.org/Meetings/UpcomingMeetings/"


var ry=Math.floor(Math.random()*astroimg.length)
	
	if (ry==0)
	ry=1
	document.write('<a href='+'"'+astrolinks[ry]+'"'+'><img src="'+astroimg[ry]+'" border=0 id="section_image">')
	}

	
// End Header Images
// Start Index Images
	function random_imglink_index(){
	var astroimg2=new Array()
	astroimg2[1]="/_design/images/index_rotator/A.jpg"
	astroimg2[2]="/_design/images/index_rotator/A.jpg"
	astroimg2[3]="/_design/images/index_rotator/C.jpg"
	astroimg2[4]="/_design/images/index_rotator/D.jpg"
	astroimg2[5]="/_design/images/index_rotator/E.jpg"
	astroimg2[6]="/_design/images/index_rotator/H.jpg"
	astroimg2[7]="/_design/images/index_rotator/G.jpg"
	astroimg2[8]="/_design/images/index_rotator/H.jpg"
	
	var astrolinks2=new Array()
	astrolinks2[1]="http://www.astro.org/Patients/"
	astrolinks2[2]="http://www.astro.org/Patients/"
	astrolinks2[3]="http://www.astro.org/Meetings/UpcomingMeetings/HeadAndNeck/index.asp"
	astrolinks2[4]="http://www.astro.org/Patients/"
	astrolinks2[5]="http://www.astro.org/Shop/"
	astrolinks2[6]="http://astro.org/Meetings/UpcomingMeetings/"
	astrolinks2[7]="http://www.astro.org/Patients/"
	astrolinks2[8]="http://astro.org/Meetings/UpcomingMeetings/"


var ry=Math.floor(Math.random()*astroimg2.length)
	
	if (ry==0)
	ry=1
	document.write('<a href='+'"'+astrolinks2[ry]+'"'+'><img src="'+astroimg2[ry]+'" border=0>')
	}
// End Index Images
// ^^^^^^^^^^^^^^^^^^^ End Image Rotation ^^^^^^^^^^^^^^^^^^^



// ^^^^^^^^^^^^^^^^^^^ Start DIV Expand/Collapse ^^^^^^^^^^^^^^^^^^^
function expandcollapse (postid) {
   whichpost = document.getElementById(postid);
   if (whichpost.className=="shown") { 
      whichpost.className="hidden";
   }
   else {
      whichpost.className="shown";
   }
}
// ^^^^^^^^^^^^^^^^^^^ End DIV Expand/Collapse ^^^^^^^^^^^^^^^^^^^



// ^^^^^^^^^^^^^^^^^^^ Start IE Square Border Fix ^^^^^^^^^^^^^^^^^^^
function removeCheckBoxBorders()
{
var el = document.getElementsByTagName("input");
for (i=0;i<el.length;i++)
  {
  var type = el[i].getAttribute("type");
  if((type=="checkbox")||(type=="radio"))
    {
   el[i].style.border = "none";
    }
  }
}

// Checkboxes in IE Forms
function addEvent(elm, evType, fn, useCapture)
{
if(elm.addEventListener)
  {
  elm.addEventListener(evType, fn, useCapture);
  return true;
  }
else if (elm.attachEvent)
  {
  var r = elm.attachEvent('on' + evType, fn);
  return r;
  }
else
  {
  elm['on' + evType] = fn;
  }
}
// ^^^^^^^^^^^^^^^^^^^ End IE Square Border Fix ^^^^^^^^^^^^^^^^^^^



// ^^^^^^^^^^^^^^^^^^^ Start Email form validation ^^^^^^^^^^^^^^^^^^^
function isEmailAddr(fromEmail)
{
  var result = false
  var theStr = new String(fromEmail)
  var index = theStr.indexOf("@");
  if (index > 0)
  {
    var pindex = theStr.indexOf(".",index);
    if ((pindex > index+1) && (theStr.length > pindex+1))
	result = true;
  }
  return result;
}
function Validate(theForm)
{

  if (theForm.SenderName.value == "")
  {
    alert("Please enter your name");
    theForm.SenderName.focus();
    return (false);
  }
  if (theForm.SenderEmail.value == "")
  {
    alert("Please enter your email address");
    theForm.SenderEmail.focus();
    return (false);
  }

  if (!isEmailAddr(theForm.SenderEmail.value))
  {
    alert("Please enter a valid email address of the form: yourname@yourdomain.com");
    theForm.SenderEmail.focus();
    return (false);
  }
   
  if (theForm.SenderEmail.value.length < 3)
  {
    alert("Please enter at least 3 characters in the \"email\" field.");
    theForm.SenderEmail.focus();
    return (false);
  }

  if (theForm.SenderEmail.value.length < 3)
  {
    alert("Please enter at least 3 characters in the \"email\" field.");
    theForm.SenderEmail.focus();
    return (false);
  }

	return (true);
}
// ^^^^^^^^^^^^^^^^^^^ End Email form validation ^^^^^^^^^^^^^^^^^^^