﻿/*All the initial variant and function define in this file
    1. varInit.js is put at the head
    2. var Object put at the bottom
    3. biilib put at the the end
*/

function pageLoad(){
    privatePageLoad();  //Each page have to define this function
}

//------ Head Tool Bar ----------------------------- 

function changeTxtTCodeStatus(obj,txttcodeid){if(obj.className=='hideTCodeTxt'){obj.className = 'showTCodeTxt';$id(txttcodeid).style.display = 'none';}else{obj.className = 'hideTCodeTxt';$id(txttcodeid).style.display = 'block';}}
function openNewSession(){window.open(hostAdd,'_blank','width=400,height=200,toolbar=yes,location=yes,directories=yes,status=yes,menubar=yes,scrollbars=yes,copyhistory=yes,resizable=yes','')}

//------------------------------------------------

//---------virtual windows------------------
var _isvirwinshow = false;
virtualWin = function(){};    //Dung de tao cua so nho ben trong window...
virtualWin.prototype.init = function(){
    //neu da co cua so ao, remove truoc.
    terminateVirWin();
    var membranediv = document.createElement("div");
    membranediv.setAttribute('id','MembraneDiv');
    document.body.appendChild(membranediv);
    membranediv.style.width= '100%';
    membranediv.style.height= '100%';
    //khoi tao khung chua cua so ao
    var windiv = document.createElement("div");windiv.setAttribute('id','WinDiv');windiv.className='virtualwin';windiv.style.height = this.height + 'px';windiv.style.width = this.width + 'px';windiv.style.top = this.top + 'px';windiv.style.left = this.left + 'px';document.body.appendChild(windiv);
    //tao thanh title
    var mytitle = '<DIV class=\'titlebar\' onmousedown="startMoveMe(\'WinDiv\',event)">';
    mytitle += '<table cellpadding="0" cellspacing="0" style="width:100%;height:16px;"><tr>';
    mytitle += '    <td style="height:15px;border-bottom:2px solid rgb(255,153,0);background:white;">';
    mytitle += '        <DIV style="padding-left:5px;padding-top:2px;height:16px;width:'+(this.width-50)+'px;overflow:hidden;white-space:nowrap;text-overflow:ellipsis;">'+this.title+'</DIV></td>';
    mytitle += '    <td style="height:16px;background:url(images/virwin-corner-top.gif) right no-repeat;text-align:right;width:40px">';
    mytitle += '        <img alt="Close" src="images/closewin.gif"';
    mytitle += '        style="margin-top:2px; margin-right:25px;cursor:default" onclick="terminateVirWin()"></td></tr></table></DIV>';
    windiv.innerHTML += mytitle;
    var mybody = '<DIV style="padding-left:10px;padding-top:20px">'+this.body+'</DIV';
    windiv.innerHTML += mybody;
    _isvirwinshow=true;
}
function terminateVirWin(){
    try{document.body.removeChild($id('WinDiv'));_isvirwinshow=false}catch(e){}
    try{document.body.removeChild($id('MembraneDiv'))}catch(e){}
}
function checkOutClickVirWin(e){    
    if(_isvirwinshow){
        getMousePos(e);
        var virwin = $id('WinDiv');
        var virwintop = findTopPos(virwin);
        var virwinleft= findLeftPos(virwin);
        if( (pX > virwinleft) && (pX < (virwinleft + getWidth(virwin))) && (pY > virwintop) && (pY < (virwintop + getHeight(virwin))) ){
            return true;
        }else{
            return false;
        }
    }else{
        return true;
    }
}
//------------------------------------------------

