
function $(id){
	return document.getElementById(id);
}

/**
*  根据class名取得对象
*/
function getElementsByClassName(clsName) {
  var retVal = new Array();    
  var elements = document.getElementsByTagName("*");    
  for(var i = 0;i < elements.length;i++){
     if(elements[i].className.indexOf(" ") >= 0){
     	var classes = elements[i].className.split(" ");
     	for(var j = 0;j < classes.length;j++){
     		if(classes[j] == clsName)
     			retVal.push(elements[i]);
   	        }
   	    }
   	else if(elements[i].className == clsName)
   		retVal.push(elements[i]);    
  }
  return retVal;
}

/**
*  取得选中radio的值
*/
function getRadioValue(name) {
	var obj = document.getElementsByName(name);
    for(i = 0;i< obj.length;  i++){
    	if(obj[i].checked)
    		return obj[i].value;
    }
    
 return "";
}
//===========================================================================
//通用JavaScript说明:
//===========================================================================
//判断字符串是否为空
//去除前后的空格
//检查输入框中是否不为空
//检查输入框的最大字符长度
//检查输入框的最小字符长度
//检查输入框的字符长度在指定范围内
//判断输入框中只能输入整数(包括负数和零)
//判断输入框中只能输入正整数（不包括零）
//判断输入框中只能输入非负整数（包括零）
//判断输入框中只能输入非负数数值型数据(包括小数)
//判断输入框中的数值是否在指定范围内（如：0-100）
//判断输入框中只能输入字母
//判断输入框中只能输入字母和数字
//判断输入框中只能输入数字

//checkbox至少选中一个
//checkbox全选
//checkbox取消

//判断是否为日期格式(YYYY-MM-DD格式)
//比较日期的大小
//校验身份证号是否有效
//根据身份证获取生日
//根据身份证获取性别
//http://IP:PORT格式地址验证
//校验Email地址是否有效
//获取指定字符串的长度，1个汉字为2个字节
// 按回车时跳到下一个焦点
// 按回车时跳到下一个焦点
// 对Cookie的操作  
// 判断是否为数组类型
// 判断是否为字符串类型
// 判断是否为数值类型
// 判断是否为日期类型
// 判断是否为函数
// 判断是否为对象

//===========================================================================

 /**
 * 判断字符串是否为空
 *	s：值
 */
function isEmpty(s) {
	if( s==null || s.length==0)
		return true;
	return false;
}

/**
 *  去除前后的空格
 */
function trim(str) {
	return str.replace(/(^\s+)|(\s+$)/g, "");
}

/**
*  检查输入框中是否不为空
*
*/
function checkNotNull( id ){
	var str = document.getElementById(id).value;
	if(str==null || trim(str)==''){
		showFieldError(id, "不能为空");
		return false;
	}
	return true;
}

/**
*  检查输入框的最大字符长度
*  
*/
function checkMaxLength(id, max){
	var str = document.getElementById(id).value;
	var len = getLength( str );
	if( len>max){
		showFieldError(id, "长度应该在"+max+"个字符之内");
		return false;
	}
	return true;
}

/**
*  检查输入框的最小字符长度
*  
*/
function checkMinLength(id, min){
	var str = document.getElementById(id).value;
	var len = getLength( str );
	if( len<min){
		showFieldError(id, "长度不能小于"+min+"个字符");
		return false;
	}
	return true;
}

/**
*  检查输入框的字符长度在指定范围内
*  
*/
function checkLength(id, min, max){
	var str = document.getElementById(id).value;
	var len = getLength( str );
	if( len<min || len>max){
		showFieldError(id, "长度应该在"+min+"~"+max+"个字符之内");
		return false;
	}
	return true;
}

/**
*  判断输入框中只能输入整数(包括负数和零)
*/
function checkInt(id){
	var val = document.getElementById(id).value;
	var pattern=/^[-]?[0-9]+$/;
	if( !pattern.test(val) ){
		showFieldError(id,"只能输入整数！");
		return false;
	}
	return true;
}

