//////////////////////////////////////////////////
// Color Define => 颜色定义列表
//////////////////////////////////////////////////
var COLOR_WHITE		= "#FFFFFF";
var COLOR_TITLE		= "#C3D9FF";
var COLOR_ITEM		= "#F5F5F5";
var COLOR_SELECT	= "#FFFFCC";
var COLOR_HOVER		= "#C3D9EE";
var COLOR_FOCUS		= "#FFCCCC";

//////////////////////////////////////////////////
// Resource Type => 资源类型列表
//////////////////////////////////////////////////
var RES_Nothing		= -1;		// 未配置资源
var RES_HardWare	= 0;		// 采集硬件设备
var RES_Desktop		= 1;		// 采集本机桌面
var RES_MediaFile	= 2;		// 采集媒体文件
var RES_PushStream	= 3;		// 编码器推
var RES_PullStream	= 4;		// 编码器拉

//////////////////////////////////////////////////
// Track State => 服务器反馈的频道状态
//////////////////////////////////////////////////
var	eNoneState		= 0;		// None-State
var	eApplyState		= 1;		// Apply-State
var	eStoppedState	= 2;		// Stopped-State
var	eRunningState	= 3;		// Running-State
var	ePauseState		= 4;		// Pause-State

var GM_PUBLISH_NO	= 0;		// 未发布
var GM_PUBLISH_YES  = 1;		// 已发布