//----------- context menu------------------------
var _ctmnItemNum = 1;        //Ghi nhan so menu item hien co
var _currChildCTMenu;
var _mouseOnCTMenu = false;  //Khod nay dung on/off contextmenu khi click vao body
var hotKeyWidthArr = new Array();
CTMenu = function (){
    this.printOut = function(parentId){
        var windiv = document.createElement("div");windiv.setAttribute('id','mycontextmenu');windiv.className='menuparent';windiv.style.position='absolute';document.body.appendChild(windiv);
        var str = '    <Table cellpadding="0" cellspacing="0" onmouseover="_mouseOnCTMenu = true;" onmouseout="_mouseOnCTMenu = false;">';
        str += '        <tr valign="top">';
        str += '            <td><DIV class="menucontent" id="'+parentId+'_menucontent"></DIV></td>';
        str += '            <td valign="bottom"><DIV class="shadow_right_top" id="'+parentId+'_shadow_right_top"></DIV><DIV class="shadow_right" id="'+parentId+'_shadow_right"></div></td></tr>';
        str += '        <tr>';
        str += '            <td style="height:3px;text-align:right"><Table cellpadding="0" cellspacing="0"><tr><td class="shadow_bottom_left" id="'+parentId+'shadow_bottom_left"></td><td class="shadow_bottom" id="'+parentId+'shadow_bottom"></td></tr></Table></td>';
        str += '            <td class="shadow_bottom_right" id="'+parentId+'shadow_bottom_right"></td></tr>';
        str += '    </Table>';
        windiv.innerHTML = str;
        //shadow effect
        blurObj($id(parentId+'_shadow_right_top'),70);
        blurObj($id(parentId+'_shadow_right'),70);
        blurObj($id(parentId+'shadow_bottom_left'),70);
        blurObj($id(parentId+'shadow_bottom'),70);
        blurObj($id(parentId+'shadow_bottom_right'),70);
    }
    this.align = function(e){
        getMousePos(e);
        var mycontextmenu = $id('mycontextmenu');
        if(bodyHeight > (getHeight(mycontextmenu)+pY)){
            mycontextmenu.style.top= pY+'px';
        }else{
            mycontextmenu.style.top = pY - getHeight(mycontextmenu) +'px';
        }
        if(bodyWidth > (getWidth(mycontextmenu)+pX)){
            mycontextmenu.style.left= pX+'px';
        }else{
            mycontextmenu.style.left= pX - getWidth(mycontextmenu)+ 'px';
        }        
    }
    this.define = function(id,obj,mn){
        this.id = id;this.obj = obj;this.name = mn;this.paddingleft = 6;this.printOut(id);this.menuItemNumber = 0;    //So menu item trong top menu
    }
    
}
CTMenu.prototype.addmenuitem = function(parentId,txt,fn,type,hotkey,childname){
    var str;    
    switch(type){
 	    case 'breakline':
 	        str = '<DIV class="menu_breakline"></DIV>';$id(parentId+'_menucontent').innerHTML += str;
 	        break; 
 	    case 'havechild':
 	        if(childname==''){alert('You still not define childname parameter')}
 	        str = '<DIV class="menuhavechild" id="'+parentId+'_'+_ctmnItemNum+'" '; 	         	        
 	        str += ' onmouseover="'+this.name+'.setMenuParentHover(this.id)" ';
 	        str += ' onmouseout="'+this.name+'.setMenuParentOut(this.id)">'; 	        
 	        str += '<TABLE cellpadding="0" cellspacing="0" width="100%" ';
 	        str += '    onmouseover="'+this.name+'.showChildMenu(\''+parentId+'_mn\',\''+parentId+'_'+_ctmnItemNum+'\',\''+childname+'\')"><TR><TD class="menuitem_icon"></TD><TD class="menuitem_text">'+txt+'</TD>';
 	        str += '<TD class="menuitem_hotkey" id="'+parentId+'_hotKey_'+_ctmnItemNum+'"><DIV>'+hotkey+'<DIV></TD>';
 	        str += '<TD class="menuitem_arrow" >&nbsp;</TD>';
 	        str += '</TR></TABLE></DIV>';   //test
 	        $id(parentId+'_menucontent').innerHTML += str;
 	        break; 
        default:
            str = '<DIV class="menuitem" id="'+parentId+'_'+_ctmnItemNum+'" onmouseover="'+this.name+'.setMenuItemHover(this.id)" ';
            str += ' onmouseout="'+this.name+'.setMenuItemOut(this.id)" onclick="'+fn+';hideCTMenuAfterFunc()">';
            str += '<TABLE cellpadding="0" cellspacing="0" width="100%"><TR><TD class="menuitem_icon"></TD><TD class="menuitem_text">'+txt+'</TD>';
            str += '<TD class="menuitem_hotkey" id="'+parentId+'_hotKey_'+_ctmnItemNum+'">'+hotkey+'</TD><TD style="width:15px;"></TD></TR></TABLE></DIV>';
            $id(parentId+'_menucontent').innerHTML += str;
            if(hotKeyWidthArr[parentId]<$id(parentId+'_hotKey_'+_ctmnItemNum).offsetWidth){
                hotKeyWidthArr[parentId] = getWidth($id(parentId+'_hotKey_'+_ctmnItemNum));    //set gia tri max width cho hotkey div nham sap xep menu cho thang hang
            }
            for(i=1;i<_ctmnItemNum;i++){try{$id(parentId+'_hotKey_'+_ctmnItemNum).style.width = hotKeyWidthArr[parentId]}catch(e){}}
            break;
 	}
    _ctmnItemNum += 1;
    //moi lan them menu item xong phai dinh dang lai menu
    $id(parentId+'_shadow_right').style.height = getHeight($id(parentId+'_menucontent')) - 10 + 'px';
    $id(parentId+'shadow_bottom').style.width = getWidth($id(parentId+'_menucontent')) -10+ 'px';  
}
CTMenu.prototype.showChildMenu = function(parentId,parentItemId,childname){
    if(mainMNStat==1){        
        try{$id(_currChildCTMenu).style.left = - 500 + 'px'}catch(e){}//phai co mot khoa ngan chan self hide                  
        try{$id(parentId+'_mn'+childname).style.left = findLeftPos($id(parentId)) + getWidth($id(parentId)) -10 + 'px'}catch(e){} 
        try{$id(parentId+'_mn'+childname).style.top = findTopPos($id(parentItemId)) + 'px'}catch(e){} 
        _currChildCTMenu = parentId+'_mn'+childname;      
    }
}
CTMenu.prototype.setMenuItemHover = function(id){$id(id).className='menuitem_hover'}
CTMenu.prototype.setMenuItemOut = function(id){$id(id).className='menuitem'}
hideCTMenuAfterFunc = function(id){try{document.body.removeChild($id('mycontextmenu'))}catch(e){}}
hideAllCTMenu = function(id){
    if(!_mouseOnCTMenu){
        try{document.body.removeChild($id('mycontextmenu'))}catch(e){}    //Dung cho ca contextmenu          
    }
}
var mycontext = new CTMenu;
//------------------------------------------------