/**
*  判断输入框中只能输入正整数（不包括零）
*/
function checkPlusInt(id){
	var val = document.getElementById(id).value;

	var pattern=/[^0-9]/;
	if(pattern.test(val) || val.slice(0,1)=="0"){
		showFieldError(id,"只能输入正整数！");
		return false;
	}
	return true;
}

/**
*  判断输入框中只能输入非负整数（包括零）
*/
function checkPlusIntAndZero(id){
	var val = document.getElementById(id).value;
	var pattern=/[^0-9]/;
	if(pattern.test(val)){
		showFieldError(id, "只能输入零或正整数");
		return false;
	}
	return true;
}


/**
*  判断输入框中只能输入非负数数值型数据(包括小数)
*/
function checkNum(id){
	var val = document.getElementById(id).value;
	var pattern=/[^0-9.]/;
	if(pattern.test(val)){
		showFieldError(id,"只能输入正数");
		return false;
	}
	return true;
}

/**
*  判断输入框中的数值是否在指定范围内（如：0-100）
*  min：最小值
*  max：最大值
*/
function checkNumRange(id,min,max){
	val = parseInt(document.getElementById(id).value);
	if(val<min || val>max){
		showFieldError(id,"只能是"+min+"~"+max+"范围内的数值");
		return false;
	}
	return true;
}

/**
*  判断输入框中只能输入字母
*/
function checkCharacters(elem,field){
	val=elem.value;
	var pattern=/\W/g;
	if(pattern.test(val)){
		alert(field+"只能为A-Z a-z 0-9等字符！");
		elem.focus();
		return false;
	}
	pattern=/_/g;
	if(pattern.test(val)){
		alert(field+"只能为A-Z a-z 0-9等字符！");
		elem.focus();
		return false;
	}

}

/**
* 判断输入框中只能输入字母和数字
*  
*/
 function verifyLetterAndNum(elem,field){
    var str=/^[a-zA-Z0-9]+$/;
    if(!str.test(elem.value)){
	   alert(field+"只能为数字和字母");
	   elem.focus();
	   return false;
       }  
    return true;
 }

/**
*  判断输入框中只能输入数字
*/
function checkNumber(elem,field){
	val=elem.value;
	var pattern=/^[0-9]/;
	if(!pattern.test(val)){
		alert(field+"只能输入数字！");
		elem.value = '';
		elem.focus();
		return false;
	}
	return true;
}

/**
* 判断checkbox至少选中一个
*/
function checkSelected(name){
	var sz = document.getElementsByName(name);
	if(sz==null || sz.length==0)
		return true;
	
	for(var i=0; i<sz.length; i++){
		if(sz[i].checked)
			return true;
	}
	
	//alert("请先选中一条记录。");
	return false;
		
}
/**
* checkbox全选
*/
function selectAll(name){
	var sz = document.getElementsByName(name);
	if(sz==null || sz.length==0)
		return ;
	
	for(var i=0; i<sz.length; i++){
		sz[i].checked = true;
	}
}

/**
* checkbox取消
*/
function selectNone(name){
	var sz = document.getElementsByName(name);
	if(sz==null || sz.length==0)
		return ;
	
	for(var i=0; i<sz.length; i++){
		sz[i].checked = false;
	}
}

 /**
 * 判断是否为日期格式(YYYY-MM-DD格式)
 *	elem：日期输入框
 *  field：提示名称
 */
function checkDate(elem,field){
	
    return true;
}

