﻿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 showModalDialog2(sURL , vArguments , sFeatures)
{
	if(window.showModalDialog) {
		return window.showModalDialog(sURL , vArguments , sFeatures);
	}
	else {
		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;
			}
		}
		
		PopUpWindow = window.open(sURL,vArguments,sFeatures+'modal=yes,centered=yes,dialog=yes'); 
	}
}
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 = 250} else {startY = 200};
		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();
}
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 voiD(){;}
