if (document.getElementById) {
document.writeln('<'+'link rel="stylesheet" type="text/css" media="screen" href="http://static.informaprofessional.com/insday/css/dev/hide.css"' + ' />');
}

/* hides and shows the date panel - advanced search */
function hideShow(theRadioSelected) {
	
	if (!document.getElementById || !document.getElementsByTagName) return false;
	
	// is hideShow on the page?
	if (null != document.getElementById("hideShow")) {
	
	// get the parent tag called 'hideShow'
	var theParentTag = document.getElementById("hideShow");
	
	// get all the radion buttons inside the parent element
	var radioButtons = theParentTag.getElementsByTagName("input");
	
	//get the datePanel
	var datePanel = document.getElementById("datepanel");
	
	// open the date picker if the date range radio is selected
        // used for when the user goes back using the back button
	
	
	for (var i=0; i<radioButtons.length; i++) {
	
	// open the date picker if the date range radio is selected
        // used for when the user goes back using the back button
        
        if (radioButtons[i].getAttribute("value") == "sel") {
           if (radioButtons[i].checked) {
           datePanel.className = "date_panel";
           }
        }
	
	
		radioButtons[i].onclick = function() {	
	
	        // get the attribute 'value' so we can check if it is the 'all' radio or not
	        var theValue = this.getAttribute("value");
	               
                // if it is then we display the 'datePanel'	
	        if (theValue == 'sel') {
	        datePanel.className = "date_panel";
	        // if not then we hide it
	        } else {
	        datePanel.className = "date_panel_hidden";
	        }
	

		}
	}	
			
	} else {
	// hideShow not on the page so nothing more will happen
	return false;
	}
	
}

/* highlighting for advanced search form */
function highlight() {
        if (document.getElementById("chooseOne.errors")) {
        var errBlock = document.getElementById("form_error");
            errBlock.className = "form_error_block_on";
        }
}

/* generates an alert box if the specified number of checkboxes is exceeded */
function checkBoxLimit(){
    var limit = 1;
    if (!document.getElementById) return false;
    if (!document.getElementsByClassName("channelcb")) return false;
    var theChannelCheckBoxes = document.getElementsByClassName("channelcb");
    for (var i=0; i<theChannelCheckBoxes.length; i++){
		theChannelCheckBoxes[i].onclick=function(){
		var checkedcount=0
		for (var i=0; i<theChannelCheckBoxes.length; i++)
			checkedcount+=(theChannelCheckBoxes[i].checked)? 1 : 0
		if (checkedcount<limit){
            this.checked=true;
			alert("You must select at least one channel");
			}
		}
	}
}


/* show next and previous tips */
function showTip(slide, numOfPanels) {

//turn off all panels, then switch on the one we want
for (var i=1;i<=numOfPanels;i++) {
document.getElementById("slide" + i).className = "slide";
}

if (!document.getElementById) return false;
var showTip = document.getElementById(slide);
showTip.className = "slide on";
return false;
}


function basicSearchClickEvents() {
if (!document.getElementById) return false;
if (!document.getElementById("query_field")) return false;
var queryField = document.getElementById("query_field");

//load event handlers
queryField.onclick = function() {
clearInput(this,'Search');
}
queryField.onblur = function() {
clickRecall(this,'Search');
}

}


/* advanced search date fields */
function advancedSearchDateFieldEvents() {
if (!document.getElementById) return false;
if (!document.getElementById("datepanel")) return false;

// fromDay field
var fromDay = document.getElementById("fromDay");
fromDay.onclick = function() {
clearInput(this,'dd');
}
fromDay.onkeyup = function() {
moveOnMax(this,'fromMonth');
}
fromDay.onfocus = function() {
clearInput(this,'dd');
}
fromDay.onblur = function() {
clickRecall(this,'dd');
}

//fromMonth field
var fromMonth = document.getElementById("fromMonth");
fromMonth.onclick = function() {
clearInput(this,'mm');
}
fromMonth.onkeyup = function() {
moveOnMax(this,'fromYear');
}
fromMonth.onfocus = function() {
clearInput(this,'mm');
}
fromMonth.onblur = function() {
clickRecall(this,'mm');
}

//fromYear field
var fromYear = document.getElementById("fromYear");
fromYear.onclick = function() {
clearInput(this,'yyyy');
}
fromYear.onkeyup = function() {
moveOnMax(this,'toDay');
}
fromYear.onfocus = function() {
clearInput(this,'yyyy');
}
fromYear.onblur = function() {
clickRecall(this,'yyyy');
}

//toDay field
var toDay = document.getElementById("toDay");
toDay.onclick = function() {
clearInput(this,'dd');
}
toDay.onkeyup = function() {
moveOnMax(this,'toMonth');
}
toDay.onfocus = function() {
clearInput(this,'dd');
}
toDay.onblur = function() {
clickRecall(this,'dd');
}

//toMonth field
var toMonth = document.getElementById("toMonth");
toMonth.onclick = function() {
clearInput(this,'mm');
}
toMonth.onkeyup = function() {
moveOnMax(this,'toYear');
}
toMonth.onfocus = function() {
clearInput(this,'mm');
}
toMonth.onblur = function() {
clickRecall(this,'mm');
}

//toYear field
var toYear = document.getElementById("toYear");
toYear.onclick = function() {
clearInput(this,'yyyy');
}
/* last field so no 'onkeyup' instruction */
toYear.onfocus = function() {
clearInput(this,'yyyy');
}
toYear.onblur = function() {
clickRecall(this,'yyyy');
}

}

