// Karen Smiley and Jan Höglund, (c) 2003-2010, all rights reserved.
//
// purpose of these modules is to centralize code for
// 1) writing page mod dates and bookmarks
// 2) launching offsite links in a separate window
// 3) writing email links but instead of a href="mailto:", hide the email addresses from
//    web crawlers and hopefully reduce the amount of spam we attract
//
// Consider adding a function to only write out the bookmarkPage() href if
//    document.all and window.external are defined (in Firebird/Firefox they aren't, and
//    this method of bookmarking doesn't work)
//
//---------------------------------------------------------------------------------------
// AgileTeams-specific
//---------------------------------------------------------------------------------------

// global, used here only for identifying the creator of the new offsite window
myName = "AgileTeams";

//---------------------------------------------------------------------------------------
function ATgoOffsite(pURL) { 
   goOffsite (pURL, "AgileTeams_offsite","status=yes,menubar=yes,scrollbars=yes,resizable=yes,location=yes,toolbar=yes");
}

//---------------------------------------------------------------------------------------
function ATwriteOnsite(linkText,linkURL,linkTitle) { 
   writeTitledLink ("onsite",linkText,linkURL,"","Click to "+linkTitle);
}

//---------------------------------------------------------------------------------------
function ATwriteOffsiteText(linkText,linkURL,linkTitle,spacerText) { 
   writeFcnLink ("offsite",linkText,"ATgoOffsite('"+linkURL+"')","Click to go offsite for "+linkTitle+" (will open in a separate window)");
   document.writeln (spacerText);
}

function ATwriteOffsite(linkText,linkURL,linkTitle) { 
   writeFcnLink ("offsite",linkText,"ATgoOffsite('"+linkURL+"')","Click to go offsite for "+linkTitle+" (will open in a separate window)");
// document.writeln ("");
}

//---------------------------------------------------------------------------------------
//function ATwriteFtpLink(ftpText,ftpFile,ftpTitle) {
//   fullFile = 'ftp://ftp.agileteams.com/pub/' + ftpFile;
//   writeTitledLink ("ftplink",ftpText,fullFile,"","Right-click to download "+ftpTitle);
//}

//---------------------------------------------------------------------------------------
function ATwritePDFFileLink(fileText,fileName) {
	fullText = fileText + '&nbsp;<img src="images/pdficon.png" border="0" width="16" height="16" alt="PDF">';
   writeTitledLink ("filelink",fullText,fileName,"","Right-click PDF icon or this link to download '"+fileText+"' via HTTP");
}

//---------------------------------------------------------------------------------------
function ATwriteFileLink(fileText,fileName) {   // not PDF, no icon
   writeTitledLink ("filelink",fileText,fileName,"","Right-click this link to download '"+fileText+"' via HTTP");
}

//---------------------------------------------------------------------------------------
function ATwriteFtpOff(ftpText,ftpFile,ftpTitle) {
   writeTitledLink ("ftpoff",ftpText,ftpFile,"AgileTeams_offsite","Right-click to download "+ftpTitle+" (offsite)");
}

//---------------------------------------------------------------------------------------
function ATwriteFooter(curPage) {
	
	document.writeln('<tr class="toolbar" height="50">\n<td colspan="5">\n<hr>');
	ATwriteToolbar(curPage);
	document.writeln('\n<hr>\n</td>\n</tr>');

	document.writeln('<tr class="footer" height="30">\n<td colspan="5">\n');
   document.write ('<i>Page</i> ');
   writeTitledLink ("footer",curPage, "javascript:bookmarkPage();", "", "Bookmark this page!");
   writeModDate();

	document.writeln('<br><a class="footer" href="copyright.html" title="By using this site, you acknowledge and accept our intellectual property rights to these materials. Read more here.">Copyright</a> &copy;&nbsp;2003-2010 the');
	document.writeln(' <a class="footer" href="sitemap.html"   title="Browse a map of our Agile Teams site(s)">Agile&nbsp;Teams</a>');
	document.writeln(' <a class="footer" href="aboutus.html"   title="Who we are, what we do, and how to contact us">team</a> -');
	document.writeln(' <a class="footer" href="copyright.html" title="By using this site, you acknowledge and accept our intellectual property rights to these materials. Read more here.">All rights reserved</a>.&nbsp;\n');

	document.writeln('<a class="footer" href="whatsnew.html" title="List of new and changed features on our sites">New</a>:');
	document.writeln('See&nbsp;our&nbsp;<a class="footer" href="privacy.html" title="Read our privacy policy here">privacy&nbsp;statement</a>.\n');
	document.writeln('<br /><i>Views expressed on this website/blog are ours alone, and do not necessarily reflect the views of our employers.</i>\n');
	document.writeln('\n</td>\n</tr>');
}

