function setChecked(checkGroup,checked)
{
	if(!checkGroup) return;
	if(!checkGroup.length)
		checkGroup.checked = checked;
	else
	{
		for(i=0;i<checkGroup.length;i++)
			if(checkGroup[i] && !checkGroup[i].disabled)
				checkGroup[i].checked=checked;
	}
};

function checkSelected(checkGroup,msg)
{
	var seled = false;
	if(checkGroup)
	{
		if(!checkGroup.length)
			seled = checkGroup.checked;
		else
		{
			for(i=0;i<checkGroup.length;i++)
			{
				if(checkGroup[i].checked)
				{
					seled = true;
					break;
				}
			}
		}
	}
	if(!seled)
		alert(msg);
	return seled;
};

function checkList(list,msg)
{
	var seled = false;
	if(list)
	{
		if(list.length > 0)
		{
			if(list.selectedIndex >= 0)
				seled = true;
		}
	}
	if(!seled)
		alert(msg);
	return seled;
};

function checkRadio(radio,msg)
{
	var seled = false;
	if(radio)
	{
		if(!radio.length)
			seled = radio.checked;
		else
		{
			for(i=0;i<radio.length;i++)
			{
				if(radio[i].checked)
				{
					seled = true;
					break;
				}
			}
		}
	}
	if(!seled)
		alert(msg);
	return seled;
};

function paging(url,pageCount,currPage,toPage,pageSize)
{
	if( !pageSize )
		pageSize = 20;
	var prePage = currPage - 1;
	if( prePage < 1 )
		prePage = 1;
	var nextPage = currPage + 1;
	if( nextPage > pageCount )
		nextPage = pageCount;
	if( !toPage || !checkNumber(toPage) )
		toPage = currPage;
	if( toPage < 1 )
		toPage = 1;
	if( toPage > pageCount )
		toPage = pageCount;
	
	var pageStr=
		'<span>共' + pageCount + '页 </span>' +'' +
		'<a class="word1" href="#" onClick="btnoc(\'firstpage\');' + pagingURL(url,1,pageSize) + ';" onMouseOver="btnmo(\'firstpage\');" onMouseOut="MM_nbGroup(\'out\');">' +
		'	<font color="#4f4f4f">首页</font>' +
		'</a> ' +
		'<a href="#" class="word1" onClick="btnoc(\'prepage\');' + pagingURL(url,prePage,pageSize) + ';" onMouseOver="btnmo(\'prepage\');" onMouseOut="MM_nbGroup(\'out\');">' +
		'	上一页' +
		'</a> ' +
		'<a href="#" class="word1" onClick="btnoc(\'nextpage\');' + pagingURL(url,nextPage,pageSize) + ';" onMouseOver="btnmo(\'nextpage\');" onMouseOut="MM_nbGroup(\'out\');">' +
		'	下一页' +
		'</a> ' +
		'<a href="#" class="word1" onClick="btnoc(\'lastpage\');' + pagingURL(url,pageCount,pageSize) + ';" onMouseOver="btnmo(\'lastpage\');" onMouseOut="MM_nbGroup(\'out\');">' +
		'	尾页' +
		'</a> ' +
		'<a href="#" class="word1" onClick="window.location.href = \'' + url + 'page=\'\+document.all(\'toPage\').value\+\'&pagesize=' + pageSize + '\'; ">' +
		'	转至' +
		'	</a> ' +
		'<span><input name="toPage" id="toPage" size="3" class="input1" value="' + toPage + '">' +
		'<input name="currPage" type="hidden" value="' + currPage + '">' +
		'<input name="pageCount" type="hidden" value="' + pageCount + '">' +
		'<input name="pageSize" type="hidden" value="' + pageSize + '">' +
		'页</span>';
		//alert(pageStr);
	return pageStr;
};

