// 090926jw_1

// NLC Code.
function dropdownredirect(dropdown)
{
    var URL = dropdown.options[dropdown.selectedIndex].value;
    document.frmRedirect.action = URL;
    document.frmRedirect.submit();
}

function doClear(theText) {
    if (theText.value == theText.defaultValue)
 	{
         theText.value = ""
	}
}
 
// The code below was created by CCS Developer - John Wallace

// Retrieve an object (backward compatible to NN4 and IE4).
function getElement(obj) {
   if (document.getElementById)
      if (typeof obj == "string") {
         return document.getElementById(obj);
      }
      else {
         return obj;
      }

   if (document.all)
      if (typeof obj == "string")
         return document.all(obj);
      else
         return obj;

   if (document.layers)
      if (typeof obj == "string")
         // just one layer deep
         return document.layers[obj];
      else
         // can be a nested layer
         return obj;
}


// Redirect to url associated with selected option in select element.
function selectOnChangeRedirect(select) {
    if (select) {
        var url = select.options[select.selectedIndex].value;
     
        var re = /^(https:\/\/|http:\/\/|)([\w\.]*)(.*)/i;
        var matches = re.exec(url);
        var host = matches[2];
        var path = matches[3];

        // CCS links without a "r" query parameter are submitted through a form.
        var useSubmit = false;
        if (host == "" || host == "cancer.ca" || host == "www.cancer.ca" || host == "cancer-ca" || host == "cancer6-ca")
        {
            path = path.replace(/\%20/, " ");
            re = /^(\/sitecore\/content)?(\/home)?\/(canada-wide|alberta-nwt|british columbia-yukon|manitoba|new brunswick|newfoundland-labrador|nova scotia|nunavut|ontario|prince edward island|quebec|saskatchewan)(\/|\.)/i;
            if (re.test(path))
            {
                re = /(\?|&)r=.*?(&|$)/i;
                if (re.test(path))
                    url = url.replace(re, "");
                else
                    useSubmit = true;
            }
        }

        if (useSubmit)
        {
            document.frmRedirect.action = url;
            document.frmRedirect.submit();
        }
        else
            window.location.href = url;
    }
}


// Redirect to url associated with selected option in select element.
// Uses window location so query parameters are not dropped.
function selectOnChangeRedirect2(select){
    if (select) {
        var url = select.options[select.selectedIndex].value;
        window.location.href = url;
    }
}


// Redirect to url associated with selected option in select element.
function selectOnChangeRedirectHandler(evt){
    evt = (evt) ? evt : ((window.event) ? window.event : null);
    if (evt) {
        var select = (evt.target) ? evt.target : ((evt.srcElement) ? evt.srcElement : null);
       
if (select) {
            var url = select.options[select.selectedIndex].value
            window.location.href = url 
        }
    }
}



// Select the id from the main content drop down and if the ID matches the format specified then call the
//selectOnChangeRedirect function to do the forward
function selectOnChangeRedirectHandler2(evt){
    evt = (evt) ? evt : ((window.event) ? window.event : null);
   
if (evt) {
        var select = (evt.target) ? evt.target : ((evt.srcElement) ? evt.srcElement : null);
        if (select) {
            if (id == "selectlink\d*"){
      
             selectOnChangeRedirect(select);
        }
     }
  }
}


// This function redirects the specified select element.  Either the element
// can be given, or the id of the element.
function forwardDropdownLink(element)
{
    var select = getElement(element);
    if (select)
        select.onchange = selectOnChangeRedirectHandler;
}



// Open url associated with selected option in a pop up window.
function selectOnChangePopUp(select){
    if (select) {
        var url = select.options[select.selectedIndex].value;
        var day = new Date();
        var id = day.getTime();
        window.open(url, id, select.openOptions);
    }
}


// Open url associated with selected option in a pop up window.
function selectOnChangePopUpHandler(evt){
    evt = (evt) ? evt : ((window.event) ? window.event : null);
    if (evt) {
        var select = (evt.target) ? evt.target : ((evt.srcElement) ? evt.srcElement : null);
        if (select) {
            var url = select.options[select.selectedIndex].value;
            var day = new Date();
            var id = day.getTime();
            window.open(url, id, select.openOptions);
        }
    }
}



// This function sets up popping up a window in response to selecting an option in the specified 
// select element.  Either the element can be given, or the id of the element.
function popUpDropdownLink(element, popUpWidth, popUpHeight)
{
    var select = getElement(element);
    if (select)
    {
        select.onchange = selectOnChangePopUpHandler;
        select.openOptions = 
            'toolbar=0,scrollbars=0,location=0,statusbar=0,menubar=0,resizable=0'
            + ',width=' + (popUpWidth ? popUpWidth : '450')
            + ',height=' + (popUpHeight ? popUpHeight : '350')
    }
}



