var xmlHttp;
var currentPage = 'home';
var currentBio = 'none';
var currentId = 'none';
var optional_show = 'none';

function MouseOver(id)
{
	if("menu_"+currentPage != id && currentPage != null)
	{
		document.getElementById(id).style.backgroundColor = '#0174BE';
		document.getElementById(id).style.color = '#fff';
	}
}

function MouseOut(id)
{
	if("menu_"+currentPage != id && currentPage != null)
	{
		document.getElementById(id).style.backgroundColor = '';
		document.getElementById(id).style.color = '#0174BE';
	}
}

function MouseOverLink(id)
{
	if(document.getElementById(id).className == 'floating_tab')
	{
		document.getElementById(id).className = 'floating_tab_over';
	}
}

function MouseOutLink(id)
{
	if(document.getElementById(id).className == 'floating_tab_over')
	{
		document.getElementById(id).className = 'floating_tab';
	}
}

function MouseOverHome(id)
{
	if("menu_"+currentPage != id && currentPage != null)
	{
		document.getElementById(id).style.backgroundColor = '#0174BE';
		document.getElementById(id).innerHTML = '<img src="images/home_over.png" alt="home"/>';
	}
}

function MouseOutHome(id)
{
	if("menu_"+currentPage != id && currentPage != null)
	{
		document.getElementById(id).style.backgroundColor = '';
		document.getElementById(id).innerHTML = '<img src="images/home.png" alt="home"/>';
	}
}

function BodyLoad()
{
	HighlightCurrentPage();
}

function HomeLoad()
{
	document.getElementById("menu_home").style.backgroundColor = '#4495CC';
	document.getElementById("menu_home").innerHTML = '<img src="images/home_over.png" alt="home"/>';
}

function HighlightCurrentPage()
{
	var string=(location.href); 
	var getit=new Array(); 
	var getit=string.split('/');
	var result=getit[3];
	var filename=result.split('.');
	

	document.getElementById("menu_"+filename[0]).style.backgroundColor = '#4495CC';
	document.getElementById("menu_"+filename[0]).style.color = '#fff';

	currentPage = filename[0];
}

function ChangeInternalTab(id,old_id, tab_section_text, opt_show)
{
	document.getElementById(id+"_body").style.display = 'block';

	document.getElementById(old_id+"_body").style.display = 'none';

	document.getElementById(id).className = 'floating_tab_active';
	document.getElementById(old_id).className = 'floating_tab';

	if(optional_show != 'none' && opt_show == 'none')
	{
		document.getElementById(optional_show).style.display = 'none';
	}

	if(opt_show != 'none')
	{
		document.getElementById(opt_show).style.display = 'block';
		optional_show = opt_show;
	}

	//Set the tab section text
	document.getElementById("tab_section_text").innerHTML = tab_section_text;
}

function ShowBio(id)
{
	if(currentBio != 'none' && currentBio != id)
	{
		document.getElementById(currentBio+'_bio').style.display = 'none';
		document.getElementById(currentBio+'_arrow').src = 'images/arrow_down.png';
		document.getElementById(currentBio+'_arrow_text').innerHTML = '<b>Read Bio</b>';
	}

	if(document.getElementById(id+'_bio').style.display == 'none')
	{
		document.getElementById(id+'_bio').style.display = 'block';
		document.getElementById(id+'_arrow').src = 'images/arrow_up.png';
		document.getElementById(id+'_arrow_text').innerHTML = '<b>Close Bio</b>';
	}
	else
	{
		document.getElementById(id+'_bio').style.display = 'none';
		document.getElementById(id+'_arrow').src = 'images/arrow_down.png';
		document.getElementById(id+'_arrow_text').innerHTML = '<b>Read Bio</b>';
	}

	currentBio = id;
}

/*---- Form code taken from placeholder ----*/

