
// MouseOver Script
function SwapImage(name,over)
	{
	var id = name.id;

	if(id=="HelpImage")
		{
		if(over)
			window.document.images[id].src = "/images/help_mouse_on.gif";
		else
			window.document.images[id].src = "/images/help_mouse_off.gif";
	}
	if(id=="HelpImageSmall")
		{
		if(over)
			window.document.images[id].src = "/images/help_mouse_on_s.gif";
		else
			window.document.images[id].src = "/images/help_mouse_off_s.gif";
	}	
	if(id=="NavAbout")
		{
		if(over)
			window.document.images[id].src = "/images/top_nav_home_mo.gif";
		else
			window.document.images[id].src = "/images/top_nav_home.gif";
	}
	if(id=="NavFAQ")
		{
		if(over)
			window.document.images[id].src = "/images/top_nav_faq_mo.gif";
		else
			window.document.images[id].src = "/images/top_nav_faq.gif";
	}	
	if(id=="scheme_info")
		{
		if(over)
			window.document.images[id].src = "/images/scheme_info_tab_mo.gif";
		else
			window.document.images[id].src = "/images/scheme_info_tab.gif";
	}
	if(id=="advice_contacts")
		{
		if(over)
			window.document.images[id].src = "/images/advice_contacts_tab_mo.gif";
		else
			window.document.images[id].src = "/images/advice_contacts_tab.gif";
	}
	if(id=="design_statement")
		{
		if(over)
			window.document.images[id].src = "/images/design_statement_tab_mo.gif";
		else
			window.document.images[id].src = "/images/design_statement_tab.gif";
	}
	if(id=="save")
		{
		if(over)
			window.document.images[id].src = "/images/save_finish_tab_mo.gif";
		else
			window.document.images[id].src = "/images/save_finish_tab.gif";
	}	
}

function UpdateDestination(destination)
	{
	document.forms["matrix"].destination2.value=destination;

	if(document.getElementById("OnSubmit").value)
		{

	var OnSubmit=document.getElementById("OnSubmit").value;
		if(checkInputValidity('matrix',OnSubmit))
			{
			document.forms["matrix"].submit();
		}
	}
	else
		{
		document.forms["matrix"].submit();
	}
}

// Global variable used to warn users if they make a change to the Scheme Information
var edit;

// Check submission forms - accepts the form name and list of fields seperated by |
function checkInputValidity (theForm,inputfields)
	{
	var errors = new String();
	errors = "";
	var field = new String();
	field= "";

	var field_array=inputfields.split("|");	
	
	var num=0;
	num = parseInt(num);
	
	while (num < field_array.length)
		{	
		var temp=field_array[num];
		
		if(temp=="sTermsAndConditions")
			{
			if(!document.forms[theForm].elements[temp].checked)
				{
	      			errors = errors + "Please read and agree to the terms and conditions\n\n";
	      		}
		}
		else
			{
		
			if(!document.forms[theForm].elements[temp].value)
				{				
				//trim the beginning 's' off before displaying to the user
				field = field_array[num].substr(1);
				if(field=="ScaleOfProposal")
					{
					field="Anticipated Scale";
				}
				if(field=="Email")
					{
					field="Email Address";
				}				
      				errors = errors + "Please provide your "+field+"\n\n";
	      		}
		}
	 	num=num+1;
	}
	
	if (errors != "") {
		alert(errors);
		return false;
	}
	else
		{
		if(edit)
			{
			input_box=confirm("WARNING\n\nYour scheme information has been updated, previous answers to your Design Statement may be lost.\n\nDo you wish to continue?");
			if(input_box==true)
				{
				return true;
			}
			else
				{
				window.location="/wizard/scheme_information.php";
				return false;
			}
		}
		return true;
	}
}


