
//公用异步操作函数
function AjaxMethod(targetUrl,cID,flag,_CallBack)
{
	//首先读取Cookie 如果为0 证明Cookie为空
	var request = "cid="+cID+"&flag="+flag+"&random="+Math.random();
	new Ajax.Request(
		 targetUrl,
		{
			method: 'post',
			postBody: request,
			onComplete: _CallBack
		}
	);
}

   ////==========================播放课件=========================================================
   //第一步:验证是否登陆
   function AjaxRequestCourseWare(cID)
   {
	   return alert('内容完善中,请稍候!');
        //验证是否登录,转到  _CallBack_IsLogin
       // CourseList.UserIsLogin(function(response){ _CallBack_IsLogin(response,cID,cUrl)});
        AjaxMethod('/common/ajaxCookie.aspx',cID,'',function(response){ _CallBack_IsLogin(response,cID)});
   }
   
   function _CallBack_IsLogin(response,cID)
   {
        if(parseInt(response.responseText) == 0)
        {
             return alert('您还未登录');
        }
        else
        {
            //验证是否有权限,转到 _CallBack_ValiedPermission
             //CourseList.ValidUserPermissionOfCourseWare(cID,function(response){ _CallBack_ValiedPermission(response,cID,cUrl)});
              AjaxMethod('/dbzx/AjaxValidPermissionOfCourseWare.ashx',cID,1,function(response){ _CallBack_ValiedPermission(response,cID)});
        }
   }
   //第二步:如果已登录,是否有此课件权限
   function _CallBack_ValiedPermission(response,cID)
   {
        //没有权限查看
        if(parseInt(response.responseText) == 0)
        {
            //弹出扣费窗口
            if(confirm('您尚未购买此课件，此操作需花费您５品学券/月，继续？') == true)
            {
                //扣费操作,转到  _CallBack_PayForCourseWare
                //CourseList.PayForCourseWare(cID,function(response){ _CallBack_PayForCourseWare(response,cID,cUrl)})
                 AjaxMethod('/dbzx/AjaxValidPermissionOfCourseWare.ashx',cID,2,function(response){ _CallBack_PayForCourseWare(response,cID)});
            }
        }
        else
        {
                //播放课件   
                PlayCourseWare(cID)
        }
   }
   //第三步:如果上一步没有权限,且选择购买,此步验证扣费是否成功
   function _CallBack_PayForCourseWare(response,cID)
   {
        var flag = response.responseText;
        switch(parseInt(flag))
        {
            case  1:alert('扣费成功');PlayCourseWare(cID);break;
            case -2:alert('您的品学券余额不足');break;
			case -4:alert('帐户类型不对,学生方可看此课件');break;
            default:alert('系统异常，请稍候重试');break;
        }
   }
   //第四步:扣费成功,则播放课件
  //播放课件(html格式)
   function PlayCourseWare(cID)
   {
        AjaxMethod('/dbzx/AjaxValidPermissionOfCourseWare.ashx',cID,3,_CallBack_PlayCourseWare);
   }
//课件播放回调函数
function _CallBack_PlayCourseWare(response)
{
   var cUrl = response.responseText;
   if(cUrl.length <= 0)
	   return alert('课件异常,请与网站管理员联系!');
   cUrl = cUrl.replace("http://newtest.eee114.com/","http://jxwtkj.eee114.com/");
      var str = "<table width=1000 border=0 align=center cellpadding=0 cellspacing=0><tr height=31><td width=9><img src=http://study.xxb.eee114.com/images/gbspan_01.gif width=9 height=30 alt= /></td><td width=985 align=right background=http://study.xxb.eee114.com/images/gbspan_02.gif><a style=cursor:hand onclick=WindowBack('"+cUrl+"')><img src=http://study.xxb.eee114.com/images/gbspan_031.gif width=87 height=30 alt=返回当前课件目录  ></a><a style=cursor:hand onclick='document.getElementById(\"divPlayCourseWare\").style.display=\"none\"'><img src=http://study.xxb.eee114.com/images/gbspan_03.gif width=87 height=30 alt=关闭 id='imgClose' ></a></td><td width=10><img src=http://study.xxb.eee114.com/images/gbspan_05.gif width=10 height=30 alt= /></td></tr><tr><td colspan=3><myiframe><input type=hidden id=txthid /></td></tr></table>";
         str = str.replace('<myiframe>','<iframe id=myfrm name=myfrm  align=middle width=1000  height=650 frameborder=0 scrolling=auto  src="'+cUrl+'"></iframe>'); 
     CreateDivOnParentDocument("divPlayCourseWare",1000,650,50,window.document.documentElement.scrollTop+2,"#CCCCCC",1000,str);
}
function WindowBack(cUrl)
{
	document.getElementById("myfrm").src = cUrl;
}
   //滚动
