function lastSibling(node)
{
  var tempObj=node.parentNode.lastChild;
  while(tempObj.nodeType!=1 && tempObj.previousSibling!=null)
  {
    tempObj=tempObj.previousSibling;
  }
  return (tempObj.nodeType==1)?tempObj:false;
}

function firstSibling(node)
{
  var tempObj=node.parentNode.firstChild;
  while(tempObj.nodeType!=1 && tempObj.nextSibling!=null)
  {
    tempObj=tempObj.nextSibling;
  }
  return (tempObj.nodeType==1)?tempObj:false;
}

function closestSibling(node,direction)
{
  var tempObj;
  if(direction==-1 && node.previousSibling!=null)
  {
    tempObj=node.previousSibling;
    while(tempObj.nodeType!=1 && tempObj.previousSibling!=null)
    {
       tempObj=tempObj.previousSibling;
    }
  }
  else if(direction==1 && node.nextSibling!=null)
  {
    tempObj=node.nextSibling;
    while(tempObj.nodeType!=1 && tempObj.nextSibling!=null)
    {
      tempObj=tempObj.nextSibling;
    }
  }
  return tempObj.nodeType==1?tempObj:false;
}

function closeExpand()
{
  allDiv = document.getElementsByTagName("div");
  for (var i=0; i < allDiv.length; i++)
  {
    if (allDiv[i].className == "contentExpand")
    {
      allDiv[i].style.display = "none";
    }
    if (allDiv[i].className == "expandIcon")
    {
      allDiv[i].innerHTML = "<span style='font-weight: normal; font-style: italic;'>see details</span> +";
    }
  }
}

function expand(titleExpand, med) {
  var expandIcon = lastSibling(titleExpand.firstChild, 1);
  var contentExpand = closestSibling(titleExpand, 1);
  if (expandIcon.innerHTML == "-")
  {
    contentExpand.style.display = "none";
    if (typeof(med) == "undefined")
    {
      titleExpand.style.background = "none";
      titleExpand.style.background = "url(images/news_icon.png) 0 1px no-repeat";
    }
    expandIcon.innerHTML = "<span style='font-weight: bold; font-style: italic;'>see details</span> +";
  }
  else
  {
    contentExpand.style.display = "block";
    if (typeof(med) == "undefined")
      titleExpand.style.background = "url(images/news2_icon.png) 0 0px no-repeat";
    expandIcon.innerHTML = "-";
  }
}

function createBookmark(title, url) {
	if (window.sidebar) { // Mozilla Firefox Bookmark
		window.sidebar.addPanel(title, url,"");
	} else if( window.external ) { // IE Favorite
		window.external.AddFavorite( url, title); }
	else if(window.opera && window.print) { // Opera Hotlist
		var elem = document.createElement('a');
    elem.setAttribute('href',url);
    elem.setAttribute('title',title);
    elem.setAttribute('rel','sidebar');
    elem.click(); }
}

function checkemail(str) {
  var filter=/^([\w-]+(?:\.[\w-]+)*)@((?:[\w-]+\.)*\w[\w-]{0,66})\.([a-z]{2,6}(?:\.[a-z]{2})?)$/i
  return filter.test(str);
}

function sendEmailSubmit()
{
  if (document.sendToFriendFrm.subject.value == "")
  {
    document.sendToFriendFrm.subject.focus();
    alert("Please enter subject for mail");
    return false;
  }
  else if (document.sendToFriendFrm.name.value == "")
  {
    document.sendToFriendFrm.name.focus();
    alert("Please enter your name for mail");
    return false;
  }
  else if (!checkemail(document.sendToFriendFrm.fromEmail.value))
  {
    document.sendToFriendFrm.fromEmail.focus();
    alert("Please enter a valid email address of your email");
    return false;
  }
  else if (!checkemail(document.sendToFriendFrm.toEmail.value))
  {
    document.sendToFriendFrm.toEmail.focus();
    alert("Please enter a valid email address of your friend's email");
    return false;
  }
  else if (document.sendToFriendFrm.content.value == "")
  {
    document.sendToFriendFrm.content.focus();
    alert("Please enter your message for mail to your friend");
    return false;
  }
  
  return true;
}

function reminderSubmit()
{
  if (document.remindFrm.name.value == "")
  {
    document.remindFrm.name.focus();
    alert("Please enter your name");
    return false;
  }
  else if (!checkemail(document.remindFrm.email.value))
  {
    document.remindFrm.email.focus();
    alert("Please enter a valid email address");
    return false;
  }
  
  return true;
}

function signupFrmSubmit()
{
  if (document.signupFrm.name.value == "")
  {
    document.signupFrm.name.focus();
    alert("Please enter your name");
    return false;
  }
  else if (document.signupFrm.tel.value.toString().length < 9)
  {
    document.signupFrm.tel.focus();
    alert("Please enter a valid tel");
    return false;
  }
  else if (!checkemail(document.signupFrm.email.value))
  {
    document.signupFrm.email.focus();
    alert("Please enter a valid email address of your email");
    return false;
  }
  else if (document.signupFrm.attend.value < 0)
  {
    document.signupFrm.attend.focus();
    alert("Please enter a valid attend number");
    return false;
  }
  
  return true;
}

function changeCalendar(val)
{
  var today = new Date();
  var todayDate = today.getDate();
  var todayMonth = today.getMonth();
  todayMonth++;
  var todayYear = today.getFullYear();
  
  if (val == 1)
  {
    window.location.href = "?com=events&month=" + todayMonth + "&year=" + todayYear;
  }
  else if (val == 2)
  {
    window.location.href = "?com=events&date=" + todayDate + "&month=" + todayMonth + "&year=" + todayYear;
  }
  else if (val == 3)
  {
    window.location.href = "?com=events&day=thisWeek";
  }
  else if (val == 4)
  {
    window.location.href = "?com=events&day=all";
  }
}
