// Created 17/09/2002 by KAK : EBO Company  :

function showlayer (id) {
  var id,obj;
  obj = document.getElementById(id);
  obj=obj.style;
  obj.visibility="visible";
  
}
function hidelayer (id) {
  var id,obj;
  obj = document.getElementById(id);
  obj=obj.style;
  obj.visibility="hidden";
}
function hl_on_menu (id) {
   var id,obj;
  obj = document.getElementById(id);
  obj=obj.style;
  obj.backgroundColor = "#FF0000";
  obj.color = "#FFFFFF";
  obj.cursor = "hand";
}

function hl_off_menu (id) {
   var id,obj;
   obj = document.getElementById(id);
   obj=obj.style;
   obj.backgroundColor = "#FFFFFF";
   obj.color = "#000000";
}
function gotourl(url) {document.location = url;}

 function new_win_def_prot(mypage, myname, w, h, scroll,fullscreen) { //Show center screen,focus page in use
				var winl = (screen.width - w) / 2;
				var wint = (screen.height - h) / 2;
				winprops = 'height='+h+',width='+w+',top='+wint+',left='+winl+',scrollbars='+scroll+',fullscreen='+fullscreen+',resizable,toolbar=no,location=no,status=yes,menubar=no'
				win = window.open(mypage, myname, winprops)
				if (parseInt(navigator.appVersion) >= 4) { win.window.focus(); }
}
function chkEmail (str) 
	{
	    var num_as = str.lastIndexOf("@");
		var num_poin = str.lastIndexOf(".");
	    if (num_as == -1 || num_poin ==-1) 
		{
		     return false; 
	    }else
		{
		   return true;
		}
   }
function isBlank(val) {
if (val=="") {
		return true;		
	}
	return false;
}

 function isNum (charCode) 
   {
       if (charCode >= 48 && charCode <= 57 )
	       return true;
      else
	     return false;
   }
    function isZero (charCode) 
   {
       if (charCode == 48)
	       return true;
      else
	     return false;
   }
   function isAtoZ (charCode) 
   {
       if (charCode >= 65 && charCode <= 90 )
	       return true;
      else
	     return false;
   }
   function isaToz (charCode)
   {
      if (charCode >= 97 && charCode <= 122 )
	       return true;
      else
	     return false;
   }
     function  chkFormatEng (str) { //  A-Z,a-z
        strlen = str.length;
       for (i=0;i<strlen;i++)
      {
            var charCode = str.charCodeAt(i);
			if (!isAtoZ(charCode) && !isaToz(charCode))
			   return false;
	  }//for
        return true;
	}
      function  chkFormatThai (str) { // Not A-Z,a-z
        strlen = str.length;
       for (i=0;i<strlen;i++)
      {
            var charCode = str.charCodeAt(i);
			if (isAtoZ(charCode) || isaToz(charCode))
			   return false;
	  }//for
        return true;
	}
	function isThaiAlphabet (charCode) {
	if (charCode >=3585 && charCode <=3630) // ¡-Î
	     return true;
    else
		return false;
	
}

function isSRWNY (charCode) { //  Sa-Ra , Wan-Na-Yuk ** Don't work 100% 11/06/04
	if (charCode >=3631 && charCode <=3670) 
	     return true;
    else
		return false;
	
}
 function chkFormatNaA (str) {//0-9,a-z,A-Z
  strlen = str.length;
  for (i=0;i<strlen;i++)
  {
      var charCode = str.charCodeAt(i);
	  if (!isNum(charCode) && !isAtoZ(charCode) && !isaToz(charCode)) {
		  return false;
	  }
   }
   return true;
}

 function chkFormatNam (str) {//0-9
  strlen = str.length;
  for (i=0;i<strlen;i++)
  {
      var charCode = str.charCodeAt(i);
	  if (!isNum(charCode)) {
		  return false;
	  }
   }
   return true;
}

 function chkFormatFNam (str) {//0
  strlen = str.length;
  for (i=0;i<strlen;i++)
  {
      var charCode = str.charCodeAt(i);
	  if(i == 0) {
	    if (!isZero(charCode)) {
		  return false;
	    }
	  }
   }
   return true;
}