function AutoMoveOnParentDocument(id,top)
{
	if(window.document.getElementById(id))
	{
		window.document.getElementById(id).style.top =  window.document.documentElement.scrollTop+top;
	}
	//alert(document.body.scrollTop+'---'+document.documentElement.scrollTop);
}

    /*
在父窗口中创建背景层
*/
function CreateDivInBackGround(divName,zIndex)
{
		if(window.document.getElementById(divName))
			 window.document.body.removeChild(document.getElementById(divName));	
        var sWidth,sHeight;
		sWidth=document.body.scrollWidth;
		sHeight = document.documentElement.scrollHeight;
		var bgObj= window.document.createElement("div");
		bgObj.setAttribute('id',divName);
		bgObj.style.position="absolute";
		bgObj.style.top="0";
		bgObj.style.background="#CCCCCC";
		bgObj.style.filter="progid:DXImageTransform.Microsoft.Alpha(style=3,opacity=25,finishOpacity=75";
		bgObj.style.opacity="0.6";
		bgObj.style.left="0";
		bgObj.style.width=sWidth + "px";
		bgObj.style.height=sHeight + "px";
		bgObj.style.zIndex = zIndex-1;
		window.document.body.appendChild(bgObj);
}

/*
功能:在交窗口中创建Div
*/
function CreateDivOnParentDocument(id,width,height,pLeft,pTop,backcolor,zIndex,innerHTML)
{
    if(window.document.getElementById(id))
       window.document.body.removeChild(window.document.getElementById(id));
   
    //创建背景层
	CreateDivInBackGround('bgdiv',zIndex);
    var ttop = window.document.documentElement.scrollTop;//确定引发此事件的控件的位置
    var tleft = 0;
    
    var s = window.document.createElement("DIV"); 
      s.id = id;
      s.name = id;      
      s.style.position="absolute";
      s.style.left = pLeft;//(window.screen.width-width)/2;  //距左边偏移量
      s.style.top = pTop;// (window.screen.height-height)/2;  //距顶部的偏移量ttop + pTop     
      s.style.width = width +"px";
      s.style.height = height +"px";
      s.style.border = "black 1px solid";
      s.style.backgroundColor = backcolor;
      s.style.zIndex=zIndex;  
      s.style.display="block";   
      s.innerHTML=innerHTML;
      window.document.body.appendChild(s);
        setInterval('AutoMoveOnParentDocument("'+id+'",'+pTop+')',200);
}
//关闭播放层
function CloseFlvCourseWare(backgrounddivid,divid)
{
	 if(window.document.getElementById(divid))
	{
		 window.document.getElementById(divid).innerHTML='';
		 window.document.body.removeChild(window.document.getElementById(divid));
	}
	 if(window.document.getElementById(backgrounddivid))
		 window.document.body.removeChild(window.document.getElementById(backgrounddivid));
}
//录制课程回放播放
function PlayerFlvFile(file,teacherName,courseName,courseType)
{
	//alert(file);
     window.setTimeout('Test("'+file+'","'+teacherName+'","'+courseName+'","'+courseType+'")',100);
}
function Test(file,teacherName,courseName,courseType)
{
	 var cUrl = "/player/index.html?"+file;
     // var str = "<table width=900 border=0 align=center cellpadding=0 cellspacing=0><tr height=31><td width=9><img src=http://study.xxb.eee114.com/images/gbspan_01.gif width=9 height=30 alt= /></td><td width=985 align=right background=http://study.xxb.eee114.com/images/gbspan_02.gif><a style=cursor:hand onclick='document.getElementById(\"divPlayCourseWare\").style.display=\"none\";document.getElementById(\"divPlayCourseWare\").innerHTML=\"\";'><img src=http://study.xxb.eee114.com/images/gbspan_03.gif width=87 height=30 alt=关闭 id='imgClose' ></a></td><td width=10><img src=http://study.xxb.eee114.com/images/gbspan_05.gif width=10 height=30 alt= /></td></tr><tr><td colspan=3><myiframe><input type=hidden id=txthid /></td></tr></table>";
	 var str ="<table width=900 border=0 align=center cellpadding=0 cellspacing=0><tr height=31><td width=9><img src=http://study.xxb.eee114.com/images/gbspan_01.gif width=9 height=30 alt= /></td><td width=793 align=left background=http://study.xxb.eee114.com/images/gbspan_02.gif><table width=80% border=0 align=left cellpadding=0 cellspacing=0>"
			+" <tr> <td width=3%>&nbsp;</td> <td width=97%>课程类型:"+courseType+" 课程名:"+courseName+" 主讲:"+teacherName+" </td>"
			+"</tr></table></td><td width=87 align=right background=http://study.xxb.eee114.com/images/gbspan_02.gif><a style=cursor:hand onclick='CloseFlvCourseWare(\"bgdiv\",\"divPlayCourseWare\")'><img src=http://study.xxb.eee114.com/images/gbspan_03.gif width=87 height=30 alt=关闭 id='imgClose' /></a></td>"
			+"<td width=11><img src=http://study.xxb.eee114.com/images/gbspan_05.gif width=10 height=30 alt= /></td></tr><tr><td colspan=4><myiframe><input type=hidden id=txthid /></td></tr></table>";
      str = str.replace('<myiframe>','<iframe id=myfrm name=myfrm  align=middle width=900  height=600 frameborder=0 scrolling=auto  src="'+cUrl+'"></iframe>'); 
     CreateDivOnParentDocument("divPlayCourseWare",900,600,100,2,"#CCCCCC",1000,str);
}