function paging0(url,pageCount,currPage,toPage,pageSize)
{
	if( !pageSize )
		pageSize = 20;
	var prePage = currPage - 1;
	if( prePage < 1 )
		prePage = 1;
	var nextPage = currPage + 1;
	if( nextPage > pageCount )
		nextPage = pageCount;
	if( !toPage || !checkNumber(toPage) )
		toPage = currPage;
	if( toPage < 1 )
		toPage = 1;
	if( toPage > pageCount )
		toPage = pageCount;
	
		var pageStr=
		'共' + pageCount + '页 ' + '' +
		'<a class="word1" href="#" onClick="btnoc(\'firstpage\');' + pagingURL0(url,1,pageSize) + ';" onMouseOver="btnmo(\'firstpage\');" onMouseOut="MM_nbGroup(\'out\');">' +
		'	<font color="#4f4f4f">首页</font>' +
		'</a> ' +
		'<a href="#" class="word1" onClick="btnoc(\'prepage\');' + pagingURL0(url,prePage,pageSize) + ';" onMouseOver="btnmo(\'prepage\');" onMouseOut="MM_nbGroup(\'out\');">' +
		'	上一页' +
		'</a> ' +
		'<a href="#" class="word1" onClick="btnoc(\'nextpage\');' + pagingURL0(url,nextPage,pageSize) + ';" onMouseOver="btnmo(\'nextpage\');" onMouseOut="MM_nbGroup(\'out\');">' +
		'	下一页' +
		'</a> ' +
		'<a href="#" class="word1" onClick="btnoc(\'lastpage\');' + pagingURL0(url,pageCount,pageSize) + ';" onMouseOver="btnmo(\'lastpage\');" onMouseOut="MM_nbGroup(\'out\');">' +
		'	尾页' +
		'</a> ' +
		'<a href="#" class="word1" onClick="window.location.href = \'' + url + 'page0=\'\+document.all(\'toPage0\').value\+\'&pagesize0=' + pageSize + '\'; ">' +
		'	转至' +
		'	</a> ' +
		'<input name="toPage0" id="toPage0" size="3" class="input1" value="' + toPage + '">' +
		'<input name="currPage" type="hidden" value="' + currPage + '">' +
		'<input name="pageCount" type="hidden" value="' + pageCount + '">' +
		'<input name="pageSize" type="hidden" value="' + pageSize + '">' +
		'页';
		//alert(pageStr);
	return pageStr;
};

function paging2(url,currPage,pageSize,lastpage)
{
	if( !pageSize )
		pageSize = 10;
	var prePage = currPage - 1;
	if( prePage < 1 )
		prePage = 1;
	var nextPage = currPage + 1;
	if(lastpage<1)lastpage=1;
	//if( nextPage > pageCount )
	//	nextPage = pageCount;
	//if( !toPage || !checkNumber(toPage) )
	//	toPage = currPage;
	//if( toPage < 1 )
	//	toPage = 1;
	//if( toPage > pageCount )
	//	toPage = pageCount;
	var pageStr='<a class="word1" href="#" onClick="btnoc(\'firstpage\');' + pagingURL2(url,1,pageSize,currPage,1) + ';" onMouseOver="btnmo(\'firstpage\');" onMouseOut="MM_nbGroup(\'out\');">' +
		'	<font color="#4f4f4f">首页</font>' +
		'</a> ' +
		'<a href="#" class="word1" onClick="btnoc(\'prepage\');' + pagingURL2(url,prePage,pageSize,currPage,1) + ';" onMouseOver="btnmo(\'prepage\');" onMouseOut="MM_nbGroup(\'out\');">' +
		'	上一页' +
		'</a> ' +
		'<a href="#" class="word1" onClick="btnoc(\'nextpage\');' + pagingURL2(url,nextPage,pageSize,currPage,1) + ';" onMouseOver="btnmo(\'nextpage\');" onMouseOut="MM_nbGroup(\'out\');">' +
		'	下一页' +
		'</a> ' +
		'<a href="#" class="word1" onClick="btnoc(\'lastpage\');' + pagingURL2(url,lastpage,pageSize,currPage,2) + ';" onMouseOver="btnmo(\'lastpage\');" onMouseOut="MM_nbGroup(\'out\');">' +
		'	尾页' +
		'</a> ';
		//alert(pageStr);
	return pageStr;
};
function pagingURL2(url,pageindex,pagecount,currPage,type)
{
 	var lastpage=1;
	if(type==2){
  		$.ajax({
			type: "POST",
			async:false,
			url: "sub_courseware_ajax.jsp?action=getlastpage",
			dataType: "text",
			success: function(result){	
				lastpage=parseInt(jQuery.trim(result));
				pageindex=lastpage;
				if(lastpage<currPage){
					pageindex=currPage;
				}
			}
		});
	}
	var returl = '\'' + url + '?rpp=' + pagecount + '&page=' + pageindex + '\'';
	return 'window.location.href = ' + returl;
};
function pagingURL0(url,page,pageSize)
{
	var returl = '\'' + url + 'page0=' + page + '&pagesize0=' + pageSize + '\'';
	return 'window.location.href = ' + returl;
};

