function Educationpopup(TypeProcess,id,path){
		//styles = 'dialogWidth=488px;dialogHeight=500px;dialogTop=20;dialogLeft=20px;status=no;help=no;';
	
		src = path+"SdbsManageEducationTypePopup.asp?id="+id+"&TypeProcess="+TypeProcess;
		//window.showModalDialog(src,window,styles); 
		winstyle = "resizable=yes,height=556,width=566,status=yes,toolbar=no,menubar=no,location=no,scrollbars=yes,top=20,left=20";
		window.open(src,'detail',winstyle);

	}
		
	

	function DetailModal(Qid,path){
		//styles = 'dialogWidth=488px;dialogHeight=500px;dialogTop=20;dialogLeft=20px;status=no;help=no;';
	
		src = path+"product_detail.asp?Qid="+Qid;
		//window.showModalDialog(src,window,styles); 
		winstyle = "height=556,width=566,status=yes,toolbar=no,menubar=no,location=no,scrollbars=yes,top=20,left=20";
		window.open(src,'detail',winstyle);

	}
	
	
			function previewmail(){
		f = document.form;
		Str_length = f.ComposeId.length
		for(i=0;i < Str_length ;i++)
		{
			if(eval("f.ComposeId["+i+"].checked"))
			{
			id = eval("f.ComposeId["+i+"].value")
			}
		}
		src = "previewmail.asp?Id="+id;
		winstyle = "resizable=yes,height=550,width=650,status=yes,toolbar=no,menubar=no,location=no,scrollbars=yes,top=20,left=20";
		window.open(src,'previewmail',winstyle);

	}
	
	
	
		function DetailModal2(Qid,path){
		//styles = 'dialogWidth=488px;dialogHeight=500px;dialogTop=20;di alogLeft=20px;status=no;help=no;';
	
		src = path+"SDBSProduct_detail2.asp?Qid="+Qid;
		//window.showModalDialog(src,window,styles); 
		winstyle = "resizable=yes,height=500,width=500,status=yes,toolbar=no,menubar=no,location=no,scrollbars=yes,top=20,left=20";
		window.open(src,'detail',winstyle);

	}


	function winopen(win_start,win_finish,str_start,str_end,code,num)
	{
	f=document.form;		
			if (code == 1)
			{
					afterdate = eval("f."+str_end+".value"); 
					open(win_start+"?num="+num+"&s_fieldstart="+str_start+"&s_fieldend="+str_end+"&"+str_end+"="+afterdate, "calendar", "height=255 ,width=290,location=0,resiable=0, Status=0,menubar=0,scrollbars=0");	
			}
			else
			{
					begindate=eval("f."+str_start+".value"); 
					open(win_finish+"?num="+num+"&s_fieldend="+str_end+"&s_fieldstart="+str_start+"&"+str_start+"="+begindate, "calendar", "height=255 ,width=290,location=0,resiable=0, Status=0,menubar=0,scrollbars=0");	
			}
	}


	function PopColor(id,path){
		styles = 'dialogWidth=110px;dialogHeight=130px;dialogTop=150;dialogLeft=400px;status=no;help=no;';
		src = path+"popcolor.asp?id="+id;
		window.showModalDialog(src,'dialog',styles); 
		//winstyle = "height=500,width=482,status=yes,toolbar=no,menubar=no,location=no,scrollbars=no,top=20,left=20";
		//window.open(src,'detail',winstyle);
	}
	
	
	function chk_blank()
	{
		f = document.forms(0);
				if(Trim(f.Data.value))
				{
					WarnInput(f.Data," Data ")
				}
				else
				{
					f.submit();
				}
	}
	
		function chk_blank1()
	{
		f = document.formsearch;
				if(Trim(f.DataSearch.value))
				{
					WarnInput(f.DataSearch," Data Search ")
				}
				else
				{
					f.submit();
				}
	}

	
		function Trim(key)
		{
			sp =key.split(" ");
				ch = 0
			 	for (st = 0;st<sp.length;st++){
					if (sp[st] == ""){
						ch++;
					}
				}
				if (eval(sp.length) ==eval(ch)){
							return true;}
				else{
							return false;}
		} 
  
  function check_email(e) {
			ok = "1234567890qwertyuiop[]asdfghjklzxcvbnm.@-_QWERTYUIOPASDFGHJKLZXCVBNM";
			for(i=0; i < e.length ;i++){
			if(ok.indexOf(e.charAt(i))<0){ 
			return (false);
			}	
			} 
			if (document.images) {
			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 (-1);		
			} 
			}
			}

  
  	function WarnInput(key,name,lang)
	{
			if(lang.toUpperCase()=='EN')
			{alert(" Please Insert "+ name +"")
			key.focus();
			}
			else
			{alert(" กรุณากรอก "+ name +"")
			key.focus();
			}
	}		
	
	function Warncheck(key,name,lang)
	{
			if (lang.toUpperCase()=='EN')
			{alert(" Please check "+ name +" again !! ")
			key.focus();
			}
			else
			{alert(" กรุณาตรวจสอบ "+ name +" อีกครั้ง !! ")
			key.focus();
			}
	}		
	
	function openWin(win_src,win_name,width,height)
		{
		 window.open(win_src,win_name,"status=yes,toolbar=1,location=no,scrollbars=yes,left=1,top=1,width="+width+",height="+height).focus();
		}
		
	function Warnselbox(key,name,lang)
	{
			if (lang=='EN')
			{alert(" Please select "+ name +"  ")
			key.focus();
			}
			else
			{alert(" กรุณาเลือก "+ name +"  ")
			key.focus();
			}
			
	}		


	
		function chk_shipping(f,id)
	{
				var str_name,str_address,str_state,str_zipcode;
				var Name,address,State,Zipcode
				
				ff = document.form;
				Name 		=  	ff.Name.value;
				Address 	= 		ff.Address.value;
				State 			=  	ff.State.value;
				Zipcode 	= 		ff.Zipcode.value;
				
				sp_Name = Name.split(",")
				sp_Address = Address.split(",")
				sp_State = State.split(",")
				sp_Zipcode =Zipcode.split(",")
				
				
				if(id == "")
				{
					str_name				= "";
					str_address			= "";
					str_state				= "";
					str_zipcode 		= "";
				}
				else
				{
						Pos = parseFloat(id-1)
						str_name				= sp_Name[Pos];
						str_address			= sp_Address[Pos];
						str_state				= sp_State[Pos];
						str_zipcode 		= sp_Zipcode[Pos];
				}
				
				f.shipname.value			=str_name;
				f.shipaddress.value		=str_address;
				f.shipstate.value			=str_state;
				f.shipzipcode.value		=str_zipcode;
	}
	
		
	
	
