//function CuaSoAnh(vLink,vWidth,vHeight)
function CuaSoAnh(id_link,ChieuRong,ChieuCao)
{
	var sLink = (typeof(id_link.href) == 'undefined') ? id_link : id_link.href;

	if (sLink == '')
	{
		return false;
	}

	winDef = 'status=no,resizable=no,scrollbars=no,toolbar=no,location=no,fullscreen=no,titlebar=yes,height='.concat(ChieuCao).concat(',').concat('width=').concat(ChieuRong).concat(',');
	winDef = winDef.concat('top=100').concat(',');
	winDef = winDef.concat('left=250');

	newwin = open('', '_blank', winDef);

	newwin.document.writeln('<title>Impex K&J</title><body topmargin="0" leftmargin="0" marginheight="0" marginwidth="0">');
	newwin.document.writeln('<a href="" onClick="window.close(); return false;"><img src="', sLink, '" alt="', 'Close window', '" border=0></a>');
	newwin.document.writeln('</body>');

	if (typeof(id_link.href) != 'undefined')
	{
		return false;
	}
}
function check_del(){
		if (confirm("Ban co chac chan thuc hien khong")){return true;}
		//for(i=0;i<document.form1.id_tv[].length)	
		return false;
}



function sm_spoto(id_tn){
	document.form_sanpham_oto.id_tinhnang.value=id_tn;
	document.form_sanpham_oto.submit();
}
function sm_danhmuc(){
	if(document.danhmuc.tenA_.value==""){
		alert("Phai nhap ten danh muc");
		document.danhmuc.tenA_.className = "Form_HopVanBan1";
		document.danhmuc.tenA_.focus();		
		return false;
	}
	return true;

}
function sm_sanpham(tenform){

 /* for( i=0;i<document.forms[tenform].length;i++){
		if((document.forms[tenform].elements[i].value=="")&&(i!=5)){
			alert("Phai nhap du thong tin" );
			document.forms[tenform].elements[i].className="Form_HopVanBan1";
			document.forms[tenform].elements[i].focus();
			return false;
		};
	}*/
	if(document.forms[tenform].maso_.value==""){
			alert("Phai nhap ma so" );
			document.forms[tenform].maso_.className="Form_HopVanBan1";
			document.forms[tenform].maso_.focus();			
			return false;					
	}
	/*if(document.forms[tenform].cdV_.value==""){
			alert("Phai nhap cong dung Viet" );
			document.forms[tenform].cdV_.className="Form_HopVanBan1";
			document.forms[tenform].cdV_.focus();			
			
			return false;					
	}*/
	
	return true;
}



function kt_donhang(tenform){

	if(document.forms[tenform].name.value==""){
			alert("Please fill name" );
			document.forms[tenform].name.focus();			
			return false;					
	}
	
	if(document.forms[tenform].email.value==""){
			alert("Please fill valid email" );
			document.forms[tenform].email.focus();			
			return false;					
	}

	if(document.forms[tenform].content.value==""){
			alert("Please fill content" );
			document.forms[tenform].content.focus();			
			return false;					
	}
	
	
	//kiem tra thong tin san pham 
	var sophantu = document.forms[tenform].soluong.length;
	var is_null = true;

	if(sophantu>1){
		for (i=1;i<sophantu;i++){
			if (document.forms[tenform].soluong[i].value!=""){
				 is_null = false;
			}
		}
		if(is_null){	
			alert("Please select product to order");
			document.forms[tenform].soluong[1].focus();
			return false;
		}
	
		//kiem tra gia tri hop le
			//dinh ngia bien kieu num
		var a_num=/(^\d+$)|(^\d+\.\d+$)/ ;	
	
		for (i=1;i<sophantu;i++){
			if ((!a_num.test(document.forms[tenform].soluong[i].value)) && (document.forms[tenform].soluong[i].value!="")){
				document.forms[tenform].soluong[i].focus();
				alert("Please fill valid number");
				return false;
			}
		}
	
		//lay nhung san pham co so luong va id san pham do ghep lai voi nhau
		var str_sanpham_soluong = "";
		for (i=1;i<sophantu;i++){
			if (document.forms[tenform].soluong[i].value!=""){
				str_sanpham_soluong += "," + document.forms[tenform].id_sanpham[i].value + "_" + document.forms[tenform].soluong[i].value;
			}
		}
		document.forms[tenform].danhsach_sanpham_soluong.value = str_sanpham_soluong;
	}
	
	/*else{
			
		alert("Xin vui long chon san pham de lien he");	
		return false;
	}*/
	return true;
}

function sm_chung_hoalop(tenform,tg){
  for( i=0;i<document.forms[tenform].length;i++){
		if((document.forms[tenform].elements[i].value=="")&&(i!=4)){
			alert("Phai nhap du thong tin ");
			document.forms[tenform].elements[i].className="Form_HopVanBan1";
			document.forms[tenform].elements[i].focus();
			return false;
		};
	}
	var newwin=window.open("",tg, "width=400,height=200,left=300,top=50,status=yes,toolbar=no,menubar=no");
	newwin.focus();
	return true;
}

function sm_chung(tenform){

	for( i=0;i<document.forms[tenform].length;i++){
		if(document.forms[tenform].elements[i].value==""){
			alert("Phai nhap du thong tin");
			document.forms[tenform].elements[i].className="Form_HopVanBan1";
			document.forms[tenform].elements[i].focus();
			return false;
		};
	}	
	return true;


}

function open_window(){
	newwin=open("remote.php", "remote", "width=400,height=150,left=300,top=50");
	newwin.focus()
}
function load_img(idvung,path,width,height){	
		var_vung_anh = document.getElementById(idvung);
		if(width==null||height==null){
			var_vung_anh.innerHTML = "<image src ='"+ path +"'>";
		}else{
			var_vung_anh.innerHTML = "<image src ='"+ path +"' width='" + width + "' height='"+ height +"'>";
		}	
}	