/**
*  比较日期的大小
*  elem1 前面的日期（string）
*  elem2 后面的日期（string）
*  elem1>elem2 return 1;elem1==elem2 return 0;elem1<elem2 return -1
*/
function compareDate(elem1,elem2){
	if(elem1.value!="" && elem2.value!=""){
		 var date1 ;
		 var date2 ;
		 try{
			date1 = elem1.value.split('-');
			date2 =elem2.value.split('-');
		 }catch(e){
			date1 = elem1.split('-');
			date2 = elem2.split('-');
		 }
		 if(eval(date1[0])>eval(date2[0])){
		 	return 1;
		 }else if(eval(date1[0])==eval(date2[0])){
		 	if(eval(date1[1])>eval(date2[1])){
		 		return 1;
		 	}else if(eval(date1[1])==eval(date2[1])){
		 	    if(eval(date1[2])>eval(date2[2])){
			 		return 1;
			 	}else if(eval(date1[2])==eval(date2[2])){
			 		return 0;
			 	}else{
			 	    return -1;
			 	}	
		 	}else{
		 		return -1;
		 	}
		 }else{
		 	return -1;
		 }
	}
}

 /**
 * 校验身份证号是否有效
 *	elem：日期输入框
 *  field：提示名称
 */
function checkIdentityCard(elem){	
    if(isEmpty(elem.value)) return true;
    
    var reOld = /^[0-9]{15}$/gi;
    var reNew = /^[0-9]{17}[0-9x]{1}$/gi;

    if(reOld.test(elem.value)) {
        return true;
    }    
    else if(reNew.test(elem.value)){
        return true;
    }
    else {
        alert('请输入正确的身份证号！');
        elem.focus();
        return false;
    }
}

 /**
 * 根据身份证获取生日
 */
function checkoutBirthday(elem){
	var birth='';
	if(!checkIdentityCard(elem)){
		return;
	};
	val=trim(elem.value);
	if(val.length==0){
		return;
	}
	
	if(val.length==15){
		birth='19'+val.substring(6,8);
		birth=birth+'-'+val.substring(8,10);
		birth=birth+'-'+val.substring(10,12);
	}
	else if(val.length=18){
		birth=val.substring(6,10);
		birth=birth+'-'+val.substring(10,12);
		birth=birth+'-'+val.substring(12,14);
	}
	return birth;
}

 /**
 * 根据身份证获取性别
 */
function checkoutSex(elem){
	var sex='';
	if(!checkIdentityCard(elem)){
		return;
	};
	val=trim(elem.value);
	if(val.length==0){
		return;
	}
	
	var sexindex=-1;
	if(val.length==15){
		sexindex=14;
	}
	else{
		sexindex=16;
	}
	sex=val.substring(sexindex,sexindex+1);
	if(sex%2==0){
		return 'F';
	}
	else{
		return 'M';
	}
}



/*
 *http://IP:PORT格式地址验证
 */
function checkipport(elem,field){
	var val=trim(elem.value);
	var pattern=/^http:\/\/\d{1,3}\.\d{1,3}\.\d{1,3}\.\d{1,3}\:\d{2,10}$/;
	if(!pattern.test(val)){
		alert(field+'请确认符合http://IP:PORT格式');
		elem.focus();
		return false;
	}
	return true;
}

 /**
 * 校验Email地址是否有效
 *	elem：Email地址输入框
 */
function checkEmail(id){
	var str = document.getElementById(id).value;
    if(isEmpty(str)) return false;
    var reEmail =/[\w-.]+@{1}[\w-]+\.{1}\w{2,4}(\.{0,1}\w{2}){0,1}/ig;
    if(reEmail.test(str)) {
        return true;
    }
    showFieldError(id, "不是有效邮箱");
	return false;
}






/**
*  获取指定字符串的长度，1个汉字为2个字节
*  text　指定字符串
*/
function getLength(text){
	var len;
	var i;
	len = 0;
	var val = text;
	var length = val.length;
	for (i=0;i<length;i++){
		if (val.charCodeAt(i)>255) 
			len+=2;
		else 
			len++;
	}	
	return len;
}

/**
*  按回车时跳到下一个焦点
*  event	事件
*  id		下一个焦点的id或doSubmit函数
*/
function goNext(event, idOrFunction){
	if( event==null )
		event = window.event;
	if( event.keyCode!=13){
  		return;   
	}
	if(isFunction(idOrFunction)){
		idOrFunction();
		return;
	}
	if(isString(idOrFunction)){
		document.getElementById(idOrFunction).focus();
		return;
	}
}

