var PageLoaded = false
window.onload = function(){
    if(window.OpenMenu){
       OpenMenu()  
    }
	PageLoaded = true;
    //alert("Loaded")
	FixIcons();
	FixHomeHeros();
	LanguageBox();
	setOnLoadCallback();
    if(window.LoadFLV){
       LoadFLV()  
    }	
}

function ToggleBBox(obj){
    if(document.getElementById('bbox'+obj).style.display == 'none'){
        document.getElementById('bbox'+obj).style.display = 'block';
        document.getElementById('showhide'+obj).innerHTML = 'Hide <img src="/css/images/bg_shuttertitle_on.gif" alt="" />';
    }else{
        document.getElementById('bbox'+obj).style.display = 'none';
        document.getElementById('showhide'+obj).innerHTML = 'Show <img src="/css/images/bg_shuttertitle_off.gif" alt="" />';
    }
}
function LanguageBox(obj) {
    var lboxinput = '#languagebox' + obj + ' input';
    var lboxli = '#languagebox' + obj + ' li';
    $(lboxinput).click(function() {
        jwplayer('mediaplayer'+obj).setup({
          'id': 'playerID',
          'width': '520',
          'height': '293',
          'file': ''+this.value,
          'skin': '/includes/mediaplayer/glow/glow.xml',
          'autostart':'true',
          'controlbar': 'over',
          'menu':'false',
          'modes': [
          {type: 'flash', src: '/includes/mediaplayer/player.swf'},
          {type: 'html5'}
          ]
          });
          $(lboxli).css('background-color', '#FFFFFF');
          $(this).parent().css('background-color', '#FEECBB');
          var tempStr = this.value;
          tempStr = tempStr.substr(tempStr.lastIndexOf("_")+1);
          tempStr = tempStr.replace('.mp4','');
          tempStr = tempStr.replace('.flv','');
          
          var tempStr2 = $('#downloadvideoIMGID'+obj).attr('onclick');
          var tempNo = tempStr2.length - 1;
          tempStr2 = tempStr2.substr(0,tempNo);
         
          
          $('#downloadvideoID'+obj).attr('onclick', tempStr2 + '&l=' + tempStr + '\'');
    });
}

//jQuery init functions
function setOnLoadCallback() {
    // Place init code here instead of $(document).ready()

    GetAllGlossaryItems();
    updateFavsCount();
    $("div.shutterContent:not('.open')").hide();
    $("div.shutterContent.open").prev("h3.shutterTitle").addClass("on");

    $("h3.shutterTitle").click(function() {
        if (!$(this).hasClass("on")) {
            CloseGlossary();

            $("div.shutterContent:visible").hide("fast");
            $(this).next("div.shutterContent").slideToggle("fast");
            $("h3.shutterTitle").removeClass("on");
            $(this).toggleClass("on");

            $(".glTerms:not(#glShutter0)").hide()
			.removeClass("printshow");

            var shutterID = $("h3.shutterTitle").index(this) + 1;
            if ($("#glShutter" + shutterID).length > 0) {
                $("#glShutter" + shutterID).addClass("printshow")
                .show();
            }
            if ($("#Utilities #savePDF a").length > 0) {
                $("#Utilities #savePDF a").attr("href", "http://pdf.raisingchildren.net.au/pdf.aspx?url=" + document.location.href + "&pdfShutter=" + shutterID);
            }
        };
        return false;
    });

    $("area.glossary").hover(
	    function() {
	        $("img.path").css("cursor", "help");
	        $(this).attr("style", "cursor:help;");
	    }
	    ,
	    function() {
	        $("img.path").css("cursor", "default");
	    }
	);

    $(".nutshell a.moreLink").each(function() {
        $(this).appendTo($(this).prev("p"));
    });
    $(".nutshell").each(function() {
        $(this).find("p:last").css("margin-bottom", "5px");
    });

    $(".inlineVideo").each(function() {
        displayInlineVideo(this);
    });

    doPinkBoxes();
    doGreenBoxes();

    $("#SectionFeature").each(function() {
        $(this).wrap('<div class="box" style="margin:10px 0;"><div class="lbgrn"><div class="rbgrn"><div class="bbgrn"><div class="blcgrn"><div class="brcgrn"><div class="tbgrn"><div class="tlcgrn"><div class="trcgrn"><div class="boxContent" style="padding:5px 0;"></div></div></div></div></div></div></div></div></div></div>')
               .css("margin", "0");
    });
    $(".vidDetails .title").ellipsis();
}


sfHover = function() {
    if (document.getElementById("NavBar")) {
        $("#Nav > li").hover(
            function() {
                $(this).addClass("sfhover");
            },
            function() {
                $(this).removeClass("sfhover");
            }
         );
    }
}

function doPinkBoxes() {
    //$("#info,#warning,#arrow,#asterix,#howto,#lightbulb,#question,#WarningTick,#quote").each(function() {
    var boxes = $("#info:not(.pinkRound),#warning:not(.pinkRound),#arrow:not(.pinkRound),#asterix:not(.pinkRound),#howto:not(.pinkRound),#lightbulb:not(.pinkRound),#question:not(.pinkRound),#WarningTick:not(.pinkRound),#quote:not(.pinkRound),.info:not(.pinkRound),.warning:not(.pinkRound),.arrow:not(.pinkRound),.asterix:not(.pinkRound),.howto:not(.pinkRound),.lightbulb:not(.pinkRound),.question:not(.pinkRound),.WarningTick:not(.pinkRound),.quote:not(.pinkRound),.pipQuote:not(.pinkRound),.t2tQuote:not(.pinkRound),.videoQuote:not(.pinkRound)");
    var currentBox = $(boxes).eq(0);
        var boxRightMargin = 0;
        var channelWidth = Math.max($("#PullOut").width(), $(".rightChannelLandingTiles").width(), $(".rightChannel").width());
        if (channelWidth > 0 && $(currentBox).parents("#bodyContent").length > 0) {
            var channelHeight = Math.max($("#PullOut").height(), $(".rightChannelLandingTiles").height(), $(".rightChannel").height()) + Math.max($("#PullOut").offset().top, ($(".rightChannelLandingTiles").offset()==null?0:$(".rightChannelLandingTiles").offset().top), ($(".rightChannel").offset()==null?0:$(".rightChannel").offset().top) );
            if ($(currentBox).offset().top < channelHeight) {
                boxRightMargin = channelWidth + 15;
            }
        }
        //if (!$.browser.msie || ($.browser.msie && parseFloat($.browser.version) >= 8)) {
        //alert(boxRightMargin);
        $(currentBox).addClass($(currentBox).attr("id") + " pinkRound")
               .attr("id","")
               .wrap('<div class="box" style="margin:10px ' + boxRightMargin + 'px 10px -6px;"><div class="lbpink"><div class="rbpink"><div class="bbpink"><div class="blcpink"><div class="brcpink"><div class="tbpink"><div class="tlcpink"><div class="trcpink"><div class="boxContent" style="padding:5px 0;"></div></div></div></div></div></div></div></div></div></div>')
               .css("margin", "0")
               .find(".lbpink").before("<!-- Start a box -->");
        //} else {
        //    $(this).css('margin', '10px ' + boxRightMargin + 'px 10px -6px');
        //}
        if ($(boxes).length != 0) { doPinkBoxes(); }
    //});
}
function doGreenBoxes() {
    $("#newsFlash").each(function() {
    $(this).wrap('<div class="box" style="margin:10px 0;"><div class="lbgrn"><div class="rbgrn"><div class="bbgrn"><div class="blcgrn"><div class="brcgrn"><div class="tbgrn"><div class="tlcgrn"><div class="trcgrn"><div class="boxContent" style="padding:5px 0;"></div></div></div></div></div></div></div></div></div></div>')
           .css("margin", "0")
           .find(".lbgrn").before("<!-- Start a box -->");
    });
}

