/* begin top navigations */

var mouseoutofnav = false; 

function timedHide(){
	mouseoutofnav = true;
	var navtimer = setTimeout("hideSubnav()",5000);
}
function hideSubnav(){
	if (mouseoutofnav) {
		hideAllSubnav();
		mouseoutofnav = false;
	}
}
function showSubnav(id){
	mouseoutofnav = false;
	hideAllSubnav();
	document.getElementById(id).style.display = 'block';
}


function hideAllSubnav(){
	document.getElementById('about_subnav').style.display = 'none';
	document.getElementById('member_subnav').style.display = 'none';
	document.getElementById('store_subnav').style.display = 'none';
}

/* end top navigations */


/* begin search field */

function clearField(form) {
for (var i = 1; i < arguments.length; ++i)
form.elements[arguments[i]].value = '';
}

/* end search field */


/* begin side navigation */

function SDMenu(id) {
	if (!document.getElementById || !document.getElementsByTagName)
		return false;
	this.menu = document.getElementById(id);
	this.submenus = this.menu.getElementsByTagName("div");
	this.remember = true;
	this.speed = 3;
	this.markCurrent = true;
	this.oneSmOnly = true;
}
SDMenu.prototype.init = function() {
	var mainInstance = this;
	for (var i = 0; i < this.submenus.length; i++)
		this.submenus[i].getElementsByTagName("span")[0].onclick = function() {
			mainInstance.toggleMenu(this.parentNode);
		};
	if (this.markCurrent) {
		var links = this.menu.getElementsByTagName("a");
		for (var i = 0; i < links.length; i++)
			if (links[i].href == document.location.href) {
				links[i].className = "current";
				break;
			}
	}
	if (this.remember) {
		var regex = new RegExp("sdmenu_" + encodeURIComponent(this.menu.id) + "=([01]+)");
		var match = regex.exec(document.cookie);
		if (match) {
			var states = match[1].split("");
			for (var i = 0; i < states.length; i++)
				this.submenus[i].className = (states[i] == 0 ? "collapsed" : "");
		}
	}
};
SDMenu.prototype.toggleMenu = function(submenu) {
	if (submenu.className == "collapsed")
		this.expandMenu(submenu);
	else
		this.collapseMenu(submenu);
};
SDMenu.prototype.expandMenu = function(submenu) {
	var fullHeight = submenu.getElementsByTagName("span")[0].offsetHeight;
	var links = submenu.getElementsByTagName("a");
	for (var i = 0; i < links.length; i++)
		fullHeight += links[i].offsetHeight;
	var moveBy = Math.round(this.speed * links.length);
	
	var mainInstance = this;
	var intId = setInterval(function() {
		var curHeight = submenu.offsetHeight;
		var newHeight = curHeight + moveBy;
		if (newHeight < fullHeight)
			submenu.style.height = newHeight + "px";
		else {
			clearInterval(intId);
			submenu.style.height = "";
			submenu.className = "";
			mainInstance.memorize();
		}
	}, 30);
	this.collapseOthers(submenu);
};
SDMenu.prototype.collapseMenu = function(submenu) {
	var minHeight = submenu.getElementsByTagName("span")[0].offsetHeight;
	var moveBy = Math.round(this.speed * submenu.getElementsByTagName("a").length);
	var mainInstance = this;
	var intId = setInterval(function() {
		var curHeight = submenu.offsetHeight;
		var newHeight = curHeight - moveBy;
		if (newHeight > minHeight)
			submenu.style.height = newHeight + "px";
		else {
			clearInterval(intId);
			submenu.style.height = "";
			submenu.className = "collapsed";
			mainInstance.memorize();
		}
	}, 30);
};
SDMenu.prototype.collapseOthers = function(submenu) {
	if (this.oneSmOnly) {
		for (var i = 0; i < this.submenus.length; i++)
			if (this.submenus[i] != submenu && this.submenus[i].className != "collapsed")
				this.collapseMenu(this.submenus[i]);
	}
};
SDMenu.prototype.expandAll = function() {
	var oldOneSmOnly = this.oneSmOnly;
	this.oneSmOnly = false;
	for (var i = 0; i < this.submenus.length; i++)
		if (this.submenus[i].className == "collapsed")
			this.expandMenu(this.submenus[i]);
	this.oneSmOnly = oldOneSmOnly;
};
SDMenu.prototype.collapseAll = function() {
	for (var i = 0; i < this.submenus.length; i++)
		if (this.submenus[i].className != "collapsed")
			this.collapseMenu(this.submenus[i]);
};
SDMenu.prototype.memorize = function() {
	if (this.remember) {
		var states = new Array();
		for (var i = 0; i < this.submenus.length; i++)
			states.push(this.submenus[i].className == "collapsed" ? 0 : 1);
		var d = new Date();
		d.setTime(d.getTime() + (30 * 24 * 60 * 60 * 1000));
		document.cookie = "sdmenu_" + encodeURIComponent(this.menu.id) + "=" + states.join("") + "; expires=" + d.toGMTString() + "; path=/";
	}
};

