/*
	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='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 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
	<script src="swfobject_source.js" type=text/javascript></script>
	<div id="slide_area"></div>
*/
function slide_qq(flash_width,flash_height,flash_pics,flash_links,flash_titles){
	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');
}
//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() ;
}