function imgsize()
		{
			f = document.all;
			TotalRecord = f.TotalRecord.value;
			numberColumns = f.numberColumns.value;
			start_i = 1;
			k =  parseFloat(numberColumns);
			var img_obj = new Image();
			for (i=start_i ; i<=TotalRecord;i++)
			{
							eval("f.img"+i+k+".style.display=''")
							img_obj = eval("f.img"+i+k+".src")
							str_price = eval("f.Price"+i+k+".value")
							eval("document.getElementById('L_Price"+i+k+"').innerHTML ='"+ formatCurrency(str_price,'1')+" บาท&nbsp;&nbsp;'")
							w =eval("f.img"+i+k+".width")
							eval("f.img"+i+k+".width ="+eval(w*0.55)+"")
							
					if ( i % parseFloat(numberColumns) == 0)
						{
						k = k+parseFloat(numberColumns);
						}
 				}
		}


function thk_val(){
	f = document.form;
	Adult = f.Adult.value;
	Chd= f.Chd.value;
	Infant= f.Infant.value;
	if(!isNaN(Adult) && (Adult != "")){Adult = parseInt(Adult)}else{Adult = parseInt(0)}
	if(!isNaN(Chd)&& (Chd != "")){Chd = parseInt(Chd)}else{Chd = parseInt(0)}
	if(!isNaN(Infant) && (Infant != "")){Infant = parseInt(Infant)}else{Infant =parseInt(0)}
	sum = parseInt(Adult) + parseInt(Chd) + parseInt(Infant)
	document.all.numberseat.value =sum;
	if (sum >100)
	{
	alert("Not over 100 Pax!!!")
	alert("Pax is reset")
	f.Adult.value=''
	f.Chd.value=''
	f.Infant.value=''
	thk_val()
	}
	else
	{
	shwCus()
	}

}


		
function shwCus()
{
	var numberseat = document.all.numberseat.value;
	var numtotal= document.all.numtotal2.value;
		if(numberseat != "0"){
			document.all.rows.style.display = '';
			//document.all.rowcon.style.display = '';
		}
		else{
			document.all.rows.style.display = 'none';
			//document.all.rowcon.style.display = 'none';
		}
		
		for ( j=1;j<=eval(numtotal);j++){
			eval("document.all.row"+j+".style.display ='none' ") 
		     }
			for ( i=1;i<=eval(numberseat);i++){
			eval("document.all.row"+i+".style.display ='' ") 
		     }
			 document.all.numtotal2.value=eval(numberseat)
}


	function ccolor(th_chk,Value,Name,Count){
		countitem(th_chk)
		var f = document.form;
		for(i=1;i<Count;i++){
			if(eval("f.c"+i+".checked")){
				chk = true;
				break;
			}else{chk=false;}
		}
			if(eval("f."+Name+".checked")){
				eval("t"+Value+".style.backgroundColor='#F4F4F4'");
			}else{
				eval("t"+Value+".style.backgroundColor=''");
			}
			
	}
	
	function TableClick(id,number,Count){
		var f = document.form;
		TableId = eval("f.c"+number+".checked");

		if(TableId)
		{
			eval("f.c"+number+".checked=false");
						ccolor(false,id,'c'+number,Count);
			}
			else
			{
				eval("f.c"+number+".checked=true");
								ccolor(true,id,'c'+number,Count);
			}
	}
	
	
	function countitem(value)
				{
						f=document.form;
						CountTotal =parseFloat(f.CountTotal.value);
						if  (value == true)
						{
							CountTotal = CountTotal +1 ;
						}
						else
						{
							CountTotal= CountTotal - 1;	
						}
						f.CountTotal.value = eval(CountTotal)
				}

	function shop(path)
	{
					var f= document.form;
					var Str_val;
					TotalRecord = f.TotalRecord.value;
					var Str_Item ="";
					if (f.CountTotal.value == 0)
					{
						alert("กรุณาเลือกรายการสินค้าด้วยครับ")
					}
					else
					{
						for (var h =1 ; h <= TotalRecord ; h++)
						{
							if (eval("f.c"+h+".checked") == true)
							{
								Str_val = eval("f.c"+h+".value")
								Str_Item = Str_Item+Str_val+","
							}
						}
						Str_Item = Str_Item.substring(0,Str_Item.lastIndexOf(","))
						f.Str_Item.value = Str_Item;
						f.action = path;
						f.method="post"
						f.submit();
					}
	}


