//=================================================================================================================================================================
// declarations
//=================================================================================================================================================================

var current_url = location.href;
var path_split;
var hexinput=255; 
var i;
var oDiv; 

	path_split = current_url.split("/");

//=================================================================================================================================================================
// function to check if return has been pressed when the user has entered something in the search box, it then loads the search page with the users search criteria
//=================================================================================================================================================================
function Check_Key_Stroke(sitename)
	{
		var keycode = window.event.keyCode;
		
		if (keycode == 13)
		{
			if (path_split[3].toLowerCase() =="website")
			{
				window.location='/Website/'+sitename+'/search1.asp?SearchView=1&SearchCriteria='+SearchWebsite.value;
			}
			else
			{
			if (sitename==''){
				window.location='http://www.salisbury.nhs.uk/'+sitename+'search1.asp?SearchView=1&SearchCriteria='+SearchWebsite.value;		
			} else {
				window.location='http://www.salisbury.nhs.uk/'+sitename+'/search1.asp?SearchView=1&SearchCriteria='+SearchWebsite.value;
			}
			//	window.location='http://cmsdev-mcr/search1.asp?SearchView=1&SearchCriteria='+SearchWebsite.value;
			}
		}
	}

//=================================================================================================================================================================
// function to load the search page with the users search criteria when the user selects the 'Go' button
//=================================================================================================================================================================
function Load_Search(sitename)
	{
		
		if (path_split[3].toLowerCase() =="website")
		{
			window.location='/Website/'+sitename+'/search1.asp?SearchView=1&SearchCriteria='+SearchWebsite.value;
		}
		else
		{
		//		window.location='http://cmsdev-mcr/search1.asp?SearchView=1&SearchCriteria='+SearchWebsite.value;
			if (sitename==''){
				window.location='http://www.salisbury.nhs.uk/'+sitename+'search1.asp?SearchView=1&SearchCriteria='+SearchWebsite.value;		
			} else {
				window.location='http://www.salisbury.nhs.uk/'+sitename+'/search1.asp?SearchView=1&SearchCriteria='+SearchWebsite.value;
			}
		}
	
	}

//=================================================================================================================================================================
// function to open the accessibilitly options page in a new window with the correct colour of the site depending on which site the user selected it from
//=================================================================================================================================================================
function Load_AccessibilityOptions()
	{
		window.open('/NewIncludes/General/Accessibility_Options.asp','','scrollbars=yes,toolbar=no,location=no,status=yes, width=790, height=540, left=0, top=0');
	}

//=================================================================================================================================================================
// function to open the accessibilitly options page in a new window and go to the access keys section with the correct colour of the site depending on which site the user selected it from
//=================================================================================================================================================================
//function Load_AccessibilityOptionsAccessKeys(sitecolour)
//	{
//		window.open('/NewIncludes/General/Accessibility_Options.asp?sitestyle='+sitecolour+'#AccessKeys','','scrollbars=yes,toolbar=no,location=no,status=yes, width=790, height=540, left=0, top=0');
//	}

//=================================================================================================================================================================
// function to open the hospital map in a fixed sized window with no scrollbars
//=================================================================================================================================================================
function Open_Map(url, type)
	{
		if (type == 'e')
		{
			window.open ( url, '','scrollbars=yes,toolbar=no,location=no,status=yes, width=1024, height=850, left=0, top=0');
		}
		else
		{
			window.open ( url, '','scrollbars=yes,toolbar=no,location=no,status=yes, width=1024, height=850, left=0, top=0');
		}	
		
	}

//=================================================================================================================================================================
// function to open the internal feedback form in a new window
//=================================================================================================================================================================
function Load_FeedbackForm()
	{
		window.open('http://iisint-fin/NewIncludes/Forms/Content_Request_Form.aspx');
	}
	
