//created by Chris
/*this js for Cenwave Media Player Check use*/

/*
*if in viewer page user this protocol, the ppt iframe and chat iframe don't jump, no media playstate event indication to them.
*/
	//var start_url = "cenwave://192.168.0.36";
	var category =-1;
	function GetCookie(sName)
	{
    // cookies are separated by semicolons
    	var aCookie = document.cookie.split("; ");
	    for (var i=0; i < aCookie.length; i++)
    	{
        // a name alue pair (a crumb) is separated by an equal sign
        	var aCrumb = aCookie[i].split("=");
			if (sName == aCrumb[0])
    	    {
        	    return true;
        	} 
		}
    // a cookie with the requested name does not exist
    	return false;
	}
	function to_join_conf(stream_url, download_url, type)
	{
		var bCheckPlayer = check_agt_object(download_url, type);
		if(bCheckPlayer)
		{
			$('MainPlayer').URL = stream_url;
		}
	}
	
	function to_download(download_url, type)
	{
		parent.document.getElementById("msg_dialog_frame").src = download_url;
		if(type == 0)
			document.getElementById("msg_dialog_div").style.display = "";
		else if(type == 1)
		{
			parent.document.getElementById("msg_dialog_div").style.display = "";
		}
		else if(type == 2)
			window.parent.parent.document.getElementById("msg_dialog_div").style.display = "";
		return;
	}
	
	//start up Cenwave Player by frame accessing the protocol cenwave://
	function to_start_agt(type)
	{
		if(type == 0)
			document.getElementById("agtStartFrame").src = start_url;
		else if(type == 1)
			parent.document.getElementById("agtStartFrame").src = start_url;
		else if(type == -1)
			document.getElementById("agtStartCommonFrame").src = start_url;
	}
	
	/*
	*try to check the Cenwave Media Player is installed or not, return value: Boolean
	*/
	var browserVersion = navigator.appVersion;
	var IE7 = false;
	if(browserVersion.indexOf("MSIE 7.") != -1) IE7 = true;
	
	function check_agt_object(download_url, type)
	{
	    category = type;
		if(getOs()==1)
		{
			if(GetCookie('jeedu_player_version'))
			{
			//	if(!IE7)
					to_start_agt(type);
				return true;
			}
//ActiveX ????
/*
			else
			{
				try
				{
					var obj_cw_dtect = new ActiveXObject("Jeedu.Detection");
					to_start_agt(type);
					obj_cw_dtect = null;
					return true;
				}
				catch(e)
				{
					return false;
				}
			}
*/
		}
		else if(getOs()==2)
		{
			var obj_cw_dtect = navigator.mimeTypes["application/x-jeedu-player"];
			 if(typeof(obj_cw_dtect) == "object") 
			 {
				getAllowSess();
				obj_cw_dtect=null;
				return true;
			 }
			 else
				 to_writeSess();
		}
		return false;
	}
	
	function check_studio_object(download_url, type)
	{
	    category = type;
		if(getOs()==1)
		{
			if(GetCookie('jeedu_studio_version'))
			{
				var browserVersion = navigator.appVersion;
				var IE7 = false;
				if(browserVersion.indexOf("MSIE 7.") != -1) IE7 = true;
			//	if(!IE7)
					to_start_agt(type);
				return true;
			}
//ActiveX ????
/*
			else
			{
				try
				{
					var obj_cw_dtect = new ActiveXObject("Jeedu.Detection");
					to_start_agt(type);
					obj_cw_dtect = null;
					return true;
				}
				catch(e)
				{
					return false;
				}
			}
*/
		}
		else if(getOs()==2)
		{
			var obj_cw_dtect = navigator.mimeTypes["application/x-jeedu-studio"];
			 if(typeof(obj_cw_dtect) == "object") 
			 {
				getAllowSess();
				obj_cw_dtect=null;
				return true;
			 }
			 else
				 to_writeSess();
		}
		return false;
	}
	
	function getAllowSess()
	{
   	 	var callback = getExistSess;
		Request.reSend("../allowStartAgt.do?type=get","",callback);
	}
	function getExistSess(xmlHttp)
	{
		var xmlStr = xmlHttp.responseText;
		var allowStart=js_parse_xml('allowstart',xmlStr);
		if(allowStart=='1')
			to_start_agt(category);

	}
	function js_parse_xml(node_name, str_xml){
		var node1 = "<"+node_name+">";
		var node2 = "</"+node_name+">";
		var index1 = str_xml.indexOf(node1);
		var index2 = str_xml.indexOf(node2);
		index1 = index1+node1.length;
		var ret = str_xml.substring(index1, index2);
		return ret;
	}
	function to_writeSess()
	{
		var callback = writeSess;
		Request.reSend("../allowStartAgt.do?type=write","",callback);	
	}
	function writeSess()
	{}