/**
* 获取cookie的值
*/
function getCookie(cookie_name){
	var allcookies = document.cookie;
	var cookie_pos = allcookies.indexOf(cookie_name);
	// 如果找到了索引，就代表cookie存在，
	// 反之，就说明不存在。
	if (cookie_pos != -1){
		// 把cookie_pos放在值的开始，只要给值加1即可。
		cookie_pos += cookie_name.length + 1;
		var cookie_end = allcookies.indexOf(";", cookie_pos);
		if (cookie_end == -1){
			cookie_end = allcookies.length;
		}
		var value = unescape(allcookies.substring(cookie_pos, cookie_end));
	}
	return value;
}

function check(id,type){;
	var siteurl = $('#siteurl').val();
	var id		= id;
	var type	= type;
	var act		= 'check';
	/*var cookie  = getCookie('topic_id');
	//alert(cookie);
	if(cookie.indexOf(id)!=-1){
		//alert('对不起');
		return false;
	}*/
	$.get(siteurl+'choose/'+Math.random(),{id:id,type:type,act:act}, 
		 function(msg){ 
			if(type){
					$('#true').html(msg);
					$("#t_").attr("onclick","");
					$("#f_").attr("onclick","");
				}else{
					$('#false').html(msg);
					$("#t_").attr("onclick","");
					$("#f_").attr("onclick","");
			}
		} 
	);
}

/************************
	投票所用JS
************************/
$(document).ready(function(){
        $("#bt_checkbox2").click(function(){
                    var value="";
                    $("input[@name=cbType2]").each(function(){
                            if(this.checked){
                                    value+=this.value+",";
                            }
                    })
					if(value == ''){
						alert('你至少得选一项！');
					}else{
						var maxnum = $('#max_num').val();
						var siteurl = $('#siteurl').val();
						var act = 'vote';
						var voteid= value; 
						//alert(maxnum);
						//alert(siteurl+'choose');
						$.get(siteurl+'choose/'+Math.random(),{voteid:voteid,maxnum:maxnum,act:act}, 
								 function(msg){
								//alert(msg);
								if(msg == 1){
									alert('投票成功！');
									//$('#div').hide();$('#div1').show;
									var topic_id = $('#topic_id').val()
									window.location = siteurl+'replay/'+topic_id;
								}else{
									alert('你最多只能选择'+maxnum+'项');
								}
							} 
						);
						//alert(num);
					//alert(value);	
				}
        })
})


var docEle = function() {
return document.getElementById(arguments[0]) || false;
}
function openNewDiv(_id) {
var m = "mask";
if (docEle(_id)) document.removeChild(docEle(_id));
if (docEle(m)) document.removeChild(docEle(m));
// 新激活图层
var newDiv = document.createElement("div");
newDiv.id = _id;
newDiv.style.position = "absolute";
newDiv.style.zIndex = "9999";
newDiv.style.width = "350px";
newDiv.style.height = "auto";
newDiv.style.top = "450px";
newDiv.style.left = (parseInt(document.body.scrollWidth) - 300) / 2 + "px"; // 屏幕居中
newDiv.style.background = "url(http://book8249.isoshu.com/image/images_cn/review/bg_00.jpg)";
newDiv.style.border = "1px solid #666666";
newDiv.style.padding = "5px";
newDiv.innerHTML = "<form name='form1' id='form1' method='post' action=''><div style=' width:95%; height:auto; line-height:18px; padding-bottom:5px; margin:0 auto; font-size:12px; font-weight:bold;'><span style='font-size:14px;'>Re:</span>屏幕居中屏幕居中屏幕居中屏幕居中屏幕居中屏幕屏幕居中屏幕</div><div style='width:95%; height:auto; line-height:18px; padding-bottom:5px; margin:0 auto; font-size:12px;color:#666666;'><strong>引用于:</strong>这个凼凼是给峰哥加引用的</div><textarea style='width:343px; height:120px; margin:0 auto; font-size:12px; line-height:18px;'></textarea><div style='width:74px; height:25px; margin:0 auto; background:url(http://book8249.isoshu.com/image/images_cn/review/botton.jpg) no-repeat; line-height:25px; font-size:12px; font-weight:bold; color:#383838; text-align:center; margin-top:6px;cursor:hand;'>评 论</form></div>";
document.body.appendChild(newDiv);
// mask图层
var newMask = document.createElement("div");
newMask.id = m;
newMask.style.position = "absolute";
newMask.style.zIndex = "1";
newMask.style.width = document.body.scrollWidth + "px";
newMask.style.height = document.body.scrollHeight + "px";
newMask.style.top = "0px";
newMask.style.left = "0px";
//newMask.style.background = \"#000\";
newMask.style.filter = "alpha(opacity=40)";
newMask.style.opacity = "0.40";
document.body.appendChild(newMask);
// 关闭mask和新图层
var newA = document.createElement("a");
newA.href = "#";
newA.innerHTML = "<div style='width:auto; float:right; margin-top:-1.2em;cursor:hand; color:#383838; text-decoration:none;'>[关闭窗口]</div>";
newA.onclick = function() {
  document.body.removeChild(docEle(_id));
  document.body.removeChild(docEle(m));
  return false;
}
newDiv.appendChild(newA);
}



function deltop(id){
	var act		= 'deltop';
	var topid	= id;
	var siteurl = $('#siteurl').val();
	//alert(id);
		$.get(siteurl+'choose/'+Math.random(),{topid:topid,act:act}, 
			 function(msg){
			//alert(msg);
			if(msg){
				//alert(msg);
				window.location.href = siteurl;
			}
		} 
	);

}
//http://219.131.193.228/update/step1.aspx?p=zhsb86239|1214558563|undefined|738|1024|32|768|1024
function checklogin(){
		var username = $('#user_name').val();
		var userpwd = $('#user_pwd').val();
		var siteurl = $('#siteurl').val();
		var cookietime = $('#cookietime:checked').val();
		var act = 'checklogin';
		cookietime = cookietime == 1 ? 1 : 0;

		$.get(siteurl+'choose/'+Math.random(),{act:act,userpwd:userpwd,username:username,cookietime:cookietime}, 
			 function(msg){
			if(msg == '1'){
				$('#login_in').show();
				$('#login_out').hide();
				//window.location.href = siteurl;
				window.location.reload();
			}else{
				alert('登陆失败!');
			}
		} 
	);	

}

function loginout(){
		var siteurl = $('#siteurl').val();
		var act = 'loginout';
		$.get(siteurl+'choose/'+Math.random(),{act:act}, 
			 function(msg){
				$('#login_in').hide();$('#login_out').show();
				window.location.reload();
		} 
	);
}