/*
	Powered by www.yiersan.cn
*/
function checkAll(o,target){
	var objs = document.getElementsByName(target);
	if(o.checked == true){
		for(i=0;i<objs.length;i++){
			objs[i].checked=true;
		}				
	}else{
		for(i=0;i<objs.length;i++){
			objs[i].checked=false;
		}					
	}
}

function checkAllForClass(o,target){
	$("."+target).attr("checked",$(o).attr("checked")); 
}

function writeDateInfo()
{
        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=" 星期六";
        document.write(year+"年"+mymonth+"月"+myday+"日"+weekday);
}

function seccode() {
	var img = 'do.php?ac=seccode&rand='+Math.random();
	//var img = 'http://localhost/discuz/seccode.php?update='+Math.random();
	
	document.writeln('<img onclick=updateseccode() id="img_seccode" src="'+img+'" align="absmiddle" width=85 height=20 alt="看不清楚点此刷新" style="cursor:pointer;">');
}
function updateseccode() {
	var img = 'do.php?ac=seccode&rand='+Math.random();
	//var img = 'http://localhost/discuz/seccode.php?update='+Math.random();
	if($('#img_seccode')) {
		$("#img_seccode").attr("src",img);
	}
}

function showandhide(obj){
	$(obj).next("div").toggle();
}


var newid=0;
function Addtr(obj,sid,fid){
	
	newid++;
	var trstr="<tr class='hover tac'><td></td><td></td><td><input type='text' class='txt' name='order_new"+newid+"' size='5' maxlength='3'></td><td style='text-align:left;'>";
	
	if(sid==2){
		trstr+="<img src='images/admincp/branch3.gif' align='absmiddle'>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;<img src='images/admincp/branch.gif' align='absmiddle'>&nbsp;";
	}else if(sid==1){
		trstr+="<img src='images/admincp/branch.gif' align='absmiddle'>";
	}
	
	trstr+="<input type='text'  class='txt' name='name_new"+newid+"' id='name_new"+newid+"' value='子菜单名称' size='25'></td><td><input type='text'  class='txt' name='url_new"+newid+"' size='45'></td>";
	//trstr+="<td><select name='type_new"+newid+"'><option value='SYS'>系统</option><option value='PAGE'>页面</option><option value='LINK'>链接</option></select></td>";
	//trstr+="<td><input type='checkbox' class='checkbox' name='status_new"+newid+"' value='1' checked></td><td><input type='checkbox' class='checkbox' name='blank' value='1'></td>";
	trstr+="<td><input type='checkbox' class='checkbox' name='blank_new"+newid+"' value='1'></td>";
	trstr+="<td><input type='hidden' value='"+fid+"' name='fatherid_new"+newid+"'/><input type='hidden' value='"+newid+"' name='newids[]'/>";
	trstr+="<a href='javascript:' onclick='Deletetr(this)'>删除</a></td></tr>";
	
	if(sid==2||sid==1){
		$(obj).parent("td").parent("tr").after(trstr);
	}else if(sid==0){
		$(obj).parent("td").parent("tr").before(trstr);
	}
	
	$("#name_new"+newid).focus();
	$("#name_new"+newid).select();
}

function Addtr2(obj,sid,fid){
	
	newid++;
	var trstr="<tr id='addtr"+newid+"' class='hover tac'><td></td><td><input type='text' class='txt' name='order_new"+newid+"' size='5' maxlength='3'></td><td style='text-align:left;'>";
	
	if(sid==2){
		trstr+="<img src='images/admincp/branch3.gif' align='absmiddle'>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;<img src='images/admincp/branch.gif' align='absmiddle'>&nbsp;";
	}else if(sid==1){
		trstr+="<img src='images/admincp/branch.gif' align='absmiddle'>";
	}
	
	trstr+="<input type='text'  class='txt' name='name_new"+newid+"' id='name_new"+newid+"' value='功能名称' size='25'></td>";
	if(sid!=0){
		trstr+="<td><input type='text'  class='txt' name='popedom_new"+newid+"' size='35'></td>";
	}else{
		trstr+="<td></td>";
	}
	trstr+="<td><input type='text' class='txt' name='description_new"+newid+"'  size='35'></td>";
	trstr+="<td><input type='hidden' value='"+fid+"' name='fatherid_new"+newid+"'/><input type='hidden' value='"+newid+"' name='newids[]'/>";
	trstr+="<a href='javascript:' onclick='Deletetr(this)'>删除</a></td></tr>";
	
	if(sid==2||sid==1){
		$(obj).parent("td").parent("tr").after(trstr);
	}else if(sid==0){
		$(obj).parent("td").parent("tr").before(trstr);
	}
	
	$("#name_new"+newid).focus();
	$("#name_new"+newid).select();
}