/**
*  对Cookie的操作
*/   
function getCookie( name ) {
     var start = document.cookie.indexOf( name + "=" );
     var len = start + name.length + 1;
     if ( ( !start ) && ( name != document.cookie.substring( 0, name.length ) ) ) {
         return null;     
     }
     if ( start == -1 ) return null;
     var end = document.cookie.indexOf( ';', len );
     if ( end == -1 ) end = document.cookie.length;
          return unescape( document.cookie.substring( len, end ) ); 
}
/*
function setCookie( name, value, expires, path, domain, secure ) {
     var today = new Date();
     today.setTime( today.getTime() );
     if ( expires ) {
         expires = expires * 1000 * 60 * 60 * 24;     
     }
     var expires_date = new Date( today.getTime() + (expires) );
     document.cookie = name+'='+escape( value ) +         ( ( expires ) ? ';expires='+expires_date.toGMTString() : '' ) + 
     //expires.toGMTString()         ( ( path ) ? ';
     path=' + path : '' ) +         ( ( domain ) ? ';
     domain=' + domain : '' ) +         ( ( secure ) ? ';secure' : '' );
}

function deleteCookie( name, path, domain ) {
     var ck = name + "=;";
     	document.cookie = name + '=' + ( path ? ';path=' + path : '') + ( domain ? ';domain=' + domain : '' ) + ';expires=Thu, 01-Jan-1970 00:00:01 GMT'; 
 }
 */

/**
*   判断是否为数组类型
*/ 
function isArray(obj){ 
    return (typeof obj=='object')&&obj.constructor==Array; 
}

/**
*  判断是否为字符串类型
*/
function isString(str){
	return (typeof str=='string')&&str.constructor==String; 
}


/**
*  判断是否为数值类型
*/
function isNumber(obj){ 
	return (typeof obj=='number')&&obj.constructor==Number; 
}

/**
*  判断是否为日期类型
*/
function isDate(obj){ 
	return (typeof obj=='object')&&obj.constructor==Date; 
}

/**
*  判断是否为函数
*/
function isFunction(obj){ 
	return (typeof obj=='function')&&obj.constructor==Function; 
}

/**
*  判断是否为对象
*/
function isObject(obj){ 
	return (typeof obj=='object')&&obj.constructor==Object; 
}
/*
**若字段有msg属性，则当字段获取焦点时，显示提示信息
*/

var contentDIV = null;
var fieldMsgName = "field_msg_tip";	//字段提示框名
var fieldErr = "err";	//字段错误属性名
var fieldMsg = "msg";	//字段提示属性名
var actionMsgName = "action_msg_tip";		//action提示框名
var isIE = navigator.appName.indexOf("Microsoft Internet Explorer")>=0 ? true : false;	//是否为ie浏览器

