// JavaScript Document

var newmap;
var freind = new Array;
var usernick;
var lon_mover;
var lat_mover;
var info_mover;

var isreg;

var guid;
var aus;
var locat;

var status_reg = 0;
var status_noreg = 0;

var toadd;

var allow = 1;
var notallow=0;


var selectlab = 0;



var strxml = "<?xml version=\"1.0\" encoding=\"UTF-8\"?>"+
			"<GTReq GUID=\"{0}\" CMD=\"005\" STA=\"OK\">"+
			"<PS>"+"{1}"+
			"</PS>"+
			"</GTReq>";




function googleMap()
{
	
	
	if (GBrowserIsCompatible())
	{
		icon4 = new GIcon();
		icon4.image = "images/shape.gif";
		icon4.shadow = "";
		icon4.iconSize = new GSize(17, 19);
		icon4.shadowSize = new GSize(22, 20);
		icon4.iconAnchor = new GPoint(6, 20);
		icon4.infoWindowAnchor = new GPoint(5, 1);
						
		newmap = new GMap2(document.getElementById("MainBody")); 
		
		newmap.addControl(new GSmallMapControl()); 
		newmap.addControl(new GMapTypeControl());
		//newmap.setMapType(G_HYBRID_MAP);
		newmap.setCenter(new GLatLng(35,106),4);
	}
	
	
}

function userlocate(lon,lat)
{

	var userlon= lon.split("%");
	var userlat=lat.split("@");
	
	var usercount = userlon.length;
	
	var markerarr;
	
	for(var i=0;i<usercount - 1;i++)
	{
		
		markerarr = new GMarker(new GLatLng(parseFloat(userlat[i]),parseFloat(userlon[i])),icon4);
		newmap.addOverlay(markerarr);
	}
	
}

function splitter(resp)
{
	var arrRes = new Array;
	arrRes = resp.split("|||");
	return arrRes;
}

function userPointshow(lon,lat)
{
	//newmap.clearOverlays();
	var usermarker = new GMarker(new GLatLng(lat,lon),icon4);
	newmap.addOverlay(usermarker);
	
	
	newmap.setCenter(usermarker.getPoint(),15);
	
				
	
	
}

function tolocate()
{
	if($("#freindname").text() == "|||")
	{
		alert("请选择您要定位的用户。");
		return;	
	}
	
	if(isreg == 0 )
	{
		alert("需要通过对方授权才能定位对方。");
		return;
	}
	
	var locname = $("#freindname").text();
	
	var reqstring = "<6>&" + locname;
	$("div#divload").show();
	$("div#overlay").show();
	
	$.ajax({ url: "test.aspx",
			 type:"post", 
			 dataType:"json",
			 data: reqstring,
			 complete:  function(){$("div#divload").hide();$("div#overlay").hide();},          
			 success:function(response){ 
					//alert(response);	
					var command =  response.com;
					switch(command)
					{
						case "9":
							alert(response.error);
							break;
						case "6":
						
							if( response.lon == '' || response.lat == '' || response.loc == '')
								alert("对方未上传位置信息。");
							else
								//alert(response.lon +'|||||'+response.lat +'|||||'+response.loc);
								locatebyclick(response.lon,response.lat,response.loc);							
							break;
						
					}

				  } 
			 });

	
	
	
}









function locatebyclick(lon,lat,info)
{

	
	newmap.clearOverlays();
	var infohtml = "<table width='300' border=0 cellspacing=0 cellpadding=0><tr><td>"+info+"</td></tr></table>";
	
	var usermarker = new GMarker(new GLatLng(lat,lon),icon4);
	
	newmap.addOverlay(usermarker);
	newmap.setCenter(usermarker.getPoint(),15);
	usermarker.openInfoWindow(infohtml);
	
	
	
	
	
}


function usersel(index)
{
	if( selectlab != 0 )
	{
		
		$(selectlab).css("font-style","normal");	
	}
	var num = "#labelmover"+index;
	//alert($(num).text());
	$("#freindname").text($(num).text());
	$(num).css("font-style","italic"); 
	selectlab = num;
	
	
}

