
//内容页载入
function diggLoad()
{
   var digval="";
   digval=document.getElementById("digVal").innerHTML;
   getdata('../../dig_vote.asp?post_str='+digval,'dig1','dig1'); //wurl+
 }

//图片大小
function resizepic(thispic) 
{ 	
    var image=new  Image();
    image.src=thispic.src;
    if(image.width>610) thispic.width=610;
    image=null;
}

//dig
function dig(elem,event,pushUrl) {
	return onDiggSubmit(elem,event,'digg',pushUrl);
}
function onDiggSubmit(elem,event,action,pushUrl) {
	Event.stop(event);
	
	var mod = Element.readAttribute(elem, 'mod');               //URL方式
	var postLink = Element.readAttribute(elem, 'href');         //当前URL
	var postID = Element.readAttribute(elem, 'postID');         //当前URL-ＩＤ
	var postKey = Element.readAttribute(elem, 'postKey');       //URL-发送关键字
	var cacheKey = Element.readAttribute(elem, 'cacheKey');     //URL-缓存关键字

	var postDiggIt = $('post-dig-it-'+postID);               //div 的id
	var postDiggCount = $('post-dig-count-'+postID);        //结果的id
	
	Element.update(postDiggIt, '<img src='+wurl+'/style/images/loading.gif align="absmiddle" width="16" height="16" />');
	
	var params = 'action=post.'+action+'&type=post&post_mod='+mod+'&post_id='+postID+'&post_key='+postKey+'&cache_key='+cacheKey;

	//alert(pushUrl);

	new Ajax.Request(pushUrl+wurl+'/ajax.asp', {method:'POST', parameters:params, onSuccess:function(transport){
		try{
			var json = transport.responseText.evalJSON(true);
			//alert(json);
			if( json ) {
				if( json.result ) {  		//返回(result=)true			
					//Element.update(postDiggIt, '<a href="'+postLink+'" class="red" target=_blank>成功</a>');
					//Element.update(postDiggCount, '<a href="'+postLink+'" target=_blank>'+json.diggCount+'</a>');
					alert("顶得太棒了，下次看到好文一定记得顶哟！");
					Element.update(postDiggIt, '<a href="'+postLink+'" class="red" target=_blank>成功</a>');
					Element.update(postDiggCount, '<Div class="lidiv"><a href=#>'+json.diggCount+'</a></Div><Div class="lifont">顶过</Div>');

				} else {					//返回(result=)false
					if( json.voted ) {		//返回(voted=)true
						Element.update(postDiggIt, '<a href="'+postLink+'" class="green" target=_blank>已投票</a>');
					} else {          		//返回(voted=)false
							Element.update(postDiggIt, '<a href=# class="red" target=_blank>失败</a>');
					}
				}
			} // end josn
		} catch (e) {                		//没有返回内容
			Element.update(postDiggIt, '<a href=void(); class="red" target=_blank>失败</a>');
			// alert(e.message);
		}
	} // end function
	});
}

//=====================================================================================
function miniDigg(elem,event,pushUrl) {
	return onMiniDiggSubmit(elem,event,'digg',pushUrl);
}

