var agt = navigator.userAgent.toLowerCase();
var is_opera = (agt.indexOf("opera") != -1);
var is_ie = (agt.indexOf("msie") != -1) && document.all && !is_opera;
var is_ie5 = (agt.indexOf("msie 5") != -1) && document.all;
var uniqnum_counter = (new Date).getTime();
var is_regexp = (window.RegExp) ? true : false;
var gidname = '';

String.prototype.trim = function() {
	a = this.replace(/^\s+/, '');
	return a.replace(/\s+$/, '');
};

function $(idname)
{
	if (document.getElementById) {
		return eval('document.getElementById("' + idname + '")');
	} else if (document.all) {
		return eval('document.all["' + idname + '"]');
	} else if (document.layers) {
		return eval('document.layers["' + idname + '"]');
	} else {
		return null;
	}
}
function $t(parentobj, tag)
{
	if (typeof parentobj.getElementsByTagName != 'undefined') {
		return parentobj.getElementsByTagName(tag);
	} else if (parentobj.all && parentobj.all.tags) {
		return parentobj.all.tags(tag);
	} else {
		return null;
	}
}
function $$(s)
{
	return document.frames?document.frames[s]:$(s).contentWindow;
}
function $c(s)
{
	return document.createElement(s);
}
function swap(s,a,b,c)
{
	$(s)[a]=$(s)[a]==b?c:b;
}
function exist(s)
{
	return $(s)!=null;
}
function dw(s)
{
	document.write(s);
}
function hide(s)
{
	$(s).style.display=$(s).style.display=="none"?"":"none";
}
function isNull(_sVal)
{
	return (_sVal == "" || _sVal == null || _sVal == "undefined");
}
function removeNode(s)
{
	if(exist(s))
	{
		$(s).innerHTML = '';
		$(s).removeNode?$(s).removeNode():$(s).parentNode.removeChild($(s));
	}
}
function myInnerHTML(idname, html)
{
	if (exist(idname))
	{
		$(idname).innerHTML = html;
	}
}
function strLen(key){
	var l=escape(key),len
	len=l.length-(l.length-l.replace(/\%u/g,"u").length)*4
	l=l.replace(/\%u/g,"uu")
	len=len-(l.length-l.replace(/\%/g,"").length)*2
	return len
}


