var isgflashover=0;
var flash_cookies_id="imflash";
var chat_url="http://www.anngo.net:2121";
var flash_cookies_trynum = 0;
var flash_cookies_maxtrynum = 3;
var meiji_flash_id = "";
var Is_Meiji_ChatMsg = false;
var clicktime = (new Date()).getTime();
mflash_referer = escape(mflash_referer.replace(/<.*?>/g, '').replace(/&acute;/g, '\'')).replace(/\//g, '%2F');

var curdomain = '';
var jsreferer = GetMJReferrer();
if(jsreferer != ''){
   if(GetMJDomain(jsreferer,false) == GetMJDomain('',false)){
	  curdomain = GetMJDomain('',true);
	  if(curdomain != ''){curdomain = escape(curdomain.replace(/&acute;/g, '\'')).replace(/\//g, '%2F');}
   }else if(mflash_referer == ''){
   	  mflash_referer = escape(jsreferer.replace(/&acute;/g, '\'')).replace(/\//g, '%2F');
   }
}

function GetMJReferrer(){
   var ref = ''; 
   if(document.referrer.length > 0){ 
      ref = document.referrer; 
   } 
   try{ 
      if(ref.length == 0 && opener.location.href.length > 0){ 
         ref = opener.location.href;
      } 
   }catch(e){}
   return ref;
}

function GetMJDomain(domain,ishttp){
	var main = '';
	if(domain == ''){domain = document.location.href;}
	if(domain != ''){
	   domain = domain.toLowerCase();
	   if(ishttp){
		  var temp = GetMJDomain(domain, false);
		  if(temp != '' && domain.substring(0,7) == 'https:/'){
		  	  main = 'https://'+temp;
		  }else{
		  	  main = 'http://'+temp;
		  }
	   }else{
		  if(domain.substring(0,7) == 'https:/'){
		  	  domain = domain.substring(8,domain.length);
		  }else{
		  	  domain = domain.substring(7,domain.length);
		  }
		  if(domain.indexOf("/") > -1){
		  	  main = domain.substring(0,domain.indexOf("/"));
		  }else{
		  	  main = domain;
		  }
	   }
	}
	return main;
}

function tsss(){alert(GetFlash_NowDay());}

function sfctodo(str){}

function thisMovie(movieName) { 
   if(navigator.appName.indexOf("Microsoft") != -1){ 
     return window[movieName] 
   }else { 
     return document[movieName]; 
   }            
} 

function setisgetflashover(n){
   isgflashover=1;
}

function SetFlashCookies(fname,fvalue){
  try{
     thisMovie(flash_cookies_id).SetFlashCookies(fname,fvalue); 
     return true;
  }catch(e){
     return false;
  }
}

function GetFlashCookies(fname){
   try{
      var results=thisMovie(flash_cookies_id).GetFlashCookies(fname);
      if(isgflashover==1){
         return results;
      }
   }catch(e){
      return "tryerr";
   }
}

function GetFlash_NowDay(){
   var now= new Date(); 
   var year=now.getYear(); 
   var month=now.getMonth()+1; 
   var day=now.getDate(); 
   var hour=now.getHours(); 
   var minute=now.getMinutes(); 
   var second=now.getSeconds(); 
   return year+""+month+""+day+""+hour+""+minute+""+second;
}

function Meiji_JsReturn(id,shopidmsg){
   if(parseInt(id) > 0){
       flash_cookies_trynum = 0;
       meiji_flash_id = "meijikf_uid_"+id;
       SetFlashCookies("meijikf_uid","meijikf_uid_"+id);
       setLkecnCookie("meijikf_uidcook","meijikf_uid_"+id,300);
       if(shopidmsg!=''){Meiji_ChatMsg(id,shopidmsg);}
       setTimeout(TryToTimeOut,60000);
   }else{
   	   meiji_flash_id = "nojs";
   }
}

function TryToTimeOut(){
   if(Is_Meiji_ChatMsg == false){
      try{
   	     if(document.getElementById("meijidivobject")){
   	  	    document.getElementById("meijidivobject").innerHTML="";
   	  	    var flashuid = "0";
   	  	    if(meiji_flash_id != ""){flashuid = meiji_flash_id.replace("meijikf_uid_","")}
            var Elements = document.getElementById("meijidivobject");
            var oScript = document.createElement("script");
            oScript.setAttribute("src",chat_url+"/user_status.aspx?flashuid="+flashuid+"&act=timeout&randtime="+GetFlash_NowDay());
            oScript.setAttribute("id","meijidivobject_js");
            oScript.setAttribute("type","text/javascript");
            oScript.setAttribute("language","javascript");
            Elements.appendChild(oScript);
   	     }
      }catch(e){}
   }else{
   	   setTimeout(TryToTimeOut,60000);
   }
}

function Meiji_JsTimeOutReturn(id,shopidmsg){
	if(id != "0"){
		if(meiji_flash_id.indexOf('meijikf_uid_') < 0){
			meiji_flash_id = "meijikf_uid_"+id;
		}
		isgflashover = 0;
		var resultid=GetFlashCookies("meijikf_uid");
		if(resultid=="tryerr" || isgflashover!=1){
			SetFlashCookies("meijikf_uid","meijikf_uid_"+id);
		}
		isgflashover = 0;
		if(shopidmsg!='' && Is_Meiji_ChatMsg == false){Meiji_ChatMsg(id,shopidmsg);}
	}
	setTimeout(TryToTimeOut,60000);
}

function TryToWaitingJs(){
   if(meiji_flash_id == ""){
       meiji_flash_id = "nojs";
       //alert("nojs");
   }
}

function Meiji_CreateJs(flashuid,act){
   try{
   	  document.getElementById("meijidivobject").innerHTML="";
      var Elements = document.getElementById("meijidivobject");
      var oScript = document.createElement("script");
      oScript.setAttribute("src",chat_url+"/user_status.aspx?flashuid="+flashuid+"&act="+act+"&mflash_uid=&mflash_username=&mflash_sessionid=&curdomain="+curdomain+"&mflash_referer="+mflash_referer+"&shoptype=lkecn&randtime="+GetFlash_NowDay());
      oScript.setAttribute("id","meijidivobject_js");
      oScript.setAttribute("type","text/javascript");
      oScript.setAttribute("language","javascript");
      Elements.appendChild(oScript);
      setTimeout(TryToWaitingJs,1000);
   }catch(e){
      if(flashuid=="0"){
      	  meiji_flash_id = "nojs";
      }
   }
}

function TryToGetCookMeijiUid(){
   var tempfuid = getLkecnCookie("meijikf_uidcook");
   if(tempfuid != ''){
	  if(tempfuid.indexOf("meijikf_uid_") > -1){
		 return tempfuid;
	  }
   }
   return "";
}

function TryToGetSWFObjectNotes(){
   var resultid=GetFlashCookies("meijikf_uid");
   if(resultid=="tryerr" || isgflashover!=1){
   	   flash_cookies_trynum++;
   	   if(flash_cookies_trynum <= flash_cookies_maxtrynum){
   	   	   setTimeout(TryToGetSWFObjectNotes,500);
   	   }else{
   	   	   resultid = TryToGetCookMeijiUid();
   	   	   if(resultid==""){
   	   	      Meiji_CreateJs(0,"insert");
   	   	   }else{
   	   	      meiji_flash_id = resultid;
   	   	      Meiji_CreateJs(resultid.replace("meijikf_uid_",""),"online");
   	   	   }
   	   }
   }else{
   	   flash_cookies_trynum = 0;
   	   if(typeof(resultid)=="undefined"){resultid="";}
   	   if(resultid==""){resultid = TryToGetCookMeijiUid();}
   	   if(resultid==""){
	 	   Meiji_CreateJs(0,"insert");
   	   }else{
   	   	   meiji_flash_id = resultid;
   	   	   Meiji_CreateJs(resultid.replace("meijikf_uid_",""),"online");
   	   }
   }
}

function opendialog(shopid){
	if(meiji_flash_id != "" || (new Date()).getTime() - clicktime > 1000 * 4){
		var flash_id = meiji_flash_id.replace("meijikf_uid_","");
		if(flash_id == "nojs"){flash_id = "";}
	    window.open('http://www.anngo.net/dialog.htm?shopid='+shopid+'&flash_id='+flash_id+'&meiji_flash_id='+meiji_flash_id+'&mflash_sessionid=&mflash_uid=&curdomain='+curdomain+'&mflash_referer='+mflash_referer+'&shoptype=lkecn','_blank','height=490,width=730,top=200,left=200,status=yes,toolbar=no,menubar=no,resizable=no,scrollbars=no,location=no,titlebar=no');
	    return true;
	}else{
		alert("数据正加载。。。\n\n请稍候再咨询");
		return false;
	}
}

function openwindialog(uid,shopid,act,num){
	//if(mflash_referer == '' && tempreferer != ''){mflash_referer = tempreferer;}
	if(num == 1){
	   try{
	   	   document.getElementById("Javascript.Meiji_ChatMsg").style.display="none";
	   }catch(e){}
	}
	window.open('http://www.anngo.net/dialog.htm?shopid='+shopid+'&flash_id='+uid+'&meiji_flash_id='+meiji_flash_id+'&mflash_sessionid=&mflash_uid=&todialog=yes&curdomain='+curdomain+'&mflash_referer='+mflash_referer,'_blank','height=490,width=730,top=200,left=200,status=yes,toolbar=no,menubar=no,resizable=no,scrollbars=no,location=no,titlebar=no');
}

function Meiji_CusName(id){
	var meijicus = new Array();
	meijicus[1] = '导购-小丽';
	meijicus[2] = '导购-婷婷';
	meijicus[3] = '售后-小妍';
	meijicus[4] = 'beam';
	meijicus[5] = '钊';
	meijicus[6] = '林卡尔代购网客服';
	meijicus[7] = 'beam0';
	if(typeof(meijicus[id]) != 'undefined'){
		return meijicus[id];
	}else{
	    return '客服';
	}
}

function MeijiChat_Scroll(){
   try{
      if(document.documentElement.scrollTop>0){
   	    document.getElementById("Javascript.Meiji_ChatMsg").style.top=(document.documentElement.scrollTop+document.documentElement.clientHeight-document.getElementById("Javascript.Meiji_ChatMsg").offsetHeight-5)+"px";
      }else{
        document.getElementById("Javascript.Meiji_ChatMsg").style.top=(document.body.scrollTop+document.documentElement.scrollTop+document.documentElement.clientHeight-document.getElementById("Javascript.Meiji_ChatMsg").offsetHeight-5)+"px";
      }
      document.getElementById("Javascript.Meiji_ChatMsg").style.left=(document.documentElement.scrollLeft+document.documentElement.clientWidth-document.getElementById("Javascript.Meiji_ChatMsg").offsetWidth-5)+"px";
   }catch(e){}
}

function Meiji_ChatMsg(uid,shopids){
   Is_Meiji_ChatMsg = true;
   var jstable="";
   var pid=shopids.split(",");
   jstable='<div id="Javascript.Meiji_ChatMsg" style="position:absolute;border:0;font-size:12px;z-index:9999;padding-top:4px;width:220px;height:100px">';
   jstable+='<div style="width:100%;"><div style="width:9px;height:27px;float:left;overflow:hidden;background:url(http://www.anngo.net:2121/images/chat_top_left.jpg);"></div><div style="width:154px;height:27px;float:left;overflow:hidden;background:url(http://www.anngo.net:2121/images/chat_top_middle.jpg);"><div style="padding-top:8px;font-weight:800;">您有新留言：</div></div><div style="width:57px;height:27px;float:right;overflow:hidden;"><a href="javascript:" onclick="Close_Meiji_ChatMsg('+uid+',0)"><img src="http://www.anngo.net:2121/images/chat_top_close.jpg" border="0"></a></div></div>';
   jstable+='<div style="width:218px;background-color:#FFFFFF;border:1px solid #7689BB;border-top:0;clear:both;">';
   jstable+='<div style="width:208px;height:80px;font-size:13px;text-align:left;padding:3px;margin-left:3px;overflow-y:auto;overflow-x:hidden;">';
   for(var i=0;i<pid.length;i++){
   	   jstable+='<div style="width:208px;height:25px;padding-top:3px;overflow:hidden;">';
   	   jstable+='<div style="width:180px;padding-top:9px;float:left"><a href="javascript:void(0)" style="color:#0044f0;text-decoration:underline;" onclick="openwindialog('+uid+','+pid[i]+',\'\','+pid.length+')">'+Meiji_CusName(pid[i])+'有新留言给您</a> <a href="javascript:void(0)" style="color:#bc0000;font-weight:800;text-decoration:underline;" onclick="openwindialog('+uid+','+pid[i]+',\'\','+pid.length+')">查看</a></div>';
   	   jstable+='<div style="width:26px;height:24px;overflow:hidden;float:left"><img src="http://www.anngo.net:2121/images/mychat.gif" /></div>';
   	   jstable+='</div>';
   }
   jstable+='</div>';
   jstable+='</div>';
   jstable+='</div>';
   document.getElementById("meijidivobject").innerHTML=jstable;
   window.onscroll=function(){MeijiChat_Scroll();};
   window.onresize=function(){MeijiChat_Scroll();};
   MeijiChat_Scroll();
}

function Close_Meiji_ChatMsg(uid,n){
	if(n==1){
	    Is_Meiji_ChatMsg = false;
	}else{
		try{
		   document.getElementById("Javascript.Meiji_ChatMsg").style.display="none";
		   document.getElementById("meijidivobject").innerHTML="";
           var Elements = document.getElementById("meijidivobject");
           var oScript = document.createElement("script");
           oScript.setAttribute("src",chat_url+"/user_status.aspx?uid="+uid+"&act=closegivewin&randtime="+GetFlash_NowDay());
           oScript.setAttribute("id","meijidivobject_js");
           oScript.setAttribute("type","text/javascript");
           oScript.setAttribute("language","javascript");
           Elements.appendChild(oScript);
        }catch(e){}
	}
}

if(typeof(SWFObject_flashck) != "undefined"){
   document.write('<div id="meijidivobject" style="width:1px;height:1px;overflow:hidden;"></div>');
   var so = new SWFObject_flashck(chat_url+"/flash/MeijiCookie.swf?"+GetFlash_NowDay(), flash_cookies_id, "1", "1", "8", "#ffffff");
   so.addParam("allowScriptAccess", "always");  //always、sameDomain、never
   so.addParam("wmode", "opaque");
   so.write("meijidivobject");
   so.addParam("menu", "false");
   setTimeout(TryToGetSWFObjectNotes,500);
}

