﻿//var host = 'http://' + window.location.host + '/EnglishOkWeb'; 
var host = 'http://' + window.location.host;

function getFormatDate() //返回当前系统日期   
{   
	var now = new Date();
	var year = now.getYear();
	var month = now.getMonth()+1;   
	var day = now.getDate();   
	return year+"-" + month+"-" + day
}

function dateDiff(sDate1, sDate2){  
	//sDate1和sDate2是2002-12-18格式
	var aDate, oDate1, oDate2, iDays;
	aDate = sDate1.split("-");
	oDate1 = new Date(aDate[1] + '-' + aDate[2] + '-' + aDate[0]);  //转换为12-18-2002格式
	aDate = sDate2.split("-");
	oDate2 = new Date(aDate[1] + '-' + aDate[2] + '-' + aDate[0]);
	iDays = parseInt(Math.abs(oDate1 - oDate2) / 1000 / 60 / 60 /24);  //把相差的毫秒数转换为天数	
	return iDays;
}

function setCookie(name, value)
//设定Cookie值
{	
	try
	{
		var expdate = new Date();
		expdate.setTime(expdate.getTime() + (30*24*60*60*1000 ));
		var expires = "; expires="+ expdate.toGMTString();
		var argv = setCookie.arguments;
		var argc = setCookie.arguments.length;
		//var expires = (argc > 2) ? argv[2] : null;
		var path = (argc > 3) ? argv[3] : null;
		var domain = (argc > 4) ? argv[4] : null;
		var secure = (argc > 5) ? argv[5] : false;			
		document.cookie = name + "=" + escape (value) +expires
		+((path == null) ? "" : ("; path=" + path)) +((domain == null) ? "" : ("; domain=" + domain))
		+((secure == true) ? "; secure" : "");	
	}catch(x){;}
}

function delCookie(name)
//删除Cookie
{
	var exp = new Date();
	exp.setTime (exp.getTime() - 1);
	var cval = getCookie (name);
	document.cookie = name + "=" + cval + "; expires="+ exp.toGMTString();
}

function getCookie(name){
	var strCookie = document.cookie;
	var arrCookie=strCookie.split("; ");
	var value;
	for(var i=0;i<arrCookie.length;i++){
		var arr=arrCookie[i].split("=");
		if(name==arr[0]){
			value=arr[1];
			break;
		}
	}
	return value;　
}

function closeHintInfo(){
	 $("#fancy_close").click();
}
	
function showHintInfo()
{	
	//提示用户
	//alert(host);
	var html ='';	
	html +='<div id="openHintInfo" style="background:#fff; width:385px; height:200px; border:1px #666 solid; display:none;">';
	html +='<table width="100%" border="0" cellspacing="0" cellpadding="0">';
    html +='<tr>';
    html +='<td width="385" height="47" align="left" background="' + host + '/images/top_Pop_title.gif" class="font14"><strong>&nbsp; 提示信息</strong></td>';
    html +='</tr>';
    html +='</table>';
	html +='<br/>';
	html +='<font face="宋体" size=3><strong>&nbsp;&nbsp;&nbsp;&nbsp;正尝试启动EnglishOK客户端，请稍候...</strong></font><br/><br/>';
	html +='<font face="宋体" size=2>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;因系统安全限制，我们无法检测客户端安装情况，<br/><br/>';
	html +='&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;如启动不了，请手动下载安装客户端。<br/>';
	html +='</font>';
	html +='<table width="100%" border="0" cellspacing="0" cellpadding="0">';
	html +='<tr>';	
    html +='<td width="385" height="40" align="right">';
    html +='<a href="javascript:closeHintInfo();">';
    html +='<img src="' + host + '/images/bt_queding.jpg" width="64" height="32"/></a>&nbsp;&nbsp;&nbsp;&nbsp;';
    html +='</td>';
    html +='</tr>';
    html +='</table>';	    
	html +='</div>';
	html +='<a id="client_a" style="display:none" href="#openHintInfo"">callClient</a>';
	$(html).appendTo("body");
	$("#client_a").fancybox({'frameHeight':200,'hideOnContentClick':false,'frameWidth':385,'padding':0});	
}

function callClient_songs(contentID){	
	callClient(10, contentID); 
}

function callClient_speaking(contentID){	
	callClient(30, contentID);
}

function downClient(contentType){	
	location.href='http://www.engok.com/download/Installer_0.9_beta.exe';
}

//检测浏览器类型，1-IE，2-firefox，3-chrome，4-Opera,5-Safari
function getBrowsersType()
  {   
        var ua = navigator.userAgent.toLowerCase();
        if (window.ActiveXObject)
            return 1;
        else if (document.getBoxObjectFor)
            return 2;
        else if (window.MessageEvent && !document.getBoxObjectFor)
            return 3;
        else if (window.opera)
            return 4;
        else if (window.openDatabase)
            return 5;            
  }

//检测是否安装客户端
function isInstallClient(){	
	var isInstalled = false; 
	var browserType = getBrowsersType();
	try{   
		if (browserType == 1){    
			//检查IE
           	var xmlhttp=new ActiveXObject("EnglishOKIsInstall.EnglishOKIsInstall");
           	isInstalled = true;   
		}else if (browserType == 2 || browserType == 3){
			//检查Firefox   		      
			var mimetype = navigator.mimeTypes["application/EnglishOKIsInstall"]|| navigator.mimeTypes["application/englishokisinstall"];
    		if(mimetype)
    		{        		
				isInstalled = true;    
			}
		}else{
			isInstalled = true;    
		}
		 
	} 
	catch(e){} 
	return isInstalled; 
}

//检测是否安装客户端
function isInstallMiniClient(){	
	var isInstalled = false; 
	var browserType = getBrowsersType();
	try{   
		if (browserType == 1){    
			//检查IE
           	var xmlhttp=new ActiveXObject("MiniEngOKInstall.MiniEngOKInstall");
           	isInstalled = true;   
		}else if (browserType == 2 || browserType == 3){
			//检查Firefox   		      
			var mimetype = navigator.mimeTypes["application/MiniEngOKIsInstall"]|| navigator.mimeTypes["application/miniengokisinstall"];
    		if(mimetype)
    		{        		
				isInstalled = true;    
			}
		}else{
			isInstalled = true;    
		}
		 
	} 
	catch(e){} 
	return isInstalled; 
}

function callClient(contentType, contentID){
	//检测是否安装简化版客户端
	if (isInstallMiniClient()){
		//如安装，则启动客户端
		location.href="CallMiniEngOK:" + contentType + "," + contentID;
	}else			
	//检测是否安装客户端
	if (isInstallClient()){
		//如安装，则启动客户端
		location.href="callEnglishOK:" + contentType + "," + contentID;
	}else
	{
		//否则跳到下载页面
		//callClientOld(contentType, contentID);		
		downClient();
	}
}

$(function(){
	//准备提示框
	showHintInfo();
});