function dialog()
{
	var titile = '信翼瑞贸易温馨提示';
	var width = 350;
	var height = 120;
	var path = "/monopoly/default/";
	var sFunc = '<input id="dialogOk" type="button" value=" 确 定 " onclick="new dialog().reset();" /> <input id="dialogCancel" type="button" value=" 取 消 " onclick="new dialog().reset();" />';
	var sClose = '<input type="image" id="dialogBoxClose" onclick="new dialog().reset();" src="' + path + 'close.gif" border="0" width="16" height="16" align="absmiddle" />';
	var sBody = '\
		<table id="dialogBodyBox" border="0" align="center" cellpadding="0" cellspacing="6" width="100%">\
			<tr height="10"><td colspan="4"></td></tr>\
			<tr><td colspan="4" align="center">\
			<div id="dialogMsgDiv" style="text-align:center"><div id="dialogMsg" style="font-size:14px;line-height:180%;color:#539F38;font-weight:bold;">&nbsp;</div></div>\
			</td></tr>\
			<tr><td id="dialogFunc" colspan="4" align="center">' + sFunc + '</td></tr>\
			<tr height="5"><td colspan="4" align="center"></td></tr>\
		</table>\
	';

	var sBox = '\
		<div id="dialogBox" style="border:1px solid #C5E0BD;display:none;z-index:10;width:'+width+'px;">\
		<table width="100%" border="0" cellpadding="0" cellspacing="0">\
			<tr height="24" bgcolor="#6795B4">\
				<td>\
					<table onselectstart="return false;" style="-moz-user-select:none;" width="100%" border="0" cellpadding="0" cellspacing="0" style="background-color:#539F38;  height:25px; border-top:1px solid #FFF5E7;">\
						<tr>\
							<td width="6" height="24"></td>\
							<td id="dialogBoxTitle" style="color:#FFFFFF;font-size:12px;font-weight:bold;">&nbsp;</td>\
							<td id="dialogClose" width="20" align="right" valign="middle">\
								' + sClose + '\
							</td>\
							<td width="6"></td>\
						</tr>\
					</table>\
				</td>\
			</tr>\
			<tr id="dialogHeight" style="height:' + height + '" valign="top">\
				<td id="dialogBody" bgcolor="#ffffff">' + sBody + '</td>\
			</tr>\
		</table></div><div id="dialogBoxShadow" style="display:none;z-index:9;"></div>\
	';
	var sIfram = '\
		<iframe id="dialogIframBG" name="dialogIframBG" frameborder="0" marginheight="0" marginwidth="0" hspace="0" vspace="0" scrolling="no" style="position:absolute;z-index:8;display:none;"></iframe>\
	';

	var sBG = '\
		<div id="dialogBoxBG" style="position:absolute;top:0px;left:0px;width:100%;height:100%;"></div>\
	';

	this.show = function()
	{
		this.middle('dialogBox');
		if ($('dialogIframBG'))
		{
			$('dialogIframBG').style.top = $('dialogBox').style.top;
			$('dialogIframBG').style.left = $('dialogBox').style.left;
			$('dialogIframBG').style.width = $('dialogBox').offsetWidth;
			$('dialogIframBG').style.height = $('dialogBox').offsetHeight;
			$('dialogIframBG').style.display = 'block';
		}
		if (!is_opera) {
			this.shadow();
		}
	}

	this.reset = function()
	{
		this.close();
		_set_id_focus();
	}

	this.resets = function(parentobj, _sName)
	{
		this.close();
		try {parentobj._sName.submit();}catch (e){}
	}

	this.close = function()
	{
		if ($('dialogIframBG')) {
			$('dialogIframBG').style.display = 'none';
		}
		$('dialogBox').style.display='none';
		$('dialogBoxBG').style.display='none';
		$('dialogBoxShadow').style.display = "none";
		myInnerHTML('dialogBody', sBody);
	}
	this.html = function(_sHtml)
	{
		myInnerHTML('dialogBody', _sHtml);
		this.show();
	}

	this.init = function()
	{
		$('dialogCase') ? $('dialogCase').parentNode.removeChild($('dialogCase')) : function(){};
		var oDiv = document.createElement('span');
		oDiv.id = "dialogCase";
		if (!is_opera) {
			oDiv.innerHTML = sBG + sIfram + sBox;
		} else {
			oDiv.innerHTML = sBG + sBox;
		}
		document.body.appendChild(oDiv);
		$('dialogBoxBG').style.height = document.body.scrollHeight;
	}

	this.button = function(_sId, _sFuc)
	{
		if($(_sId)) {
			$(_sId).style.display = '';
			if($(_sId).addEventListener) {
				if($(_sId).act) {
					$(_sId).removeEventListener('click', function(){eval($(_sId).act)}, false);
				}
				$(_sId).act = _sFuc;
				$(_sId).addEventListener('click', function(){eval(_sFuc)}, false);
			} else {
				if($(_sId).act) {
					$(_sId).detachEvent('onclick', function(){eval($(_sId).act)});
				}
				$(_sId).act = _sFuc;
				$(_sId).attachEvent('onclick', function(){eval(_sFuc)});
			}
		}
	}

	this.shadow = function()
	{
		var oShadow = $('dialogBoxShadow');
		var oDialog = $('dialogBox');
		oShadow['style']['position'] = "absolute";
		oShadow['style']['display']	= "";
		oShadow['style']['opacity']	= "0.1";
		oShadow['style']['filter'] = "alpha(opacity=10)";
		oShadow['style']['background']	= "#000";

		try {
			var aIframe = parent.document.getElementById("iframe_parent");
		} catch (e){}
		if (aIframe) {
			var sClientWidth = aIframe.offsetWidth;
			var sClientHeight = aIframe.offsetHeight;
			var sScrollTop = 0;
		} else {
			var sClientWidth = parent ? parent.document.body.clientWidth : document.body.clientWidth;
			var sClientHeight = parent ? parent.document.body.clientHeight : document.body.clientHeight;
			var sScrollTop = parent ? parent.document.body.scrollTop : document.body.scrollTop;
		}

		oShadow['style']['top'] = '0';
		oShadow['style']['left'] = '0';
		oShadow['style']['width'] = sClientWidth;
		oShadow['style']['height'] = sClientHeight + sScrollTop;
	}

	this.open = function(_sUrl, _sMode, _sClose)
	{
		this.show();
		if(!_sMode || _sMode == "no" || _sMode == "yes"){
			var openIframe = "<iframe width='100%' height='100%' name='iframe_parent' id='iframe_parent' src='" + _sUrl + "' frameborder='0' scrolling='" + _sMode + "'></iframe>";
			myInnerHTML('dialogBody', openIframe);
		}
		_sClose ? this.button('dialogBoxClose', _sClose) : function(){};
	}

	this.showWindow = function(_sUrl, _iWidth, _iHeight, _sMode)
	{
		var oWindow;
		var sLeft = (screen.width) ? (screen.width - _iWidth)/2 : 0;
		var iTop = -80 + (screen.height - _iHeight)/2;
		iTop = iTop > 0 ? iTop : (screen.height - _iHeight)/2;
		var sTop = (screen.height) ? iTop : 0;
		if(window.showModalDialog && _sMode == "m"){
			oWindow = window.showModalDialog(_sUrl,"","dialogWidth:" + _iWidth + "px;dialogheight:" + _iHeight + "px");
		} else {
			oWindow = window.open(_sUrl, '', 'height=' + _iHeight + ', width=' + _iWidth + ', top=' + sTop + ', left=' + sLeft + ', toolbar=no, menubar=no, scrollbars=' + _sMode + ', resizable=no,location=no, status=no');
			this.reset();
		}
	}

	this.event = function(_sMsg, _sOk, _sCancel, _sClose)
	{
		myInnerHTML('dialogFunc', sFunc);
		myInnerHTML('dialogClose', sClose);
		$('dialogBodyBox') == null ? $('dialogBody').innerHTML = sBody : function(){};
		$('dialogMsg') ? $('dialogMsg').innerHTML = _sMsg  : function(){};

		_sOk && _sOk != "" ? this.button('dialogOk', _sOk) : $('dialogOk').style.display = 'none';
		_sCancel && _sCancel != "" ? this.button('dialogCancel', _sCancel) : $('dialogCancel').style.display = 'none';
		_sClose ? this.button('dialogBoxClose', _sClose) : function(){};

		this.show();
	}

	this.set = function(_oAttr, _sVal)
	{
		var oShadow = $('dialogBoxShadow');
		var oDialog = $('dialogBox');
		var oHeight = $('dialogHeight');

		if(!isNull(_sVal)) {
			switch(_oAttr)
			{
				case 'title':
					myInnerHTML('dialogBoxTitle', _sVal);
					break;
				case 'width':
					oDialog['style']['width'] = _sVal;
					break;
				case 'height':
					oHeight['style']['height'] = _sVal;
					break;
			}
		}
		this.middle('dialogBox');
		oShadow['style']['top'] = oDialog.offsetTop + 6;
		oShadow['style']['left'] = oDialog.offsetLeft + 6;
		oShadow['style']['width'] = oDialog.offsetWidth;
		oShadow['style']['height'] = oDialog.offsetHeight;
	}

	this.middle = function(_sId)
	{
		try {
			var aIframe = parent.document.getElementById("iframe_parent");
		} catch (e){}
		if (aIframe) {
			var sClientWidth = aIframe.offsetWidth;
			var sClientHeight = aIframe.offsetHeight;
			var sScrollTop = 0;
		} else {
			var sClientWidth = parent ? parent.document.body.clientWidth : document.body.clientWidth;
			var sClientHeight = parent ? parent.document.body.clientHeight : document.body.clientHeight;
			var sScrollTop = parent ? parent.document.body.scrollTop : document.body.scrollTop;
		}
		var sleft = (document.body.clientWidth / 2) - ($(_sId).offsetWidth / 2);
		var iTop = -80 + (sClientHeight / 2 + sScrollTop) - ($(_sId).offsetHeight / 2);
		var sTop = iTop > 0 ? iTop : (sClientHeight / 2 + sScrollTop) - ($(_sId).offsetHeight / 2);
		$(_sId)['style']['display'] = '';
		$(_sId)['style']['position'] = "absolute";
		$(_sId)['style']['left'] = sleft;
		$(_sId)['style']['top'] = sTop;
	}
}