function view(name,num) 
{
	for(i=0;i<document.all[name].length;i++)	
		{
		if(i==parseInt(num-1)) 
		document.all[name][i].style.visibility="visible";
	else
		document.all[name][i].style.visibility="hidden";
		}
}

function init() 
{
	if(document.all["layer"]!=null)	
		{
		for(i=0;i<document.all["layer"].length;i++)
			document.all["layer"][i].style.visibility="hidden";
		}
}


function chk_position()
{
			for(i=0;i<document.all["layer"].length;i++)
			{
				screen_width  = screen.width;
				if(screen_width== 1024)
				{
					document.all["layer"][i].style.left = "230px"
				}
			}
		//	imgsize();
}

function chk_maillist(f)
{
		var maillista;
		
		f = document.all;
		if(f.maillist.value.length <4){
				Warncheck(f.maillist," Email ")
		}
		else if(!check_email(f.maillist.value)){
				Warncheck(f.maillist," Email ")
		}
		else
		{
			maillista = f.maillist.value;
			popup('1',maillista)
		}
}

function cls_value(f)
{
	f.maillist.value = '';
}

	function chk_itm(id)
	{
		f = document.formpro;
		f.Str_Item.value = id;
		f.submit();
	}

function chk_mailcontact(f,lang)
{


var chk_val
		if(Trim(f.str_sender.value)){
				if (lang.toUpperCase()=='EN')
				{
				WarnInput(f.str_sender ," Sender ",lang)
				}
				else
				{
				WarnInput(f.str_sender ," ชื่อผู้ส่ง ",lang)
				}
		}
		/*else if(!check_email(f.str_email.value)){
				if (lang.toUpperCase()=='EN')
				{
					Warncheck(f.str_email ," Email ",lang)
				}
				else
				{
					Warncheck(f.str_email ," อีเมลล์ ",lang)
				}
		}*/
		else if(Trim(f.str_subject.value))
		{
				if (lang.toUpperCase()=='EN')
				{
					WarnInput(f.str_subject," Subject ",lang)
				}
				else
				{
					Warncheck(f.str_subject ," เรื่อง ",lang)
				}
		}
		else if(Trim(f.str_comment.value))
		{
				if (lang.toUpperCase()=='EN')
				{
					WarnInput(f.str_comment," Description ",lang)
				}
				else
				{
					Warncheck(f.str_comment ," รายละเอียด ",lang)
				}
		}
		else if(Trim(f.str_email.value)==false)
			{
			if (!check_email(f.str_email.value))
			{Warncheck(f.str_email,"  Email ",lang)}
			else
			{chk_val = true;}
			}
		else
			{chk_val = true;}
			
		if(chk_val)
		{
			senders = f.str_sender.value;
			email= f.str_email.value;
			subjects= f.str_subject.value;
			comments = f.str_comment.value;
			str_address = f.str_address.value;
			str_tel = f.str_tel.value;
			str_fax = f.str_fax.value;
			
			querystring = "?sender="+senders+"&email="+email+"&suject="+subjects+"&comment="+comments+"&str_address="+str_address+"&str_tel="+str_tel+"&str_fax="+str_fax
			popup('_block/mailcontact.asp',querystring)
		}
}


