﻿
function insideUserLogin(username,userid)
{
	//alert(username);
	var ajax=new AJAXRequest;
	ajax.get(
		"j.aspx?action=insideUserlogin&n="+Math.random()+"&name="+encodeURIComponent(username)+"&userid="+encodeURIComponent(userid),
		function(obj) {
			//alert(obj.responseText);

			window.open('http://iss.homelink.com.cn/iss2/linkmanWin.html?myloginId='+userid+'&username='+username,'linkWin'+userid,'width=215,height=560,resizable=no');

		}
	);
}



function isstouser(userid)
{
//alert(userid)

window.open('http://iss.homelink.com.cn/iss2/chatWindow.html?touserid='+userid,'ISSW'+userid,'width=630,height=520,resizable=no');
	//window.open('http://passport.homelink.com.cn/iss/sms.htm?touserid='+userid,'ISSW'+userid,'width=800,height=500,resizable=yes');
	//window.open('/iss/sms.htm?touserid='+userid,'ISSW'+userid,'width=800,height=500');
}


function LoadMsg()
{
	//alert(document.getElementById("msg").document.getElementById("viewmsg").innerHTML);  
	//alert(document.frames["msg"].document.getElementById("viewmsg").innerHTML);
	//alert(lastreadid);
	//alert(window.frames["msg"].offsetTop);
	//alert(document.frames["msg"].document.body.offsetHeight );
	var ajax=new AJAXRequest;
	//alert(getCookie('iis_lastloadid'));
	ajax.get(
		"j.aspx?action=read&n="+Math.random()+"&lastid="+encodeURIComponent(getCookie('iis_lastloadid')),
		function(obj) {
		//alert(obj.responseText);
			if(obj==null)
				return ;
			var mygms=eval(obj.responseText);
			var outhtml='';
			for (var k in mygms) {
			//outhtml+='<br>';
			/*
			if(lastspeaker!=mygms[k].FormUserName)
				outhtml+=' <b>'+CovCode(mygms[k].FormUserName)+'</b>  <i class=datecss>'+mygms[k].Date+'</i> :';
			else
				outhtml+='　<i class=datecss>'+mygms[k].Date+'</i> :';
			outhtml+="<br><blockquote>"+CovCode(mygms[k].Message)+"</blockquote>";
			*/
			//lastreadid=eval(mygms[k].Index);
			setCookie('iis_lastloadid',mygms[k].Index,null,null,null,null);
			isstouser(mygms[k].FormUserName);
			//lastspeaker=mygms[k].FormUserName
			}
			outhtml+='';
			//document.getElementById("msg").innerHTML+=outhtml; 
			
			}
			//lastreadid++;
		//}
	);
}
function getCookieVal(offset) {
  var endstr = document.cookie.indexOf (";", offset);
  if (endstr == -1) {
    endstr = document.cookie.length;
  }
  return unescape(document.cookie.substring(offset, endstr));
}
function getCookie(name) {
  var arg = name + "=";
  var alen = arg.length;
  var clen = document.cookie.length;
  var i = 0;
  while (i < clen) {
    var j = i + alen;
    if (document.cookie.substring(i, j) == arg) {
      return getCookieVal(j);
    }
    i = document.cookie.indexOf(" ", i) + 1;
    if (i == 0) break;
  }
  return null;
}

function GetQueryvalue(sorStr,panStr) 
{ 

	var vStr=""; 
	if (sorStr==null || sorStr=="" || panStr==null || panStr=="") return vStr; 
	sorStr = sorStr.toLowerCase();
	panStr += "="; 
	var itmp=sorStr.indexOf(panStr); 
	if (itmp<0){return vStr;} 
	sorStr = sorStr.substr(itmp + panStr.length); 
	itmp=sorStr.indexOf("&"); 
	if (itmp<0)
	{
	return sorStr; 
	} 
	else 
	{
	sorStr=sorStr.substr(0,itmp); 
	return sorStr;
	} 
} 
// store cookie value with optional details as needed
function setCookie(name, value, expires, path, domain, secure) {
  document.cookie = name + "=" + escape (value) +
    ((expires) ? "; expires=" + expires : "") +
    ((path) ? "; path=" + path : "") +
    ((domain) ? "; domain=" + domain : "") +
    ((secure) ? "; secure" : "");
}


function InitNewISS(obje)
{
	var cget=getCookie('iis_lastloadid');
	if(cget==null)
		setCookie('iis_lastloadid','-1',null,null,null,null);
	var ajax=new AJAXRequest;
	ajax.get(
		"j.aspx?action=getmsgcount",
		function(obj) {
			//alert(obj.responseText);

				if(obj==null || obj.responseText==null || obj.responseText=='')
				{
					obje.innerHTML="未读即时沟通信息（<font color=red>0条</font>）";
				}
				else
				{
					var ko=eval(obj.responseText)-getCookie('iis_lastloadid')-1;;
					/*
					var outhtml='';
					if(lastspeaker!=jsmyusername)
						outhtml+=' <b>'+CovCode(jsmyusername)+'</b>  <i class=datecss>'+new Date().toLocaleString()+'</i> :';
					else
						outhtml+='　　　<i class=datecss>'+new Date().toLocaleString()+'</i> :';
					outhtml+="<br><blockquote>"+CovCode(document.getElementById("sendmsg").value)+"</blockquote>";
	
					lastspeaker=jsmyusername;
					if(outhtml!=''){
					document.frames["msg"].document.getElementById("viewmsg").innerHTML+=outhtml; 
					window.frames["msg"].scroll(0,document.frames["msg"].document.body.offsetHeight);
					}
					*/
					obje.innerHTML="<a href=\"javascript:LoadMsg()\">未读即时沟通信息（<font color=red>"+ko+"条</font>）</a>";
				}
		}
	);
	
	}