var buildVersion 			= "3.06 \nFri 10.27pm";
var maxPostLength 			= 20000;
var maxPostLengthMessage 	= "Sorry, the maximum number of characters is "+ parseInt(( maxPostLength / 1000 )) +",000.\nPlease edit the text you have entered to be below this limit.";
var mouseOutDelay			= 300;

window.mom = (window.mom || {features:{},roles:{},variants:{},previous:{}} );
function validateForm(name) {
	var flag = true;
	var el;
	for(var i = 1; i<arguments.length; i++) {
		el = document[name][arguments[i]];
		if(el.type=="text" || el.type=="textarea") {
			flag = flag && checkText(el);
			if (el.value.length > maxPostLength)
			{
				alert(maxPostLengthMessage);
				return;
			}
		}
		else if (el.type=="select-one") {
			flag = flag && checkSelect(el);
		}
 	}
	function checkText(el){
		return (el.value=="") ? false : true;
	}
	function checkSelect(el){
		return (el.selectedIndex) ? true : false;
	}
	if(flag) {
		if (name == "createThreadForm")
		{
			flag = checkLocalView();
		}
		if (flag)
		document[name].submit();
	}
	else {
		alert("Please fill in all form fields before submitting.");
	}
}
function checkLocalView()// feedback form (feedback.html) check to see if your in your local view
{
	var t = true;
	if (!document.switchVariantForm){return t;}
	var s = document.switchVariantForm.variant.selectedIndex;
	if (s)
	{
		t = confirm("WARNING: You are not in your Local view. \nTo see any responses to this feedback your will need to return to this view.\n\nAre you sure you want to continue?")
	}
	return t;
}
function formNameVisibility(args,visibility) {
	for(var i = 0; i<args.length; i++) {
		var o = document.getElementById(args[i]);
		if(o) {
			if(visibility) {
				o.style.visibility = "visible";
			}
			else {
				o.style.visibility = "hidden";
			}
		}
	}
}
function clearInputField(obj,form,reset) {
	if (!obj.originalValue){obj.originalValue = obj.value}
	if (reset)
	{
		obj.value = obj.originalValue;
	} 
	else if (obj.originalValue == obj.value && (obj.value.indexOf("Please write your")==0 || obj.value.indexOf("Click in this box")==0) )
	{
		obj.value = "";
		obj.setAttribute("cleared","yes")
	}
}
function preload(imgObj,imgSrc) {
	if (document.images) {
		eval('var '+imgObj+' = new Image()');
		eval(imgObj+'.src = "'+imgSrc+'"');
	}
}
function changeImage(imgName,imgObj) {
	document.images[imgName].src = eval(imgObj+".src");
}
preload('img_feedback','../i/header/bttn_feedback_1.gif');
preload('img_home','../i/header/bttn_return_home_1.gif');
preload('img_navigation','../i/header/bttn_navigation_open_1.gif');
preload('img_print','../i/header/bttn_print_1.gif');
preload('img_referral','../i/header/bttn_referral_1.gif');
function toggleImage(o,tristate) {
	if (o.tagName != "IMG"){o = o.getElementsByTagName("IMG")[0]}
	ceToggled = o;
	if(tristate) {
		if(o.src.indexOf("_def") != -1) {
			o.src = o.src.replace(/_def/g,"_off");
		}
		else if(o.src.indexOf("_off") != -1) {
			o.src = o.src.replace(/_off/g,"_def");
		}
	}
	else {
		if(o.src.indexOf("_off") != -1) {
			o.src = o.src.replace(/_off/g,"_on");
			if (!o.originalAlt){o.originalAlt = o.alt}
			o.alt = "Click to close";
		}
		else if(o.src.indexOf("_on") != -1) {
			o.src = o.src.replace(/_on/g,"_off");
			if (o.originalAlt){o.alt = o.originalAlt}		
		}
	}
}
var ceToggled = null;
function resetImage(o) {
	if(o.src.indexOf("_on") != -1) {
		o.src = o.src.replace(/_on/g,"_def");
	}
	if(o.src.indexOf("_off") != -1) {
		o.src = o.src.replace(/_off/g,"_def");
	}
}
function cancelBubbling(e) {
	if(!e) {
		e = window.event;
	}
 	if(window.event) {
   e.cancelBubble = true
  } 
  else {
   e.cancelBubble = true;
   e.preventDefault();
   e.stopPropagation()
  }
}
function addEvent(o,name,f) {
	if(window.event) {
		o.attachEvent(name, f);
	}
	else {
		o.addEventListener(name.substr(2,name.length), f, false);
	}
}
function getEventElement(e) {
	var o = null;
	if(!e) {
		e = window.event;
	}
	if(e.target) {
		o = e.target;
	}
	else if (e.srcElement) {
		o = e.srcElement;
		if (o.nodeType == 3) {
			o = o.parentNode;
		}
	}
	return o;
}
function openWindow(url, name, info) {
	if(url) {
		window.open(url, name, info);
	}
	else {
		window.open("", "", "");
	}
}
function popup(url,type){
	var str,name;
	if (!url){
		var currId = window.currId || 0 ;
		gbl_sendError('error in popup(url:'+ typeof(url) +' type:'+ type +') nodeId:'+ currId );
		return ;
	}
	switch(type) 
	{
		case "search" :
			str="";
			name = "searchWin";			
			window.searchWin = window.open(url,name,str);
			window.searchWin.focus();
			break ;			
		case "movie" :
			str="width=800,height=600";
			name = "movieWin";			
			window.movieWin = window.open(url,name,str);
			window.movieWin.focus();
			break ;			
		case "help" :
			str="width=800,height=600,resizable=1";
			name = "helpWin";			
			window.helpWin = window.open(url,name,str);
			window.helpWin.focus();
			break ;			
		case "print" :
			if (!window.printWin) {window.printWin = new Array;}
			var offset = (10 * window.printWin.length) + 10;// move new win down 10px each time
			str="width=776,height=558,status=yes,toolbar=no,left="+ offset +",top="+ offset +",scrollbars=1,resizable=1";
			window.printWin[window.printWin.length] = window.open(url,"printWin_"+ window.printWin.length,str);
			break ;
		case "printWithNav" :
			if (!window.printWin) {window.printWin = new Array;}
			var offset = (10 * window.printWin.length) + 10;// move new win down 10px each time
			str="width=776,height=558,status=yes,toolbar=yes,left="+ offset +",top="+ offset +",scrollbars=yes,resizable=yes,location=yes, menubar=yes";
			window.printWin[window.printWin.length] = window.open(url,"printWin_"+ window.printWin.length,str);
			break ;			
		case "referral" :
			str="width=710,height=550,status=yes,toolbar=no,left=20,top=20,scrollbars=1,resizable=1";
			name = "referralWin";			
			window.referralWin = window.open(url,name,str);
			window.referralWin.focus();
			break ;		
		case "asset" :
			if (!window.assetWin) {window.assetWin = new Array;}
			var offset = (10 * window.assetWin.length) + 10;// move new win down 10px each time
			str="width=776,height=558,status=yes,toolbar=no,left="+ offset +",top="+ offset +",scrollbars=1,resizable=1";
			window.assetWin[window.assetWin.length] = window.open(url,"assetWin_"+ window.assetWin.length,str);
			break ;	
		case "pathway_ref" :
			str="width=800,height=600,status=yes,toolbar=yes,location=yes,menubar=yes,left=20,top=20,scrollbars=1,resizable=1";
			name = "pathwayrefWin";			
			window.pathwayrefWin = window.open(url,name,str);
			window.pathwayrefWin.focus();
			break ;	
		case "pathway_info" :
			str="width=528,height=540,status=yes,toolbar=no,location=no,left=20,top=20,scrollbars=1,resizable=1";
			name = "pathwayinfoWin";			
			window.pathwayinfoWin = window.open(url,name,str);
			window.pathwayinfoWin.focus();
			break ;		
		case "new" :
			str="";
			name = "";			
			window.open(url,name,str);
			break ;		
		default : 
			if (url)
			{
				str="";
				name="";
				var newWin = window.open(url,name,str);
				newWin.focus();				
			}
	}		
}
function moveFooter(contentId) {
}
function moveSideLines(contentId) {
}
function moveElements(contentId){
 moveSideLines(contentId);
 moveFooter(contentId);
}
function closeIframe()
{
	if (!document.getElementById("referralNodeDiv")){return;}
	var referralNodeDiv = document.getElementById("referralNodeDiv");
	referralNodeDiv.style.display = "none";
}
function saveIframe(url)
{
	var referralNodeDiv = document.getElementById("referralNodeDiv");
	referralNodeDiv.style.display = "none";
	location.href = url;
}
function Button()
{
	this.init 		= Init; 
	this.initBttn	= InitBttn;
	this.on			= On;	
	this.reset		= Reset;
	this.hit		= Hit;	

	function Init(el)
	{
		if (!document.getElementById){return;};
		if (!el.getElementsByTagName("INPUT")){return;};
		var bttn = el.getElementsByTagName("INPUT")[0];
	
		el.onmousedown 		= this.on;
		el.onmouseup 		= this.reset;
		el.onmouseout		= this.reset;
		el.originalClass	= el.className; 		
		el.hotClass			= el.className.replace(/Up/g,"Down"); 		
		el.onmouseover		= null;					
		
	
		bttn.onmouseover 	= this.on;
		bttn.onfocus		= this.on;				
		bttn.onmouseout 	= this.reset;
		bttn.onblur			= this.reset;			
		if (document.all)	{bttn.onfocus = this.hit};
		bttn.originalClass	=bttn.className;		
		bttn.hotClass		=bttn.className+"Hover";  
		bttn.onmouseover();
	}
	function InitBttn(el)
	{
		if (!document.getElementById){return;};
		el.onfocus	=	null;
		this.init(el.parentNode);
	}
	function On() 	{this.className=this.hotClass;};
	function Reset(){this.className=this.originalClass;};
	function Hit() 	{this.blur()};
}
var button = new Button;
function FunkyButton()
{
	this.init 			= Init; 
	this.currentActive	= null;	
	this.div			= new Div
	this.div.elements	= new Array
	this.elements		= new Array
	this.on				= On;	
	this.reset			= Reset;
	this.setOff			= SetOff;
	this.setOn			= SetOn;
	this.toggle			= Toggle

	function Init(el)
	{
		if (!document.getElementById){return;};
		if (!this.elements.length){
			var els = el.parentNode.getElementsByTagName("A");
			for (var i=0;i<els.length;i++){
				if (els[i].getElementsByTagName("IMG"))
				els[i].img = els[i].getElementsByTagName("IMG")[0];
				this.elements[this.elements.length] = els[i];
			}
		}
	
		var re = new RegExp("_0.gif");
		for (i=0;i<this.elements.length;i++){
			this.elements[i].onmouseover = this.elements[i].on = this.elements[i].onfocus = this.on;
			this.elements[i].onmouseout = this.elements[i].onblur = this.reset;
			this.elements[i].setOff							= this.setOff;
			this.elements[i].setOn		 					= this.setOn;
			this.elements[i].img.originalSrc				= this.elements[i].img.src; 													
			this.elements[i].img.hotSrc						= this.elements[i].img.src.replace(/_0.gif/g,"_2.gif").replace(/_1.gif/g,"_2.gif");
			if (re.exec(this.elements[i].img.src)) {
				this.elements[i].active	= true;
			} else {
				this.elements[i].active	= false;// no mouse over 
				this.currentActive 		= this.elements[i];
			}
		}
		el.on();
	}
	function Div(){
		this.close = Close;
		this.setActive	= SetActive;
		function Close()
		{
			this.elements = new Array("Browser","History");
			for(var i=0;i<this.elements.length;i++){
				document.getElementById("div"+this.elements[i]).className="hidden";
			}
		}
		function SetActive(divId)
		{
			this.close();
			if (document.getElementById("div"+divId)) {
				document.getElementById("div"+divId).className="show";
			} else {
			
			}
		}
	}
	function On() 	{if(this.active){this.img.src=this.img.hotSrc;}};
	function Reset(){this.img.src=this.img.originalSrc;this.img.active=true;this.blur()};
	function SetOff(){this.img.src=this.img.originalSrc=this.img.src.replace(/_1.gif/g,"_0.gif").replace(/_2.gif/g,"_0.gif");}
	function SetOn(){this.img.src=this.img.originalSrc=this.img.src.replace(/_2.gif/g,"_1.gif").replace(/_0.gif/g,"_1.gif");}
	function Toggle(el,divId)
	{
		for (var i=0;i<this.elements.length;i++){
			this.elements[i].setOff();
		}
		if (this.currentActive){
			this.currentActive.active = true;
		}
		this.currentActive = el;
		el.setOn();
		el.active=false;
		this.div.setActive(divId);
	}
}
var funkyButton = new FunkyButton;	
function UpdateDisplay() 
{
	this.init 				= Init; 		
	this.out				= Reset;		
	this.on					= On;			
	this.clearDefaultText 	= ClearDefaultText 
	
	function Init(el)
	{
		el.onblur 		= this.out;
		el.defaultClass	= el.className;
		el.defaultText	= el.value;
		el.onfocus = el.on = this.on;
		el.on();
	}
	function On()
	{
		this.returnValue 	= updateDisplay.clearDefaultText(this);
		this.className 		= this.className.replace(/disabled/g,"");
	}
	function Reset()// reset if value not changed
	{
		if (!this.value){ 
			this.value 		= this.defaultValue
			this.className 	= this.defaultClass;
		};
	}
	function ClearDefaultText(el)
	{
		if (!el.defaultText && el.value){el.value = ""};
		if (el.defaultText && el.value == el.defaultText){el.value = ""};
		return true;
	}
}
var updateDisplay = new UpdateDisplay;
var gbl_text_switchvariant = "WARNING: You are about to change view.\nAre you sure you want to continue?";
function variantConfirm(previous) {
	var selObj = document.switchVariantForm.variant;
	if (selObj[selObj.selectedIndex].value==0){resetOptions(previous);return;}
	if (selObj[selObj.selectedIndex].value==previous){return;}
	if (!confirm(gbl_text_switchvariant)) {resetOptions(previous);return;}
	var toVariant = selObj[selObj.selectedIndex].value;
	var previousURI = location.href;
	var previousParam = location.search;
	document.location.href="switchVariant.action?toVariant=" + selObj[selObj.selectedIndex].value + "&previousURL=" + escape(location.href);
	function resetOptions(previous){
		for(var i=0; i<selObj.length; i++) {
			selObj[i].selected = false;
			if(selObj[i].value == previous) {
				selObj[i].selected = true;
			}
		}	
	}
}
function switchVariant(id) {
	if (id && confirm(gbl_text_switchvariant)){
		location.href = "switchVariant.action?toVariant=" + id + "&previousURL=" + escape(location.href) + "&previousParam=" + escape(location.search);
	}
}
function checkContentStatus(obj)
{	
	if (!obj.src) {return;}
	var pageOk = true;
	if (!obj.contentWindow && obj.contentDocument){obj.contentWindow = obj.contentDocument};


 	if ( obj.src.toString().toLowerCase().indexOf("ssb-harness") != -1 )
	{
		pageOk = false;
	}
	if (obj.contentWindow && pageOk){
		try { 
			if (obj.contentWindow.document.title) {
				var title = obj.contentWindow.document.title;
				if (title.toLowerCase().indexOf("session") != -1) {pageOk = false} 
				if (title.toLowerCase().indexOf("error") != -1) {window.ifameError = title;} 
			} 
		} catch(e){pageOk = false;}
	}
	if (!pageOk)
	{
		if (obj.errorMessage){
			alert(obj.errorMessage);
		} else {
			window.location.reload();
		}
	}
}
function iframeSetHeight(iframe){
	if (window.frames[iframe.id].setHeight){
		window.frames[iframe.id].setHeight();
	}
}
function get_random(top)
{
	var n = (top) ? top : 10000000 ;
    var ranNum = Math.round(Math.random()*n);
    return ranNum;
}
 function ImageRolloverBehavior()
 {
 	this.over 	= Over;	
 	this.out 	= Out; 	
 	this.init	= Init;	

	function Init(el)
	{
		if (!document.getElementById){return}
		var imageOffExtention 	= "_0.";
		var imageOverExtention 	= "_1.";
		if (el.tagName != "IMG" && el.tagName != "INPUT")
		{
			try{
				el = el.getElementsByTagName("IMG")[0];
			} catch(e){
				return;
			}
		}// normalize if roll event is on parent element
		if (el && el.src)// if everything is ok
		{
			if (el.isset == null)
			{
				el.isset 		= true;
				el.offSrc 		= el.src;
				el.overSrc 		= el.src.replace(imageOffExtention,imageOverExtention);
			
				el.onmouseover 	= this.over;
				el.on			= this.over;
				el.onfocus		= this.over;
			
				el.off			= this.out;		
				el.onmouseout 	= this.out;
				el.onblur		= this.out;
				el.on();
			}
		}
	}
	function Over()
	{
		if (this.overSrc){this.src = this.overSrc;}
	}
	function Out()
	{
		if (this.offSrc){this.src = this.offSrc;}
	}
 }
 var roll = new ImageRolloverBehavior;