//---------------------------------------------------------------------------------------
function ATwriteSvFooter(curPage) {

	// 2005-03-29 JH - Translation into swedish
	// 2005-03-30 JH - site changed to webb-plats, teamet changed to team
	
	document.writeln('<tr class="toolbar" height="50">\n<td colspan="5">\n<hr>');
	ATwriteSvToolbar(curPage);
	document.writeln('\n<hr>\n</td>\n</tr>');

	document.writeln('<tr class="footer" height="30">\n<td colspan="5">\n');
   document.write ('<i>Sida</i> ');
   writeTitledLink ("footer",curPage, "javascript:bookmarkPage();", "", "Öronmärk denna sida!");
   writeSvModDate();

	document.writeln('<br><a class="footer" href="copyright.html" title="Genom att använda denna webb-plats, tillerkänner och accepterar Du våra upphovsrättsliga rättigheter till vårt material. Läs mer här (engelska).">Copyright</a> &copy;&nbsp;2003-2010 ');
	document.writeln(' <a class="footer" href="sitemap.html"   title="Navigationskarta över Agile Teams webb-platser">Agile&nbsp;Teams</a>');
	document.writeln(' <a class="footer" href="aboutus.html"   title="Vilka vi är, vad vi gör, och hur Du kan kontakta oss">team</a> -');
	document.writeln(' <a class="footer" href="copyright.html" title="Genom att använda denna webb-plats, tillerkänner och accepterar Du våra upphovsrättsliga rättigheter till vårt material. Läs mer här (engelska).">Alla rättigheter förbehålles</a>.&nbsp;\n');

	document.writeln('<a class="footer" href="whatsnew.html" title="Lista över det som är nytt och ändrat på vår webb-plats">Nytt</a>:');
	document.writeln('Se&nbsp;vår&nbsp;<a class="footer" href="privacy.html" title="Läs vår policy (engelska)">privacy&nbsp;statement</a>.\n');
	document.writeln('<br /><i>Uppfattningar som vi ger uttryck för på denna webb-plats/blogg är enbart våra egna, och återspeglar inte nödvändigtvis våra arbetsgivares uppfattning.</i>\n');
	document.writeln('\n</td>\n</tr>');
}

//---------------------------------------------------------------------------------------
function ATwriteToolbar(curPage) {
   // note: this does not take into account nulling out the link for the current page,
	// if it is a toolbar page
	writeToolbarLink (curPage,"HOME",			"index.html",       "Agile Teams home page");
	writeToolbarLink (curPage,"Blog",			"blog/index.php",   "Agile Teams blog (new!)");
	writeToolbarLink (curPage,"Teaching",		"teaching.html",    "Materials from courses we've taught");
	writeToolbarLink (curPage,"Papers",			"publications.html","Our conference papers and other publications");
	writeToolbarLink (curPage,"Affiliations",	"affiliations.html","Our associations with technical and professional organizations");
	writeToolbarLink (curPage,"Links",			"links.html",       "Links to reference materials on combining agility and discipline (coming soon)");
	writeToolbarLink (curPage,"About Us",		"aboutus.html",     "CVs and contact information for the Agile Teams team members");
	writeToolbarLink (curPage,"Search",			"search.html",      "Search our site using keywords");
}

//---------------------------------------------------------------------------------------
function ATwriteSvToolbar(curPage) {
   // note: this does not take into account nulling out the link for the current page,
 // if it is a toolbar page

 // 2005-03-29 JH - Translation into swedish
 writeToolbarLink (curPage,"Hem",          "index.html",       "Agile Teams hemsida");
 writeToolbarLink (curPage,"Blog",			 "blog/index.php",   "Agile Teams blog");
 writeToolbarLink (curPage,"Utbildning",   "teaching.html",    "Material från kurser som vi har hållit");
 writeToolbarLink (curPage,"Publikationer","publications.html","Våra konferensbidrag och andra publikationer");
 writeToolbarLink (curPage,"Anknytningar", "affiliations.html","Våra anknytningar till tekniska och professionella organisationer");
 writeToolbarLink (curPage,"Länkar",       "links.html",       "Länkar till referensmaterial (kommer snart)");
 writeToolbarLink (curPage,"Om oss",       "aboutus.html",     "CVs och annan kontaktinformation för Agile Teams teammedlemmar");
 writeToolbarLink (curPage,"Sök",          "search.html",      "Sök efter nyckelord på denna site");
}

