var NS4 = (document.layers) ? 1 : 0;
var IE = (document.all) ? 1 : 0;


//------------------------------------------function Ajax---------------------------------------------

function clsAjax(){
	this.ajax;
	this.url;
	this.method;
	this.param;
	this.responseText;
	this.function_name;
	
	//Create Ajax Object
	this.create = function(){
		this.param = new Array();
		if(window.ActiveXObject){
			this.ajax = new ActiveXObject("Microsoft.XMLHTTP");
		}else{
			this.ajax = new XMLHttpRequest();
		}
	}
	
	this.addParam = function(name, value){
		this.param.push(name+"="+encodeURI(value));
	}
	
	this.createParameters = function(){
		var q = "";
		if(this.param.length > 0){
			for(i=0; i<this.param.length; i++){
				q += this.param[i]+"&";
			}
			q = q.substr(0, q.length-1);
		}
		return q;
	}
	
	//Send data
	this.send = function(){
		var tempurl = this.url;
		var querystring = this.createParameters();
		if(this.method.toLowerCase() == "get"){
			tempurl += "?"+querystring;
		}
		this.ajax.onreadystatechange = this.stateChange; 
		this.ajax.open(this.method, tempurl, true);
		if(this.method.toLowerCase()=="post"){
			this.ajax.setRequestHeader('Content-Type', 'application/x-www-form-urlencoded; charset=UTF-8');
			this.ajax.send(querystring);
		}else{
			this.ajax.send(null);
		}
	}
	
	//Check state change and retrieve data.
	var self = this;
	this.stateChange = function(){
		if(self.ajax!=null){
			if(self.ajax.readyState == 4){ 
				if(self.ajax.status == 200){
					self.responseText = self.ajax.responseText;
					if(self.function_name != ""){ 
						eval(self.function_name);
					}
				}
			}
		}else{
			alert("Ajax object not set.");
		}
	}
}

//---------------------------------------------------------------------------------------

//------------------------------------fixPNG-------------------------------------------
var arVersion = navigator.appVersion.split("MSIE")
var version = parseFloat(arVersion[1])

function fixPNG(myImage) 
{
    if ((version >= 5.5) && (version < 7) && (document.body.filters)) 
    {
       var imgID = (myImage.id) ? "id='" + myImage.id + "' " : ""
	   var imgClass = (myImage.className) ? "class='" + myImage.className + "' " : ""
	   var imgTitle = (myImage.title) ? 
		             "title='" + myImage.title  + "' " : "title='" + myImage.alt + "' "
	   var imgStyle = "display:inline-block;" + myImage.style.cssText
	   var strNewHTML = "<span " + imgID + imgClass + imgTitle
                  + " style=\"" + "width:" + myImage.width 
                  + "px; height:" + myImage.height 
                  + "px;" + imgStyle + ";"
                  + "filter:progid:DXImageTransform.Microsoft.AlphaImageLoader"
                  + "(src=\'" + myImage.src + "\', sizingMethod='scale');\"></span>"
	   myImage.outerHTML = strNewHTML	  
    }
}

//---------------------------------------------------------------------------------------
function trim(text){
	return text.replace(/^\s+|\s+$/, '')	
}

function popup(name,url,scrollbars,width,height){
	var windowprops = "toolbar=0,location=0,directories=0,status=1,menubar=0,scrollbars="+scrollbars+",resizable=0,width="+width+",height="+height;
	var winName=window.open(url,name, windowprops); // opens remote control
	winName.focus();
}

function CreatePopup(name,link,width,height,scrollbars){
	var windowprops = "toolbar=0,location=0,directories=0,status=0,menubar=0,resizable=0,scrollbars="+scrollbars+",width="+width+",height="+height;
	var winName=window.open(link,name, windowprops); // opens remote control
	winName.focus();
}

function hasItem(target){
	var reValue=false;
	if (IE) { if(document.all[target]) reValue=true;}
	else if (NS4) { if(document.layers[target]) reValue=true;}
	else { if(document.getElementById(target)) reValue=true;} 
	return reValue;
}