function StartSlideshow(id){
	var NewWindow = window.open('/Slideshow.aspx?id=' + id,'slideshow','height=390,width=500,left=10,top=10,directories=0,fullscreen=0,location=0,menubar=0,scrollbars=0,resizable=0,status=0,toolbar=0');
}

function saveFavsPDF() {
    var strExistingCookie = get_cookie("rcnfavs");
    if (strExistingCookie == "") {
        alert("You have not saved any favourites.");
        return false;
    } else {
        var NewWindow = window.open("http://pdf.raisingchildren.net.au/FavouritesPDF.aspx", "FavouritesPDF", 'height=350,width=350,left=200,top=150,directories=0,fullscreen=0,location=0,menubar=0,scrollbars=0,resizable=0,status=0,toolbar=0');
    }
}

// Home page scroller
function SlideLeft() {
    isMoving = true;
    $("#PromoTiles li:first").stop();
    $("#PromoTiles li:first").animate({ marginLeft: '-215px' }, 350, function() {
        $("#PromoTiles li:first").insertAfter($("#PromoTiles li:last"));
        $("#PromoTiles li:last").css("margin-left", "");
        isMoving = false;            
    });
}

function SlideRight() {
    isMoving = true;
    $("#PromoTiles li:last").css("margin-left", "-215px");
    $("#PromoTiles li:last").insertBefore($("#PromoTiles li:first"));
    $("#PromoTiles li:first").stop();
    $("#PromoTiles li:first").animate({ marginLeft: '0px' }, 350, function() {
        isMoving = false; 
    });
}

// Function drives the left menu
var blnMenusInit = false

function Menu(id,aID) {
	var d = document.getElementById(id);
	var a = document.getElementById(aID);
	for (var i = 1; i<=20; i++) {
		// Hide all Our open folders and reset the class name	
		if (document.getElementById('smenu'+i)) {document.getElementById('smenu'+i).style.display='none';}
		if (document.getElementById('a'+i)) {document.getElementById('a'+i).className  = "";}
	}
	//If we have an active one show it and apply a class
	if (d) {d.style.display='block';}
	if (a) {a.className = 'Active'}
}	

function OpenInitialMenu(id,aID){
	Menu(id,aID);
	blnMenusInit = true;
}
function initMenu(){
	// If we havent already initialised the menus do it here.	
	//alert(blnMenusInit)
	//if(!blnMenusInit){	
		Menu();
	//}
}

function showHideRefs() {
    $('#ulRefs').slideToggle('normal', function() {
        $('.btnRefs').toggleClass("minus");
    });
}

// Favourites
function isInFavourites(id) {
    var strExistingCookie = get_cookie("rcnfavs");
    var arrExistingCookie = new Array();
    
    if (strExistingCookie != null) {
        arrExistingCookie = strExistingCookie.split(",");
        if (jQuery.inArray(id, arrExistingCookie) != -1) {
            return true;
        } else {
            return false;
        }
    }
    return false;
}

function setAddRemoveLink() {
    var strPageID = $("meta[name='asset.id']").attr("content");
    
    var objAddRemoveLink = $("#Utilities #favs a");

    if (!isInFavourites(strPageID)) {
        $(objAddRemoveLink).removeClass("remove")
                           .text("add to favourites")
                           .attr("href", "javascript:addToFavourites('" + strPageID + "')");
    } else {
        $(objAddRemoveLink).addClass("remove")
                           .text("remove from favourites")
                           .attr("href", "javascript:removeFromFavourites('" + strPageID + "')");       
    }

}

function removeFromFavouritesLink(link, id, group) {
    var strGroup = "";
    if (group) {
        strGroup = group;
    }

    if (strGroup != "") {
        removeFromRecFavourites(id, strGroup);
    } else {
        removeFromFavourites(id);
    }

    var objLinkListitem = $(link).parent("li");
    var objLinkList = $(objLinkListitem).parent("ul");

    $(objLinkListitem).fadeOut("slow", function() {
        if ($(objLinkList).children(":visible").length == 0) {
            $(objLinkList).css("border","1px solid #FFF");
            $(objLinkList).slideUp("fast");
            $(objLinkList).prev("h3").slideUp("fast");
            if (strGroup != "") {
                if ($(".suggested li:visible").length == 0) {
                    $(".suggested .message").append('<p class="redbold" style="margin:.5em 0 0;">Your suggested favourites have been removed.</p>');
                    checkFavsButtons();
                }
            } else {
                if ($(".myfavs li:visible").length == 0) {
                    $(".myfavs .message").append('<p class="redbold" style="margin:.5em 0 0;">Your favourites have been removed.</p>');
                    checkFavsButtons();
                }
            }
        }
    });
}

function checkFavsButtons() {
    if ($(".favsSection .Links li:visible").length == 0) {
        $(".favsButtons").hide();
    } else if ($(".myfavs li:visible").length == 0) {
        $(".favsButtons .svPDF,.favsButtons .eml").hide();
    } 
}

function removeAllFavs() {
    var datToday = new Date();
    set_cookie("rcnfavs", "", datToday.getFullYear() - 10, datToday.getMonth(), datToday.getDate(), '/',"raisingchildren.net.au");
    set_cookie("rcnrecfavs", "", datToday.getFullYear() - 10, datToday.getMonth(), datToday.getDate(), '/',"raisingchildren.net.au");
    location.replace("/Favourites.aspx?action=removeall");
}

function addToFavourites(id) {
    var strToAdd = id;
    var strCookieName = "rcnfavs";
    
    var strExistingCookie = get_cookie(strCookieName);
    var arrExistingCookie = new Array();
    var datToday = new Date();

    if (strExistingCookie != null) {
        arrExistingCookie = strExistingCookie.split(",");
        if (jQuery.inArray(id, arrExistingCookie) == -1) {
            arrExistingCookie.push(id);
        }
        strToAdd = arrExistingCookie.toString();
    }

    set_cookie(strCookieName, strToAdd, datToday.getFullYear() + 10, datToday.getMonth(), datToday.getDate(), '/',"raisingchildren.net.au");

    //alert("Cookie = " + get_cookie("rcnfavs"));
    updateFavsCount();
    showAddFavouritesOverlay(id);
}

function showAddFavouritesOverlay(id){
    var strURL = "/AddFavourite.aspx?id=" + id
    if (!cookiesEnabled()) {
        strURL = "/AddFavourite.aspx?cookiesenabled=false"
    }
    Shadowbox.open({
        content: strURL,
        player: "iframe",
        title: "",
        height: 400,
        width: 590
    });
    
}

function cookiesEnabled() {
    var dt = new Date();
    dt.setSeconds(dt.getSeconds() + 60);
    document.cookie = "cookietest=1; expires=" + dt.toGMTString();
    var cookiesEnabled = document.cookie.indexOf("cookietest=") != -1;
    document.cookie = "cookietest=1; expires=" + new Date(80, 1, 1).toGMTString();
    if (!cookiesEnabled) {
        return false;
    } else {
        return true;
    }
}