/*
function userPointshowAndTab(lon,lat,info)
{
	lon_mover = lon;
	lat_mover = lat;
	info_mover = info;
	var num = "#labelmover"+info;
	$("#freindname").text($(num).text());
	//$("#freindname").css({ background: "#FFFF00", float: "none" ,width:"100%"});				
}
*/

			 
			 
function clkLogin()
{
	
	if($("#nick")[0].value == "" )  
	{
		alert('昵称不能为空！');
		return;
	}
	
	if($("#pwd")[0].value == "" )  
	{
		alert('密码不能为空！');
		return;
	}
	
	var reqstring = "<1>&" + $("#nick")[0].value+"&"+$("#pwd")[0].value + "&" + guid +  "&" + aus;
	usernick = $("#nick")[0].value;
	$("div#divload").show();
	$("div#overlay").show();
	$.ajax({ url: "test.aspx",
			 type:"post", 
			 dataType:"json",
			 data: reqstring,
			 complete:  function(){$("div#divload").hide();$("div#overlay").hide();},          
			success:function(response){ 
					//alert(response);	
					var command =  response.com;
					switch(command)
					{
						case "9":
							alert(response.error);
							break;
						case "1":
						
							//locat = response.locate;
							var freinds = response.mover;
							freind = freinds.split('|||');
							$("#SidebarTOP").html(response.SidebarTOP);
							
							$("#reg").html(response.divReg);
							$("#notreg").html(response.divNotReg);
							$("#SidebarBOT").empty();										
							$("#SidebarBOT").html($("#userList"));
							$("#btn").show();
							//alert($("#SidebarBOT").html());
							break;
						
					}

				  } 
			 });

}

function showreg(status)
{
	switch(status)
	{
		case 0:
			$("div#reg").hide();
			$("#showreg").attr("src","images/arrow_heng.jpg");
			status_reg = 1;
			break;
		case 1:
			$("div#reg").show();
			$("#showreg").attr("src","images/arrow_shu.jpg");
			status_reg = 0;
			break;
	}
		
		
	
}


function shownoreg(status)
{
	switch(status)
	{
		case 0:
			$("div#noreg").hide();
			$("#shownoreg").attr("src","images/arrow_heng.jpg");
			status_noreg = 1;
			break;
		case 1:
			$("div#noreg").show();
			$("#shownoreg").attr("src","images/arrow_shu.jpg");
			status_noreg = 0;
			break;
	}
}


function  clkLoginOut()
{
	var reqstring = "<9>&" +  guid ;
	
	$("div#divload").show();
	$("div#overlay").show();
	$.ajax({ url: "test.aspx",
			 type:"post", 
			 dataType:"json",
			 data: reqstring,
			 complete:  function(){$("div#divload").hide();$("div#overlay").hide();},          
			success:function(response){ 
					var command =  response.com;
					switch(command)
					{
						case "9":
							alert(response.error);
							break;
						case "1":
							window.location.href="webtoy.html";									
							break;
						
					}
				} 
			 });

}

function addshow()
{
	$("div#adddiv").show();
	$("div#overlay").show();
}

function renturnto()
{
	
	
	$("div#adddiv").hide();
	$("div#overlay").hide();
}

function  checkuserlist()
{

	var reqstring = "<2>&" +$("#addnick")[0].value;
	$("div#divload").show();
	//$("div#overlay").show();
	$.ajax({ url: "test.aspx",
			 type:"post", 
			 dataType:"json",
			 data: reqstring,
			 complete:  function(){$("div#divload").hide();},//$("div#overlay").hide();},          
			success:function(response){ 
					var command =  response.com;
					switch(command)
					{
						case "9":
							alert(response.error);
							break;
						case "2":
							$("#adduserlist").html(response.nicklist);		
							break;
						
					}
					
				} 
			 }); 
}