function _error_msg_show(msg, click, idname, title)
{
	gidname = idname;
    click = click ? click : ' ';
    title = title ? title : '信翼瑞贸易温馨提示';
    dg=new dialog();
    dg.init();
    dg.set('title', title);
    dg.event(msg, click, '', click);
}

function _error_msg_show_parent(msg, click, idname, title)
{
	gidname = idname;
    click = click ? click : ' ';
    title = title ? title : '信翼瑞贸易温馨提示';
    dg=new parent.dialog();
    dg.init();
    dg.set('title', title);
    dg.event(msg, click, '', click);
}

function _confirm_msg_show(msg, click_ok, click_no, title, width, height)
{
    click_ok = click_ok ? click_ok : ' ';
    click_no = click_no ? click_no : ' ';
    title = title ? title : '信翼瑞贸易温馨提示';

    dg=new dialog();
    dg.init();
    dg.set('title', title);
	if (width) {
        dg.set('width', width);
    }
    if (height) {
        dg.set('height', height);
    }
    dg.event(msg, click_ok, click_no, click_no);
}

function _confirm_msg_show_parent(msg, click_ok, click_no, title, width, height)
{
    click_ok = click_ok ? click_ok : ' ';
    click_no = click_no ? click_no : ' ';
    title = title ? title : '信翼瑞贸易温馨提示';

    dg=new parent.dialog();
    dg.init();
    dg.set('src', '');
    dg.set('title', title);
	if (width) {
        dg.set('width', width);
    }
    if (height) {
        dg.set('height', height);
    }
    dg.event(msg, click_ok, click_no, click_no);
}