//---------------------------------------------------------------------------------------
function writeToolbarLink (curPage,linkText,linkLoc,linkTitle) {
	//if ( curPage = linkLoc ) {  // this compare is broken, fix it then uncomment the if structure
	//	document.write (linkText);
	//} else {
		writeTitledLink ("toolbar",linkText,linkLoc,"",linkTitle);
	//}
   document.write ("&nbsp;&nbsp;&nbsp;&nbsp;");
}

//---------------------------------------------------------------------------------------
function ATwritePubHeader (what) {
	document.writeln ('<br>Our '+what+' are posted in ');
	ATwriteLegal ("Adobe","Adobe");
	ATwriteMark  ("&reg; ");
	ATwriteLegal ("Adobe","Acrobat");
	ATwriteMark  ("&reg; ");
	document.writeln ('(PDF, ');
	ATwriteOffsite("v6.0+","http://www.adobe.com/products/acrobat/readstep2.html","downloading Acrobat Reader V6.0+ from the Adobe site");
	document.writeln (') format.');
	document.writeln ('<!br>Right-click&nbsp;the&nbsp;<img src="images/pdficon.png" border="0" width="16" height="16" alt="PDF">&nbsp;icons '); 
	document.writeln ('to download via&nbsp;HTTP.');
			  
	document.write ('(');
	ATwriteOffsite("Italicized&nbsp;links","about:blank","testing how this works");
	document.writeln ('&nbsp;go&nbsp;off&nbsp;this&nbsp;site,&nbsp;and&nbsp;will&nbsp;open&nbsp;in&nbsp;a&nbsp;new&nbsp;window.)');
//	document.writeln ('<br>&nbsp;');
}

//---------------------------------------------------------------------------------------
// set of routines for writing offsite links for SEI topics
// 	purposely do NOT end with a newline here, so that other text can immediately follow
// 	these URLs
//---------------------------------------------------------------------------------------

function ATwritePspTsp () {
	ATwriteSeiMark ("PSP","tsp/psp.html","SM");	document.write("/");
	ATwriteSeiMark ("TSP","tsp/","SM");
}

function ATwritePspTspWords () {
	ATwritePspWords();	document.write("/");
	ATwriteTspWords();
}

function ATwriteSei()      { 
	ATwriteSeiLink   ("SEI","","home");
	ATwriteLegalMark ("SEI","SM");
}

function ATwriteAgile(what) { ATwriteOffsite(what,"http://www.agilealliance.com/programs/roadmaps/Roadmap/index.htm","the Agile Alliance roadmap to agile methods"); }
function ATwriteScrum()		 { ATwriteOffsite("Scrum","http://www.scrumalliance.org","the Scrum Alliance site"); }
function ATwriteCrystal()	 { ATwriteOffsite("Crystal","http://alistair.cockburn.us/crystal/crystal.html","the Crystal Methodologies home page"); }

function ATwriteSwCmm()     { ATwriteSeiMark ("SW-CMM","cmm/",             "&reg;"); }
function ATwriteCmms()      { ATwriteSeiMark ("CMM",   "cmm/cmms/cmms.html","&reg;"); }
function ATwriteCmmi()      { ATwriteSeiMark ("CMMI",  "cmmi/",            "&reg;"); }
function ATwriteSepg()      { ATwriteSeiMark ("SEPG",  "sepg/",       		"SM"); }
function ATwritePsp()       { ATwriteSeiMark ("PSP",   "tsp/psp.html",		"SM"); }
function ATwriteTsp()       { ATwriteSeiMark ("TSP",   "tsp/",        		"SM"); }
function ATwritePspWords()  { ATwriteSeiMark ("Personal Software Process",	"tsp/psp.html","SM"); }
function ATwriteTspWords()  { ATwriteSeiMark ("Team Software Process",		"tsp/","SM"); }

function ATwriteSeiMark (what,seiurl,mark) {
	ATwriteSeiLink (what,seiurl,what);
	ATwriteLegalMark ("SEI",mark);
}