function chkLen (str,numLen)
{
        var  strLen = str.length;
      	if (strLen < numLen) {
		    return false;
		}
     return true;
}

function new_win_def_point(mypage, myname, l, t, w, h, scroll,fullscreen) { //Show center screen,focus page in use
				winprops = 'height='+h+',width='+w+',top='+t+',left='+l+',scrollbars='+scroll+',fullscreen='+fullscreen+',resizable,toolbar=no,location=no,status=yes,menubar=no'
				win = window.open(mypage, myname, winprops)
				if (parseInt(navigator.appVersion) >= 4) { win.window.focus(); }
}
function hl_on_menu (id) {
   var id,obj;
  obj = document.getElementById(id);
  obj=obj.style;
  obj.backgroundColor = "#FFEEDD";
  obj.color = "#FF9933";
  obj.cursor = "hand";
}

function hl_off_menu (id) {
   var id,obj;
   obj = document.getElementById(id);
   obj=obj.style;
   obj.backgroundColor = "#FFDCB9";
   obj.color = "#000000";
}
function auto_close () {
	 setTimeout("closeWin()",3000);
 }
 function closeWin() {
                self.close();
}
function resizeWin(w,h) {
if (window.screen) {
     window.resizeTo(w, h);
   }
}
function maximizeWin() {
	if (window.screen) {
		var aw = screen.availWidth;
		var ah = screen.availHeight;
		window.moveTo(0, 0);
		window.resizeTo(aw, ah);
   }
}
function alertSave (stus) {
   if (stus == "Y")
	    alert ('Process data complete......');
}

/* Checkbox*/
      function ToggleAll(e,f,elementName)
    {
	if (e.checked) {
	    CheckAll(f,elementName);
	}
	else {
	    ClearAll(f,elementName);
	}
    }

    function Check(e)
    {
	e.checked = true;
    }

    function Clear(e)
    {
	e.checked = false;
    }

    function CheckAll(ml,elementName)
    {
	var len = ml.elements.length;
	for (var i = 0; i < len; i++) {
	    var e = ml.elements[i];
	    if (e.name == elementName) {
		Check(e);
	    }
	}
	ml.toggleAll.checked = true;
    }

    function ClearAll(ml,elementName)
    {
	var len = ml.elements.length;
	for (var i = 0; i < len; i++) {
	    var e = ml.elements[i];
	    if (e.name == elementName) {
		Clear(e);
	    }
	}
	ml.toggleAll.checked = false;
    }
	/* End checkbox*/
	 function hightLightOn (obj) {
       cRef = obj.style.backgroundColor;
           if (cRef != "#ffcc99")
           {
                obj.style.backgroundColor = "#FFFFCC";
           }
	 }

	  function hightLightOff (obj) {
       cRef = obj.style.backgroundColor;
           if (cRef != "#ffcc99")
           {
                obj.style.backgroundColor = "#F5F5E2";
           }
	 }

	 function hightLightMark (obj) {
		 var  cRef = obj.style.backgroundColor;
		 var  c1 = "#ffcc99";
         var c2 = "#f5f5e2";

			if (cRef == c1)
			    obj.style.backgroundColor = c2;
			 else
			    obj.style.backgroundColor = c1;
	 }
