function setup(){
	var yes = document.getElementById("pi-yes");
	var no = document.getElementById("pi-no");
  
	var share_yes = document.getElementById("share_yes");
	
	// Elements exist?
	if(yes == undefined || no == undefined) return;
	if(share_yes == undefined) return;

	yes.onclick = function(){ turnOffDetails() };
	no.onclick = function(){ turnOnDetails() };

  share_yes.onclick = function(){ setHiddenValue('m_field_id_11') };

	// Ensure details are turned off if the yes box is checked (captures page refresh)
	if(yes.checked) turnOffDetails();
	if(share_yes.checked) setHiddenValue('Yes','m_field_id_11');
}

function setHiddenValue($hidden_box){
	var box = document.getElementById($hidden_box);
	if(box.value == 'No') box.value = 'Yes'
	else box.value = 'No';
	return;
}

function turnOffDetails(){
	document.getElementById("details").style.display = "none";

	// Get role select
	var roles = document.getElementById("type");

	// Build role
	var pi = document.createElement('option');
	pi.text = "Private Investor";
   	pi.value = "Private Investor";

	// Add option
	try{
		roles.add(pi, null);
	}
	catch(ex){
		roles.add(pi);
	}

	// select it
	roles.selectedIndex = roles.options.length - 1;

//document.getElementById("m_field_id_12").value = "n/a";

}

function turnOnDetails(){
	// Get role select
	var roles = document.getElementById("type");
	if(roles.options.length > 11) roles.remove(roles.options.length - 1);

	document.getElementById("details").style.display = "block";

//document.getElementById("m_field_id_12").value = "";
}

function checkCompany(companyName, location){
	var yes = document.getElementById("pi-yes");
	if(yes.checked) return true;
	else return (validateString(companyName, 'Company', 'Please enter your company', 1, 30) && validateString(location, 'Location', 'Please enter your location', 1, 30));
}

function checkSelected(element, msg){
	var yes = document.getElementById("pi-yes");
	if(yes.checked) return true;

	if(element.value == ''){
		alert(msg);
		return false;
	}
        else return true;
}

window.onload = setup;

