﻿
var tbl = "";
//var lastYear = "";
//Months
var m_names = new Array("January", "February", "March", "April", "May", "June", "July", "August", "September", "October", "November", "December");
var d_names = new Array("Sunday", "Monday", "Tuesday", "Wednesday", "Thursday", "Friday", "Saturday", "Sunday");

function buildTours(x) {
    
    
    var gTours = new Array();
    
    //if (x == 'A') gTours = gActs;
    if (x == 'T') gTours = gTours2;

    var tempdate = ""; 
    var today = new Date(); 
    var past = true;

    //Past
    tbl = "<table id='past'><tr><td align='center'>";
    //if (x == 'A') tbl += "<h2>Past Events</h2></td></tr>";
    if (x == 'T') tbl += "<h2>Past</h2></td></tr>";
    for (i = 0; i < gTours.length; i++) {
        var tourParts = new Array();
        tourParts = gTours[i].split('||');
        tempdate = new Date(tourParts[0]);

        //compare to today
        if (tempdate.getTime() < (today.getTime() - 86400000)) {
            buildRow(tourParts, tbl);
        }
    }
    tbl += "</table>";
    document.getElementById('divToursPast').innerHTML = tbl;
    
    
    //Upcoming
    tbl = "";
    gTours.reverse();
    tbl = "<table id='up' width=100%><tr><td align='center'>";
    //if (x == 'A') tbl += "<h2>Upcoming Events</h2></td></tr>";
    if (x == 'T') tbl += "<h2>Upcoming</h2></td></tr>";

    var nothingFound = true; 
    
    for (i = 0; i < gTours.length; i++) {
        var tourParts = new Array();
        tourParts = gTours[i].split('||');
        tempdate = new Date(tourParts[0]);

        //compare to today
        if (tempdate.getTime() > (today.getTime() - 86400000)) {
            buildRow(tourParts, tbl);
            nothingFound = false;
        }
    }
    if(nothingFound)
    {
        tbl += "<tr><td><strong>Tours and Activities Coming Soon!</strong></td></tr>";
    }
    tbl += "</table>";
    document.getElementById('divToursUp').innerHTML = tbl;
	
    		
	var strHref = window.location.href;
    if ( strHref.indexOf("#") > -1 ) window.location = window.location;
}

function openSlideShow(p, f, n, t) {
    var pars = "?f=" + f +"&n=" + n +"&t=" + t +"&p=" + p;
    var w = window.open("../nwmo/slideshow.htm" + pars, "slideShow", "status=0,toolbar=0,resizable=1")
    w.focus();
}

function setClass(o, x) {
    if(x){
        o.setAttribute("className", "headOn"); //IE
        o.setAttribute("class", "headOn");
    } else {
        o.setAttribute("className", "headOff"); //IE
        o.setAttribute("class", "headOff");
    }
}

function buildRow(p, t) {
    tempdate = new Date(p[0]);
  
//    //Display Year 
//    if (tempdate.getFullYear() != lastYear) {
//        lastYear = tempdate.getFullYear();
//        if (lastYear != new Date().getFullYear()) {
//            tbl += "<tr><td>&nbsp;</td></tr>";
//            tbl += "<h3>" + lastYear + "</h3></td></tr>";
//        }
//    }
    //event anchor
    tbl += "<tr><td><a name='" + p[4] + "'>&nbsp;</a></td></tr>";
    if (p[2] > 0) {

        //newer  
        tbl += "<tr><td>";

        var xx = "<span class='headOff' ";
        xx += "  title='Click to see the pictures' ";
        xx += " onmouseover='javascript:setClass(this, 1); ' ";
        xx += " onmouseout='javascript:setClass(this, 0); ' ";
        xx += " onclick='javascript: openSlideShow(0, \"" + p[4] + "\", " + p[2] + " ,\"" + p[5] + "\")' >" + p[5] + "";
        xx += "&nbsp;&nbsp;&nbsp;&nbsp;<span  style='font-size:11px; cursor:pointer' >" + p[2] + " pictures</span></span>";
        tbl += xx;
        tbl +="</td></tr>";

    } else {
        tbl += "<tr><td><strong>" + p[5] + "</strong></td></tr>";
    }
    //date
    var theDate = "";
    if (p[1] > 0) {

        var myDate = new Date();
        myDate.setDate(tempdate.getDate() + Number(p[1]));
        theDate = tempdate.getDate() + " - " + myDate.getDate();
    } else {
        theDate = tempdate.getDate();
    }
    tbl += "<tr><td>" + d_names[tempdate.getDay()] + ", " + m_names[tempdate.getMonth()] + " " + theDate + ", " + tempdate.getFullYear() + " </td></tr>";
    //description
    tbl += "<tr><td class='tourDesc'>" + p[6] + "</td></tr>";
}    