//录制课程回放播放
function PlayerFlvFiles(file,teacherName,courseName,courseType)
{
	//alert(file);
     window.setTimeout('Tests("'+file+'","'+teacherName+'","'+courseName+'","'+courseType+'")',100);
}
function Tests(file,teacherName,courseName,courseType)
{
	 var cUrl = "/player/index.html?"+file;
     // var str = "<table width=900 border=0 align=center cellpadding=0 cellspacing=0><tr height=31><td width=9><img src=http://study.xxb.eee114.com/images/gbspan_01.gif width=9 height=30 alt= /></td><td width=985 align=right background=http://study.xxb.eee114.com/images/gbspan_02.gif><a style=cursor:hand onclick='document.getElementById(\"divPlayCourseWare\").style.display=\"none\";document.getElementById(\"divPlayCourseWare\").innerHTML=\"\";'><img src=http://study.xxb.eee114.com/images/gbspan_03.gif width=87 height=30 alt=关闭 id='imgClose' ></a></td><td width=10><img src=http://study.xxb.eee114.com/images/gbspan_05.gif width=10 height=30 alt= /></td></tr><tr><td colspan=3><myiframe><input type=hidden id=txthid /></td></tr></table>";
	 var str ="<table width=710 border=0 align=center cellpadding=0 cellspacing=0><tr height=31><td width=9><img src=https://pic.78ic.com/images/im_index/gbspan_01.gif width=9 height=30 alt= /></td><td width=603 align=left background=https://pic.78ic.com/images/im_index/gbspan_02.gif><table width=80% border=0 align=left cellpadding=0 cellspacing=0>"
			+" <tr> <td width=3%>&nbsp;</td> <td width=97%>课程类型:"+courseType+" 课程名:"+courseName+" 主讲:"+teacherName+" </td>"
			+"</tr></table></td><td width=87 align=right background=https://pic.78ic.com/images/im_index/gbspan_02.gif><a style=cursor:hand onclick='CloseFlvCourseWare(\"bgdiv\",\"divPlayCourseWare\")'><img src=https://pic.78ic.com/images/im_index/gbspan_03.gif width=87 height=30 alt=关闭 id='imgClose' /></a></td>"
			+"<td width=11><img src=https://pic.78ic.com/images/im_index/gbspan_05.gif width=10 height=30 alt= /></td></tr><tr><td colspan=4><myiframe><input type=hidden id=txthid /></td></tr></table>";
      str = str.replace('<myiframe>','<iframe id=myfrm name=myfrm  align=middle width=710  height=474 frameborder=0 scrolling=auto  src="'+cUrl+'"></iframe>'); 
     CreateDivOnParentDocument("divPlayCourseWare",710,474,15,20,"#CCCCCC",725,str);
}
//==============================高考专区视频播放===========================================================
function PlayCourseWareForGoaKao(playpage,title,width,height,showclosebutton,file)
{
    var width=width;
    var height=height;
	 var cUrl = '/exam/decryptExam/play.aspx?'+file;
	 var str ="<table width="+width+" border=0 align=center cellpadding=0 cellspacing=0><tr height=31><td width=9><img src=http://study.xxb.eee114.com/images/gbspan_01.gif width=9 height=30 alt= /></td><td width=793 align=left background=http://study.xxb.eee114.com/images/gbspan_02.gif><table width=80% border=0 align=left cellpadding=0 cellspacing=0>"
			+" <tr> <td width=3%>&nbsp;</td> <td width=97% align=center>"+title+"</td>"
			+"</tr></table></td><td width=87 align=right background=http://study.xxb.eee114.com/images/gbspan_02.gif><a style=cursor:hand onclick='CloseFlvCourseWare(\"bgdiv\",\"divPlayCourseWare\")'><img src=http://study.xxb.eee114.com/images/gbspan_03.gif width=87 height=30 alt=关闭 id='img1' /></a></td>"
			+"<td width=11><img src=http://study.xxb.eee114.com/images/gbspan_05.gif width=10 height=30 alt= /></td></tr><tr><td colspan=4><myiframe><input type=hidden id=Hidden1 /></td></tr></table>";
      str = str.replace('<myiframe>','<iframe id=myfrm name=myfrm  align=middle width='+width+'  height='+height+' frameborder=0 scrolling=auto  src="'+cUrl+'"></iframe>'); 
     CreateDivOnParentDocument("divPlayCourseWare",width,height,(document.body.scrollWidth-width)/2,150,"#CCCCCC",1000,str);
}