//--------------------------------------------------------------------------------------------------//

//					File chua cac ham Javascript cho don the User									//									

//								Huynh Le Thanh Tung 												//

//								Tan Le Nguyen: 30/3/2004											//

//					Modified by Nguyen thi Thanh Thanh (3/2005)
//--------------------------------------------------------------------------------------------------//

function OpenWindow(FormName,FileName,Title)
{
	FormName.action=FileName;
	FormName.method="post";
	FormName.target=Title;
	W=700;
	H=470;
	Xcenter = screen.width/2;
	Ycenter = screen.height/2;
	Xtop = Xcenter - (W/2);	
	Ytop = Ycenter - (H/2);
	sList = window.open(FileName, Title,"width="+ W +",height="+H+",left="+Xtop+",top="+Ytop+",toolbar,resizable,scrollbars,z-locks=yes,dependent=yes");
}
function OpenRMWindow() 
{
		W=950;
		H=630;
		Xtop = 20;
		Ytop = 10;
		window.name="TLN";
		sList = window.open("Include/Details/rapmay.php", "rapmay","width="+ W +",height="+H+",left="+Xtop+",top="+Ytop+",toolbar,resizable,scrollbars,z-locks=yes,dependent=yes");
}

function cent(amount) {
return (amount == Math.floor(amount)) ? amount + '.00' : (  (amount*10 == Math.floor(amount*10)) ? amount + '0' : amount)
}

/*
	function formhandle(string,DG,VAT,SL,TT,Name,DVT,ID)
	{
		str=string.split("!");
		MALSP=str[0];
		ID.value=str[1];
		DG.value=parseInt(str[2],10);
		VAT.value=parseInt(str[3],10);
		TT.value=Math.round((parseInt(SL,10)*DG.value*(1+VAT.value/100))*100)/100;
		DVT.value=str[4];
		Name.value=str[5];
		document.rapmay.total.value=Math.round(parseInt(document.rapmay.total.value,10)+parseInt(TT.value,10))*100/100;
//		document.write('<a href="OpenNWindow(Include/Details/hienthichitiet.php&deep=2&cbolsp="'+MALSP+'"&Masp="'+str[1]+'">Chi tiet</a>');
	}

*/
	function formhandle(string,DG,VAT,SL,TT,Name,DVT,ID,LK,i)
	{
		str=string.split("!");
		MALSP=str[0];
		ID.value=str[1];
		DG.value=parseInt(str[2],10);
		VAT.value=parseInt(str[3],10);
		TT.value=cent(Math.round((parseInt(SL,10)*DG.value*(1+VAT.value/100))*100)/100);
		DVT.value=str[4];
		Name.value=str[5];
		LK[i]=parseFloat(TT.value);//Math.round((parseInt(SL,10)*DG.value*(1+VAT.value/100))*100)/100;
		tam=0;
		for(j=0;j<LK.length;j++)
		{
			if(isNaN(LK[j]))
				LK[j]=0;
			tam = tam+LK[j];
		}
		document.rapmay.total.value=cent(Math.round(tam*100)/100);
//		document.write('<a href="OpenNWindow(Include/Details/hienthichitiet.php&deep=2&cbolsp="'+MALSP+'"&Masp="'+str[1]+'">Chi tiet</a>');
	}
	function formhandleSL(SL,DG,VAT,TT,LK,i)
	{
		if(DG!="")
		{
			TT.value=cent(Math.round((parseInt(SL,10)*parseInt(DG,10)*(1+parseInt(VAT,10)/100))*100)/100);
			LK[i]=parseFloat(TT.value);//Math.round((parseInt(SL,10)*parseInt(DG,10)*(1+parseInt(VAT,10)/100))*100)/100;
			tam=0;
			for(j=0;j<LK.length;j++)
			{
				if(isNaN(LK[j]))
					LK[j]=0;
				tam=tam+LK[j];
			}
			document.rapmay.total.value=cent(Math.round(tam*100)/100);
		}
	}

function formhandleLSP(script)
{
	cbogtri=document.form1.cbolsp.options[document.form1.cbolsp.selectedIndex].value;
	if (cbogtri!="")
		window.location.href=script + cbogtri;
}

function formhandleHSX(script)

{

	cbogtri=document.form1.cbohsx.options[document.form1.cbohsx.selectedIndex].value;

	if (cbogtri!="")

		window.location.href=script + cbogtri;

}



function formhandleHSXHienThi(MaLSP) // hien thi Hang San Xuat them Loai San Pham

{

	cbogtri=document.form2.cbohsx.options[document.form2.cbohsx.selectedIndex].value;

	script = "index.php?file=hienthi&deep=1&cbolsp=" + MaLSP;

	if (cbogtri!="")

		script += "&cbohsx=";

	window.location.href=script + cbogtri;

}



function formhandleLSPHienThi(MaHSX) // Hien thi Loai San Pham Theo Hang San Xuat

{

	cbogtri=document.form2.cbolsp.options[document.form2.cbolsp.selectedIndex].value;

	script = "index.php?file=hienthi&deep=1&cbohsx=" + MaHSX;

	if (cbogtri!="")

		script += "&cbolsp=";

	window.location.href=script + cbogtri;

}



function MaxDate(th,na)

{

	var result=0;

	var thang,nam;

	thang = parseInt(th,10);

	nam = parseInt(na,10);

	if(thang<=12 && thang>=1 && nam>0)

	{

		switch(thang)

		{

			case 1:

			case 3:

			case 5:

			case 7:

			case 8:

			case 10:

			case 12:

				result =31;

			break;

		

			case 2:

				if(nam%4)

				{

					result =28;

				}

				else

				{

					result =29;

				}

				break;

		

			default :

				result =30;

			break;

		}

	}

	return result;

}



