/****************************************
**
**  author: johnson
**	description: common class lib
**	(描述: 共用类库,存放js共用类及方法的lib库)
**	createdate: 2009-08-08
**	(创建时间: 2009-08-08)
**
*****************************************/

/**************************************
 **	公共方法类
 **************************************/
 var CommonClass = function(){
 	/**************************************
	** 库常量
	**************************************/
	//课程库
	var COURSELIB = "http://www.qvedu.com/xmllib/COURSETABLE.xml";
	//SELECT列表库
	var SELECTLIB = "http://www.qvedu.com/xmllib/SELECTTABLE.xml";
	/****************************************
 	** 搜索网内课程 
 	** searchCond: 查询条件
 	** major: 专业
 	** university 学校
 	** resultSet 取出的表结果
 	*****************************************/
 	this.searchCourse = function(searchCond,major,university,resultSet){
 	 	//课程结果集,内部放课程对象。
 	 	var searchResult = new Array();
 	 	var searchCondBOOL = searchCond!="";
 	 	var marjorBOOL = major!="";
 	 	var universityBOOL = university!="";
 	 	if(searchCondBOOL){
	 	 	for(var i=0; i<resultSet.length; i++){
	 	 		//取出三个条件对象
	 	 		var courseName = this.getString(resultSet[i],"coursename");
	 	 		var majorName = this.getString(resultSet[i],"major");
	 	 		var universityName = this.getString(resultSet[i],"university");
	 	 		//过滤条件
	 	 		var containSearchCond = courseName.indexOf(searchCond)!=-1;
	 	 		var containMarjor = majorName.indexOf(major)!=-1;
	 	 		var containUniversity = universityName.indexOf(university)!=-1;
	 	 		var finalBOOL;
	 	 		if(marjorBOOL && universityBOOL){//专业、学校不为空
		 	 		//push 条件
		 	 		finalBOOL = containSearchCond && containMarjor && containUniversity;
		 	 		//push 满足条件的对像
		 	 		if(finalBOOL){
		 	 			searchResult.push(resultSet[i]);
		 	 		}
	 	 		}else if(marjorBOOL){//专业不为空
	 	 			//push 条件
		 	 		finalBOOL = containSearchCond && containMarjor;
		 	 		//push 满足条件的对像
		 	 		if(finalBOOL){
		 	 			searchResult.push(resultSet[i]);
		 	 		}
	 	 		}else if(universityBOOL){//学校不为空
	 	 			//push 条件
		 	 		finalBOOL = containSearchCond && containUniversity;
		 	 		//push 满足条件的对像
		 	 		if(finalBOOL){
		 	 			searchResult.push(resultSet[i]);
		 	 		}
	 	 		}else{//专业、学校为空
	 	 			//push 条件
	 	 			finalBOOL = containSearchCond;
		 	 		//push 满足条件的对像
	 	 			if(finalBOOL){
	 	 				searchResult.push(resultSet[i]);
	 	 			}
	 	 		}
	 	 	}
 	 	}
		
		return searchResult;
 	}
 	
 	/****************************************
 	** 通过列名取出列值
 	** nodeRow：元组对象(表中定位行对象)
 	** 通过列名取出列值
 	*****************************************/
 	this.getString = function(nodeRow,colName){
 		var valueSTR = null;
 		for(var i=0; i<nodeRow.childNodes.length; i++){
 			if(colName == nodeRow.childNodes[i].nodeName){
 				valueSTR = nodeRow.childNodes[i].firstChild.nodeValue;
 			}
 		}
 		return valueSTR;
 	}
 	
 	/****************************************
 	** 创建XMLHttpRequest对象
 	*****************************************/
 	 this.createXMLHttpRequest = function(){
 	 	 var xmlHttp;
 	 	 //IE
 	 	 if(window.ActiveXObject){
 	 	 	 xmlHttp = new ActiveXObject("Microsoft.XMLHTTP");
 	 	 }else if(window.XMLHttpRequest){//NO IE
 	 	 	 xmlHttp = new XMLHttpRequest();
 		 }
 		 
 		 return xmlHttp;
 	 }
 	 
 	/****************************************
 	** 表格操作方法
 	*****************************************/
 	//添加行
 	//obj: table的tbody对象
 	//tr: tr对象
 	this.addTR = function(obj,tr){
 		if(tr){
			obj.appendChild(tr);
 		}else{
 			tr = document.createElement("TR");
			obj.appendChild(tr);
 		}
 		
 		return tr;
 	}
 	
 	//添加列
 	//obj: tr对象
 	//td: td对象
 	this.addTD = function(obj,td){
 		if(td){
			obj.appendChild(td);
 		}else{
 			tr = document.createElement("TD");
			obj.appendChild(td);
 		}
 		
 		return td;
 	}
 	
 	//设置td文本
 	//td: td对象
 	//textSTR: 文本字符串
 	this.setText = function(td,textSTR){
 		td.innerHTML = textSTR;
 	}
 	
 	//设置align
 	//td: td对象
 	//textSTR: 文本字符串
 	this.setAlign = function(td,valueSTR){
 		td.setAttribute("align",valueSTR);
 	}
 	
 	//设置attribute
 	//td: td对象
 	//textSTR: 文本字符串
 	this.setAttribute = function(obj,aName,aValue){
 		obj.setAttribute(aName,aValue);
 	}
 	
 	/****************************************
 	** select 操作区
 	*****************************************/
 	//填充select内容
 	//obj: select对象
 	//resultSet: 填内容列表
 	this.createSelectContent = function(obj,resultSet,colName){
 		//遍历添加select的options
 		for(var i=0; i<resultSet.length; i++){
 			var option = document.createElement("option"); 
	 		var text = this.getString(resultSet[i],colName);
	 		this.setSelectText(option,text);
	 		this.setSelectValue(option,text);
	 		this.addOptions(obj,option);
 		}
 	}
 	//添加select options
 	//obj: select对象
 	//option: option对象
 	this.addOptions = function(obj,option){
 		obj.options.add(option);
 	}
 	//获取选择的options text
 	//obj: option对象
 	//textSTR: option对象的text值
 	this.setSelectText = function(obj,textSTR){
 		obj.text = textSTR;
 	}
 	//获取选择的options value
 	//obj: option对象
 	//valueSTR: option对象的value值
 	this.setSelectValue = function(obj,valueSTR){
 		obj.value = valueSTR;
 	}
 	 
 	/****************************************
 	** set get 方法区
 	*****************************************/
 	//获取 COURSELIB
	this.getCourselib = function(){
		return COURSELIB;
	}
 	//获取 MAJORLIB
	this.getSelectlib = function(){
		return SELECTLIB;
	}
	
	/********************************
	**	获取当前日期时间(静态实现)
	*********************************/

	this.getCurrentTime = function(obj){
		var day="";
		var month="";
		var ampm="";
		var ampmhour="";
		var myweekday="";
		var year="";
		var hour="";
		var minute="";
		var second="";
		//获取日期
		mydate=new Date();
		myweekday=mydate.getDay();
		mymonth=mydate.getMonth()+1;
		myday= mydate.getDate();
		myyear= mydate.getYear();
		year=(myyear > 200) ? myyear : 1900 + myyear;
		//获取时间
		hour = mydate.getHours();
		minute = mydate.getMinutes();
		second = mydate.getSeconds();
		if(myweekday == 0)
		weekday=" 星期日 ";
		else if(myweekday == 1)
		weekday=" 星期一 ";
		else if(myweekday == 2)
		weekday=" 星期二 ";
		else if(myweekday == 3)
		weekday=" 星期三 ";
		else if(myweekday == 4)
		weekday=" 星期四 ";
		else if(myweekday == 5)
		weekday=" 星期五 ";
		else if(myweekday == 6)
		weekday=" 星期六 ";
		obj.innerHTML = year+"年" + mymonth + "月" + myday + "日" + hour + ":" + minute + ":" + second + weekday;
	 } 
 	
 }