//=================================================================================================================================================================
// function to open the disclaimer page in a new window with the correct colour of the site depending on which site the user selected it from
//=================================================================================================================================================================
function Load_Disclaimer()
	{
		
		if (path_split[2].toLowerCase() =="iisint-fin")
		{
			window.open('/NewIncludes/General/Disclaimer_Internal.asp','','scrollbars=yes,toolbar=no,location=no,status=yes, width=790, height=540, left=0, top=0');
		}
		else
		{
			if (path_split[3].toLowerCase() =="website")
			{
				window.open('/NewIncludes/General/Disclaimer_Internal.asp','','scrollbars=yes,toolbar=no,location=no,status=yes, width=790, height=540, left=0, top=0');
			}
			else
			{
				window.open('/NewIncludes/General/Disclaimer_External.asp','','scrollbars=yes,toolbar=no,location=no,status=yes, width=790, height=540, left=0, top=0');
			}
		}
	}	

//=================================================================================================================================================================
// function to open the values and beliefs page in a new window with the correct colour of the site depending on which site the user selected it from
//=================================================================================================================================================================
function Load_ValuesBeliefs()
	{
		window.open('/NewIncludes/General/Values_And_Beliefs.asp','','scrollbars=yes,toolbar=no,location=no,status=yes, width=790, height=540, left=0, top=0');
	}

//=================================================================================================================================================================
// function to open the contact us page in a new window
//=================================================================================================================================================================
function Load_ContactUs()
	{
	//	window.open('http://www.salisbury.nhs.uk/Contact/Contact_The_Hospital.aspx');
		window.location ='http://www.salisbury.nhs.uk/Contact/Contact_The_Hospital.aspx';
	}

//=================================================================================================================================================================
// function to open the internal help page in a new window with the right colour
//=================================================================================================================================================================
//function Load_InternalHelp()
//	{
//		window.open('/NewIncludes/General/Internal_Help.asp','','scrollbars=yes,toolbar=no,location=no,status=yes, width=790, height=540, left=0, top=0');
//	}

//=================================================================================================================================================================
// function to open the external help page in a new window with the right colour
//=================================================================================================================================================================
//function Load_ExternalHelp()
//	{
//		window.open('/NewIncludes/General/External_Help.asp','','scrollbars=yes,toolbar=no,location=no,status=no, width=790, height=540, left=0, top=0');
//	}

//=================================================================================================================================================================
// function to decide which help file to open
//=================================================================================================================================================================
function Load_Help( )	
	{
		if (path_split[2].toLowerCase() =="iisint-fin") // for the editing site
		{
			window.open('/NewIncludes/General/Internal_Help.asp','','scrollbars=yes,toolbar=no,location=no,status=yes, width=790, height=540, left=0, top=0');
		}
		else // for the live and staged sites
		{
			if (path_split[3].toLowerCase() =="website")
			{
				window.open('/NewIncludes/General/Internal_Help.asp','','scrollbars=yes,toolbar=no,location=no,status=yes, width=790, height=540, left=0, top=0');
			}
			else
			{
				window.open('/NewIncludes/General/External_Help.asp','','scrollbars=yes,toolbar=no,location=no,status=no, width=790, height=540, left=0, top=0');
			}
		}
	}
	
//=================================================================================================================================================================
// shows and hides the div tags on the splash screen
//=================================================================================================================================================================
function Show_Description (DivID)
	{
		if (DivID.className=="Hide_Div")
		{
			DivID.className="Show_Div";
			hexinput-=11; // increase color value
			document.getElementById(DivID.id).style.color="rgb("+hexinput+","+hexinput+","+hexinput+")"; // Set color value.
			setTimeout("Fade_Text('"+DivID.id+"')",20);
			divFrontPicture.className="Hide_Div";
		}
		else
		{
			DivID.className="Hide_Div";
			divFrontPicture.className="Show_Div";
		}
	}

//=================================================================================================================================================================
// to fade in the text in the div tags on the splash screen
//=================================================================================================================================================================
function Fade_Text(DivID)
	{ 
		if(hexinput>0) 
		{	
			hexinput-=11; // increase color value
			document.getElementById(DivID).style.color="rgb("+hexinput+","+hexinput+","+hexinput+")"; // Set color value.
			setTimeout("Fade_Text('"+DivID+"')",20);
		}
		else
		{
			hexinput=255;  //reset hex value
		}
	}

