﻿


function ENQUIRY_DisplayDiagram(e,id)
{
  var a=document.getElementById(id+"DiagramControl");
  a.style.display="none";  
  a.style.left=(e.pageX || (e.clientX + (document.documentElement.scrollLeft || document.body.scrollLeft)) - 5);
  a.style.top=(e.pageY || (e.clientY + (document.documentElement.scrollTop || document.body.scrollTop)) - 5);
  a.style.display="block";
}


function ENQUIRY_HideDiagram(e,id)
{
  var a=document.getElementById(id+"DiagramControl");
  a.style.display="none";
}


function ENQUIRY_ShowBookingDetails(e,id)
{
  var a=document.getElementById(id+"EnquiryRow");
  a.style.display="none";
  var b=document.getElementById(id+"BookingDetailsPanel");
  b.style.display="block";
  var c=document.getElementById(id+"IndividualsSection");
  c.style.display="block";
  var d=document.getElementById(id+"IndividualsPanel");
  d.style.display="none";
  var e=document.getElementById(id+"SubmitButton");
  e.innerHTML="Submit Booking Request";
  var f=document.getElementById(id+"BookingSubmitTextRow");
  f.style.display="block"
}


function ENQUIRY_HideBookingDetails(e,id)
{
  var a=document.getElementById(id+"EnquiryRow");
  a.style.display="block";
  var b=document.getElementById(id+"BookingDetailsPanel");
  b.style.display="none";
  var c=document.getElementById(id+"IndividualsSection");
  c.style.display="none";
  var d=document.getElementById(id+"SubmitButton");
  d.innerHTML="Submit";
  var e=document.getElementById(id+"BookingSubmitTextRow");
  e.style.display="none"
}


function ENQUIRY_ShowKiltDetails(e,id)
{
  var c=document.getElementById(id+"KiltPanel");
  c.style.display="block";
  var c=document.getElementById(id+"TrewsPanel");
  c.style.display="none";
}


function ENQUIRY_ShowTrewsDetails(e,id)
{
  var c=document.getElementById(id+"TrewsPanel");
  c.style.display="block";
  var c=document.getElementById(id+"KiltPanel");
  c.style.display="none";
}


function ENQUIRY_ShowIndividualDetails(e,id)
{
  var c=document.getElementById(id+"IndividualDetails");
  c.style.display="block";
}


function ENQUIRY_DisplayCalendar(e,id,dateTextBox,dateFormat,direction){
  var c=document.getElementById(id+"calendarControl");
  document.body.appendChild(c);  
  c.style.left=(e.pageX || (e.clientX + (document.documentElement.scrollLeft || document.body.scrollLeft)) - 5);
  c.style.top=(e.pageY || (e.clientY + (document.documentElement.scrollTop || document.body.scrollTop)) - 5);
  c.style.display="block";
  var cb=document.getElementById("CalendarBackdrop");
  cb.style.left=(e.pageX || (e.clientX + (document.documentElement.scrollLeft || document.body.scrollLeft)) - 5);
  cb.style.top=(e.pageY || (e.clientY + (document.documentElement.scrollTop || document.body.scrollTop)) - 5);
  
  var browserName=navigator.appName;
  var browserVer=parseInt(navigator.appVersion); 
  
  switch(browserName)
  {
    case "Microsoft Internet Explorer":
      cb.style.width = c.offsetWidth;
      cb.style.height = 145;
    break;
    default:
      cb.style.width = c.offsetWidth - 5;
      cb.style.height = 140;
    break
  }
  
  cb.style.display="block";  
  
  var dateValue=ENQUIRY_GetDateTextBoxValue(dateTextBox);   
   
  ENQUIRY_SetDate(id,dateValue,dateTextBox,dateFormat,direction);
  document.getElementById(id+"closeCalendar").onclick=function ENQUIRY_Close(){document.getElementById(id+'calendarControl').style.display='none';document.getElementById('CalendarBackdrop').style.display='none';};
}