//----------- Special effect ---------------------
function slideObj(obj,objstylefloat,fX,fY,tX,tY,t,slideStep){
    //Ham nay dung de truot doi tuong theo duong thang.
    //kiem tra tham so truyen vao...
    if(slideStep<=0){alert('slideStep must be greater than 0');return false}
    if(t<=0){alert('Total slide time(t) must be greater than 0');return false}
    if(typeof(obj)!='object'){alert('obj is not an object');return false}
    //Dinh nghia cac bien.
    obj.style.position = objstylefloat;
    this.fromX = fX;        //Hoanh do ban dau
    this.fromY = fY;        //Tung do ban dau
    this.dX = (tX - fX)/slideStep;
    this.dY = (tY - fY)/slideStep;
    this.startSlide = function(){        
        if(slideStep>=0){
            this.fromX += this.dX;this.fromY += this.dY;slideStep -= 1;
            obj.style.top = parseInt(this.fromY) + 'px';obj.style.left = parseInt(this.fromX) + 'px';
            setTimeout("this.startSlide()",t);
        }
    }
    this.startSlide();
}
function expandObj(obj,direct,fX,fY,tX,tY,t,slideStep){
    //Ham nay dung de truot doi tuong theo duong thang.
    //kiem tra tham so truyen vao...
    if(slideStep<=0){alert('slideStep must be greater than 0');return false}
    if(t<=0){alert('Total slide time(t) must be greater than 0');return false}
    if(typeof(obj)!='object'){alert('obj is not an object');return false}
    //Dinh nghia cac bien.
    this.fromX = fX;        //Hoanh do ban dau
    this.fromY = fY;        //Tung do ban dau
    this.dX = (tX - fX)/slideStep;
    this.dY = (tY - fY)/slideStep;
    this.startSlide = function(){
        if(slideStep>=0){
            this.fromX += this.dX;this.fromY += this.dY;slideStep -= 1;
            try{obj.style.height = parseInt(this.fromY) + 'px';}catch(e){}
            try{obj.style.width = parseInt(this.fromX) + 'px';}catch(e){}
            setTimeout("this.startSlide()",t);
        }else{
            if(direct=='up')obj.style.display = 'none';
        }
    }
    this.startSlide();
}
function blurObj(element,curOpVal){
    if(is_ie){element.style.filter = 'alpha(opacity = ' + curOpVal + ')';}else{element.style.opacity = curOpVal/100;} 
}
function animateFade(eid,fadeMode,curOpVal){
    var element = $id(eid); var newCurOpVal;      
    if(curOpVal>=0 && curOpVal<=100){
        fadeMode=='out'?curOpVal-=10:curOpVal+=10;
        if(is_ie){element.style.filter = 'alpha(opacity = ' + curOpVal + ')';}else{element.style.opacity = curOpVal/100;}         
        setTimeout("animateFade('" + eid + "','" + fadeMode + "'," + curOpVal + ")", 30);         
    }
}
function fadeOutObj(eid){animateFade(eid,'out',100)}
function fadeInObj(eid){animateFade(eid,'in',0)}

//------------------------------------------------


//------general function-----------------------------
var Dom = {
  get: function(el) {
    if (typeof el === 'string') {
      return $id(el);
    } else {
      return el;
    }
  },
  add: function(el, dest) {
    var el = this.get(el);
    var dest = this.get(dest);
    dest.appendChild(el);
  },
  remove: function(el) {
    var el = this.get(el);
    el.parentNode.removeChild(el);
  }
  };
var Event = {
  add: function() {
    if (window.addEventListener) {  //FF
      return function(el, type, fn) {
        if(type=='mousewheel')type = 'DOMMouseScroll';
        Dom.get(el).addEventListener(type, fn, false);
      };
    } else if (window.attachEvent) {//IE
      return function(el, type, fn) {
        var f = function() {
          if (!e)var e = window.event||window.Event;
          fn.call(Dom.get(el), e);
        };
        Dom.get(el).attachEvent('on' + type, f);
      };
    }
  }()
 };
window.onresize = function () {
    try{mainAlignPage()}catch(e){}
    try{privateAlignPage()}catch(e){}
    try{
        if(_winMainDiv && is_ie6){
            //getBodySize();
            _winMainDiv.style.height = bodyHeight - 25 + 'px';
        }
    }catch(ex){}
    try{
        
    }catch(ex){}
}
document.onmousedown = function(e){       //Doan nay dung cho drag
    try{hideAllCTMenu()}catch(e){};
    try{if(!_mouseonimotpad){$id('emoticonsParentDiv').style.display = 'none';}}catch(e){};
    try{if(!_mouseonimotpad){$id('editorRemoticonsParentDiv').style.display = 'none';}}catch(e){};
    try{if(!_mouseonrequestDiv){$id('requestDiv').style.display = 'none';}}catch(e){}
    return checkOutClickVirWin(e);    
}
document.onmousemove = function(e){
    try{mM(e)}catch(e){};
    
}
document.onmouseup = function(e){
    try{mU(e)}catch(e){} 
}
document.onkeydown = function(){
    //Disable F5
    if(window.event && window.event.keyCode == 116)window.event.keyCode = 505;
    //Disable F3
    if(window.event && window.event.keyCode == 114)window.event.keyCode = 505;
    if(window.event && window.event.keyCode == 505)return false;
}
//--------------encode base 64 ---------------
var ua = navigator.userAgent.toLowerCase();
if (ua.indexOf(" chrome/") >= 0 || ua.indexOf(" firefox/") >= 0 || ua.indexOf(' gecko/') >= 0) {
	var StringMaker = function () {
		this.str = "";
		this.length = 0;
		this.append = function (s) {
			this.str += s;
			this.length += s.length;
		}
		this.prepend = function (s) {
			this.str = s + this.str;
			this.length += s.length;
		}
		this.toString = function () {
			return this.str;
		}
	}
} else {
	var StringMaker = function () {
		this.parts = [];
		this.length = 0;
		this.append = function (s) {
			this.parts.push(s);
			this.length += s.length;
		}
		this.prepend = function (s) {
			this.parts.unshift(s);
			this.length += s.length;
		}
		this.toString = function () {
			return this.parts.join('');
		}
	}
}
var keyStr = "ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789+/=";
function encode64(input) {
	var output = new StringMaker();
	var chr1, chr2, chr3;
	var enc1, enc2, enc3, enc4;
	var i = 0;
	while (i < input.length) {
		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.append(keyStr.charAt(enc1) + keyStr.charAt(enc2) + keyStr.charAt(enc3) + keyStr.charAt(enc4));
   }   
   return output.toString();
}