function _set_id_focus()
{
	if (!isNull(gidname)) {
		try {$(gidname).focus();}catch (e){}
	}
}

function openWindow(_sUrl, _sWidth, _sHeight, _sTitle, _sClickNo, _sScroll)
{
	var oEdit = new dialog();
	oEdit.init('yes');
	oEdit.set('title', _sTitle ? _sTitle : "系统提示信息" );
	oEdit.set('width', _sWidth);
	oEdit.set('height', _sHeight);
	oEdit.open(_sUrl, _sScroll != "yes" ? 'no' : 'yes', _sClickNo);
}

function zsxz(ta, zs, maxl)
{
	if(ta.value.length > maxl) {
		ta.value = ta.value.substring(0,maxl);
	} else {
		zs.value = maxl - ta.value.length;
	}
}

function checkcommentform(this_form)
{
	if (this_form.comment.value.length > 400 || this_form.comment.value.length == 0)
	{
		_error_msg_show("请输入评论内容！");
		return false;
	}
	return true;
}

function checkLogin(form){
	if (form.name.value == "")
	{
		_error_msg_show("用户名不能为空！");
		form.name.focus();
		return false;
	}
	if (form.pass.value == "")
	{
		_error_msg_show("用密码不能为空！");
		form.pass.focus();
		return false;
	}

//	if (form.kind)
//	{
//		if (!form.kind[0].checked && !form.kind[1].checked)
//		{
//			_error_msg_show("请选择会员类型：个人还是企业会员？");
//			return false;
//		}
//	}

	return true;
}