function removeFromFavourites(id) {
    var strCookieName = "rcnfavs";
    
    var strExistingCookie = get_cookie(strCookieName);

    if (strExistingCookie != null) {
        var strToRemove = id;
        var arrExistingCookie = new Array();
        var datToday = new Date();

        arrExistingCookie = strExistingCookie.split(",");
        var index = jQuery.inArray(id, arrExistingCookie);
        if (index >= 0) {
            arrExistingCookie.splice(index, 1);
        }
        strToAdd = arrExistingCookie.toString();

        if (strToAdd != "") {
            set_cookie(strCookieName, strToAdd, datToday.getFullYear() + 10, datToday.getMonth(), datToday.getDate(), '/',"raisingchildren.net.au");
        }
        else {
            set_cookie(strCookieName, strToAdd, datToday.getFullYear() - 10, datToday.getMonth(), datToday.getDate(), '/',"raisingchildren.net.au");
        }

        //alert("Cookie = " +  get_cookie("rcnfavs"));
        updateFavsCount();
    }
    else {
        alert("You have not saved any favourites.");
    }
}

function removeFromRecFavourites(id, group) {
    var strCookieName = "rcnrecfavs";
    
    var strExistingCookie = get_cookie(strCookieName);

    if (strExistingCookie != null) {
        var strToRemove = id;
        var arrExistingCookieGroups = new Array();
        var arrCurrentCookieGroup = new Array();
        var arrCurrentCookieGroupValue = new Array();
        var datToday = new Date();
        var strNewCookieString = "";
        var k = 0;

        arrExistingCookieGroups = strExistingCookie.split(";");

        for (k = 0; k < arrExistingCookieGroups.length; k++) {
            arrCurrentCookieGroup = arrExistingCookieGroups[k].split("=");
            arrCurrentCookieGroupValue = arrCurrentCookieGroup[1].split(",");
            if (arrCurrentCookieGroup[0] == group) {
                var index = jQuery.inArray(strToRemove, arrCurrentCookieGroupValue);
                if (index >= 0) {
                    arrCurrentCookieGroupValue.splice(index, 1);
                }
            }
            if (arrCurrentCookieGroupValue.length > 0) {
                strNewCookieString += arrCurrentCookieGroup[0] + "=" + arrCurrentCookieGroupValue.toString();
                if (k < arrExistingCookieGroups.length - 1) {
                    strNewCookieString += ";"
                }
            }
        }

        if (strNewCookieString.charAt(strNewCookieString.length - 1) == ";") {
            strNewCookieString = strNewCookieString.slice(0, -1);
        }
        //alert(strNewCookieString);

        if (strNewCookieString != "") {
            set_cookie(strCookieName, strNewCookieString, datToday.getFullYear() + 10, datToday.getMonth(), datToday.getDate(), '/',"raisingchildren.net.au");
        }
        else {
            set_cookie(strCookieName, strNewCookieString, datToday.getFullYear() - 10, datToday.getMonth(), datToday.getDate(), '/',"raisingchildren.net.au");
        }

        updateFavsCount();
    }
    else {
        alert("You do not have any suggested favourites.");
    }
}

function updateFavsCount() {
    var count = 0;
    var strExistingCookie = get_cookie("rcnfavs");

    if (strExistingCookie != null) {
        var arrExistingCookie = new Array();
        arrExistingCookie = strExistingCookie.split(",");

        count = arrExistingCookie.length;
    }

    if (count > 0) {
        $(".favscount").text('(' + count.toString() + ')');
    } else {
        $(".favscount").text('(' + 0 + ')');
    }
    setAddRemoveLink();
}


// Glossary XML HTTP Stuff 

// Load XMLHttpRequest Object for User detail lookups
// DO NOT DELETE ANY OF THE CODE BELOW. What appears to be comments is IE conditional code
// We need two objects so we dont get any conflicts at load time.
var xmlhttp=false;
var xmlhttp2=false
function CreateXMLHttpRequestObject(){
	/*@cc_on @*/
	/*@if (@_jscript_version >= 5)
	// JScript gives us Conditional compilation, we can cope with old IE versions.
	// and security blocked creation of the objects.
	 try {
	  xmlhttp = new ActiveXObject("Msxml2.XMLHTTP");
	 } catch (e) {
	  try {
	   xmlhttp = new ActiveXObject("Microsoft.XMLHTTP");
	  } catch (E) {
	   xmlhttp = false;
	  }
	 }
	@end @*/
	if (!xmlhttp && typeof XMLHttpRequest!='undefined') {
	  xmlhttp = new XMLHttpRequest();
	}	
	
}
function CreateXMLHttpRequestObject2(){
	/*@cc_on @*/
	/*@if (@_jscript_version >= 5)
	// JScript gives us Conditional compilation, we can cope with old IE versions.
	// and security blocked creation of the objects.
	 try {
	  xmlhttp2 = new ActiveXObject("Msxml2.XMLHTTP");
	 } catch (e) {
	  try {
	   xmlhttp2 = new ActiveXObject("Microsoft.XMLHTTP");
	  } catch (E) {
	   xmlhttp2 = false;
	  }
	 }
	@end @*/
	if (!xmlhttp2 && typeof XMLHttpRequest!='undefined') {
	  xmlhttp2 = new XMLHttpRequest();
	}	
	
	
	
}
CreateXMLHttpRequestObject();
CreateXMLHttpRequestObject2();

var blnGlossaryLoaded = false
function GetAllGlossaryItems(){
	var strAssetList = "";
	var anchors;
	var mapareas;
	var shutters;
	var pdfShutter = 0;
	if(xDOM("glossaryPrintContent", 0)){
		if (document.getElementsByTagName) {			
			
			if ($("span#pdfShutter").length > 0) {
			    shutters = $(".shutterContent.open")
			} else {
			    shutters = $(".shutterContent");
			}
			
			//alert($("span#pdfShutter").length);
			
			for (var j=0; j<=shutters.length; j++) {			
			
			    if (j<1){
			       anchors = $("a:not(.shutterContent a)");
			    } else {
			       anchors = $(shutters[j-1]).find("a");
			    } 
			    
			    for (var i=0; i<anchors.length; i++) {
				    var anchor = anchors[i];
				    if(anchor.getAttribute('href')){
				        if (anchor.getAttribute('href').indexOf('showGlossary')>0) {
					        strAssetList = strAssetList + anchor.getAttribute('href').substring(24,anchor.getAttribute('href').length - 2) + "~" + j + ",";
				        }
				    }
			    }
			    
			    if (j<1){
			       mapareas = $("area:not(.shutterContent area)");
			    } else {
			       mapareas = $(shutters[j-1]).find("area");
			    }
			    for (var i=0; i<mapareas.length; i++) {
				    var maparea = mapareas[i];
				    if(maparea.getAttribute('href')){
				        if (maparea.getAttribute('href').indexOf('showGlossary')>0) {
							if (maparea.getAttribute('href').indexOf('pathfinder')>0) {  // Has additional 'pathfinder' param to give different popup functionality
					        	strAssetList = strAssetList + maparea.getAttribute('href').substring(24,maparea.getAttribute('href').length - 15) + "~" + j + ",";
							}else{
					        	strAssetList = strAssetList + maparea.getAttribute('href').substring(24,maparea.getAttribute('href').length - 2) + "~" + j + ",";								
							}
				        }
				    }
			    }
			    
			}

			
		}	
		//alert(strAssetList);
		if(strAssetList!=''){
		    xmlhttp.open("GET", location.protocol + "//" + location.hostname + "/getGlossaryContent.aspx?id=" + strAssetList, true);
		    //alert(location.protocol + "//" + location.hostname + "/getGlossaryContent.aspx?id=" + strAssetList);
			xmlhttp.onreadystatechange=function() {
				if (xmlhttp.readyState==4) {
					xDOM("glossaryPrintContent", 0).innerHTML = xmlhttp.responseText;
					blnGlossaryLoaded = true;
					if ($("span#pdfShutter").length == 0) {
					    setActivePrintItems();
					} else {
					    $(".glTerms").show();
					}
										
				}
			}
			xmlhttp.send(null)
			
		}		
	}
}

