define(function(require){
	var $ = require('jquery');
    require('uriTemplate')($);
    require('validation')($);
    require('dialog')($);
    var IFA = require('util');
	require("../../../styles/cim/jquery-ui-1.8.14.custom.css");
	require('../../../styles/cim/validation.css');
	require('../../../js/seaJsExtends/autoComplete.js')($);
	require('../../../styles/cim/autoComplete.css');
	$(function(){	
		$('#newColorForm').validate({
			rules:{
				name:{
							required:true,
							rangelength:[0,20],
							regex: /^[a-zA-Z0-9\u4e00-\u9fa5\s_)(-\/\'&]+$/,
							nameCheck:true
				},
				codeValue:{
							required:true,
							rangelength:[0,20]
				},
				description:{
							rangelength:[0,100]
					}
			
			}
		});

		$("#saveBt").click(function(){
			if($('#newColorForm').valid()){	
			    var codeTypeName = $("#codeTypeName").val();
			    var urlval = $("#saveUrl").val();
				var urlStr = new $.Template(urlval);
				var urlParam = {"codeTypeName":codeTypeName};
				var urlStr = urlStr.expand(urlParam);
				$("#newcolorForm").attr("action",urlStr);
				$("#newColorForm").submit();
			}else{
				$.msg.alert(i18n["Page.Dialog.content.inputError"]);
			}
			 return false;
		});
		$("#cancelBt").click(function(){
		    var url = $("#cancelUrl").val();
			window.location=url;
		});
	});
	
	$.validator.addMethod("nameCheck",function(value,element,param){  
	    var name = $("#name").val();
	    var codeTypeName = $("#codeTypeName").val();
	    var url = $('#codeCheckUrl').val();
		var urlStr = new $.Template(url);
		var urlParam = {"name":name,"codeTypeName":codeTypeName};
		var urlStr = urlStr.expand(urlParam);
	    if(name!="name"){
	    	flag = true;
	    	$.ajax({
	    		  url:urlStr+".json",
				  async: false,
				  success: function(data){
	   		      if(data.flag=="dataRepeat")
						flag=false;
		    		else
			    		flag=true;
		   		  }
	   		});
	   	 return flag;
	    }
	    }, i18n["Validation.nameRepeat"]);

	$(function init(){
		//$("#save").click(function(){submitForm();});
		var messageKey = $("#messageKey").val();
		var messages = $("#message").val();
		if(messages==messageKey)
		$.msg.alert(i18n["Page.title.dialogshow.title"],i18n["Page.savesuccessfully.dialogshow.title"],{
			buttons: IFA.generateJson(i18n["Entity.Operation.ok"], function() {
				var message = messages;
				if(message!=''){
					if(message==messageKey){
					    var url = $("#cancelUrl").val();
						window.location=url;
					}
				}
			$(this).dialog("close");
			})});
		
	});
});