var dToday = null;
var thisYear = 2008;
var thisMonth = 1;

var httpDesignSingaporeCouncil;
var httpIESingapore;
var httpSpringSingapore;
var httpSingleEvent;

function initPage() {
  dToday = new Date();
  thisYear = dToday.getFullYear();
  thisMonth = dToday.getMonth() + 1; //getMonth start with 0
  
  //document.getElementById("divSelYear").innerHTML = thisYear;
  
  showDesignIntroLoading();
  showDesignTouchLoading();
  showDesignExcelLoading();
  //getDesignSingaporeCouncilLoading();
  //getIESingaporeLoading();
  //getSpringSingapore();
  
  
}

//EVENT CALENDAR INTERACTIVES
/*
function selPrevYear() {
  thisYear -= 1;
  document.getElementById("divSelYear").innerHTML = thisYear;
}
function selNextYear() {
  thisYear += 1;
  document.getElementById("divSelYear").innerHTML = thisYear;
}

function showMonthSelector() {
  document.getElementById("divMonthSelector").style.visibility = "visible";
  document.getElementById("monthSel").style.backgroundPosition = "left bottom";
  
}
function hideMonthSelector() {
  document.getElementById("divMonthSelector").style.visibility = "hidden";
  document.getElementById("monthSel").style.backgroundPosition = "left top";
}

function selMonth(m) {
  thisMonth = parseInt(m, 10);
  drawCalendar();
}

function drawCalendar() {
  //get first day of the month
  var dMonth = new Date();
  dMonth.setFullYear(thisYear);
  dMonth.setMonth(thisMonth-1);
  dMonth.setDate(1);
  document.getElementById("monthSel").innerHTML = getMonthLongName(thisMonth) + " " + thisYear;

  var buff = "";
  buff = "<table cellspacing='0'>" +
         "<tr><td>Sun</td><td>Mon</td><td>Tue</td><td>Wed</td><td>Thu</td><td>Fri</td><td>Sat</td></tr>";
         
  var d = dMonth.getDay();
  var totalDays = getMonthDays(thisYear, thisMonth);
  alert(d + ", " + totalDays);
         
  buff += "</table>";
  
  document.getElementById("divCalendar").innerHTML = buff;
}
*/

//EVENT TABS INETERACTIVES 
function showDesignIntro() {
  
  document.getElementById("divDesignIntro").style.display = "";
  document.getElementById("divDesignTouch").style.display = "none";
  document.getElementById("divDesignExcel").style.display = "none";
  document.getElementById("aDesignIntro").className = "secTabSel_ast";
  document.getElementById("aDesignTouch").className = "secTab_ast";
  document.getElementById("aDesignExcel").className = "secTab_ast";
  
  document.getElementById("divDesignEngage").style.display = "none";
  document.getElementById("aDesignEngage").className = "secTab_ast";
}

function showDesignTouch() {
  document.getElementById("divDesignIntro").style.display = "none";
  document.getElementById("divDesignTouch").style.display = "";
  document.getElementById("divDesignExcel").style.display = "none";
  document.getElementById("aDesignIntro").className = "secTab_ast";
  document.getElementById("aDesignTouch").className = "secTabSel_ast";
  document.getElementById("aDesignExcel").className = "secTab_ast";
  
  document.getElementById("divDesignEngage").style.display = "none";
  document.getElementById("aDesignEngage").className = "secTab_ast";
}

function showDesignExcel() {
  document.getElementById("divDesignIntro").style.display = "none";
  document.getElementById("divDesignTouch").style.display = "none";
  document.getElementById("divDesignExcel").style.display = "";
  document.getElementById("aDesignIntro").className = "secTab_ast";
  document.getElementById("aDesignTouch").className = "secTab_ast";
  document.getElementById("aDesignExcel").className = "secTabSel_ast";
  
  document.getElementById("divDesignEngage").style.display = "none";
  document.getElementById("aDesignEngage").className = "secTab_ast";
  
}

function showDesignEngage(){
  document.getElementById("divDesignIntro").style.display = "none";
  document.getElementById("divDesignTouch").style.display = "none";
  document.getElementById("divDesignExcel").style.display = "none";
  document.getElementById("divDesignEngage").style.display = "";
  
  document.getElementById("aDesignIntro").className = "secTab_ast";
  document.getElementById("aDesignTouch").className = "secTab_ast";
  document.getElementById("aDesignExcel").className = "secTab_ast";  
  document.getElementById("aDesignEngage").className = "secTabSel_ast"; 
}

