//处理CSS中的表达式的逻辑处理
$(document).ready( function() {
	/* 1. table的如下css的处理：
		 #m: expression(this.cellSpacing='0px');
		 #m1:expression(this.cellPadding='0px');
		 */
		$("table").attr({'cellSpacing':'0px','cellPadding':'0px'});
		$(".merp-right-query-table").attr({'cellSpacing':'5px'});
		$(".merp-right-query-table-spacing-3").attr({'cellSpacing':'2px'});
		
		/*
		 2. .merp-left-menu-table-body-tr{
		*/
		
		$(".merp-left-menu-table-body-tr").hover( function() {
			$(this).css( {
				'backgroundColor' :'#ffec92',
				'borderColor' :'#e6bc49',
				'borderStyle' :'solid',
				'borderWidth' :'1px'
			});
		}, function() {
			$(this).css( {
				'backgroundColor' :'#eef9e2',
				'borderStyle' :'none',
				'borderWidth' :'0px'
			});
		});
		/*
		 3 .merp-right-list-table-body-tr{ 
		 }*/
		$(".merp-right-list-table-body-tr").hover( function() {
			$(this).css( {
				'backgroundColor' :'#feffbd'
			});
		}, function() {
			$(this).css( {
				'backgroundColor' :'#ffffff'
			});
		});
		/*4. */
		$(".merp-login-input-text, .merp-login-input-text-mod, .merp-right-input-text-page, .merp-right-input-text-query, .merp-right-input-text-common, .merp-right-input-text-common-max, .merp-right-input-text-common-readonly, .merp-right-input-text-date-readonly, .merp-right-input-text-common-disable, .merp-right-input-text-date").hover( function() {
			$(this).css( {
				'borderColor' :'#6887a4'
			});
		}, function() {
			$(this).css( {
				'borderColor' :'#97b0c5'
			});
		});
		
		/*
		 * 按钮
		 
		 * */
		$(".merp-right-input-button-query, .merp-right-contact-input-button-operation, .merp-right-input-button-pages, .merp-right-input-button-operation, .merp-right-input-button-operation-4, .merp-right-input-button-operation-4,.merp-right-input-button-operation-5, .merp-right-input-button-operation-6, .merp-right-input-button-query-m, .merp-right-input-button-pages-m, .merp-right-input-button-operation-m, .merp-right-input-button-operation-4-m, .merp-right-input-button-operation-5-m, .merp-right-input-button-operation-6-m").hover( function() {
			$(this).css( {
				'borderColor':'e7ab38',
				'backgroundColor' :'#ffeeb1'
			});
		}, function() {
			$(this).css( {
				'borderColor':'e4f7c8',
				'backgroundColor' :'#bcd19e'
			});
		});
		
		/*
		 *  
		 * 分页
		 * */
		$(".merp-a-page").hover( function() {
			$(this).css( {
				'textDecoration':'underline',
				'color':'#325203'
			});
		}, function() {
			$(this).css( {
				'textDecoration':'none',
				'color' :'#000000'
			});
		});
		/*
		 * .merp-a-help
		 * 
		 * */
		$(".merp-a-help").hover( function() {
			$(this).css( { 
				'color':'#6fb007'
			});
		}, function() {
			$(this).css( { 
				'color' :'#6F6F6F'
			});
		});
		/*
		 * .merp-a-data
		 * */
		$(".merp-a-data").hover( function() {
			$(this).css( { 
				'textDecoration':'underline'
			});
		}, function() {
			$(this).css( { 
				'textDecoration':'none'
			});
		});
		
		
		
	});


function nextFocus(e)
{
	var keyValue=0;
	var srcObj=null;
	if(!document.all){
		keyValue=e.which;
		srcObj=e.target;
	}else{
		keyValue=e.keyCode;
		srcObj=e.srcElement;
	}
	if(keyValue==13)
	{
		var inputs=document.getElementsByTagName('input');
		var i=0;
		for(i=0;i<inputs.length;i++){
			if(inputs[i]==srcObj){
				if((i+1)<inputs.length){
					inputs[i+1].focus();
					return true;
				}
			}
		}
		
	}
}