function mailwebtofriend(lang)
{
f=document.sendwebtofriend
		if(!check_email(f.str_email.value)){
				if (lang.toUpperCase()=='EN')
				{
					Warncheck(f.str_email ," Email ",lang)
				}
				else
				{
					Warncheck(f.str_email ," อีเมลล์ ",lang)
				}
		}
		else if(Trim(f.str_sender.value))
		{
				if (lang.toUpperCase()=='EN')
				{
					Warncheck(f.str_sender ," From (Name) ",lang)
				}
				else
				{
					Warncheck(f.str_sender ," จาก (ชื่อ) ",lang)
				}
		}
		else
		{
		senders = f.str_sender.value;
		email= f.str_email.value;
			querystring = "?sender="+senders+"&email="+email
			popup('_block/mailwebtofriend.asp',querystring)
		}
}


	function Get_Group(f,val,sid)
	{
		f = document.forms(0);
		fa = document.all;
		var str_style,str_mnr,sumval;
		sumval = 0;
		if(sid == 1)
		{
			Get_SubGroup("","")
		}
		f.Group.value = '';
		str_mnr = f.s_mnr.value;
		countmain = f.Cut_Countrecord.value;
		spmnr = str_mnr.split(",");
		spcountmain = countmain.split(",");
		for(i=0  ;i < spmnr.length; i++){
			if(spmnr[i] !="" )
			{
				if(spcountmain[i] >= 0)
				{
						if(parseFloat(spmnr[i]) == parseFloat(val))
						{
						eval("fa.main"+spmnr[i]+".style.display=''");
						sumval = parseFloat(sumval) +1
						}
						else
						{
						eval("fa.main"+spmnr[i]+".style.display='none'");
						}
				}
			}
			if(sumval > 0)
			{
				fa.cols.style.display = '';
			}
			else
			{
				fa.cols.style.display = 'none';
			}
		}
	}

	function Get_SubGroup(f,val)
	{	
		f = document.forms(0);
		fa = document.all;
		var str_style,str_mnr,sumval;
		sumval=0;
		f.SubGroup.value = '';		
		f.Group.value = val;
		str_mnr = f.s_mnr1.value;
		c_count = f.s_count.value;
		spmnr = str_mnr.split(",");
		spcount = c_count.split(",");
		for(i=0  ;i < spmnr.length; i++){
			eval("f.SubGroup"+spmnr[i]+".value=''");
			if(spcount[i] > 0)
				{
						if(parseFloat(spmnr[i]) == parseFloat(val))
							{
							sumval = parseFloat(sumval) +1
							eval("fa.submain"+spmnr[i]+".style.display=''");
							}
							else
							{
							eval("fa.submain"+spmnr[i]+".style.display='none'");
							}
				}	
		}
		if(sumval > 0)
			{
				fa.cols1.style.display = '';
			}
			else
			{
				fa.cols1.style.display = 'none';
			}

	}
		
	function popup(url,querystring)
	{

			winstyle = "height=200,width=400,status=no,toolbar=no,menubar=no,location=no,scrollbars=yes,top=250,left=250";
			window.open(url+querystring,null,winstyle);
	}

	function Fill_val(f,val,id)
	{
			f = document.forms(0);
			if (id == 1)
			{
			f.Group.value = val;
			}
			else
			{
			f.SubGroup.value = val;
			eval("f.SubGroup"+f.Group.value+".value=val");
			}
	}
	
	function set_val(id,val)
	{
		f= document.form;
		//eval("f.SubGroup"+id+".value = "+val+"")
	}
	function IsDigits(Temp,f,name){
		var v = Temp.value
		var m = v.match(/[0-9]+/)
		var n = v.match(/0/)
		if(null != m){
			if (m[0].length==v.length){
			return true;
			}
		}
		alert(" Please Check  Amonut again !!")
		eval("f."+name+".value = 1")
		return false;
}