function onMiniDiggSubmit(elem,event,action,pushUrl) {
	Event.stop(event);
	
	var mod = Element.readAttribute(elem, 'mod');
	var postLink = Element.readAttribute(elem, 'href');
	var postID = Element.readAttribute(elem, 'postID');
	var postKey = Element.readAttribute(elem, 'postKey');
	var cacheKey = Element.readAttribute(elem, 'cacheKey');
	var rawValue = $(elem).innerHTML;
	Element.update(elem, '<img src='+wurl+'/style/images/loading.gif align="absmiddle" width="16" height="16" />');
	
	var params = 'action=post.'+action+'&type=post&post_mod='+mod+'&post_id='+postID+'&post_key='+postKey+'&cache_key='+cacheKey;
	//alert(pushUrl);
	new Ajax.Request(pushUrl+'/ajax.asp', {method:'POST', parameters:params, onSuccess:function(transport){
		try{
			var json = transport.responseText.evalJSON(true);
			if( json ) {
				if( json.result ) {
					Element.update(elem, json.diggCount);
					onMiniTip(elem,event,'成功',5,24,32,0);
				} else {
					if( json.voted ) {
						onMiniTip(elem,event,'已投票',5,36,32,0);
					} else {
						onMiniTip(elem,event,'失败',5,24,32,0);
					}
					Element.update(elem, rawValue);
				}
			} // end josn
		} catch (e) {
			onMiniTip(elem,event,'失败',5,24,32,0);
			Element.update(elem, rawValue);
		}
	} // end function
	});
	
}
// onMiniTip
function onMiniTip(elem, event, msg, sec, width, offsLeft, offsTop) {
	if( !sec ) {
		sec = 5;
	}
	if( !offsLeft ) {
		offsLeft = 0;
	}
	if( !offsTop ) {
		offsTop = 0;
	}
	
	if( $('__js_ajax_tip_control') ) {
		// TODO
	} else {
		new Insertion.Bottom(document.body, '<div id="__js_ajax_tip_control" style="display:none;z-index:20000;"></div>');
	}
	Position.absolutize('__js_ajax_tip_control');
	Position.clone(elem,'__js_ajax_tip_control', {setWidth:false,setHeight:true,offsetLeft:offsLeft,offsetTop:offsTop});
	Element.update('__js_ajax_tip_control', '<div style="width:'+width+'px;background:#E10601;color:#FFF;font-size:12px;padding:1px 3px;line-height:130%;white-space:nowrap;z-index:20001;">'+msg+'</div>');
	Element.show('__js_ajax_tip_control');
	setTimeout("Element.hide('__js_ajax_tip_control');", sec*1000);
}

//digg
function diggIt(purl,pval)
{
	var pdata;
		pdata="active=diggIt&pid="+pval;
	var xmlhttp=createxmlhttp();
	if(!xmlhttp)
	{
		alert("你的浏览器不支持XMLHTTP！！");
		return;
	}
	xmlhttp.open("POST",purl,true);
	xmlhttp.onreadystatechange=requestdata;
	xmlhttp.setRequestHeader("Content-Type","application/x-www-form-urlencoded");
	xmlhttp.send(pdata);
	function requestdata()
	{
		if(xmlhttp.readyState==4)
		{
			if(xmlhttp.status==200)
			 {
				if (xmlhttp.responseText!="已顶过")
				 {
				  alert("顶得太棒了，下次看到好文一定记得顶哟！");
				  diggLoad();
				 }
				else
				 {
				   alert(xmlhttp.responseText);
				 }
			 }
		}
	}   
}

//offdig
function offdig(purl,pval)
{
	var pdata;
		pdata="active=offdig&pid="+pval;
	var xmlhttp=createxmlhttp();
	if(!xmlhttp)
	{
		alert("你的浏览器不支持XMLHTTP！！");
		return;
	}
	xmlhttp.open("POST",purl,true);
	xmlhttp.onreadystatechange=requestdata;
	xmlhttp.setRequestHeader("Content-Type","application/x-www-form-urlencoded");
	xmlhttp.send(pdata);
	function requestdata()
	{
		if(xmlhttp.readyState==4)
		{
			if(xmlhttp.status==200)
			 {
				if (xmlhttp.responseText!="已踩过" && xmlhttp.responseText!="请登录")
				{
					if (xmlhttp.responseText==0)
					{
						alert("已经踩到最底了");
					}
					else
					{
						alert("在你的强烈反对下,已经成功把它踩下去了！");
						diggLoad();
					}
				}
				else
				{
					if (xmlhttp.responseText=="请登录")
					{
                       alert("你想把它踩下去，请先登录"); 
					}
					else //已踩过
					{
                       alert(xmlhttp.responseText);
					}
				}
			 }
		}
	}   
}

// 登录检测
 function checkLogin(form)
 {
    if(form.TxtUser.value=="")
	{
	  alert("请输入登录用户名");
	  form.TxtUser.focus();
	  return false;
	}
    if(form.TxtPassword.value=="")
	{
	  alert("请输入登录密码");
	  form.TxtPassword.focus();
	  return false;
	}
	form.login.disabled="disabled";
 }

//检测登录状态
function iCheckLogin()
{
   getdata(wurl+'/loginsta.asp?active=index','loginState','loginState');	
}
