/*-----------------------------------------------
support.sas.com   bookpage.js 
scripts for the book pages for the iframe bookviewer v2
author:   pjt
version:  10Oct09
----------------------------------------------- */
 
var documentid = 'noid';
	//alert('page: '+ window.history.length);
/* ************************************************************
/* Always load a page within the viewer frameset
/* ***********************************************************  */
    function loadin(pageid) {
    	//alert(self.location.hash);
		if (window.parent.location.href == self.location.href){
			//alert('top:'+parent.location.href);
    		//window.location.href = 'viewer.htm#' + self.location.pathname; 
    		window.location.replace('viewer.htm#' + pageid);
		} else {
		
		var title = '';
		
		if (document.getElementsByTagName('title')) {
			title = document.getElementsByTagName('title')[0].text; }
		 
    	
    	//alert(self.location.hash);
    	
		parent.setState(pageid, self.location.hash, title)
    	//parent.setpageid(pageid);  //
    	//parent.setpagehash(self.location.pathname, document.getElementsByTagName('title')[0].text);
    	
    	// reset book scroll when new bookpage is loaded.  (does not impact hash tags)
    	parent.document.documentElement.scrollTop = 0;
    	
		if (document.getElementById('docid')) documentid = document.getElementById('docid').content;
		
    	}

    }
    
  	function parseLinks(pubrelease) {
  		// Parse A tag elements to add a target="_top" attribute for external links  
  		//    uses pubrelease as the key to determine which links are internal to book.

  		var atags = document.getElementsByTagName('A');
  		//alert(atags.length);
		for (var i=0;i<atags.length;i++) {							// loop thru all anchor tags
			if (atags[i].href != '') {    							// skip #anchors 
				if (atags[i].target == '') {						// skip if target specified
					if(atags[i].href.indexOf('common') < 0) {  		// skip if link is in common
						if(atags[i].href.indexOf(pubrelease) < 0) {	// check to see if in this book
							atags[i].target = '_top';				// set target to top for out of book links	
							}
						}
					}
				}
		}

  	}
    