//===========================
	function Get_Group_a(f,val)
	{

		fa = document.all;
		var str_style,str_mnr;
		f.Group.value = '';
		if(val !="")
		{
			str_style='';
		}
		else
		{
			str_style= 'none';
		}
		fa.cols.style.display = str_style;
		str_mnr = f.s_mnr.value;
		spmnr = str_mnr.split(",");
		for(i=0  ;i < spmnr.length; i++){
			if(parseFloat(spmnr[i]) == parseFloat(val))
				{
				eval("fa.main"+spmnr[i]+".style.display=''");
				}
				else
				{
				eval("fa.main"+spmnr[i]+".style.display='none'");
				}	
			}
	}
//function Fill_val(f,val)
//	{
//			f.Group.value = val;
//	}
	function chkval(val)
	{
		fa = document.all;
		if (val.toLowerCase() == "price")
		{
			fa.L_Price.style.display = '';
		}
		else
		{
			fa.L_Price.style.display = 'none';
		}
	}
	
	function chkSearch()
	{
		ff = document.form2;
		if(Trim(ff.Data.value))
		{
			alert("กรุณากรอกคำที่คุณต้องการค้นหาด้วยครับ")
			ff.Data.focus();
		}
	//	else if(Trim(ff.Model.value))
	//	{
	//		alert("กรุณาเลือก Model ด้วยครับ")
	//		ff.Model.focus();
	//	}
		else if(Trim(ff.Prop.value))
		{
			alert("กรุณาเลือก Option ด้วยครับ")
			ff.Prop.focus();
		}
		else
		{
			ff.submit();
		}

	}
	
		function gotoshow()
		{
				var f = document.forms(0);
				f.action	=	"modifyItem.asp"
				f.submit();
		}
//window.onerror = handle_error; function handle_error(){return true;}

	function dmy(str_day,str_month,str_year)
	{
	f = document.form;
    var cday=eval("f."+str_day+".value");
	var cmonth=eval("f."+str_month+".value");
	var cyear=eval("f."+str_year+".value");
	if((cmonth == 'Apr')||(cmonth == 'Jun')||(cmonth == 'Jul')||(cmonth == 'Nov') || (cmonth == '4')||(cmonth == '6')||(cmonth == '9')||(cmonth == '11'))
	{
		if(cday > 30)
		{
		alert ('Please Check Day Again  ( This month have 30days )');
		eval("f."+str_day+".value = 30 ");
		eval("f."+str_day+".focus");
		}
	}
	else if((cmonth =='Feb')||(cmonth =='2'))
		{
		var nyear = eval((cyear - 543)%4);
		if( nyear > 0 && cday > 28)
			{
		//	alert(nyear);
			alert('Please Check Day Again  ( This month have 28 days )');
			eval("f."+str_day+".value = 28 ");
			eval("f."+str_day+".focus");
			}
		else if( nyear == 0 && cday > 29)
			{
			//alert(nyear);
			alert(' Please Check Day Again  ( This month have 29 days )');
			eval("f."+str_day+".value = 29 ");
			eval("f."+str_day+".focus");
			}
		}
	}

function CheckNumber(value)
{
	 ch = String.fromCharCode(event.keyCode);
	 	if   (ch >= ":" )
	{alert("Please Insert Number \n กรุณาใส่เป็นตัวเลข")
	event.keyCode = 0;    
	}
}

function MultiReplace(Data,FindSubstring,ReplaceSubstring)
{
var i,s
FindSubstring=FindSubstring.split(",")
ReplaceSubstring=ReplaceSubstring.split(",")
for (i=0;i<FindSubstring.length;i++)
{
	for (j=0;j<Data.length;j++)
	{
	Data=Data.replace(FindSubstring[i],ReplaceSubstring[i])
	}
}

return Data

}

function ControlReplace(Data)
{
Data=MultiReplace(Data,"(),(_1)","',\"")
return Data
}




function showhide(elementName)
{
if (eval("document.all."+elementName+".style.display")=='')
eval("document.all."+elementName+".style.display='none'")
else
eval("document.all."+elementName+".style.display=''")
}


function checklogin(Url,val) //Use With Link For Check Login
{
	if (val=='')
	{
		alert(" กรูณา Login ก่อนเข้าเมนูนี้ค่ะ")
	}
	else
	{
	window.location=Url
	}
}

