
function addAlias(target)
{
	Element.clonePosition($('aliasDiv'), target, {setWidth:false, setHeight:false, offsetTop:15});
	new Effect.Appear('aliasDiv',{duration:0.3});
}

function hideAlias()
{
	new Effect.Fade('aliasDiv',{duration:0.3});
}
function updateAlias()
{
	if(!$('newaliasvalue').value.blank())
	{   	
		$('aliasform').disable();
		
		new Ajax.Request('/index.php/creditcard/addalias',
		{
			method: 'post',
			parameters:'?cardid='+$("cardid").value + '&alias='+$('newaliasvalue').value,
			onSuccess: function() {
				$('newaliasvalue').value="谢谢您的参与！";
				hideAlias.delay(0.5);
			}
		});
	}
	else
	{
		alert('请输入一个有效的别名');
	}
}



function initComment()
{
	$('loadingtd2').hide();
	new Ajax.Request('/index.php/comment/read', {
		method:'post',
		postBody:'tid=1&act=0&eid='+$('comment_eid').value,
		onSuccess: function(transport){
			$('loadingtd').hide();		
			var returnObj=transport.responseText.evalJSON(true);
			if(returnObj!="" && returnObj.cs.length>0)
			{
				var comments=returnObj.cs;
				for(var i=0;i<comments.length;i++)
				{
					$('commenttable').insert('<tr><td align="center">'+comments[i].u+'</td><td >'+comments[i].c+'</td><td align="center">'+comments[i].d+'</td></tr>');					
				}
			}
			else
			{
				$('loadingtd2').show();
			}
		}
	});
}
function sendComment(n)
{
   var fm;
   if(n==1) fm=$('inpagefm'); else  fm=$('popfm');
	if(!$F(fm['comment_content']).strip().empty() && !$F(fm['comment_picvalid']).strip().empty())
	{
		fm.disabled=true;
		new Ajax.Request('/index.php/comment/write',	{
		method:'post',
		postBody:'id='+$F(fm['comment_eid'])+'&tid='+$F(fm['comment_tid'])+'&comment='+$F(fm['comment_content'])+'&pic='+$F(fm['comment_picvalid']),
		onSuccess:function(fback){
			var result=fback.responseText;
			if(result=="1")
			{
				$('submitBox'+n).update("<span style='color:red'>谢谢您的参与！您的评论将经审核后显示在上面。</span>");
			   fm['comment_content'].value='';
				if(n==2)
					hidebgDiv.delay(1);

			}
			else if(result=="-1")
			{
				alert('您输入的验证码不正确');
			}
			fm.disabled=false;
		}
	}
	);	
	}else
	{
	alert("请输入评论内容和验证码!");
	}
}


function reloadPicvalidsrc(ObjId)
{
$(ObjId).src="/rdimg.php?"+Math.random();
}


function updateCount()
	{
	new Ajax.Request('/index.php/digg/write/t/'+$("digclick").readAttribute("t")+'/id/'+$("digclick").readAttribute("gid"), 
	{   
	method: 'post',   
		onSuccess: function() {     
			$("dignum").innerHTML=Number($("dignum").innerHTML)+1;
			$("digclick").innerHTML='谢谢参与';
		} 
	}); 
	}


function creditchg(n)
{
	var i=0;
	for (i=1;i<=5;i++)
	{
		$("tb_"+i).className="normal";
		$("data_"+i).style.display="none";
		$("tb_"+1).className="normalfirst";
	}

	$("tb_"+n).className="highlighted";
	$("data_"+n).style.display="block";
	if(n>2) $("tb_"+(n-1)).className="normalprehigh";
	if(n==2) $("tb_1").className="normalfirstprehigh"; 
}


function writeMessage(strText)
{
	var text='';
	if(strText=='xs')
	{
		text='高校学生申请条件：身份证复印件及学生证复印件';
										
	}
	else if(strText=='by')
	{
		text='应届毕业生申请条件： 身份证复印件及三方协议复印件';
	}
	else if(strText=='sm')
	{
		text=' 普通市民申请条件：<br /> 1) 缴纳四金正常的客户仅需提供一张“身份证复印件” <br />2)不能缴纳四金的客户需提供： <br />A、“身份证复印件”一张； <br />B、“收入证明材料”一份 有效收入证明包含：个人所得税税单复印件、或待发工资存折交易明细（近三个月）复印件、或单位出具的收入证明原件。 <br />3)如果您期望达到较高的信用额度，你可以补充提供以下任一资料： 本人名下的银行定期存款、国债证明、商品房房产证等个人资产证明复印件。';
	}
	return text;
}


