﻿
function Friend()
{
	var ServerPath="http://www.bluecat.net.cn/";
	//var ServerPath="http://localhost/newmedia/newmedia/";	
		
	this.initoption=function()
	{
		for(i=1;i<81;i++){
			addoptions("age_from",i,i);
			addoptions("age_to",i,i);
		}
		//选择年龄
		//var agefrom=getValueById('hidage_from');	
		//var ageto=getValueById('hidage_to');
		
		autoSelect("age_from","");
		autoSelect("age_to","");
	}
	
	this.initoptionandselect=function()
	{
		for(i=1;i<81;i++){
			addoptions("age_from",i,i);
			addoptions("age_to",i,i);
		}
		//选择年龄
		var agefrom=getValueById('hidage_from');	
		var ageto=getValueById('hidage_to');
		
		autoSelect("age_from",agefrom);
		autoSelect("age_to",ageto);
	}
	this.ShowResult=function(PageIndex)
	{
		setInnerHtmlById('result',getHttpHtml(ServerPath+'Mybluecat/Friend/Result.aspx?PageIndex='+PageIndex+'&cacheid='+Math.random()));
		
	}
	
	this.OpenWin=function(Type)
	{		
		this.InitSession(Type);
		window.open(ServerPath+'Friend/Query','');		
	}
	
	this.InitSession=function(Type)
	{
		if(Type=='1')
		{
			//var returnValue=AjaxMethod.UpdateSession(Type,',RealName,agefrom,ageto,Sex,rfyear,rfmonth,rfday,rtyear,rtmonth,rtday,bfyear,bfmonth,bfday,btyear,btmonth,btday,province,city).value;
			var returnValue=AjaxMethod.UpdateSession(Type,'','','','','','','','','','','','','','','','','','','').value;
			if(returnValue==false)
			{
				alert("初始化失败");
			}	
		}
		else
		{
			var NC=document.getElementById("lnc").value; //昵称
			var RealName=getValueById('realname'); //真实姓名
			var agefrom=getValueById('age_from');
			var ageto=getValueById('age_to');
			
			var Sex='';
			var sex1=document.getElementById('sex1'); //男
			if(sex1.checked==true)
			{
				Sex='男';
			}
					
			var sex2=document.getElementById('sex2'); //女
			if(sex2.checked==true)
			{
				Sex=Sex+'女';
			}
					
			var rfyear=getValueById('rfyear'); //入住时间：从年		
			var rfmonth=document.getElementById("rfmonth").value; //入住时间：从月
			var rfday=getValueById('rfday'); //入住时间：从日
			
			var rtyear=getValueById('rtyear'); //入住时间：到年
			var rtmonth=getValueById('rtmonth'); //入住时间：到月
			var rtday=getValueById('rtday'); //入住时间：到日
			
			var bfyear=getValueById('bfyear'); //生日：从年
			var bfmonth=getValueById('bfmonth'); //生日：从月
			var bfday=getValueById('bfday'); //生日：从日
			
			var btyear=getValueById('btyear'); //生日：到年
			var btmonth=getValueById('btmonth'); //生日：到月
			var btday=getValueById('btday'); //生日：到日
			
			var province=getValueById('province'); //省份
			var city=getValueById('city'); //城市
			
			var returnValue=AjaxMethod.UpdateSession(Type,NC,RealName,agefrom,ageto,Sex,rfyear,rfmonth,rfday,rtyear,rtmonth,rtday,bfyear,bfmonth,bfday,btyear,btmonth,btday,province,city).value;
			//var returnValue=AjaxMethod.UpdateSession(Type,NC,RealName,agefrom,ageto,Sex,'','','','','','','','','','','','',province,city).value;
			if(returnValue==false)
			{
				alert("初始化失败");
			}		
		
		}
	}
	
	this.Search=function(Type,PageIndex)
	{		
		setInnerHtmlById('result','Loading.....');
		this.InitSession(Type);
		this.ShowResult(PageIndex);
	}
	
	
	this.invite_friend=function()
	{
		var sname=getValueById('iOwner');	
		//先判断是否已经登录，如果没登录出示提示框
		var returnValue=AjaxMethod.IsLogon().value;
		if(returnValue==false)  //说明没有登录
		{
			alert("您还没有登录，请先登录，再点击此按钮");
			ShowHide();
		}
		else
		{
			var ret=AjaxMethod.AddFriend(sname).value;
			if(ret==true)
			{
				alert("添加成功！");
			}
			else
			{
				alert("添加失败！");
			}
		}
	}
	
	this.LoadFriend=function(PageIndex)
	{
		var sname=getValueById('iOwner');	
		var shlink=getValueById('iHomeLink');			
		setInnerHtmlById('right_info',getHttpHtml(ServerPath+'Mybluecat/Friend/FriendList.aspx?OwnerName='+escape(sname)+'&HomeLink='+shlink+'&PageIndex='+PageIndex+'&cacheid='+Math.random()));
		var showname=AjaxMethod.GetShowName(sname).value;
		window.document.title=showname+"--"+sname+'--亲友团';
	}
	
	this.DeleteFriend=function(fname,PageIndex)
	{
		var sname=getValueById('iOwner');
		var returnValue=AjaxMethod.DelFriend(sname,fname).value;
		if(returnValue==false)
		{
			alert("删除失败！");
			return;
		}
		else
		{
			alert("删除成功");
			this.LoadFriend(PageIndex);
		}
			
	}
}
