//var contextPath = "/pro";
var contextPath = "";
function doLogOut() {
	var url = contextPath + '/j_acegi_logout?cd='+Math.random();
	var userinfo = $('userinfo');
	var info = $('info');
	var login = "<a href='" + contextPath + "/usercenter/login.jsp'>[登录]</a>";
	var register = "<a href='" + contextPath + "/usercenter/user_register_item.jsp'>[注册]</a>";
	var viewInfo = register + "&nbsp;&nbsp;" + login;
	var myAjax = new Ajax.Request(
		url,
		{
			method: 'get',
			onComplete: showResponse
		}
	);
	function showResponse(originalRequest){
		var text = originalRequest.responseText;
		if(info && userinfo) {
			info.innerHTML = viewInfo;
			new Effect.Opacity("userinfo",{from:1,to:0,duration:1.5,
							afterFinish:function(){userinfo.innerHTML = ""}});
//				userinfo.innerHTML = "";
		}
	}
}
function gfnSwitch(strObj) {
	var obj = document.getElementById(strObj);
	if(obj.style.display =="block") {
		obj.style.display ="none";
	}else {
		obj.style.display ="block";
	}
} 

function toggle(divid) {
	if($(divid)) {
		Element.toggle($(divid));
	}
}
/** 
 *  分页页面换页用
 *  参 数: toPage  -- 要去的页的页数
 *  参 数: strAction  -- form提交向的action
 *  返回值: 无
 */
function goPage(toPage,strAction,objForm) {
	if(strAction.indexOf("?")>0){
		strAction=strAction+"&nowPage="+toPage
	}else{
		strAction=strAction+"?nowPage="+toPage
	}
	var runMsg = document.getElementById("runMsg");
	if(runMsg) {
		runMsg.style.display = "block";
	}
	var nowPage = document.getElementById("nowPage");
	if(nowPage) {
		nowPage.value = toPage;
	}
	var form = objForm;
	if(!form) {
		form = document.forms[0];
	}
	form.action = strAction;
	form.target = "_self";
	form.submit();
}
function gotoPage(gotoPageObjID,strAction,objForm) {
	var toPage = document.getElementById(gotoPageObjID).value;
	goPage(toPage,strAction,objForm);
}
function openKYP2PWin(kyp2pUrl) {
	var newwin = window.open(kyp2pUrl,'KYP2PWin','toolbar=0,location=0,height=150,width=380,left=0,top=0');
	var closeNewwin = function(){newwin.close()};
	newwin.focus();
	setTimeout(closeNewwin,'2500');
}

function emtInstalled() {
	return true;
}
// IE用，判断医脉通有没有安装
function emtInstalledBak() {
	try {
		var obj = new ActiveXObject("Msxml2.XMLHTTP");

		if (obj) {
			try {
				var emt = new ActiveXObject("EmtQuery.EMTQuery");

				if (emt) {
					var isEMTInstalled = emt.IsEMTInstalled(0)
					if (isEMTInstalled && isEMTInstalled == 1) {
						// alert("检测成功");
						return true;
					} else {
						// 理论上没有这样的情况
						alert("您的医脉通安装有问题，请重新安装");
						return false;
					}
				}
			} catch (e2) {
				// 医脉通没有安装
				alert("您还没有安装医脉通或您安装的版本太低，请下载并安装最新版医脉通");
				window.location.href = "http://www.medlive.cn" + contextPath + "/download/emt.exe";
				return false;
			}
		} else {
			// 理论上没有这样的情况
			alert("您的医脉通安装有问题，请重新安装");
			return false;
		}
	} catch (e) {
		// ActiveX对象不允许运行
		alert("您的安全设置太高，请修改安全设置。");
		return false;
	}
}

/** 
 *  评论部分前端分页页面换页用
 *  参 数: toPage  -- 要去的页的页数
 *  参 数: typeid  -- 数据库的表id
 *  参 数: objid  -- 数据库的主键id
 *  返回值: 无
 */
function goMyPage(toPage,typeid,objid) {
	var  pars  =  'nowPage=' + toPage+'&typeid='+typeid+'&objid='+objid;
	if($('commentDiv')) {
		var url = contextPath + '/comment/comment_list.do';
//		$('commentDiv').focus();
		var myAjax = new Ajax.Updater({success:'commentDiv'},url,{
			method: 'get',
			parameters: pars,
			evalScripts: true,
			on503: function(){$('commentDiv').innerHTML = ''}
		});
//		new Effect.ScrollTo('commentDiv', {offset: 2});
	}
}
function MM_swapImgRestore() { 
  var i,x,a=document.MM_sr; for(i=0;a&&i<a.length&&(x=a[i])&&x.oSrc;i++) x.src=x.oSrc;
}

function MM_preloadImages() { 
  var d=document; if(d.images){ if(!d.MM_p) d.MM_p=new Array();
    var i,j=d.MM_p.length,a=MM_preloadImages.arguments; for(i=0; i<a.length; i++)
    if (a[i].indexOf("#")!=0){ d.MM_p[j]=new Image; d.MM_p[j++].src=a[i];}}
}

function MM_findObj(n, d) {
  var p,i,x;  if(!d) d=document; if((p=n.indexOf("?"))>0&&parent.frames.length) {
    d=parent.frames[n.substring(p+1)].document; n=n.substring(0,p);}
  if(!(x=d[n])&&d.all) x=d.all[n]; for (i=0;!x&&i<d.forms.length;i++) x=d.forms[i][n];
  for(i=0;!x&&d.layers&&i<d.layers.length;i++) x=MM_findObj(n,d.layers[i].document);
  if(!x && d.getElementById) x=d.getElementById(n); return x;
}

function MM_swapImage() {
  var i,j=0,x,a=MM_swapImage.arguments; document.MM_sr=new Array; for(i=0;i<(a.length-2);i+=3)
   if ((x=MM_findObj(a[i]))!=null){document.MM_sr[j++]=x; if(!x.oSrc) x.oSrc=x.src; x.src=a[i+2];}
}
function preLoadTopImage() {
	MM_preloadImages(
		contextPath+'/zIndex/image/index_menu_on.gif',
		contextPath+'/zIndex/image/jhwzyx_menu_on.gif',
		contextPath+'/zIndex/image/yxzy_menu_on.gif',
		contextPath+'/zIndex/image/qwqz_menu_on.gif',
		contextPath+'/zIndex/image/fyqz_menu_on.gif',
		contextPath+'/zIndex/image/smsqz_menu_on.gif',
		contextPath+'/zIndex/image/scqj_menu_on.gif',
		contextPath+'/zIndex/image/fourm_menu_on.gif'
	);
}
//input text 有缺省值
function changeText(){
	var defaultText = "请输入关键词或用户ID";
    var obj = document.getElementById('q'); 
    if(obj.value == defaultText){ 
		obj.value=''; 
		obj.style.color = '#000000'; 
    } 
}
function getImage() {
	$('captcha').src='captchaAction.do?cd='+Math.random();
}