function setActivePrintItems(){
    if ($("div.shutterContent.open").length > 0) {
        //show glossary content for shutter and change pdf link  
        var shutters = $("div.shutterContent"); 
        
        for (var i=0; i<shutters.length; i++) {        
            if ($(shutters[i]).hasClass("open")) {                
                if ($("#glShutter" + String(i + 1)).length > 0) {
                    $("#glShutter" + String(i + 1)).addClass("printshow");
                }
                if ($("#Utilities #savePDF a").length > 0) {
                    if ($("div.shutterContent.open").length = 1) {
                        $("#Utilities #savePDF a").attr("href", "http://pdf.raisingchildren.net.au/pdf.aspx?url=" + document.location.href + "&pdfShutter=" + String(i + 1));
                    }
                }                
            }          
        }
        if ($("#Utilities #savePDF a").length > 0 && $("div.shutterContent.open").length > 1) {
            $("#Utilities #savePDF a").attr("href", "http://pdf.raisingchildren.net.au/pdf.aspx?url=" + document.location.href + "&pdfShutter=all");
        }
                      
    } else {
        if ($("#Utilities #savePDF a").length > 0) {
            //$("#Utilities #savePDF a").attr("href", "http://pdf.raisingchildren.net.au/pdf.aspx?url=" + document.location.href);
        }
    }   
    $(".glTerms:not(.printshow)").hide();
    $("#glShutter0").show();
}

function displayInlineVideo(obj){
    var strVideoID = $(obj).text().substring(8);
    if (strVideoID != "") {
        $.get('/ShowInlineVideo.aspx?id=' + strVideoID, function(data) {
          $(obj).replaceWith(data);
          //alert('Load was performed.');          
        });
    }    
}

function showGlossaryMouseover(e,intID){
    SetXY(e);
    showGlossary(intID);
}

function showGlossary(intID){
	if(blnGlossaryLoaded){	
		var strGlossaryItem = xDOM("gloss" + intID, 0).innerHTML
		var strContent
		var GlossBrowserWidth = 0
		strContent = '<div id="glossaryTop"><a href="Javascript:CloseGlossary()">Close</a></div>'
		strContent = strContent + '<div id="glossaryMain"><div>' + strGlossaryItem + '</div></div>'
		strContent = strContent + '<div id="glossaryBottom">&#160;</div>'
		var objGlossary = xDOM("glossaryContent", 0)
		objGlossary.innerHTML = strContent
		if(tempX == 0)tempX = 150;
		if(tempY == 0)tempY = 550;



		if(IE){
			showOrHideAllDropDowns("hidden")
		}


		if(typeof( window.innerWidth ) == 'number' ) {//Non-IE
			GlossBrowserWidth = window.innerWidth;
		} else if( document.documentElement && ( document.documentElement.clientWidth || document.documentElement.clientHeight ) ) {//IE 6+ in 'standards compliant mode'
			GlossBrowserWidth = document.documentElement.clientWidth;
		} else if( document.body && ( document.body.clientWidth || document.body.clientHeight ) ) {//IE 4 compatible
			GlossBrowserWidth = document.body.clientWidth;
		}			
		
		//alert(parseInt(navigator.appVersion))
		if(IE && (navigator.userAgent.indexOf("MSIE 5.5") != -1)){ 
			// IE 5.5
			
			xDOM("glossaryMain", 1).height = Math.ceil(strGlossaryItem.length / 4.2) + 'px';	
            if((tempX + 380) > GlossBrowserWidth){
                objGlossary.style.left = GlossBrowserWidth - 390 + "px";
            }else{
                objGlossary.style.left = tempX / 2 + "px";
		    }
		    objGlossary.style.top = tempY - 100 + "px";				
		
		
				
		}else if(IE){// IE 6.0
			xDOM("glossaryMain", 1).height = Math.ceil(strGlossaryItem.length / 4.2) + 'px';	
            if((tempX + 380) > GlossBrowserWidth){
                objGlossary.style.left = GlossBrowserWidth - 390 + "px";
            }else{
                objGlossary.style.left = tempX + 10 +  "px";
		    }
		    objGlossary.style.top = tempY + 10 + "px";	 			
		}else{ // Everyone else
            if((tempX + 380) > GlossBrowserWidth){
                objGlossary.style.left = GlossBrowserWidth - 380 + "px";
                
            }else{
               objGlossary.style.left = tempX + "px";	 
			}
			objGlossary.style.top = tempY + 10 + "px";					
	    }	


		if(strType='pathfinder'){
		    var arrViewport = getViewPort();
		    var BottomSpace = arrViewport[3] - tempY;
		    var GlossItemHeight = $("#glossaryContent").height();
 
		    if(GlossItemHeight > BottomSpace){
		        var intMoveUp = (GlossItemHeight - BottomSpace) + 20;
		        var newTop = objGlossary.style.top;
		        var newLeft = objGlossary.style.left;
		        
		        // Get new top point based on old point - offset
		        if(objGlossary.style.top.indexOf("px") > 0){
		            newTop = parseInt(objGlossary.style.top.substring(0,objGlossary.style.top.length - 2)) - intMoveUp
		        }
		        // Move the item 10px to the right
		        if(objGlossary.style.left.indexOf("px") > 0){
		            newLeft = parseInt(objGlossary.style.left.substring(0,objGlossary.style.left.length - 2)) + 15
	            
		        }		        
                // Check we arent going of the top
                if(newTop < arrViewport[2]){
                    newTop = arrViewport[2] + 5 
                }
                // Apply new positions
		        objGlossary.style.top = newTop + "px";
		        objGlossary.style.left = newLeft + "px";
		    }
		   
		}



	    objGlossary.style.display = "block";		
	}else{

		
	}
}
function getViewPort(){
	var x,y;
	if (self.innerHeight) // all except Explorer
	{
		x = self.innerWidth;
		y = self.innerHeight;
	}
	else if (document.documentElement && document.documentElement.clientHeight)
		// Explorer 6 Strict Mode
	{
		x = document.documentElement.clientWidth;
		y = document.documentElement.clientHeight;
	}
	else if (document.body) // other Explorers
	{
		x = document.body.clientWidth;
		y = document.body.clientHeight;
	}
	
	
	var scrX,scrY;
	if (self.pageYOffset) // all except Explorer
	{
		scrX = self.pageXOffset;
		scrY = self.pageYOffset;
	}
	else if (document.documentElement && document.documentElement.scrollTop)
		// Explorer 6 Strict
	{
		scrX = document.documentElement.scrollLeft;
		scrY = document.documentElement.scrollTop;
	}
	else if (document.body) // all other Explorers
	{
		scrX = document.body.scrollLeft;
		scrY = document.body.scrollTop;
	}
	var arrDimentions = new Array(4)
	arrDimentions[0] = scrX;
	arrDimentions[1] = (scrX + x);
	arrDimentions[2] = scrY;
	arrDimentions[3] = (scrY + y);
	return arrDimentions
}
//Glossary Items
var IE = document.all?true:false
//Add the event
document.onclick = SetXY

var tempX = 0
var tempY = 0

function CloseGlossary(){
	if(xDOM("glossaryContent", 0)){
		var objGlossary = xDOM("glossaryContent", 0)
		objGlossary.style.display = "none";
	}
	if(IE){
		showOrHideAllDropDowns("visible")
	}	
}

function showOrHideAllDropDowns(newState) {
	
	var elements = document.documentElement.getElementsByTagName('select');
 
	for (var i=0; i<elements.length; i++) {
		elements[i].style.visibility = newState;
	}
}	

