
/***************************************************************
/* General Pop-up Window function
/***************************************************************/

function openNewWindow(url, windowname, winwidth, winheight, wintop, winleft,showWindowTools) {
	var left;
	var top;

	if(typeof(wintop) != 'undefined' && wintop){
		top = wintop
	}else {
		top = (screen.height/2)-(winheight/2);
	}

	if(typeof(winleft) != 'undefined' && winleft){
		left = winleft
	}else {
		left = (screen.width/2)-(winwidth/2);		
	}

	if(typeof(showWindowTools) != 'undefined' && showWindowTools){
		var newWin = window.open(url, windowname, 'toolbar=yes, location=yes, directories=yes, status=yes, menubar=yes, scrollbars=yes, resizable=yes, width='+winwidth+', height='+winheight+', top='+top+', left='+left+'');
	} else {
		var newWin = window.open(url, windowname, 'toolbar=no, location=no, directories=no, status=no, menubar=no, scrollbars=yes, resizable=yes, width='+winwidth+', height='+winheight+', top='+top+', left='+left+'');
	}

	if (window.focus) {newWin.focus()}
	return false;

}
	
/***************************************************************
/* Pop-up Window to show full size image for Book and Journals
/***************************************************************/
	var newWin = '';
		
	function ViewThumbnail(url,caption,contenttype, copyrightInfo)
	{	
		var inCaption = URLDecode(caption);
		
		// URL: "bbmapAsset?appID=MDC&eid=4-u1.0-B0-7216-9652-X..50035-9..f029004"
		var eid = url.substr(url.indexOf("eid") + 4);
		var appID = url.substr(url.indexOf("appID") + 6, 3);
		var urlExportToPPT = 'book.do?method=getFigure&eid=' + eid +"&appID=" + appID + "&contentStyle=ppt";
		var jsSaveImage= 'javascript:saveImageAjax("' + eid + '");';
		
		if (!newWin.closed && newWin.location)
		{//check if pop-up already exists
			//newWin.location.href = url;
			//leave the window alone...
		}
		else
		{			
				if (contenttype	== "bk"){
					//Check "content type"
					//book	
					newWin=window.open(url,"Popup","toolbar=no, location=no, directories=no, status=no, menubar=no, scrollbars=yes, resizable=yes, width=700, height=500");
				}
				else if (contenttype == "jn"){
					//journal
					newWin=window.open("about:blank","Popup","toolbar=no, location=no, directories=no, status=no, menubar=yes, scrollbars=yes, resizable=yes, width=700, height=500");
				} else {
					//default
					newWin=window.open(url,"Popup","toolbar=no, location=no, directories=no, status=no, menubar=no, scrollbars=yes, resizable=yes, width=700, height=500");
				}
							
				//Page Content
				var buf;
				buf = "<html><head>\n";
				buf = buf + "<SCRIPT language=javascript type=text/javascript src=\"../book/script/image.js\"></SCRIPT>";
				buf = buf + "<script type=text/javascript src=\"../book/script/dojo.js\"></script>";
				buf = buf + "<style>";
				buf = buf + ".text { font-family:verdana; text-decoration:none; font-size:x-small; color:#000000 }";
				buf = buf + ".logo { display:none; }";
				buf = buf + ".clearnoheight {clear: both; height: 0px; font-size: 0px; overflow: hidden; margin:0; padding:0;}";
				buf = buf + "</style>\n";
				buf = buf + "<link rel='stylesheet' type='text/css' media='print' href='../book/style/styles_mdc-new_print.css' />";
				buf = buf + "</head><body>\n";
					
				buf = buf + "<div class='logo'><img style='margin-left: 6px' height='33' width='104' alt='eDitions' src='../images/eDitionLogo.gif' border='0'></div>\n";
				
				buf = buf + "<div class='text' style='float:left;'><a href='javascript:window.print();' title='Print'><b>Print</b></a></div>\n";
				buf = buf + "<div class='text' style='float:right;'><a href='javascript:window.close();' title='Close window'><b>Close</b></a></div>\n";	
				buf = buf + "<div class='clearnoheight'></div>";
				buf = buf + "<div class='text' id='statusLine'><br/></div>";
				buf = buf + "<hr size='1' align='center' width='100%' color='#7EBC9C'><br/>\n";
				buf = buf + "<img border='0' src='"+url+"'/>\n";
				if (copyrightInfo) {
					buf = buf + "<p class='text'>" + copyrightInfo + "</p>\n";
				}
				buf = buf + "<p class='text'>\n";
				buf = buf + "<b>"+inCaption+"</b>\n";
				buf = buf + "<br/><hr size='1' align='center' width='100%' color='#7EBC9C'>\n";
				buf = buf + "</body></html>";
				newWin.document.write(buf);
				
				
		 }//end if
		 if (window.focus) {newWin.focus()}
		 
	}
			
	function URLDecode(strText)
	{
	   // Replace + with ' '
	   // Replace %xx with equivalent character
	   // Put [ERROR] in output if %xx is invalid.
	   var HEXCHARS = "0123456789ABCDEFabcdef"; 
	   var encoded = strText;
	   var plaintext = "";
	   var i = 0;
	   while (i < encoded.length) {
	       var ch = encoded.charAt(i);
		   if (ch == "+") {
		       plaintext += " ";
			   i++;
		   } else if (ch == "%") {
				if (i < (encoded.length-2) 
						&& HEXCHARS.indexOf(encoded.charAt(i+1)) != -1 
						&& HEXCHARS.indexOf(encoded.charAt(i+2)) != -1 ) {
					plaintext += unescape( encoded.substr(i,3) );
					i += 3;
				} else {
					//alert( 'Bad escape combination near ...' + encoded.substr(i) );
					//plaintext += "%[ERROR]";

					plaintext += ch;
					i++;
				}
			} else {
			   plaintext += ch;
			   i++;
			}
		} // while
	   strText = plaintext;
	   //alert("strText: "+strText);
	   return strText;
	}
