function setup( ) {

	//index.jsp?src=repfinder&group=patients

	//Hide base form elements & patient set/healthcare provider set (on by default for accessibility)

	hideBaseForm();
	hidePatientSet();
	hideHealthcareProviderSet();
	//Set noscript check to false

	noscript = document.getElementById( 'noscript' );
	noscript.value = 0;
	var linkCheck = ( document.location.href ) ? document.location.href : document.location;
	if( linkCheck.indexOf( "?" ) != -1 ) {//whether the location contains a "?" or not

		var attributesList = linkCheck.split( "?" )[1].split( "&" );
		var srcValue = "";
		var groupValue = "";
		//Extract the values of src and group from the URL

		for( var i = 0; i < attributesList.length; i++ ) {

			if( attributesList[i].match( "src" ) != null ) {

				srcValue = attributesList[i];
			}

			if( attributesList[i].match( "group" ) != null ) {

				groupValue = attributesList[i];
			}

		}

		srcValue = srcValue.split( "=" )[1];
		groupValue = groupValue.split( "=" )[1];
		//Apply value to figure out what should be selected

		// only check the box if src is NOT 3000iu
			if (srcValue != "3000iu"){
			var keepinformed3000iu = document.getElementById( 'keepinformed3000iu' );
			//keepinformed3000iu.checked = false;
			}


		if( groupValue == "" ) {

			document.getElementById( 'whatAmI' ).selectedIndex = 0;
		} else if( groupValue == "patients" ) {

			document.getElementById( 'whatAmI' ).selectedIndex = 1;
		} else if( groupValue == "parentsandcaregivers" ) {

			document.getElementById( 'whatAmI' ).selectedIndex = 2;
		} else if( groupValue == "healthcareproviders" ) {

			document.getElementById( 'whatAmI' ).selectedIndex = 3;
		}

		//Update page to show this change

		whatAmISelectionChange( document.getElementById( 'whatAmI' ).value );
		document.getElementById( 'patientSearching' ).selectedIndex = 0;
		document.getElementById( 'parentOrCaregiverSearching' ).selectedIndex = 0;
		document.getElementById( 'healthcareProviderSearching' ).selectedIndex = 0;
		//Apply srvValue

		if( groupValue == "" ) {

			whatAmISearchingChange( "" );
		} else if( groupValue == "patients" ) {

			if( srcValue == "repfinder" ) {

				document.getElementById( 'patientSearching' ).selectedIndex = 1;
			} else if( srcValue == "question" ) {

				document.getElementById( 'patientSearching' ).selectedIndex = 2;
			} else if( srcValue == "feedback" ) {

				document.getElementById( 'patientSearching' ).selectedIndex = 3;
			} else if( srcValue == "stayinformed" ) {

				document.getElementById( 'patientSearching' ).selectedIndex = 4;
			} else if( srcValue == "3000iu" ) {
				// unhide image
				document.getElementById( 'contact3000iu' ).style.display = "inline";
				document.getElementById( 'patientSearching' ).selectedIndex = 5;
			}

		} else if( groupValue == "parentsandcaregivers" ) {

			if( srcValue == "repfinder" ) {

				document.getElementById( 'parentOrCaregiverSearching' ).selectedIndex = 1;
			} else if( srcValue == "question" ) {

				document.getElementById( 'parentOrCaregiverSearching' ).selectedIndex = 2;
			} else if( srcValue == "feedback" ) {

				document.getElementById( 'parentOrCaregiverSearching' ).selectedIndex = 3;
			} else if( srcValue == "stayinformed" ) {

				document.getElementById( 'parentOrCaregiverSearching' ).selectedIndex = 4;
			} else if( srcValue == "3000iu" ) {
				document.getElementById( 'contact3000iu' ).style.display = "inline";
				document.getElementById( 'parentOrCaregiverSearching' ).selectedIndex = 5;
			}

		} else if( groupValue == "healthcareproviders" ) {

			if( srcValue == "repfinder" ) {

				document.getElementById( 'healthcareProviderSearching' ).selectedIndex = 1;
			} else if( srcValue == "question" ) {

				document.getElementById( 'healthcareProviderSearching' ).selectedIndex = 2;
			} else if( srcValue == "feedback" ) {

				document.getElementById( 'healthcareProviderSearching' ).selectedIndex = 3;
			} else if( srcValue == "stayinformed" ) {

				document.getElementById( 'healthcareProviderSearching' ).selectedIndex = 4;
			} else if( srcValue == "3000iu" ) {

				document.getElementById( 'healthcareProviderSearching' ).selectedIndex = 5;
			}

		}

		if( groupValue == "" ) {

			whatAmISearchingChange( "" );
		} else if( groupValue == "patients" ) {

			whatAmISearchingChange( document.getElementById( 'patientSearching' ).value );
		} else if( groupValue == "parentsandcaregivers" ) {

			whatAmISearchingChange( document.getElementById( 'parentOrCaregiverSearching' ).value );
		} else if( groupValue == "healthcareproviders" ) {

			whatAmISearchingChange( document.getElementById( 'healthcareProviderSearching' ).value );
		}

	}

}