function SetXY(e){
    //alert("hi")
    if(xDOM("glossaryPrintContent", 0)){
	    
		
	   if( e )
	   {
		  if( typeof( e.pageX ) == 'number' )
		  {
			 tempX = e.pageX;
			 tempY = e.pageY;
		  }
		  else
		  {
			 tempX = e.clientX;
			 tempY = e.clientY;
		  }
	   }
	   else
	   {
		  e = window.event;
		  tempX = e.clientX;
		  tempY = e.clientY;
		  if( document.documentElement
			&& ( document.documentElement.scrollTop
				|| document.documentElement.scrollLeft ) )
		  {
			 tempX += document.documentElement.scrollLeft;
			 tempY += document.documentElement.scrollTop;
		  } 
		  else if( document.body
			 && ( document.body.scrollTop
				 || document.body.scrollLeft ) )
		  {
			 tempX += document.body.scrollLeft;
			 tempY += document.body.scrollTop;
		  }
	   }		
		
		
	    if(xDOM("glossaryPrintContent", 0).innerHTML != '&nbsp;'){CloseGlossary()};
	}    
}


function showSnippet(){
	 var newsdiv = document.getElementById('newsnippetspopup');
	/* newsdiv.style.top=(tempX)+"px";
	 newsdiv.style.left=(tempY)+"px";*/
	 newsdiv.style.display = "block";
	 
	 //alert("tempX: "+tempX+"  tempY: "+tempY);
	 
	 if(newsdiv){
		var GlossBrowserWidth = 0
		var objGlossary = xDOM('newsnippetspopup', 0)
		if(tempX == 0)tempX = 150;
		if(tempY == 0)tempY = 550;


		if(typeof( window.innerWidth ) == 'number' ) {//Non-IE
			GlossBrowserWidth = window.innerWidth;
		} else if( document.documentElement && ( document.documentElement.clientWidth || document.documentElement.clientHeight ) ) {//IE 6+ in 'standards compliant mode'
			GlossBrowserWidth = document.documentElement.clientWidth;
		} else if( document.body && ( document.body.clientWidth || document.body.clientHeight ) ) {//IE 4 compatible
			GlossBrowserWidth = document.body.clientWidth;
		}			
		
		//alert(parseInt(navigator.appVersion))
		if(IE && (navigator.userAgent.indexOf("MSIE 5.5") != -1)){ 
			// IE 5.5
			
			//xDOM("glossaryMain", 1).height = Math.ceil(strGlossaryItem.length / 4.2) + 'px';	
            if((tempX + 380) > GlossBrowserWidth){
                objGlossary.style.left = GlossBrowserWidth - 200 + "px";
            }else{
                objGlossary.style.left = tempX / 2 + "px";
		    }
		    objGlossary.style.top = tempY - 100 + "px";				
		
		
				
		}else if(IE){// IE 6.0
			//xDOM("glossaryMain", 1).height = Math.ceil(strGlossaryItem.length / 4.2) + 'px';	
            if((tempX + 380) > GlossBrowserWidth){
                objGlossary.style.left = GlossBrowserWidth - 200 + "px";
            }else{
                objGlossary.style.left = (tempX - 5) +  "px";
		    }
		    objGlossary.style.top = tempY + 10 + "px";	 			
		}else{ // Everyone else
            if((tempX + 380) > GlossBrowserWidth){
                objGlossary.style.left = GlossBrowserWidth - 200 + "px";
                
            }else{
               objGlossary.style.left = tempX + "px";	 
			}
			objGlossary.style.top = tempY + 10 + "px";					
	    }	
		//alert(objGlossary.style.left + "," + objGlossary.style.top)
	    objGlossary.style.display = "block";		
	}else{

		
	}
}

function hideSnippet(){
	var newsdiv = document.getElementById('newsnippetspopup');
	newsdiv.style.display = "none";
}

// Cross Browser DOM Functions used to create objects and get top / left coords
// copyright Stephen Chapman, 4th Jan 2005
// you may copy this code but please keep the copyright notice as well
var aDOM = 0, ieDOM = 0, nsDOM = 0
var stdDOM = document.getElementById;
if (stdDOM) aDOM = 1; else {
  ieDOM = document.all;
  if (ieDOM) aDOM = 1; else {
    nsDOM = (
      (navigator.appName.indexOf('Netscape') != -1)
      && (parseInt(navigator.appVersion) ==4));
    if (nsDOM) aDOM = 1;
  }
}
function xDOM(objectId, withStyle) {
var st = ''; if (withStyle) st = '.style';
if (stdDOM) return (eval('document.getElementById(objectId)'+st));
if (ieDOM) return (eval('document.all[objectId]'+st));
if (nsDOM) return (document.layers[objectId]);
}




function UpdateCategories(obj){
    
    //First Clear the other options     
    ClearExistingOptions(xDOM("Category", 0))
    ClearExistingOptions(xDOM("Topic", 0))

    // Now get our categories
    
    var SelectedGroup = obj[obj.selectedIndex].value
    
	xmlhttp.open("GET", "/getQuickBrowseData.aspx?level=2&group=" + SelectedGroup, true);
	xmlhttp.onreadystatechange=function() {
		if (xmlhttp.readyState==4) {
		    //alert(xmlhttp.responseText.length)
			if(xmlhttp.responseText.length!=0){
			    RepopulateOptions(xDOM("Category", 0), ConvertToOptionArray(xmlhttp.responseText), true, "All Categories", "")
			}else{
			    var arrNewOptions = [];
			    arrNewOptions[0] = {optText:"No Sections Found", optValue:""};
			    RepopulateOptions(xDOM("Category", 0), "", true, "All Categories", "")
			}
		}
	}
	xmlhttp.send(null)	
}




function UpdateArticles(obj){
    
    //First Clear the Topics
    ClearExistingOptions(xDOM("Topic", 0))

    // Now get our categories
    
    
    var SelectedGroup = xDOM("Age", 0)[xDOM("Age", 0).selectedIndex].value
    var SelectedSubGroup = obj[obj.selectedIndex].value
    
    //alert(SelectedSubGroup)
	xmlhttp.open("GET", "/getQuickBrowseData.aspx?level=3&group=" + SelectedGroup + "&subGroup=" + SelectedSubGroup, true);
	xmlhttp.onreadystatechange=function() {
		if (xmlhttp.readyState==4) {
		    //alert(xmlhttp.responseText.length)
			if(xmlhttp.responseText.length!=0){
			    RepopulateOptions(xDOM("Topic", 0),ConvertToOptionArray(xmlhttp.responseText),false, "", "")
			}else{
			    var arrNewOptions = [];
			    arrNewOptions[0] = {optText:"No Topics Found", optValue:""};
			    RepopulateOptions(xDOM("Topic", 0),arrNewOptions,false, "", "")
			}
		}
	}
	xmlhttp.send(null)	
}



function RepopulateOptions(objSelect, arrNewOptions, blnCreateALL, strAllText, selectedValue){
    // alert(arrNewOptions.length)
   
    //firstly create the "All" option if we need to
    if (blnCreateALL){
		var optALL = document.createElement('option');
		optALL.text = strAllText;
		optALL.value = "";    
		// Now load the Item into the array	
		try {
			objSelect.add(optALL, null) //elSel.add(elOptNew, null); // standards compliant; doesn't work in IE
		}
		catch(ex) {
			objSelect.add(optALL); //elSel.add(elOptNew); // IE only
		}	    
    
    }
    if(arrNewOptions!=''){
	    // Loop through the New options and create a new option
	    for (var loop=0; loop<arrNewOptions.length; loop++) {
		    var optObj = document.createElement('option');
		    optObj.text = arrNewOptions[loop].optText;
		    optObj.value = arrNewOptions[loop].optValue;
		    if (selectedValue == arrNewOptions[loop].optValue) { optObj.selected = true }
		    
            
		    // Now load the Item into the array	
		    try {
			    objSelect.add(optObj, null) //elSel.add(elOptNew, null); // standards compliant; doesn't work in IE
		    }
		    catch(ex) {
			    objSelect.add(optObj); //elSel.add(elOptNew); // IE only
		    }		
	    }
	}    
	//sortSelect(objSelect, true);
}



