
function toggleLayer( whichLayer )
{
  var elem, vis;
  if( document.getElementById ) // this is the way the standards work
    elem = document.getElementById( whichLayer );
  else if( document.all ) // this is the way old msie versions work
      elem = document.all[whichLayer];
  else if( document.layers ) // this is the way nn4 works
    elem = document.layers[whichLayer];
  vis = elem.style;
  // if the style.display value is blank we try to figure it out here
  if(vis.display==''&&elem.offsetWidth!=undefined&&elem.offsetHeight!=undefined)
    vis.display = (elem.offsetWidth!=0&&elem.offsetHeight!=0)?'block':'none';
  vis.display = (vis.display==''||vis.display=='block')?'none':'block';
}


function CheckForm(thisform,destination)
{
    if(thisform.name.value=='')
	{ alert("Please fill in the name field");
	return false;
	}
	
	if(!validEmail(thisform.email.value))
	return false;
	
	if((thisform.country.value=='United States') && (thisform.zip.value==''))
	{ alert("If you live in the US please enter a valid zipcode");
	return false;
	}

    thisform.action=destination;return true;


}




function CheckGoalsForm(thisform)
{
    if(thisform.name.value=='')
	{ alert("Please fill in the name field");
	return false;
	}
	
	if(!validEmail(thisform.email.value))
	return false;
	
	if((thisform.country.value=='United States') && (thisform.zip.value==''))
	{ alert("If you live in the US please enter a valid zipcode");
	return false;
	}

	if(thisform.subsection.value=='')
	{ alert("Please select a subsection");
	return false;
	}
	
   return true;


}


function validEmail(str, msg){

	var emailErrorMsg = msg;

	if(emailErrorMsg == null) emailErrorMsg = "Please enter a valid email address. Email addresses must include the\n@ sign and at least one period. (e.g. friendname@abc.com)";

	if (!isValidEmail(str)){

		if(emailErrorMsg != "nomsg") alert(emailErrorMsg);

		return false;

	}

	return true;

}

function isValidEmail(str){

	var at;

	var i = 0;

	var j = str.length - 1;

	var count = 0;

	at = str.indexOf("@", 0);

	if (at <= 0 || at == j) return false;

	while (i < at){

		if ((str.charAt(i) >= '0' && str.charAt(i) <= '9') ||

			(str.charAt(i) >= 'a' && str.charAt(i) <= 'z') ||

			(str.charAt(i) >= 'A' && str.charAt(i) <= 'Z') ||

			str.charAt(i) == '.' || str.charAt(i) == '&' || 

			str.charAt(i) == '?' || str.charAt(i) == '#' || 

			str.charAt(i) == '$' || str.charAt(i) == '*' || 

			str.charAt(i) == '+' || str.charAt(i) == '!' || 

			str.charAt(i) == '%' || str.charAt(i) == '\'' || 

			str.charAt(i) == '^' || str.charAt(i) == '/' || 

			str.charAt(i) == '_' || str.charAt(i) == '-')

				i++;

		else return false;

	}

	i = at + 1;

	if(str.charAt(i) == '.' || str.charAt(j) == '.') return false;

	while (i <= j){

		if(str.charAt(i) == '.'){

			count++;

			if (str.charAt(i + 1) == '.') return false;

			else i++;

		}

		if((str.charAt(i) >= '0' && str.charAt(i) <= '9') || (str.charAt(i) >= 'a' && str.charAt(i) <= 'z') ||

			(str.charAt(i) >= 'A' && str.charAt(i) <= 'Z') || str.charAt(i) == '_' || str.charAt(i) == '-')

			i++;

		else return false;

	}

	return (count == 0) ? false : true;

}


// TAB script

function tabview_aux(TabViewId, CurrentId)
{
  var TabView = document.getElementById(TabViewId);

  // ***** Tabs *****

  var Tabs = TabView.firstChild;
  while (Tabs.className != "Tabs") Tabs = Tabs.nextSibling;
  var Tab  = Tabs   .firstChild;
  var i    = 0;

  do
  {
    if (Tab.tagName == "A")
    {
      i++;
      Tab.href         = "javascript:tabview_switch('"+TabViewId+"', "+i+");";
      Tab.className    = (i == CurrentId) ? "Current" : "";
      Tab.blur();
    }
  }
  while (Tab = Tab.nextSibling);

  // ***** Pages *****

  var Pages = TabView.firstChild;
  while (Pages.className != 'Pages') Pages = Pages.nextSibling;
  var Page  = Pages  .firstChild;
  var i     = 0;

  do
  {
    if (Page.className == 'Page')
    {
      i++;
      //if (Pages.offsetHeight) Page.style.height = (Pages.offsetHeight-2)+"px";
	  //Pages.offsetHeight=0;
      Page.style.display  = (i == CurrentId) ? 'block' : 'none';
    }
  }
  while (Page = Page.nextSibling);
}


// ***** Tab View **************************************************************

function tabview_switch(TabViewId, id) { tabview_aux(TabViewId, id); }
function tabview_initialize(TabViewId) { tabview_aux(TabViewId,  1); }



function CheckOrgForm(thisform,destination)
{
	var warning="";
     if(thisform.organization.value=='')
	{ warning="Please fill in the organization field\n";
	
	}
	
	if(thisform.name.value=='')
	{ warning=warning+"Please fill in the name field\n";
	
	}
	
	if(!validEmail(thisform.email.value))
	warning=warning + "Invalid Email\n";
	
	if((thisform.country.value=='United States') && (thisform.zip.value==''))
	{ warning=warning + "If you live in the US please enter a valid zipcode\n";
	
	}
	if((thisform.sign.checked==false) || (thisform.found.checked==false) || (thisform.donatec.checked==false) )
	{ 
	warning=warning+"You must agree to the commitments in order to become an orgnanizational partner\n";
	
	}
	
	if(warning=='')
	{
    thisform.action=destination;
	return true;
	}
	else
	{ alert(warning);
	return false;
	}


}


	function SetCheckOrCredit(type) {
		document.getElementById("payByCredit").style.display = "none"
		document.getElementById("payByCheck").style.display = "none"
		// Using style.display="block" instead of style.display="" leaves a carriage return
		document.getElementById(type).style.display = ""
	}
