
// Adds event to window.onload without overwriting currently 
// assigned onload functions.

function addLoadEvent(func) {    
  var oldonload = window.onload;
  if (typeof window.onload != 'function') {
    window.onload = func;
  } 
  else {
    window.onload = function() {
      oldonload();
      func();
    }
  }
}


// set target for external links (rel="external")

function external() { 
  if(!document.getElementsByTagName)return; 
  var anchors = document.getElementsByTagName("a"); 
  for(var i=0;i<anchors.length;i++) { 
    var anchor = anchors[i]; 
    if(anchor.getAttribute("href") && anchor.getAttribute("rel") == "external")anchor.target = "_blank";
    else if(anchor.getAttribute("href") && anchor.getAttribute("type") == "external")anchor.target = "_blank";
  } 
} 

addLoadEvent(external);

// ------------- print page popup -------------

function printpage(title, date, url) { 

  if(document.getElementById!= null) { 
    var divid = "print-area";
    var html = '<?'+'xml version="1.0" encoding="UTF-8"?>\n';
    html += '<!DOCTYPE html>\n';
    html += '<html xmlns="http://www.w3.org/1999/xhtml" lang="en">\n<head>\n';
    html += '<title>' + title + '</title>\n';
        html += '<link rel="stylesheet" type="text/css" href="http://classifieds.shuswapnews.com/wp-content/themes/shuswapnews-classifieds-10-03-10/common/stylesheets/template/shuswapnews-classifieds-template.css" />\n';
        html += '<link rel="stylesheet" type="text/css" href="http://classifieds.shuswapnews.com/wp-content/themes/shuswapnews-classifieds-10-03-10/common/stylesheets/content/shuswapnews-classifieds-content.css" />\n';
        html += '<link rel="stylesheet" type="text/css" href="http://classifieds.shuswapnews.com/wp-content/themes/shuswapnews-classifieds-10-03-10/common/stylesheets/content/shuswapnews-classifieds-print.css" />\n';
        html += '<link rel="stylesheet" type="text/css" href="http://classifieds.shuswapnews.com/wp-content/plugins/wp-page-numbers/classic/wp-page-numbers.css" />\n';
    html += '</he' + 'ad>\n<body>\n';
    var printPageElem = document.getElementById(divid); 
    if(printPageElem != null) {
      html += '\n\n';
      if(title != '' && date != '' && url != '') {
        html += '<div style="font-size:11px;letter-spacing:1px;margin-left:15px;margin-bottom:15px;">';
        if(title != '')html += title + " - ";
        if(date != '')html += date;
        if(url != '')html += "<br/>" + url;
        html += '</div>\n\n';
      }
      html += printPageElem.innerHTML; 
    }
    else return;
    html += '\n\n</bo' + 'dy>\n</ht' + 'ml>'; 
    var printWin = window.open("","printFriendly","toolbar=no,location=no,directories=no,menubar=no,scrollbars=yes,resizable=no,status=no,width=540,height=600");
    printWin.document.open(); 
    printWin.document.write(html); 
    printWin.document.close(); 
    printWin.print(); 
  } 
} 