//---------------------------------------------------------------------------------------
// set of routines for writing other common offsite links
//---------------------------------------------------------------------------------------
function ATwriteAbb() {
	// could include a small version of the ABB logo here?
	fcnUrl = "javascript:ATgoOffsite('http://www.abb.com');";
	mouseoverText = "Click to go offsite for the ABB home page (will open in a separate window)";
	document.writeln ('<a');
	document.writeln (' class="offsite" href="'+fcnUrl+'"');
	document.writeln (' title="' + mouseoverText + '"');
	document.write   ('>ABB</a>');
}

//---------------------------------------------------------------------------------------
// misc site-specific
//---------------------------------------------------------------------------------------
function ATwriteSeiLink (what,seiurl,descr) {

	fcnUrl = "javascript:ATgoOffsite('http://www.sei.cmu.edu/" + seiurl + "');";
	mouseoverText = "Click to go offsite for the SEI's "+descr+" page (will open in a separate window)";

	document.writeln ('<a');
	document.writeln (' class="offsite" href="'+fcnUrl+'"');
	document.writeln (' title="' + mouseoverText + '"');
	document.write   ('>' + what + '</a>');
}

function ATwriteLegal (who,what) {

	document.writeln ('<a'); 
	document.write   (' class="legal" href="copyright.html#'+who+'"'); 
	document.write   (' title="Click to view information on '+who+' copyrights">'+what+'</a>');
	// do NOT put in a writeln
}

function ATwriteLegalMark (who,mark) {

	document.writeln ('<a'); 
	document.write   (' class="legal" href="copyright.html#'+who+'"'); 
	document.write   (' title="Click to view information on '+who+' copyrights">');
	ATwriteMark (mark);
	document.write   ('</a>');
	// do NOT put in a writeln
}

function ATwriteMark (mark) {
	document.write ('<small><sup>'+mark+'</sup></small>');
	// do NOT put in a writeln
}


//---------------------------------------------------------------------------------------
// generic
//---------------------------------------------------------------------------------------
function bookmarkPage () {

// note that document.all and window.external are "undefined" in the Firebird browser, so
// bookmarking does not work in them.	

   if(document.all) {
      window.external.AddFavorite(top.location.href,"Agile Teams - "+document.title);
   } else {
   	alert ("Type Ctrl-D to bookmark this page; automated bookmarking does not work in this browser.");
   }
}

//---------------------------------------------------------------------------------------
function goOffsite(pURL,pwName,features) { 

   // load the window and set 'creator' variables in it
   new_window = window.open(pURL, pwName, features);

   if ( new_window != null ) {
		if ( new_window.opener == null ) {
			new_window.opener = window; // for Netscape 2.0 compatibility
        	alert ("no opener property - setting to " + new_window.opener);
		}
		if ( new_window.creatorName != null ) {	// may be undefined (as in IE 6.0)
			new_window.creatorName = myName;
		}
//alert ('After loading\nOpener: ' + new_window.opener + ' Name: ' + new_window.creatorName + '\n');
		new_window.focus(); 
 		
   } else {
		alert ("Cannot create/open window for offsite link");
   }
   return new_window;
} 

//---------------------------------------------------------------------------------------
function writePageAndDate (pageUrl) {

// fullUrl=location.href;
   document.write ('<!br><i>Page:</i>&nbsp;');
   writeTitledLink ("footer",pageUrl, pageUrl, "", "");
   document.writeln ('');
   writeModDate();
}

//---------------------------------------------------------------------------------------
// set of mailto link generating functions
//---------------------------------------------------------------------------------------
function writePageEmailLink (myDomain, emailAddr, myUrl) {  // emailaddr = xyz, myDomain=name.tld

   fullAddr = emailAddr + '@' + myDomain;
//   mySubject = myDomain + '%20page%20' + myUrl;
//   linkLoc = 'mailto:' + fullAddr + '?subject=' + mySubject;
//   mouseoverTitle="Send email to " + emailAddr + " about '" + mySubject + "'";
//   document.write ('<a href="' + linkLoc + '" title="' + mouseoverTitle + '">' + emailAddr + '</a>');
	writeMailtoLink (fullAddr,emailAddr,emailAddr,myDomain + '%20page%20' + myUrl);
}

