var MyMar;
document.cookie="Cache=vod;domain=9158.com;path=/";

function getObject(id) 
{
	if(document.getElementById) 
	{
		return document.getElementById(id);
	}
	else if(document.all)
	{
		return document.all[id];
	}
	else if(document.layers)
	{
		return document.layers[id];
	}
}

function Xmopen()
{
	var xmlhttp, bComplete = false;
	try { xmlhttp = new ActiveXObject("Msxml2.XMLHTTP"); }
	catch (e) { try { xmlhttp = new ActiveXObject("Microsoft.XMLHTTP"); }
	catch (e) { try { xmlhttp = new XMLHttpRequest(); }
	catch (e) { xmlhttp = false; }}}
	if (!xmlhttp) return null;
	this.loaded = function(sURL, sMethod, sVars, fnDone)
	{
		if (!xmlhttp) return false;
		bComplete = false;
		sMethod = sMethod.toUpperCase();
		try
		{
			if (sMethod == "GET")
			{
				xmlhttp.open(sMethod, sURL+"?"+sVars, true);
				sVars = "";
			}
			else
			{
				xmlhttp.open(sMethod, sURL, true);
				xmlhttp.setRequestHeader("Method", "POST "+sURL+" HTTP/1.1");
				xmlhttp.setRequestHeader("Content-Type","application/x-www-form-urlencoded");
			}
			xmlhttp.onreadystatechange = function()
			{
				if (xmlhttp.readyState == 4 && !bComplete)
				{
					bComplete = true;
					fnDone(xmlhttp);
				}
			};
			xmlhttp.send(sVars);
    	 }
		catch(z) { return false; }
		return true;
	};
	return this;
}

function xmlhttp()
{
	var A=null;
	try
	{
		A=new ActiveXObject("Msxml2.XMLHTTP");
	}
	catch(e)
	{
		try
		{
			A=new ActiveXObject("Microsoft.XMLHTTP");
		}
		catch(oc)
		{
			if (typeof XMLHttpRequest != "undefined" );
			{
				A=new XMLHttpRequest();
			}
		}
	}			
	return A;
}

function set_select(select_obj_id,code)
{
	end = getObject(select_obj_id).outerHTML.search('>')+1;
	getObject(select_obj_id).outerHTML = getObject(select_obj_id).outerHTML.substr(0,end)+code+"</select>";
}

/**
 * 设置下拉选框数据
 * target_id 为目标下拉选框的ID号
 * code_url 为请求数据的服务端的URL
 */
function get_listbox(target_id,code_url)
{
	var request_url;
	var request_str;
	var tmp = code_url.split('?');
	
	request_url = tmp[0];
	if(tmp.length == 2)
	{
		request_str = tmp[1];
	}	
	try 
	{		
		var myOpen = new Xmopen();
		var showDone = function (oXML) 
		{	
			set_select(target_id, oXML.responseText);	
		};
		myOpen.loaded(request_url, "GET", request_str, showDone);
	}
	catch(e)
	{
		// do nothing
	}
}

//评论提交及显示
var oXmlHttp = xmlhttp();
function getReplayResult(target_id,code_url,value,table,UserId)
{
	len=value.length;
	if (len < 2 )
	{
		alert("输入的字符不能少于2个");
		return;
	}
	if(len > 125)
	{
		alert("输入的字符不能多于125个");
		return;
	}
	var filterValue=value.replace(/^\s*/i,'');
	filterValue=filterValue.replace(/╱°*/gim,'"');
	filterValue=escape(filterValue);
	try 
	{ 
		var myOpen = new Xmopen();
		var showDone = function (oXML) 
		{	
			var result = oXML.responseText;	
			if(result=="$%^&*@!+)sgsg#$&*@#")
			{
				alert("对不起!出现意外，请稍后再试！");
			}				
			else
			{
				var flag = result.substr(0, 1);
				if(flag==0)
				{
					alert("评论提交成功！");
					target_id.innerHTML = result.substring(1);
				}
				else if(flag==1)
				{
					alert("该用户设定只有VIP才能给他留言或评论！");
					window.open('http://www.9158.com/Vip.html');
				}
				else if(flag==2)
				{
					alert("该用户拒绝任何人给他留言或评论！");
				}
				else if(flag==3)
				{
					alert("您已被对方加入黑名单，无权留言或评论！");
				}
				else if(flag==6)
				{
					alert("该用户设定只有好友才能给他留言或评论！");
				}
				else if(flag==7)
				{
					alert("您未设置形象照，请到您的相册上传照片，并设为形象照后再发布留言或评论！");
					window.open('NoPhoto.aspx','暂无形象照','height=400,width=600');
				}				
				else
				{
					alert(result);
				}				
			}
		};
		myOpen.loaded("BlogMusic_UpdateRemark.aspx", "POST", "hiddenCid=" +code_url+ "&table=" +table+ "&UserID=" +UserId+ "&memo=" +filterValue, showDone);	
	}
	catch(e)
	{
		// do nothing
	}
}

