define(function(require){
	var $ = require('jquery');
	var IFA=require('util');
	require('dialog')($);
	require('uriTemplate')($);
	//require('../paymethod/generatorForEditting.js');
	require('../../../styles/cim/jquery-ui-1.8.14.custom.css');
	var contextPath = $("#contextPath").val();
		//返回按钮
		$("#returnButton").bind("click",function(){
			if($("#flow").val()){
				location.href=$("#flowUrl").val();
			}else{
				location.href=$("#indexUrl").val();
			}
		});
		//resHistory审计历史
		$("#resHistory").bind("click",function(){
			var urlString=new $.Template($("#searchOrderBySegmentIndex").val());
			var urlParams={"segmentNo":$("#segmentNo").val(),
					      "personId":$("#personId").val()};
			var url=urlString.expand(urlParams);
			resHistory(url);
		});
		 
		function resHistory(url){
			window.open(url,window);
		}
				
				//通知按钮
		$("#manuallyNotification").bind("click",function(){
					var urlString=new $.Template($("#notificationUrl").val());
					var urlParams={"resId":$("#id").val()};
					var url=urlString.expand(urlParams);
					location.href = url;
				});

	//公司图片显示
	$("#companyImageHandlerShow").bind("click",companyImageFun);
	//公司价格链接显示图片
	function companyImageFun(){
		$("#imageDrag").removeAttr("style");
		$("#companyImage").dialog({title:i18n["JS.workOrder.companyPricePic"], height:420,width:330, 
			modal: false,closeOnEscape:true,overlay: { opacity: 0.5, background: 'black',overflow:'auto'},
			buttons:{
			'ReDo':function(){$("#imageDrag").removeAttr("style");},	
			'Zoom In':function(){
				$("#imageDrag").css({
				      width: function(index, value) {
				        return parseFloat(value) * 1.2;
				      }, 
				      height: function(index, value) {
				        return parseFloat(value) * 1.2;
				      }});
			},
			'Zoom Out':function(){
				$("#imageDrag").css({
				      width: function(index, value) {
				        return parseFloat(value) / 1.2;
				      }, 
				      height: function(index, value) {
				        return parseFloat(value) / 1.2;
				      }});
			},
			'Close':function(){$(this).dialog('close');}
			}}); 
	}
	
	function hve_display(tId,iId){//显示隐藏程序
		var t_id = tId;//表格ID
		var i_id = iId;//图片ID
		var on_img=contextPath+"/images/btn_arrow_down.gif";//打开时图片
		var off_img=contextPath+"/images/btn_arrow_right.gif";//隐藏时图片
		if (t_id.style.display == "none") {//如果为隐藏状态
			t_id.style.display="";//切换为显示状态
			i_id.src=on_img;//换图
		}
		else{
			t_id.style.display="none";//切换为隐藏状态
			i_id.src=off_img;//换图
		}
		}
	
	$(".tableRes h2").bind("click",function(){
		var tal = $(this).parents(".tableRes").next(".tableRes");
		var img = $(this).children();
		hve_display(tal.get(0),img.get(0));
	});

	$("#allOpen").bind("click",function(){
		var tal = $("table[name='table']");
		var img = $("img[name='img']");
		var i = 0;
		$.each(tal,function(){
			hve_open(tal.get(i),img.get(i));
			i++;
		});
	});
	
	$("#allClose").bind("click",function(){
		var tal = $("table[name='table']");
		var img = $("img[name='img']");
		var i = 0;
		$.each(tal,function(){
			hve_close(tal.get(i),img.get(i));
			i++;
		});
	});
	function hve_open(tId,iId){//显示隐藏程序
		var t_id = tId;//表格ID
		var i_id = iId;//图片ID
		var on_img=contextPath+"/images/btn_arrow_down.gif";//打开时图片
			t_id.style.display="";//切换为显示状态
			i_id.src=on_img;//换图
		}
	
	function hve_close(tId,iId){//显示隐藏程序
		var t_id = tId;//表格ID
		var i_id = iId;//图片ID
		var off_img=contextPath+"/images/btn_arrow_right.gif";//隐藏时图片
			t_id.style.display="none";//切换为隐藏状态
			i_id.src=off_img;//换图
		}
	
});