//Smart Folding Menu tree- By Dynamic Drive (rewritten 03/03/02)
//For full source code and more DHTML scripts, visit http://www.dynamicdrive.com
//This credit MUST stay intact for use
var ns6=document.getElementById&&!document.all
var ie4=document.all&&navigator.userAgent.indexOf("Opera")==-1

var intLeftNavItems = 13;

function checkcontained(e){
	var iscontained=0
	cur=ns6? e.target : event.srcElement
	i=0
	if (cur.id.indexOf("foldheader") != -1)			
		iscontained=1	
	else
		while (ns6&&cur.parentNode||(ie4&&cur.parentElement)){
			if (cur.id.indexOf("foldheader") != -1 || cur.id.indexOf("foldinglist")!= -1){
				iscontained=(cur.id.indexOf("foldheader")!=-1)? 1 : 0
				break
			}
			cur=ns6? cur.parentNode : cur.parentElement
		}	
		
	var arrFolder = cur.id.split("_");
	var intFolder = arrFolder[1];	
	
	if (iscontained && navigator.appName != "Netscape" && intFolder != 1 && intFolder != 8 && intFolder != 9){						
		if (eval("document.all.foldinglist_" + intFolder + ".style").display=="none"){			
			eval("document.all.foldinglist_" + intFolder + ".style").display=""
		}
		else{
			eval("document.all.foldinglist_" + intFolder + ".style").display=="none"
		}						
		for (var i=1; i<intLeftNavItems;i++)
		{
			if (intFolder != i)
				eval("document.all.foldinglist_" + i + ".style").display = "none"
		}	
	}		
	else if (iscontained && navigator.appName == "Netscape" && intFolder != 1 && intFolder != 8 && intFolder != 9){						
		if (eval("document.getElementById('foldinglist_" + intFolder + "').style").display=="none"){			
			eval("document.getElementById('foldinglist_" + intFolder + "').style").display=""
		}
		else{
			eval("document.getElementById('foldinglist_" + intFolder + "').style").display=="none"
		}						
		for (var i=1; i<intLeftNavItems;i++)
		{
			if (intFolder != i)
				eval("document.getElementById('foldinglist_" + i + "').style").display = "none"
		}	
	}
	
}

if (ie4||ns6)
document.onclick=checkcontained

function popupNewWindow(sURL)
{					
	var newWindow = window.open(sURL, "wndNew", "scrollbars=yes, menubar=no, width=500, height=300");		
}

function validateMaterialRequestForm() {
    var valid = true;
	var validationText = "";
	
	
	if ( document.frmMatericalRequest.first_name.value == "" )
	{
		validationText += "First Name is required. \n";
		valid =  false;
	}
	if ( document.frmMatericalRequest.last_name.value == "" )
	{
		validationText += "Last Name is required. \n";
		valid = false;
	}
	if ( document.frmMatericalRequest.email.value == "" )
	{
		validationText += "Email is required. \n";
		valid = false;
	}
	if ( document.frmMatericalRequest.donor_sperm_info_packet.selectedIndex == 0 && 
	     document.frmMatericalRequest.insemination_brochure.selectedIndex == 0 && 
	     document.frmMatericalRequest.sperm_storage_brochure.selectedIndex == 0 && 
	     document.frmMatericalRequest.embryo_storage_brochures.selectedIndex == 0 && 
	     document.frmMatericalRequest.comparison_chart.selectedIndex == 0 && 
	     document.frmMatericalRequest.business_cards.selectedIndex == 0 )
	{
		validationText += "You have not requested any materials. \n";
		valid = false;
	}
	
	if (!valid) alert(validationText);
	
	return valid;
}