//返回评论
function getComment(table,c_id)
{
	var myOpen = new Xmopen();
	var showDone = function (oXML) 
	{	
		document.getElementById("pinlun").innerHTML = oXML.responseText;	
	};
	myOpen.loaded("GetComment.aspx", "GET", "hiddenCid=" +c_id+ "&table=" +table, showDone);
}

//下面是留言的ajax函数
function getReplayMemoResult(target_id,code_url,value,table,ispuc)
{
	len=value.length;
	if (len < 2 )
	{
		alert("输入的字符不能少于2个");
		return;
	}
		if (len > 125){
		alert("输入的字符不能多于125个");
		return;
	}
	
	var strreg=/\[swf\]\d+.gif\[\/swf\]/img;
	var ms=value.match(strreg);

    if(ms!=null)
    {
		if(ms.length>3)
		{
			alert("魔法表情不能多于3个！");
			return;
		}
	}
	var filterValue=value.replace(/^\s*/i,'');
    filterValue=filterValue.replace(/╱°*/gim,'"');
    filterValue=escape(filterValue);
	try 
	{	
		var myOpen = new Xmopen();
		var showDone = function (oXML) 
		{	
			var result = oXML.responseText;	
			if(result=="$%^&*@!+)sgsg#$&*@#")
			{
				alert("对不起!出现意外，请稍后再试！");
			}				
			else
			{
				var flag = result.substr(0,1);
				if(flag==0)
				{
					alert("留言提交成功！");
					target_id.innerHTML = result.substring(1);
				}
				else if(flag==1)
				{
					alert("该用户设定只有VIP才能给他留言或评论！");
					window.open('http://www.9158.com/Vip.html');
				}
				else if(flag==2)
				{
					alert("该用户拒绝任何人给他留言或评论！");
				}
				else if(flag==3)
				{
					alert("您已被对方加入黑名单，无权留言或评论！");
				}
				else if(flag==4)
				{
					alert("普通用户每天只能发50条留言.VIP享有更多特权！");
					window.open("http://www.9158.com/Vip.html");
				}
				else if(flag==5)
				{
					alert("对不起,只有VIP用户才可以发表私密留言!");
					window.open("http://www.9158.com/Vip.html");
				}
				else if(flag==6)
				{
					alert("该用户设定只有好友才能给他留言或评论！");
				}
				else if(flag==7)
				{
					alert("您未设置形象照，请到您的相册上传照片，并设为形象照后再发布留言或评论！");
					window.open('NoPhoto.aspx');
				}else if(flag==8)
				{
					alert("VIP用户每天只能发100条留言！");
				}				
				else
				{
					alert(result);
				}			
			}
		};
		myOpen.loaded("BlogMusic_UpdateRemark.aspx", "POST", "hiddenCid=" +code_url+ "&table=" +table+ "&IsPuc=" +ispuc+ "&UserID=" +code_url+ "&memo=" +filterValue, showDone);
	}
	catch(e)
	{
		//do nothing
	}
}
 
 
//返回主页面的ajax函数
function GetIndexAjax(id,templateid,divid,subpage)
{
	var myOpen = new Xmopen();
	var showDone = function (oXML) 
	{	
		var targetobj = document.getElementById(divid);
		targetobj.innerHTML = oXML.responseText;
		if(divid=='diary')
		{
			targetobj.style.display = "";
			if(document.getElementById('tishi')!=null)
			{
				document.getElementById('tishi').style.display="none";
			}
		}		
	};
	myOpen.loaded(subpage, "GET", "userid=" +id+ "&TemplateID=" +templateid, showDone);
}