function showDesignEngageMore(){
  document.getElementById("divDesignEngageMore").style.display = "";  
  document.getElementById("aDesignEngageMore").style.display = "none";  
  
}


function showDesignIntroLoading() {
  document.getElementById("divDesignIntro").innerHTML = getLoadingBar();
}

function showDesignTouchLoading() {
  document.getElementById("divDesignTouch").innerHTML = getLoadingBar();
}

function showDesignExcelLoading() {
  document.getElementById("divDesignExcel").innerHTML = getLoadingBar();
}

//AJAX FOR EVENT TABS
function getDesignSingaporeCouncil() {
  if (httpDesignSingaporeCouncil == null) {
    httpDesignSingaporeCouncil = GetXmlHttpObject();
  }
  
  if (httpDesignSingaporeCouncil != null)  {
    if (httpDesignSingaporeCouncil.readyState == 4 || httpDesignSingaporeCouncil.readyState == 0) {
      var url="process.aspx?type=DESIGN_SG_COUNCIL&page=1";
      httpDesignSingaporeCouncil.onreadystatechange=drawDesignSingaporeCouncil;
      httpDesignSingaporeCouncil.open("GET",url,true);
      httpDesignSingaporeCouncil.setRequestHeader('Content-Type','application/x-www-form-urlencoded');
      httpDesignSingaporeCouncil.send(null);
    }
  }
  else  {
    alert ("Your browser does not support AJAX!");
  }
}

function drawDesignSingaporeCouncil() {

  if (httpDesignSingaporeCouncil != null)  {
    if (httpDesignSingaporeCouncil.readyState==4 && httpFDesignSingaporeCouncil.status == 200)  {
      var xmlDoc = httpDesignSingaporeCouncil.responseXML.documentElement; 
      var buff = "";
      for (n=0; n<xmlDoc.childNodes.length; n++) {
        if (xmlDoc.childNodes[n].nodeName == "assistance") {
          var assistanceNode = xmlDoc.childNodes[n];
          var strassistance = "";
          
          structAssistance = nodeFieldsToArray(assistanceNode);
          
          buff += 
            "<div class='divEIcon'><img src='" + structAssistance["icon"] + "' alt='' /></div>" +
            "<div class='divEDetail'>" +
              "<div><a class='listLink' href='javascript:getSingleEvent(" + structAssistance["id"] + ")'>" + structAssistance["title"] + "</a></div>" +
              "<div class='smaller'>" + structAssistance["description"] + "</div>" +
            "</div>" +
            "<div class='divEDate smaller'>" + structAssistance["start_date"] + "</div>" + 
            "<div class='sepHor' style='clear:both'></div>";
        }
      }
      
      document.getElementById("divDesignIntro").innerHTML = buff;
    }
  }
}


function getIESingapore() {
  //document.getElementById("divDesignTouch").innerHTML = "testing";
        alert("ahha");
  if (httpIESingapore == null) {
    httpIESingapore = GetXmlHttpObject();
  }
  
  if (httpIESingapore != null)  {
    if (httpIESingapore.readyState == 4 || httpIESingapore.readyState == 0) {
      var url="process.aspx?type=IE_SG&page=1";
      httpIESingapore.onreadystatechange=drawIESingapore;
      httpIESingapore.open("GET",url,true);
      httpIESingapore.setRequestHeader('Content-Type','application/x-www-form-urlencoded');
      httpIESingapore.send(null);
    }
  }
  else  {
    alert ("Your browser does not support AJAX!");
  }
  
}