//Check to see if the email is in correct format - designplace.org
function IsValidEmail(strEmail)
{
  validRegExp = /^[^@]+@[^@]+.[a-z]{2,}$/i;

  // search email text for regular exp matches
  if (strEmail.search(validRegExp) == -1) 
  {
     return "false";
  }

  return "true"; 
}

function submitForm2()
{
	var title = document.contactform["title"].value;
	var firstName = document.contactform["first_name"].value;
	var lastName = document.contactform["last_name"].value;
	var phone = document.contactform["phone"].value;
	var email = document.contactform["email"].value;
	var orgName = document.contactform["00N30000003gIgX"].value;
	var address = document.contactform["street"].value;
	var city = document.contactform["city"].value;
	var state = document.contactform["state"].value;
	var zip = document.contactform["zip"].value;
	var comments = document.contactform["00N30000003gIh1"].value;
	var ann_ed_vol = document.contactform["00N30000003r7fo"].value;
	var p_ann_ad = document.contactform["00N30000003r7f3"].value;
	var ann_ed_vol_medicare = document.contactform["00N30000003r7f4"].value;
	var p_ann_medicare_ad = document.contactform["00N30000003r7gD"].value;
	var ann_ed_vol_medicaid = document.contactform["00N30000003r7fc"].value;
	var p_ann_medicaid_ad = document.contactform["00N30000003r7gm"].value;

	var emailClean = "false";

	emailClean = IsValidEmail(email);

	//Run checks to determine if all required fields have been filled out
	if(firstName == "") 
	{ alert("Please fill in your First Name"); return false; }

	if(lastName == "") 
	{ alert("Please fill in your Last Name"); return false; }

	if(email == "" || emailClean == "false") 
	{ alert("Please fill in a valid Email Address"); return false; }

	if(orgName == "") 
	{ alert("Please fill in your Organization's Name"); return false; }

	if(title == "") 
	{ alert("Please fill in your Title"); return false; }
	
	//If all the form field checks pass, continue to post the data
	xmlHttp=GetXmlHttpObject()
		
	if (xmlHttp==null)
	{
		alert("Browser does not support HTTP Request")
		return
	}
	
	var url="submit.php";

	var str="firstName="+firstName;
	str=str+"&lastName="+lastName;
	str=str+"&title="+title;
	str=str+"&phone="+phone;
	str=str+"&email="+email;
	str=str+"&orgName="+orgName;
	str=str+"&address="+address;
	str=str+"&city="+city;
	str=str+"&state="+state;
	str=str+"&zip="+zip;
	str=str+"&comments="+comments;
	str=str+"&ann_ed_vol="+ann_ed_vol;
	str=str+"&p_ann_ad="+p_ann_ad;
	str=str+"&ann_ed_vol_medicare="+ann_ed_vol_medicare;
	str=str+"&p_ann_medicare_ad="+p_ann_medicare_ad;
	str=str+"&ann_ed_vol_medicaid="+ann_ed_vol_medicaid;
	str=str+"&p_ann_medicaid_ad="+p_ann_medicaid_ad;

	xmlHttp.open("POST",url,true)
	xmlHttp.setRequestHeader("Content-Type","application/x-www-form-urlencoded; charset=UTF-8")
	xmlHttp.onreadystatechange=stateChanged
	xmlHttp.send(str)

	return true;
}

function stateChanged() 
{
	if (xmlHttp.readyState==4 || xmlHttp.readyState=="complete")
	{
		var t = xmlHttp.responseText;

		if(t != "error")
		{
			document.contactform.style.display = 'none';
			document.getElementById("thank_you").style.display = 'block';
		}
	} 
}

function GetXmlHttpObject()
{ 
	var objXMLHttp=null
	
	if (window.XMLHttpRequest)
	{
		objXMLHttp=new XMLHttpRequest()
	}
	else if (window.ActiveXObject)
	{
		objXMLHttp=new ActiveXObject("Microsoft.XMLHTTP")
	}
	return objXMLHttp
}

/*----- End of Code from placeholder ------*/