/* used to move on to next date field - advanced search */
function moveOnMax(field, nextFieldID) {
        if (field.value.length >= field.maxLength) {
            document.getElementById(nextFieldID).focus();
        }
}

/* used to clear and populate text in basic search input */
function clearInput(thisfield, defaulttext) {
    if (thisfield.value == defaulttext) {
        thisfield.value = "";
    }
}

function clickRecall(thisfield, defaulttext) {
    if (thisfield.value == "") {
        thisfield.value = defaulttext;
    }
}

function setUpTipsPanel() {

if (!document.getElementById) return false;
if (!document.getElementsByClassName("slide")) return false;
if (!document.getElementById("help")) return false;

// turn off all tip panels
/*var theSlides = document.getElementsByClassName("slide");
for (var i=1;i<theSlides.length; i++) {
theSlides[i].className = "slide hidden";
}*/

//need to get number of tips - count the number of divs inside 'help' div

var helpPanel = document.getElementById("help");
//alert(helpPanel.getElementsByTagName("div").length);

var numberOfPanels = helpPanel.getElementsByTagName("div").length;

var helpText = document.getElementsByClassName("helptext");

for (var i=0;i<helpText.length;i++) {

var parentDivId = helpText[i].parentNode.getAttribute("id");
var slideNum = i + 1;
var parentDivElement = document.getElementById("slide" + (i+1));

//extract the number from the id name
var count = parseFloat(parentDivId.replace(/\D/g,""));
var containerDiv = document.createElement("div");
parentDivElement.appendChild(containerDiv);

if (count == 1) {
containerDiv.innerHTML = "<ul class\=\"nav\"><li><a class\=\"tip_buttons\" onclick\=\"showTip('slide" + (count+1) + "'," + numberOfPanels +");\" title\=\"next\">next tip &raquo;</a></li></ul>";
} else if (count == numberOfPanels) {
containerDiv.innerHTML = "<ul class\=\"nav\">" +
"<li><a class\=\"tip_buttons\" onclick\=\"showTip('slide" + (count-1) + "'," + numberOfPanels + ");\" title\=\"previous\"> &laquo; previous tip</a></li>" +
"</ul>";
} else {
containerDiv.innerHTML = "<ul class\=\"nav\">" +
"<li><a class\=\"tip_buttons\" onclick\=\"showTip('slide" + (count-1) + "'," + numberOfPanels + ");\" title\=\"previous\"> &laquo; previous tip</a></li>" + 
"<li><a class\=\"tip_buttons\" onclick\=\"showTip('slide" + (count+1) + "'," + numberOfPanels + ");\" title\=\"next\">next tip &raquo;</a></li></ul>"
}

}

}

function pullInPubImage() {

/** 
takes no arguments */

/* This function pulls in the image required for the publication image panel.
Rather than have an inline style for the background image, we pull in the pubCode from the 'src' attribute
and use this to generate the background style instruction */

if (!document.getElementById) return false;
if (!document.getElementById("epaper-insuranceday")) return false;

var targetElement = document.getElementById("epaper-insuranceday");
var pubCode = targetElement.getAttribute("src");
//targetElement.setAttribute("style", "");
targetElement.style.cssText = "background: #fff url('http://static.informaprofessional.com/insday/img/" + pubCode + "_cover.jpg') top left \!important";
}

/* used to hijack the addThis script (for social bookmarking) - moves it clear of the ads, 'zIndex' conflict */
function nudgePanel() {
// leave if id is not found
if (!document.getElementById("at16p")) return false;
    var insday_addthis = document.getElementById("at16p");
    insday_addthis.style.position = "relative";
    insday_addthis.style.top = "-50px";
    insday_addthis.style.left = "450px";
}

// variables required by addThis
var addthis_pub = "informapod";
var addthis_offset_top = -150;
var addthis_offset_left = 60;

function applyAddThisEvents() {

//functions defined in

if (!document.getElementById) return false;
if (!document.getElementById("add_this")) return false;

var addThisLink = document.getElementById("add_this");

addThisLink.onmouseover = function() {
addthis_open(this, '', '[URL]', '[TITLE]');
}

addThisLink.onmouseout = function() {
addthis_close();
}

addThisLink.onclick = function() {
return addthis_sendto();
}

/* this is my additional dirty mouse event to nudge the panel to the left - see function 'nudgePanel' above */
addThisLink.onmousedown = function() {
nudgePanel();
}


}

function openNewWindow() {

if (!document.getElementsByClassName) return false;
if (!document.getElementsByClassName("open_new_window")) return false;

var openNewTabs = document.getElementsByClassName("open_new_window");

for (var i=0;i<openNewTabs.length;i++) {
	openNewTabs[i].onclick = function() {
	window.open(this.href);
	return false;
	}
}


}


function addPrintClickEvent() {

if (!document.getElementById) return false;
if (!document.getElementById("print-button")) return false;

var printButton = document.getElementById("print-button");
var articleId = printButton.getAttribute("src");
var url = "printArticle.htm?" + articleId;

printButton.onclick = function() {
printDocument(url);
}

}

function printDocument(url) {
appWindow = window.open(url, "", "'toolbar=no,location=no,status=no,menubar=no,directories=no,scrollbars=yes,resizable=yes,width=700,height=470')");
appWindow.focus();
}