//首页相册（幻灯版)
function GetIndexPhoto(userid)
{
	var paras;
	var typeindex = document.location.href.indexOf("type=");
	if(typeindex!=-1)
	{
		var type = document.location.href.substr(typeindex+5, 1)
		paras = "userid=" +userid+ "&type=" +type;
	}
	else
	{
		paras = "userid=" +userid;
	}
	
	var myOpen = new Xmopen();
	var showDone = function (oXML) 
	{	
		var result = oXML.responseText;
		if(result!="")
		{
			document.getElementById("divImageAll").innerHTML = result.split("@@")[1];
			//oImage=document.getElementById("ZoomImage");
			//photoNumber=parseInt(result.split("@@")[0]);
			//rTime=window.setInterval(Move,3000);
		}
		else
		{
			document.getElementById("divImageAll").innerHTML = "";
			//document.getElementById("photo").style.display="block";
		}	
	};
	myOpen.loaded("indexPhotoShow.aspx", "GET", paras, showDone);
}

//专门返回主页的photo的函数
function GetIndexPhotoAjax(id,templateid,divid,subpage)
{
	var myOpen = new Xmopen();
	var showDone = function (oXML) 
	{	
		var ts = document.getElementById('hidd').value;
		if(ts>=4)
		{
			//movejs();
			document.getElementById(divid).innerHTML = "<marquee scrollamount='2' direction='left' behaviour='scroll' onmouseover='stop()' onmouseout='start()'>" +oXML.responseText+ "</marquee>";
		}
		else
		{
			document.getElementById(divid).innerHTML = oXML.responseText;
		}
	};
	myOpen.loaded(subpage, "GET", "userid=" +id+ "&TemplateID=" +templateid, showDone);
}
 
//返回日记的所有列表函数
function ToShowDiaryList(pageindex,userid)
{
	var myOpen = new Xmopen();
	var showDone = function (oXML) 
	{	
		document.getElementById("diarylist").innerHTML = oXML.responseText;
	};
	myOpen.loaded("IndexDiaryList.aspx", "GET", "userid=" +userid+ "&PageIndex=" +pageindex, showDone);
}

function movejs()
{
	var speed=30;
	demo2.innerHTML=demo1.innerHTML;
	function Marquee()
	{
		if(demo2.offsetWidth-demo.scrollLeft<=0)
			demo.scrollLeft-=demo1.offsetWidth;
		else
		{
			demo.scrollLeft++;
		}
	}
	MyMar=setInterval(Marquee,speed)
	demo.onmouseover=function() {clearInterval(MyMar)}
	demo.onmouseout=function() {MyMar=setInterval(Marquee,speed)}
}
 
function showfriendlink(obj)
{
	if((obj.height/obj.width)>0.4)
	{ 
		if(obj.height>80)
		{ 
		   obj.resized=true;
		   obj.height=80;
		}
	} 
	else
	{ 
		if(obj.width>200)
		{
			obj.resized=true;
			obj.width=200;
		}
	}
}

//连播歌词
/*
function getlyric()
{
	var obj = document.getElementById("lyric");
	obj.innerHTML = "下载好友列表...";
	try
	{
		oXmlHttp.open("GET", "Getlyric.aspx", true);
		oXmlHttp.onreadystatechange = filllyrics;
		oXmlHttp.send(null);
	} catch (e) {
	}
}

function filllyrics()
{
	try{
		if(oXmlHttp.status == 200)
		{
			var obj = document.getElementById("lyric");
			//alert(oXmlHttp.responseText);
			obj.innerHTML = oXmlHttp.responseText;
		}
	}catch(e){}
}
*/