function ENQUIRY_SetDate(id,dateValue,dateTextBox,dateFormat,direction){

  var separator=dateFormat=="dd/MM/yyyy"?"/":" ";
  var d;  
  if(dateValue==""){
    d=new Date()    
    var months=dateFormat=="dd/MM/yyyy"?new Array("01","02","03","04","05","06","07","08","09","10","11","12"):new Array("Jan","Feb","Mar","Apr","May","Jun","Jul","Aug","Sep","Oct","Nov","Dec");
    dateValue=(d.getDate().toString().length==1?"0"+d.getDate():d.getDate())+separator+months[d.getMonth()]+separator+d.getFullYear();    
  }    
  var dateParts=dateValue.split(separator);  
  var monthDd=document.getElementById(id+"calendarMonth");
  var i=0;
  while(i<monthDd.options.length){
    if((dateFormat=="dd/MM/yyyy"&&monthDd.options[i].value==dateParts[1])||(dateFormat!="dd/MM/yyyy"&&monthDd.options[i].text==dateParts[1])){
      monthDd.options[i].selected=true;
      i=monthDd.options.length;
    }
    else{
      i++;
    }
  }  
  monthDd.onchange=function ENQUIRY_NewMonth(){ENQUIRY_SetDate(id,dateParts[0]+separator+(dateFormat=="dd/MM/yyyy"?monthDd.value:monthDd.options[monthDd.selectedIndex].text)+separator+dateParts[2],dateTextBox,dateFormat,direction);}
  var yearDd=document.getElementById(id+"calendarYear");
  i=0;
  while(i<yearDd.options.length){
    if(yearDd.options[i].text==dateParts[2]){
      yearDd.selectedIndex=i;
      i=yearDd.options.length;
    }
    else{
      i++;
    }
  }  
  dateParts[2]=yearDd.value;
  yearDd.onchange=function ENQUIRY_NewYear(){ENQUIRY_SetDate(id,dateParts[0]+separator+dateParts[1]+separator+yearDd.value,dateTextBox,dateFormat,direction);}
  var tbody=document.getElementById(id+"dateRange");
  for(i=tbody.childNodes.length-1;i>=0;i--){
    tbody.removeChild(tbody.childNodes[i]);
  }
  d=new Date(dateParts[2], monthDd.selectedIndex, 1);
  d=new Date(d-86400000*d.getDay());  
  while((d.getMonth()<=monthDd.selectedIndex&&d.getFullYear()==dateParts[2])||(d.getMonth()==11&&monthDd.selectedIndex==0)){
    var row=document.createElement("tr");
    for(i=0;i<7;i++){
      var cell=document.createElement("td");      
      if(d.getDate()==dateParts[0]&&d.getMonth()==monthDd.selectedIndex){
        cell.className="currentDay";
      }
      else{
        if(d.getDay()==0||d.getDay()==6){
          cell.className="weekEnd";
        }
        else{
          cell.className="weekDay";
        }          
      }        
      if(d.getMonth()==monthDd.selectedIndex){
      
        cell.innerHTML="<span onclick=\"ENQUIRY_SetDateTextBoxValue('"+dateTextBox+"','"+(d.getDate().toString().length<2?"0"+d.getDate().toString():d.getDate().toString())+separator+dateParts[1]+separator+dateParts[2]+"',"+direction+");document.getElementById('"+id+"calendarControl').style.display='none';document.getElementById('CalendarBackdrop').style.display='none';\" >"+d.getDate()+"</span>"; 
      }
      row.appendChild(cell);
      var currDay=d.getDay();            
      while(d.getDay()==currDay){
        d=new Date(d-0+86400000);
      }
    }
    tbody.appendChild(row);
  }  
}




function ENQUIRY_SetDateTextBoxValue(dateTextBox,value,reverse){  
  document.getElementById(dateTextBox).value=value;
}


function ENQUIRY_GetDateTextBoxValue(dateTextBox){
  return(document.getElementById(dateTextBox).value); 
}


function ENQUIRY_MonthToNumber(value){
  var num;
  switch(value.substr(3,3)){
    case "Jan":
      num="01";
      break;
    case "Feb":
      num="02";
      break;
    case "Mar":
      num="03";
      break;
    case "Apr":
      num="04";
      break;
    case "May":
      num="05";
      break;
    case "Jun":
      num="06";
      break;
    case "Jul":
      num="07";
      break;
    case "Aug":
      num="08";
      break;
    case "Sep":
      num="09";
      break;
    case "Oct":
      num="10";
      break;
    case "Nov":
      num="11";
      break;
    case "Dec":
      num="12";
      break;
  }
  return(num);
}



function ENQUIRY_TopOfPage(){
  //alert("done");
  document.scrollTo(0, 0);
  //window.location.reload();
  //window.scrollTo(0, 0)
  return(false);
}



