
/**
 * Set the Conponet of select to secified index.
 * @param {Object} Object
 * @param {Object} Value
 */
function compareListValue(Object, Value) {
	for (i = 0; i < Object.length; i++) {
		if (Value == Object.options[i].value) {
			Object.selectedIndex = i;
		}
	}
}
/**
 * Get the value of the radio group.
 * @param {Object} _name
 */
function getRadioValue(_name) {
	var values = document.getElementsByName(_name);
	for (var i = 0; i < values.length; i++) {
		if (values[i].checked) {
			return values[i].value;
		}
	}
}
/**
 * Open a new window with the specified parameters
 * @param {Object} url
 * @param {Object} _name
 * @param {Object} iWidth
 * @param {Object} iHeight
 */
openwindow = function (url, _name, iWidth, iHeight) {
	var url;
	var name = _name;
	var iWidth;
	var iHeight;
	var iTop = ((window.screen.availHeight) - parseInt(iHeight)) / 2;
	var iLeft = ((window.screen.availWidth) - parseInt(iWidth)) / 2;
	newWindow = window.open(url, name, "height=" + iHeight + ",innerHeight=" + iHeight + ",width=" + iWidth + ",innerWidth=" + iWidth + ",top=" + iTop + ",left=" + iLeft + ",toolbar=no,menubar=no,scrollbars=auto,resizable=no,status=no");
	newWindow.focus();
	return newWindow;
};
/**
 * Clear the information in the page
 * @param {Object} tempObj
 */
function cleanComponentValues(formContainer) {
	with (formContainer) {
		for (var i = 0; i < elements.length; i++) {
			if (elements[i].type.toUpperCase() == "TEXT" || elements[i].type.toUpperCase() == "HIDDEN") {
				elements[i].value = "";
			}
			if (elements[i].tagName.toUpperCase() == "SELECT") {
				tempObj.item(i).selectedIndex = 0;
			}
			if (elements[i].tagName.toUpperCase() == "CHECKBOX") {
				elements[i].checked = false;
			}
		}
	}
}
/**
 * Set submit state
 * @param {Object} flag
 */
function submitState(flag) {
	var allComponents = document.getElementsByTagName("input");
	for (var i = 0; i < allComponents.length; i++) {
		if ((allComponents[i].type.toUpperCase() == "BUTTON" || allComponents[i].type.toUpperCase() == "SUBMIT" || allComponents[i].type.toUpperCase() == "IMAGE")) {
			if (flag == false) {
				allComponents[i].disabled = !false;
			} else {
				if (flag == !false) {
					allComponents[i].disabled = false;
				}
			}
		} else {
			continue;
		}
	}
}

/**
 * 
 * @param {Object} e
 */
function getLength(e) {
	if (e) {
		var str = e.replace(/[^\x00-\xff]/g, "**");
		return str.length;
	}
	return 0;
}
/**
 * 
 * @param {Object} str
 * @param {Object} begin
 * @param {Object} end
 */
function subString(str, begin, end) {
	var length = getLength(str);
	if (parseInt(length) > parseInt(end)) {
		return str.leftB(begin, end) + "...";
	} else {
		return str;
	}
}

/**
 * 
 * @param {Object} begin
 * @param {Object} len
 */
String.prototype.leftB = function (begin, len) {
	var s = this.replace(/\*/g, " ").replace(/[^\x00-\xff]/g, "**");
	return this.slice(0, s.slice(0, len).replace(/\*\*/g, " ").replace(/\*/g, "").length);
};

/**
 * 
 */
String.prototype.trim = function () {
	return this.replace(/(^\s*)|(\s*$)/g, "");
};

/**
 * 
 */
String.prototype.toSimpleDate = function () {
	if (this.indexOf("-") != -1) {
		elements = this.split("-");
		if (elements.length == 3) {
			if (elements[1] != 10 && elements[2] != 10 && elements[2] != 20 && elements[2] != 30) {
				return elements[0] + "-" + (elements[1] + "-" + elements[2]).replace(/((0)*)/g, "");
			} else {
				return elements[0] + "-" + elements[1] + "-" + elements[2];
			}
		} else {
			return this.replace(/((0)*)/g, "");
		}
	}
};

/**
 * 
 * @param {Object} _form
 * @param {Object} _actionPath
 */
function deleteObjects(_form, _actionPath) {
	with (_form) {
		var rec = "";
		var j = 0;
		var k = 0;
		for (var i = 0; i < elements.length; i++) {
			if ((elements[i].type == "checkbox") && (elements[i].checked == false)) {
				j++;
			}
		}
		for (var i = 0; i < elements.length; i++) {
			if (elements[i].type == "checkbox") {
				k++;
			}
		}
		if (j == k) {
			alert("\u8bf7\u9009\u62e9\u60a8\u8981\u5220\u9664\u7684\u9879\u76ee\uff01");
		} else {
			if (confirm("\u786e\u5b9a\u8981\u5220\u9664\uff1f")) {
				action = _actionPath;
				submit();
			}
		}
	}
}
/**
 * 
 * @param {Object} _form
 * @param {Object} _actionPath
 */