Event.observe(window, 'load', function()
	{
	creditchg(1);
	initComment();
	new Ajax.Request('/index.php/count/credit/cardid/'+$('cardid').value);	
	new Ajax.Updater('dignum', '/index.php/digg/index/t/'+$("digclick").readAttribute("t")+'/id/'+$("digclick").readAttribute("gid"));	
	$$('body')[0].innerHTML+='<div id="messageBox" style="display:none"><div id="messageText"></div><h5><img src="/images/triangle.gif" alt="" /></h5></div>';
		$$('.showdetail').each(function(item)
			{
				item.observe('mouseover', function()
					{
						var type=this.readAttribute('type');
						$('messageText').innerHTML=writeMessage(type);
						var height=$('messageBox').getHeight();
						Element.clonePosition($('messageBox'), this, {setWidth:false, setHeight:false, offsetTop:-height});									
						new Effect.Appear($('messageBox'), {duration:0.3, transition:Effect.Transitions.sinoidal});									
					}
				);
				item.observe('mouseout', function()
					{
						new Effect.Fade($('messageBox'), {duration:0});
					}
				);
			}
		);
	}
);



var commentused=false;

function showbgDiv()
{
    var pageSize=getPageSize();
	$('coverall').style.width=getPageSize()[0]+"px";
	$('coverall').style.height=getPageSize()[1]+"px";
	$('allcommentbox').style.top= (document.viewport.getScrollOffsets().top+(pageSize[3]-$('allcommentbox').getHeight())/2)+'px';
	new Effect.Appear('coverall', {duration:0.5, from:0, to:0.6});
	if(!commentused)
	{
		requestComments(1);
		commentused=true;
	}	
	new Effect.Appear('allcommentbox', {delay:0.5, duration:1.0});
}

function requestComments(current)
{
    $('commloadingdiv').innerHTML='<img src="/images/loading.gif" style="margin-left:266px;margin-top:100px;" />';
	new Ajax.Request('/index.php/comment/read', {
		method:'post',
		postBody:'tid=1&act=1&eid='+$('comment_eid').value+'&p='+current,
	 	onSuccess: function(transport){
		    if(!transport.responseText.blank())
			{
				var returnObj=transport.responseText.evalJSON(true);
				
				if(returnObj!="" && returnObj.cs.length>0)
				{
					var comments=returnObj.cs;
					var htmls="";
					var pager="";
					var pages=returnObj.pages;
					for(var i=0;i<comments.length;i++)
					{
						htmls+='<li class="header">用户： '+comments[i].u+' 发表于 '+comments[i].d+'</li>';
						htmls+='<li>'+comments[i].c+'</li>';
					}
					$('commloadingdiv').innerHTML=htmls;
					if(current==1)
					{
						pager=" 上一页 ";
					}
					else if(current>1 && current<=pages)
					{
						pager=' <span onclick="requestComments('+(current-1)+', '+pages+')">上一页</span> ';
					}
					
					if(current==pages)
					{
						pager+=' 下一页 ';
					}
					else if(current>0 && current<pages)
					{
						pager+=' <span onclick="requestComments('+(current+1)+', '+pages+')">下一页</span> ';
					}
					
					$('allcommentpager').innerHTML=pager+'第'+returnObj.p+'页/共'+pages+'页';
					$('allcommentbox').style.top= (document.viewport.getScrollOffsets().top+(getPageSize()[3]-$('allcommentbox').getHeight())/2)+'px';
				}			
				else
				{
					$('commloadingdiv').innerHTML='<div style="text-align:center;padding-top:100px;color:red">还没有网友评论过呢，就等您了～～</div>';
					$('allcommentpager').innerHTML='第0页/共0页';
				}
			}

		}
	});	
}

function hidebgDiv()
{
	new Effect.Fade('allcommentbox', {duration:0.5});	
	new Effect.Fade('coverall', {delay:0.5, duration:0.5});	
}




function getPageSize(){
	
	var xScroll, yScroll;
	
	if (window.innerHeight && window.scrollMaxY) {	
		xScroll = document.body.scrollWidth;
		yScroll = window.innerHeight + window.scrollMaxY;
	} else if (document.body.scrollHeight > document.body.offsetHeight){ // all but Explorer Mac
		xScroll = document.body.scrollWidth;
		yScroll = document.body.scrollHeight;
	} else { // Explorer Mac...would also work in Explorer 6 Strict, Mozilla and Safari
		xScroll = document.body.offsetWidth;
		yScroll = document.body.offsetHeight;
	}
	
	var windowWidth, windowHeight;
	if (self.innerHeight) {	// all except Explorer
		windowWidth = self.innerWidth;
		windowHeight = self.innerHeight;
	} else if (document.documentElement && document.documentElement.clientHeight) { // Explorer 6 Strict Mode
		windowWidth = document.documentElement.clientWidth;
		windowHeight = document.documentElement.clientHeight;
	} else if (document.body) { // other Explorers
		windowWidth = document.body.clientWidth;
		windowHeight = document.body.clientHeight;
	}	
	
	// for small pages with total height less then height of the viewport
	if(yScroll < windowHeight){
		pageHeight = windowHeight;
	} else { 
		pageHeight = yScroll;
	}

	// for small pages with total width less then width of the viewport
	if(xScroll < windowWidth){	
		pageWidth = windowWidth;
	} else {
		pageWidth = xScroll;
	}


	arrayPageSize = new Array(pageWidth,pageHeight,windowWidth,windowHeight) 
	return arrayPageSize;
}