function pagingURL(url,page,pageSize)
{
	var returl = '\'' + url + 'page=' + page + '&pagesize=' + pageSize + '\'';
	return 'window.location.href = ' + returl;
};

function checkNumber(str)
{
	var patrn = /^\d+$/;
	return patrn.test(str);
};

function deleteRow(tabWindow,tableId,rowId)
{
	var tab = tabWindow.document.all(tableId);
	var r = tabWindow.document.all(rowId);
	if( tab == null || r == null )
		return;
	tab.deleteRow(r.rowIndex);
};

function getMonthDayCount(year,month)
{
	if(year == null || month == null)
		return 0;
	switch(month)
	{
	case 2 : 
	{
		if(year % 4 == 0)
			return 29;
		else
			return 28;
	}
	case 1 :
	case 3 :
	case 5 :
	case 7 :
	case 8 :
	case 10 :
	case 12 : return 31;
	default : return 30;
	}
}

function dateSelect(year,yName,defYear,month,mName,defMonth,day,dName,defDay)
{
	var str;
	if(year != null)
	{
		str = '<select name="' + year + '" id="' + year + '">';
		for(i=2005; i<2020; i++)
		{
			if(defYear != null && defYear == i )
				str += '<option value="' + i + '" selected>' + i + '</option>';
			else
				str += '<option value="' + i + '">' + i + '</option>';
		}
		str += '</select>' + yName;
	}
	
	if(month != null)
	{
		str += '<select name="' + month + '" id="' + month + '">';
		for(i=1; i<13; i++)
		{
			if(defMonth != null && defMonth == i )
				str += '<option value="' + i + '" selected>' + i + '</option>';
			else
				str += '<option value="' + i + '">' + i + '</option>';
		}
		str += '</select>' + mName;
	}
	
	if(day != null)
	{
		str += '<select name="' + day + '" id="' + day + '">';		 
		for(i=0; i<=31; i++)
		{
			if(defDay != null && defDay == i )
				str += '<option value="' + i + '" selected>' + i + '</option>';
			else
				str += '<option value="' + i + '">' + i + '</option>';
		}
		str += '</select>' + dName;
	}
	document.write(str);
};

function timeSelect(hour,hName,defHour,minute,mName,defMin,second,sName,defSec)
{
	var str;
	if(hour != null)
	{
		str = '<select name="' + hour + '" id="' + hour + '">';
		for(i=0; i<24; i++)
		{
			if(defHour != null && defHour == i )
				str += '<option value="' + i + '" selected>' + i + '</option>';
			else
				str += '<option value="' + i + '">' + i + '</option>';
		}
		str += '</select>' + hName;
	}
	
	if(minute != null)
	{
		str += '<select name="' + minute + '" id="' + minute + '">';
		for(i=0; i<60; i++)
		{
			if(defMin != null && defMin == i )
				str += '<option value="' + i + '" selected>' + i + '</option>';
			else
				str += '<option value="' + i + '">' + i + '</option>';
		}
		str += '</select>' + mName;
	}
	
	if(second != null)
	{
		str += '<select name="' + second + '" id="' + second + '">';
		for(i=0; i<60; i++)
		{
			if(defSec != null && defSec == i )
				str += '<option value="' + i + '" selected>' + i + '</option>';
			else
				str += '<option value="' + i + '">' + i + '</option>';
		}
		str += '</select>' + sName;
	}
	document.write(str);
};