function queryObjects(_form,_actionPath){
	with (_form) {
		action = _actionPath;
		submit();
	}
}
/**
 * 
 * @param {Object} _form
 * @param {Object} _actionPath
 */
function showSchoolSelection(schoolId,schoolname,classes){
				var returnValue = showModalDialog("/school/displaySchoolList.do", window, "dialogWidth:450px;dialogHeight:550px;help:no;scroll:no;status:no;");
				if(returnValue){
				  $("#"+schoolId).val(returnValue[1]);
				  $("#"+schoolname).val(returnValue[0]);
				$.getJSON(
					     "/console/getSpecialtyListBySchoolname.do",
					    {schoolId: returnValue[1]},
					     function(json){
					     var selecthtml;
					     selecthtml="<select id=\"specialtyId\" name=\"specialtyId\" dataType=\"Require\" msg=\"\u8bf7\u9009\u62e9\u4e13\u4e1a\" isRequire=\"false\">";
					     	selecthtml += "<option value=\"\">\u8bf7\u9009\u62e9</option>";
					     	for(var i=0;i<json.length;i++){
					     		selecthtml += "<option value=\""+json[i]["id"]+"\">";
					     		selecthtml += json[i]["caption"];
					     		selecthtml += "</option>"
					     	}
					     	selecthtml=selecthtml+"</select>"
					     	$("#"+classes).text("");
					     	$("#"+classes).append(selecthtml);
					     }   
 						);}else{
 						//$("#"+classes).append("<font color='red'>\u8bf7\u9009\u62e9\u5b66\u6821\uff0c\u518d\u9009\u62e9\u4e13\u4e1a</font>");
					return;
				}
			}
			
function showSchoolSelectionOnly(schoolId,schoolname){
				var returnValue = showModalDialog("/school/displaySchoolList.do", window, "dialogWidth:750px;dialogHeight:650px;help:no;scroll:no;status:no;");
				if(returnValue){
				  $("#"+schoolId).val(returnValue[1]);
				  $("#"+schoolname).val(returnValue[0]);
				  return;
				 }			 			 
}

function showSchoolSelCaption(schoolId,schoolname,classes){
				var returnValue = showModalDialog("/school/displaySchoolList.do", window, "dialogWidth:750px;dialogHeight:650px;help:no;scroll:no;status:no;");
				if(returnValue){
				  $("#"+schoolId).val(returnValue[1]);
				  $("#"+schoolname).val(returnValue[0]);
				$.getJSON(
					     "/console/getSpecialtyListBySchoolname.do",
					    {schoolId: returnValue[1]},
					     function(json){
					     var selecthtml;
					     selecthtml="<select id=\"specialtyId\" name=\"authorPlace.specialtyname\" dataType=\"Require\" msg=\"choose specialty\" isRequire=\"true\">";
					     	for(var i=0;i<json.length;i++){
					     		selecthtml=selecthtml+"<option value=\""+json[i]["caption"]+"\">";
					     		selecthtml=selecthtml+json[i]["caption"];
					     		selecthtml=selecthtml+"</option>"
					     	}
					     	selecthtml=selecthtml+"</select>"
					     	$("#"+classes).text("");
					     	$("#"+classes).append(selecthtml);
					     }   
 						);}else{
 						//$("#"+classes).append("<font color='red'>\u8bf7\u9009\u62e9\u5b66\u6821\uff0c\u518d\u9009\u62e9\u4e13\u4e1a</font>");
					return;
				}
			}
/**
*	Forward Form.
*/
function forward(_form,_path,_param){
	with(_form){
		action=_path+_param;
		submit();
	}
}

/*************************************************
 **	Description:Selector
 **	Author:Chenghaojun
 **	Create:2008-08-27
 */
var Initializer = {
  	Version : '1.0.0',
  	Author : 'Chenghaojun',
 	setSelectot : function(){
 		var allChk = document.getElementsByTagName("SELECT");
		for(var i=0; i<allChk.length; i++){
			if(allChk[i].getAttribute("_value") != undefined){
				for (j = 0; j < allChk[i].length; j++) {
					if (allChk[i].getAttribute("_value") == allChk[i].options[j].value) {
						allChk[i].selectedIndex = j;
					}
				}
			}
		}
 	},
 	bind : function(_path){
 		var forms = document.getElementsByTagName("FORM");
 	}
}
window.onload = function(){
	if(typeof(window.onload) == "function"){
		window.eval(window.onload);
	}
	Initializer.setSelectot();
	Initializer.bind();
}

function createElement(type, name) {
    var element = null;
  	try{
       element = document.createElement('<'+type+' name="'+name+'">');
    }catch(e){
    	//
    }
    if (!element) {
       element = document.createElement(type);
       element.name = name;
    }
    return element;
}
	