function drawIESingapore() {
  if (httpIESingapore != null)  {
    if (httpIESingapore.readyState==4 && httpIESingapore.status == 200)  {
      var xmlDoc = httpIESingapore.responseXML.documentElement; 
      var buff = "";
      for (n=0; n<xmlDoc.childNodes.length; n++) {
        if (xmlDoc.childNodes[n].nodeName == "assistance") {
          
          var assistanceNode = xmlDoc.childNodes[n];
          var strAssistance = "";
          
          strAssistance = nodeFieldsToArray(assistanceNode);
          
          buff += 
            "<div class='divEIcon'><img src='../images/image3-testing.jpg' alt='' /></div>" +
            "<div class='divEDetail'>" +
              "<div><a class='listLink' href='javascript:getSingleEvent(" + strAssistance["id"] + ")'>" + strAssistance["title"] + "</a></div>" +
              "<div class='smaller'>" + strAssistance["description"] + "</div>" +
            "</div>" +
            "<div class='divEDate smaller'>" + strAssistance["start_date"] + "</div>" + 
            "<div class='sepHor' style='clear:both'></div>";
        }
      }

      document.getElementById("divDesignTouch").innerHTML = "<div>ssss</div>";
    }
  }
}


function getSpringSingapore() {
  if (httpSpringSingapore == null) {
    httpSpringSingapore = GetXmlHttpObject();
  }
  
  if (httpSpringSingapore != null)  {
    if (httpSpringSingapore.readyState == 4 || httpSpringSingapore.readyState == 0) {
      var url="process.aspx?type=SPRING_SG&page=1";
      httpSpringSingapore.onreadystatechange=drawSpringSingapore;
      httpSpringSingapore.open("GET",url,true);
      httpSpringSingapore.setRequestHeader('Content-Type','application/x-www-form-urlencoded');
      httpSpringSingapore.send(null);
    }
  }
  else  {
    alert ("Your browser does not support AJAX!");
  }
}

function drawSpringSingapore() {
  if (httpSpringSingapore != null)  {
    if (httpSpringSingapore.readyState==4 && httpSpringSingapore.status == 200)  {
      var xmlDoc = httpSpringSingapore.responseXML.documentElement; 
      var buff = "";
      for (n=0; n<xmlDoc.childNodes.length; n++) {
        if (xmlDoc.childNodes[n].nodeName == "assistance") {
          var assistanceNode = xmlDoc.childNodes[n];
          var strAssistance = "";
          
          structAssistance = nodeFieldsToArray(assistanceNode);
          
          buff += 
            "<div class='divEIcon'><img src='" + structAssistance["icon"] + "' alt='' /></div>" +
            "<div class='divEDetail'>" +
              "<div><a class='listLink' href='javascript:getSingleEvent(" + structAssistance["id"] + ")'>" + structAssistance["title"] + "</a></div>" +
              "<div class='smaller'>" + structAssistance["description"] + "</div>" +
            "</div>" +
            "<div class='divEDate smaller'>" + structAssistance["start_date"] + "</div>" + 
            "<div class='sepHor' style='clear:both'></div>";
        }
      }
      
      document.getElementById("divDesignExcel").innerHTML = buff;
    }
  }
}


function getSingleEvent(eid) {
  if (httpSingleEvent == null) {
    httpSingleEvent = GetXmlHttpObject();
  }
  
  if (httpSingleEvent != null)  {
    if (httpSingleEvent.readyState == 4 || httpSingleEvent.readyState == 0) {
      var url="process.aspx?type=GET_EVENT&Event_id=" + eid;
      httpSingleEvent.onreadystatechange=drawSingleEvent;
      httpSingleEvent.open("GET",url,true);
      httpSingleEvent.setRequestHeader('Content-Type','application/x-www-form-urlencoded');
      httpSingleEvent.send(null);
    }
  }
  else  {
    alert ("Your browser does not support AJAX!");
  }
}

function drawSingleEvent() {
  if (httpSingleEvent != null)  {
    if (httpSingleEvent.readyState==4 && httpSingleEvent.status == 200)  {
      var xmlDoc = httpSingleEvent.responseXML.documentElement; 
      var buff = "";
      for (n=0; n<xmlDoc.childNodes.length; n++) {
        if (xmlDoc.childNodes[n].nodeName == "event") {
          var eventNode = xmlDoc.childNodes[n];
          var strEvent = "";
          
          structEvent = nodeFieldsToArray(eventNode);
          
          buff += 
            "<div>" + structEvent["title"] + "</div>" +
            "<div>" + structEvent["filename"] + "</div>" +
            "<div>" + structEvent["description"] + "</div>";
            
        }
      }
      
      document.getElementById("divEventDetail").innerHTML = buff;
    }
  }
}