//---------------------------------------------------------------------------------------
function writeTopicEmailLink (myDomain, emailAddr, mySubject) { // emailaddr = xyz, myDomain=name.tld

   fullAddr = emailAddr + '@' + myDomain;
//   linkLoc = 'mailto:' + fullAddr + '?subject=' + myDomain + '%20' + mySubject;
//   mouseoverTitle="Send email to " + emailAddr + " about '" + mySubject + "'";
//   document.write ('<a href="' + linkLoc + '" title="' + mouseoverTitle + '">' + emailAddr + '</a>');
	writeMailtoLink (fullAddr,emailAddr,emailAddr,myDomain + '%20' + mySubject);
}

//---------------------------------------------------------------------------------------
function writeTextEmailLink (myDomain, emailAddr, mySubject, linkText) { // emailaddr = xyz, myDomain=name.tld

   fullAddr = emailAddr + '@' + myDomain;
//   linkLoc = 'mailto:' + fullAddr + '?subject=' + mySubject;
//   mouseoverTitle="Send email to " + linkText + " about '" + mySubject + "'";
//   document.write ('<a href="' + linkLoc + '" title="' + mouseoverTitle + '">' + linkText + '</a>');
	writeMailtoLink (fullAddr,linkText,linkText,mySubject);
}

//---------------------------------------------------------------------------------------
function writeAddrEmailLink (myDomain, emailAddr, mySubject) { // emailaddr = xyz, myDomain=name.tld

   fullAddr = emailAddr + '@' + myDomain;
//   linkLoc = 'mailto:' + fullAddr + '?subject=' + mySubject;
//   mouseoverTitle="Send email to " + emailAddr + " about '" + mySubject + "'";
//   document.write ('<a href="' + linkLoc + '" title="' + mouseoverTitle + '">' + fullAddr + '</a>');
	writeMailtoLink (fullAddr,emailAddr,fullAddr,mySubject);
}

//---------------------------------------------------------------------------------------
function writeMailtoLink (fullAddr,whoText,linkText,mySubject) {  // fulladdr = xyz@name.tld

   linkLoc = 'mailto:' + fullAddr + '?subject=' + mySubject;
   mouseoverTitle="Send email to " + whoText + " about '" + mySubject + "'";
   document.writeln ('<a');
   document.write (' href="' + linkLoc + '" title="' + mouseoverTitle + '">' + linkText + '</a>');
}
//---------------------------------------------------------------------------------------
// end set of mailto link generating functions
//---------------------------------------------------------------------------------------

//---------------------------------------------------------------------------------------
// set of href link generating functions
//---------------------------------------------------------------------------------------

//---------------------------------------------------------------------------------------
function writeCopy (linkText) {

   writeTitledLink ("footer",linkText,"./copyright.html","","View copyright acknowledgements and legal notices.");
}

//---------------------------------------------------------------------------------------
function writeFcnLink (linkClass,linkText,fcnCall,linkTitle) {

	// does document.write (linkText.link(linkLoc)) work on mailto's? no way to do a target tho
//	document.writeln ('<a');
//	document.write (' class="' + linkClass + '" href="javascript:'+fcnCall+';"');
//
//	if ( linkTitle != "" ) {
//		document.write (' title="' + linkTitle);
//	}
//	document.write ('">' + linkText + '</a>');

	writeTitledLink (linkClass,linkText,"javascript:"+fcnCall+";", "", linkTitle);
}

//---------------------------------------------------------------------------------------
function writeTitledLink (linkClass,linkText,linkLoc,targetFrame,linkTitle) {

	// does document.write (linkText.link(linkLoc)) work on mailto's? no way to do a target tho
	document.writeln ('<a');
	if ( linkClass != "" ) {
		document.write (' class="' + linkClass + '"');
	}
	document.write (' href="' + linkLoc + '"');
	if ( targetFrame != "" ) {
		document.write (' target="' + targetFrame + '"');
	}
	if ( linkTitle != "" ) {
		document.write (' title="' + linkTitle + '"');
	}
	document.write ('>' + linkText + '</a>');
}

//---------------------------------------------------------------------------------------
function writeModDate () {

//   document.writeln (', <i>last updated</i> ' + document.lastModified+', ');
   document.writeln (', <i>last updated</i> ' + document.lastModified+'. ');
}


//---------------------------------------------------------------------------------------
function writeSvModDate () {
// 2005-03-29 JH - Translation into swedish

//   document.writeln (', <i>last updated</i> ' + document.lastModified+', ');
   document.writeln (', <i>Senast uppdaterad</i> ' + document.lastModified+'. ');
}

