	
	
	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=550,width=550,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=yes,menubar=0,scrollbars=yes");	
			}
			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=yes,menubar=0,scrollbars=yes");	
			}
	}


	function openWin(win_src,win_name,width,height)
		{
		 window.open(win_src,win_name,"status=yes,toolbar=no,location=no,scrollbars=yes,left=1,top=1,width="+width+",height="+height).focus();
		}
		
		
	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 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 shwCus()
{
	var Pack = document.all.Pack.value;
	var numtotal= document.all.numtotal.value;
	//	if(Pack != "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(Pack);i++){
			eval("document.all.row"+i+".style.display ='' ") 
		     }
			 document.all.numtotal.value=eval(Pack)
}


	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(lang)
{
		f = document.form;

		if(Trim(f.cause.value)){
				Warnselbox(f.cause ," cause ",lang)
		}
		else if(Trim(f.str_sender.value)){
				WarnInput(f.str_sender ," Sender ",lang)
		}
		else if(f.str_email.value.length <4){
				if (lang.toUpperCase()=='EN')
				{
					Warncheck(f.str_email ," Email ",lang)
				}
				else
				{
					Warncheck(f.str_email ," อีเมลล์ ",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
		{
			cause = f.cause.value;
			senders = f.str_sender.value;
			email= f.str_email.value;
			subjects= f.str_subject.value;
			comments = f.str_comment.value;
			querystring = "?sender="+senders+"&email="+email+"&suject="+subjects+"&comment="+comments+"&cause="+cause
			popup('_block/sdbsmailcontact.asp',querystring)
		}
}





	function Get_Group(f,val,sid)
	{
		f = document.form;
		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.form;
		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.form;
			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 chk_date(d,named,m,namem,y,namey)
	{
			var f  = document.all;
			var str_day		=	eval("f."+d+".value");
			var str_month	=	eval("f."+m+".value");
			var str_year		=	eval("f."+y+".value");
			if((str_month == '4')||(str_month == '6')||(str_month == '9')||(str_month == '11'))
			{
				if(str_day > 30)
				{
				alert ('Please Check Date again Because In  the Month have 30 days');
				eval("f."+d+".focus()");
				return false;
				}
				else
				{
				return true;
				}
			}
	else if(str_month =='2')
		{
		var nyear = eval((str_year - 543)%4);
		if( nyear > 0 && str_day > 28)
			{
				alert ('Please Check Date again Because In  the Month have 28 days');
				eval("f."+d+".focus()");
								return false;

			}
		else if( nyear == 0 && str_day > 29)
			{
				alert ('Please Check Date again Because In  the Month have 29 days');
				eval("f."+d+".focus()");
								return false;
			}
			else
			{
				return true;
			}
		}
		else
		{
			return true;
		}	
	}
//window.onerror = handle_error; function handle_error(){return true;}

	



