/**
 * @file_name util.js
 * @file_to *.jsp
 * @explain 页面脚本公用方法
 * @author zhaohui
 * @date 2010-01-23
 */

function getHost_util(){
	   var host = window.location.hostname;   
	   var port = window.location.port;   
	   domainName = "http://" + host;   
	   if(port != ""){   
	         domainName += ":" + port;   
	   } 
	   //alert(domainName);
	   return domainName; 
}
//关闭窗口
function closeWindow_util(){
	window.close();
}

/**
 *  设置到收藏夹
 *  @param url 网站地址
 *  @param name 网站名称
 */

function setFavorite_util(name){
	var url = getHost_util();
	try{
		window.external.addFavorite(url,name);
	}catch(ex){
		alert(ex.message);
	}
}
/**
 * 设置为主页
 * @param element 元素
 * @param url 网页地址
 * @return
 */
function setHomePage_util(element,url){
	try{
		var url = getHost_util();
		element.style.behavior='url(#default#homepage)'; 
		element.setHomePage(url);
	}catch(ex){
		alert(ex.message);
	}
}
/**
 * 页面打印
 * @param isView 是否预览
 */
function printsetup_util(isView){
	if(isView){
		web.execwb(7,1); //打印页面预览	
	}else{
		web.execwb(8,1); // 打印页面设置	
	}
} 
// 复制本文链接和标题到剪贴板 [ IE ]
function copyToClipBoard()  { 
    var clipBoardContent=""; 
    clipBoardContent+=document.title; 
    clipBoardContent+="\n"; 
    clipBoardContent+=this.location.href; 
    window.clipboardData.setData("Text",clipBoardContent); 
    alert("复制成功，粘贴即可！"); 
}

 
function setValue_util(element,value){
	document.getElementById(element).value = value;
}

function getValue_util(element){
	return	document.getElementById(element).value;
}

function getElementById_util(elementId){
	return document.getElementById(elementId);
}

function getElementsByTagName_util(elementName){
	return document.getElementsByTagName(elementName);
}

/**
 * 设置元素获取焦点
 * @param elementId 元素ID
 */
function setFocus_util(elementId){ 
	jQuery("#" + elementId).focus();
}

/**
 * 判断数据(相当于equals)
 * @param data 要判断的数据
 */
function equals_util(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_util(elementId){
	if(document.getElementById(elementId).checked == true){
		return true;
	}else{
		return false;
	}
}

// 设置按钮被选中
function setChecked_util(elementId){
	document.getElementById(elementId).checked = true;
}
//设置按钮未被选中
function setUnchecked_util(elementId){
	document.getElementById(elementId).checked = false;
}
/**
 * 设置TableGride
 * @param tbodyId tbody's id 
 * @param tableId table's id
 * @param cellFuncs 数组
 * @param data  数据
 * @param isTableSorter 是否显示为可排序表格
 * @param isRemove 是否清空表格
 */
function setTableGride_util(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});
	if(isTableSorter){
		jQuery("#" + tableId).tablesorter({widgets: ['zebra']});
	}
}
/**
 * 填充下拉列表
 * @param element 元素
 * @param value 值
 * @param isRemove 是否清空
 * @return
 */
function fillSelect_util(element,value,isRemove){ 
	if(isRemove){
		dwr.util.removeAllOptions(element);
	}
	dwr.util.addOptions(element,value);
}
/**
 * 对象数组模式：(指定text和value值)：
 * @param element 元素
 * @param value 值
 * @param valueProp value属性值
 * @param textProp  text属性值
 * @param isRemove 是否清空
 * dwr.util.addOptions(selectid, array, valueprop, textprop)
 * 
 */
function fillSelectWithProperty_util(element,value,valueProp,
		textProp,isRemove){
	if(isRemove){
		dwr.util.removeAllOptions(element);
	}
	dwr.util.addOptions(element,value,valueProp,textProp);
}
/**
 * 清空下拉列表
 * @param element 元素
 * @return
 */
function removeSelect_util(element){
	dwr.util.removeAllOptions(element);
}

/**
 * 设置InnerHTML
 * @param elementId 元素ID
 * @param textValue 值
 * @return
 */
function setInnerHTML_util(elementId,textValue){
	document.getElementById(elementId).innerHTML = textValue;
}

/** 
 * 获取元素的innerHTML
 * @param elementId 元素ID
 * @param textValue 文本
 */
function getInnerHTML_util(elementId){
	try{
	  return document.getElementById(elementId).innerHTML;
		                                            
	}catch(ex){
		//alert('设置元素的innerHTML文本异常:' + ex.message);
	}
}
/** 
 * 获取元素的innerHTML
 * @param elementId 元素ID
 * @param textValue 文本
 */
function getInnerText_util(elementId){
	try{
	  return document.getElementById(elementId).innerText;
		                                            
	}catch(ex){
		//alert('设置元素的innerHTML文本异常:' + ex.message);
	}
}
/** 
 * 设置元素的innerHTML
 * @param elementId 元素ID
 * @param value 文本
 */
function setInnerText_util(elementId,value){
	try{
	  document.getElementById(elementId).innerText = value;
		                                            
	}catch(ex){
		//alert('设置元素的innerHTML文本异常:' + ex.message);
	}
}

/**
 * 动态添加层之jQuery().appendTo()
 * @param  element 所要添加的元素
 * @param container 所要添加到的容器
 */
function appendTo_util(element,container){ 
	jQuery(element).appendTo("#" + container);
}

/**
 * 动态添加层之jQuery().prependTo 
 * @param  element 所要添加的元素
 * @param  container 所要添加到的容器
 */ 
function prependTo_util(element,container){
	jQuery(element).prependTo("#" + container);
}

/**
 * 动态添加层之jQuery().prependTo 
 * @param  element 所要添加的元素
 * @param  container 所要添加到的容器
 */ 
function insertAfter_util(element,container){
	jQuery(element).insertAfter("#" + container);
}

/**
 * 动态移除之jQuery().remove()
 * @param  element 所要移除的元素
 */
function remove_util(element){
	jQuery("#" + element).remove();
}

/**
 * 删除该元素集合中的子结点
 * @param element 元素id
 */
function deleteAllElementsById_util(element){
	jQuery("#" + element).empty();
}

/**
 * 设置元素可见
 * @param  element 元素
 */
function abledElement_util(element){ 
	document.getElementById(element).style.display = "";
}

/**
 * 设置元素不可见
 * @param  element 元素
 */ 
function disabledElement_util(element){ //alert(element); 
	document.getElementById(element).style.display = "none";
}

// 获取日期,格式为:年月日 星期
function getDate_util(){
	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;
	
}
