

function kdevent(evt,action) {
	evt = (evt) ? evt : event;
	var charCode = (evt.charCode) ? evt.charCode : ((evt.which) ? evt.which : evt.keyCode);
	if (charCode == 13 || charCode == 3) {
		eval(action);
		return false;
	} else {
		return true;
	}
}


            	var aDay	= new Array("Sunday","Monday","Tuesday","Wednesday","Thursday","Friday","Saturday");
	var aMonth	= new Array("January","February","March","April","May","June","July","August","September","October","November","December")


	function DateFormat(xdate,x)
		{

		x = x.toLowerCase();
		return (((x == "d")  ? xdate.getDate() : ((x == "dd") ? ((xdate.getDate() <= 9) ? "0"+xdate.getDate() : xdate.getDate()) : ((x == "ddd") ? aDay[xdate.getDay()].substring(0,3)+". " : ((x == "dddd") ? aDay[xdate.getDay()]+", " : ((x == "m")  ? xdate.getMonth()+1 : ((x == "mm") ? (((xdate.getMonth()+1) <= 9) ? "0"+(xdate.getMonth()+1) : xdate.getMonth()+1) : ((x == "mmm") ? aMonth[xdate.getMonth()] : ((x == "mmmm") ? aMonth[xdate.getMonth()] : ((x == "y" || x == "yy" || x == "yyy") ? xdate.getFullYear().toString().substring(2,4) : ((x == "yyyy") ? xdate.getFullYear().toString() : "")))))))))))
		}


	function Showdate(_date, _var1, _var2, _var3, _var4, _del)
		{
		var today	= (_date == null) ? new Date() : new Date(_date);
		_del =  ((_del == null) ? " " : _del);
		return ( DateFormat(today, _var1) + DateFormat(today, _var2) + ((_var2 != "")? _del : "") + DateFormat(today, _var3) + ((_var3 != "")? _del : "") + DateFormat(today, _var4))
		}

function newWindow(file,window) {

msgWindow=open(file,window,'resizable=no,width=450,height=200');
if(msgWindow.opener == null) msgWindow.opener = self;
}	

function newjobWindow(file,window) {

msgWindow=open(file,window,'scrollbars=yes,width=440,height=450');
if(msgWindow.opener == null) msgWindow.opener = self;
}	

function newWindow1(file,window) {
msgWindow=open(file,window,'resizable=no,width=600,height=500,resizable=1,scrollbars=yes');
if(msgWindow.opener == null) msgWindow.opener = self;
}	

function newWindow2(file,window,wh) {

	wh = wh+ ',resizable=no,scrollbars=no';
msgWindow=open(file,window,wh);
if(msgWindow.opener == null) msgWindow.opener = self;
}	

function page_Data(targ,selObj,selpage,restore){ //v3.0
	eval("window.location.href='"+selpage+selObj.options[selObj.selectedIndex].value+"'");
	if (restore) selObj.selectedIndex=0;
}	  


function MM_goToURL() { //v3.0
  var i, args=MM_goToURL.arguments; document.MM_returnValue = false;
  for (i=0; i<(args.length-1); i+=2) eval(args[i]+".location='"+args[i+1]+"'");
}

function MM_jumpMenu(targ,selObj,restore){ //v3.0
  eval(targ+".location='"+selObj.options[selObj.selectedIndex].value+"'");
  if (restore) selObj.selectedIndex=0;
}

function isNumber(s)
{
    var patrn=/^[+]{0,1}(\d){1,3}[ ]?([-]?((\d)|[ ]){1,12})+$/;
    if (!patrn.exec(s)) return false
    return true
}

function isTel(s)
{
    var patrn=/^[+]{0,1}(\d){1,3}[ ]?([-]?((\d)|[ ]){1,12})+$/;
    if (!patrn.exec(s)) return false
    return true
}

function IsMail(Input)
{
	return check_email(Input);
}

function check_email(e) 
{
	
	//alert("email="+e);
	
	ok = "1234567890qwertyuiop[]asdfghjklzxcvbnm.@-_QWERTYUIOPASDFGHJKLZXCVBNM";
	
	for(i=0; i < e.length ;i++){
		if(ok.indexOf(e.charAt(i))<0){ 
			return false;
		}	
	} 
	re = /(@.*@)|(\.\.)|(^\.)|(^@)|(@$)|(\.$)|(@\.)/;
	re_two = /^.+\@(\[?)[a-zA-Z0-9\-\.]+\.([a-zA-Z]{2,4}|[0-9]{1,3})(\]?)$/;
	if (!e.match(re) && e.match(re_two)) {
		return  true;		
	}else{
		return false;
	}

}