function decode64(input) {
	var output = new StringMaker();
	var chr1, chr2, chr3;
	var enc1, enc2, enc3, enc4;
	var i = 0;
	// remove all characters that are not A-Z, a-z, 0-9, +, /, or =
	input = input.replace(/[^A-Za-z0-9\+\/\=]/g, "");
	while (i < input.length) {
		enc1 = keyStr.indexOf(input.charAt(i++));
		enc2 = keyStr.indexOf(input.charAt(i++));
		enc3 = keyStr.indexOf(input.charAt(i++));
		enc4 = keyStr.indexOf(input.charAt(i++));
		chr1 = (enc1 << 2) | (enc2 >> 4);
		chr2 = ((enc2 & 15) << 4) | (enc3 >> 2);
		chr3 = ((enc3 & 3) << 6) | enc4;
		output.append(String.fromCharCode(chr1));
		if (enc3 != 64) {
			output.append(String.fromCharCode(chr2));		}
		if (enc4 != 64) {
			output.append(String.fromCharCode(chr3));
		}
	}
	return output.toString();
}
//-----------------------------------------------
String.prototype.trim = function() { return this.replace(/^\s+|\s+$/, ''); };
String.prototype.alltrim = function() { return this.replace(/^\s+|\s+$/g, ''); };
String.prototype.ltrim = function() { return this.replace(/^\s+/, ''); };
String.prototype.rtrim = function() { return this.replace(/\s+$/, ''); };
String.prototype.endWith=function(oString){var reg=new RegExp(oString+"$","ig");return reg.test(this);}
String.prototype.contains=function(oString){return(this.indexOf(oString)>-1);}
Array.prototype.clean = function(val) {for(var i = 0; i < this.length; i++){if(this[i] == val){this.splice(i, 1);i--;}}return this;}
Array.prototype.content = function(v){var check = false;for(var i = 0; i < this.length; i++){if(this[i] == v){check = true;}}return check;}
String.prototype.generatePostData = function(){var str = this.replace(/&/g,'%26');str = str.replace(/\|\*\|\?\|/gi,'-splitpage-');str = str.replace(/\|messinf\|/gi,'-splitmessinf-');str = str.replace(/\|messsplit\|/gi,'-splitmesssplit-');return str;}
String.prototype.haveWhiteSpace = function(){return /\s/g.test(this);};
String.prototype.isEmail = function(){    
    var str = this.alltrim();
    if(str=='')return false;
    var at="@";
    var dot=".";
    var lat=str.indexOf(at);
    var lstr=str.length;
    var ldot=str.indexOf(dot);
    if (str.indexOf(at)==-1)return false;
	if (str.indexOf(at)==0 || str.indexOf(at)==str.length)return false;
	if (str.indexOf(dot)==-1 || str.indexOf(dot)==0 || str.indexOf(dot)==lstr)return false;
	if (str.indexOf(at,(lat+1))!=-1)return false;
	if (str.substring(lat-1,lat)==dot || str.substring(lat+1,lat+2)==dot)return false;
	if (str.indexOf(dot,(lat+2))==-1)return false;	
	if (str.indexOf(" ")!=-1)return false;
	return true
}
if (/*@cc_on!@*/false) {document.onfocusin = onFocus;document.onfocusout = onBlur;} else { window.onfocus = onFocus;window.onblur = onBlur;}
function onFocus(){_documentfocus = true;clearInterval(_alertTimeOut);document.title = _oldTitle;}
function onBlur(){_documentfocus = false;}
function newMessComingAlerts(msg) {clearInterval(_alertTimeOut);_alertTimeOut = setInterval(function() {document.title = document.title == msg ? _oldTitle : msg;}, 1000);}

function getKeyCode(e){if (!e){var e = window.event||window.Event;}var key =  e.keyCode ? e.keyCode : e.which ? e.which : e.charCode;return key}
function findTopPos(obj){var curtop = 0;if (obj.offsetParent) {do {curtop += obj.offsetTop;} while (obj = obj.offsetParent);}return parseInt(curtop);}
function findLeftPos(obj) {var curleft = 0;if (obj.offsetParent){do {curleft += obj.offsetLeft;} while (obj = obj.offsetParent);}return parseInt(curleft);}
function assignScrollPos(parentScroll){
    _parentScrollTop = parentScroll.scrollTop; 
    _parentScrollLeft = parentScroll.scrollLeft;
}
function getWidth(obj){if(getStyle(obj,'display')=='none'){return 0}else{return parseInt(obj.offsetWidth)}}
function getHeight(obj){if(getStyle(obj,'display')=='none'){return 0}else{return parseInt(obj.offsetHeight)}}
function getStyle(el,styleProp){try{var x = el;if (x.currentStyle){var y = x.currentStyle[styleProp];}else if (window.getComputedStyle){var y = document.defaultView.getComputedStyle(x,null).getPropertyValue(styleProp)}return y}catch(e){}}
function getBodySize(){if( typeof( window.innerWidth ) == 'number' ){/*Non-IE*/bodyWidth = window.innerWidth;bodyHeight = window.innerHeight;} else {if( document.documentElement &&( document.documentElement.clientWidth || document.documentElement.clientHeight ) ) {/*IE 6+ in 'standards compliant mode'*/bodyWidth = document.documentElement.clientWidth;bodyHeight = document.documentElement.clientHeight;} else {if( document.body && ( document.body.clientWidth || document.body.clientHeight ) ) {/*IE 4 compatible*/bodyWidth = document.body.clientWidth;bodyHeight = document.body.clientHeight;}}}}

