/*
Simply4Doctors UK additional JS functions

*/
//define the message for the exit ramp
exitMessage='You are about to leave the simply4doctors website.\n We have no control over third party owned websites and we do not therefore endorse, sponsor, recommend or accept any responsibility for third party websites, their content or availability.';


//used to replicate some visual elements on migrated oncology site registration pages
function replicateRegistration(){
	//adds markup into registration form to organise checkboxes into lists 
	//so that they can be styled
	//should eventually be replaced by the ability to configure this in Morello

	var registration_page=document.getElementById('registration1');
	if(registration_page){
		labels=document.getElementsByTagName('label');
		labelsCount=labels.length;
		if(labelsCount>0){
			for(var i=0;i<labelsCount;i++){
				if(labels[i].innerHTML.indexOf('news from England')>-1){
						var h3=document.createElement('h3');
						var h3Content=document.createTextNode('Simply4doctors regional weekly newsletters');
						h3.appendChild(h3Content);
						labels[i].parentNode.insertBefore(h3,labels[i]);
				}
				
				if(labels[i].innerHTML.indexOf('international healthcare news')>-1){
					var h3=document.createElement('h3');
					var h3Content=document.createTextNode('Simply4doctors international newsletter');
					h3.appendChild(h3Content);
					labels[i].parentNode.insertBefore(h3,labels[i]);
				}
				
				if(labels[i].innerHTML.indexOf('I would also')>-1){
					var h3=document.createElement('h3');
					var h3Content=document.createTextNode('AstraZeneca HCP email service');
					h3.appendChild(h3Content);
					labels[i].parentNode.insertBefore(h3,labels[i]);
				}
			}			
		}
	}	
}

// ensure exit ramp is added to any events which link to urls which start http://
function addExitRampToEvents()
{
	if (document.links == null
		|| document.links.length == 0)
	{
		// document hasn't loaded fully yet so just exit.
		return;
	}
	document.onmousemove = null;
	document.onkeydown = null;

	var eventDiv = document.getElementById("events");
	if (eventDiv)
	{
		var contentDiv = document.getElementById("contentholder");
		if (contentDiv)
		{
			var links = contentDiv.getElementsByTagName('A');
			for (var i = 0; i < links.length; i++)
			{
				href=links[i].href;
				if (links[i].href.length >= 4 && links[i].href.substring(0,4) == 'http')
				{
					links[i].onclick=function(){return showExitWarning(href)};
				}
			}
			
		}
	}
}

//Temporary function specific to http://www.simply4doctors.co.uk/meeting-zone/register
function onMeetingFormSubmit () {
	//If there is no feedback form on this page it means form has been submitted
	if (document.getElementById('itemid4934122')&& !document.getElementById('frm_feedback')) {
	// Redirect to different page once form submitted
		location.href="http://www.simply4doctors.co.uk/meeting-zone/instructions/";
	}
}


//Redirect the regional news to the correct page

function fnSwitchpage(the_form){
 	//Get the selected link URL from the dropdown
  	var link_chosen;
  	link_chosen=the_form.selection.options[the_form.selection.selectedIndex].value;	
 	//Redirect to this URL
 	window.location=link_chosen;
 	return false;
}

function switchPageSelect()
{
	//Put the Redirect forms into an array
	var form_id=new Array;
	if (document.getElementById('frm_news')) {
	form_id[0]=document.getElementById('frm_news');
	}
	if (form_id.length > 0) {
	 	for (var i = 0; i < form_id.length; i++) { 
			form_id[i].onsubmit = function () {
			// On submit tell fnSwitchpage function which form to use
				return fnSwitchpage(this); 
			}
		}
	}
}

var toCall=new Array;	
toCall[0]=onMeetingFormSubmit;
toCall[1]=replicateRegistration;
toCall[2]=addExitRampToEvents;
toCall[3]=switchPageSelect;