function ClearExistingOptions(objSelect) {
    if (objSelect) {
        for (var i = objSelect.options.length - 1; i >= 0; i--) {
            objSelect.options[i] = null;
        }
    }
}
function ConvertToOptionArray(strHTTPResponse){
	var arrNewOptions = [];
	if(strHTTPResponse.indexOf("|") != -1){ 
		var arrItems = strHTTPResponse.split('|')
		for(var i=0; i<arrItems.length; i++) {
			var arrItemProperties =  arrItems[i].split(',~^')
			arrNewOptions[i] = {optText:strTrim(arrItemProperties[0]), optValue:strTrim(arrItemProperties[1])};
		}		
	}else{
		var arrItems = strHTTPResponse
		var arrItemProperties =  arrItems.split(',')
		arrNewOptions[0] = {optText:strTrim(arrItemProperties[0]), optValue:strTrim(arrItemProperties[1])};
	}
	return arrNewOptions
}


function GoToArticle(){
 
    var objAge = xDOM("Age", 0)     
    var objCategory = xDOM("Category", 0)
    var objTopic = xDOM("Topic", 0)  
    if(objTopic.selectedIndex!=-1){
        var objURL = objTopic[objTopic.selectedIndex].value;
        document.location.href=objURL;
        return false;
    }else if(objAge.selectedIndex==-1){
        alert("Choose an age"); 
        return false;
    }else if(objCategory.selectedIndex==-1){
        alert("Choose a category"); 
        return false;
    }else{
     
        alert("Choose a topic"); 
        return false;
    }
}

function PostToSocial(url, site, objLink) {
    var baseURL = "http://raisingchildren.net.au";
    var strUrl = "";
    if (url) {
        strUrl = baseURL + url;
    } else {
        strUrl = location.href;
    }
    var pagetitle = escape($("title").text());    
    var strContent = "";

    switch (site) {
        case "facebook":
            strContent = 'http://www.facebook.com/sharer.php?u=' + strUrl + '&t=' + pagetitle;
            break;
        case "twitter":
            strContent = 'http://twitter.com/?status=' + strUrl;
            break;
        case "digg":
            strContent = 'http://digg.com/submit?url=' + strUrl + '&title=' + pagetitle;
            break;
        case "myspace":
            strContent = 'http://www.myspace.com/Modules/PostTo/Pages/?u=' + strUrl;
            break;
    }

    objLink.href = strContent;
    return true;    
}

function EmailFriend(id,context){

	//var objWindow = window.open('/MailtoFriend.aspx?id=' + id + '&context=' + context,'mailfriend','height=660,width=550,left=10,top=10,directories=0,fullscreen=0,location=0,menubar=0,scrollbars=1,resizable=0,status=0,toolbar=0');
    Shadowbox.open({
        content: '/MailtoFriend.aspx?id=' + id + '&context=' + context,
        player: "iframe",
        title: "",
        height: 625,
        width: 590
    });

}
function EmailFavourites() {
    Shadowbox.open({
        content: '/MailtoFriend.aspx?action=favs',
        player: "iframe",
        title: "",
        height: 650,
        width: 590
    });
}
function OpenFeedback(title){
	//var objWindow = window.open('/feedback.aspx?title=' + title,'feedback','height=660,width=550,left=10,top=10,directories=0,fullscreen=0,location=0,menubar=0,scrollbars=1,resizable=0,status=0,toolbar=0');
    Shadowbox.open({
        content: '/feedback.aspx?title=' + title,
        player: "iframe",
        title: "",
        height: 660,
        width: 590
    });
}
function RateThisPage(id){
//	var intWidth = 528
//	var intHeight = 280
//	var intLeft = (screen.width - intWidth) / 2;
//	var intTop = (screen.height - intHeight - 35) / 2;
//	var objWindow = window.open('/RateThisPage.aspx?id=' + id,'ratepage','height=' + intHeight + ',width=' + intWidth + ',left=' + intLeft + ',top=' + intTop + ',directories=0,fullscreen=0,location=0,menubar=0,scrollbars=1,resizable=0,status=0,toolbar=0');
    Shadowbox.open({
        content: '/RateThisPage.aspx?id=' + id,
        player: "iframe",
        title: "",
        height: 300,
        width: 590
    });
}

function UpdatePageRating(id){
	var arrData

	xmlhttp2.open("GET", "/getAssetRating.aspx?id=" + id + "&t=" + Math.floor(Math.random() * 1000), true);
	xmlhttp2.onreadystatechange=function() {
		if (xmlhttp2.readyState==4) {
			if(xmlhttp2.responseText.length!=0){
				arrData = xmlhttp2.responseText.split('|')
				document.getElementById('imgRating').src = '/css/images/' + arrData[0] + '_star.gif'
				document.getElementById('NumRatings').innerHTML = '<small>(' + arrData[1] + ' ratings)</small>'
			}
		}
	}
	xmlhttp2.send(null)	
	
}

function PrintPage(){
    var i, a, main;
        
    // Find the print stylesheet and update it's href to the print one
    for(i=0; (a = document.getElementsByTagName("link")[i]); i++) {
         if(a.getAttribute("rel").indexOf("style") != -1
            && a.getAttribute("title")) {
            if(a.getAttribute("title") == "rcnprint"){
                a.href = "/css/rcn-print.css";
            }
        }
    }
    //alert(document.getElementById("Content").style.width)
    //Print
    if(window.print()){
        window.print()
    }

    //After 15 seconds, set the print stylesheet back to the empty one
    //setTimeout(DisablePrint,15000);
}

function DisablePrint(){
    
    // Find the print stylesheet and update it's href to the empty one
    for(i=0; (a = document.getElementsByTagName("link")[i]); i++) {
         if(a.getAttribute("rel").indexOf("style") != -1
            && a.getAttribute("title")) {
            if(a.getAttribute("title") == "rcnprint"){
                a.href = "/css/rcn-print-null.css";
            }
        }
    }
}

function strTrim(strText) {
	if(typeof strText!='undefined' && strText!=''){
	    for (i = 0; i < strText.length; ++i) {
			if (strText.charAt(i) != ' ') break;
		}
		if (i >= strText.length) return ('');
		if (i > 0) strText = strText.substring(i, strText.length);
		for (j=strText.length-1; j > i; --j) {
			if (strText.charAt(j) != ' ') break;
		}
		if (j < strText.length -1)
			strText = strText.substring(0, j+1);
	}
	return strText;
}

function clearSearch(){
    xDOM("againq", 0).value="";
    xDOM("againq", 0).focus();
}

function wordhighlight(aSourceObject, aWords){
	//Extract HTML Tags
	regexp=/<[^<>]*>/ig;
	vHTMLArray = aSourceObject.innerHTML.match(regexp);

	//Replace HTML tags
	vStrippedHTML = aSourceObject.innerHTML.replace(regexp,"$!$");

	//Replace search words
	regexp= new RegExp ("(" + aWords + ")", "gi");
	vTemp = vStrippedHTML.replace(regexp,'<span class="highlightWord">$1</span>');

	//Reinsert HTML
	for(i=0;vTemp.indexOf("$!$") > -1;i++){
	vTemp = vTemp.replace("$!$", vHTMLArray[i]);
	}
	
	//Disply Result
	aSourceObject.innerHTML = vTemp;
}