function add_data_tr(obj){
	
	newid++;
	var trstr="<tr id='addtr"+newid+"' class='hover tac'>";	
	trstr+="<td></td>";
	trstr+="<td></td>";
	trstr+="<td><input type='checkbox' name='status"+newid+"' class='status_checkbox' value='1'></td>";
	trstr+="<td><input type='text' class='txt' name='var"+newid+"' value='' size='20' maxlength='20'></td>";
	trstr+="<td><select name='type"+newid+"' size='1'><option value='cnt'>详细内容</option><option value='news'>新闻列表</option><option value='news_top'>新闻头条推荐</option><option value='news_top_list'>新闻头条推荐列表</option><option value='plan'>展览计划列表</option><option value='speakers'>嘉宾列表</option><option value='file'>文件列表</option><option value='slide'>幻灯片</option></select></td>";
	trstr+="<td><input type='text' class='txt' name='data_id"+newid+"' value='' size='10' maxlength='5'></td>";
	trstr+="<td><input type='text' class='txt' name='num"+newid+"' value='' size='10' maxlength='2'></td>";
	trstr+="<td><input type='text' class='txt' name='remark"+newid+"' value='' size='30' maxlength='20'></td>";
	trstr+="<td><a href='javascript:' onclick='Deletetr(this)'>删除</a><input type='hidden' value='"+newid+"' name='newids[]'/></td>";
	trstr+="</tr>";
	$(obj).parent("td").parent("tr").before(trstr);	
}

function Deletetr(obj){
	$(obj).parent("td").parent("tr").remove();
}

function ShowAdd(obj){
	$(obj).css("color","red");
}

function HideAdd(obj){
	$(obj).css("color","#fff");
}

function subEmail(){
	var emailObj = document.getElementById('emailAddress');
	var emailAddress = $.trim(emailObj.value);
	if(emailAddress!=""){
		if(/^([a-zA-Z0-9_-])+@([a-zA-Z0-9_-])+((\.[a-zA-Z0-9_-]{2,3}){1,2})$/.test(emailAddress)){
			$.post("email.php", {email:emailAddress}, function(text){
				//alert(text);
				if(text=='ok'){
					alert("订阅成功");
					emailObj.value='';
				}else if(text=='repeat'){
					alert("该邮箱地址已经存在，请重新输入");
				}else{
					alert("订阅失败");
				}
			});
		}else{
			alert("邮箱地址错误，请重新输入");
		}
	}else{
		alert("请填写邮箱地址");
	}
	emailObj.focus();
	emailObj.select();
}
//英文版邮件订阅
function subEmail_en(){
	var emailObj = document.getElementById('emailAddress');
	var emailAddress = $.trim(emailObj.value);
	if(emailAddress!=""){
		if(/^([a-zA-Z0-9_-])+@([a-zA-Z0-9_-])+((\.[a-zA-Z0-9_-]{2,3}){1,2})$/.test(emailAddress)){
			$.post("email.php", {email:emailAddress}, function(text){
				//alert(text);
				if(text=='ok'){
					//alert("订阅成功");
					alert("Success!");
					emailObj.value='';
				}else if(text=='repeat'){
					//alert("该邮箱地址已经存在，请重新输入");
					alert("Email address is repeat,please retype");
				}else{
					alert("Faild!");
				}
			});
		}else{
			//alert("邮箱地址错误，请重新输入");
			alert("Must be in the form of xxxx@yyyy.zzz");
		}
	}else{
		//alert("请填写邮箱地址");
		alert("Must be in the form of xxxx@yyyy.zzz");
	}
	emailObj.focus();
	emailObj.select();
}