//=================================================================================================================================================================
// to show and hide the sitemap that has been clicked on
//=================================================================================================================================================================
function Change_Sitemap(CellID)
	{
		for (var i=1; i < 11; i++) 
			{	
				oDiv=document.getElementById('div_' + i)
				oDiv.className="Hide_Sitemap";
			}
		
		CellID.className="Show_Sitemap";
	}	

//=================================================================================================================================================================
// function to display a selected Post from PostIT on the Staff Home Page of the Intranet
//=================================================================================================================================================================	
function ShowPost( PostBodyText, PostSubjectText, HasAttachment, AttachmentPath )
	{
		var AttachmentImage;
		
		ShowSelectedPost.className="ShowSelectedPost";
		PostBody.innerHTML=PostBodyText;
		PostSubject.innerHTML=PostSubjectText;
		
		if (HasAttachment==1)
		{
			if (RightString (AttachmentPath, 4).toLowerCase() ==".pdf")
			{
				AttachmentImage="<img src='/NewIncludes/Images/Small_PDF_Icon.gif'>";
			}
			
			if (RightString (AttachmentPath, 4).toLowerCase() ==".doc")
			{
				AttachmentImage="<img src='/NewIncludes/Images/Small_Word_Icon.gif'>";
			}
			
			if (RightString (AttachmentPath, 4).toLowerCase() ==".rtf")
			{
				AttachmentImage="<img src='/NewIncludes/Images/Small_Word_Icon.gif'>";
			}
			
			if (RightString (AttachmentPath, 4).toLowerCase() ==".xls")
			{
				AttachmentImage="<img src='/NewIncludes/Images/Small_Excel_Icon.gif'>";
			}
			
			if (RightString (AttachmentPath, 4).toLowerCase() ==".pps")
			{
				AttachmentImage="<img src='/NewIncludes/Images/Small_PowerPoint_Icon.gif'>";
			}
			
			if (RightString (AttachmentPath, 4).toLowerCase() ==".pub")
			{
				AttachmentImage="<img src='/NewIncludes/Images/Small_Publisher_Icon.gif'>";
			}
			
			if (RightString (AttachmentPath, 4).toLowerCase() ==".gif")
			{
				AttachmentImage="<img src='/NewIncludes/Images/Small_Image_Icon.gif'>";
			}
			
			if (RightString (AttachmentPath, 4).toLowerCase() ==".jpg")
			{
				AttachmentImage="<img src='/NewIncludes/Images/Small_Image_Icon.gif'>";
			}
			
			PostAttachment.className="ShowSelectedPost";
			PostAttachment.innerHTML="<a class='AttachmentText' href='"+AttachmentPath+"' target='_blank' alt='Click here to open this attachment'>Attachment for this post</a>&nbsp;<a class='AttachmentText' href='"+AttachmentPath+"' target='_blank' alt='Click here to open this attachment'>"+AttachmentImage+"</a>";
		}
		else
		{
			PostAttachment.className="HideSelectedPost";
		}
	}