function validateForm()
{	
	var valid = true;
	var validationText = "";

	if ( document.pregForm.oder_no.value == "" )
	{
		validationText += "Order No. is required. \n";
		valid =  false;
	}
	if ( document.pregForm.donor_no.value == "" )
	{
		validationText += "Donor No. is required. \n";
		valid = false;
	}
	if ( document.pregForm.email.value == "" )
	{
		validationText += "Email is required. \n";
		valid = false;
	}
	if (document.pregForm.preg_type.value == undefined)
	{
		var currentRadio = false;
		for (var i = 0; i < document.pregForm.preg_type.length; i++) {
			if (document.pregForm.preg_type[i].checked)
			currentRadio = true;
		}
		if (!currentRadio)
		{
			validationText += "Pregnancy type is required. \n";
			valid = false;
		}
	}
	if (document.pregForm.location_country.selectedIndex == 0)
	{
		validationText += "Insemination location is required. \n";
		valid = false;
	}
	if (document.pregForm.location_country.selectedIndex == 1 && 
		(document.pregForm.location_state.selectedIndex == 0 || document.pregForm.location_zip.value == ""))
	{
		validationText += "Insemination location is required. \n";
		valid = false;
	}
	if (document.pregForm.location_country.selectedIndex == 2 && 
		document.pregForm.location_country_other.value == "")
	{
		validationText += "Insemination location is required. \n";
		valid = false;
	}
	if (document.pregForm.prev_form.value == undefined)
	{
		var currentRadio = false;
		for (var i = 0; i < document.pregForm.prev_form.length; i++) {
			if (document.pregForm.prev_form[i].checked)
			currentRadio = true;
		}
		if (!currentRadio)
		{
			validationText += "Please indicate whether you have previously filled out this form.";
			valid = false;				
		}		
	}
	
	if (!valid)
		alert (validationText);

	return valid;
}

function displayLocation()
{
	if (document.pregForm.location_country.selectedIndex == 1) 
	{
		if (document.all)
		{					
			document.all.location2.style.display = 'block';					
			document.all.location1.style.display = 'none';	
		}
		else	
		{					
			document.getElementById('location2').style.display = 'block';
			document.getElementById('location1').style.display = 'none';										
		}
	} 
	if (document.pregForm.location_country.selectedIndex == 2)
	{
		if (document.all)
		{					
			document.all.location1.style.display = 'block';		
			document.all.location2.style.display = 'none';			
		}
		else	
		{					
			document.getElementById('location1').style.display = 'block';
			document.getElementById('location2').style.display = 'none';
		}
	}		
}

function showDivs(divTag)
{
	if (divTag == "bio")
	{
		if (document.all)
		{
			document.all.bio1.style.display = 'block';
			document.all.clin1.style.display = 'none';
			document.all.clin2.style.display = 'none';
			document.all.birth1.style.display = 'none';
			document.all.birth2.style.display = 'none';
		}
		else	
		{
			document.getElementById('bio1').style.display = 'block';
			document.getElementById('clin1').style.display = 'none';
			document.getElementById('clin2').style.display = 'none';
			document.getElementById('birth1').style.display = 'none';
			document.getElementById('birth2').style.display = 'none';
		}
	}
	if (divTag == "clin")
	{
		if (document.all)
		{
			document.all.bio1.style.display = 'none';
			document.all.bio2.style.display = 'none';
			document.all.clin1.style.display = 'block';					
			document.all.birth1.style.display = 'none';
			document.all.birth2.style.display = 'none';
		}
		else	
		{
			document.getElementById('bio1').style.display = 'none';
			document.getElementById('bio2').style.display = 'none';
			document.getElementById('clin1').style.display = 'block';					
			document.getElementById('birth1').style.display = 'none';
			document.getElementById('birth2').style.display = 'none';
		}
	}
	if (divTag == "birth")
	{
		if (document.all)
		{
			document.all.bio1.style.display = 'none';
			document.all.bio2.style.display = 'none';
			document.all.clin1.style.display = 'none';
			document.all.clin2.style.display = 'none';	
			document.all.birth1.style.display = 'block';
			document.all.birth2.style.display = 'block';
		}
		else	
		{
			document.getElementById('bio1').style.display = 'none';
			document.getElementById('bio2').style.display = 'none';
			document.getElementById('clin1').style.display = 'none';
			document.getElementById('clin2').style.display = 'none';
			document.getElementById('birth1').style.display = 'block';
			document.getElementById('birth2').style.display = 'block';
		}
	}
	if (divTag == "bio1")
	{
		if (document.all)
		{					
			document.all.bio2.style.display = 'block';					
		}
		else	
		{					
			document.getElementById('bio2').style.display = 'block';										
		}
	}
	if (divTag == "clin1")
	{
		if (document.all)
		{					
			document.all.clin2.style.display = 'block';					
		}
		else	
		{					
			document.getElementById('clin2').style.display = 'block';										
		}
	}
}
function showDiv()
{
	if (document.all)
		document.all.showDiv.style.display = 'block';
	else	
		document.getElementById('showDiv').style.display = 'block';
}

