define(function(require){
	var $ = require('jquery');
	require('uriTemplate')($);
	require('dialog')($);
	require('datepicker')($);
	require('validation')($);
	require('globalization');
	require('grid')($);
	var IFA = require('util');
	require('../../../styles/cim/jquery-ui-1.8.14.custom.css');
	require('../../../styles/cim/cim-grid.css');
	$(function(){
		check();
		$("#cancel").bind("click",cancel);
		$("#save").bind("click",function(){
			$("#editForm").submit();
		});
		$("#selectall").toggle(function(){
			$("input[ name^='applicable']").attr("checked","checked");
		},function(){
			$("#selectall").removeAttr("checked");
			$("input[name^='applicable']").removeAttr("checked");
		});
	});
	
	//全选
	 function selectall(){
			var check = $(this).attr("checked");
			if(check){
				$("input[type='checkbox']").attr("checked","checked");
			}
	 }
	
	function check(){
		var allpro=$("#allpro :checkbox");
		var  checked=$("#checkedpro :checkbox");
		var discount = $("#hidediscount").val();
			if(discount==1){
				$("input[name=discount]").attr("checked","checked");
			}
		for(var i=0;i<allpro.length;i++){
			for(var j=0;j<checked.length;j++){
				if($(checked[j]).attr("value")==$(allpro[i]).attr("value")){
					$(allpro[i]).attr("checked","checked");
				}
			}
		}
	}
	
	function cancel(){
		var url = $("#cancelUrl").val();
		location.href=url;
	}
	
	$("#editForm").validate({
		rules:{
			rateName:{
				required:true
			},
			ratePrice:{
				required:true,
				regex: /^((([0-9]|\,)*(\.[0-9]{1,2})?)|(([0-9]|\.)*(\,[0-9]{1,2})?)|(([0-9]|\')*((\.|\,)[0-9]{1,2})?))$/
			}
		},
		messages:{
			rateName:{
				required:i18n["Rate.Validate.rateName"]
			},
			ratePrice:{
				required:i18n["Rate.Validate.ratePrice"],
				regex:i18n["Rate.Validate.ratePrice.reg"]
			}
		}
	});
});