function getMousePos(e){if(!e)var e = window.event||window.Event; switch(navigator.appName){case 'Microsoft Internet Explorer': scrollX = getInternetExplorerVersion() > 6 ? document.documentElement.scrollLeft : document.body.scrollLeft; scrollY = getInternetExplorerVersion() > 6 ? document.documentElement.scrollTop : document.body.scrollTop;break; default:scrollY = window.pageYOffset;}pX = is_ff ? e.pageX : e.clientX + scrollX;pY = is_ff ? e.pageY : e.clientY + scrollY;}
function playSound(surl) {
    if(!$id('playSoundDiv')){var playDiv = document.createElement('div');playDiv.setAttribute('id','playSoundDiv');playDiv.style.zIndex = 1001;_winMainDiv.appendChild(playDiv);}
    $id('playSoundDiv').innerHTML = '<OBJECT id="mediaPlayer" name="MediaPlayer" width="1" height="1" classid="clsid:6BF52A52-394A-11D3-B153-00C04F79FAA6"><param name="URL" value="'+hostAdd+'/'+surl+'"><param name="volume" value="100"><param name="PlayCount" value="1"><param name="Autostart" value="1"><EMBED type="application/x-mplayer2" pluginspage="http://microsoft.com/windows/mediaplayer/en/download/" id="mediaPlayer" name="mediaPlayer" width="1" height="1" src="'+hostAdd+'/'+surl+'" autostart="1" loop="0"> </EMBED></object>';
}
function alertInputSuccess(txt){    
    _AttDiv.style.backgroundColor='rgb(37,165,47)';_AttDiv.innerHTML='<table><tr valign=top><td><img alt="" id="errimg" src="css/img/success.gif" style="position:relative"\></td><td><div style="">'+txt+'</div></td></tr></table>';
	setTimeout("_AttDiv.style.backgroundColor='rgb(190,200,210)';",1000);$id('errimg').style.top = -5 + 'px';playSound('sound/ding.wav');
}
function alertInputErr(txt){
    _AttDiv.style.backgroundColor='rgb(255,0,0)';_AttDiv.innerHTML='<table><tr valign=top><td><img alt="" id="errimg" src="css/img/error.gif" style="position:relative"\></td><td><div style="">'+txt+'</div></td></tr></table>';
	setTimeout("_AttDiv.style.backgroundColor='rgb(190,200,210)';",1000);$id('errimg').style.top = -5 + 'px';playSound('sound/ding.wav');
}
function alertInputAtt(txt){
    _AttDiv.style.backgroundColor='rgb(255,160,12)';_AttDiv.innerHTML='<table><tr valign=top><td><img alt="" id="errimg" src="css/img/error.gif" style="position:relative"\></td><td><div style="">'+txt+'</div></td></tr></table>';
	setTimeout("_AttDiv.style.backgroundColor='rgb(190,200,210)';",1000);$id('errimg').style.top = -5 + 'px';playSound('sound/ding.wav');
}
function checkIsEmpty(num){if(num.replace(/^\s+|\s+$/gi,'')==''){return true}else{return false}}
function getInternetExplorerVersion(){
// Returns the version of Internet Explorer or a -1
// (indicating the use of another browser).
      var rv = -1; // Return value assumes failure.
      if (navigator.appName == 'Microsoft Internet Explorer'){
        var ua = navigator.userAgent;
        var re  = new RegExp("MSIE ([0-9]{1,}[\.0-9]{0,})");
        if (re.exec(ua) != null)
          rv = parseFloat( RegExp.$1 );
      }
      return rv;
}

//------------------------------------------------
//------------------------------------------------

//Drag-drop-resize functions
//Declare global variable for draging, resize or drag-drop
var dragObject, resizeObj, offsetX, offsetY;
var isDragging=false;
var isMouseMove = false;
var resizerule; //for datagrid
var dragX=false;
var dragY=false;
var isResize=false;
var isResizeDataGrid = false;
var resizeX=false;
var resizeY=false;
var firstX, lastX, lastY;
var currentGrid;
//**************************************** 
//Phan nay dung move object
function startMoveMe(ob,e){
    try{hideListButton()}catch(e){};
    dragObject = $id(ob);
    getMousePos(e);
    isDragging = true;    
	offsetX = pX - findLeftPos(dragObject);
	offsetY = pY - findTopPos(dragObject);
	dragX=true;
	dragY=true;
	return false;	
}
function mM(e){
    if (!isDragging) return false;
    isMouseMove = true;
	getMousePos(e);
	var newX = pX - offsetX;
	var newY = pY - offsetY;
	var delta = 0;  //delta width for resize grid
	lastX = newX;   //user for grid 
	//--------use for tiny data grid-------->
	if(typeof(currentGrid)!='undefined' && currentGrid.isScrollGridY){
	        var a = findTopPos(currentGrid.verscrbar);
	        var b = getHeight(currentGrid.verscrbar) - currentGrid.slidebarheight;
	        if(newY<a+2){return false};if(newY>(a + b - 2)){return false};	          
	        //dragObject.style.top = newY + "px";
	        var c = newY - a -2;
	        var d = c/b;
	        var e = currentGrid.p3DataHeight-currentGrid.p3Height-4;
	        var f = e*c/b;
	        currentGrid.p3.scrollTop = f;
	        currentGrid.p4.scrollTop = f;
	        currentGrid.scrTop = f;
	}	
	if(typeof(currentGrid)!='undefined' && currentGrid.isScrollGridX){
	        var a = findLeftPos(currentGrid.horscrbar);
	        var b = getWidth(currentGrid.horscrbar) - currentGrid.slidebarwidth;
	        if(newX<a+2){return false};
	        if(newX>(a + b - 3)){return false};
	        //dragObject.style.left = newX + "px";
	        var c = newX - a -2;
	        var d = c/b;
	        var e = currentGrid.p2DataWidth-currentGrid.p2Width-4;
	        var f = e*c/b;
	        currentGrid.p2.scrollLeft = f;
	        currentGrid.p4.scrollLeft = f;
	        currentGrid.scrLeft = f;
	}
	//move oject
	if(dragX)dragObject.style.left = newX + "px";
	if(dragY)dragObject.style.top = newY + "px";
	
	if(isResizeDataGrid){
	    delta=7;
	    if(pX>(findLeftPos(currentGrid.gridbody)+getWidth(currentGrid.gridbody))){return false}
	    resizerule.style.left = pX + 'px';
	}
	if(isResize){
		//try{
		    
			if((getWidth(resizeObj)<0 && resizeX) || getHeight(resizeObj)<0 && resizeY) return false;  //(newX-firstX)<0 = drag to left
			if(resizeX && !isResizeDataGrid){
			    if(is_ie){
			        resizeObj.style.width = newX - findLeftPos(resizeObj) - parseInt(getStyle(resizeObj,'marginLeft')) + parseInt(getStyle(resizeObj,'borderLeftWidth')) + parseInt(getStyle(resizeObj,'borderRightWidth')) + delta + 'px';
			    }else{
			        resizeObj.style.width = newX - findLeftPos(resizeObj) + delta - 2 + 'px';
			    }
			}
			if(resizeY){
			    if(is_ie){
			        resizeObj.style.height = newY - findTopPos(resizeObj) - parseInt(getStyle(resizeObj,'marginRight')) + parseInt(getStyle(resizeObj,'borderTopWidth')) + parseInt(getStyle(resizeObj,'borderBottomWidth')) + 'px';	
			    }else{
			        resizeObj.style.height = newY - findTopPos(resizeObj) - 2 + 'px';
			    }
			}			
								
		//}catch(e){}
	}
	return false;
}
function mU(e){
    if (!isDragging) return false;
    //----- use for grid 
    if(isResizeDataGrid){
        lastX = Math.min(lastX,(getWidth(currentGrid.gridbody)-3)) ;
        if(isMouseMove)lastX += currentGrid.scrLeft;
              
        if(is_ie){
            currentGrid.headarray[resizeCol][1] = lastX - findLeftPos(resizeObj) + parseInt(getStyle(resizeObj,'borderLeftWidth')) + parseInt(getStyle(resizeObj,'borderRightWidth')) + 8;	
            resizeObj.style.width = currentGrid.headarray[resizeCol][1] - 2 + 'px';            	               
        }else{
            currentGrid.headarray[resizeCol][1] = lastX - findLeftPos(resizeObj) + 8;	
            resizeObj.style.width = currentGrid.headarray[resizeCol][1] - 1 + 'px';	
        }
        for(j=0;j<currentGrid.numrow;j++){
	        $id(currentGrid.id+'row'+j+'col'+resizeCol).style.width = currentGrid.headarray[resizeCol][1] + uad + 'px';
        }
        $id(currentGrid.id+'rzrule').style.display='none';
        currentGrid.align();
        
	}
	//-------------->
	
	isDragging = false;
	dragY=false;
	dragX=false;
	isResize=false;	
	isResizeDataGrid = false;
	resizeX=false;
    resizeY=false;
    isMouseMove = false;
    currentGrid.isScrollGridY = false;
    currentGrid.isScrollGridX = false;
    currentGrid.clickOnSlideBar = false;
	return false;
}
//****************************************