function formatnumber(val) //Sample  formatnumber('100') Or  formatnumber(100.toFixed(2))
{
val=val.split(".");
if  (val[0]=='NaN') return  ""
if  (val[1]==undefined) val[1]="00"
var num=''
var temp=0
	for (a=val[0].length;a>=0;a--)
	{
	if (temp==3 && a !=0)
	{temp=0
	comma=','}
	else
	{comma=''}
	
	subval=val[0].substr(a,1)
	num=comma+subval+num
	temp++
	}
		//alert(num+"."+val[1])
	return  num+"."+val[1]

}


   function PopupPic(sPicURL) { 
     window.open( "_block/popupimgfix.asp?"+sPicURL, "",  
     "resizable=no,status=no,toolbar=no,location=no,scrollbars=yes,HEIGHT=200,WIDTH=200"); 
   } 
   
   
<!--
function addToFavorite(favTitle){
  if ((navigator.appVersion.indexOf("MSIE") > 0) && (parseInt(navigator.appVersion) >= 4)) {
    window.external.AddFavorite(location.href, unescape(favTitle));
  }
}









<!---- function for invoice---->

function formatnumber(val)
{
val=val.split(".");
if  (val[1]==undefined) val[1]="00"
var num=''
var temp=0
	for (a=val[0].length;a>=0;a--)
	{
	if (temp==3 && a !=0)
	{temp=0
	comma=','}
	else
	{comma=''}
	
	subval=val[0].substr(a,1)
	num=comma+subval+num
	temp++
	}
		//alert(num+"."+val[1])
	return  num+"."+val[1]

}




function userReplace(val,rexExp,newStr)
{var data

	data=val.replace(rexExp,newStr)
	for (d=0;d<val.length;d++)
	{
	data=data.replace(rexExp,newStr)
	}

	return data
}

	function Checkvalue(lang)
	{
				f = document.form;
					if(Trim(f.OrderNO.value))
						{
							WarnInput(f.OrderNO,"  เลขที่ ",lang)
						}
				/*	else if(Trim(f.CalNameEN.value))
						{
							warninput(f.CalNameEN," Topic (English) ",lang)
						}
					else if(Trim(f.CalStart.value))
						{
							Warnselbox(f.CalStart," Validity Start ",lang)
						}*/
					else
						{
							if(confirm(" Are you sure ?"))
							{

							f.submit();
							}
						}

			  
	}
	
	
	function FindData(val,Data,ObjectName)
	{
				f = document.forms[0];
				Data=Data.split(",")
				for (a=0;a<Data.length;a++)
				{
					if(val==Data[a])
					{
					alert("มีเลขที่นี้แล้ว")
					eval("f."+ObjectName+".value=''")
					}
				
				}
				
	}
	
	
function swapprice(index,quantitybuy,price,specialprice)   //swap price between nornal price and special price
{
	
	f=document.forms(0);
	if(quantitybuy>=10)
	{
		if (parseInt(specialprice)<parseInt(price))
		{
			eval("f.UnitPrice"+index+".value="+specialprice)
			eval("f.UnitPrice10_"+index+".value="+price)
		}
		else
		{
			eval("f.UnitPrice"+index+".value="+price)
			eval("f.UnitPrice10_"+index+".value="+specialprice)
		}
	}
	else
	{
		if (parseInt(specialprice)>parseInt(price))
		{
			eval("f.UnitPrice"+index+".value="+specialprice)
			eval("f.UnitPrice10_"+index+".value="+price)
		}
		else
		{
			eval("f.UnitPrice"+index+".value="+price)
			eval("f.UnitPrice10_"+index+".value="+specialprice)
		}
	}
	

}

function calAmount(quantity,price,Fillobjectname,discountperunit)
{
f=document.forms(0)

	if ((price !='') || (quantity !=''))
	{
	eval("f."+Fillobjectname+".value='"+formatnumber((price*quantity-discountperunit).toFixed(2))+"'")
	}
	else
	{
	eval("f."+Fillobjectname+".value=''")
	}

	
}





function calTotal(numrow,Calobjectname,Fillobjectname)
{
f=document.forms(0)
var total=0

for (i=0;i<=numrow;i++)
{
	if  (eval("f."+Calobjectname+i+".value")!='')
	{
	total=(parseFloat(total)+parseFloat(userReplace(eval("f."+Calobjectname+i+".value"),",","")))
	
		//	alert("10000".replace("0","#"))
	}

}

	if (total != 0 )
	{
	eval("f."+Fillobjectname+".value='"+formatnumber(total.toFixed(2))+"'")
	}
	else
	{
	eval("f."+Fillobjectname+".value=''")
	}
	


}