function checkReg(form)
{
	var ext = "";

	if (!/^[a-zA-Z0-9]{4,30}$/.exec(form.uname.value))
	{
		_error_msg_show("用户名应该由4-30个英文字母或数字组成！");
		form.uname.focus();
		return false;
	}

	if (!/^[a-zA-Z0-9]{6,30}$/.exec(form.pwd.value))
	{
		_error_msg_show("密码应该由6-30个英文字母或数字组成！");
		form.pwd.focus();
		return false;
	}

	if (form.pwd2.value != form.pwd.value)
	{
		_error_msg_show("两次输入的密码不一致！");
		form.pwd2.focus();
		return false;
	}
	if (form.question.value == "")
	{
		_error_msg_show("请输入安全提问！");
		form.question.focus();
		return false;
	}
	if (form.answer.value == "")
	{
		_error_msg_show("请输入问题答案！");
		form.answer.focus();
		return false;
	}
	if (form.email.value == "")
	{
		_error_msg_show("请输入电子邮箱！");
		form.email.focus();
		return false;
	}

	if (form.cname && form.cname.value == "")
	{
		_error_msg_show("请输入公司名称！");
		form.cname.focus();
		return false;
	}
	if (form.realname.value == "")
	{
		_error_msg_show("请输入您的真实姓名！");
		form.realname.focus();
		return false;
	}
	if (form.phone.value == "")
	{
		_error_msg_show("请输入您的联系电话！");
		form.phone.focus();
		return false;
	}
	if (form.address.value == "")
	{
		_error_msg_show("请输入您的联系地址！");
		form.address.focus();
		return false;
	}
	return true;
}

function checkMeeting(form)
{
	var ext = "";

	if (form.name.value == "")
	{
		_error_msg_show("请输入展会名称！");
		form.name.focus();
		return false;
	}

	if (form.company.value == "")
	{
		_error_msg_show("请输入主办单位！");
		form.company.focus();
		return false;
	}
	if (form.company2.value == "")
	{
		_error_msg_show("请输入协办单位！");
		form.company2.focus();
		return false;
	}
	if (form.supportMedia.value == "")
	{
		_error_msg_show("请输入媒体支持！");
		form.supportMedia.focus();
		return false;
	}
	if (form.bound.value == "")
	{
		_error_msg_show("请输入参展范围！");
		form.bound.focus();
		return false;
	}
	if (form.email.value == "")
	{
		_error_msg_show("请输入EMAIL！");
		form.email.focus();
		return false;
	}
	if (form.website.value == "")
	{
		_error_msg_show("请输入网址！");
		form.website.focus();
		return false;
	}

	return true;
}

function checkSearch(form){
	if (form.name.value == "" || form.name.value == "查询关键字")
	{
		_error_msg_show("请输入搜索关键字！");
		form.name.focus();
		return false;
	}

	return true;
}

function getpassCheck(form){
	if (!/^[a-zA-Z0-9]{4,20}$/.exec(form.name.value))
	{
		_error_msg_show("用户名应该由4-20个英文字母或数字组成！");
		form.name.focus();
		return false;
	}

	if (form.question.value == "")
	{
		_error_msg_show("请输入安全提问！");
		form.question.focus();
		return false;
	}
	if (form.answer.value == "")
	{
		_error_msg_show("请输入问题答案！");
		form.answer.focus();
		return false;
	}

	if (!/^[a-zA-Z0-9]{6,20}$/.exec(form.pass.value))
	{
		_error_msg_show("密码应该由6-20个英文字母或数字组成！");
		form.pass.focus();
		return false;
	}

	if (form.pass2.value != form.pass.value)
	{
		_error_msg_show("两次输入的密码不一致！");
		form.pass2.focus();
		return false;
	}

	return true;
}


function resize()
{
	parent.document.getElementById("right").style.height=document.body.scrollHeight;
}