//=================================================================================================================================================================
// function to display a selected Post from PostIT on the Staff Home Page of the Intranet - revised function - 05-09-2006
//=================================================================================================================================================================	
function ShowPost1( PostBodyText, PostSubjectText, HasAttachment, AttachmentPath , id )
	{
		var AttachmentImage;
		
		var att_array = AttachmentPath.split("~");
		var i = 0;
		var y = 0 ;
		var strAttachment = '';
		var filetype = '';
		var arr_ids = document.getElementById("msgids").value.split ( "~" );

		for (y = 0; y <= 4; y++)
		{
			if ( arr_ids[y] == id ) {
					for (i = 1; i <= 4; i++)
					{
						if ( i==1){
							document.getElementById('td'+i+arr_ids[y]).className = 'Staff_Home_Page_Results_Left_Selected';
						} else
						{
							document.getElementById('td'+i+arr_ids[y]).className = 'Staff_Home_Page_Middle_Selected';
						}
					}				
			} else {
					for (i = 1; i <= 4; i++)
					{
						if ( i==1){
							document.getElementById('td'+i+arr_ids[y]).className = 'Staff_Home_Page_Results_Left';
						} else {
							document.getElementById('td'+i+arr_ids[y]).className = 'Staff_Home_Page_Middle';
						}
					}				
			}
		}
		
		ShowSelectedPost.className="ShowSelectedPost";
		PostBody.innerHTML=PostBodyText;
		PostSubject.innerHTML=PostSubjectText;
			
		while ( i < att_array.length - 1 )
			{
				if (att_array[i]!='') {
							filetype = RightString ( att_array[i] , 4 )
							switch ( filetype ) {
								case '.pdf':
									AttachmentImage="<img src='/NewIncludes/Images/Small_PDF_Icon.gif'>";
								case '.doc':
									AttachmentImage="<img src='/NewIncludes/Images/Small_Word_Icon.gif'>";
								case '.rtf':
									AttachmentImage="<img src='/NewIncludes/Images/Small_Word_Icon.gif'>";
								case '.xls':
									AttachmentImage="<img src='/NewIncludes/Images/Small_Excel_Icon.gif'>";
								case '.pps':
									AttachmentImage="<img src='/NewIncludes/Images/Small_PowerPoint_Icon.gif'>";
								case '.pub':
									AttachmentImage="<img src='/NewIncludes/Images/Small_Publisher_Icon.gif'>";
								case '.gif':
									AttachmentImage="<img src='/NewIncludes/Images/Small_Image_Icon.gif'>";
								case '.jpg':
									AttachmentImage="<img src='/NewIncludes/Images/Small_Image_Icon.gif'>";
							}
			
					strAttachment = strAttachment + "<a class='AttachmentText' href='"+att_array[i]+"' target='_blank' alt='Click here to open this attachment'>Attachment " + (i+1) + "</a>&nbsp;<a class='AttachmentText' href='"+att_array[i]+"' target='_blank' alt='Click here to open this attachment'>"+AttachmentImage+"</a>" + '<br>';
				}
				i += 1 ;
			}
			
			PostAttachment.className="ShowSelectedPost";
			PostAttachment.innerHTML=strAttachment;
			
	}
	

//=================================================================================================================================================================
// function to get the right four characters of the string that is passed in
//=================================================================================================================================================================		
function RightString ( str, n )
	{
		var iLen=String(str).length;
		return String(str).substring(iLen, iLen - n);
	}
		
//=================================================================================================================================================================
// function to re-load the search results page with the sort option that the user has selected
//=================================================================================================================================================================	
function Sort_By_Option(sortby,stroption)
	{
		if (sortby=="Rank")
			{
				if (stroption=="rank[d]")
					{
						stroption="rank[a]";
					}
					
				if (stroption=="rank[a]")
					{
						stroption="rank[d]";
					}
			}
		
		if (sortby=="posting_name")
			{
				if (stroption=="posting_name[d]")
					{
						stroption="posting_name[a]";
					}
					
				if (stroption=="posting_name[a]")
					{
						stroption="posting_name[d]";
					}
			}
		
		if (sortby=="posting_start_date")
			{
				if (stroption=="posting_start_date[d]")
					{
						stroption="posting_start_date[a]";
					}
					
				if (stroption=="posting_start_date[a]")
					{
						stroption="posting_start_date[d]";
					}
			}
			
		if (sortby=="site_name")
			{
				if (stroption=="site_name[d]")
					{
						stroption="site_name[a]";
					}
					
				if (stroption=="site_name[a]")
					{
						stroption="site_name[d]";
					}
			}			
			
		window.location='./Search1.asp?SearchView=1&SearchString='+UrlEncodedQueryString.value+'&strOption='+stroption+'&andString='+TheAdvancedQuery.andString.value+'&exactString='+TheAdvancedQuery.exactString.value+'&orString='+TheAdvancedQuery.orString.value+'&NotString='+TheAdvancedQuery.NotString.value+'&Source='+TheAdvancedQuery.Source.value+'&Occurrence='+TheAdvancedQuery.Occurrence.value	
	
	}	