function whatAmISelectionChange( selectItemValue ) {

	//reset Subquestions

	var classItems = getElementsByClass( "patientSet" );
	//Hide base form elements

	hideBaseForm();
	for( var i = 0; i < classItems.length; i++ ) {

		classItems[ i ].style.display = "none";
	}

	var classItems = getElementsByClass( "parentOrCaregiverSet" );
	for( var i = 0; i < classItems.length; i++ ) {

		classItems[ i ].style.display = "none";
	}

	var classItems = getElementsByClass( "healthcareProviderSet" );
	for( var i = 0; i < classItems.length; i++ ) {

		classItems[ i ].style.display = "none";
	}

	document.getElementById( 'patientSearching' ).selectedIndex = 0;
	document.getElementById( 'parentOrCaregiverSearching' ).selectedIndex = 0;
	document.getElementById( 'healthcareProviderSearching' ).selectedIndex = 0;
	whatAmISearchingChange( "" );
	document.getElementById( 'institution' ).className = "";
	//Display related

	if( selectItemValue == "patient" ) {

		classItems = getElementsByClass( "patientSet" );
		for( var i = 0; i < classItems.length; i++ ) {

			classItems[ i ].style.display = "block";
		}

	} else if( selectItemValue == "parent or caregiver" ) {

		classItems = getElementsByClass( "parentOrCaregiverSet" );
		for( var i = 0; i < classItems.length; i++ ) {

			classItems[ i ].style.display = "block";
		}

	} else if( selectItemValue == "healthcare provider" ) {

		classItems = getElementsByClass( "healthcareProviderSet" );
		for( var i = 0; i < classItems.length; i++ ) {

			classItems[ i ].style.display = "block";
		}

		document.getElementById( 'institution' ).className = "reqField";
	}

}