function ToShowCommentList(pageindex,id,divid,tableid)
{	
	var myOpen = new Xmopen();
	var showDone = function (oXML) 
	{	
		document.getElementById(divid).innerHTML = oXML.responseText;
	};
	myOpen.loaded("AllCommentPager.aspx", "GET", "id=" +id+ "&PageIndex=" +pageindex+ "&table=" +tableid, showDone);
}

//加一类型，type:1表示老版本，2表示新版本
function GetIndexPhotoList(divid,userid,pg,albumid,type)
{
	stopmovejs();
	
	var myOpen = new Xmopen();
	var showDone = function (oXML) 
	{	
		document.getElementById(divid).innerHTML = oXML.responseText;
		
		if(document.getElementById('hiddphoto')!=null)
		{
			var hidph=document.getElementById('hiddphoto').value;
			InsertHtmlPhoto(pg,hidph,albumid,userid,type);
		}
		else
		{
			if(type==2)
			{
				document.getElementById('photoup').innerHTML=" ";
				document.getElementById('photodown').innerHTML=" ";
			}
			else
			{
				document.getElementById('photoup').innerHTML="<img src='Common/images/NewImg/prev2.png' title='无上一页' />";
				document.getElementById('photodown').innerHTML="<img src='Common/images/NewImg/next2.png' title='无下一页' />";
			}
		}
		if(document.getElementById('hidd')!=null)
		{
			var ts= document.getElementById('hidd').value;
			if(ts>=4)
			{
				movejs();
			}
			PhotoShowInit();
		}			
	};
	myOpen.loaded("NewGetPhoto.aspx", "GET", "userid=" +userid+ "&PageIndex=" +pg+ "&albumid=" +albumid+ "&type=" +type, showDone);
}

function stopmovejs()
{
	if(document.getElementById('demo2')!=null)
	{
		document.getElementById('demo2').innerHTML="";
	}

	if(MyMar!=null)
	{
		clearInterval(MyMar);
	}
}

function GetIndexAlbumList(divid,userid,pg,subpage)
{
	var myOpen = new Xmopen();
	var showDone = function (oXML) 
	{ 
		if(subpage == "GetMtvAlbum.aspx" && pg==0)
		{
			//result += "<scri" + "pt defer>addplay();</scri" + "pt>";
			getMtvComment(userid);	
		}		
		document.getElementById(divid).innerHTML = oXML.responseText; 	
	};
	myOpen.loaded(subpage, "GET", "userid=" +userid+ "&PageIndex=" +pg, showDone);
}

function GetIndexNewAlbumList(divid,userid,pg,subpage,type)
{
	var myOpen = new Xmopen();
	var showDone = function (oXML) 
	{ 	
		document.getElementById(divid).innerHTML = oXML.responseText; 	
	};
	myOpen.loaded(subpage, "GET", "userid=" +userid+ "&PageIndex=" +pg+ "&type=" +type, showDone);
}

function addplay()
{
	var mvlist = document.getElementById("photolist");
	if(mvlist)
	{
		var imgs = mvlist.getElementsByTagName("img");
		for(var i=0; i<imgs.length; i++)
		{
			var div = imgs[i].parentElement.nextSibling;
			div.style.top = (45+1*i) +"px";
			div.style.left = "55px";
		}
	}
}