// Open the given url in a pop up window.
function popUp(url){
    var day = new Date();
    var id = day.getTime();
    window.open(url, id, 'toolbar=0,scrollbars=0,location=0,statusbar=0,menubar=0,resizable=0,width=450,height=350');
}

function collapse_block (block, close, open){ 
    close = document.getElementById(close);
    open = document.getElementById(open);
    comment_body = document.getElementById(block);
    if (comment_body.style.display=='block' || !comment_body.style.display) {
        comment_body.style.display = 'none';
        close.style.display = 'none';
        open.style.display = 'block';
    }
    else {
        comment_body.style.display = 'block';
        close.style.display = 'block';
        open.style.display = 'none'; 
    }
}

/* Begin Font Style Changer Functions*/
function fontsizeup() {
  active = getActiveStyleSheet();
  switch (active) {
    case 'A--' : 
      setActiveStyleSheet('A-');
      break;
    case 'A-' : 
      setActiveStyleSheet('A');
      break;
    case 'A' : 
      setActiveStyleSheet('A+');
      break;
    case 'A+' : 
      setActiveStyleSheet('A++');
      break;
    case 'A++' :
      break;
    default :
      setActiveStyleSheet('A+');
      break;
  }
}

function fontsizedown() {
  active = getActiveStyleSheet();
  switch (active) {
    case 'A++' : 
      setActiveStyleSheet('A+');
      break;
    case 'A+' : 
      setActiveStyleSheet('A');
      break;
    case 'A' : 
      setActiveStyleSheet('A-');
      break;
    case 'A-' : 
      setActiveStyleSheet('A--');
      break;
    case 'A--' : 
       break;
    default :
      setActiveStyleSheet('A-');
      break;
  }
}

function setActiveStyleSheet(title) {
  var links = document.getElementsByTagName("link");
  for(var i = 0; i < links.length; i++) {
    var a = links[i];
    if (a.getAttribute("rel") == "alternate stylesheet" && a.getAttribute("title"))
    {
      a.disabled = true;
      if (a.getAttribute("title") == title)
        a.disabled = false;
    }
  }
}

function getActiveStyleSheet() {
  var links = document.getElementsByTagName("link");
  for(var i = 0; i < links.length; i++) {
    var a = links[i];
    if (!a.disabled && a.getAttribute("rel") == "alternate stylesheet" && a.getAttribute("title"))
        return a.getAttribute("title");
  }
  return null;
}

function getPreferredStyleSheet() {
  return ('A');
}

function createCookie(name,value,days) {
  if (days) {
    var date = new Date();
    date.setTime(date.getTime()+(days*24*60*60*1000));
    var expires = "; expires="+date.toGMTString();
  }
  else expires = "";
  document.cookie = name+"="+value+expires+"; path=/";
}

function readCookie(name) {
  var nameEQ = name + "=";
  var ca = document.cookie.split(';');
  for(var i=0;i < ca.length;i++) {
    var c = ca[i];
    while (c.charAt(0)==' ') c = c.substring(1,c.length);
    if (c.indexOf(nameEQ) == 0) return c.substring(nameEQ.length,c.length);
  }
  return null;
}
/* End Font Style Changer Functions*/



/*this is the add this image on the right nav*/
function bookmarkPage(isMainPage) {
  var re = /\/(canada\-wide|nunavut).aspx$/i;
    var isStandardPage = !re.test(location.pathname);

     var english = /[?&]sc\_lang\=en/i;  
     var isEnglish = english.test(location.search);
   
    if (isStandardPage)
        document.write('<br><br>');
    if (isMainPage || isStandardPage) {
        if (isEnglish)
            document.write('<div onmouseover="return addthis_open(this, \'\', \'[URL]\', \'[TITLE]\')" onmouseout="addthis_close()" onclick="return addthis_sendto()"><img src="/~/media/CCS/Global/Design/Right_nav_images/English/share_this_page_en.ashx" width ="208" border="0" alt="" /></div>');
        
        else
            document.write('<div onmouseover="return addthis_open(this, \'\', \'[URL]\', \'[TITLE]\')" onmouseout="addthis_close()" onclick="return addthis_sendto()"><img src="/~/media/CCS/Global/Design/Right_nav_images/French/share_this_page_fr.ashx" width = "208" border="0" alt="" /></div>');


}
}

