var ie=false;
var ns=false;
var isNav6=false;
if(document.layers)ns = true;
if(window.sidebar)isNav6 = true;
if(document.all)ie = true;


// date function
function writeDate()
{
  var now = new Date();
  var date = now.getDate();
  var year = now.getFullYear();

  var monthNumber = now.getMonth();
  var month = "";
  switch (monthNumber)
  {
    case 0:
      month = "Jan";
      break;
    case 1:
      month = "Feb";
      break;
    case 2:
      month = "Mar";
      break;
    case 3:
      month = "Apr";
      break;
    case 4:
      month = "May";
      break;
    case 5:
      month = "Jun";
      break;
    case 6:
      month = "Jul";
      break;
    case 7:
      month = "Aug";
      break;
    case 8:
      month = "Sep";
      break;
    case 9:
      month = "Oct";
      break;
    case 10:
      month = "Nov";
      break;
    case 11:
      month = "Dec";
      break;
  }


  var hour = now.getHours();
  var numMinutes = now.getMinutes();
  var minutes = "";
  if (numMinutes < 10)
  {
    minutes = "0" + numMinutes;
  }
  else
  {
    minutes = numMinutes;
  }

  var dateString = "<span class='date'>";
  dateString += hour + ":" + minutes + " - " + date + " " + month + " " + year;
  dateString += "</span>";
  document.writeln(dateString);
}


// validation function for event booking
function validateBookingForm()
{
  // check the contact name
  if (document.eventBooking.contactName.value.length < 2)
  {
    alert("Please enter your name");
    document.eventBooking.contactName.focus();
    return false;
  }

  // Check to see that at least one person is booking
  if (document.eventBooking.members.selectedIndex == 0 && document.eventBooking.nonMembers.selectedIndex == 0)
  {
    alert("Please indicate how many people will be attending.");
    return false;
  }

  // Check the to see if a member, if yes check membership number entered
  if (document.eventBooking.notPMIMember.checked == false && document.eventBooking.membershipNumber.value.length < 1)
  {
   alert("Please enter your PMI membership number\nor indicate that you are not a member");
   document.eventBooking.membershipNumber.focus();
   document.eventBooking.membershipNumber.select();
   return false;
  }

  // Check contact email address
  if (document.eventBooking.contactEmail.value.length < 1)
  {
    alert("Please enter your email address");
    document.eventBooking.contactEmail.focus();
    document.eventBooking.contactEmail.select();
    return false;
  }

  else
  {
    var reg1 = /(@.*@)|(\.\.)|(@\.)|(\.@)|(^\.)|([^\w\.\@\-\_])/;       // not valid
    var reg2 = /^.+\@[a-zA-Z0-9\-\.]+\.([a-zA-Z]{2,3}|[0-9]{1,3})$/;    // valid

    var email = document.eventBooking.contactEmail.value;

    if (!reg1.test(email) && reg2.test(email)) // if syntax is valid
    {
      return true;
    }
    else
    {
      alert("The contact email address you entered is not valid.\nPlease check it and try again.");
      document.eventBooking.contactEmail.focus();
      document.eventBooking.contactEmail.select();
      return false;
    }
  }
  return true;
}

// validation function for event booking
function validateAGMBookingForm()
{
  // check the contact name
  if (document.eventBooking.contactName.value.length < 2)
  {
    alert("Please enter your name");
    document.eventBooking.contactName.focus();
    return false;
  }

  // Check to see that at least one person is booking
  if (document.eventBooking.members.selectedIndex == 0)
  {
    alert("Please indicate how many people will be attending.");
    return false;
  }

  // Check the to see if a member, if yes check membership number entered
  if (document.eventBooking.membershipNumber.value.length < 1)
  {
   alert("Please enter your PMI membership number");
   document.eventBooking.membershipNumber.focus();
   document.eventBooking.membershipNumber.select();
   return false;
  }

  // Check contact email address
  if (document.eventBooking.contactEmail.value.length < 1)
  {
    alert("Please enter your email address");
    document.eventBooking.contactEmail.focus();
    document.eventBooking.contactEmail.select();
    return false;
  }

  else
  {
    var reg1 = /(@.*@)|(\.\.)|(@\.)|(\.@)|(^\.)|([^\w\.\@\-\_])/;       // not valid
    var reg2 = /^.+\@[a-zA-Z0-9\-\.]+\.([a-zA-Z]{2,3}|[0-9]{1,3})$/;    // valid

    var email = document.eventBooking.contactEmail.value;

    if (!reg1.test(email) && reg2.test(email)) // if syntax is valid
    {
      return true;
    }
    else
    {
      alert("The contact email address you entered is not valid.\nPlease check it and try again.");
      document.eventBooking.contactEmail.focus();
      document.eventBooking.contactEmail.select();
      return false;
    }
  }
  return true;
}

// fuction to set the name of the event by checking the url search string
// takes one argument the URL search string
function setEventTitle(qryString)
{
  if (qryString != null)
  {
    var eventName = qryString;
    eventName = eventName.substring(5, eventName.length);
    document.eventBooking.eventTitle.selectedIndex =  eventName;
  }
}


// function to open a popup window
function openPopup(url)
{
  window.open(url, "new", "width=670, height=500, toolbar=no, menubar=no, scrollbars=yes");
}

// function to open a popup window - used on the events pages
function openWin(url)
{
  var strURL = url
  window.open(strURL, 'newWin', 'width=400, height=400, left=100, top=100, menubar=no, toolbar=no, scrollbars=yes, status=no, location=no');
}

// function to open a vacancies details window
function vacancyPopup(lngID)
{
  window.open ('./asp/pmp_position.asp?popup=0&pid=' + lngID,"vacpopup","height=360,width=425,left=100,top=100,toolbar=no,location=no,directories=no,status=no,menubar=no,scrollbars=yes,resizable=no,copyhistory=no")
}

// function to open course schedule outlines
function popup(course,pth,bi)
  {
  var cpth = 0
  var wnam = 0
  if(pth)
    {
    cpth = pth + '/courses/' + course
    }
  else
    {
    cpth = 'courses/' + course
    }
  if(bi)
    {
    var wnam = bi
    }
  else
    {
    wnam = 'thiscourse'
    }

  window.open(cpth + ".htm",wnam,"scrollbars=yes,status=no,toolbars=no,top=1,left=1,width=640,height=400")
  }

