var article_page_num_param_name = "pn";

function isNull(formName,objectName,message){
	formObject = eval("document." + formName + "." + objectName);
	if (formObject.value == ""){
		alert(message);
		formObject.focus();
		return true;
	}
	return false;
}

function searchManage(searchStr,operType,name,value){
	var searchArray = new Array();
	var returnStr = "";		
	if (searchStr != ""){
		searchArray = searchStr.split("&");	
		
		for(var i = 0 ; i < searchArray.length ; i ++){
			if (searchArray[i] != ""){
				var paramArray = new Array();
				paramArray = searchArray[i].split("=");		
				if (paramArray[0] == name){
					searchArray.splice(i,1);
					i--;
				}
			}
		}
	}
	
	if (operType == "add"){
		returnStr = name +  "=" + value;
	}
	
	if (operType == "remove"){
	}
	
	
	for(var j = 0; j < searchArray.length; j++){
		if (searchArray[j] != ""){
			returnStr += "&" + searchArray[j];
		}
	}

	return returnStr;
	
}

function getSearchValue(searchStrParam,name){
	if (searchStrParam == "URL"){
		searchStr = this.location.search.substr(1);
	}else{
		searchStr = searchStrParam;
	}
	
	
	var searchArray = new Array();
	var returnStr = "";		
	if (searchStr != ""){
		searchArray = searchStr.split("&");	
		
		for(var i = 0 ; i < searchArray.length ; i ++){
			if (searchArray[i] != ""){
				var paramArray = new Array();
				paramArray = searchArray[i].split("=");		
				if (paramArray[0] == name){
					returnStr = paramArray[1];
					return returnStr;
				}
			}
		}
	}
	
	return "";
}


function addSearch(searchStr,name,value){
	if (searchStr == "URL"){
		return searchManage(this.location.search.substr(1),"add",name,value);
	}
	return searchManage(searchStr,"add",name,value);	
}




function removeSearch(searchStr,name){
	if (searchStr == "URL"){
		return searchManage(this.location.search.substr(1),"remove",name,"");	
	}
	return searchManage(searchStr,"remove",name,"");	
}


function pageJump(){
	var e = event.srcElement;
	this.location.search = addSearch("URL",article_page_num_param_name,e.value);
}

function unselectall(checkBoxID){
	var selectAllObj = document.getElementById(checkBoxID);
    if(selectAllObj.checked){
 		selectAllObj.checked = selectAllObj.checked&0;
    }
}

function checkAll(form){
  var eSource = window.event.srcElement;
  for (var i=0;i<form.elements.length;i++){
    var e = form.elements[i];
    if (e.Name != eSource.name && e.disabled == false)
       e.checked = eSource.checked;
    }
}

function checkAllForCheckBox(element){
	var eSource = window.event.srcElement;
	if (element.Name != eSource.name && element.disabled == false)
       element.checked = eSource.checked;
	   
	for (var i=0;i<element.length;i++){
    var e = element[i];
    if (e.Name != eSource.name && e.disabled == false)
       e.checked = eSource.checked;
    }
}



function displayCtrl(displayElement,hideElement){
	if(displayElement != ""){
		var displayObj = document.getElementById(displayElement);
		displayObj.style.display = "";
	}
	
	if(hideElement != ""){
		var hideObj = document.getElementById(hideElement);
		hideObj.style.display = "none";
	}
	
	
}


function first_page(){
	this.location.search = addSearch("URL",article_page_num_param_name,1);
}


function next_page(pageCount){
	var pn = getSearchValue("URL",article_page_num_param_name);
	if (pn == "" || pn == null){
		var nextPage = 2;
	}else{
		var nextPage = parseInt(pn) + 1;
	}
	
	
	
	if (nextPage > pageCount){
		nextPage = pageCount;
	}
	
	this.location.search = addSearch("URL",article_page_num_param_name,nextPage);
	
}

function prev_page(){
	var pn = getSearchValue("URL",article_page_num_param_name);
	if (pn == "" || pn == null){
		first_page();
		return;
	}
	
	var nextPage = parseInt(pn) - 1;
	
	if (nextPage < 1){
		nextPage = 1;
	}
	
	this.location.search = addSearch("URL",article_page_num_param_name,nextPage);
}

function last_page(pageCount){
	this.location.search = addSearch("URL",article_page_num_param_name,pageCount);
}


function dataFilter(search_param_name){
	var e = event.srcElement;
	var tmp = removeSearch("URL",search_param_name);
	this.location.search = addSearch(tmp,search_param_name,e.value);
}



function addURLParam(paramName,paramValue){
	var tmp = removeSearch("URL",paramName);
	this.location.search = addSearch(tmp,paramName,paramValue);
}



function cTrim(sInputString,iType){
	var sTmpStr = ' '
	var i = -1

	if(iType == 0 || iType == 1){
		while(sTmpStr == ' '){
			++i
			sTmpStr = sInputString.substr(i,1)
		}
      		sInputString = sInputString.substring(i)
	}

	if(iType == 0 || iType == 2){
		sTmpStr = ' '
		i = sInputString.length
		while(sTmpStr == ' '){
			--i
			sTmpStr = sInputString.substr(i,1)
		}
		sInputString = sInputString.substring(0,i+1)
	}
	return sInputString
}


function actionConfirm(text,actionUrl){
	if (! window.confirm(text)){
		return;
	}
	
}



function openModalDialog(theURL,winName,features) { 
  window.showModalDialog(theURL,'',features+"center=yes;middle=yes ;help=no;status=no;scroll=no");
}

function openModalDialog(theURL,winName,features,scrollState) { 
  window.showModalDialog(theURL,'',features+"center=yes;middle=yes ;help=no;status=no;scroll=" + scrollState);
}

function openModalDialog2(theURL,w,h,scrollState) { 
  window.showModalDialog(theURL,'',"dialogWidth:"+w+"pt;dialogHeight:"+h+"pt;center=yes;middle=yes ;help=no;status=no;scroll=" + scrollState);
}

//居中打开某窗口
function openWindow(url,w,h){
	window.open(url,"","scrollbars=yes,width="+w+",height="+h+",left="+(window.screen.width-w)/2+",top="+(window.screen.height-h-50)/2+'"')
}



//写cookies函数
function SetCookie(name,value,Days){	//两个参数，一个是cookie的名子，一个是值
    var exp  = new Date();    //new Date("December 31, 9998");
    exp.setTime(exp.getTime() + Days*24*60*60*1000);
    document.cookie = name + "="+ escape (value) + ";expires=" + exp.toGMTString();
}

//取cookies函数     
function getCookie(name){	   
    var arr = document.cookie.match(new RegExp("(^| )"+name+"=([^;]*)(;|$)"));
     if(arr != null) return unescape(arr[2]); return null;
}

//删除cookie
function delCookie(name){	
    var exp = new Date();
    exp.setTime(exp.getTime() - 1);
    var cval=getCookie(name);
    if(cval!=null) document.cookie= name + "="+cval+";expires="+exp.toGMTString();
}