﻿function showItem(ID)
{
    myItem = document.getElementById(ID);
    myItem.style.display = '';
}

function hideItem(ID)
{
    myItem = document.getElementById(ID);
    myItem.style.display = 'none';
}

function RemovePart(whole, toBeRemoved)
{
    var returnString;
    var startOf = whole.indexOf(toBeRemoved);
    var endOf = toBeRemoved.length;
    
    return (whole.substring(0, startOf) + whole.substring(endOf + startOf, whole.length));
}

$(document).ready(function(){
	$(".list-orange li:last-child").addClass("list-last-child");
	$(".list-green li:last-child").addClass("list-last-child");
	$("#ctl00_OMSContentPlaceHolder_tblScreenings tr:first").addClass("screeningstr");
});

function DisplayHelp()
{
	var page;
	page = location.href;
	if(page.indexOf("?", 0)== -1)
	{
	DisplayCentreWindow(900, 450, '/help.aspx?rh=' + page.substr(page.lastIndexOf("/") + 1));
	} else {
	DisplayCentreWindow(900, 450, '/help.aspx?rh=' + page.substring(page.lastIndexOf("/") + 1, page.indexOf("?")))
	}
}

function DisplayCentreWindow(width, height, url)
{
	var horizontalPosition = (screen.width - width)/2;
	var verticalPosition = (screen.height - height)/2;
	if (horizontalPosition < 0) horizontalPosition = 0;
	if (verticalPosition < 0) verticalPosition = 0;
	
	var windowprops = "height=" + height +",width=" + width + ",top=" + verticalPosition + ",left=" + horizontalPosition + ",location=no,scrollbars=yes,menubars=no,toolbars=no,resizable=no,status=yes";
	window.open(url, target='_new', windowprops);
}

function navigateWithReferrer(url)
{
    var fakeLink = document.createElement ("a");
    if (typeof(fakeLink.click) == 'undefined')
        location.href = url;  // sends referrer in FF, not in IE
    else
    {
        fakeLink.href = url;
        document.body.appendChild(fakeLink);
        fakeLink.click();   // click() method defined in IE only
    }
}

function visibleRowsOfTable(tableID)
{
    var tableToCheck = document.getElementById(tableID);
    var numberOfRows = 0;
    
    for(var rCount = 0; rCount < tableToCheck.rows.length; rCount ++)
    {
        if(tableToCheck.rows[rCount].style.display=='')
            numberOfRows ++;
    }
    
    return numberOfRows;
}

function toggler(ID)
{
	myID = document.getElementById(ID); 
	myID.style.display = (myID.style.display == '') ? 'none' : '';
}

function toggleWithImage(ID, imageID, firstImage, secondImage)
{
	toggler(ID);
	myImage = document.getElementById(imageID);
	
	tidySrc = myImage.src.substr(myImage.src.lastIndexOf("/", myImage.src.lastIndexOf("/") - 1) + 1);
	
	myImage.src = (tidySrc == secondImage) ? firstImage : secondImage;
}