/**************************************
 **	CommonClass 类静态内容实现区
 *************************************/

//内容收藏(静态实现)
CommonClass.addCollection = function(){
 	if(document.all){
 		window.external.addFavorite(window.location.href,document.title);
 	}else if(window.sidebar){
 		window.sidebar.addPanel(document.title,window.location.href,"");
 	}
 }
 
/******************************************
**	动态控制DIV显示
**	showContentId 要显示的内容区id
**	selfObj 要操作的对像
**	cName 要更新成的样式名称
*******************************************/

CommonClass.selectTag = function(showContent,selfObj,cName){
	var j = null;
	//更改标签css样式
	for(i=0; j=document.getElementById("tag"+i); i++){
		j.className ="tag"+i;
	}
	selfObj.className = cName;
	//控制操作内容显示
	for(i=0; j=document.getElementById("tagContent"+i); i++){
		j.style.display = "none";
	}
	document.getElementById(showContent).style.display = "block";
}

 /******************************************
**	动态图片交替显示
**	aId 要操作的IMG对象
**	imgId 要操作的IMG对象
**	pic1Path 图片１PATH
**	pic2Path 图片２PATH
**	link1 图片１PATH
**	link2 图片２PATH
**	title1 图片１PATH
**	title2 图片２PATH
*******************************************/

CommonClass.twoPicSwap = function(aId,imgId,pic1Path,pic2Path,link1,link2,title1,title2){
	var aObj = document.getElementById(aId);
	var imgObj = document.getElementById(imgId);
	if(aObj.href != link1){
		imgObj.src = pic1Path;
		aObj.href = link1;
		aObj.title = title1;
	}else{
		imgObj.src = pic2Path;
		aObj.href = link2;
		aObj.title = title2;
	}
}