/****************************** End (Pop-up Window)****************************/

function composePrevNext(eid, appid){
		document.forms[0].eid.value=eid;	
		document.forms[0].appID.value=appid;
		document.forms[0].screenID.value=4;	
		document.forms[0].method.value="getBook";
		var url = "book.do";
		changeFormActionandSubmit(url + "#" + eid);
}

function changeFormActionandSubmit(url){
       document.forms[0].action = url;
       submitForm();
}

function submitForm(){
       document.forms[0].submit();
}



var dw_fontSizerDX = {
    sizeUnit:       "px",
    defaultSize:    14,
    maxSize:        24,
    minSize:        10,
    queryName:      "dw_fsz",   // name to check query string for when passing size in URL
    queryNum:       true,       // check query string for number only (eg. index.html?18 )
	adjustList:[],

	setDefaults:function(unit,dflt,mn,mx,sels){
		this.sizeUnit=unit;
		this.defaultSize=dflt;
		this.maxSize=mx;
		this.minSize=mn;
		if(sels)
			this.set(dflt,mn,mx,sels);
	},
		
	set:function(dflt,mn,mx,sels){
		var ln=this.adjustList.length;
		for(var i=0;sels[i];i++){
			this.adjustList[ln+i]=[];
			this.adjustList[ln+i]["sel"]=sels[i];
			this.adjustList[ln+i]["dflt"]=dflt;
			this.adjustList[ln+i]["min"]=mn||this.minSize;
			this.adjustList[ln+i]["max"]=mx||this.maxSize;
			this.adjustList[ln+i]["ratio"]=this.adjustList[ln+i]["dflt"]/this.defaultSize;
		}
	},
	
	init:function(){
	
		
	
		if(!document.getElementById||!document.getElementsByTagName||!dw_fontSizerDX.ready)
			return;
		var size,sizerEl,i;
		size=getValueFromQueryString(this.queryName,this.queryNum);
		if(isNaN(parseFloat(size))||size>this.maxSize||size<this.minSize){
			
			size=dojo.io.cookie.getCookie("fontSize");
			
			
			
			if(isNaN(parseFloat(size))||size>this.maxSize||size<this.minSize){
				size=this.defaultSize;
			}
			
			//alert("init: size: " + size);
		}
		this.curSize=this.defaultSize;
		sizerEl=document.getElementById('sizer');
		if(sizerEl)sizerEl.style.display="block";
		if(this.adjustList.length==0){
			this.setDefaults(this.sizeUnit,this.defaultSize,this.minSize,this.maxSize,['body','td']);
		}
		if(size!=this.defaultSize)
			this.adjust(size-this.defaultSize);
	},
	
	adjust:function(n){
		if(!this.curSize||!dw_fontSizerDX.ready)
			return;
		var alist,size,list,i,j;
		if(n>0){
			if(this.curSize+n>this.maxSize)
				n=this.maxSize-this.curSize;
		}else if(n<0){
			if(this.curSize+n<this.minSize)
				n=this.minSize-this.curSize;
		}
		if(n==0)
			return;
		this.curSize+=n;
		alist=this.adjustList;
		for(i=0;alist[i];i++){
			size=this.curSize*alist[i]['ratio'];
			size=Math.max(alist[i]['min'],size);
			size=Math.min(alist[i]['max'],size);
			list=dw_getElementsBySelector(alist[i]['sel']);
			for(j=0;list[j];j++){
				list[j].style.fontSize=size+this.sizeUnit;
			}
		}
		
		//alert("adjust: size: " + size);
		
		dojo.io.cookie.setCookie("fontSize",size,1,"/");
	},
	
	reset:function(){
		if(!this.curSize||!dw_fontSizerDX.ready)
			return;
		var alist=this.adjustList,list,i,j;
		for(i=0;alist[i];i++){
			list=dw_getElementsBySelector(alist[i]['sel']);
			for(j=0;list[j];j++){
				list[j].style.fontSize='';
			}
		}
		this.curSize=this.defaultSize;
		dojo.io.cookie.setCookie("fontSize",this.defaultSize,1,"/");
	}
};
													