(function(jQuery){

/**
 @descripton 复选框全选操作（选中所有的复选项） 
 @param checkSelector
 	 checkSelector为定义的checkbox的全选操作，假如有一个复选框定义的name="checkbox" 
 	 则checkSelector的值应该为 "[name='checkbox']"
 @author gjl
 @date 2009-02-16
*/
this.checkAll=function(checkSelctor){
	$(checkSelctor).attr("checked",'true');
};

/**
@description 检查复选框中是否有被选中的项
@param checkSelector
@author gjl
@date 2009-02-20
*/

/**
 复选框取消选择操作（所有的复选项都不被选中）
 @param checkSelector
 	checkSelector为定义的checkbox的全选操作，假如有一个复选框定义的name="checkbox"
 	则 checkSelector的值应该为 "[name='checkbox']"
 @author gjl
 @date 2009-02-16
*/	
this.checkNone=function(checkSelctor){
	$(checkSelctor).removeAttr("checked");
};
	
/**
@description 复选框反选操作（选择没有选中的，弃选选中的）
@param checkSelector
	checkSelector为定义的checkbox的全选操作，假如有一个复选框定义的name="checkbox"
 	则 checkSelector的值应该为 "[name='checkbox']"
@author gjl
@date 2009-02-16
*/
this.checkReserve=function(checkSelector){
	$(checkSelector).each(function(){
		if($(this).attr("checked")){
			$(this).removeAttr("checked");
		}else{
			$(this).attr("checked",'true');
		}
	})
};

/**
@description 判断复选框是否有选中的选项
@param checkSelector
	checkSelector为定义的checkbox的全选操作，假如有一个复选框定义的name="checkbox"
 	则 checkSelector的值应该为 "[name='checkbox']"
@author gjl
@date 2009-02-16
*/
this.hasChecked=function(checkSelector){
	var hasChecks = false;
	$(checkSelector).each(function(){
		if($(this).attr("checked")){
			hasChecks = true;
		}
	})
	return hasChecks;
};

/**
@description 判断复选框是否有唯一一个选中的项
@param checkSelector
	checkSelector为定义的checkbox的全选操作，假如有一个复选框定义的name="checkbox"
 	则 checkSelector的值应该为 "[name='checkbox']"
@author gjl
@date 2009-02-16
*/
this.hasCheckOne=function(checkSelector){
	var hasChecks = false;
	var onlyOne = 0 ;
	$(checkSelector).each(function(){
		if($(this).attr("checked")){
			onlyOne ++ ;
		}
	})
	if(onlyOne == 1){
		hasChecks = true;
	}
	return hasChecks;
};

/**
@description 获取复选框中所有被选中的项
@param checkSelector
	checkSelector为定义的checkbox的全选操作，假如有一个复选框定义的name="checkbox"
 	则 checkSelector的值应该为 "[name='checkbox']"
@author gjl
@date 2009-02-16
*/
this.getChecked=function(checkSelector){
	var result = new Array();
	var count = 0;
	$(checkSelector).each(function(){
		if($(this).attr("checked")){
			result[count] = $(this);
			count ++ ;
		}
	})
	return result;
};


/**
@description 删除选中的表格行操作
@param rowSelector
	rowSelector的定义为复选框选中的某一行，通常为 "input:checked"
*/
this.deleteRow = function(rowSelector){		
	$(rowSelector).parents("tr").remove();
};
	
/**
@description 打开新的窗口
@author gjl
@date 2009-02-16
*/
this.openNewWindow=function(url,title,height, width, left, top){
	var windowFeature = "directories=no,status=yes,toolbar=no,menubar=no,scrollbars=yes,status=no,resizable=yes";
	 if (height > 0) {
	    windowFeature += ",height=" + height;
    }
    if (width > 0) {
	    windowFeature += ",width=" + width;
    }
    if (left >= 0) {
	    windowFeature += ",left=" + left;
    }
    if (top >= 0) {
    	 windowFeature += ",top=" + top;
    }	
	window.open(url,title,windowFeature);
};

/**
@description 关闭窗口
@author gjl
@dete 2009-02-16
*/
this.closeWindow=function(){
	javascript:window.close();
};

/**
@description 关闭窗口并且刷新父窗口
@author gjl
@date 2009-02-16
*/
this.refreshParentAndClose=function(){
	opener.location.reload();
	javascript:window.close();
};

/**
@description 计算两个日期的月份差，2009-02-01与2009-03-01月份差为1，但是2009-02-01与2009-03-02月份差为2
@author gjl
@date 2009-02-20
*/
this.monthDifferOfDates=function(startDate, endDate){
	var startArray = new Array();
	startArray = startDate.split("-");	
	if(startArray.length <3){
		return -1 ;
	}
	var endArray = new Array();
	endArray = endDate.split("-");
	if(endArray.lengh<3){
		return -1;
	}
	var start = new Date(startArray[0],startArray[1]-1,startArray[2]);
	var end = new Date(endArray[0],endArray[1]-1,endArray[2]);
	var monthDiffer = 0 ;
	if(start >= end){
		monthDiffer = 12*(start.getYear() - end.getYear()) + start.getMonth()-end.getMonth();
		if(start.getDate() > end.getDate()){
			monthDiffer ++ ;
		}
		return monthDiffer;
	}else{
		monthDiffer = 12*(end.getYear() - start.getYear()) + end.getMonth() - start.getMonth();
		if(end.getDate() > start.getDate()){
			monthDiffer ++ ;
		}
		return monthDiffer;
	}
};

/**
@description 修改表单的action属性，并提交表单
@param formSelector 表单的选择器，通常为form，destAction要修改的action属性值
@author gjl
@date 2009-02-24
*/
this.changeFormActionAndSubmit=function(formSelector, destAction){
	var form = $(formSelector);
	$("[name=action]").val(destAction);
	form.submit();
};

this.getRadioCheck=function(){
	var selected = null;
	$("input[type='radio']").each(function(){
		if($(this).attr("checked")){
			selected = $(this).val();
		}
	})
	return selected;
};

})(jQuery);