function getMtvComment(userid)
{
	var myOpen = new Xmopen();
	var showDone = function (oXML) 
	{	
		document.getElementById("commentlist").innerHTML = oXML.responseText; 	
	};
	myOpen.loaded("GetMtvComment.aspx", "GET", "userid=" +userid, showDone);
}

 
//新的留言采用的js,由于函数不能采用同一页面处理，新开一个js函数处理 加一参数 type
function NewgetReplayMemoResult(target_id,code_url,value,table,ispuc,type)
{
	len=value.length;
	if(len < 2 )
	{
		alert("输入的字符不能少于2个");
		return;
	}
    if(len > 125)
    {
		alert("输入的字符不能多于125个");
		return;
	}
	
	var strreg=/\[swf\]\d+.gif\[\/swf\]/img;
	var ms=value.match(strreg);

    if(ms!=null)
    {
		if(ms.length>3)
		{
			alert("魔法表情不能多于3个！");
			return;
		}
	}
	var filterValue=value.replace(/^\s*/i,'');
    filterValue=filterValue.replace(/╱°*/gim,'"');
    filterValue=escape(filterValue);
	try 
	{	
		var myOpen = new Xmopen();
		var showDone = function (oXML) 
		{ 	
			var result = oXML.responseText; 
			if(result=="$%^&*@!+)sgsg#$&*@#")
			{
				alert("对不起!出现意外，请稍后再试！");
			}		
			else
			{
				target_id.innerHTML = result;
				boxhidden(); //close box
			}
			if(document.getElementById('hiddenpub').value==0)
			{
				alert("留言成功！");
			}
			else if(document.getElementById('hiddenpub').value==1)
			{
				alert("该用户设定只有VIP才能给他留言或评论！");
				window.open('http://www.9158.com/Vip.html');
			}
			else if(document.getElementById('hiddenpub').value==2)
			{
				alert("该用户拒绝任何人给他留言或评论！");
			}
			else if(document.getElementById('hiddenpub').value==3)
			{
				alert("您已被对方加入黑名单，无权留言或评论！");
			}
			else if(document.getElementById('hiddenpub').value==4)
			{
				alert("普通用户每天只能发50条留言.VIP享有更多特权！");
				window.open("http://www.9158.com/Vip.html");
			}
			else if(document.getElementById('hiddenpub').value==5)
			{
				alert("对不起,只有VIP用户才可以发表私密留言!");
				window.open("http://www.9158.com/Vip.html");
			}
			else if(document.getElementById('hiddenpub').value==6)
			{
				alert("该用户设定只有好友才能给他留言或评论！");
			}
			else if(document.getElementById('hiddenpub').value==7)
			{
				alert("您未设置形象照，请到您的相册上传照片，并设为形象照后再发布留言或评论！");
				window.open('NoPhoto.aspx','暂无形象照','height=400,width=600,top=0,screenX=200,screenY=200,left=0,toolbar=no,menubar=no,scrollbars=yes, resizable=no,location=no, status=no,z-look=yes');
			}
			else if(document.getElementById('hiddenpub').value==8)
			{
				alert("VIP用户每天只能发100条留言！");
			}
			else
			{
				alert("登陆用户才能发表留言,请先登陆!");
			}	
		};
		myOpen.loaded("NewGetMemo.aspx", "POST", "hiddenCid=" +code_url+ "&table=" +table+ "&IsPuc=" +ispuc+ "&type=" +type+ "&memo=" +filterValue, showDone);
	}
	catch(e)
	{
		// do nothing
	}
}