//移动提示框位置
function divMove(obj,x,y){
	if(obj==null) return;
	obj.style.left = x+"px";
	obj.style.top = y+"px";
}
//初始化提示事件
function initFieldEvent() {
    // add input box error tip
    initFocusHandlers(document.getElementsByTagName("input"));
    initFocusHandlers(document.getElementsByTagName("SELECT"));
    initFocusHandlers(document.getElementsByTagName("textarea"));

    //显示第一个错误字段的焦点
    showFirstError();
}
//坐标对象
function Pos(x, y){
    this.x = x;
    this.y = y;
}
//获取当前控件坐标位置
function getPos(target){
    var pos = new Pos(target.offsetLeft, target.offsetTop);
    
    target = target.offsetParent;
    while (target){
        pos.x += target.offsetLeft;
        pos.y += target.offsetTop;
        target = target.offsetParent;
    }
    
    return pos;
}
//初始化取得焦点和失去焦点的事件
function initFocusHandlers(elements) {
	var hasFirstErrorDisplay=false;
	var msgTipDiv=document.getElementById(fieldMsgName);
	var element;
	
    for (i=0; i < elements.length; i++) {
    	element = elements[i];
        if (element.type == "button" || element.type == "submit" 
        	|| element.type == "reset" || element.type == "file" 
        	|| element.type == "checkbox" || element.type == "radio") 
        	continue;

     	//取得焦点
     	if(element.getAttribute(fieldErr) != null || element.getAttribute(fieldMsg) != null ){
	        element.onfocus=function() {
	        	//当字段有错误提示信息时
	            if(this.getAttribute(fieldErr) != null){
					if(msgTipDiv==null) return;	
					var pos = getPos(this);
					var x = pos.x + this.clientWidth ;
					var y = pos.y;
	
					divMove(msgTipDiv,x,y);
					msgTipDiv.parentobj=this;
					msgTipDiv.className="tip_field_error";
					msgTipDiv.style.display = "";
					msgTipDiv.innerHTML = this.getAttribute(fieldErr);
				}else if(this.getAttribute(fieldMsg) != null){//当字段有普通提示信息时
					if(msgTipDiv==null) return;
					var pos = getPos(this);
					var x = pos.x + this.clientWidth ;
					var y = pos.y;
					
					divMove(msgTipDiv,x,y);
					msgTipDiv.parentobj=this;
					msgTipDiv.className="tip_field_msg";
					msgTipDiv.style.display = "";
					msgTipDiv.innerHTML = this.getAttribute(fieldMsg);
				}
	        };
        }
          
        //失去焦点
        if(element.getAttribute(fieldMsg)!=null || element.getAttribute(fieldErr)!=null){
	        element.onblur=function() {
				if(msgTipDiv!=null){
					msgTipDiv.innerHTML="";
					msgTipDiv.style.display = "none";
				}
			};
		}
			
		//改变内容
		if(element.getAttribute(fieldErr)!=null){
			element.onchange=function() {
				this.removeAttribute(fieldErr);
				if(this.tagName=="SELECT"){
					this.style.color="";
				}else{
					this.style.borderColor="";
				}
				if(msgTipDiv!=null){
					msgTipDiv.innerHTML="";
					msgTipDiv.style.display = "none";
				}
			};
		}
		
		//必填项(右下角显示图标)
		//不通过css是考虑到侵入性更小
		if( element.getAttribute('necessarily')=="true"){
			element.style.backgroundImage = "url(http://img.eaful.com/common/actionmsg/images/necessarily.gif)";
			element.style.backgroundRepeat = "no-repeat";
			element.style.backgroundPosition = "bottom right";
			element.style.backgroundAttachment = "scroll";
		}
		
		
    }
}



//--------------------------------------------------------
//显示第一个错误字段的焦点
function showFirstError(){
	var e = document.getElementsByTagName("*");
	for(var i=0; i<e.length; i++){
		if(e[i].getAttribute(fieldErr) !=null){
			//document.getElementById("__focus").focus();
			e[i].focus();
			e[i].select();
			return;
		}
	}
}
//--------------------------------------------------------


//--------------------------------------------------------
//显示客户端错误信息
function showFieldError(name,value){
	setFieldError(name,value);
	
	var elements = document.getElementsByName(name);
	initFocusHandlers(elements);

	//document.getElementById("__focus").focus();	//用了在IE6下反而得不到焦点
	elements[0].focus();
}
//--------------------------------------------------------


