// /prod/webdocs/htdocs/amednews/scripts/amn.js
// amednews js scripts (ehs ad processing is separate)...

// vars for login/logout routines
// NOTE these shd be should be changed to the appropriate 
// domain for use on the staging site
var ssoURLBase    = "https://ssl3.ama-assn.org/apps";
var amnewsHomeURL = "http://www.ama-assn.org/amednews/";




// PRINTME functionality - now handled in R-bar SSIs 
//function print_page() {window.print();}
//function prt() {var p=1;}



// generic AMA logout-link writer
// copied w/mods from "http://www.ama-assn.org/ama1/js/ama-default.js"
function logoutLink(sessionTitle) {
  var ldap = document.cookie.indexOf("AMAHTTPSESSIONID");
  if (ldap != -1) {
    //document.write('<A HREF="https://ssl3.ama-assn.org/apps/ldap/logout.cgi?url=http://www.amednews.com/&r=0&t=AMNews">LOG OUT</A>');
    //document.write('<A HREF="' + ssoURLBase + '/ldap/logout.cgi?url=' + amnewsHomeURL + '&r=0&t=AMNews">LOG OUT</A>');
      document.write('<span id="loginspan"><a href="' + ssoURLBase + '/ldap/logout.cgi?url=' + amnewsHomeURL + '&r=0&t=AMNews">Log&nbsp;out</a></span>');
  }
}



// logIN link writer (analogous to logoutLink)
// allows us to have an explicit login link, not just folks will click on content
function loginLink(sessionTitle) {
  var ldap = document.cookie.indexOf("AMAHTTPSESSIONID");
  if (ldap == -1) {
    var loginUrl = ssoURLBase + "/xsite/x-amnews/xsite.cgi?site=" + escape(document.location);
    document.write(' <span id="loginspan"><a href="' + loginUrl + '">Log&nbsp;in</a></span> ');
  }
}

// same but just writes the link itself
// does not check for logged in state, as going only to Limited pages
function loginLim(sessionTitle) {
    var loginUrl = ssoURLBase + "/xsite/x-amnews/xsite.cgi?site=" + escape(document.location);
    document.write(' <span id="loginspan"><a href="' + loginUrl + '">Log&nbsp;in</a></span> ');
}


// generic AMA cookie grabber
function getCookie(cookieName) {
  var cookieStr = "" + document.cookie;
  var index1 = cookieStr.indexOf(cookieName);
  if (index1 == -1 || !cookieName) {
    return "";
  }
  var index2 = cookieStr.indexOf(";", index1);
  if (index2 == -1) {
    index2 = cookieStr.length;
  }
  return(unescape(cookieStr.substring(index1 + cookieName.length + 1, index2)));
}


// Multi-browser "bookmark this page"
function bkmark(title,url){ 
if (window.sidebar) // firefox 
    alert('Press CTRL+D to bookmark after popup closes'); 
else if(window.opera && window.print){ // opera 
    var elem = document.createElement('a'); 
    elem.setAttribute('href',url); 
    elem.setAttribute('title',title); 
    elem.setAttribute('rel','sidebar'); 
    elem.click(); 
}  
else if(document.all)// ie 
    window.external.AddFavorite(url, title); 
}

// "link to this page"
function poplink(fname) {
	newwindow2=window.open('','name','height=150,width=550');
	var tmp = newwindow2.document;
	tmp.write('<html><head><title>Link to this page</title>');
	tmp.write('</head><body><p>To link to this page, simply copy and paste the following HTML code:</p>');
	tmp.write('<p>&lt;a href="'+self.location.href+'"&gt;'+fname+'&lt;/a&gt;</p>');
	tmp.write('<p><a href="javascript:self.close()">Close</a></p>');
	tmp.write('</body></html>');
	tmp.close();
}