//
// JavaScript string class extention...
String.prototype.trim = function() {
	return this.replace(/(^\s*)|(\s*$)/g, "");
}
String.prototype.isEMAIL = function() {
	var myPatrn = /^[A-Za-z0-9]+([._\-\+]*[A-Za-z0-9]+)*@([A-Za-z0-9]+[-A-Za-z0-9]*[A-Za-z0-9]+\.)+[A-Za-z0-9]+$/;
	return myPatrn.test(this);
}
Function.prototype.getMultiLine = function() {   
    var lines = new String(this);   
    lines = lines.substring(lines.indexOf("/*") + 3, lines.lastIndexOf("*/"));   
    return lines;   
}
function S(i, win) {
	return (win?win:window).document.getElementById(i);
}
function GetLeftWin() {
	return top.leftFrame;
}
function GetMainWin() {
	return top.mainFrame ? top.mainFrame : top;
}
function FolderListResize() {
	var f = GetLeftWin();
	if(!S("folder", f))	return; 
	var dh = parseInt(f.document.body.clientHeight);
	var s = dh < 440;
	S("folder", f).style.height = dh - 15;
	S("folder", f).style.overflow = s ? "auto" : "hidden";
	S("folder", f).style.margin = s ? "0 5px 0 0" : "0";
}
function fAddEvent(oTarget, sType, fHandler, bRemove) {
	if (!oTarget) {
		return;
	}
	if (oTarget.addEventListener) {
		bRemove ? oTarget.removeEventListener(sType, fHandler, false) : oTarget.addEventListener(sType, fHandler, false);
	}
	else if (oTarget.attachEvent) {
		bRemove ? oTarget.detachEvent("on" + sType, fHandler) : oTarget.attachEvent("on" + sType, fHandler);
	}
	else {
		oTarget["on" +sType] = bRemove ? null : fHandler;
	}
}
function fRemoveEvent(oTarget, sType, fHandler) {
	if (!oTarget) {
		return;
	}
	if (oTarget.removeEventListener) {
		oTarget.removeEventListener(sType, fHandler, false);
	} 
	else if (oTarget.detachEvent) {
		oTarget.detachEvent("on" + sType, fHandler);
	}
	else {
		oTarget["on" + sEventType] = null;
	}
}
function doImageSubmit(_form) {
	_form.Save.disabled = true;
	var strFile = _form.postfile.value;
	if( strFile.length <= 1 || strFile.charAt(1) != ':' ) {
		alert('必须选择要上传的图片文件');
		_form.Save.disabled = false;
		_form.postfile.focus();
		return false;
	}
	if( typeof(image_error_div)=='object' )
		image_error_div.innerHTML = "<img src='images/loading.gif' />";
	return true;
}
function glHideMenu(_item) {
	if( _item != null )
		_item.style.display = "none";
}
function glShowMenu(_item) {
	var el = document.activeElement;
	if( _item != null ) {
		_item.style.display = 'block'; 
		_item.style.pixelLeft = glGetPos(el,"Left"); 
		_item.style.pixelTop = glGetPos(el,"Top") + el.offsetHeight;
	}
}
function glGetPos(_el,_sProp) {
	var iPos = 0;
	while(_el != null) {
		iPos += _el["offset" + _sProp];
		_el = _el.offsetParent;
	}
	return iPos;
}
function glCheckDateTime(_dateTime) {
	var myPatrn = /^(\d{4})-(\d{2})-(\d{2})\s(\d{2}):(\d{2}):(\d{2})$/;
	return myPatrn.test(_dateTime);
}
function glCutString(_text,_len) {
	var nTheLength = 0;
	for(var nIndex = 0; nIndex < _text.length; ++nIndex) {
		if( _text.charCodeAt(nIndex) > 255 )	// Chinese
			nTheLength += 2;
		else
			nTheLength += 1;					// ASIIC
		if( nTheLength >= _len )	
			break;
	}
	var strResult = _text.substr(0, nIndex);
	if( strResult.length < _text.length )
		strResult = strResult + "...";
	return strResult;
}
function glEncodeUrl(_url) {
	var strValue = "";
	strValue = _url.replace(/&/g,">");		// "&" => ">"
	strValue = strValue.replace(/\+/g,"|");	// "+" => "|"
	return strValue;
}
function glEncodePath(_path) {
	var strValue = "";
	strValue = _path.replace(/ /g,"<");		// " " => "<"
	strValue = strValue.replace(/&/g,">");	// "&" => ">"
	strValue = strValue.replace(/\+/g,"?");	// "+" => "?"
	strValue = strValue.replace(/%/g,"|");	// "%" => "|"
	return strValue;
}
function glEventClose(_table,_page) {
	if( _table != null ) {
		var _tr = null;
		var _theEnd = _table.rows.length;
		for(var i = 1; i < _theEnd; ++i) {
			_tr = _table.rows[i];
			_tr.onmouseout = null;
			_tr.onmouseover = null;
			_tr = null;
		}
		_table.onclick = null;
	}
	if( _page != null ) {
		var theFirst = _page.all['pageFirst'];
		if( typeof(theFirst) == 'object' )
			theFirst.onclick = null;
		var thePrev = _page.all['pagePrev'];
		if( typeof(thePrev) == 'object' )
			thePrev.onclick = null;
		var theNext = _page.all['pageNext'];
		if( typeof(theNext) == 'object' )
			theNext.onclick = null;
		var theLast = _page.all['pageLast'];
		if( typeof(theLast) == 'object' )
			theLast.onclick = null;
		var theSelect = _page.all['pageSelect'];
		if( typeof(theSelect) == 'object' )
			theSelect.onchange = null;
	}
}
//
// Define base ajax class for all class...
/*var GMAjax = Class.create();
GMAjax.prototype = {
	initialize: function() {
	},
	doAjaxValue: function() {
		this.m_AjaxType = "";
		this.m_AjaxObject = null;
		this.m_arWnd = new Array();
	},
	AbortAjax: function() {
		if( this.m_AjaxObject != null ) {
			var theTrans = this.m_AjaxObject.transport;
			theTrans.abort(); theTrans = null;
		}
	},
	SendAjaxRequest: function(_url) {
		var theComplete = this.DoAjaxResponse.bindAsEventListener(this);
		var theCmd = ((arguments[1] != null) ? arguments[1] : 'GET');
		var theBody = ((arguments[2] != null) ? arguments[2] : null);
		var theOptions = {
      		method:     theCmd,
      		postBody:	theBody,
			onComplete: theComplete
		};
		delete this.m_AjaxObject;
		this.m_AjaxObject = new Ajax.Request(_url,theOptions);
	},
	onCloseWnd: function(_id) {
		var theWnd = this.m_arWnd[_id];
		if( typeof(theWnd) == 'object' ) {
			theWnd.OnDestroy(); theWnd = null;
			delete this.m_arWnd[_id];
		}
	}
};*/
//
// Gemini base window class implement...
var GMWnd = Class.create();
GMWnd.prototype = {
	initialize: function(_id,_html,_width,_height) {
		this.m_ObjX = 0;
		this.m_ObjY = 0;
		this.m_id = null;
		if( $(_id) != null )
			return;
		this.m_id = _id;
		var hasBG = ((arguments[4] != null) ? arguments[4] : true);
		if( hasBG ) {
			var wndBG = document.createElement("div");
			var wndBG_id = _id + "_bg";
			var wndBG_left = 0;
			var wndBG_top = document.body.scrollTop;
			var wndBG_width = window.frameElement.offsetWidth;
			var wndBG_height = window.frameElement.offsetHeight;
		    var wndBG = this.set_div_style(wndBG,wndBG_id,wndBG_top,wndBG_left,wndBG_width,wndBG_height,"absolute","0px solid #c0d4db","default","#000",30);
			document.body.appendChild(wndBG);
		}
		var lw = document.createElement("div");
		var lw2 = document.createElement("div");
		var iFrame = document.createElement("iframe");
	    var lw_id = _id;
	    var lw2_id = _id + "_lw2";
	    var frame_id = _id + "_frame";
	    var lw_left = window.frameElement.offsetWidth/2 - _width/2;
	    var lw_top = window.frameElement.offsetHeight/2 - _height/2 - 30 + document.body.scrollTop;
	    var lw2_left = 0;
	    var ifr_left = 0;
	    var lw = this.set_div_style(lw,lw_id,lw_top,lw_left,_width,_height,"absolute","0px solid #c0d4db","default","#fff");
	    var lw2 = this.set_div_style(lw2,lw2_id,0,lw2_left,_width,_height,"absolute","1px solid #c0d4db","default","#fff");
	    var iFrame = this.set_div_style(iFrame,frame_id,0,0,_width,_height,"absolute","0px solid #c0d4db","default","#fff");
	    iFrame.frameBorder = "0";
	    iFrame.name = frame_id;
		lw2.innerHTML += _html;
		document.body.appendChild(lw);
		lw.appendChild(iFrame);
	    lw.appendChild(lw2);
	    var drag_div = lw2.firstChild.childNodes[2];
	    var my_move = this.drag_mouse_move.bindAsEventListener(this);
	    var my_down = this.drag_mouse_down.bindAsEventListener(this);
	    var my_up = this.drag_mouse_up.bindAsEventListener(this);
	    drag_div.onmousemove = function() {
	    	my_move(lw);
	    };
	    drag_div.onmousedown = function() {
	    	drag_div.setCapture();
	    	my_down(lw);
	    };
	    drag_div.onmouseup = function() {
	    	drag_div.releaseCapture();
	    	my_up();
	    };
	},
	OnDestroy: function() {
		var lw = $(this.m_id);
		var bg = $(this.m_id + "_bg");
		var lw2 = $(this.m_id + "_lw2");
	    var drag_div = lw2.firstChild.childNodes[2];
	    drag_div.onmousemove = null;
	    drag_div.onmousedown = null;
	    drag_div.onmouseup = null;
        document.body.removeChild(lw);
		document.body.removeChild(bg);
        bg = null; lw = null; lw2 = null; drag_div = null;
	},
	set_div_style: function(_obj,_id,_top,_left,_width,_height,_position,_border,_cursor,_background,_filter) {
		var obj = _obj;
		obj.style.filter = _filter ? "Alpha(Opacity=" + _filter + ")" : 0;
	    obj.id = _id?_id:null;
	    obj.style.top = _top?_top:0;
	    obj.style.left = _left?_left:0;
	    obj.style.width = _width?_width:0;
	    obj.style.height = _height?_height:0;
	    obj.style.position = _position?_position:"static";
	    obj.style.border = _border?_border:"1px #000 solid";
	    obj.style.cursor = _cursor?_cursor:"default";
	    obj.style.background = _background?_background:"";
	    return obj;
	},
	drag_mouse_move: function(_obj) {
		if( this.m_ObjX!=0 && this.m_ObjY!=0 ) {
			if( event!=null && event.button==1 ) {
				var theLeft = event.clientX - this.m_ObjX;
	            var theTop = event.clientY - this.m_ObjY;
	            var theWidth = theLeft + _obj.offsetWidth;
	            var theHeight = theTop + _obj.offsetHeight;
	            if( theLeft < 0 || theTop < 0 || theWidth >= window.frameElement.offsetWidth ||	theHeight >= window.frameElement.offsetHeight )
	            	return;
            	_obj.style.left = theLeft;
            	_obj.style.top = theTop;
			}
		}
	},
	drag_mouse_down: function(_obj) {
		var obj_left = _obj.style.pixelLeft;
	    var obj_top = _obj.style.pixelTop;
	    var clientX = event.x;
	    var clientY = event.y;
	    this.m_ObjX = clientX - obj_left;
	    this.m_ObjY = clientY - obj_top;
	},
	drag_mouse_up: function() {
	   	this.m_ObjX = 0;
	   	this.m_ObjY = 0;
	}
};