function addnew()
{
	
	toadd = $("input[@type=radio][@checked]").val();

	var reqstring = "<3>&" + guid +"&"+toadd+"&"+usernick;
	$("div#divload").show();
	//$("div#overlay").show();
	$.ajax({ url: "test.aspx",
			 type:"post", 
			 dataType:"json",
			 data: reqstring,
			 complete:  function(){$("div#divload").hide();},//$("div#overlay").hide();},          
			success:function(response){ 
					var command =  response.com;
					switch(command)
					{
						case "9":
							alert(response.error);
							break;
						case "3":	
						
							locat = response.locate;
							var freinds = response.mover;
							freind = freinds.split('|||');
							
							$("#reg").html(response.divReg);
							$("#notreg").html(response.divNotReg);
							//$("#SidebarBOT").empty();										
							//$("#SidebarBOT").html($("#userList"));	
							//alert($("#SidebarBOT").html());
							alert(response.content);
							renturnto();
							break;
						
					}
					
				} 
			 }); 

}

function flashlist()
{
	var reqstring = "<4>&" + guid +"&"+usernick;
	$("div#divload").show();
	$("div#overlay").show();

		$.ajax({ url: "test.aspx",
			 type:"post", 
			 dataType:"json",
			 data: reqstring,
			 complete:  function(){$("div#divload").hide();$("div#overlay").hide();},          
			success:function(response){ 
					var command =  response.com;
					switch(command)
					{
						case "9":
							alert(response.error);
							break;
						case "4":	
							
							locat = response.locate;
							var freinds = response.mover;
							freind = freinds.split('|||');
							$("#reg").html(response.divReg);
							$("#notreg").html(response.divNotReg);
							$("#freindname").text("|||");
							break;
						
					}
					
				} 
			 }); 
	
	
}
function openDialogWin()
{
		if($("#freindname").text() == "|||")
		{
			alert("请选择您要删除的用户。");
			return;	
		}
		var delname  = "确定要删除  "+$("#freindname").text()+ "  ?";
		$("#delmesg").text(delname);
		$("div#deldiv").show();		
		$("div#overlay").show();
	
}

function todel()
{
	$("div#deldiv").hide();		
	$("div#overlay").hide();
	deleteuser();
}

function notodel()
{
		$("div#deldiv").hide();		
		$("div#overlay").hide();
}







function deleteuser()
{
		//alert($("#freindname").text());
		
		var reqstring = "<5>&" + guid +"&"+$("#freindname").text();
		$("div#divload").show();
		$("div#overlay").show();

		$.ajax({ url: "test.aspx",
			 type:"post", 
			 dataType:"json",
			 data: reqstring,
			 complete:  function(){$("div#divload").hide();$("div#overlay").hide();},          
			success:function(response){ 
					var command =  response.com;
					switch(command)
					{
						case "9":
							alert(response.error);
							break;
						case "5":	
							locat = response.locate;
							var freinds = response.mover;
							freind = freinds.split('|||');
							$("#reg").html(response.divReg);
							$("#notreg").html(response.divNotReg);
							alert(response.content);
							break;
						
					}
					
				} 
			 }); 
			
	
}

function overuser(index)
{
	
	var labelindex = "#labelmover"+index;
	$(labelindex).css({ background: "yellow" }); 	
}

function outuser(index)
{
	
	var labelindex =  "#labelmover"+index;
	$(labelindex).css({ background: "white" }); 	
}


function imgout(index)
{
 	switch(index)
	{
		case 1:
			$("#locatelist").attr("src","images/定位.jpg"); 
			break;
		case 2:
			$("#flashlist").attr("src","images/刷新.jpg"); 
			break;
		case 3:
			$("#addlist").attr("src","images/添加用户.jpg"); 
			break;
		case 4:
			$("#deletelist").attr("src","images/删除用户.jpg"); 
			break;
		
	}

}


function imgover(index)
{
	switch(index)
	{
		case 1:
			$("#locatelist").attr("src","images/定位_lk.jpg"); 
			break;
		case 2:
			$("#flashlist").attr("src","images/刷新_lk.jpg"); 
			break;
		case 3:
			$("#addlist").attr("src","images/添加用户_lk.jpg"); 
			break;
		case 4:
			$("#deletelist").attr("src","images/删除用户_lk.jpg"); 
			break;
		
	}

}