function CheckCheckBoxes(objCheckbox){
	var blnStatus
	var intItemID = objCheckbox.id.substring(8,objCheckbox.id.length)

	if (objCheckbox.checked){
		blnStatus = true
	}else{
		blnStatus = false
	}
	//alert(intItemID)
    for(i=0; (chBx = document.getElementsByTagName("input")[i]); i++) {
        if(chBx.getAttribute("id")){
            if(chBx.getAttribute("id").indexOf("Article" + intItemID + "-") != -1) {
                chBx.checked = blnStatus;
            }
        }
    }
}
function CheckChapter(objCheckbox){
	if (objCheckbox.checked){ // Its checked so make sure the Chapter is checked.
        
        var objChapter = document.getElementById("Chapter-" + objCheckbox.getAttribute("id").substring(7,objCheckbox.getAttribute("id").indexOf("-")))
        objChapter.checked = true;

	}
}

function PopulateMapDetails(intID){
	var objFrame = xDOM("FooterMap",0);
	if(intID != ''){
	    objFrame.style.display = "block";
		objFrame.src = "/MapFooter.aspx?id=" + intID; 
		
	}
	
}

function UnPopulateMapDetails() {
    var objFrame = xDOM("FooterMap", 0);
    objFrame.style.display = "none";

}

function left(str, n){
	if (n <= 0)
	    return "";
	else if (n > String(str).length)
	    return str;
	else
	    return String(str).substring(0,n);
}

function UpdateExternalLinks(source,name)
{
	var i
	var pagelinks = document.links
	var host = document.location.host
	host = host.replace('www.','')
	host = host.replace('verve.','')
	host = host.replace('dev.','')
	
	for (i=0; i<document.links.length; i++)
	{
		if(pagelinks[i].host.indexOf(host) ==-1 && left(pagelinks[i].href,7) == 'http://')
		{
			pagelinks[i].href = '/link.aspx?url=' + encodeURIComponent(pagelinks[i].href) + '&source=' + source + '&name=' + name
		}
	}


}

function newExternalURL(aspxId)
{
	top.document.location.href = 'http://' + top.document.location.host + '/link.aspx?id=' + aspxId
}

// ----------------------------------------------
// StyleSwitcher functions written by Paul Sowden
// http://www.idontsmoke.co.uk/ss/
// - - - - - - - - - - - - - - - - - - - - - - -
// For the details, visit ALA:
// http://www.alistapart.com/stories/alternate/

function setActiveStyleSheet(title,intClick) {
  var i, a, main, cssTitle;
//  if (BrowserWidth >= BrowserLarge) {
	  cssTitle = title
//  }else{
//	  cssTitle = title + "800"
//  }
  //alert(cssTitle)
  for(i=0; (a = document.getElementsByTagName("link")[i]); i++) {
    if(a.getAttribute("rel").indexOf("style") != -1 && a.getAttribute("title") && a.getAttribute("title")!='rcnprint') {
      a.disabled = true;
      if(a.getAttribute("title") == cssTitle) a.disabled = false;
    }
  }
  SetCookie('fonttextsize',title,null,'/');
  FixIcons();
  if(intClick == 1){FixHomeHeros();}
}

function getActiveStyleSheet() {
  var i, a;
  for(i=0; (a = document.getElementsByTagName("link")[i]); i++) {
    if(a.getAttribute("rel").indexOf("style") != -1 && a.getAttribute("title") && !a.disabled) return a.getAttribute("title");
  }
  return null;
}
function GetCookie (name) {
  var arg = name + "=";
  var alen = arg.length;
  var clen = document.cookie.length;
  var i = 0;
  while (i < clen) {
    var j = i + alen;
    if (document.cookie.substring(i, j) == arg)
      return getCookieVal (j);
    i = document.cookie.indexOf(" ", i) + 1;
    if (i == 0) break; 
  }
  return null;
}
function SetCookie (name,value,expires,path,domain,secure) {
  document.cookie = name + "=" + escape (value) +
    ((expires) ? "; expires=" + expires.toGMTString() : "") +
    ((path) ? "; path=" + path : "") +
    ((domain) ? "; domain=" + domain : "") +
    ((secure) ? "; secure" : "");
}
function DeleteCookie (name,path,domain) {
  if (GetCookie(name)) {
    document.cookie = name + "=" +
      ((path) ? "; path=" + path : "") +
      ((domain) ? "; domain=" + domain : "") +
      "; expires=Thu, 01-Jan-70 00:00:01 GMT";
  }
}
function getCookieVal (offset) {
  var endstr = document.cookie.indexOf (";", offset);
  if (endstr == -1)
    endstr = document.cookie.length;
  return unescape(document.cookie.substring(offset, endstr));
}

// This function resizes the Article Icons so they are the correct height
function FixIcons(){
	if(document.getElementById('ArticleHeader') && PageLoaded){
		var IconHeight = 0
		if(document.all){
			IconHeight = document.getElementById('ArticleHeader').offsetHeight;
		}else{
			IconHeight = document.getElementById("ArticleHeader").clientHeight;
		}
		//alert(IconHeight);
		if(document.getElementById("IconList")){
			if(IconHeight > 106){
				document.getElementById("Icons").className = "largestHeight";
				document.getElementById("IconList").className = "largestHeight";
			}else if(IconHeight > 90){
				document.getElementById("Icons").className = "largeHeight";
				document.getElementById("IconList").className = "largeHeight";
			}else{
				document.getElementById("Icons").className = "";
				document.getElementById("IconList").className = "";
			}
		}
	}
}


function getHeroHeight(theElt){
		if(document.all){
				tmphght = document.getElementById(theElt).offsetHeight - 15;
		}
		else{
				docObj = document.getElementById(theElt);
				var tmphght1 = document.defaultView.getComputedStyle(docObj, "").getPropertyValue("height");
				tmphght = tmphght1.split('px');
				tmphght = tmphght[0] - 10;
		}
		return tmphght;
}
function FixHomeHeros(){
	if(document.getElementById("HeroTiles")){
		// Firstly reset the heights
		var i
		
		var heroNode = document.getElementById("HeroTiles")
		for (i=0;i < heroNode.childNodes.length;i++) {
			if(heroNode.childNodes[i].nodeName == "LI"){
				heroNode.childNodes[i].style.height = "auto"
			}
		}
		
		var intHeroHeight = getHeroHeight("SkipContent")
		//alert(intHeroHeight)
		for (i=0;i < heroNode.childNodes.length;i++) {
			if(heroNode.childNodes[i].nodeName == "LI"){
				heroNode.childNodes[i].style.height = intHeroHeight + "px"
			}
		}
	}
}