function OpenWindowImage(page)

{

	winwidth = 480;

	winheight =  480;



	x = screen.width / 2;

	y = screen.height / 2 ;

	xwin = x - winwidth;

	ywin = y - winheight;



	prowin = "toolbar=no,menubar=no,location=no,scrollbars=yes,resizable=yes";

	prowin += ",width=" + winwidth;

	prowin += ",height=" + winheight;

	prowin += ",screenX=" + x;

	prowin += ",screenY=" + y;

	newwin = window.open(page, "CtrlWindow",prowin);
	newwin.document.write("<a href='javascript:window.close()'><p align='right'><font face='verdana,arial' size=2><b>CLOSE</b></font></p></a>");
	newwin.document.write("<p align=center><img border='0' src=" + page +"></p>");	
//	newwin.document.write("<a href='javascript:window.close()'><p align=center><img border='0' src=" + page +"></p></a>");	
/*
	newwin.document.write("<p align=center><img src=" + page +"></p>");	

	newwin.document.write('<p align="center">');		

	newwin.document.write("<a href='javascript:window.close()'>");

	newwin.document.write('<font face="Verdana" size="3pt">');		

	newwin.document.write("Close Window");

	newwin.document.write('</font>');

	newwin.document.write("	</a>");		

	newwin.document.write('</p>');						
*/
	newwin.focus();

}



function sendinfo()

{

	f = document.khachhang;

	if (document.khachhang.hoten.value=="")

	{

		alert("Ban chua nhap ho ten");

		document.khachhang.hoten.focus();

		return false;

	}

	else

	if (document.khachhang.diachi.value=="")

	{

		alert("Ban chua nhap dia chi");

		document.khachhang.diachi.focus();

		return false;

	}

	else

	if (document.khachhang.dienthoai.value=="")

	{

		alert("Ban chua nhap dien thoai");

		document.khachhang.dienthoai.focus();

		return false;

	}

	else

	if (document.khachhang.email.value=="")

	{

		alert("Ban chua nhap email");

		document.khachhang.email.focus();

		return false;

	}

	else

	if (document.khachhang.email.value.indexOf('@')==-1)

	{

		alert("Email nhap khong dung");

		document.khachhang.email.focus();

		return false;

	}

	else

	if (document.khachhang.email.value.indexOf('.')==-1)

	{

		alert("Email nhap khong dung");

		document.khachhang.email.focus();

		return false;

	}

	else

/*	if (document.khachhang.thanhpho.value=="")

	{

		alert("Ban chua nhap ten Thanh pho - Quoc gia");

		document.khachhang.thanhpho.focus();

		return false;

	}

	else

*/	return true;

}





function TimKiem() // Hien thi Loai San Pham Theo Hang San Xuat

{

	searchstring = document.form1.searchstring.value;

	script = "index.php?file=timkiem&deep=1&search=" + searchstring;

	window.location.href=script;

}



/* Lam Hinh mo di */

function high(which2){

theobject=which2

highlighting=setInterval("highlightit(theobject)",50)

}

function low(which2){

clearInterval(highlighting)

if (which2.style.MozOpacity)

which2.style.MozOpacity=0.3

else if (which2.filters)

which2.filters.alpha.opacity=60

}



function highlightit(cur2){

if (cur2.style.MozOpacity<1)

cur2.style.MozOpacity=parseFloat(cur2.style.MozOpacity)+0.1

else if (cur2.filters&&cur2.filters.alpha.opacity<100)

cur2.filters.alpha.opacity+=10

else if (window.highlighting)

clearInterval(highlighting)

}

/* het lam hinh mo di*/



function CheckAll(myform)

{

	for(var i=0;i<myform.length;++i) 

	{ 

		 var boolValue = myform.CBIDAll.checked;

		 if(myform.elements[i].type=='checkbox')

		 { 

		 	if (myform.elements[i].name!="CBIDAll")

			{

				if (myform.elements[i].name=="CheckBoxID[]")

						myform.elements[i].checked=boolValue;  

			}

		}

	}

}



// ham kiem tra so luong trong gio hang dung la so hay khong



function CheckGioHang(myform)

{

	for(var i=0;i<myform.length;++i) 

	{ 

		 if(myform.elements[i].type=='text')

		 { 

			if (myform.elements[i].name=="SoLuongID[]")

			{

				if (isNaN(myform.elements[i].value))

					break;

			}

		}

	}



	if (i>=myform.length)

	{

		return true;	

	}

	else

	{

		alert("Xin hay kiem tra lai thong tin : So luong da nhap khong hop le");

		return false;

	}

}



function Delete()

{

	form2 = document.f;

	form2.action = "index.php?file=order&action=delete";

	form2.submit();



}

//--------------------------------------------------------------------------------------------------//

//					File chua cac ham Javascript cho don the user									//									

//								Huynh Le Thanh Tung 												//

//								Tan Le Nguyen: 30/3/2004											//

//--------------------------------------------------------------------------------------------------//

// Ham chon tat ca check box tren form
//input: ten form
//output: tat ca checkbox trong form se duoc chon
function checkAll(myform)
{
	for(var i=0;i<myform.length;++i) 
	{ 
		 if(myform.elements[i].type=='checkbox') 
		{   
			myform.elements[i].checked=true;  
		} 
	}
}
// Ham bo chon tat ca check box tren form
//input: ten form
//output: tat ca checkbox trong form se duoc bo chon
	
function uncheckAll(myform)
{
	for(var i=0;i<myform.length;++i) 
	{ 
		 if(myform.elements[i].type=='checkbox') 
		{   
			myform.elements[i].checked=false;  
		} 
	}
}