//--------------------------------------------------------
//设置action field error信息
function setFieldError(name,value){
	var obj = document.getElementsByName(name)[0];
	if(obj==null)
		return;	
		
	obj.setAttribute(fieldErr,value);
	if(obj.tagName=="SELECT"){
		obj.style.color="red";
	}else{
		obj.style.borderColor="red";
	}
	
}
//设置action error信息
function setActionError(actionError){
	showActionMsg("tip_action_error", actionError);
}
//设置action message信息
function setActionMessage(actionMessage){
	showActionMsg("tip_action_msg", actionMessage);
}
//显示action消息
function showActionMsg(cssName, text){
	var actionMsg = document.getElementById(actionMsgName);	
	if(actionMsg==null) return;
	
	var x, y, width;
	var contents = getElementsByClassName("main");
	if(contents == null || contents.length==0 ){
		x = 20;
	}else{
		var pos = getPos(contents[0]);
		x = pos.x; 
	}
	width = document.documentElement.clientWidth - x*2 -40;
	
	//必须放在取Height前才能取得正确的Height
	actionMsg.className = cssName;
	actionMsg.innerHTML = text;
	actionMsg.style.display = "";
	var y = document.documentElement.clientHeight -actionMsg.offsetHeight ;
	
	actionMsg.parentobj = contents;
	actionMsg.style.width = width +"px";
	divMove(actionMsg, x, y);
	actionMsg.style.display = "";
}
//滚动条事件
function scrollEvent(event){
	if (!event) 
   		event = window.event;
   	var target;
   	if(event.currentTarget){
        target = event.currentTarget;
    }else if(event.srcElement){
        target = event.srcElement;
    }
    
    var actionMsg = document.getElementById(actionMsgName);	
    var y = document.documentElement.clientHeight -actionMsg.offsetHeight
    
	actionMsg.style.top = document.documentElement.scrollTop + y + "px";
}
//定义一个对话框对象
function Dialog() {
	var backPanel, dialogPanel, title, iframe;
	var dialogType = "default";	//对话框类型:default,confirm,iframe
	var isIE;	//是否为ie浏览器
	if(navigator.appName.indexOf("Microsoft Internet Explorer")>=0){
		isIE = true;
	}else{
		isIE = false;
	}

	//设置对话框属性
	this.setDefaultDialog = function( ){
		dialogType = "default";
	}
	this.setConfirmDialog = function( ){
		dialogType = "confirm";
	}
	this.setIframeDialog = function( ){
		dialogType = "iframe";
	}
	
    //初始化
	function init() {
        //透明背景
		if ( document.getElementById("dialog_back_panel") == null) {
			var div = document.createElement("div");
			div.setAttribute("id","dialog_back_panel");
			document.body.appendChild(div);
			//document.body.innerHTML += "<div id='dialog_back_panel' ></div>";
		}
            
        //对话框
		if (document.getElementById("dialog_panel") == null) {
			var panel = document.createElement("div");
			panel.setAttribute("id","dialog_panel");
			
			var div = document.createElement("img");
			div.setAttribute("id","dialog_close_img");
			div.setAttribute("src","http://img.eaful.com/common/dialog/image/close.gif");
			panel.appendChild(div);
			
			div = document.createElement("div");
			div.setAttribute("id","dialog_title");
			div.setAttribute("onselectstart","return false");
			panel.appendChild(div);
			
			div = document.createElement("iframe");
			div.setAttribute("id","dialog_iframe");
			div.setAttribute("src","about:blank");
			div.setAttribute("frameborder","0");
			div.setAttribute("scrolling","no");
			panel.appendChild(div);
			
			document.body.appendChild(panel);
			
			//事件绑定
			var closeObj = document.getElementById("dialog_close_img");
			if(isIE)
				closeObj.attachEvent("onclick",dlgClose);
			else
				closeObj.addEventListener("click",dlgClose,false);
			
			var titleObj = document.getElementById("dialog_title");
			if(isIE){
				titleObj.attachEvent("onmousedown",startMove);
				titleObj.attachEvent("onmouseup",stopMove);
				titleObj.attachEvent("onmouseout",stopMove);
				titleObj.attachEvent("onmousemove",doMove);
			}else{
				titleObj.addEventListener("mousedown",startMove,true);
				titleObj.addEventListener("mouseup",stopMove,true);
				titleObj.addEventListener("mouseout",stopMove,true);
				titleObj.addEventListener("mousemove",doMove,true);
			}
			
			var ifForm = document.getElementById("dialog_iframe").contentWindow;
			ifForm.document.open();
			ifForm.document.write("<html><head></head>");
			ifForm.document.write("<body style='background:wight;width:100%;height:100%;margin:0;padding:0;overflow:hidden;'>");
			ifForm.document.write("<div id='content' style='text-align:center;'></div>");
			ifForm.document.write("<div id='botton' align='right'></div>");
			ifForm.document.write("</body></html>");
			ifForm.document.close();
		}
		
		backPanel = document.getElementById("dialog_back_panel");
		dialogPanel = document.getElementById("dialog_panel");
		title = document.getElementById("dialog_title");
		iframe = document.getElementById("dialog_iframe");
		
	}

    //显示对话框控件.
	this.show = function (smCaption, smMessage, smButton, iWidth, iHeight) {
		if (smCaption=="")
			smCaption = "对话框";
		if( iWidth == 0 )
			iWidth = 220;
		if( iHeight == 0 )
			iHeight = 180;
		if(smButton==""){
			smButton = "<input id='__dlg_close_button' type='button' value='关闭' />";
		}
			
		init();
		            
        //设置标题和内容
        title.innerHTML =  smCaption;
		var ifForm = iframe.contentWindow;
		ifForm.document.getElementById("content").innerHTML = smMessage;
		ifForm.document.getElementById("botton").innerHTML = smButton;
		//事件绑定
		var closeButton = ifForm.document.getElementById("__dlg_close_button");
		if( closeButton ){
			if(isIE)
				closeButton.attachEvent("onclick",dlgClose);
			else
				closeButton.addEventListener("click",dlgClose,false);
		}	
		
		resize(iWidth, iHeight);
		
	};
	
	this.iframeDialogShow = function ( smCaption, sUrl, iWidth, iHeight ){
		if (smCaption==null ||smCaption=="")
			smCaption = sUrl;
		if( sUrl==null || sUrl=="")
			return;
		if( iWidth == 0 )
			iWidth = 220;
		if( iHeight == 0 )
			iHeight = 180;
		
		init();
		
		//设置标题
		title.innerHTML =  smCaption;
		
        //刷新iframe
		var ifForm = document.getElementById("dialog_iframe");
		ifForm.src = sUrl;
		
		resize(iWidth, iHeight);
		
	}
	
	//获得iframe控件
	this.getMainFrame = function(){
		return document.getElementById("dialog_iframe").contentWindow;
	}
	
	//关闭对话框控件.
	this.close = function(){
		backPanel.parentNode.removeChild(backPanel);
		dialogPanel.parentNode.removeChild(dialogPanel);
	};

	//对话框的iframe中关闭对话框
	function dlgClose() {
		var backPanel = document.getElementById("dialog_back_panel");
		var dialogPanel = document.getElementById("dialog_panel");
		backPanel.parentNode.removeChild(backPanel);
		dialogPanel.parentNode.removeChild(dialogPanel);
	}
	
	function resize(iWidth, iHeight){
		var sizeObj = getPageSize();
		
		backPanel.style.left = "0px";
		backPanel.style.top = "0px";
		backPanel.style.width = sizeObj[0] + "px";
		backPanel.style.height = sizeObj[1] + "px";
		backPanel.style.visibility = "visible";
		
		var left = sizeObj[2] / 2 - iWidth / 2;
		var top = sizeObj[3] / 2 - iHeight / 2;
		dialogPanel.style.left = left<0?0:left + "px";
		dialogPanel.style.top = top<0?0:top + "px";
		dialogPanel.style.width = iWidth + "px";
		dialogPanel.style.height = iHeight + "px";
		dialogPanel.style.visibility = "visible";
	}



	//*******************     
	//移动dialog 
	//*******************
	var   moving   =   false;     
	var   oX     =   0;     
	var   oY     =   0;
	var   oLeft     =   0;     
	var   oTop     =   0;
	
	function startMove(evt){
		if (!evt) 
	   		evt = window.event;
	   		
		//按下鼠标左键才允许移动     
		//evt.button   ==   1   IE/Opera   7.23/7.54     
		//evt.button   ==   0   Firefox/Opera   7.6+     
		if( evt.button == 1 || evt.button == 0 ){
			moving = true;
			oX = evt.clientX;
			oY = evt.clientY;
			var iDgl = document.getElementById("dialog_panel");
			oLeft = parseInt(iDgl.style.left);
			oTop = parseInt(iDgl.style.top);
			//alert("x:"+oX+"y:"+oY+"left:"+oLeft+"top:"+oTop);
		}else{
			stopMove( evt );
		}     
	}     
	
	function stopMove( evt ){
		moving   =   false;      
	}
	
	function doMove(evt){
		if (!evt) 
	   		evt = window.event;
	   		
		 //按下鼠标左键才允许移动     
		 //evt.button   ==   1   IE/Opera   7.23/7.54     
		 //evt.button   ==   0   Firefox/Opera   7.6+     
		 if(moving && (evt.button==1 || evt.button == 0)){
			var x =  evt.clientX;   //获取当前鼠标位置的X坐标
			var y =  evt.clientY;   //获取当前鼠标位置的Y坐标
			var iDgl = document.getElementById("dialog_panel");
			iDgl.style.left = oLeft + x - oX + "px";
			iDgl.style.top = oTop + y - oY + "px"; 
		}    
	}   
	
	/*获取页面和窗口长宽*/
	function getPageSize(){
		
		var xScroll, yScroll;
		
		if (window.innerHeight && window.scrollMaxY) {
			xScroll = document.body.scrollWidth;
			yScroll = window.innerHeight + window.scrollMaxY;
		} else if (document.body.scrollHeight > document.body.offsetHeight){ // all but Explorer Mac
			xScroll = document.body.scrollWidth;
			yScroll = document.body.scrollHeight;
		} else { // Explorer Mac...would also work in Explorer 6 Strict, Mozilla and Safari
			xScroll = document.body.offsetWidth;
			yScroll = document.body.offsetHeight;
		}
		
		var windowWidth, windowHeight;
		if (document.documentElement && document.documentElement.clientHeight) { // Explorer 6 Strict Mode
			windowWidth = document.documentElement.clientWidth;
			windowHeight = document.documentElement.clientHeight;
		} else if (document.body) { // other Explorers
			windowWidth = document.body.clientWidth;
			windowHeight = document.body.clientHeight;
		}	
	
		// for small pages with total height less then height of the viewport
		if(yScroll < windowHeight){
			pageHeight = windowHeight;
		} else { 
			pageHeight = yScroll;
		}
	
		// for small pages with total width less then width of the viewport
		if(xScroll < windowWidth){	
			pageWidth = windowWidth;
		} else {
			pageWidth = xScroll;
		}
		
		arrayPageSize = new Array(pageWidth,pageHeight,windowWidth,windowHeight) 
		return arrayPageSize;
	}

}
//关闭对话框控件.
function closePopWindow(){
	var backPanel = document.getElementById("dialog_back_panel");
	var dialogPanel = document.getElementById("dialog_panel");
	backPanel.parentNode.removeChild(backPanel);
	dialogPanel.parentNode.removeChild(dialogPanel);
}
//======================================
//eaful专用方法
//======================================
// 弹出式登陆框
// 登陆页面
// 注销
 

/*弹出式登陆框*/
function showLogin(){
	var Br = new Dialog();
	Br.iframeDialogShow("登陆","/common/user/popLogin.ef", 520, 180);
}
/*登陆页面*/
function doLogin(targetLink){
	if(targetLink!=null)
		this.location.href = "http://www.eaful.com/common/user/login.ef?targetLink="+targetLink;
	else
		this.location.href = "http://www.eaful.com/common/user/login.ef";
}
/*注销*/
function doLogoff(){
	//注销回到首页
	this.location.href = "http://www.eaful.com/common/user/logoff.ef";
}


/**
* 为事件添加多个处理方法
* 执行顺序是随机的，所以不要有顺序依赖
*/
function addEvent(obj, eventName, functionName){
	if (obj.addEventListener){
		obj.addEventListener(eventName, functionName, false);
		return true;
	}else if (obj.attachEvent){
		var r = obj.attachEvent("on"+eventName, functionName);
		return r;
	}
	return false;
} 