﻿// JavaScript Document
function GE(TagID)
{
	return document.getElementById(TagID)	
}

function showMenuContent(MenuName)
{
	if(MenuName.style.display=="none")
	{
		MenuName.style.display="block"
	}
	else
	{
		MenuName.style.display="none"
	}
}

function setattr(xmlobj,name,value)
{
	xmlobj.setAttribute(name,value);
}

function getattr(xmlobj,name)
{
	return xmlobj.getAttribute(name);
}

	function getUrl()
	{
		var Url=""
		Url=Url+window.location

		if (Url.indexOf("?")<0)
		{
			return Url
		}
		else
		{
			Url=Url.substr(0,Url.indexOf("?"))
			return Url
		}
	}
	
	function GoPage(CurPage,FormAction)
	{
		if (FormAction=="Submit()")
		{
			document.forms[0].action="?curpage=" +CurPage
			document.forms[0].submit()
		}
		else
		{
			window.location=getUrl()+"?curpage=" + CurPage + FormAction
		}
	}
	
	function  TransInfo(flag,SourceList,DestList)
    {
       // var source=CellSelect;
        
        if(SourceList.length+DestList.length<1)
        {
            alert("没有可选项");
            return;
        }
        switch(flag)
        {
            case 0:
                {
                    for(var i=0;i<SourceList.length;i++)
                    {
                        DestList.options[DestList.length]=new Option(SourceList.options[i].text,SourceList.options[i].value);
                    }
                    SourceList.length=0;
                    break;
                }
            case 1:
                {
                    if(SourceList.options.selectedIndex<0)
                    {
                        //alert("请选择辅助代码");
                        return;
                    }
                    var SourceListlen=SourceList.length-1
                    for(var i=SourceListlen;i>=0;i--)
                    {
                        if(SourceList.options[i].selected)
                        {
                            DestList.options[DestList.length]=new Option(SourceList.options[i].text,SourceList.options[i].value);
                            SourceList.options.remove(i);
                        }
                    }
                    break;                
                }
             case 2:
                {
                
                    for(var i=0;i<DestList.length;i++)
                    {
                        SourceList.options[SourceList.length]=new Option(DestList.options[i].text,DestList.options[i].value);
                        
                    }
                    DestList.length=0;
                    break;
                }
            case 3:
                {
                    var desttextlen=DestList.length-1
                    for(var i=desttextlen;i>=0;i--)
                    {
                        if(DestList.options[i].selected)
                        {
                           SourceList.options[SourceList.length]=new Option(DestList.options[DestList.options.selectedIndex].text,DestList.options[DestList.options.selectedIndex].value);
                           DestList.options.remove(DestList.options.selectedIndex);
 
                        }
                    }
                    break;
               }
        }
    }
	
	function getRadioGroupValue(RadioObj)
	{
		for(var i=0;i<RadioObj.length;i++)
		{
			if (RadioObj[i].checked)
			{
				return RadioObj[i].value;
			}
		}
		return "";
	}
	
	function getTermWeeks(beginDate,currDate)
	 {   
	   var diff=currDate.getTime()-beginDate.getTime();
	   var dDays=diff/1000/60/60/24;
	   var dWeeks=Math.floor(dDays/7)+1;
	   
	   return dWeeks;
	 }
	function InitalInfoBar(beginDate)
	{
	
		var week;
		var today=new Date();
		
		switch (today.getDay())
		{
			case 1:
			  week="　星期一";
			  break;
			case 2:
			  week="　星期二";
			  break;
			case 3:
			  week="　星期三";
			  break;
			case 4:
			  week="　星期四";
			  break;
			case 5:
			  week="　星期五";
			  break;
			case 6:　
			  week="　星期六";
			  break;
			case 0:
			  week="　星期日";
			  break;		        
		}	

		document.getElementById("TimeBar").innerHTML=today.getYear()+"年"+(today.getMonth()+1)+"月"+today.getDate()+"日"+week+"　第"+getTermWeeks(beginDate,today)+" 教学周";
}
var http_request = false;
function getRequestBody(oForm)
{ 
	var aParams=new Array(); 

	for(var i=0;i<oForm.elements.length;i++)
	{   
		var sParam=encodeURIComponent(oForm.elements[i].name); 		
		sParam+="=";
		sParam+=encodeURIComponent(oForm.elements[i].value); 

		aParams.push(sParam);  
	}  
	return aParams.join("&");
}
function callServer(postform,ReturnValue) {
  // Get the city and state from the web form
  //var city = document.getElementById("city").value;
  //var state = document.getElementById("state").value;
  // Only go on if there are values for both fields
  //if ((city == null) || (city == "")) return;
  //if ((state == null) || (state == "")) return;

  // Build the URL to connect to
  //var url = "/scripts/getZipCode.php?city=" + escape(city) + "&state=" + escape(state);

  // Open a connection to the server
  /* Create a new XMLHttpRequest object to talk to the Web server */
var oForm=postform;  
var sBody=getRequestBody(oForm);
if(!http_request)
	{
		if (window.XMLHttpRequest) 
		{ 
			// Mozilla, Safari,... 
			http_request = new XMLHttpRequest(); 
			if(http_request.overrideMimeType)
			{ 
				http_request.overrideMimeType('text/xml'); 
			} 
		} 
		else if (window.ActiveXObject) 
		{ 
			// IE 
			try 
			{ 
					http_request = new ActiveXObject("Msxml2.XMLHTTP"); 
			} 
			catch (e) 
			{ 
				try 
				{ 
					http_request = new ActiveXObject("Microsoft.XMLHTTP"); 
				} 
				catch (e) 
				{
				} 
			} 
		} 
	}
	if (!http_request) 
	{ 
		alert('Giving up  Cannot create an XMLHTTP instance'); 
		return false; 
	}
	//alert(http_request)
	http_request.open('POST', oForm.action, true); 
	http_request.onreadystatechange = ReturnValue; 
	http_request.setRequestHeader("Content-Type","application/x-www-form-urlencoded");
	http_request.setRequestHeader("charset","utf-8");
	alert(sBody);
	http_request.send(sBody); 
}