/*this is the add this image on the right nav*/
function Addthispage(isMainPage) {
  var div = /\/(Alberta\-NWT|British%20Columbia\-Yukon|Manitoba|New%20Brunswick|NewFoundland\-Labrador|Nova%20Scotia|Ontario|Prince%20Edward%20Island|Quebec|Saskatchewan).aspx$/i;
    
  var isStandardDivPage = !div.test(location.pathname);

    var english = /[?&]sc\_lang\=en/i;  
     var isEnglish = english.test(location.search);
   
    if(isStandardDivPage){
     document.write('<br><br>');
      }


    
    if (isMainPage) {
        if (isEnglish)
            document.write('<div onmouseover="return addthis_open(this, \'\', \'[URL]\', \'[TITLE]\')" onmouseout="addthis_close()" onclick="return addthis_sendto()"><img src="/~/media/CCS/Global/Design/Right_nav_images/English/share_this_page_en.ashx" width ="208" border="0" alt="" /></div>');
        
        else
            document.write('<div onmouseover="return addthis_open(this, \'\', \'[URL]\', \'[TITLE]\')" onmouseout="addthis_close()" onclick="return addthis_sendto()"><img src="/~/media/CCS/Global/Design/Right_nav_images/French/share_this_page_fr.ashx" width = "208" border="0" alt="" /></div>');


}
}



function NS(isMainPage) {
  var div = /\/Nova%20Scotia\/Support%20Services*/i;
    
  var isStandardDivPage = div.test(location.pathname);
   if (isMainPage){
    if(isStandardDivPage){
    document.write('<a href="http://canadiancancersociety.na5.acrobat.com/p62248104/" target="_blank"><img src="/~/media/CCS/Nova%20Scotia/Images%20list/English%20Images/Graphics/video.ashx" width ="208" border="0" alt="" /></a>');
      }

}
}


function trackMedia(evt) {
    evt = (evt) ? evt : ((window.event) ? window.event : null);
    if (evt && typeof(pageTracker)!="undefined") {
        //create an element variable
        var elem = (evt.target) ? evt.target : evt.srcElement;
        //checks if parent element is a link instead, due to formatting tags
        if (elem.nodeName.toLowerCase() != "a" && !elem.href && elem.parentNode.href && elem.parentNode.nodeName.toLowerCase() == "a")
            elem = elem.parentNode;
        //checks if the element is a link
        if (elem.nodeName.toLowerCase() == "a" && elem.href) {
            var url = elem.href;
            url = url.replace(/\%20/g, " ");
            url = url.toLowerCase();

            var re = /.*\/media\/(ccs|research).*\.ashx/i;
            var siteMatch = re.exec(url);

            if (siteMatch) {
                if (siteMatch[1] == "ccs")
                    re = /.*media\/ccs\/(canada wide|alberta|british columbia-yukon|manitoba|new brunswick|newfoundland-labrador|nova scotia|nunavut|ontario|prince edward island|quebec|saskatchewan)\/.*\/(english files heading|english files|liste de fichiers|.*)\/(.*)\/(.*)\.ashx/i;
                if (siteMatch[1] == "research")
                    re = /.*media\/(research)\/.*\/(english files heading|english files|liste de fichiers|.*)\/(.*)\/(.*)\.ashx/i;
                
                var fileMatch = re.exec(url);
                
                if (fileMatch) {
                    if (fileMatch[2] == "english files heading" || fileMatch[2] == "english files")
                        fileMatch[2] = "english";
                    else if (fileMatch[2] == "liste de fichiers")
                        fileMatch[2] = "french";
                    else
                        fileMatch[2] = "unknown";
                    
                    var division = fileMatch[1];
                    var lang = fileMatch[2];
                    var folderName = fileMatch[3];
                    var fileName = fileMatch[4];
                    
                    pageTracker._trackPageview(division+"/files/"+lang+"/"+folderName+"/"+fileName);
                }
            }
        }
    }
    return true;
}


/*
window.onload = function(e) {
    var cookie = readCookie("style");
    var title = cookie ? cookie : getPreferredStyleSheet();
    setActiveStyleSheet(title);
}
*/

addEvent(window, "load",
    function() {
        addEvent(document.getElementById("body"), "click", 
            function(evt) {
                return trackMedia(evt);
       		}
	        );

	    var cookie = readCookie("style");
	    var title = cookie ? cookie : getPreferredStyleSheet();
	    setActiveStyleSheet(title);
    }
    );

window.onunload = function(e) {
    var title = getActiveStyleSheet();
    createCookie("style", title, 365);
}

function addEvent(elem, evtType, func) {
    if (elem == null)
        return;
    //Microsoft IE
    if (elem.attachEvent)
        elem.attachEvent("on" + evtType, func);
    //W3C Model, Firefox
    else if (elem.addEventListener)
        elem.addEventListener(evtType, func, false);
     //Others
    else
        elem["on" + evtType] = func;
}      



var cookie = readCookie("style");
var title = cookie ? cookie : getPreferredStyleSheet();
if (title == "null") {
  title = getPreferredStyleSheet();
}

setActiveStyleSheet(title);