function calVAT(val,VATPercent,Fillobjectname)
{
f=document.forms(0)

	if (val !=0)
	{
	eval("f."+Fillobjectname+".value='"+formatnumber(((userReplace(val,",","")*VATPercent)/100).toFixed(2))+"'")
	}
	else
	{
	eval("f."+Fillobjectname+".value=''")
	}
}

function calDiscount(val,DiscountPercent)
{
f=document.forms(0)
	if (val !=0)
	{
	Pricediscount=(val*DiscountPercent)/100
	}
	else
	{
	Pricediscount=0
	}
	return formatnumber(Pricediscount.toFixed(2))
}

function excludeVAT2()
{
f=document.forms(0)

	if (f.excludeVAT=='[object]')
	{
	TotalPrice=parseFloat(f.TotalPrice.value.replace(",",""))
	if (f.excludeVAT[0].checked==1)
	{TotalPrice2=TotalPrice}
	else
	{TotalPrice2=(TotalPrice.toFixed(2)*100)/107}
	f.TotalPrice.value=TotalPrice2.toFixed(2)
	}
}


function OrderOnload(numrow)
{f=document.forms(0)

	for (z=0;z<=numrow;z++)
	{
	
	if (eval("f.DiscountPerUnit"+z)=='[object]')
	{discountperunit=eval("f.DiscountPerUnit"+z+".value").replace(",","")}
	else
	{discountperunit=0}
	
	calAmount(userReplace(eval("f.Quantity"+z+".value"),",",""),userReplace(eval("f.UnitPrice"+z+".value"),",",""),'Amount'+z,discountperunit);
	calTotal(numrow,'Amount','TotalPrice');
	excludeVAT2();
	if  (f.discount.value!='0')
	{f.discountPrice.value=calDiscount(userReplace(f.TotalPrice.value,',',''),userReplace(f.discount.value,',',''))}
	else
	{f.discountPrice.value=parseFloat(f.discountPrice.value).toFixed(2)}
	f.TotalPrice2.value=formatnumber((userReplace(f.TotalPrice.value,',','')-userReplace(f.discountPrice.value,',','')).toFixed(2))
	calVAT(f.TotalPrice2.value,f.VAT.value,'VATPrice');
	f.TotalAllPrice.value=formatnumber((parseFloat(userReplace(document.form.TotalPrice2.value,',',''))+parseFloat(userReplace(document.form.VATPrice.value,',',''))).toFixed(2))
	}
	
	if (f.TotalAllPrice.value!='')
	{
		if (f.WordNum!=undefined)
		{f.WordNum.value=convertnumber(f.TotalAllPrice.value.replace(',',''))}

		if (f.WordNumEN!=undefined)
		{f.WordNumEN.value=dollarText(f.TotalAllPrice.value.replace(',',''))}

	}
}



function convertnumber(number)
{
f=document.forms(0)
var main=new Array("","สิบ","ร้อย","พัน","หมื่น","แสน","ล้าน")
var numname=new Array("","หนึ่ง","สอง","สาม","สี่","ห้า","หก","เจ็ด","แปด","เก้า")
var  convertnumber=""
number=number.replace(",","")
number=number.split(".");

				for (z=0;z<number.length;z++)
				{
				var countnum=number[z].length
			//alert(countnum) //4,2         //sample value is 3,000.00              
				var x=0
							for (i=1;i<=countnum;i++)
							{
							var subnumbertemp,subnumber
							
							subnumbertemp=subnumber
							//alert(subnumber)    //underfined,3,0,0,0,0            
							//alert(subnumbertemp)  //underfined,3,0,0,0,0
							var subnumber = number[z].substr(x,1);
							//alert(number[z]) //3000,3000,3000,3000     00,00
							//alert(z) //0,0,0,0,1,1
							
							//alert(subnumber) //3,0,0,0      0,0
							var submain=countnum-i
							//alert(submain) //3,2,1,0      1,0
							//var tnumname
							//alert(numname[subnumber])  //สาม,"","","","",""
							if (numname[subnumber]!="")
							{
											 if (i==countnum)
											 {
															  if ((subnumber==1) && (countnum>1) && (subnumbertemp!=0))
															  {tnumname="เอ็ด"}
															  else
															  {tnumname=numname[subnumber]}
												}
												else if (i==(countnum-1))
												{
															  if (subnumber==1)
															  {tnumname="สิบ"}
															  else if (subnumber==2)
															  {tnumname="ยี่"+main[submain]}
															  else
															  {tnumname=numname[subnumber]+main[submain]}
												}
												else
												{
											    tnumname=numname[subnumber]+main[submain]
												//alert(main[submain])  //พัน
												}
							}
							else
							{
							tnumname=""
							}
							convertnumber=convertnumber+tnumname
							x++
							}
				
						switch  (z)
						{
						case 0 :
							if (number.length==0)
							{
										if (number[z]!=0) {convertnumber=convertnumber+"บาทถ้วน"}
							}
							else 
							{
										if (number[1]!=0) 
										{convertnumber=convertnumber+"บาท"}
										else if (number[1]==0) 
										{convertnumber=convertnumber+"บาทถ้วน"}
										



							}
						break;

						case 1 :
							if (number[z]!=0) {convertnumber=convertnumber+"สตางค์"}
						break;

						}
				
				}
				
			if (number!="") 
			{convertnumber="-"+convertnumber+"-";}
			else
			{convertnumber="";}
			
			return convertnumber;
				
}