function whatAmISearchingChange( selectItemValue ) {

	clearLowerCheckboxes();
	var classItems = getElementsByClass( "hematologyAccountExecutiveSet" );
	for( var i = 0; i < classItems.length; i++ ) {

		classItems[ i ].style.display = "none";
	}

	var classItems = getElementsByClass( "questionFeedbackSet" );
	for( var i = 0; i < classItems.length; i++ ) {

		classItems[ i ].style.display = "none";
	}

	document.getElementById( 'questionComment' ).className = "";
	document.getElementById( 'contactrequest' ).className = "";
	document.getElementById( 'postalCode' ).className = "";
	document.getElementById( 'postalCodeLabel' ).innerHTML = "Postal Code:";
	document.getElementById( 'phone1' ).className = "";
	document.getElementById( 'phone2' ).className = "";
	document.getElementById( 'phone3' ).className = "";
	document.getElementById( 'phone1Label' ).innerHTML = "Phone:";
	if( selectItemValue == "hematology account executive" ) {

			classItems = getElementsByClass( "hematologyAccountExecutiveSet" );
			for( var i = 0; i < classItems.length; i++ ) {

				classItems[ i ].style.display = "block";
			}

		//Check the request contact box and require the field

		contactrequest = document.getElementById( 'contactrequest' );
		contactrequest.checked = true;
		contactrequest.className = "reqField";
		postalCode = document.getElementById( 'postalCode' );
		postalCode.className = "reqField";
		document.getElementById( 'postalCodeLabel' ).innerHTML = "<em>*</em>Postal Code:";
		document.getElementById( 'phone1' ).className = "reqField";
		document.getElementById( 'phone2' ).className = "reqField";
		document.getElementById( 'phone3' ).className = "reqField";
		document.getElementById( 'phone1Label' ).innerHTML = "<em>*</em>Phone:";
		//Show base form

		showBaseForm();
	} else if( selectItemValue == "question" ) {

		document.getElementById( 'questionComment' ).className = "reqField";
		classItems = getElementsByClass( "questionFeedbackSet" );
		for( var i = 0; i < classItems.length; i++ ) {

			classItems[ i ].style.display = "block";
		}

		//Show base form

		showBaseForm();
	} else if( selectItemValue == "feedback" ) {

		document.getElementById( 'questionComment' ).className = "reqField";
		classItems = getElementsByClass( "questionFeedbackSet" );
		for( var i = 0; i < classItems.length; i++ ) {

			classItems[ i ].style.display = "block";
		}

		//Show base form

		showBaseForm();
	} else if( selectItemValue == "stay informed" ||  selectItemValue == "3000iu") {

		classItems = getElementsByClass( "stayInformed" );
		for( var i = 0; i < classItems.length; i++ ) {

			classItems[ i ].style.display = "block";
		}

		keepInformed = document.getElementById( 'keepinformed' );
		contactRequest = document.getElementById( 'contactrequest' );
		keepInformed.checked = true;
		contactRequest.checked = true;
		//Show base form

		showBaseForm();
	}

}

function getElementsByClass( className ) {

	var all = document.all ? document.all : document.getElementsByTagName('*');
	var elements = new Array();
	for( var e = 0; e < all.length; e++ ) {

		if( all[e].className.search( className ) != -1 ) {

			elements[elements.length] = all[e];
		}

	}

	return elements;
}

function showBaseForm() {

	var baseForm = document.getElementsByClassName("baseForm");
	for (i = 0; i < baseForm.length; i++)

		baseForm[i].style.display = "block";
}

function hideBaseForm() {

	var baseForm = document.getElementsByClassName("baseForm");
	for (i = 0; i < baseForm.length; i++)

		baseForm[i].style.display = "none";
}

function hidePatientSet() {

	var set = document.getElementsByClassName("patientSet");
	for (i = 0; i < set.length; i++)

		set[i].style.display = "none";
}

function hideHealthcareProviderSet() {

	var set = document.getElementsByClassName("healthcareProviderSet");
	for (i = 0; i < set.length; i++) {

		set[i].style.display = "none";
		set[i].style.backgroundColor = "transparent";
	}

}

function clearLowerCheckboxes() {
	var keepInformed = document.getElementById( 'keepinformed' );
	keepInformed.checked = false;
	var contactrequest = document.getElementById( 'contactrequest' );
	contactrequest.checked = false;
}

function checkPreValidation() {

	var error="";
        // if no "I am a", return error

        if( document.getElementById( 'whatAmI' ).selectedIndex == 0 ) {

              error = "Please select a value in 'I am a' before continuing.\n";
        }

        else { // has "I am a", so make sure has "I am looking to"

            if( document.getElementById( 'patientSearching' ).selectedIndex == 0 &&

                document.getElementById( 'parentOrCaregiverSearching' ).selectedIndex == 0 &&

                document.getElementById( 'healthcareProviderSearching' ).selectedIndex == 0 ) {

              error = "Please select a value in 'I am looking to' before continuing.\n";
            }

        }

        if(error != "") {

              alert(error);
              return false;
        }

        return(validateRequired()); // otherwise check standard items

}

function getwhatAmISearching()

{
        var whatamIsearching;
        switch( document.getElementById( 'whatAmI' ).value ) {

            case 'patient':
                whatamIsearching = document.getElementById( 'patientSearching' ).value;
                break;
            case 'parent or caregiver':
                whatamIsearching = document.getElementById( 'parentOrCaregiverSearching' ).value;
                break;
            case 'healthcare provider':
                whatamIsearching = document.getElementById( 'healthcareProviderSearching' ).value;
                break;
        }
        return(whatamIsearching);
}