﻿var Prototype = {
  Browser: {
    IE:	!!(window.attachEvent &&navigator.userAgent.indexOf('Opera') === -1),
    Opera:  navigator.userAgent.indexOf('Opera') > -1,
    WebKit: navigator.userAgent.indexOf('AppleWebKit/') > -1,
    Gecko:  navigator.userAgent.indexOf('Gecko') > -1 && navigator.userAgent.indexOf('KHTML') === -1,
    MobileSafari: !!navigator.userAgent.match(/Apple.*Mobile.*Safari/)
  },
  BrowserFeatures: {
    XPath: !!document.evaluate,
    SelectorsAPI: !!document.querySelector,
    ElementExtensions: !!window.HTMLElement,
    SpecificElementExtensions: document.createElement('div')['__proto__'] && document.createElement('div')['__proto__'] !== document.createElement('form')['__proto__']
  }
}

var jScript = {
  isReady: false, 
  readyList: [],
  
  addReady : function(fn) {
		bindReady();

		// If the DOM is already ready
		if ( jScript.isReady )
			// Execute the function immediately
			fn.call( document, jScript );

		// Otherwise, remember the function for later
		else
			// Add the function to the wait list
			jScript.readyList.push( fn );

		return this;
  },
  
  each : function( object, callback, args ) {
		var name, i = 0, length = object.length;

		if ( args ) {
			if ( length === undefined ) {
				for ( name in object )
					if ( callback.apply( object[ name ], args ) === false )
						break;
			} else
				for ( ; i < length; )
					if ( callback.apply( object[ i++ ], args ) === false )
						break;

		// A special, fast, case for the most common use of each
		} else {
			if ( length === undefined ) {
				for ( name in object )
					if ( callback.call( object[ name ], name, object[ name ] ) === false )
						break;
			} else
				for ( var value = object[0];
					i < length && callback.call( value, i, value ) !== false; value = object[++i] ){}
		}

		return object;
  },
  
  // Handle when the DOM is ready
  ready : function() {
		// Make sure that the DOM is not already loaded
		if ( !jScript.isReady ) {
			// Remember that the DOM is ready
			jScript.isReady = true;

			// If there are functions bound, to execute
			if ( jScript.readyList ) {
				// Execute all of them
				jScript.each( jScript.readyList, function(){
					this.call( document, jScript );
				});

				// Reset the list of functions
				jScript.readyList = null;
			}

			// Trigger any bound ready events
			//jScript(document).triggerHandler("ready");
		}
  }
}

var readyBound = false;

function bindReady(){
	if ( readyBound ) return;
	readyBound = true;

	// Mozilla, Opera and webkit nightlies currently support this event
	if ( document.addEventListener ) {
		// Use the handy event callback
		document.addEventListener( "DOMContentLoaded", function(){
			document.removeEventListener( "DOMContentLoaded", arguments.callee, false );
			jScript.ready();
		}, false );

	// If IE event model is used
	} else if ( document.attachEvent ) {
		// ensure firing before onload,
		// maybe late but safe also for iframes
		document.attachEvent("onreadystatechange", function(){
			if ( document.readyState === "complete" ) {
				document.detachEvent( "onreadystatechange", arguments.callee );
				jScript.ready();
			}
		});

		// If IE and not an iframe
		// continually check to see if the document is ready
		if ( document.documentElement.doScroll && window == window.top ) (function(){
			if ( jScript.isReady ) return;

			try {
				// If IE is used, use the trick by Diego Perini
				// http://javascript.nwbox.com/IEContentLoaded/
				document.documentElement.doScroll("left");
			} catch( error ) {
				setTimeout( arguments.callee, 0 );
				return;
			}

			// and execute any waiting functions
			jScript.ready();
		})();
	}

	// A fallback to window.onload, that will always work
	//jScript.event.add( window, "load", jScript.ready );
}

function inc(filename)
{
      var script = document.createElement('script');
      script.type = 'text/javascript';
      script.src = filename;
      document.getElementsByTagName('head')[0].appendChild(script); 
/*
	var body = document.getElementsByTagName('body').item(0);
	script = document.createElement('script');
	
	script.src = filename;
	script.type = 'text/javascript';
	
	body.appendChild(script)
*/
}

