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');
	$(function(){

		$("#savaHref").click(function(){
			if($('#bookingChannel').valid()){		
				var url=$("#saveUrl").val().trim();
				$("#bookingChannel").attr('action',url);
				$("#bookingChannel").submit();
			}else{
				$.msg.alert(i18n["Page.Dialog.content.inputError"]);
			}
			 return false;
		});
		$("#cancel").click(function(){
      	  var urlstr = $("#cancelUrl").val().trim();
         	  location.href = urlstr;
		});
	});
	
	$("#bookingChannel").validate({
		rules:{
			name:{
			    required:true,
			    maxlength:100,
			    VerificationBookingChannelName:true
			},
			remarks:{
				maxlength:200
			}
		}
	});
	
	$.validator.addMethod("VerificationBookingChannelName",function(value,element,param){
		var name = $("#name").val();
		var flag = "";
			var urlStr = $("#uniqueUrl").val();
		    $.ajax({
		    	type:"POST",
		    	url:urlStr+".json",
				async:false,
		    	data:{"name":name},
			    success: function(response,ioArgs){
		   		    flag = response.status;
			   	},error:function(response,ioArgs){
			   		alert(ioArgs);
			   	}
		   	});
		return flag;
	},i18n["Validation.bookingChannel.norepeat"]);
});