
var kf_openurl="http://eca.dongfeng-nissan.com.cn/client.jsp?flag=1&companyId=2&style=316&locate=cn" +"&refer="+ escape(window.location.href)+"&username="+encodeURIComponent("");
//路径
var route = escape(window.location.href);

var kdocTitle = document.title;//标题 
if(kdocTitle == null){ 
    var t_titles = document.getElementByTagName("title") 
    if(t_titles && t_titles.length >0) 
    { 
       kdocTitle = t_titles[0]; 
    }else{ 
       kdocTitle = ""; 
    } 
} 

function setCookie(name, value, path, domain) {
  var oCookie = name + "=" + escape(value) +
      "; expires=Thu, 6 Jan 2100 12:01:01 UTC" +
      ((path) ? "; path=" + path : "") +
      ((domain) ? "; domain=" + domain : "");
  document.cookie = oCookie;
}

function getCookie(name) {
  var dc = document.cookie;
  var prefix = name + "=";
  var begin = dc.indexOf("; " + prefix);
  if (begin == -1) {
    begin = dc.indexOf(prefix);
    if (begin != 0) return "";
  } else
    begin += 2;
  var end = document.cookie.indexOf(";", begin);
  if (end == -1)
    end = dc.length;
  return unescape(dc.substring(begin + prefix.length, end));
}

var  now  =  new  Date();  
var  ss  =  now.getTime() 

var temp_d = parseInt(Math.random() *10000);
var user_str = "" + ss + "_" + temp_d;

var userid = getCookie("kf51_userid");
if(userid == "" || userid == null)
{
	
	setCookie("kf51_userid",user_str);
	userid = user_str ;	
}

//alert("userid is-->" + getCookie("kf51_userid"));
var ref = document.referrer; 
var local_host = document.domain;
if(ref.indexOf(local_host) < 0)
{
	setCookie("kf51_referrer",ref);
}