//add category start
function showAddCategoryDiv(){
	var categoryDiv = document.getElementById('newCategoryDiv');
	var inputCategory = document.getElementById('newCategoryName');
	categoryDiv.style.display = 'block';
	inputCategory.value = "";
	inputCategory.focus();
}
function hideCategoryFolderDiv(){
	document.getElementById('newCategoryDiv').style.display = 'none';
}
function addOptionToSelect(selStr,categoryStr){
	var inputCategory = document.getElementById(categoryStr);
	var category_name = inputCategory.value;
	if($.trim(category_name) == ""){
		alert("请填写文件夹名称!");
		inputCategory.focus();
	}else{
		var slt=document.getElementById(selStr);
		var objOption = new Option(category_name,'6'); 
		slt.options[slt.options.length] = objOption;
		slt.options[slt.options.length-1].selected = 'selected';
		document.getElementById('hideCategory').value = category_name;
		document.getElementById('newCategoryDiv').style.display = 'none';
	}
}
//add category end

//countdown start
function countdown(expire_date,is_day){
	var start = new Date().getTime();
	var end = new Date(expire_date).getTime();
	var loop = 1;
	if (end <= start) {
		return;
	}
	var alltime = parseInt((end - start) / 1000) - loop;
	var d = parseInt(alltime / 86400);
	var h = parseInt((alltime - d*86400) / 3600);
	var m = parseInt((alltime - d*86400 - h*3600) / 60);
	var s = parseInt(alltime - d*86400 - h*3600 - m*60);
	loop ++;
	setTimeout("countdown('"+expire_date+"',"+is_day+")", 1000);
	
	//只显示日期
	if(is_day==1){
		document.getElementById("day_num").innerHTML = countdown_format_number(d);
	}else{
		document.getElementById("day_num").innerHTML = countdown_format_number(d);
		document.getElementById("hour_num").innerHTML = countdown_format_number(h);
		document.getElementById("minute_num").innerHTML = countdown_format_number(m);
		document.getElementById("second_num").innerHTML = countdown_format_number(s); 		
	}
}
function countdown_format_number(n) {
	if (n < 10) {
		return "0" + n;
	} else {
		return n;
	}
}
//countdown end

