function LoadPreviewImage(filename, preview){
	var maxWidth = 200;
	var maxHeight = 150;
	var par = window.parent.document;
	
  var Img = new Image();
  Img.src = filename;
  PreviewImg = par.getElementById(preview).childNodes[0];
	var scaleX = maxWidth / Img.width;
	var scaleY = maxHeight / Img.height;
	var scale = (scaleX < scaleY ? scaleX : scaleY);
  PreviewImg.src = Img.src;
//    PreviewImg.width = Img.width * scale;
//    PreviewImg.height = Img.height * scale;
  PreviewImg.width = maxWidth;
  PreviewImg.height = maxHeight;
}

function del(id){
	var flag = confirm("確定要刪除這貨品?");
	if(flag == true){
		alert("123");
		window.location.href = "del.php?id="+id;
	}
}

function search_form(form, sch){
	if($$("search_field").value != ""){
		var sch_str = encodeURI($$("search_field").value);
		if(sch){
			form.action = "index.php?mode=2&search="+sch_str;
		}else{
			form.action = "index.php?search="+sch_str;
		}
		return true;
	}else{
		var msg = "請輸入關鍵字!";
		alertBOX(msg,'300',true);
		return false;
	}
}

function validChar(obj){
	if(obj)	{
		var str = obj.value;
		var filter = /[\#\$\%\^\&\*\@\!\?\.\-\+\=\|\{\}\'\~\`\(\)\<\>\,\;\:\\\"\[\]]/ 
		if (str.match(filter)) 
		{
			alert("你輸入的名稱有不正確的字符!");
		}
	}
}
