
var mainMenu=function(boxId,xmlUrl,loaderSrc,hoursNum,nowClass){var menuBox=document.getElementById(boxId);var loader=0;var xmlDoc;var docDateArr=new Array();var docProNameArr=new Array();var docBeginTimeArr=new Array();var liArr=new Array();var createLoader=function(){menuBox.innerHTML=" ";loader=document.createElement("div");menuBox.appendChild(loader);with(loader){style.width=95+"px";style.height=7+"px";style.marginTop=(menuBox.offsetHeight-7)/2+"px";style.marginLeft=(menuBox.offsetWidth-95)/2+"px";style.background="url("+loaderSrc+") no-repeat";}};var getData=function(doc){var c=doc.getElementsByTagName("dayItem");for(var a=0;a<c.length;a++){docDateArr.push(c[a].getElementsByTagName("dayDate")[0].childNodes[0].nodeValue);docProNameArr[a]=new Array();docBeginTimeArr[a]=new Array();for(var b=0;b<c[a].getElementsByTagName("program").length;b++){docProNameArr[a].push(c[a].getElementsByTagName("proName")[b].childNodes[0].nodeValue);docBeginTimeArr[a].push(c[a].getElementsByTagName("beginTime")[b].childNodes[0].nodeValue);}};for(var a=0;a<c.length;a++){for(var b=0;b<docProNameArr[a].length-1;b++){for(var d=docProNameArr[a].length-1;d>0;d--){if(checkTime(docBeginTimeArr[a][d])<checkTime(docBeginTimeArr[a][d-1])){var dotStr=new String();dotStr=docBeginTimeArr[a][d];docBeginTimeArr[a][d]=docBeginTimeArr[a][d-1];docBeginTimeArr[a][d-1]=dotStr;var dotStr2=new String();dotStr2=docProNameArr[a][d];docProNameArr[a][d]=docProNameArr[a][d-1];docProNameArr[a][d-1]=dotStr2;}}}};for(var a=0;a<c.length-1;a++){for(var b=c.length-1;b>0;b--){if(docDateArr[b]<docDateArr[b-1]){var newStr=new String();newStr=docDateArr[b];docDateArr[b]=docDateArr[b-1];docDateArr[b-1]=newStr;var newArr=new Array();newArr=docProNameArr[b];docProNameArr[b]=docProNameArr[b-1];docProNameArr[b-1]=newArr;newArr=new Array();newArr=docBeginTimeArr[b];docBeginTimeArr[b]=docBeginTimeArr[b-1];docBeginTimeArr[b-1]=newArr;}}}};var checkArr=function(){var theDate=new Date();var theDay=theDate.getDay();var theHours=theDate.getHours();var theMin=theDate.getMinutes();var tadayProArr=new Array();var tadayBeginTimeArr=new Array();if(theHours*60+theMin+hoursNum*60>=24*60){var startTime=theHours*60+theMin-hoursNum*60;var endTime=hoursNum*60+theHours*60+theMin-24*60;for(var a=0;a<docBeginTimeArr[theDay].length;a++){if(checkTime(docBeginTimeArr[theDay][a])>=startTime){tadayBeginTimeArr.push(docBeginTimeArr[theDay][a]);tadayProArr.push(docProNameArr[theDay][a]);}};for(var b=0;b<docBeginTimeArr[nextDay(theDay)].length;b++){if(checkTime(docBeginTimeArr[nextDay(theDay)][b])<=endTime){tadayBeginTimeArr.push(docBeginTimeArr[nextDay(theDay)][b]);tadayProArr.push(docProNameArr[nextDay(theDay)][b]);}}}else if(theHours*60+theMin-hoursNum*60<=0){var startTime=24*60-(hoursNum*60-theHours*60-theMin);var endTime=theHours*60+theMin+hoursNum*60;for(var a=0;a<docBeginTimeArr[prevDay(theDay)].length;a++){if(checkTime(docBeginTimeArr[prevDay(theDay)][a])>=startTime){tadayBeginTimeArr.push(docBeginTimeArr[prevDay(theDay)][a]);tadayProArr.push(docProNameArr[prevDay(theDay)][a]);}};for(var b=0;b<docBeginTimeArr[theDay].length;b++){if(checkTime(docBeginTimeArr[theDay][b])<=endTime){tadayBeginTimeArr.push(docBeginTimeArr[theDay][b]);tadayProArr.push(docProNameArr[theDay][b]);}}}else{var startTime=theHours*60+theMin-hoursNum*60;var endTime=theHours*60+theMin+hoursNum*60;for(var a=0;a<docBeginTimeArr[theDay].length;a++){if(checkTime(docBeginTimeArr[theDay][a])<=endTime&&checkTime(docBeginTimeArr[theDay][a])>=startTime){tadayBeginTimeArr.push(docBeginTimeArr[theDay][a]);tadayProArr.push(docProNameArr[theDay][a]);}}};createUi(tadayBeginTimeArr,tadayProArr);};var createUi=function(tiArr,conArr){menuBox.innerHTML=" ";var thisUl1=document.createElement("ul");var thisUl2=document.createElement("ul");var nowDate=new Date();var nowTime=nowDate.getHours()*60+nowDate.getMinutes();var chaTime1=new Array();var chaTime2=new Array();var nowNum=0;var leftBox=document.createElement("div");var rightBox=document.createElement("div");with(leftBox){style.width=menuBox.offsetWidth/2-5+"px";style.cssFloat="left";style.styleFloat="left";style.overflow="hidden";style.zoom=1;};with(rightBox){style.width=menuBox.offsetWidth/2-15+"px";style.cssFloat="left";style.styleFloat="left";style.overflow="hidden";style.zoom=1;};menuBox.appendChild(leftBox);menuBox.appendChild(rightBox);leftBox.appendChild(thisUl1);rightBox.appendChild(thisUl2);var tiLen1=0;var tiLen2=0;if(tiArr.length%2==0){tiLen1=tiArr.length/2;tiLen2=tiArr.length/2;}else{tiLen1=(tiArr.length-1)/2+1;tiLen2=(tiArr.length-1)/2;};for(var a=0;a<tiArr.length;a++){liArr[a]=document.createElement("li");if(a<tiLen1){thisUl1.appendChild(liArr[a]);}else{thisUl2.appendChild(liArr[a]);};liArr[a].innerHTML='<span style="color:red">['+tiArr[a]+"]</span>"+' '+conArr[a];liArr[a].style.wordSpacing=5+"px";liArr[a].style.clear="both";liArr[a].style.width=menuBox.offsetWidth/2-15+"px";if(a%2!=0){liArr[a].style.backgroundColor="#f7f7f7";};chaTime1[a]=nowTime-checkTime(tiArr[a]);};for(var b=0;b<chaTime1.length;b++){if(chaTime1[b]>=0){chaTime2.push(chaTime1[b]);}};for(var c=0;c<chaTime2.length-1;c++){for(var d=chaTime2.length-1;d>0;d--){if(chaTime2[d]<chaTime2[d-1]){var newChaTime=chaTime2[d-1];chaTime2[d-1]=chaTime2[d];chaTime2[d]=newChaTime;}}};for(var e=0;e<chaTime1.length;e++){if(chaTime1[e]==chaTime2[0]){nowNum=e;}};liArr[nowNum].className=nowClass;};var nextDay=function(i){var newNum=0;if(i>5){newNum=0;}else{newNum=i+1;};return newNum;};var prevDay=function(i){var newNum=0;if(i<1){newNum=6;}else{newNum=i-1;};return newNum;};var checkTime=function(i){var returnNum=0;returnNum=i.split(":")[0]*60+i.split(":")[1]*1;return returnNum;};function ajaxFunction(){var xmlHttp;try{if(!document.all){xmlHttp=new XMLHttpRequest();}else{xmlHttp=new ActiveXObject("Msxml2.XMLHTTP");}}catch(e){try{xmlHttp=new ActiveXObject("Msxml2.XMLHTTP");}catch(e){try{xmlHttp=new ActiveXObject("Microsoft.XMLHTTP");}catch(e){alert("ÄúµÄä¯ÀÀÆ÷²»Ö§³ÖAJAX£¡");return false;}}};xmlHttp.onreadystatechange=function(){switch(xmlHttp.readyState){case 1:menuBox.style.height=80+"px";createLoader();break;case 4:menuBox.style.height="auto";xmlDoc=loadXMLDoc(xmlUrl);getData(xmlDoc);checkArr();break;}};xmlHttp.open("GET",xmlUrl,true);xmlHttp.send(null);};ajaxFunction();};