//slide style for default
function slide_default(flash_width,flash_height,flash_pics,flash_links){
	var pic_width = flash_width;
	var pic_height = flash_height;
	var show_text=0;
	var button_pos=1;
	var stop_time=5000;

	var swf_height=show_text==1?pic_height+20:pic_height;
	var pics="", links="",texts="";

	pics = flash_pics;
	links = flash_links;
	texts = "||||";

	document.write('<object classid="clsid:d27cdb6e-ae6d-11cf-96b8-444553540000" codebase="http://fpdownload.macromedia.com/pub/shockwave/cabs/flash/swflash.cab#version=6,0,0,0" width="'+ pic_width +'" height="'+ swf_height +'">');
	document.write('<param name="movie" value="js/slide2.swf">');
	document.write('<param name="quality" value="high">');
	document.write('<param name="wmode" value="opaque">');
	document.write('<param name="FlashVars" value="pics='+pics+'&links='+links+'&texts='+texts+'&pic_width='+pic_width+'&pic_height='+pic_height+'&show_text='+show_text+'&button_pos='+button_pos+'&stop_time='+stop_time+'">');
	document.write('<embed src="js/slide2.swf" FlashVars="pics='+pics+'&links='+links+'&texts='+texts+'&pic_width='+pic_width+'&pic_height='+pic_height+'&show_text='+show_text+'&button_pos='+button_pos+'&stop_time='+stop_time+'" quality="high" width="'+ pic_width +'" height="'+ swf_height +'" allowScriptAccess="sameDomain" type="application/x-shockwave-flash" pluginspage="http://www.macromedia.com/go/getflashplayer" />');
	document.write('</object>');
}
//slide style for iresearch
function slide_iresearch(flash_width,flash_height,flash_pics,flash_links){
	var swf_width = flash_width;
	var swf_height = flash_height;
	var files=flash_pics;
	var links = flash_links;
	var texts='||';

	document.write('<object classid="clsid:d27cdb6e-ae6d-11cf-96b8-444553540000" codebase="http://fpdownload.macromedia.com/pub/shockwave/cabs/flash/swflash.cab#version=6,0,0,0" width="'+ swf_width +'" height="'+ swf_height +'">');
	document.write('<param name="movie" value="js/slide.swf"><param name="quality" value="high">');
	document.write('<param name="menu" value="false"><param name=wmode value="opaque">');
	document.write('<param name="FlashVars" value="bcastr_file='+files+'&bcastr_link='+links+'&bcastr_title='+texts+'&bcastr_config=999999:文字颜色|2:文字位置|0xffffff:文字背景颜色|75:文字背景透明度|0xffffff:按键文字颜色|0x365DA0:按键默认颜色|0x000033:按键当前颜色|4:自动播放时间(秒)|3:图片过渡效果|1:是否显示按钮|_blank:打开窗口">');
	document.write('<embed src="js/slide.swf" wmode="opaque" FlashVars="bcastr_file='+files+'&bcastr_link='+links+'&bcastr_title='+texts+'& menu="false" quality="high" width="'+ swf_width +'" height="'+ swf_height +'&bcastr_config=999999:文字颜色|1:文字位置|0xffffff:文字背景颜色|75:文字背景透明度|0xffffff:按键文字颜色|0x365DA0:按键默认颜色|0x000033:按键当前颜色|6:自动播放时间(秒)|3:图片过渡效果|1:是否显示按钮|_blank:打开窗口" type="application/x-shockwave-flash" pluginspage="http://www.macromedia.com/go/getflashplayer" />'); document.write('</object>');
}
//slide style for qq
function slide_qq(flash_width,flash_height,flash_pics,flash_links,flash_titles){
	//<script src="js/swfobject_source.js" type=text/javascript></script>
	//document.write('<script src="js/swfobject_source.js" type=text/javascript></script>');

	//var swf_obj = document.createElement("script");
	//swf_obj.type = "text/javascript";
	//swf_obj.src = 'js/swfobject_source.js';
	
	document.write('<div id="slide_area_qq"></div>');
	
	var pw = flash_width;
	var ph = flash_height;
	var imgs = flash_pics;
	var urls = flash_links;
	var titles = flash_titles;
	var sizes = 14;
	var Times = 4000;
	var umcolor = 0xFFFFFF;
	var btnbg =0xFF7E00;
	var txtcolor =0xFFFFFF;
	var txtoutcolor = 0x000000;
	var flash = new SWFObject('js/slide_qq.swf', 'mymovie', pw, ph, '7', '');
	flash.addParam('allowFullScreen', 'true');
	flash.addParam('allowScriptAccess', 'always');
	flash.addParam('quality', 'high');
	flash.addParam('wmode', 'Transparent');
	flash.addVariable('pw', pw);
	flash.addVariable('ph', ph);
	flash.addVariable('sizes', sizes);
	flash.addVariable('umcolor', umcolor);
	flash.addVariable('btnbg', btnbg);
	flash.addVariable('txtcolor', txtcolor);
	flash.addVariable('txtoutcolor', txtoutcolor);
	flash.addVariable('urls', urls);
	flash.addVariable('Times', Times);
	flash.addVariable('titles', titles);
	flash.addVariable('imgs', imgs);
	flash.write('slide_area_qq');
}
//slide style for flipper
function slide_flipper(flash_width,flash_height,flash_pics,flash_links){
	var fp_pics="",fp_links="";
	document.write('<div id="slide_area_flipper"></div>');
	//document.write('<script src="js/flipper.js" type=text/javascript></script>');

	//广告图片与链接
	//fp_pics += "§"+"uploads/201103/10/1_1299722835YVF3.jpg";
	//fp_links += "§"+escape("newshow.asp?id=145&mnid=16831"); //广告链

	fp_pics = flash_pics;
	fp_links = flash_links;
	fp_pics=fp_pics.substring(1);
	fp_links=fp_links.substring(1);

	var FP = new zadaiFlash("js/flipper.swf", "FP_L_swf", flash_width, flash_height, "7", "#FFFFFF", false, "High");
	FP.addParam("menu", "false");
	FP.addParam("wmode", "transparent");
	FP.addVariable("pic_width", flash_width);		//图片宽
	FP.addVariable("pic_height", flash_height);		//图片高
	FP.addVariable("flip_time", "300");				//翻牌速度
	FP.addVariable("pause_time", "4000");			//间隔时间
	FP.addVariable("wait_time", "2000");			//等待时间
	FP.addVariable("pics", fp_pics);				//广告图片地址
	FP.addVariable("urls", fp_links);				//广告链接地址
	FP.write("slide_area_flipper");
}
//Tab card
function nTabs(thisObj,Num){
	if(thisObj.className == "active")return;
	var tabObj = thisObj.parentNode.id;
	var tabList = document.getElementById(tabObj).getElementsByTagName("li");
	for(i=0; i <tabList.length; i++)
	{
		if(i == Num){
			thisObj.className = "active"; 
		    document.getElementById(tabObj+"_Content"+i).style.display = "block";
		}else{
			tabList[i].className = "normal"; 
			document.getElementById(tabObj+"_Content"+i).style.display = "none";
		}
	} 
}
//use fck pic select
function OpenFile( fileUrl ){
	window.top.opener.SetUrl( fileUrl ) ;
	window.top.close() ;
	window.top.opener.focus() ;
}