function getItem(target){
	var reValue="";
	if (IE) { reValue = document.all[target];}
	else if (NS4) { reValue = document.layers[target];}
	else { reValue = document.getElementById(target);}   
	return reValue;
}

function setHide(target,hide){
	if (IE) { 
		document.all[target].style.visibility=hide ? "hidden":"visible";
	}else if (NS4) { 
		document.layers[target].style.visibility=hide ?"hide":"show";
	}else { 
		document.getElementById(target).style.visibility= hide?"hidden":"visible";
	}
}

function setPosition(target,change) {
	if (IE) {	document.all[target].style.position = change;}
	else if (NS4) { 	document.layers[target].style.position = change;}
	else{document.getElementById(target).style.position=change; }
}
//-------------------------------------Show Loading---------------------------------------

function showDialog(vis){
if(vis == "block"){ 
document.getElementById("xx").style.position ="static";
document.getElementById("xx").style.visibility ="visible";
}else{
document.getElementById("xx").style.position ="absolute";
document.getElementById("xx").style.visibility ="hidden";
}
}
var w3c=(document.getElementById)?true:false;
var ie=(document.all)?true:false;
var N=-1;
var bars=new Array();

function createBar(w,h,bgc,brdW,brdC,blkC,speed,blocks){
if(ie||w3c){
var t='<div style="position:relative; overflow:hidden; width:'+w+'px; height:'+h+'px; background-color:'+bgc+'; border-color:'+brdC+'; border-width:'+brdW+'px; border-style:solid; font-size:1px;">';
t+='<span id="blocks'+(++N)+'" style="left:-'+(h*2+1)+'px; position:absolute; font-size:1px">';
for(i=0;i<blocks;i++){
t+='<span style="background-color:'+blkC+'; left:-'+((h*i)+i)+'px; font-size:1px; position:absolute; width:'+h+'px; height:'+h+'px; '
t+=(ie)?'filter:alpha(opacity='+(100-i*(100/blocks))+')':'-Moz-opacity:'+((100-i*(100/blocks))/100);
t+='"></span>';
}
t+='</span></div>';
document.write(t);
var bA=(ie)?document.all['blocks'+N]:document.getElementById('blocks'+N);
bA.blocks=blocks;
bA.w=w;
bA.h=h;
bars[bars.length]=bA;
setInterval('startBar('+N+')',speed);
}}

function startBar(bn){
var t=bars[bn];
t.style.left=((parseInt(t.style.left)+t.h+1-(t.blocks*t.h+t.blocks)>t.w)? -(t.h*2+1) : parseInt(t.style.left)+t.h+1)+'px';
}
//-------------------------------------Show Loading---------------------------------------

var sel_on = '#FFEFA3'; //select highlight color
var sel_off = '#FFFFFF'; // select default color

function setShowOn(target)
{
	document.getElementById(target).style.background = sel_on;
}

function setShowOff(target)
{
	document.getElementById(target).style.background = sel_off;
}
function waitPreloadPage() { //DOM
if (document.getElementById){
document.getElementById('prepage').style.visibility='hidden';
}else{
if (document.layers){ //NS4
document.prepage.visibility = 'hidden';
}
else { //IE4
document.all.prepage.style.visibility = 'hidden';
}
}
}

var obj = new clsAjax();
	function chk_dup(i,t_table,f_code){
	//alert(document.getElementById('id_lab_'+i).value);
		setShowOff("id_lab_"+i);
		document.getElementById("p_chk_dup").value="Y";
	if(document.getElementById('id_lab_'+i).value!=document.getElementById('id_lab_current_'+i).value){
				obj.create();
				obj.url = "/tisi/utils/chk_duplicate.jsp";
				obj.method = "POST"
				obj.addParam("id_lab", document.getElementById('id_lab_'+i).value);
				obj.addParam("t_table",t_table);
				obj.addParam("f_code",f_code);
				obj.function_name = "chk_show("+i+")"; 
				obj.send();
	}
}
function chk_show(i){
		//alert(trim(obj.responseText));
		setShowOff("id_lab_"+i);
		document.getElementById("p_chk_dup").value="Y";
		if(trim(obj.responseText)==1){
			alert("ÃËÑÊ«éÓ");
			setShowOn("id_lab_"+i);
		document.getElementById("id_lab_"+i).focus();
		document.getElementById("p_chk_dup").value="N";
		}
}

