function ChkMaxLength(n, slength,Label) {
 if(n.value.length>slength)
	  {
			alert("Charactor in \"" + Label + "\" is not over "+slength+" charactor");
			temp=n.value.substring(0,slength);
			n.value=temp;
	  }
}

function ChkLength(n, slength) {
  if(n.value.length != slength)  
			return false;
	else
			return true;
}


function ChkNum(n, Msg) {
  var digits="0123456789.," ;
  var temp ;
  for (var i=0;i<n.value.length;i++)
  { 
	 temp=n.value.substring(i,i+1) ;
     if (digits.indexOf(temp)==-1)
	  {
        alert("Data in \"" + Msg + "\" is  number only.") ;
        n.value="0";		
		n.select()
      }
  }
}
function CheckInput(Input,Desc)
{
	check=1;
	ErrorMsg="";
	InputL=Input.length;
	for(ic=0;ic<InputL;ic++)
	{
		n=Input.indexOf("|",0);
		temp=Input.substring(0,n);
		Input=Input.substring(n+1,Input.length);
		n2=Desc.indexOf("|",0);
		temp2=Desc.substring(0,n2);
		Desc=Desc.substring(n2+1,Desc.length);
		if(frm.elements(temp).value=="")
		{
			ErrorMsg=ErrorMsg+"- "+temp2+"\n";
			check=0;
		}			
		if(Input.length==0){ic=InputL}
	}
	if(check==1)
	{
		ask=confirm("Submit data?");
		if(ask==1)
		{
			frm.method="post";
			frm.submit();
		}
	}else{
		alert("Please insert \n"+ErrorMsg);
	}
}
function CheckAll(Sbox)
{
	try {
		ChkLength=Sbox.length;
		ChkStatus=Sbox[0].checked;
		for(i=1;i<ChkLength;i++)	
		{
			Sbox[i].checked=ChkStatus;
		}
	} catch (e) {}

}
function DelCmd(n)
{
	temp=""
	Chk=0;
	if(n==0)
	{
		if(frm.DelChk.checked==true)
		{
			temp=Field+"="+frm.DelChk.value;
			Chk=Chk+1;
		}
	}else{
		for(i=1;i<=n;i++)
		{
			if(frm.DelChk[i].checked==true)
			{
				if(Chk==0)
				{ 
					temp=Field+"="+frm.DelChk[i].value;
					Chk=Chk+1;
				}else{
					temp=temp+" OR  "+Field+"="+frm.DelChk[i].value;
					Chk=Chk+1;
				}
			}
			}
		}
	if(temp!="")
	{
		ask=confirm("Delete?");
		if(ask==1)
		{
			temp=" Where "+temp;
			frm.WhereTxt.value=temp;
			frm.method="post";
			frm.submit();
		}
	}
}

function replaceAll(strItem,strFrom,strTo) {
	try {
		while (strItem.indexOf(strFrom) >= 0) {
  			strItem = strItem.replace(strFrom,strTo);
 		}
	} catch (e) {}
	return strItem
}

tempMoney="";
function formatMoney(mItem,money,format)
{
	if(tempMoney != money) {
		temp1= replaceAll(money,",","");
		temp2="";
		temp3="";
		if(temp1.indexOf(".") >=0) {
			temp3=temp1.substring(temp1.indexOf(".")+1,temp1.length);
			temp3="."+replaceAll(temp3,".","");
			temp1=temp1.substr(0,temp1.indexOf("."));
			temp1= replaceAll(temp1,",","");
		}
	
		if(temp1.length>3){
			for(i=0;i<=temp1.length;i++) {
				if(temp1.length>3){
					temp2 = temp1.substr(temp1.length-3,temp1.length);
					temp1 = temp1.substr(0,temp1.length-3);
					temp3=format+temp2+temp3;
				}
			}
		} 
		temp3 = temp1+temp3;
		tempMoney=temp3;
		mItem.value = temp3;
	}
}
function getFormatMoney(money,format) {
		temp1 = money+"";
		temp2="";
		temp3=".00";
		try {
			if(temp1.indexOf(".") != -1) {
				temp3=temp1.substring(temp1.indexOf(".")+1,temp1.length);
				temp3 = (temp3.length==1)?temp3 +="0":temp3;
				temp3="."+temp3; //replaceAll(temp3,".","");
				temp1=temp1.substr(0,temp1.indexOf("."));
			}
		}catch(e){}
	
		if(temp1.length>3){
			for(i=0;i<=temp1.length;i++) {
				if(temp1.length>3){
					temp2 = temp1.substr(temp1.length-3,temp1.length);
					temp1 = temp1.substr(0,temp1.length-3);
					temp3=  format+temp2+temp3;
				}
			}
		} 
		temp3 = temp1+temp3;

		return temp3;
}


	function getParamPattern(pattern,param) {
		temp = "",tempPattern="";
		param += "";
		try {
			if(pattern.length>=param.length){
				tempPattern = pattern.substring(0,pattern.length-param.length);
				temp = tempPattern + param;
				return temp;
			} else {
				return param;
			}
		} catch (e) {
			return e;
		}
	}

	function keyFocus(obj1,obj1length,obj2,obj2length,obj3) {
	  	if(obj1 != null) {
			if(obj1.value==""||obj1.value.length != obj1length ){
				obj1.focus();
				obj2.value = "";
				obj1.select();
			}
		}
		if(obj3 != null) {
			if(obj2length != 0) {
				if(obj2.value.length == obj2length ) {
					obj3.select();
					obj3.focus();
				}
			}
		}
		if(obj2length != 0) {
			if(obj2.value.length == obj2length ) {
				return true;
			}else {
				return false;
			}
		}else{
			return true;
		}
	  }

	function mailValidate(param) {
		var returnVal = true;
		var emailaddress=param.value;
		var emailFormat = /^\w(\.?[\w-])*@\w(\.?[\w-])*\.[a-zA-Z]{2,6}(\.[a-zA-Z]{2})?$/i;

		if (emailaddress.search(emailFormat) == -1) {
			alert("Please specify your email address in the following format: email@emailaddress.com");
			param.value = "";
			returnVal = false;
		}
		return returnVal;
	}