function InsertHtmlPhoto(pg1,pg2,alid,usid,typeid)
{
	if(parseInt(pg1)==0)
	{
		if(parseInt(pg2)>1)
		{
			if(typeid==2)
			{
				document.getElementById('photoup').innerHTML="";
				document.getElementById('photodown').innerHTML="<a class='next' title='下一页' onclick=\"GetIndexPhotoList('demo1','"+usid+"',1,"+alid+","+typeid+")\" style='CURSOR: hand;'>下一页</a>";
			}
			else
			{
				document.getElementById('photoup').innerHTML="<img src='Common/images/NewImg/prev2.png' title='无上一页' />";
				document.getElementById('photodown').innerHTML="<img src='Common/images/NewImg/next.png' title='下一页' onclick=\"GetIndexPhotoList('demo1','"+usid+"',1,"+alid+","+typeid+")\" style='CURSOR: hand;'/>";
			}
		}
		else
		{
			if(typeid==2)
			{
				document.getElementById('photoup').innerHTML="";
				document.getElementById('photodown').innerHTML="";
			}
			else
			{
				document.getElementById('photoup').innerHTML="<img src='Common/images/NewImg/prev2.png' title='无上一页' />";
				document.getElementById('photodown').innerHTML="<img src='Common/images/NewImg/next2.png' title='无下一页' />";
			}
		}
	}
	else
	{
		if(parseInt(pg2)-parseInt(pg1)==1)
		{
			if(typeid==2)
			{
				document.getElementById('photoup').innerHTML="<a class='prev' style='cursor: hand;' onclick=\"GetIndexPhotoList('demo1','" +usid+ "'," +(parseInt(pg1)-1)+"," +alid+ "," +typeid+ ")\" title='上一页'>上一页</a>";
				document.getElementById('photodown').innerHTML="";
			}
			else
			{
				document.getElementById('photoup').innerHTML="<img style='cursor: hand;' src='Common/images/NewImg/prev.png' onclick=\"GetIndexPhotoList('demo1','" +usid+ "'," +(parseInt(pg1)-1)+ ","+alid+ "," +typeid+ ")\" title='上一页'/>";
				document.getElementById('photodown').innerHTML="<img src='Common/images/NewImg/next2.png' title='无下一页' />";
			}
		}
		else
		{
			if(typeid==2)
			{
				document.getElementById('photoup').innerHTML="<a class='prev' style='cursor: hand;' onclick=\"GetIndexPhotoList('demo1','" +usid+ "'," +(parseInt(pg1)-1)+ "," +alid+ "," +typeid+ ")\" title='上一页'>上一页</a>";
				document.getElementById('photodown').innerHTML="<a class='next' style='cursor: hand;' onclick=\"GetIndexPhotoList('demo1','" +usid+ "'," +(parseInt(pg1)+1)+ "," +alid+ "," +typeid+ ")\" title='下一页'>下一页</a>";
			}
			else
			{
				document.getElementById('photoup').innerHTML="<img style='cursor: hand;' src='Common/images/NewImg/prev.png' onclick=\"GetIndexPhotoList('demo1','" +usid+ "'," +(parseInt(pg1)-1)+ "," +alid+ ","+typeid+")\" title='上一页'/>";
				document.getElementById('photodown').innerHTML="<img style='cursor: hand;' src='Common/images/NewImg/next.png' onclick=\"GetIndexPhotoList('demo1','" +usid+ "'," +(parseInt(pg1)+1)+ "," +alid+ "," +typeid+ ")\" title='下一页'/>";
			}
		}
	}
}
 
//返回密码
function SendPassword(typenum)
{
	if((document.getElementById('demo1')!=null)&&(document.getElementById('passuserid')!=null)&&(document.getElementById('passhidden')!=null)&&(document.getElementById('passalbumid')!=null))
   	{
   		var passuseridvalue=document.getElementById('passuserid').value;
   		var passhiddenvalue=document.getElementById('passhidden').value;
   		var passalbumidvalue=document.getElementById('passalbumid').value+"&hiddenpass="+passhiddenvalue;
   	}
   	GetIndexPhotoList('demo1',passuseridvalue,0,passalbumidvalue,typenum);
}
 
//留言分页显示
function ToShowMemoList(pageindex,userid,type)
{
	var myOpen = new Xmopen();
	var showDone = function (oXML) 
	{	
		document.getElementById("memoid").innerHTML = oXML.responseText; 	
	};
	myOpen.loaded("NewGetMemo.aspx", "GET", "userid=" +userid+ "&PageIndex=" +pageindex+ "&type=" +type, showDone);
}

//开场动画不存在自动播放背景音乐
document.onreadystatechange=function()
{
	if(document.readyState=="complete")
	{
		if(isNull(getObject("mFlash")))
		{
			if(!isNull(getObject("WMPlayer")))
			{
				getObject("WMPlayer").controls.play();
			}
		}
	}
}

function isNull(A){return(A==""||A==null||A=="undefined");}

//红人 更新推荐视频
function RecommendVideo(blogownerid,videoid)
{
	
	var myOpen = new Xmopen();
	var showDone = function (oXML) 
	{	
		var result = oXML.responseText;	
		if(result=="1")
		{
			alert('设置成功!');
		}
		else
		{
			alert('设置失败!'+ result);
		}
	};
	myOpen.loaded("Ajax_StarUpdateRecommendVideo.aspx", "POST", "blogownerid="+blogownerid+"&videoid="+videoid, showDone);
}