/* end side navigation */


/* begin form validation */

function submitIt(myform) {

if(document.myform.realname.value==""){
	alert("Please enter your name.") 
  
    return false
    }

	if(document.myform.email.value==""){
		alert("Please enter your email.")
   
    	return false
	}
	
	if(document.myform.address.value==""){
		alert("Please enter your address.")
   
		return false
	}
	
	if(document.myform.city.value==""){
		alert("Please enter your city.")
   
		return false
	}
	
		if(document.myform.state.value==""){
		alert("Please enter your state.")
   
		return false
	}
	
		if(document.myform.zip.value==""){
		alert("Please enter your zip code.")
   
		return false
	}
     
return true
}

/* end form validation */
/* Begin counter code */



function _isLeap(y){return ( ((y%4==0)&(y%100!=0))|(y%400==0) );}

//return number of days in a particular month
function daysInMonth(m, y)
{

  var gaMonthCnt = new Array(31, 28, 31, 30, 31, 30, 31, 31, 30, 31, 30, 31);
  var gaMonthCntL = new Array(31, 29, 31, 30, 31, 30, 31, 31, 30, 31, 30, 31);
  if (_isLeap(y))
    return gaMonthCntL[m];
  else
	 return gaMonthCnt[m];
	 
}

/* Given two Dates, returns a string showing the Years, months, and days betwen them */
function durationBetween(oldDate, newDate) {
  var yearsApart;
  var monthsApart;
  var daysApart;
  
  var oldYear = oldDate.getFullYear();
  var newYear = newDate.getFullYear();
  var oldMonth = oldDate.getMonth();
  var newMonth = newDate.getMonth();
  var oldDay = oldDate.getDate();
  var newDay = newDate.getDate();

// debug
//  document.write("<br>Debug: Old: Year " + oldYear + " Month " + oldMonth + " day " + oldDay);
//  document.write("<br>Debug: New: Year " + newYear + " Month " + newMonth + " day " + newDay + "<br>");
// Find difference in days
  if (newDay >= oldDay)  
    daysApart = newDay - oldDay; // If the new day is greater than the old day - subtract and return
  else {   // if the new day is less than the old day 
    var lastMonth = (newMonth==0) ? 11 : newMonth-1;
    var lastMonthYear = (newMonth==0) ? newYear-1 : newYear;
    var daysInPrevMonth = daysInMonth(lastMonth, lastMonthYear); //   find number of days in previous month
    daysApart = daysInPrevMonth - oldDay + newDay;
//   borrow the 1


    if (newMonth > 0) //   if new month > january 
      newMonth = newMonth - 1; //     subtract 1 from new month 
    else {  //     new month is January
      newMonth = 12; // crank it back to December
      newYear = newYear - 1; //     subtract 1 from year
    }
   }

// Find difference in months 

	if (newMonth >= oldMonth) // If the new month is greater than the old month - subtract and return 
	  monthsApart = newMonth - oldMonth;
	else { // If the new month is less than the month day
     monthsApart = (12 - oldMonth) + newMonth;
	  newYear = newYear - 1; //   borrow the 1
	}

// Find the difference in years
   yearsApart = newYear - oldYear;
   

   var yearsString = yearsApart > 1 ? yearsApart + " years " : yearsApart + " year "
   var monthsString = monthsApart > 0 ? monthsApart > 1 ? monthsApart + " months " : monthsApart + " month " : "" 
   var daysString = daysApart > 0 ? daysApart > 1 ? daysApart + " days" : daysApart + " day" : ""
   return yearsString + monthsString + daysString;
}

/* Return duration since certain date */
/* Accept date as input */
/* Return current date - input date */
function timeSince(d)
{
  today = new Date();
  return durationBetween(d, today);
}


/* Return Gilad Shalit's time in captivity */
/* Abducted 25 June 2006 */
function giladTime() {
  return timeSince(new Date(2006, 5, 25));
}

/* Return Eldad Regev's and Ehud Goldwasser's time in captivity */
/* Abducted 12 July 2006 */
function eldadAndEhudTime() {
  return timeSince(new Date(2006, 6, 12));
}

/* End Counter Code */