function MM_swapImgRestore() { //v3.0
  var i,x,a=document.MM_sr; for(i=0;a&&i<a.length&&(x=a[i])&&x.oSrc;i++) x.src=x.oSrc;
}
function MM_findObj(n, d) { //v4.0
  var p,i,x;  if(!d) d=document; if((p=n.indexOf("?"))>0&&parent.frames.length) {
    d=parent.frames[n.substring(p+1)].document; n=n.substring(0,p);}
  if(!(x=d[n])&&d.all) x=d.all[n]; for (i=0;!x&&i<d.forms.length;i++) x=d.forms[i][n];
  for(i=0;!x&&d.layers&&i<d.layers.length;i++) x=MM_findObj(n,d.layers[i].document);
  if(!x && document.getElementById) x=document.getElementById(n); return x;
}
function MM_swapImage() { //v3.0
  var i,j=0,x,a=MM_swapImage.arguments; document.MM_sr=new Array; for(i=0;i<(a.length-2);i+=3)
   if ((x=MM_findObj(a[i]))!=null){document.MM_sr[j++]=x; if(!x.oSrc) x.oSrc=x.src; x.src=a[i+2];}
}
	 function convToCurrency (num,digit_decimal) {
		  
		  if (isBlank(digit_decimal))
		       digit_decimal =2; // Default 2 digit

           var str = roundFloat(num, digit_decimal)+''; // »Ñ´àÈÉ+Convert number to string
		   var t =0;
		   var decimal=textFormat= '';
		   var num_poin = str.lastIndexOf(".");// Find decimal
           var str_len    = str.length;
		   if (num_poin != -1){  // found decimal
		        decimal = str.substring(num_poin,str_len);
				str_len -= decimal.length; 
			}

		  if (str_len != 0){
			for (var k =str_len-1; k>=0 ; k--) {		
			t++;
			if (t % 3 == 0)
			    textFormat = "," + str.substr(k,1) + textFormat; 
			else 
               textFormat =  str.substr(k,1) + textFormat;
		 }//for
	 } 
   
  if (isBlank(decimal))
	   decimal = ".00";

     if (textFormat.substr(0,1) == ",")
         return textFormat.substr(1,textFormat.length-1)+decimal;
    else  
        return textFormat+decimal;
 }

 function roundFloat(fltValue, intDecimal) {
               return Math.round(fltValue * Math.pow(10, intDecimal)) / Math.pow(10, intDecimal)
 }

 function antiChar (str,tragetChar) {
  var strLen = str.length;
  var newStr="";
  for (i=0;i<strLen;i++)
  {
      var thisChar = str.charAt(i);
	  if (thisChar != tragetChar) {
		  newStr += thisChar
	  }
   }
   return newStr;
}
function openFrameless(windowW,windowH,urlPop, title){

//Set center  screen
//   var windowX = (screen.width - windowW) / 2;
//   var windowY = (screen.height - windowH) / 2;
var windowY = windowX = 0;
// var debug = ",status=yes";// Debug error

   windowH=windowH+37;
   windowW=windowW+10;
   
   
   s = "width="+windowW+",height="+windowH+",scrollbars=no";
   var beIE = document.all?true:false
   
// set this to true if the popup should close
// upon leaving the launching page; else, false

var autoclose = true
   
  if (beIE){
    //NFW = window.open("","popFrameless","fullscreen,"+s)     
	NFW = window.open("","popFrameless",s)
    NFW.blur()
    window.focus()       
    NFW.resizeTo(windowW,windowH)
    NFW.moveTo(windowX,windowY)
    var frameString=""+
"<html>"+
"<head>"+
"<title>"+title+"</title>"+
"</head>"+
"<frameset rows='*,0' framespacing=0 border=0 frameborder=0>"+
"<frame name='top' src='"+urlPop+"' scrolling=auto>"+
"<frame name='bottom' src='about:blank' scrolling='no'>"+
"</frameset>"+
"</html>"
    NFW.document.open();
    NFW.document.write(frameString)
    NFW.document.close()
  } else {
    NFW=window.open(urlPop,"popFrameless","scrollbars,"+s)
    NFW.blur()
    window.focus() 
    NFW.resizeTo(windowW,windowH)
    NFW.moveTo(windowX,windowY)
  }   
  NFW.focus()   
  if (autoclose){
    window.onunload = function(){NFW.close()}
  }
}