// Displays the admin row
function showLINK(theHelp,Library)
	{
	var temp;
	var id=document.getElementById(Library).id.substring(1);
	var test='';
	var length;
	
	if(document.getElementById(Library))
		{
		var length=document.getElementById(Library).options.length;
	}
	

	if(Library)
		{
		document.getElementById(theHelp+'Input').value='';

		for (i = 0; i < length; i++)
			{
			if (document.getElementById(Library).options[i].selected)
				{
				test=test+id+'='+document.getElementById(Library).options[i].value+'|';
			}
			var strLength=test.length;
			strLength=strLength-1;	
			document.getElementById(theHelp+'Input').value=test.substr(0,strLength);
		}
	}	
	
	if(document.getElementById)
		{
		if(document.getElementById(theHelp).style.display=="block")
			{
			temp="none";
		}
		else
			{
			temp="block";
		}
		document.getElementById(theHelp).style.display=temp;
	}
}


// Popup the design statement window
function pop_window(url,width,height,name)
	{
	var winleft = (screen.width - width) / 2;
	var winUp = ((screen.height - height) / 2)-50;
	var popit = window.open(url,name,'width='+width+',scrollbars=1,menubar=1,height='+height+',top='+winUp+',left='+winleft+'');
}


// Function to show dynamic form elements
function Show(source,target)
	{
	if(document.getElementById("s"+source))
		{
		if(document.getElementById("s"+source).value=="No" | document.getElementById("s"+source).value=="Other" | document.getElementById("s"+source).value=="")
			{
			if(document.getElementById(target+"Row1")) { document.getElementById(target+"Row1").style.display='none'; }
			if(document.getElementById(target+"Row2")) { document.getElementById(target+"Row2").style.display='none'; }
			if(document.getElementById(target+"Row3")) { document.getElementById(target+"Row3").style.display='none'; }
		}
		else
			{
			if(document.getElementById(target+"Row1")) { document.getElementById(target+"Row1").style.display=''; }
			if(document.getElementById(target+"Row2")) { document.getElementById(target+"Row2").style.display=''; }
			if(document.getElementById(target+"Row3")) { document.getElementById(target+"Row3").style.display=''; }
		}
	}
}


// Function to submit the design statement form
function SubmitForm(area)
	{
	document.getElementById("destination").value=area;
	document.matrix.submit();
}


// Warn the user if they are updating a field that is linked in to the matrix
function WarnUser()
	{
	edit=1;
}


// Function to copy text to clipboard (IE Only)
function copy_clip()
	{
	if (window.clipboardData)
 		{
 		text=document.getElementById("DesignStatementView").innerHTML;
 		text=stripHTML(text);
 		window.clipboardData.setData("Text", text);
 		alert("Your Design Statment has been copied into your clipboard.");
 	}
}


// Function to strip HTML tags from a string
function stripHTML(str) {
	str = str.replace(/<SPAN class=heading>/gi, "\n");
	str = str.replace(/<[^>]*>/g, "");
	str = str.replace(/&nbsp;/gi,"\n");
	return str;
}

// DHTML DropDown Menu
startList = function() {
	if (document.all&&document.getElementById) {
		navRoot = document.getElementById("nav");
		
		for (i=0; i<navRoot.childNodes.length; i++) {
			node = navRoot.childNodes[i];
			
			if (node.nodeName=="LI") {
				node.onmouseover=function() {
					this.className+=" over";
				}
				node.onmouseout=function() {
					this.className=this.className.replace(" over", "");
  				}
			}
		}
	}
}

// DHTML DropDown Menu
startListMain = function() {
	if (document.all&&document.getElementById) {
		navRoot = document.getElementById("navMain");
		
		for (i=0; i<navRoot.childNodes.length; i++) {
			node = navRoot.childNodes[i];
			
			if (node.nodeName=="LI") {
				node.onmouseover=function() {
					this.className+=" over";
				}
				node.onmouseout=function() {
					this.className=this.className.replace(" over", "");
  				}
			}
		}
	}
}

// Function to alert user when trying to close the window
function closewindow()
	{
	input_box=confirm("WARNING\n\nYou are about to close down the Design Statement Tool.\n\nIf you press OK then you will lose any unsaved information.");
	if(input_box==true)
		{
		window.close();
	}
	else
		{
		
	}
}


//-->