//------------------Cookie------------------------
/*------ Register Cookie name --------------------
View detail in scriptDescription.js
------------------------------------------------*/
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 ReadCookie(cookieName){var theCookie=""+document.cookie;var ind=theCookie.indexOf(cookieName);if(ind==-1 || cookieName==""){return ""};var ind1=theCookie.indexOf(';',ind);if (ind1==-1){ind1=theCookie.length};return unescape(theCookie.substring(ind+cookieName.length+1,ind1))}
function setCookieArray2(cname,key,v,lifetime){  //set an available or create new key for cookie cname value v
    var keyIsOld = false; var myArr;var str = ReadCookie(cname); 
    if(str!=''){
        myArr = str.split('||');
        for(i=0;i<myArr.length-1;i++){if(myArr[i].split('|')[0]==key){myArr[i] = key + '|' + v; keyIsOld = true}}
        str='';
        for(i=0;i<myArr.length-1;i++){str += myArr[i] + '||'}
        if(!keyIsOld){str += key + '|' + v + '||';}        
    }else{str += key + '|' + v + '||';}    
    SetCookie(cname,str,lifetime); 
}
function getCookieArray2(cname,key){             //get value of key name in cookie cname
    var myval; var myArr; 
    var str = ReadCookie(cname);
    if(str!=''){
        myArr = str.split('||');
        for(i=0;i<myArr.length-1;i++){
            //myVal = myArr[i].split('|');
            if(myArr[i].split('|')[0]==key){myval = myArr[i].split('|')[1]}
        }       
    }else{myval=0}
    return myval;
}
function removeFromCookieArray2(cname,key){      //remove a pair of key and value from cookie name cname
    var myval;var myArr;var str = ReadCookie(cname);
    if(str!=''){
        myArr = str.split('||');
        str='';
        for(i=0;i<myArr.length-1;i++){
            if(myArr[i].split('|')[0]!=key){
                str += myArr[i];
                //if(i<(myArr.length-2)) 
                str +=  '||'
            }
        }
    }
    SetCookie(cname,str,30);
}