function getCookie(c_name){
	if (document.cookie.length>0) {
		c_start=document.cookie.indexOf(c_name + "=");
		if (c_start!=-1) {
			c_start=c_start + c_name.length+1;
			c_end=document.cookie.indexOf(";",c_start);
			if (c_end==-1) c_end=document.cookie.length;
			return unescape(document.cookie.substring(c_start,c_end));
		}
	}
	return "";
}
function setCookie(cookieName,cookieValue,nDays) {
	var today = new Date();
	var expire = new Date();
	
	if (nDays==null || nDays==0) nDays=1;
	expire.setTime(today.getTime() + 3600000*24*nDays);
	document.cookie = cookieName+"="+escape(cookieValue) + ";expires="+expire.toGMTString();
} 
function extract_URI(url){	
	var _GET = {};
	if(url==null) url = location.href;
	for(var m, v=url.split(/[?&]/), k=v.length-1;k>0;k--){
		_GET[(m=v[k].split(/[=#]/))[0].toLowerCase()] = m.length>1?decodeURIComponent(m[1]):"";
	}
	
	return _GET;
}
function ScrollToElement(theElement){
	var selectedPosX = 0;
	var selectedPosY = 0;
			  
	while(theElement != null){
		selectedPosX += theElement.offsetLeft;
		selectedPosY += theElement.offsetTop;
		theElement = theElement.offsetParent;
	}
									  
	window.scrollTo(selectedPosX,selectedPosY);
}
function getElementByName(doc,en){
	if(doc.getElementById(en)!=null) return doc.getElementById(en);
	else if(document.all) {
		return doc.all.item(en);
	}
	else {
		var aSelects = doc.getElementsByName(en);
		if(aSelects.length>0) return aSelects[0];
		else return aSelects;
	}
	
	return null;
}
var curPopUp = null;
function showModalDialog2(sURL, vArguments, sFeatures, onSelectList)
{
	curPopUp = null;
	if(window.showModalDialog) { // IE
		var tmp = window.showModalDialog(sURL , vArguments , sFeatures);
		if(onSelectList==undefined) return tmp;
		else {
			window.returnValue = tmp;
			onSelectList();	
		}
	}
	else { // FireFox
		var temp=sFeatures.split(";");
		//if(sFeatures.indexOf(",")>=0) temp=sFeatures.split(",");
		if (temp.length>0){
			sFeatures = "";
			for (var i = 0; i < temp.length; i++) {
				if(temp[i].indexOf(":")>=0){
					var temp2 = temp[i].split(":");
					if(temp[i].indexOf('dialogWidth')>=0){
						sFeatures = 'width='+temp2[1]+','+sFeatures;
					}
					else if(temp[i].indexOf('dialogHeight')>=0){
						sFeatures = 'height='+temp2[1]+','+sFeatures;
					}
					else sFeatures = temp2[0]+'='+temp2[1]+','+sFeatures;
				}
				else sFeatures = temp[i]+','+sFeatures;
			}
		}
		
		curPopUp = window.open(sURL,vArguments,sFeatures+'modal=yes,dialog=yes,center=yes'); 
		curPopUp.onunload = onSelectList;
		curPopUp.returnValue = null;
	}
}
function returnFromModalDlg(varName, varVal)
{
	if(window.showModalDialog) {
		window.returnValue = varVal;
	}
	else {
		window.opener.document.all.item(varName).value = varVal;
	}

	window.close();
}
function popUp( location, w, h , scrollbars, resizable, screenX, screenY, menubar) 
{
	popDlg(location,'editWin', w, h , scrollbars, resizable, screenX, screenY, menubar);
}
function popDlg( location, name, w, h , scrollbars, resizable, screenX, screenY, menubar) 
{
	if( w == null ) { w = 300; }
	if( h == null ) { h = 200; }
	if(screenX == null) screenX = "150";
	if(screenY == null) screenY = "120";
	if( menubar == null) menubar = "0";
	if(scrollbars == null) scrollbars="0";
	if(resizable == null) resizable="0";	

var toolbar = "menubar="+menubar+",scrollbars="+scrollbars+",resizable="+resizable+",width="+w+",height="+h+",center=true";
	var editorWin = window.open(location,name, toolbar);
	editorWin.focus(); 
}
function openImage(ImageName) {
  PopUpWindow=window.open("/","ImageViewer","status=no,resizable=no,width=90,height=110,top=10,left=10");     
  PopUpWindow.document.writeln('<html>');
  PopUpWindow.document.writeln('<head>');
  PopUpWindow.document.writeln('<title>Xem anh</title>');   
  PopUpWindow.document.writeln('</head>');

  if (navigator.appName == "Microsoft Internet Explorer") 
  	  // in IE resizeTo give the outer of the window
     PopUpWindow.document.writeln('<body topmargin="0" leftmargin="0" marginwidth="0" marginheight="0" onLoad="window.resizeTo(document.images[0].width+10,document.images[0].height+ 55)">');   
      // resize the window to match the picture

   else
       PopUpWindow.document.writeln('<body topmargin="0" leftmargin="0" marginwidth="0" marginheight="0" onLoad="window.resizeTo(document.images[0].width+10,document.images[0].height+55)">');   
          // resize the window to match the picture
  PopUpWindow.document.writeln('<center><a href="/" onClick=window.close()><img src="'+ImageName+' " border="0">');
  PopUpWindow.document.writeln("</body></html>");

// load the image in the window
  PopUpWindow.document.writeln('</body>');
  PopUpWindow.document.writeln('</html>');
  PopUpWindow.document.close();
  PopUpWindow.focus();  // place the window in front
}

function openFile(item,pageid,how){
	window.open(pageid+'&opt=brpage&item='+item+'&how='+how,'_blank');
}
function saveFile(item,pageid,how){
	window.open(pageid+'&opt=brpage&item='+item+'&act=save&how='+how,'_self');
}
function viewFile(item,pageid,how){
	window.open(pageid+'&opt=brpage&item='+item+'&act=view&how='+how,'_blank');
}

function expandMe(id) {
	var obj = document.getElementById(id);
	if(obj!=null){
		var color = 'red';
		var act = null;
		var cls = null;
		var title = 'Mở xuống';
		
		var box = document.getElementById(id+'_box');
		if(box!=null) cls = box.className;

		//if(cls==null) color = 'red';
		//else color = 'white';

		if(obj.className=='off'){
			obj.className = 'on';
			title = 'Thu lại';
			
			act = 'dropto';
		}
		else{
			obj.className = 'off';
			
			act = 'arrowto';
		}
		obj.data = true;
		
		var img = document.getElementById(id+'_img');
		if(img!=null){
			img.src = 'images/'+act+'_'+color+'.gif';
			img.title = title;
		}		
	}
}
function closeMe() {
	opener.location.reload();
	self.close();
}
function checkDelete(msg) {
 var value = confirm(msg);
	if (value == true) {
		return true;
	} else {
		return false;
	}
}
function radioVal(name){
	var val=null;
	var aCheckBoxes=document.getElementsByName(name);
	var nRows = aCheckBoxes.length;
	for (var i = 0; i < nRows; i++) {
		if(aCheckBoxes[i].checked){
			return aCheckBoxes[i].value;
		}
	}
	return false;
}
function selectedVals(name){
	var val=null;
	var aSelects=document.getElementById(name);
	var nRows = aSelects.length;
	for (var i = 0; i < nRows; i++) {
		if(aSelects[i].selected){
			if(val==null) val = aSelects[i].value;
			else val = val + ',' + aSelects[i].value;
		}
	}
	return val;
}
function checkValsByName(name,sep){
	var val=null;
	var aSelects=document.getElementsByName(name);
	var nRows = aSelects.length;
	for (var i = 0; i < nRows; i++) {
		if(aSelects[i].checked){
			if(val==null) val = aSelects[i].value;
			else val = val + sep + aSelects[i].value;
		}
	}
	return val;
}
function textValsByName(name,sep){
	var val=null;
	var aSelects=document.getElementsByName(name);
	var nRows = aSelects.length;
	for (var i = 0; i < nRows; i++) {
		if(aSelects[i].value!=null&&aSelects[i].value!=''){
			if(val==null) val = aSelects[i].value;
			else val = val + sep + aSelects[i].value;
		}
	}
	return val;
}
function Logo_FloatTopDiv(id,edge)
{
	var obj = document.getElementById(id);
	
	var startX = document.body.clientWidth - obj.clientWidth, startY = 50;
	if(edge=='left') startX = 0;

	var ns = (navigator.appName.indexOf("Netscape") != -1);
	var d = document;					
	function ml()	{
		var el = d.getElementById?d.getElementById(id):d.all?d.all[id]:d.layers[id];
		if(d.layers) el.style = el;
		if(document.body.clientWidth<1000) el.style.display = 'none';
		else el.style.display = '';

		el.sP = function(x,y){this.style.left=x;this.style.top=y;};
		
		el.x = startX;
		if (verticalpos=="fromtop")	el.y = startY;
		else {
			el.y = ns ? pageYOffset + innerHeight : document.body.scrollTop + document.body.clientHeight;
			el.y -= startY;
		}
		return el;
	}
	window.stayTopLeft=function() {
		var main_tab_w = document.getElementById('main_tab').clientWidth;
		if(main_tab_w<700) main_tab_w = 775;
		var left_X = (document.body.clientWidth - main_tab_w) / 2 - obj.clientWidth - 1;
		var right_X = (document.body.clientWidth - main_tab_w) / 2 + main_tab_w + 1;

		if (document.body.scrollTop > 50){startY = 0} else {startY = 50};
		if(document.body.clientWidth<995) {
			ftlObj.style.display = 'none';
			if(leftBox!=null) leftBox.style.display = 'none';
			if(rightBox!=null) rightBox.style.display = 'none';
		}
		else {
			ftlObj.style.display = '';
			if(leftBox!=null) leftBox.style.display = '';
			if(rightBox!=null) rightBox.style.display = '';
		};

		if (verticalpos=="fromtop"){
			var pY = ns ? pageYOffset : document.body.scrollTop;
			ftlObj.y += (pY + startY - ftlObj.y)/8;
		}
		else{
			var pY = ns ? pageYOffset + innerHeight : document.body.scrollTop + document.body.clientHeight;
			ftlObj.y += (pY - startY - ftlObj.y)/8;
		}
		
		if(leftBox!=null) leftBox.sP(left_X, ftlObj.y);
		if(rightBox!=null) rightBox.sP(right_X, ftlObj.y);//document.body.clientWidth - rightBox.clientWidth
		setTimeout("stayTopLeft()", 15);
	}
	
	ftlObj = ml();
	if(edge=='left') leftBox = ftlObj;
	else rightBox = ftlObj;
	stayTopLeft();
}
function Panel_FloatTopDiv(id,edge)
{
	var obj = document.getElementById(id);
	document.getElementById('loadCont').height=document.body.clientHeight-4;
	var startX = document.body.clientWidth - obj.clientWidth, startY = 50;
	if(edge=='left') startX = 0;

	var ns = (navigator.appName.indexOf("Netscape") != -1);
	var d = document;					
	function ml()	{
		var el = d.getElementById?d.getElementById(id):d.all?d.all[id]:d.layers[id];
		if(d.layers) el.style = el;
		if(document.body.clientWidth<1000) el.style.display = 'none';
		else el.style.display = '';

		el.sP = function(x,y){this.style.left=x;this.style.top=y;};
		
		el.x = startX;
		if (verticalpos=="fromtop")	el.y = startY;
		else {
			el.y = ns ? pageYOffset + innerHeight : document.body.scrollTop + document.body.clientHeight;
			el.y -= startY;
		}
		return el;
	}
	window.stayTopRight=function() {
		var main_tab_w = document.getElementById('main_tab').clientWidth;
		if(main_tab_w<700) main_tab_w = 775;
		var right_X = main_tab_w + 3;

		if (document.body.scrollTop > 30){startY = 2} else {startY = 2};//30
		if(document.body.clientWidth<995) {
			ftlObj.style.display = 'none';
			if(leftBox!=null) leftBox.style.display = 'none';
			if(rightBox!=null) rightBox.style.display = 'none';
		}
		else {
			ftlObj.style.display = '';
			if(leftBox!=null) leftBox.style.display = '';
			if(rightBox!=null) rightBox.style.display = '';
		};

		if (verticalpos=="fromtop"){
			var pY = ns ? pageYOffset : document.body.scrollTop;
			ftlObj.y += (pY + startY - ftlObj.y)/8;
		}
		else{
			var pY = ns ? pageYOffset + innerHeight : document.body.scrollTop + document.body.clientHeight;
			ftlObj.y += (pY - startY - ftlObj.y)/8;
		}
		
		if(rightBox!=null) rightBox.sP(right_X, ftlObj.y);//document.body.clientWidth - rightBox.clientWidth
		setTimeout("stayTopRight()", 15);
	}
	
	ftlObj = ml();
	rightBox = ftlObj;
	stayTopRight();

	return document.getElementById('loadCont').height;
}
var keyStr = "ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789+/=";

function encode64(input) {
   var output = "";
   var chr1, chr2, chr3;
   var enc1, enc2, enc3, enc4;
   var i = 0;

   do {
      chr1 = input.charCodeAt(i++);
      chr2 = input.charCodeAt(i++);
      chr3 = input.charCodeAt(i++);

      enc1 = chr1 >> 2;
      enc2 = ((chr1 & 3) << 4) | (chr2 >> 4);
      enc3 = ((chr2 & 15) << 2) | (chr3 >> 6);
      enc4 = chr3 & 63;

      if (isNaN(chr2)) {
         enc3 = enc4 = 64;
      } else if (isNaN(chr3)) {
         enc4 = 64;
      }

      output = output + keyStr.charAt(enc1) + keyStr.charAt(enc2) + 
         keyStr.charAt(enc3) + keyStr.charAt(enc4);
   } while (i < input.length);
   
   return output;
}
function copy2clipb(text2copy) {
	if (window.clipboardData) {
		window.clipboardData.setData("Text",text2copy);
	}
	else {
		var flashcopier = 'flashcopier';
		if(!document.getElementById(flashcopier)) {
			var divholder = document.createElement('div');
			divholder.id = flashcopier;
			document.body.appendChild(divholder);
		}
		
		document.getElementById(flashcopier).innerHTML = '';
		var divinfo = '<embed src="/wtools/_clipboard.swf" FlashVars="clipboard='+encodeURIComponent(text2copy)+'" width="0" height="0" type="application/x-shockwave-flash"></embed>';
		document.getElementById(flashcopier).innerHTML = divinfo;
	}
}
function voiD(){;}
