// 读取元素对象
function GetE( elementId )
{
	return document.getElementById( elementId )  ;
}
String.prototype.trim = function()
{
	return this.replace( /(^\s*)|(\s*$)/g, '' ) ;
}
// 取得checkbox的值，以","分割
function GetValueCheckBox( el, checked )
{
	// checked		读取类别，true--选中，默认，flase--所有选项
	var checked = ( checked == undefined || checked ) ? true : false;
	if ( !el )
		return;

	// 将单一元素设置为数组
	if ( !el.length )
		el = [ el ];

	var sValue = "";
	for( var i = 0; i < el.length; i++ )
	{
		var e = el[ i ];
		//单选下拉框提示选项设置为value=""
		if( e.value != "" )
		{
			// 读取选中值
			if ( checked && !e.checked )
				continue;
			sValue += e.value + ",";
		}
	}
	return sValue.substring( 0, sValue.length - 1 );
}
// 打开ModalDialog窗口
var Dialog = new Object() ;

Dialog.OpenDialog = function( dialogName, dialogTitle, dialogPage, width, height, customValue, framePage, parentWindow, resizable )
{
	// 设置传递的参数
	var oDialogInfo = new Object() ;
	// 标题
	oDialogInfo.Title = dialogTitle ;
	
	// 求被打开页面的绝对路径
	if ( dialogPage )
		dialogPage = AbsolutePath( document.location.pathname, dialogPage );
	// alert( "dialogPage:" + dialogPage );
	// 打开页面地址
	oDialogInfo.Page = dialogPage ;
	// 自定义传递参数变量
	oDialogInfo.CustomValue = customValue ;		// Optional
	
	// var sUrl = ( framePage ) ? framePage : dialogPage ;
	var sUrl = ( framePage ) ? framePage : getSrcDir( __Script__ ) + 'Dialog/dialog.html' ;

	return this.Show( oDialogInfo, dialogName, sUrl, width, height, parentWindow, resizable ) ;
}

Dialog.Show = function( dialogInfo, dialogName, pageUrl, dialogWidth, dialogHeight, parentWindow )
{
	if ( !pageUrl )
		return false;
	pageUrl = pageUrl + "?" + Math.round( Math.random() * 1000 );
	if ( !parentWindow )
		parentWindow = window ;

	return parentWindow.showModalDialog( pageUrl, dialogInfo, "dialogWidth:" + dialogWidth + "px;dialogHeight:" + dialogHeight + "px;help:no;scroll:no;status:no") ;
}

// 根据相对路径求被相对文件的完全路径
function AbsolutePath( sFile, file ){
	// file		被引用文件路径
	// sFile	基本文件
	if ( !file || file.substring(0, 1)=="/" || file.substring(0, 7)=="http://" )
		return file;
	var arrFile = file.split( "/" );
	var arrSFile = sFile.split( "/" );
	var cFile = arrFile.length;
	var cSFile = arrSFile.length;

	var nc = 0 ;
	var nFile = "";
	for ( var i = 0; i < cFile - 1; i ++ ){
		if ( arrFile[ i ] == ".." && nFile == "" ){
			nc ++;
		}else{
			nFile += arrFile[ i ] + "/";
		}
	}

	var path = "";
	var mc = arrSFile.length - nc- 1 ;
	if ( mc <= 0 )
		var mc = 1;
	for ( var j = 0; j < mc; j++ ){
		path += arrSFile[ j ] + "/";
	}

	path += nFile;

	return path + arrFile[ cFile - 1 ];;
}