function getServer(getUrl,ReturnValue) {
  // Get the city and state from the web form
  //var city = document.getElementById("city").value;
  //var state = document.getElementById("state").value;
  // Only go on if there are values for both fields
  //if ((city == null) || (city == "")) return;
  //if ((state == null) || (state == "")) return;

  // Build the URL to connect to
  //var url = "/scripts/getZipCode.php?city=" + escape(city) + "&state=" + escape(state);

  // Open a connection to the server
  /* Create a new XMLHttpRequest object to talk to the Web server */
//var oForm=postform;  
//var sBody=getRequestBody(oForm);
if(!http_request)
	{
		if (window.XMLHttpRequest) 
		{ 
			// Mozilla, Safari,... 
			http_request = new XMLHttpRequest(); 
			if(http_request.overrideMimeType)
			{ 
				http_request.overrideMimeType('text/xml'); 
			} 
		} 
		else if (window.ActiveXObject) 
		{ 
			// IE 
			try 
			{ 
					http_request = new ActiveXObject("Msxml2.XMLHTTP"); 
			} 
			catch (e) 
			{ 
				try 
				{ 
					http_request = new ActiveXObject("Microsoft.XMLHTTP"); 
				} 
				catch (e) 
				{
				} 
			} 
		} 
	}
	if (!http_request) 
	{ 
		alert('Giving up  Cannot create an XMLHTTP instance'); 
		return false; 
	}
	//alert(http_request)
	http_request.open('GET', getUrl, true); 
	http_request.onreadystatechange = ReturnValue; 
	http_request.setRequestHeader("Content-Type","application/x-www-form-urlencoded");
	http_request.setRequestHeader("charset","utf-8");
	//alert(sBody);
	http_request.send(null); 
}

function _doPost(ClickObject,ActionState,FormID,IsCheck,CheckContainer,ClientSubmit)
{
	var FormObj=document.getElementById(FormID);
	var m_FormState=document.getElementById("FormState")

	if (m_FormState)
	{
		m_FormState.value=ActionState	
	}

	if (FormObj)
	{	
		if(IsCheck)
		{

     		if (CheckForm(CheckContainer))
			{
				if(!ClientSubmit)
				{
					FormObj.submit();
				}
				else
				{
					callServer(FormObj,new Function('ReceiveResult()'));	
				}
				return true;
			}
			else
			{
				return false;	
			}
		}
		else
		{

			if(!ClientSubmit)
				{
					FormObj.submit();
				}
				else
				{
					callServer(FormObj,new Function('ReceiveResult()'));	
				}
			return true;
		}
	}
	else
	{
		alert("页面错误");	
	}
}