function FixFlash(strFlashPath, height800, width800, height1024, width1024, blnSwitchImage, flash1024src, flash1024width, flash1024height, flashID){
	// Fix the wrapper div height and width
	//alert(BrowserWidth + "-" + BrowserLarge);
	//alert("http://rcn.dev.lateralsystems.net" + strFlashPath)
	
	var blnhasViewed
	if(get_cookie("viewed" + flashID) == "yes"){
	    blnhasViewed = "true";
	}else{
	    blnhasViewed = "false";
	}
	
	var objFlashWrapper = xDOM("FlashWrapper", 1)
//	if (BrowserWidth >= BrowserLarge) {
		
		objFlashWrapper.height = height1024 + 'px';
		objFlashWrapper.width = width1024 + 'px';
		objFlashWrapper.overflow = 'hidden';
		
		/*
		if(xDOM("flashMap", 0) && blnSwitchImage){
			var objFlashImage = xDOM("flashMap", 0)
			objFlashImage.src = flash1024src;
			objFlashImage.width = flash1024width;
			objFlashImage.height = flash1024height;
			objFlashImage.useMap = "#Map1024";
		}
		*/
		
//		if (xDOM("flashMap", 0) && blnSwitchImage) {
//			xDOM("flashMap", 1).display = "none";
//		}else 
//		if(xDOM("flashMap1024", 0) && blnSwitchImage){
//			xDOM("flashMap1024", 1).display = "none";
//		}
		
		var fo = new SWFObject(strFlashPath + "?hasViewed=" + blnhasViewed, "RaisingChildrenFlash", width1024, height1024, "6", "#ffffff", true);
		fo.addParam("wmode", "transparent");
		fo.write("flashContent");			
		
		
//	}else{
		// 800
//		objFlashWrapper.height = height800 + 'px';		
//		objFlashWrapper.overflow = 'hidden';

//		var fo = new SWFObject(strFlashPath + "?hasViewed=" + blnhasViewed, "RaisingChildrenFlash", width800, height800, "6", "#ffffff", true);
//		fo.addParam("wmode", "transparent");
//		fo.write("flashContent");			
//	}
	set_cookie("viewed" + flashID, "yes", 2020, 01, 01 );

}

function FixFlvFlash(strContainerID, strFlashPath, width, height, flashvars){

	var fo = new SWFObject(strFlashPath, "FlowPlayer", width, height, "7", "#ffffff", true);
	fo.addVariable("config", flashvars);
	fo.addParam("wmode", "transparent");
	fo.write(strContainerID);	
}
function FixFullscreenFlvFlash(strContainerID, strFlashPath, width, height, flashvars){
	var fo = new SWFObject(strFlashPath, "FlowPlayer", width, height, "7", "#ffffff", true);
	fo.addVariable("config", flashvars);
	fo.write(strContainerID);	
	
}

function FixHomeFlash(){
	// Fix the wrapper div height and width
//	if (BrowserWidth >= BrowserLarge) {
//		xDOM("HomeFlashImage", 1).display = "none";
//	}else{
//		xDOM("HomeFlashImage1024", 1).display = "none";
//	}
	var fo = new SWFObject("/includes/hompageFlash.swf", "RaisingChildrenHomeFlash", "100%", "100%", "6", "#ffffff", true);
	fo.addParam("wmode", "transparent");
	fo.write("flash");	
}
function ShowDetails(TextID){
	xDOM(TextID, 1).display = "block";
}

function HideDetails(TextID){
	xDOM(TextID, 1).display = "none";
}


function ToggleMovieDefinition(strObjNumber){
	var objDef = xDOM("MovieDefinitionContent" + strObjNumber, 1)
	var objDefImg = xDOM("defimg" + strObjNumber, 0)
	var objDefInfo = xDOM("defInfo" + strObjNumber, 0)
	if(objDef.display == "block"){
		objDef.display = "none";
		objDefImg.src = "/css/images/plus.gif";
		objDefInfo.innerHTML = "What is this?";
	}else{
		objDef.display = "block";
		objDefImg.src = "/css/images/minus.gif";
		objDefInfo.innerHTML = "Hide Definition";
	}
}

function ValidEmail(s){
    var i = 1;
    var sLength = s.length;
    while ((i < sLength) && (s.charAt(i) != "@"))
    { i++
    }
    if ((i >= sLength) || (s.charAt(i) != "@")) return false;
    else i += 2;
    while ((i < sLength) && (s.charAt(i) != "."))
    { i++
    }
    if ((i >= sLength - 1) || (s.charAt(i) != ".")) return false;
    else return true;
} 


function get_cookie ( cookie_name )
{
  var results = document.cookie.match ( cookie_name + '=(.*?)(;|$)' );

  if ( results )
    return ( unescape ( results[1] ) );
  else
    return null;
}
function set_cookie ( name, value, exp_y, exp_m, exp_d, path, domain, secure )
{
  var cookie_string = name + "=" + escape ( value );

  if ( exp_y )
  {
    var expires = new Date ( exp_y, exp_m, exp_d );
    cookie_string += "; expires=" + expires.toGMTString();
  }

  if ( path )
        cookie_string += "; path=" + escape ( path );

  if ( domain )
        cookie_string += "; domain=" + escape ( domain );
  
  if ( secure )
        cookie_string += "; secure";
  
  document.cookie = cookie_string;
}

function pausecomp(millis)
{
var date = new Date();
var curDate = null;

do { curDate = new Date(); }
while(curDate-date < millis);
} 

function Go(dropdown)
{
    var url = dropdown.options[dropdown.selectedIndex].value;
    if(url != "")
    {
        document.location.href = url;
    }
    else
    {
        return false;
    }
}



// Functions for state / region category display
function UpdateSearchRegions(obj, SelectedRegion) {

    //First Clear the Topics
    ClearExistingOptions(xDOM("q_region", 0))

    // Now get our categories


    var SelectedState = xDOM("q_state", 0)[xDOM("q_state", 0).selectedIndex].value

    //alert(SelectedSubGroup)
    xmlhttp.open("GET", "/remote/getRegionForums.aspx?parents=" + SelectedState, true);
    xmlhttp.onreadystatechange = function() {
        if (xmlhttp.readyState == 4) {
            //alert(xmlhttp.responseText)
            if (xmlhttp.responseText.length != 0) 
            {
                RepopulateOptions(xDOM("q_region", 0), ConvertToOptionArray(xmlhttp.responseText), true, "Select region", SelectedRegion)
            }
        }
    }
    xmlhttp.send(null)
}

function addSelectOption(objSelect, objOption) {
    // Now load the Item into the array	
    try {
        objSelect.add(objOption, null) //elSel.add(elOptNew, null); // standards compliant; doesn't work in IE
    }
    catch (ex) {
        objSelect.add(objOption); //elSel.add(elOptNew); // IE only
    }	    

}

function selectOption(selectid, value) {

    var obj = xDOM(selectid, 0)
    if (obj) {
        for (i = 0; i < obj.length; i++) {
            if (obj.options[i].value == value) {
                obj.selectedIndex = i;
                break;
            }
        }
    }
}

function CheckClick(obj){
    isAlert = true;
    for(i=1;i<=4;i++)
    {
        if (document.getElementById("subscribe" + i).checked)
        {
            isAlert = false;
            break;
        }

    }
    if (document.getElementById("subscribe15").checked)
    {
        isAlert = false;
    }
        
    if (isAlert)
    {
        alert("Please check the box(es) to indicate which email(s) you would like to receive.");
        return false;
    }
    else
        return true;
}
(function($) {
    $.fn.ellipsis = function(enableUpdating) {
        var s = document.documentElement.style;
        //if (!('textOverflow' in s || 'OTextOverflow' in s)) {
        return this.each(function() {
            var el = $(this);
            if (el.css("overflow") == "hidden") {
                var originalText = el.html();
                var w = el.width();
                var h = el.height();

                if ($(el).css("max-height") != "none") { h = $(el).css("max-height").replace("px",""); }

                var t = $(this.cloneNode(true)).hide().css({
                    'position': 'absolute',
                    'height': 'auto',
                    'max-height': 'none',
                    'overflow': 'visible',
                    'max-width': w
                });
                el.after(t);

                var text = originalText;
                while (text.length > 0 && t.height() > h) {
                    text = text.substr(0, text.length - 1);
                    t.html(text + "...");
                }
                el.html(t.html());

                t.remove();

                if (enableUpdating == true) {
                    var oldH = el.height();
                    setInterval(function() {
                        if (el.height() != oldH) {
                            oldH = el.height();
                            el.html(originalText);
                            el.ellipsis();
                        }
                    }, 200);
                }
            }
        });
        //} else return this;
    };
})(jQuery);