//选择图片后显示
function viewpic(obj){
	//alert($(obj).val());
	if($(obj).val()!=""){
		$("#pic").attr("src",$(obj).val());
		$("#pic").show();
	}else{
		$("#pic").hide();
	}
}


//------------------------------------sortTable---------------------------------
//比较函数生成器
function generateCompareTRs(iCol,sDataType){
	return function compareTRs(oTR1,oTR2){
		var sValue1=convert(oTR1.cells[iCol].firstChild.nodeValue,sDataType);
		var sValue2=convert(oTR2.cells[iCol].firstChild.nodeValue,sDataType);
		//如果是字符串就用系统默认的字符串比较
		if(sDataType=="string"){
			return sValue1.localeCompare(sValue2);				
		}else{
			if(sValue1<sValue2){
				return -1;
			}else if(sValue1>sValue2){
				return 1;
			}else{
				return 0;
			}
		}
	}
}
//数据类型转换函数
function convert(sValue,sDataType){
	switch(sDataType){
		case "int":
			return parseInt(sValue);
		case "float":
			return parseFloat(sValue);
		case "date":
			return new Date(Date.parse(sValue));
		default:
			return sValue.toString();
	}
}
//table sort
function sortTable(tableId,iCol,sDataType){
	//alert('asdf');
	var oTable=document.getElementById(tableId);
	var oTBody=oTable.tBodies[0];
	var colDataRows=oTBody.rows;

	var aTrs=new Array;
	for(var i=0;i<colDataRows.length;i++){
		//在数组后面添加一个项
		aTrs.push(colDataRows[i]);
	}
	//
	if(oTable.sortCol==iCol){
		aTrs.reverse();
	}else{
		aTrs.sort(generateCompareTRs(iCol,sDataType));
	}
	
	var oFragment=document.createDocumentFragment();
	for(var i=0;i<aTrs.length;i++){
		oFragment.appendChild(aTrs[i]);
	}
	oTBody.appendChild(oFragment);
	oTable.sortCol=iCol;
}
