	function escapeTxt(os){
		var ns='';
		var t;
		var chr='';
		var cc='';
		var tn='';
		for(i=0;i<256;i++){
			tn=i.toString(16);
			if(tn.length<2)tn="0"+tn;
			cc+=tn;
			chr+=unescape('%'+tn);
		}
		cc=cc.toUpperCase();
		os.replace(String.fromCharCode(13)+'',"%13");
		for(q=0;q<os.length;q++){
			t=os.substr(q,1);
			for(i=0;i<chr.length;i++){
				if(t==chr.substr(i,1)){
					t=t.replace(chr.substr(i,1),"%"+cc.substr(i*2,2));
					i=chr.length;
				}
			}
			ns+=t;
		}
		return ns;
	}

	function unescapeTxt(s){
		return unescape(s);
	}

	function getFrameReference(frameName) {
		if (window.frames[frameName])
			return window.frames[frameName];
		else if (parent.window.frames[frameName])
			return parent.window.frames[frameName];
		else if (parent.parent.window.frames[frameName])
			return parent.parent.window.frames[frameName];
		else {
			var i,j;
			
			for (i=0; i<parent.window.frames.length; i++)
				if (parent.window.frames[i].window.frames[frameName])
					return parent.window.frames[i].window.frames[frameName];
			
			for (j=0; j<parent.parent.window.frames.length; j++)
				if (parent.parent.window.frames[j].window.frames[frameName])
					return parent.parent.window.frames[j].window.frames[frameName];
		}

		return null;
	}

	function getFrameElementReference(frameId) {
		var frameRef = getFrameReference(frameId);
		if (frameRef.parent.document.getElementById(frameId))
			return frameRef.parent.document.getElementById(frameId);

		return null;
	}

	function collapseTools() {		
		parent.document.getElementById("hfrReaderFrameset").cols = "1,*,0,0";
	}
	
	function expandTools() {
		parent.document.getElementById("hfrReaderFrameset").cols = "280,*,0,0";
	}
		
	function getCurrentFrameHeight() {
		return ((self.innerHeight) ? self.innerHeight : (document.documentElement.clientHeight) ? document.documentElement.clientHeight : document.body.clientHeight);
	}
	
	function getCurrentFrameWidth() {
		return ((self.innerWidth) ? self.innerWidth : (document.documentElement.clientWidth) ? document.documentElement.clientWidth : document.body.clientWidth);
	}
	
	function getFrameHeight(frame) {
		var frameRef = getFrameElementReference(frame);
		return (frameRef.offsetHeight) ? frameRef.offsetHeight : (frameRef.height) ? frameRef.height : frameRef.innerHeight;
	}
	
	function getFrameWidth(frame) {
		var frameRef = getFrameElementReference(frame);		
		return (frameRef.offsetWidth) ? frameRef.offsetWidth : (frameRef.width) ? frameRef.width : frameRef.innerWidth;
	}

	function sessionTimeout(sid,bshid,bid){
		//alert("get in timeout bookshelf_id="+bshid);
		//alert("get in timeout book_id="+b_id);
		parent.EbookTimeout.location=('sessionTimeout.php?sid='+sid+'&bookshelf_id='+bshid+'&book_id='+bid);
	}

	function sessionGenerate(sid,bid,bshid,uid){
		alert("get in gen");
		parent.EbookCreateSession.location=('sessionGenerate.php?sid='+sid+'&book_id='+bid+'&bookshelf_id='+bshid+'&user_id='+uid);
	}

	function sessionDestroy(uni_id,faculty_id,major_id,course_id,book_id){
		//parent.hidden.location('bookdestroy.php?uni_id='+uni_id+'&faculty_id='+faculty_id+'&major_id='+major_id+'&course_id='+course_id+'&book_id='+book_id);
	}

	function toolReadingSearch(){
		document.toolReadingSearch.submit();
	}
	function toolReadingContent(){
		document.toolReadingContent.submit();
	}
	function toolReadingNote(){
		document.toolReadingNote.submit();
	}
	function toolReadingBorrow(){
		document.toolReadingBorrow.submit();
	}
	function toolReadingDetail(){
		document.toolReadingDetail.submit();
	}
	function toolReadingTool(){
		document.toolReadingTool.submit();
	}
	function toolReadingTranslate(){
		document.toolReadingTranslate.submit();
	}
	function closeItem(topic){
		var agree=confirm("คุณต้องการปิดหนังสือ "+unescapeTxt(topic)+" ใช่หรือไม่?");
		if(agree){
			document.closeItem.submit();
		}
	}

