/**
 * @file_name publicFunction.js
 * @file_to *.jsp
 * @explain 页面脚本公用方法
 * @author zhaohui
 * @date 2010-01-23
 */

// 获取URL 
var localObj_common = window.location;
// 
var pathName_common = localObj_common.pathname;
//
var contextPath_common = "/" + pathName_common.split("/")[1];

function setValue_public(element,value){
	document.getElementById(element).value = value;
}

function getValue_public(element){
	return	document.getElementById(element).value;
}

function getElementById_public(elementId){
	return document.getElementById(elementId);
}

function getElementsByTagName_public(elementName){
	return document.getElementsByTagName(elementName);
}

/**
 * 设置元素获取焦点
 * @param elementId 元素ID
 */
function setFocus_public(elementId){ 
	jQuery("#" + elementId).focus();
}

/**
 * 判断数据(相当于equals)
 * @param data 要判断的数据
 */
function equals_public(data){ 
	try{
		if((data == null) || (data == "undefined")
				||( data == undefined )
			//	||(data == "" )
				){
			return false;
		}
		return true;
	}catch(ex){
		alert('判断数据(相当于equals)异常:' + ex.message);
		return false;
	}
}

// 判断radio或checkbox按钮是否被选中
function isChecked_public(elementId){
	if(document.getElementById(elementId).checked == true){
		return true;
	}else{
		return false;
	}
}

// 设置按钮被选中
function setChecked_public(elementId){
	document.getElementById(elementId).checked
}

/**
 * 设置TableGride
 * @param tbodyId tbody's id 
 * @param tableId table's id
 * @param cellFuncs 数组
 * @param data  数据
 * @param isTableSorter 是否显示为可排序表格
 * @param isRemove 是否清空表格
 */
function setTableGride_public(tbodyId,tableId,cellFuncs,data,isTableSorter,isRemove){ 
	if(isRemove){
		// 清除
		dwr.util.removeAllRows(tbodyId);		
	}
	// 动态添加
	dwr.util.addRows(tbodyId,data,cellFuncs,{rowCreator:function(options){
	var row = document.createElement("tr");
    //row.id = row_count ;
	return row;
	},cellCreator:function(options){
	var td = document.createElement("td");
	return td;
	},escapeHtml:false});
	//jQuery("#tab").tablesorter({sortList:[[0,0],[2,1]], widgets: ['zebra']});
	if(isTableSorter){
		jQuery("#" + tableId).tablesorter({widgets: ['zebra']});
	}
}
/**
 * 填充下拉列表
 * @param element 元素
 * @param value 值
 * @param isRemove 是否清空
 * @return
 */
function fillSelect_public(element,value,isRemove){ 
	if(isRemove){
		dwr.util.removeAllOptions(element);
	}
	dwr.util.addOptions(element,value);
}
/**
 * 清空下拉列表
 * @param element 元素
 * @return
 */
function removeSelect_public(element){
	dwr.util.removeAllOptions(element);
}

/**
 * 设置InnerHTML
 * @param elementId 元素ID
 * @param textValue 值
 * @return
 */
function setInnerHTML_public(elementId,textValue){
	document.getElementById(elementId).innerHTML = textValue;
}

/** 
 * 获取元素的innerHTML
 * @param elementId 元素ID
 * @param textValue 文本
 */
function getInnerHTML_public(elementId){
	try{
	  return document.getElementById(elementId).innerHTML;
		                                            
	}catch(ex){
		//alert('设置元素的innerHTML文本异常:' + ex.message);
	}
}
/** 
 * 获取元素的innerText
 * @param elementId 元素ID
 * @param textValue 文本
 */
function getInnerText_public(elementId){
	try{
	  return document.getElementById(elementId).innerText;
		                                            
	}catch(ex){
		//alert('设置元素的innerHTML文本异常:' + ex.message);
	}
}

/** 
 * 设置元素的innerText
 * @param elementId 元素ID
 * @param textValue 文本
 */
function setInnerText_public(elementId,value){
	try{
	  document.getElementById(elementId).innerText = value;
		                                            
	}catch(ex){
		//alert('设置元素的innerText文本异常:' + ex.message);
	}
}

/**
 * 动态添加层之jQuery().appendTo()
 * @param  element 所要添加的元素
 * @param container 所要添加到的容器
 */
function appendTo_public(element,container){ 
	jQuery(element).appendTo("#" + container);
}

/**
 * 动态添加层之jQuery().prependTo 
 * @param  element 所要添加的元素
 * @param  container 所要添加到的容器
 */ 
function prependTo_public(element,container){
	jQuery(element).prependTo("#" + container);
}

/**
 * 动态移除之jQuery().remove()
 * @param  element 所要移除的元素
 */
function remove_public(element){
	jQuery("#" + element).remove();
}

/**
 * 删除该元素集合中的子结点
 * @param element 元素id
 */
function deleteAllElementsById_public(element){
	jQuery("#" + element).empty();
}

/**
 * 设置元素可见
 * @param  element 元素
 */
function abledElement_public(element){ 
	document.getElementById(element).style.display = "";
}

/**
 * 设置元素不可见
 * @param  element 元素
 */ 
function disabledElement_public(element){ 
	document.getElementById(element).style.display = "none";
}
// 获取日期,格式为:年月日 星期
function getDate_public(){
	var result = "";
	var day="";
	var month="";
	var ampm="";
	var ampmhour="";
	var myweekday="";
	var year="";
	mydate=new Date();
	myweekday=mydate.getDay();
	mymonth=mydate.getMonth()+1;
	myday= mydate.getDate();
	myyear= mydate.getYear();
	year=(myyear > 200) ? myyear : 1900 + myyear;
	if(myweekday == 0)
	weekday=" 星期日 ";
	else if(myweekday == 1)
	weekday=" 星期一 ";
	else if(myweekday == 2)
	weekday=" 星期二 ";
	else if(myweekday == 3)
	weekday=" 星期三 ";
	else if(myweekday == 4)
	weekday=" 星期四 ";
	else if(myweekday == 5)
	weekday=" 星期五 ";
	else if(myweekday == 6)
	weekday=" 星期六 ";
	result += year+"年"+mymonth+"月"+myday+"日 "+weekday;
	return result;
	
}