function dw_getElementsBySelector(selector){
	if(!document.getElementsByTagName)
		return[];
	var nodeList=[document.getElementById("bookContentPane")],tokens,bits,list,col,els,i,j,k;
	selector=selector.normalize();
	tokens=selector.split(' ');
	for(i=0;tokens[i];i++){
		if(tokens[i].indexOf('#')!=-1){
			bits=tokens[i].split('#');
			var el=document.getElementById(bits[1]);
			if(!el)
				return[];
			if(bits[0]){
				if(el.tagName.toLowerCase()!=bits[0].toLowerCase())
					return[];
			}
			for(j=0;nodeList[j];j++){
				if(nodeList[j]==document||dw_contained(el,nodeList[j]))
					nodeList=[el];
				else 
					return[];
			}
		}else if(tokens[i].indexOf('.')!=-1){
			bits=tokens[i].split('.');
			col=[];
			for(j=0;nodeList[j];j++){
				els=dw_getElementsByClassName(bits[1],bits[0],nodeList[j]);
				for(k=0;els[k];k++){
					col[col.length]=els[k];
				}
			}
			nodeList=[];
			for(j=0;col[j];j++){
				nodeList.push(col[j]);
			}
		}else{
			els=[];
			for(j=0;nodeList[j];j++){
				list=nodeList[j].getElementsByTagName(tokens[i]);
				for(k=0;list[k];k++){
					els.push(list[k]);
				}
			}
			nodeList=els;
		}
	}
	return nodeList;
};

function dw_getElementsByClassName(sClass,sTag,oCont){
	var result=[],list,i;
	var re=new RegExp("\\b"+sClass+"\\b","i");
	oCont=oCont?oCont:document;
	if(document.getElementsByTagName){
		if(!sTag||sTag=="*"){
			list=oCont.all?oCont.all:oCont.getElementsByTagName("*");
		}
		else{
			list=oCont.getElementsByTagName(sTag);
		}
		for(i=0;list[i];i++)
			if(re.test(list[i].className))
				result.push(list[i]);
	}
	return result;
};

function getValueFromQueryString(varName,bReturn){
	var val="";
	if(window.location.search){
		var qStr=window.location.search.slice(1);
		var ar=qStr.split("&");
		var get=[],ar2;
		for(var i=0;ar[i];i++){
			if(ar[i].indexOf("=")!=-1){
				ar2=ar[i].split("=");
				get[ar2[0]]=ar2[1];
			}
		}
		val=get[varName];
		if(!val&&bReturn){
			val=qStr;
		}
	}
	return val;
};

function dw_contained(oNode,oCont){
	if(!oNode)
		return;
	while(oNode=oNode.parentNode)
		if(oNode==oCont)
			return true;
	return false;
};

if(!Array.prototype.push){
	Array.prototype.push=function(){
		for(var i=0;arguments[i];i++)
			this[this.length]=arguments[i];
		return this[this.length-1];
	}
};

String.prototype.normalize=function(){
	var re=/\s\s+/g;
	return this.trim().replace(re," ");
};

String.prototype.trim=function(){
	var re=/^\s+|\s+$/g;
	return this.replace(re,"");
};

dw_fontSizerDX.ready=true;

//setDefaults:function(unit,dflt,mn,mx,sels){

dw_fontSizerDX.setDefaults( "px", 14, 10, 24, ['body', 'td', 'div', 'p', 'font', 'span.title'] ); 
//dw_fontSizerDX.init();

var newWin = ' ';

function openWebWindow(url) {	
				
	if (!newWin.closed && newWin.location){
		//check if pop-up already exists
		newWin.location.href = url;
		//leave the window alone...
	}
	else{			
			newWin=window.open(url,"Popup","toolbar=no, location=no, directories=no, status=no, menubar=no, scrollbars=no, resizable=yes, width=700, height=500");
							
	 }//end if
	 if (window.focus) {
	 	newWin.focus()
	 }
}

// Popup a window using the href of an anchor (which wasn't otherwise configured to popup). 
// Note:  This is designed to work as the onclick method of an anchor tag.
function popupAnchor() {	
	// 'this' should be the actual anchor tag DOM element...							
	if(this.href) {	
		openWebWindow(this.href);
	}
		
	// Don't follow the link we've popped the href url up.
	return false; 					
}