function addgrid(imgsrc)
{
	var width = 940;
	var img = document.createElement("IMG");
	img.style.position 	= "absolute";
	img.style.top 		= "-70px";
	img.style.left 		= "50%";
	img.style.marginLeft= "-"+(width/2)+"px";
	img.style.zIndex	= "10000000";
	img.style.display	= "none";
	img.id				= "imgGrid";
	img.src				= imgsrc;
	img.title			= "Doubleclick to close";
	img.ondblclick		= hidegrid;
	img.active			= true;
	document.getElementsByTagName("BODY")[0].appendChild(img);
	img = null;
	document.ondblclick = showgrid;
	function showgrid()// use parameter 
	{
		 if (!document.getElementById('imgGrid').active) 
		 {
			 document.getElementById('imgGrid').active = true;
		 }
		 else
		 {
			 document.getElementById('imgGrid').style.display='block';
		 }
	}		
	function hidegrid()
	{
		 document.getElementById('imgGrid').style.display='none';
		 document.getElementById('imgGrid').active = false;
	}			
}
function showByID(id) {
	document.getElementById(id).style.display='inline';
}
function hideByID(id) {
	document.getElementById(id).style.display='none';
}
function getStaticReferralLetter(id)//id=string ids e.g. 09870987;098987;098987
{
	var ids = id.split(";")
	if (ids.length<3){return;}
	var specialtyId 	= ids[0];
	var subSpecialtyId	= ids[1];
	var pathwayId	= ids[2];
	var referralFormUrl = "generic.html";
	switch(specialtyId)
	{
		case "484125" :
			referralFormUrl = "generic_a_and_e.html"
		break ;
		case "783109934" :
			switch(subSpecialtyId)
			{
				case "36420425" :
					referralFormUrl = "medicine_cardiology.html"
				break;
				case "1928291" :
					referralFormUrl = "medicine_dermatology.html"
				break;
				case "1588644092" :
					referralFormUrl = "medicine_endocrinology.html"
				break;
				case "83974555" :
					referralFormUrl = "medicine_gastroenterology.html"
				break;
				case "3677117" :
					referralFormUrl = "medicine_haem.html"
				break;
				case "3754550" :
					referralFormUrl = "medicine_hepatology.html"
				break;
				case "784652388" :
					referralFormUrl = "medicine_infectious.html"
				break;
				case "1585786810" :
					referralFormUrl = "medicine_metabolic.html"
				break;
				case "168911251" :
					referralFormUrl = "medicine_nephrology.html"
				break;
				case "6500223" :
					referralFormUrl = "medicine_neurology.html"
				break;
				case "85238605" :
					referralFormUrl = "medicine_thoracic.html"
				break;
				default :
					referralFormUrl = "generic.html";				
			}	
		break ;
		case "290642512" :
			switch(pathwayId)
			{	
				case "3000162" :
					referralFormUrl = "oncology_breastcancer.html";
				break ;
				default : referralFormUrl = "oncology.html"; 
			}
		break ;
		case "179482206" :
			referralFormUrl = "obstetrics_gynaecology.html";
		break ;
		default :
			referralFormUrl = "generic.html";
	}
	popup("../html/referral_forms/"+referralFormUrl,"referral");
}
	function gbl_sendError(url)
	{
		if (mom.features['feature_development_build']){
			if (window.console) {
				console.log(url);
			} else if (window.opera) {
				opera.postError(url);
			} else {
				alert(url);
			}
			return;
		}
		url = "logJavaScriptError.action?logMessage=" + url;
		if (window.XMLHttpRequest)// code for Mozilla, etc.
		{
			window.xmlhttp=new XMLHttpRequest();
			try {
				xmlhttp.open("GET",url,true);
				xmlhttp.send(null);
			} catch(e){}
		}
		else if (window.ActiveXObject)// ie vesion
		{
			window.xmlhttp=new ActiveXObject("Microsoft.XMLHTTP")
			if (xmlhttp)
			{
				try {
					xmlhttp.open("GET",url,true);
					xmlhttp.send();
				} catch(e){}
			}
		}
	}	