function JKMessageBox(IconPath,BoxTitle,MessageStr)
{
	alert(MessageStr);	
}

function InitalFrame(frmobj,AdjustHeight)
{	
	var subWeb = document.frames ? frmobj.Document : frmobj.contentDocument;
	frmobj.height=subWeb.body.scrollHeight+AdjustHeight;	
}

function FillSelect(Control)
{
	if (http_request.readyState == 4 ) {
	var response =http_request.responseXML;
	//alert(http_request.responseText);
	var _select=response.getElementsByTagName("select");
	//alert(response.xml)
	var _targselect
	if (_select && _select.length>0)
	{
		var _ControlArr=Control.split("^")
		var selectHTML=""
		var selectValue=""
		for(var i=0;i<_select.length;i++)
		{
			for(var j=0;j<_ControlArr.length;j++)
			{
				//alert("slt"+_ControlArr[j].split("|")[1])
				if ("slt"+_ControlArr[j].split("|")[1]==getattr(_select[i],"id"))
				{
					_targselect=document.getElementById(_ControlArr[j].split("|")[0])
					selectValue=_targselect.value;
					if(_targselect)
					{
						_targselect.options.length=0;
						for(var x=0;x<_select[i].childNodes.length;x++)
						{
							
   						    _targselect.options[x]=new Option(getattr(_select[i].childNodes[x],"value"),getattr(_select[i].childNodes[x],"value"));
							setattr(_targselect.options[x],"ItemID",getattr(_select[i].childNodes[x],"ItemID"));
							if (_targselect.options[x].value==selectValue)
							{
								_targselect.selectedIndex=x;	
							}
							
							//selectHTML=selectHTML+_select[i].childNodes[x].xml
						}
					
					//alert(selectHTML)
					
					//if (_targselect)
//					{
//						alert(_targselect.innerHTML);
//						_targselect.innerHTML=selectHTML;	
//						alert(_targselect.innerHTML);
//					}
						if(getattr(_targselect,"NeedInit")=="true")
						{
							_targselect.onchange();
						}
					}
					selectHTML="";
				}
			}
		}
	}
	}
	
}
	
function LoadNextAssist(TypeID,ItemContent,DataPage,RefreshControlID)
{
	
	//var _RefreshControl=RefreshControlID.split("^")
	
	//var _RefreshControl=GE(RefreshControlID)
	//alert(TypeID)
	//if (_RefreshControl)
	//{
			
			var ItemID=getattr(ItemContent,"ItemID")
			//alert(ItemID)
			if (ItemID!="")
			{
					//alert("dd")
					//alert(DataPage.replace("{0}",ItemID));
					getServer(DataPage.replace("{0}",ItemID),new Function("FillSelect('" + RefreshControlID +"')"));
					//alert("dd")
			}
	//}
}
var InitSelectCount=0;
var InitSelectArr=new Array();
function InitSelect()
{
	var _select=document.getElementsByTagName("select");
	if(_select)
	{
		for(var i=0;i<_select.length;i++)
		{
			if(getattr(_select[i],"NeedInit")=="true")
			{
				InitSelectCount++;
				InitSelectArr.push(_select[i]);
			}
		}
		if(InitSelectArr.length>0)
		{
			InitSelectArr[0].onchange();	
		}
	}
}
function DecToBin(num)
{
	var i=7;
	var _num=num;
	var num2=new Array(0,0,0,0,0,0,0,0);
	var num1="1";
	
	while (_num>1)
	{
		if (_num%2==0)
		{
			num2[i]="0"
		}
		else
		{
			num2[i]="1"		
		}
		i--;
		_num=parseInt(_num/2)
	}
	num2[i]=_num;
	return num2.join("");
}

function fGetDIVXY(aTag)
{
  //alert(aTag);
  var r = { x: aTag.offsetLeft, y: aTag.offsetTop };
  if (aTag.offsetParent)
   {
	    var tmp = fGetDIVXY(aTag.offsetParent);
	    r.x += tmp.x;
	    r.y += tmp.y;
    }
    return r;
	
}




