﻿// JavaScript Document
function $(id) { return document.getElementById(id); }
// 重置页面容器大小
function resizeBox(id,cutheight) {
	var bodyHeight = document.body.clientHeight;
	$(id).style.height = (bodyHeight-cutheight) + "px";
}

// 插入标签
function insertLabel(contentObj,labelContent)
{
	$(contentObj).focus();
    var str = document.selection.createRange();
  	str.text = labelContent; 
}
// 打开窗口
function openWindow(url,width,height,windowObj){
	var ReturnStr=showModalDialog(url,windowObj,'dialogWidth:'+width+'pt;dialogHeight:'+height+'pt;status:no;help:no;scroll:no;status:0;help:0;scroll:0;');
	return ReturnStr;
}
// 打开窗口 返回值给父窗口
function openThenSetValue(url,width,height,windowObj,setObj){
	if (document.all){
	var ReturnStr=showModalDialog(url,windowObj,'dialogWidth:'+width+'pt;dialogHeight:'+height+'pt;status:no;help:no;scroll:no;status:0;help:0;scroll:0;');
	if (ReturnStr!='') $(setObj).value=ReturnStr;
	if (ReturnStr==null) $(setObj).value='';
	return ReturnStr;
	}else{
		 
	 var obj = $(setObj);
	 width=width+180;
	 height=height+80;
	 window.open(wrl,'newWin','modal=yes,width='+width+',height='+height+',resizable=no,scrollbars=no');
	}
}

/* 验证表单 
   参数: idArray 表单元素数组,正则表达式数组,提示信息数组
*/
function checkFormByAlert(idArray,patternArray,errorMessage) {
	var flag = true;
	for(i = 0; i < idArray.length; i++) {
		if($(idArray[i]).value.match(patternArray[i])==null) {
			alert(errorMessage[i]);
			$(idArray[i]).focus();
			flag = false;
			break;
		}
	}
	return flag;
}

// 改变表格背景色
function changeBgColor(obj,classname) {
	var elements = obj.childNodes;
	for(var i=0;i<elements.length;i++)
	{
		elements[i].className = classname;
	}
	obj.onmouseout = function() {
		for(var i=0;i<elements.length;i++)
		{
			elements[i].className = "";
		}
	}
}

// 重置当前页面
function resetUrl(url,action,urlid) {
    location.href = url + "?action=" + action + "&id=" + urlid;
}

// 全选|反选
function selectAll(e,parentId,tag) {
	var checkboxs=document.getElementById(parentId).getElementsByTagName(tag);
    for (var i=0; i<checkboxs.length; i++) {              
    	checkboxs[i].checked = e.checked;
    }
}

// 全选|反选 <input onclick="selectAll('e','itemName')" /> e 触发事件checkbox,itemName为要全选的checkbox子项名称
function selectAll(e,itemName) {
	var checkboxs = document.getElementsByName(itemName);
	for (var i=0; i<checkboxs.length; i++) {              
    	checkboxs[i].checked = e.checked;
    }
}

// 左侧控制(show or hidden,control为主控标记,bycontrol为受控标记)
function showHidden(control,bycontrol) {
	if($(bycontrol).style.display == "") {
		$(bycontrol).style.display = "none";
		$(control).src = "Images/Permissions/arrow_right.gif";
	}
	else if($(bycontrol).style.display == "none") {
		$(bycontrol).style.display = "";
		$(control).src = "Images/Permissions/arrow_left.gif";
	}
	else { 
		$(bycontrol).style.display=""; 
		$(control).src = "Images/Permissions/arrow_right.gif";
	}
}
// 左侧滑动菜单
function switchMenu(menu,number,count) {
	for(i=1; i <=count; i++) {
		if (i==number) { 
			$(menu + i).className = menu + "On"; 
			$(menu + "box" + i).style.display="block";
		}
		else { 
			$(menu + i).className = menu + "Off"; 
			$(menu + "box" + i).style.display="none";
		}
	}
}
// 开关
function showMenu(menu,css) {
	if($("box_" + menu).style.display == "") {
		$("box_" + menu).style.display = "none";
		$(menu).className= css + "Off";
	}
	else if($("box_" + menu).style.display == "none") {
		$("box_" + menu).style.display = "";
		$(menu).className= css + "On";
	}
	else {
		$("box_" + menu).style.display = "";
		$(menu).className= css + "On";
	}
}
// ajax object
function ajaxObj()
{
	if(window.XMLHttpRequest){
		return new XMLHttpRequest();
	} else if(window.ActiveXObject){
		return new ActiveXObject("Microsoft.XMLHTTP");
	} 
	throw new Error("XMLHttp object could be created.");
}

// ajax 用于左侧滑动菜单
function getResponse(posturl)
{ 
  var result="";
  try{
	var ajax = new ajaxObj(); 
	ajax.open("get",posturl,false);
    ajax.onreadystatechange = function(){
		if(ajax.readyState == 1) { 
			result="";
		}
	    else if(ajax.readyState == 2 || ajax.readyState == 3) {
			result="";
		}
		else if(ajax.readyState == 4) {
			if (ajax.status == 200) {
				result = ajax.responseText;
			}
		}
	}
	ajax.send(result);  
  }
  catch(e)
  {}
  return result;
}

// 获取当前系统时间
function myTime(timebox){
    $(timebox).innerHTML = new Date().toLocaleString();
    var mytimer = setTimeout("myTime('"+timebox+"')",1000);
}
// 设置css样式
function setCurrentMenu(menuId,cssStyle)
{
	$(menuId).className = $(menuId).className + " " + cssStyle;
}

function setCurrentMenusa(menuIdsa,cssStylesa)
{
	$(menuIdsa).className = $(menuIdsa).classNamesa + " " + cssStyle;
}




//window.onload = function(){ resizeBox('leftbox',128); resizeBox('togglebox',128); resizeBox('rightbox',128);}
//window.onresize = function(){ resizeBox('leftbox',128); resizeBox('togglebox',128); resizeBox('rightbox',128); }