//--------------Form ---------------
function getCaretPositionIntexbox(control){
    var CaretPos = 0;
    if (document.selection){
        control.focus();
        var Sel = document.selection.createRange();
        Sel.moveStart ('character', -control.value.length);
        CaretPos = Sel.text.length;
    }else if(control.selectionStart || control.selectionStart == '0'){
        CaretPos = control.selectionStart;
    }
    return (CaretPos);
}
function getCaretPosition(control){ //use for textarea
    var CaretPos = 0;
    if (document.selection){
        control.focus();
        var Sel = document.selection.createRange();
        var Sel2 = Sel.duplicate();
        Sel2.moveToElementText(control);var CaretPos = 0;var CharactersAdded = 1;
        while (Sel2.inRange(Sel)){
            if (Sel2.htmlText.substr(0, 2) == "\r\n"){
                CaretPos += 2;CharactersAdded = 2;
            }else {
                CaretPos++;CharactersAdded = 1;
            }
            Sel2.moveStart('character');
        }
        CaretPos -= CharactersAdded;
    }else if(control.selectionStart || control.selectionStart == '0'){
        CaretPos = control.selectionStart;
    }
    return (CaretPos);
}
function setCaretPosition(ctrl, pos){
	if(ctrl.setSelectionRange){
		ctrl.focus();ctrl.setSelectionRange(pos,pos);
	}else if (ctrl.createTextRange) {
		var range = ctrl.createTextRange();
		range.collapse(true);
		range.moveEnd('character', pos);
		range.moveStart('character', pos);
		range.select();
	}
}
function clickOnTextField(obj){
    var caretpos = getCaretPositionIntexbox(obj);
    obj.value = obj.value.alltrim();
    setCaretPosition(obj, caretpos);
}
function keyDownOnMandatoryField(textObj,e,listpage,listwidth,listheight,rc){
    switch(e.keyCode){
        case 115:
           showList(textObj,listpage,listwidth,listheight,rc);
           // if(listpage!='')showList(textObj,listpage,listwidth,listheight,rc);                
            break;
    }
}
function keyDownOnMandatoryFieldDate(textObj,e){
    switch(e.keyCode){
        case 115:            
            showCalendarWin(textObj);                
            break;
    }
}
function keyDownOnTextField(textObj,e,listpage,listwidth,listheight,rc){
    switch(e.keyCode){
        case 115:
            if(listpage!='')showList(textObj,listpage,listwidth,listheight,rc);
            break;
    }
}
function keyDownOnTextFieldDate(textObj,e){
    switch(e.keyCode){
        case 115:
            showCalendarWin(textObj);
            break;
    }    
}
function keydownOnReadOnlyField(textObj,e){
    var evt = e || window.event;
        if (evt) {
            var keyCode = evt.charCode || evt.keyCode;
            if (keyCode === 8) {
                if (evt.preventDefault) {
                    evt.preventDefault();
                } else {
                    evt.returnValue = false;
                }
            }
        }
}
function disableSelection(target){
    try{
        if (typeof target.onselectstart!="undefined") //IE route
	        target.onselectstart=function(){return false}
        else if (typeof target.style.MozUserSelect!="undefined") //Firefox route
	        target.style.MozUserSelect="none"
        else //All other route (ie: Opera)
	        target.onmousedown=function(){return false}
    }catch(e){}
    
    //target.style.cursor = "default"
}
var _listButton;
function getListButton(obj){
    var myListButton;
    if(!$id('listButtonDiv')){
        _listButton = document.createElement('div');
        _listButton.setAttribute('id','listButtonDiv');
        _listButton.className = 'listButton';
        _winMainDiv.appendChild(_listButton);
        _listButton.innerHTML = '';
    }else{
        _listButton = $id('listButtonDiv');
    }
    _listButton.style.zIndex = 1300;
    _listButton.onmousedown = function(){_listButton.className = 'listButton_click';}
    _listButton.onmouseup = function(){_listButton.className = 'listButton';}
    _listButton.onmouseout = function(){_listButton.className = 'listButton';}
}
function focusMandatoryField(textObj,listpage,listwidth,listheight,rc,parentscroll){
    classNameBeforeFocus = textObj.className;
    textObj.className='input_focus';
    var deltax = is_ie ? 3:2;
    var deltay = is_ie ? -1:0;
    if(listpage!=''){
        getListButton();
        _listButton.onclick = function(){
            showList(textObj,listpage,listwidth,listheight,rc);
        }        
        _listButton.style.display = 'block';        
        if(typeof(parentscroll)!='undefined' && parentscroll){
            assignScrollPos($id(parentscroll));
            _listButton.style.top = parseInt(findTopPos(textObj)) + deltay - _parentScrollTop + 'px';
	        _listButton.style.left = parseInt(findLeftPos(textObj)) + parseInt(getStyle(textObj,'width')) + deltax - _parentScrollLeft + 'px';
        }else{
            _listButton.style.top = parseInt(findTopPos(textObj)) + deltay + 'px';
		    _listButton.style.left = parseInt(findLeftPos(textObj)) + parseInt(getStyle(textObj,'width')) + deltax + 'px';
        }
    }else{
        try{_listButton.style.display = 'none'}catch(e){};
    }
}
function focusMandatoryFieldDate(textObj,parentscroll){    
    classNameBeforeFocus = textObj.className;
    if(textObj.readOnly){
        textObj.className='input_readonly';
    }else{    
        textObj.className='input_focus';
    }
    var deltax = is_ie ? 3:2;
    var deltay = is_ie ? -1:0;
    getListButton();
    _listButton.onclick = function(){
        showCalendarWin(textObj);        
    }
    _listButton.style.display = 'block'; 
    if(typeof(parentscroll)!='undefined' && parentscroll){
        assignScrollPos($id(parentscroll));
        _listButton.style.top = parseInt(findTopPos(textObj)) + deltay - _parentScrollTop + 'px';
        _listButton.style.left = parseInt(findLeftPos(textObj)) + parseInt(getStyle(textObj,'width')) + deltax - _parentScrollLeft + 'px';
    }else{
        _listButton.style.top = parseInt(findTopPos(textObj)) + deltay + 'px';
	    _listButton.style.left = parseInt(findLeftPos(textObj)) + parseInt(getStyle(textObj,'width')) + deltax + 'px';
    }
}
function focusTextField(textObj,listpage,listwidth,listheight,rc,parentscroll){
    classNameBeforeFocus = textObj.className;
    //parentscroll to detect parent scroll or not to repos _listButton
    if(!textObj.readOnly)textObj.className='input_focus';    
    var deltax = is_ie ? 3:2;
    var deltay = is_ie ? -1:0;
    if(listpage!=''){
        getListButton();
        _listButton.onclick = function(){
            showList(textObj,listpage,listwidth,listheight,rc);
        }        
        _listButton.style.display = 'block';
        if(typeof(parentscroll)!='undefined' && parentscroll){
            assignScrollPos($id(parentscroll));
            _listButton.style.top = parseInt(findTopPos(textObj)) + deltay - _parentScrollTop + 'px';
	        _listButton.style.left = parseInt(findLeftPos(textObj)) + parseInt(getStyle(textObj,'width')) + deltax - _parentScrollLeft + 'px';
        }else{
            _listButton.style.top = parseInt(findTopPos(textObj)) + deltay + 'px';
		    _listButton.style.left = parseInt(findLeftPos(textObj)) + parseInt(getStyle(textObj,'width')) + deltax + 'px';
        }        
    }else{
        try{_listButton.style.display = 'none'}catch(e){};
    }
}
function focusTextFieldDate(textObj,parentscroll){
    classNameBeforeFocus = textObj.className;
    textObj.className='input_focus';
    var deltax = is_ie ? 3:2;
    var deltay = is_ie ? -1:0;
    getListButton();
    _listButton.onclick = function(){
        showCalendarWin(textObj);  
    }
    _listButton.style.display = 'block';
    if(typeof(parentscroll)!='undefined' && parentscroll){
        assignScrollPos($id(parentscroll));
        _listButton.style.top = parseInt(findTopPos(textObj)) + deltay - _parentScrollTop + 'px';
        _listButton.style.left = parseInt(findLeftPos(textObj)) + parseInt(getStyle(textObj,'width')) + deltax - _parentScrollLeft + 'px';
    }else{
        _listButton.style.top = parseInt(findTopPos(textObj)) + deltay + 'px';
	    _listButton.style.left = parseInt(findLeftPos(textObj)) + parseInt(getStyle(textObj,'width')) + deltax + 'px';
    }
}
function fucusReadOnlyField(textObj){
    classNameBeforeFocus = textObj.className;
    try{_listButton.style.display = 'none';}catch(e){}    
}
function hideListButton(){try{_listButton.style.display = 'none'}catch(ex){}}
function blurMandatoryField(myObj){
    if(myObj.readOnly){
        myObj.className = classNameBeforeFocus;
    }else{
        if(checkIsEmpty(myObj.value)){myObj.value='';myObj.className='input_mandatory';}else{myObj.className='input_text';}
    }
}
var classNameBeforeFocus;
function blurTextField(myObj){
    
    myObj.className = classNameBeforeFocus;
}
function decodeCompareChar(text){
    var newVal;
    switch(text){
        case '&gt;=':
            newVal = '>=';
            break;
        case '&lt;=':
            newVal = '<=';
            break;
        case '&gt;':
            newVal = '>';
            break;
        case '&lt;':
            newVal = '<';
            break;
        case '&lt;&gt;':
            newVal = '<>';   
            break;  
        case '&#91; &#93;':
            newVal = '';
            //newVal = '\[ \]';   
            break;  
        case '&#93; &#91;':
            newVal = '\] \[';   
            break;    
        case '=':
            newVal = '';
            //newVal = '=';
            break;
    }
    return newVal;
}
function showCompareList(textObj,listpage,listwidth,listheight,rc){
    //rc as require column filter
    var pagestr  = 'list.aspx?f='+listpage+'&t='+new Date().getTime();
    if(rc != '') pagestr += '&rc='+rc;
    
    var getVal;
    if(is_ie){
        getVal = window.showModalDialog(pagestr,'listwindow',"dialogWidth:"+listwidth+"px;dialogHeight:"+listheight+"px;center:yes;help:no;resizable:yes;scroll:no;status:yes;unadorned:yes");
    }else{
        getVal = window.showModalDialog(pagestr,'listwindow',"center:on;dialogheight: "+listheight+"px; dialogwidth:"+listwidth+"px;dialogleft:200;dialogtop:20;resizable:no;");
    }    
    if(typeof(getVal)=='undefined' || getVal==null){        
    }else{        
        getVal = getVal.replace(/\[ \]/gi,'&#91; &#93;');
        getVal = getVal.replace(/\] \[/gi,'&#93; &#91;');
        var newVal = decodeCompareChar(getVal);
        textObj.value=newVal;textObj.focus();        
    } 
}
function showList(textObj,listpage,listwidth,listheight,rc){
    hideListButton();
    //rc as require column filter
    var pagestr  = 'list.aspx?f='+listpage+'&t='+new Date().getTime();
    if(rc != '') pagestr += '&rc='+rc;
    var getVal;
    if(is_ie){
        getVal = window.showModalDialog(pagestr,'listwindow',"dialogWidth:"+listwidth+"px;dialogHeight:"+listheight+"px;center:yes;help:no;resizable:yes;scroll:no;status:yes;unadorned:yes");
    }else{
        getVal = window.showModalDialog(pagestr,'listwindow',"center:on;dialogheight: "+listheight+"px; dialogwidth:"+listwidth+"px;dialogleft:200;dialogtop:20;resizable:no;");
    }
    if(typeof(getVal)=='undefined' || getVal==null){        
    }else{
        if(!textObj.readOnly){
            textObj.value=getVal;textObj.focus()
        }
    }
    window.event.keyCode = 505;
    textObj.focus();
    
}
function showCalendarWin(textObj){
    hideListButton();    
    var getVal;
    if(is_ie){
        getVal = window.showModalDialog('calendar.aspx','calendarwindow',"modal:yes;dialogWidth:282px;dialogHeight:228px;center:yes;help:no;resizable:no;scroll:no;status:yes;unadorned:yes;");
    }else{
        getVal = window.showModalDialog('calendar.aspx','calendarwindow',"center:on;dialogheight: 228px; dialogwidth:282px;dialogleft:200;dialogtop:20;resizable:no;");
    }
    if(typeof(getVal)!='undefined'){textObj.value=getVal;textObj.focus()}
    window.event.keyCode = 505;
    textObj.focus();
}