function getSelectedValue(sel)
{
	selObj = document.getElementById(sel);
	if(selObj != null && selObj.length > 0)
	{
		return selObj.item(selObj.selectedIndex).value;
	}
	else
		return '';
};

function trimString(str)
{
	index = str.lastIndexOf(' ');
	oldIndex = str.length;
	if(index == -1)
		return str;
	else
	{
		while(str.indexOf(' ',index) < oldIndex)
		{
			oldIndex = index;
			index--;
		}
		return str.substring(0, oldIndex);
	}
}

function downnew(docid,title,docType,money){	

var url = '../buy.jsp?docId='+docid+'&title='+title+'&docType='+docType+'&money='+money;
var sDocType = "彩信";
  if (docType==0){
    sDocType = "彩信";
  }else if (docType==1){
    sDocType = "课件";
  }
  if (confirm("您确认要下载该"+sDocType+"？"))
  window.open(url,'下载鉴权','status=no,menubar=no,scrollbars=no,top=200,left=350,height=450,width=450');
  return;
}

//多一个bookType参数，表示定制类型，3为免费
function downnew2(docid,title,bookType,docType,money){	

var url = 'buy.jsp?docId='+docid+'&title='+title+'&bookType='+bookType+'&docType='+docType+'&money='+money;
var sDocType = "彩信";
  if (docType==0){
    sDocType = "彩信";
  }else if (docType==1){
    sDocType = "课件";
  }
  if (confirm("该"+sDocType+"的资费为"+money+"，您确认要下载该"+sDocType+"？"))
  window.open(url,'下载鉴权','status=no,menubar=no,scrollbars=no,top=200,left=350,height=450,width=450');
  return;
}

//包月 1 点播 0
function downnew3(docid,title,docType,money,type){	

var url = 'buy.jsp?docId='+docid+'&title='+title+'&docType='+docType+'&money='+money+'&type='+type;
var sDocType = "彩信";
  if (docType==0){
    sDocType = "彩信";
  }else if (docType==1){
    sDocType = "课件";
  }
  if (confirm("您确认要下载该"+sDocType+"？"))
  window.open(url,'下载鉴权','status=no,menubar=no,scrollbars=no,top=200,left=350,height=450,width=450');
  return;
}
function downkt(docid,title,docType,money){	

var url = '../buy.jsp?docId='+docid+'&title='+title+'&docType='+docType+'&money='+money;
var sDocType = "彩信";
  if (docType==0){
    sDocType = "彩信";
  }else if (docType==1){
    sDocType = "课件";
  }
  if (confirm("您确认要下载该"+sDocType+"？"))
  window.open(url,'下载鉴权','status=no,menubar=no,scrollbars=no,top=200,left=350,height=450,width=450');
  return;
}
function downkt2(docid,title,bookType,docType,money){	

var url = '../buy.jsp?docId='+docid+'&title='+title+'&bookType='+bookType+'&docType='+docType+'&money='+money;
var sDocType = "彩信";
  if (docType==0){
    sDocType = "彩信";
  }else if (docType==1){
    sDocType = "课件";
  }
  if (confirm("该"+sDocType+"的资费为"+money+"，您确认要下载该"+sDocType+"？"))
  window.open(url,'下载鉴权','status=no,menubar=no,scrollbars=no,top=200,left=350,height=450,width=450');
  return;
}