/*
ROLL OVER FUNCTIONS #############################
*/
function swapRestore() { //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 preloadImages() {
    var d=document;
    if(d.images){
        if(!d.MM_p) {
            d.MM_p=new Array();
        }
        var i, j=d.MM_p.length, a=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='../images/'+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 swapImage() { //v3.0
  var i,j=0,x,a=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='../images/'+a[i+2];
      //alert('swapping: '+a[i+2]);
    }
  }
}

function setSubMenuActive( curPage ) {
    var subM = document.getElementById("submenu_cell");
    var i, href, url;
    url = curPage.split("/");
    curPage = url.pop();
    for (i=0; i < subM.childNodes.length; i++ ) {
        try {
            href = subM.childNodes[i].getAttribute("href");
            url = href.split("/");
            href = url.pop();
            //alert(href + " :  " + curPage);
            if ( href == curPage ) {
                //alert(subM.childNodes[i].className);
                subM.childNodes[i].style.color = "#66ccff";
            }
        } catch (e) {}
    }
}

var curPageID="none";

function setSubNav(id) {  //set ro effect for current page
  curPageID = id;
  var thisDiv = document.getElementById(id);
  thisDiv.style.backgroundColor = "#000033";
}

function subnavHover( thisDiv ) {
  //alert(thisDiv.style.backgroundColor);
  thisDiv.style.backgroundImage = "url('../images/back_leftpanel_mid.jpg')";
}

function subnavMO( thisDiv ) {
  if (thisDiv.getAttribute("id") != curPageID ) {
    thisDiv.style.backgroundImage = "none";
  } else {
    thisDiv.style.backgroundImage = "none";
    thisDiv.style.backgroundColor = "#000033";
  }
}

/*
 SLIDE SHOW  FUNCTIONS  ###########################
*/
//LIST SPONSOR LOGO IMAGES HERE FOR SPONSOR SLIDE SHOW
var imgs = new Array(new Array('logo_pshift.gif','http://pshift.com'),
                     new Array('logo_xpress.jpg','http://www.thexpressink.com'),
                     new Array('logo_fixpc.jpg','http://www.fixpc.com/'),
                     new Array('logo_bauman.jpg','http://www.drrobertbauman.com/'),
                     new Array('logo_fixpc.jpg','http://fixpc.com'),
                    new Array('logo_xpress.jpg','http://www.thexpressink.com'),
                    new Array('logo_pshift.gif','http://www.pshift.com/'),
                    new Array('logo_bauman.jpg','http://www.drrobertbauman.com/')
                    );

var loimages = new Array();
var whichimage = Math.floor(Math.random() * imgs.length);
var whichimage = 0;
//takes string of images and puts them into array
function loadImages( loi ) {
    for (i=0;i<imgs.length;i++){  //loimages is global
        loimages[i]=new Image();
        loimages[i].src="../images/" +imgs[i][0];
    }
}

function runSlides(){
    if (!document.images) {
        return;
    }
    var img = document.getElementById("slideshow");
    var sl = document.getElementById("sponsor_link");
    try {
      img.src=loimages[whichimage].src;
      sl.setAttribute("href",imgs[whichimage][1]);
      sl.setAttribute("onclick","window.open('"+imgs[whichimage][1]+"', 'order_window', 'toolbar,menu,scrollbars,width=596,height=485,status=yes,left='+((window.screen.width - 596)/2)+',top='+((window.screen.height - 485) /2.5)).focus();return false;");
    } catch (e) {  //if index is out of range
      img.src=loimages[0].src;
    }

    //if (whichimage<loimages.length-1) { whichimage++;} else {whichimage=0;}

    //random index
    whichimage=Math.floor(Math.random() * loimages.length);

    setTimeout("runSlides()",4000);
}


/*
 CALCULATE TOTAL FUNCTIONS
*/

function calcTotal() {
  var ttl = 0;
  ttl = 65 * document.forms[0].tix_quantity.value;
  //alert(document.forms[0].family_sponsor[0].checked); //debug
  if (document.forms[0].family_sponsor[0].checked) {ttl += 550;}
  if (document.forms[0].family_sponsor[1].checked) {ttl += 275;}
  if (document.forms[0].family_sponsor[2].checked) {ttl += 115;}

  document.forms[0].totaldue.value = '$'+ ttl;
}

function printableForm() {
  var q = 'firstname='+ encodeURIComponent(document.forms[0].firstname.value);
  q += '&lastname='+ encodeURIComponent(document.forms[0].lastname.value);
  q += '&email='+ encodeURIComponent(document.forms[0].email.value);
  q += '&address='+ encodeURIComponent(document.forms[0].address.value);
  q += '&city='+ encodeURIComponent(document.forms[0].city.value);
  q += '&state='+ encodeURIComponent(document.forms[0].state.value);
  q += '&zip5='+ encodeURIComponent(document.forms[0].zip5.value);
  q += '&phone='+ encodeURIComponent(document.forms[0].phone.value);
  q += '&tix_quantity='+encodeURIComponent(document.forms[0].tix_quantity.value);
  q += '&seating_preference='+encodeURIComponent(document.forms[0].seating_preference.value);
  q += '&comments='+encodeURIComponent(document.forms[0].comments.value);
  if (document.forms[0].family_sponsor[0].checked) {q += '&sponsor=director'}
  else if (document.forms[0].family_sponsor[1].checked) {q += '&sponsor=producer'}
  else if (document.forms[0].family_sponsor[2].checked) {q += '&sponsor=stagemanager'}
  else {q += '&sponsor=none'}
  window.open('printable_tickets.php?'+q, 'order_window', 'menubar,scrollbars,width=596,height=485,status=yes,left='+((window.screen.width - 596)/2)+',top='+((window.screen.height - 485) /2.5)).focus();
}