function dollarText(amt) {
// Note: It is expected that amt is a number
// (not a text string).
var crores=0; var millions=0; var lakhs=0; var myriads=0;
var thousands=0; var hundreds=0; var tens=0; var ones=0;
var dimes=0; var cents=0;
var leftover=amt;
if (leftover<0) return "Error: Negative amounts not allowed.";
if (leftover>1.0e8) return "Error: Amount is too large.";
while (leftover>=1.0e7) {leftover-=1.0e7; crores++;}
while (leftover>=1.0e6) {leftover-=1.0e6; millions++;}
while (leftover>=1.0e5) {leftover-=1.0e5; lakhs++;}
while (leftover>=1.0e4) {leftover-=1.0e4; myriads++;}
while (leftover>=1.0e3) {leftover-=1.0e3; thousands++;}
while (leftover>=1.0e2) {leftover-=1.0e2; hundreds++;}
while (leftover>=1.0e1) {leftover-=1.0e1; tens++;}
while (leftover>=1.0e0) {leftover-=1.0e0; ones++;}
while (leftover>=0.100) {leftover-=0.100; dimes++;}
while (leftover>=0.010) {leftover-=0.010; cents++;}
if (leftover>=0.005) cents++;
if (cents>=10) {cents-=10; dimes++;}
if (dimes>=10) {dimes-=10; ones++;}
if (ones>=10) {ones-=10; tens++;}
if (tens>=10) {tens-=10; hundreds++;}
if (hundreds>=10) {hundreds-=10; thousands++;}
if (thousands>=10) {thousands-=10; myriads++;}
if (myriads>=10) {myriads-=10; lakhs++;}
if (lakhs>=10) {lakhs-=10; millions++;}
if (millions>=10) {millions-=10; crores++;}
if (crores>=10) return "Error: Amount is too large.";
var lowWords=new Array("zero","one","two","three","four","five",
"six","seven","eight","nine","ten","eleven","twelve","thirteen",
"fourteen","fifteen","sixteen","seventeen","eighteen","nineteen");
var medWords=new Array("ERROR","ERROR","twenty","thirty","forty",
"fifty","sixty","seventy","eighty","ninety");
// I was going to make an array called highWords, but I changed my mind.
var work="";
if (crores>=2) work+=(((medWords[crores])+((millions==0)?
'':('-'+lowWords[millions])))+' million ');
else if (crores>0 || millions>0) work+=
lowWords[(crores*10)+millions]+' million ';
if (lakhs>0) work+=(lowWords[lakhs]+' hundred'+
((myriads>0 || thousands>0)?' ':''));
if (myriads>=2) work+=(((medWords[myriads])+((thousands==0)?
'':('-'+lowWords[thousands]))));
else if (myriads>0 || thousands>0) work+=
lowWords[(myriads*10)+thousands];
if (lakhs>0 || myriads>0 || thousands>0) work+=' thousand ';
if (hundreds>0) work+=(lowWords[hundreds]+' hundred'+' ');
if (tens>=2) work+=(((medWords[tens])+((ones==0)?
'':('-'+lowWords[ones])))+' ');
else if (tens>0 || ones>0) work+=(lowWords[(tens*10)+ones]+' ');
if (crores==0 && millions==0 && lakhs==0 && myriads==0
&& thousands==0 && hundreds==0 && tens==0) {
if (ones==0) work+='';
else if (ones==1) work+='';
else work+='';
} else work+='';
if (dimes==0 && cents==0) work+='';
else if (dimes==0 && cents==1) work+=' and one';
else if (dimes<2) work+=' and '+lowWords[(dimes*10)+cents]+'';
else work+=' and '+(medWords[dimes]+(cents==0?'':('-'+lowWords[cents]))
+'');
return work;
}

//-->