//=====check ID return true or false
function IDcheck(idno){
  if (idno.length == 10) {
	var compstr,pos,checksum;
	checksum = 0;
	cmpstr="ABCDEFGHJKLMNPQRSTUVXYWZIO";
	pos=cmpstr.indexOf((idno.charAt(0)).toUpperCase());
	if(pos == -1 || isNaN(idno.substring(1,9)))
	   return false;
	else   {
		pos = pos + 10;
		checksum = Math.floor(pos/10) + (pos - (Math.floor(pos/10)*10) )*9;
		var checksum = checksum+8*parseInt(idno.charAt(1))+7*parseInt(idno.charAt(2))+6*parseInt(idno.charAt(3))+5*parseInt(idno.charAt(4))+4*parseInt(idno.charAt(5))+3*parseInt(idno.charAt(6))+2*parseInt(idno.charAt(7))+1*parseInt(idno.charAt(8))+1*parseInt(idno.charAt(9));
		var check1 = parseInt(checksum/10);
		var check2 = checksum/10;
		var check3 = (check2-check1)*10;
		if (checksum == check1*10) { return true; }
		else {
		  if (parseInt(idno.charAt(9)) == (10-check3)) { return true; }
		  else { return false; }
		}
	}
  }
  else
	return false;
}


	function ToUpCase(obj)
	{
		obj.value=obj.value.toUpperCase();
	}


//===== check Tax No. ===
// var no = "12345678";
// var msg = chknum(no)
// if ( msg.length ) != 0 then alert(msg)  
//
function chknum(NO){
	var cx = new Array;
	cx[0] = 1;
	cx[1] = 2;
	cx[2] = 1;
	cx[3] = 2;
	cx[4] = 1;
	cx[5] = 2;
	cx[6] = 4;
	cx[7] = 1;
  var SUM = 0;
  if (NO.length != 8) {
	alert("Wrong Tax No., should have 8 numbers"); 
	return false;	
  }
  var cnum = NO.split("");
  for (i=0; i<=7; i++) {
	if (NO.charCodeAt() < 48 || NO.charCodeAt() > 57) {
		alert("Wrong Tax No., should have 8 assembled numbers from 0 to 9"); 
		return false;		  
	}
	SUM += cc(cnum[i] * cx[i]);
  }
  if (SUM % 10 == 0) return true; 
  else if (cnum[6] == 7 && (SUM + 1) % 10 == 0) return true; 
  else{
  alert("Tax No. "+NO+" Error"); 
		return false;		  
	}
}

function cc(n){
  if (n > 9) {
	var s = n + "";
	n1 = s.substring(0,1) * 1;
	n2 = s.substring(1,2) * 1;
	n = n1 + n2;
  }
  return n;
}
//===

function chktax(s){

	var cx = new Array;
	cx[0] = 1;
	cx[1] = 2;
	cx[2] = 1;
	cx[3] = 2;
	cx[4] = 1;
	cx[5] = 2;
	cx[6] = 4;
	cx[7] = 1;
  var SUM = 0;
  if (s.length != 8) {
  	alert("Wrong Tax No., should have 8 numbers"); 
	return false;
  }

  var cnum = s.split("");
  for (i=0; i<=7; i++) {
	if (s.charCodeAt() < 48 || s.charCodeAt() > 57) {
			alert("Wrong Tax No., should have 8 assembled numbers from 0 to 9"); 
	  return false;
	}
	SUM += cc(cnum[i] * cx[i]);
  }

  if (SUM % 10 == 0) return true; 
  else if (cnum[6] == 7 && (SUM + 1) % 10 == 0) return true;
  else {
  	alert("Tax No. "+NO+" Error"); 
  	return false;}
}


function DateFormat1(xdate,x){
	x = x.toLowerCase();
	return (((x == "d")  ? xdate.getDate() : ((x == "dd") ? ((xdate.getDate() <= 9) ? "0"+xdate.getDate() : xdate.getDate()) : ((x == "ddd") ? aDay[xdate.getDay()].substring(0,3)+". " : ((x == "dddd") ? aDay[xdate.getDay()]+", " : ((x == "m")  ? xdate.getMonth()+1 : ((x == "mm") ? (((xdate.getMonth()+1) <= 9) ? "0"+(xdate.getMonth()+1) : xdate.getMonth()+1) : ((x == "mmm") ? aMonth[xdate.getMonth()].substring(0,3) : ((x == "mmmm") ? aMonth[xdate.getMonth()] : ((x == "y" || x == "yy" || x == "yyy") ? xdate.getFullYear().toString().substring(2,4) : ((x == "yyyy") ? xdate.getFullYear().toString() : "")))))))))))
}

function formatIndate(_date, _var1, _var2, _var3,_del){
	if (_date.length == 0){ 
		return "";
	}else{
		var today	= (_date == null) ? new Date() : new Date(_date);
		_del =  ((_del == null) ? " " : _del);
		return ( DateFormat1(today, _var1) + ((_var2 != "")? _del : "")+ DateFormat1(today, _var2) + ((_var2 != "")? _del : "") + DateFormat1(today, _var3) )
	}
}