function Counter()
{
	this.incr 			= Increment;
	this.write 			= Write;
	this.reset 			= Reset;
	this.add 			= Add;
	this.total			= 0.0;
	this.grandTotal 	= 0.0;
	this.wirteGrandTotal= WirteGrandTotal;
	function Add(n)
	{
		if (n) {
			this.total+= parseFloat(n);
			this.grandTotal+= parseFloat(n);
		}
	}
	function Increment(n)
	{
		document.write(n);
		this.add(n);
	}
	function Write(reset,exact)
	{
		if (exact){
			document.write(this.total)
		} else {
			document.write( parseInt(this.total * 100) / 100 )
		}
		if (reset){this.reset()}
	}
	function Reset()
	{
		this.total = 0.0;
	}
	function WirteGrandTotal()
	{
		document.write( parseInt( this.grandTotal * 100)  / 100  );
	}
}
var counter = new Counter;
function glb_ExtendBrowser(behavoir)
{
	switch (behavoir)
	{
		case "currentStyle" :
			try {
				HTMLElement.prototype.__defineGetter__("currentStyle", function() {return getComputedStyle(this, null);});
			} catch (e) {};
		break ;
		case "attachEvent" :
			try {
				HTMLDocument.prototype.attachEvent 	= AttachEvent;
				HTMLElement.prototype.attachEvent 	= AttachEvent;
				HTMLDocument.prototype.detachEvent 	= DetachEvent;
				HTMLElement.prototype.detachEvent 	= DetachEvent;
			} catch (e) {};
		break ;
	}
	function AttachEvent(name, handler){
		this.addEventListener(name.slice(2), handler, false);
	};
	function DetachEvent(name, handler) {
		this.removeEventListener(name.slice(2), handler, false);
	};	
}
function glb_ShowProperties(obj)
{
	if (!obj) obj = window;
	var temp = new String;
	for (name in obj){
		if (obj[name]!= null) 
		temp+= name +" = "+ obj[name] + "\n";
	}
	alert(temp);
}
function glb_SetTableRow(obj)
{
	obj.onmouseover = function(){this.className='over';}
	obj.onmouseout 	= function(){this.className='';}
	obj.onclick		= function(){if(this.getElementsByTagName("A")[0] && this.getElementsByTagName("A")[0].href.length)location.href=this.getElementsByTagName("A")[0].href}
}
mom.writeToConsol = function(m)
{
	if (mom.features['feature_development_build']) {
		if (window.console) {
			window.console.log(m);
		} else if (window.opera) {
			window.opera.postError(m);
		}		
	}
}
String.prototype.endsWidth = function(str){if(this.indexOf(str)<0){return false}else if(str.length>this.length){return false}else{return(this.substring(this.length-str.length) == str)?true:false;}}	