function open_pic_chat(com_id,style_id)
{
	try
	{
		window_url ="http://eca.dongfeng-nissan.com.cn/client.jsp?flag=1&companyId="+com_id+"&style="+style_id+"&locate=cn" +"&refer="+ escape(window.location.href);
		var chat_win =  window.open(window_url,"chat_"+com_id,"height=473,width=703,top=200,left=200,status=yes,toolbar=no,menubar=no,resizable=no,scrollbars=no,location=no,titlebar=no");
		chat_win.focus();
	}catch(e){};
} 

	var onloadInterval_fixed = window.setInterval(show_fixed_kf,500);
	function show_fixed_kf()
	{

		try{showKFDiv()}catch(e){};
	}
	
 //显示客服图标代码 结束
 //主动邀约开始

       var onloadInterval = window.setInterval(checkIfShow,10000);
		var isIE = (document.all)?1:0;
		
		function getTime(){
		 var dd=new Date();
		 return Math.floor(dd.getTime()/1000);
		 }
		 var starttime = getTime();


		function sendAndRecieve(js_src)
		{
			
				js_src = "http://222.73.123.155" +js_src;
				var script=document.createElement("script");
				script.type='text/javascript';
				script.language='javascript';
				script.src=js_src;
				document.getElementsByTagName("head")[0].appendChild(script);
				
		}

		var companyId=2;
		var host = "http://eca.dongfeng-nissan.com.cn";	
		var work_id=0;

	    document.write("<div id=\"aotu_kf\"  style=\"border:0px #FF0000 solid;position:absolute;width:auto;height:auto;top:35%;z-index:7999;left:38%;display:none;\"></div>");
		var   image1=new   Image();
		image1.src = host +"/auto/a3.gif";;
		image1.onerror=function(){}

		var   image2=new   Image();
		image2.src =  host + "/auto/a2.gif";
		image2.onerror=function(){}
		var bg_img_auto = host +"/auto/a5.jpg";
		img_recieve = host + "/auto/a2.jpg";
		
		//主动邀约 html 开始
		
		auto_str ='<img src="http://eca.dongfeng-nissan.com.cn/images/Service.gif" alt="客服邀请" width="344" height="165" border="0" usemap="#Map" /><map name="Map" id="Map"><area shape="rect" coords="149,102,228,133" href="#" onclick="open_win_chat_for_win();return false" /><area shape="rect" coords="236,99,314,136" href="#"  onclick="hidden_auto();return false"/></map>';
	
		//主动邀约 html 结束
		
		function GetObjFromDoc(id,theDoc)
			{
				if(!theDoc){theDoc = document;}
				if (theDoc.getElementById){return theDoc.getElementById(id);}
				else if (document.all)
				{return theDoc.all(id);}
			}
		  function insert_aotu_kf()
		  {
				var aotu_kf_div=GetObjFromDoc('aotu_kf');
				//alert(10)
				if(aotu_kf_div==null){
					setTimeout('insert_aotu_kf()',100);
					return;
				}
			try{
				GetObjFromDoc("aotu_kf").innerHTML = auto_str;
			}
			catch(e){alert(e)}
			
		}
	    insert_aotu_kf();
	    
		
		
		function showKFDiv()
		{
			
			


			var screen_width = 0;
			var screen_hight = 0;
			
			var diffY = document.documentElement.scrollTop;	
			var diffX = document.documentElement.scrollLeft ;

			
				
			if(diffY==0)
			{		
				diffY = document.body.scrollTop;
			}
			
			if(diffX==0)
			{		
				diffX = document.body.scrollLeft;
			}


				if (self.innerHeight) { // all except Explorer 
				screen_width = self.innerWidth; 
				screen_hight = self.innerHeight; 
				} 
				else if (document.documentElement && document.documentElement.clientHeight) { 
				// Explorer 6 Strict Mode 
				screen_width = document.documentElement.clientWidth; 
				screen_hight = document.documentElement.clientHeight; 
				} else if (document.body) { // other Explorers 
				screen_width = document.body.clientWidth; 
				screen_hight = document.body.clientHeight; 
				} 





			try{
			
				if(auto_has_show )
				{
					
					var auto_top = document.getElementById("aotu_kf").style.top
					var auto_width = 582;		
					var auto_hight = document.getElementById("aotu_kf").offsetHight
					if(typeof(auto_hight)=="undefined")
					auto_hight = 125;

					if(typeof(auto_width)=="undefined")
					auto_hight = 125;
					//if(screen_hight == 0)screen_hight = 600;
					//if(screen_hight > 800) screen_hight = 800;
					//alert(1)
					GetObjFromDoc("aotu_kf").style.top = (diffY + ( screen_hight / 2) - (auto_hight)/2)+"px" ;
					//alert(2)
					//alert(GetObjFromDoc("aotu_kf").style.top)
					if (document.all) 
					GetObjFromDoc("aotu_kf").style.left = screen_width/2  - auto_width/2 ;

					
				}
			}
			catch(e){};
		}
		var kfwin_has_show = false;
		var auto_has_show = false;
		
		var time_to_show = 5000;
		time_to_show = 5000;

		
		function show_kf_auto(workid){
           // nextAccept();
		   work_id = workid;
		   var aotu= document.getElementById("aotu_kf");
			aotu.style.display="block";
			auto_has_show = true;
			
         }


		 function show_51kf_dialog(workid){
			 work_id = workid;
			try
			{
				kfwin_has_show = true;
				window.clearInterval(onloadInterval);
				kf_openurl = kf_openurl+"&workId="+work_id;
				sendAndRecieve("/js/recieve.jsp?state=4&companyId="+companyId+"&sessionId="+userid);	
				location.href=kf_openurl;
				window.focus();
			}catch(e){}
			
         }

		function hidden_auto(){
			var aotu=document.getElementById("aotu_kf");
            aotu.style.display="none";
			auto_has_show = false;
			sendAndRecieve("/js/recieve.jsp?state=3&companyId="+companyId+"&sessionId="+userid);	
		}
		//kf_openurl="http://eca.dongfeng-nissan.com.cn/client.jsp?flag=1&companyId=2&style=316&locate=cn" +"&refer="+ escape(window.location.href);
		

		var keyword_brand = "";
		function open_win_chat(brand_id){
			work_id = 0;
			if(brand_id == 1)keyword_brand="奇骏";
			if(brand_id == 2)keyword_brand="天籁";
			if(brand_id == 3)keyword_brand="颐达";
			if(brand_id == 4)keyword_brand="骐达";
			if(brand_id == 5)keyword_brand="逍客";
			if(brand_id == 6)keyword_brand="骊威";
			if(brand_id == 7)keyword_brand="轩逸";
			if(brand_id == 8)keyword_brand="骏逸";
			//document.getElementById("51kf_accept_img").click();
			open_win_chat_for_win();		
}
		function open_win_chat_for_win(){
			try
			{
				kfwin_has_show = true;
				window.clearInterval(onloadInterval);
				var aotu=document.getElementById("aotu_kf");
				aotu.style.display="none";
				sendAndRecieve("/js/recieve.jsp?state=4&companyId="+companyId+"&sessionId="+userid);	
				kf_openurl = kf_openurl+"&workId="+work_id;
				var chat_win =  window.open(kf_openurl+ "&keyword="+encodeURIComponent(keyword_brand),"chat_2","height=473,width=703,top=200,left=200,status=yes,toolbar=no,menubar=no,resizable=no,scrollbars=no,location=no,titlebar=no");
				chat_win.focus();
			}catch(e){}
			
		}

		
		var counttimes = 0;
		function checkIfShow()
		{
			if(kfwin_has_show) return;
			//if(auto_has_show) return;
			var now_time = getTime();
			if(now_time - starttime > 60 * 10 )
			{
				window.clearInterval(onloadInterval);
				return;
			}
			counttimes++;			
			if(counttimes > 2)
			{
				sendAndRecieve("/js/autoShow.jsp?t="+counttimes+"&companyId="+companyId+"&sessionId="+userid);
			}
		}

		sendAndRecieve("/js/autoShow.jsp?t=0&page_level=z&companyId="+companyId+"&sessionId="+userid+"&route="+route+"&keyword="+escape(getCookie("kf51_referrer"))+"&page_title="+escape(kdocTitle));



 //主动邀约结束