function RTrim(strMyString) {
	return(strMyString.replace(/^\s*/,""));
}
 
function LTrim(strMyString) {
	return(strMyString.replace(/\s*$/, ""));
}
 
function Trim(strMyString) {
	return(RTrim(LTrim(strMyString)));
}
	
function validateShareStory() {
	var strStatus = "";
	var showStatus = 0;
	var theForm = document.forms['request_form']

	if (theForm.share_with_media[0].checked) {

		if ((theForm.evening_phone.value=="Evening Phone") || (Trim(theForm.evening_phone.value)=="")) {
			showStatus=1;
			strStatus = "Please enter your evening phone.";
		}	

		if ((theForm.daytime_phone.value=="Daytime Phone") || (Trim(theForm.daytime_phone.value)=="")) {
			showStatus=1;
			strStatus = "Please enter your daytime phone.";
		}	
		
		if ((theForm.address.value=="Address") || (Trim(theForm.address.value)=="")) {
			showStatus=1;
			strStatus = "Please enter your address.";
		}
			
		if ((theForm.name.value=="Name") || (Trim(theForm.name.value)=="")) {
			showStatus=1;
			strStatus = "Please enter your name.";
		}

	}
	
	if ((theForm.share_with_media[0].checked==false)&&(theForm.share_with_media[1].checked==false)) {
		showStatus=1;
		strStatus = "Please select an option for sharing your identity.";
	}
	
	if ((theForm.publish_photo_anonymously[0].checked==false)&&(theForm.publish_photo_anonymously[1].checked==false)) {
		showStatus=1;
		strStatus = "Please select an option for publishing your photos.";
	}	
	
	if ((theForm.publish_testimonial_anonymously[0].checked==false)&&(theForm.publish_testimonial_anonymously[1].checked==false)) {
		showStatus=1;
		strStatus = "Please select an option for publishing your story.";
	}
	
	if ((theForm.state.value=="Please list your state of residence") || (Trim(theForm.state.value)=="")) {
		showStatus=1;
		strStatus = "Please enter your state of residence.";
	}

	if ((theForm.initials.value=="Please list your initials") || (Trim(theForm.initials.value)=="")) {
		showStatus=1;
		strStatus = "Please enter your initials.";
	}
	
	if ((theForm.story.value=="Story Entry") || (Trim(theForm.story.value)=="")) {
		showStatus=1;
		strStatus = "Please enter your story.";
	}	
	
	if (showStatus) {
		alert(strStatus);		
		return false;
	}
	else {
		return true;
	}
}

function validateNewsletter()
{	
	var valid = true;
	var validationText = "";

	if ( document.frmNewsletter.email.value == "" )
	{
		validationText += "Email is required. \n";
		valid =  false;
	}
	if ( document.frmNewsletter.first_name.value == "" )
	{
		validationText += "First Name is required. \n";
		valid =  false;
	}
	if ( document.frmNewsletter.last_name.value == "" )
	{
		validationText += "Last Name is required. \n";
		valid =  false;
	}
	if ( document.frmNewsletter.company_name.value == "" )
	{
		validationText += "Company Name is required. \n";
		valid =  false;
	}
	if ( document.frmNewsletter.address.value == "" )
	{
		validationText += "Address is required. \n";
		valid =  false;
	}
	if ( document.frmNewsletter.city.value == "" )
	{
		validationText += "City is required. \n";
		valid =  false;
	}
	if (document.frmNewsletter.state.selectedIndex == 0)
	{
		validationText += "State/Province is required. \n";
		valid = false;
	}	
	if ( document.frmNewsletter.zip.value == "" )
	{
		validationText += "Zip/Postal Code is required. \n";
		valid =  false;
	}		
	
	if (!valid)
		alert (validationText);

	return valid;
}