// Needs to be included just above the footer, Will add logos to pdf links external links and email addresses. - JC
// Do not edit below here
// Select all links on the page
if(typeof(editorFrame) == 'undefined') {
var hrefs_list = document.getElementsByTagName("a");
var link_path_check = "";
// Step through the array of links
for (var l = 0; l < hrefs_list.length; l++) {
    try {
		// select the links path
        var link_path_check = hrefs_list[l].pathname;
        // check whether it ends in .pdf
        if (link_path_check.match(/\.(pdf)$/)) {
            //send link to pdf icon function
            PDFicon(hrefs_list[l]);
        }
        // If the links not a pdf check whther its an external link.
        if (! (link_path_check.match(/\.(pdf)$/))) {
			// sends link to the external link icon function
            ExternalIcon(hrefs_list[l]);
        }
        // select the links href
        var link_path_check = hrefs_list[l].href;
        // Check if link is an email link
        if (link_path_check.match("mailto") && !link_path_check.match("EmailAddress@wigan.gov.uk")) {
            // sends link to the email icon function
            Emailicon(hrefs_list[l]);
        }
    } catch(err) {}
}
}
// Add pdf icon to links that are a pdf
function PDFicon(obj) {
	// check if PDF icons are enabled, set in web.config
    if (doPDF == true) {
		// Select links text
        NewHTML = obj.innerHTML;
        // Replace encoded spaces with a unencoded space, make it easier to find what we are looking for
        NewHTML = NewHTML.replace(/&nbsp;/ig, ' ');
        // convert text to lower case
        PDFcheck = NewHTML.toLowerCase(); 
        // Check if the link text contains .pdf
        if (PDFcheck.match(".pdf")) {
			// Replace the (.pdf, with our icon
            NewHTML = NewHTML.replace(/\(.pdf, /i, "<img src='http://www.wigan.gov.uk/pub/images/icons/acrobat.gif' style='border:0;' height='16' width='16' alt='(PDF file)'> (");
        } else {
			// Place pdf icon at the end of the link text
            NewHTML = NewHTML + "<img src='http://www.wigan.gov.uk/pub/images/icons/acrobat.gif' style='border: 0;' height='16' width='16' alt='(PDF file)'>";
        }
        // update the links text.
        obj.innerHTML = NewHTML;
    }
}
function ExternalIcon(obj) {
	// check if External link icons are enabled, set in web.config
    if (doExternal == true) {
		// Select links text
        NewHTML = obj.innerHTML;
        // Replace encoded spaces with a unencoded space, make it easier to find what we are looking for
        NewHTML = NewHTML.replace(/&nbsp;/ig, ' ');
        // Replace (External link) with our icon
        NewHTML = NewHTML.replace(/\(External link\)/i, " <img src='http://www.wigan.gov.uk/pub/images/icons/ExternalLinkRed.gif' style='border:0;' alt='(External Link)'>");
        // update the links text.
        obj.innerHTML = NewHTML;
    }
}

function Emailicon(obj) {
	// check if email icons are enabled, set in web.config
    if (doMail == true) {
		// Select links text
        NewHTML = obj.innerHTML;
        // Add email icon
        NewHTML = NewHTML + " <img src='http://www.wigan.gov.uk/pub/images/icons/mail.gif' style='border:0;' height='16' width='16' alt='(Email Link)'>";
        // update the links text.
        obj.innerHTML = NewHTML;
    }
}