//--------------------------------------------------------------------------------------------------------------------------------------






//--------------------------------------------LAYER ---------------------------------------------------------------------------------
var isIE=document.all;
var isNN=!document.all&&document.getElementById;
var isN4=document.layers;
var isHot=false;



function ddInit(e){
//    alert("value  =  "+e);
//    alert("1 =  "+document.all.x_pop);
//    alert("2 =  "+document.all.e);
//	alert("3 =  "+document.all[e]);
  topDog=isIE ? "BODY" : "HTML";
  whichDog=isIE ? document.all[e] : document.getElementById(e);  
  hotDog=isIE ? event.srcElement : e.target;  
  while (hotDog.id!="titleBar"&&hotDog.tagName!=topDog){
    hotDog=isIE ? hotDog.parentElement : hotDog.parentNode;
  }  
  if (hotDog.id=="titleBar"){
    offsetx=isIE ? event.clientX : e.clientX;
    offsety=isIE ? event.clientY : e.clientY;
    nowX=parseInt(whichDog.style.left);
    nowY=parseInt(whichDog.style.top);
    ddEnabled=true;
    document.onmousemove=dd;
  }
}
function dd(e){
  if (!ddEnabled) return;
  whichDog.style.left=isIE ? nowX+event.clientX-offsetx : nowX+e.clientX-offsetx; 
  whichDog.style.top=isIE ? nowY+event.clientY-offsety : nowY+e.clientY-offsety;
  return false;  
}
function ddN4(whatDog){
  if (!isN4) return;
  N4=eval(whatDog);
  N4.captureEvents(Event.MOUSEDOWN|Event.MOUSEUP);
  N4.onmousedown=function(e){
    N4.captureEvents(Event.MOUSEMOVE);
    N4x=e.x;
    N4y=e.y;
  }
  N4.onmousemove=function(e){
    if (isHot){
      N4.moveBy(e.x-N4x,e.y-N4y);
      return false;
    }
  }
  N4.onmouseup=function(){
    N4.releaseEvents(Event.MOUSEMOVE);
  }
}
function hideMe(x_name){
  if (isIE||isNN) document.getElementById(x_name).style.visibility="hidden";
  else if (isN4) document.x_name.visibility="hide";
}
function showMe(x_name){
  if (isIE||isNN) document.getElementById(x_name).style.visibility="visible";
  else if (isN4) document.x_name.visibility="show";
}
//document.onmousedown=ddInit;
//document.onmouseup=Function("ddEnabled=false");


//---------------------------------------------------------------------------------------------------------------------------------------
//==========================================
// Check All boxes
//==========================================
function CheckAll(fmobj,chk) {
  for (var i=0;i<fmobj.elements.length;i++) {
    var e = fmobj.elements[i];
    if ( (e.type=='checkbox') ) {
      e.checked = chk;
    }
  }
}
//==========================================
// get Element by id
//==========================================
var NS4 = (document.layers) ? 1 : 0;
var IE = (document.all) ? 1 : 0;
var DOM = 0; 
if (parseInt(navigator.appVersion) >=5) {DOM=1};

function Element(target){
	var element=null;
	if (DOM) {
		element = document.getElementById(target);
	}
	else if (IE) {
		element = document.all[target];
	}
	else if (NS4) {
		element = document.layers[target];
	} 
	return element;
}

function trim(text){
	return text.replace(/^\s+|\s+$/, '')	
}
function submitForm(target){
	Element(target).submit();
}

function setInputData(target,text){
	Element(target).value=text;
}

function getInputData(target){
	return Element(target).value;
}

function setHtml(target,text){
	Element(target).innerHTML=text;
}

function getHtml(target){
	return Element(target).innerHTML;
}

function setFocus(target){
	return Element(target).focus();
}
function Hello(){
alert("WOooo HO oooo !!!!");
}
