﻿// JavaScript Document
var xmlHttp,showplace=null,values=null;

function createXMLHttpRequest() 
{
    if (window.ActiveXObject) 
	{
        xmlHttp = new ActiveXObject("Microsoft.XMLHTTP");
    }
    else if (window.XMLHttpRequest) 
	{
        xmlHttp = new XMLHttpRequest();                
    }
}

function startRequest(url)
{
	createXMLHttpRequest();
	xmlHttp.onreadystatechange=startCallback;
	xmlHttp.open("GET",url,true);
	xmlHttp.setRequestHeader("If-Modified-Since","0"); //禁止IE缓存
	if(values!=null)
	{
		xmlHttp.setRequestHeader("Content-Type","application/x-www-form-urlencoded;");	
	}
	xmlHttp.send(values);
}

function startCallback()
{
	if(xmlHttp.readyState==4)
	{
		if(xmlHttp.status==200)
		{
			if(showplace!=null)
			{	
				if(showplace=="balance")
				{
					document.getElementById(showplace).value=xmlHttp.responseText;
					if(checknum(xmlHttp.responseText))
					{
						if(Math.floor(document.getElementById("paymoney").value)>Math.floor(xmlHttp.responseText))
						{
							alert("您的帐户余额不够支付本此挂号费，请为您的帐号充值！");
						}else
						{
							document.getElementById("form1").submit();
						}
					}else
					{
						alert(xmlHttp.responseText);
					}
				}else if(showplace=="initial")
				{
					document.getElementById(showplace).value=xmlHttp.responseText;
				}else if(showplace=="error_hint")
				{
					if(xmlHttp.responseText==1)
					{
						error_hint.innerHTML="此卡已开通，只能通过<a href='login.php'>授权登录</a>";
					}else if(xmlHttp.responseText==404){
						error_hint.innerHTML="此卡不存在请检查您输入的卡号";
					}else if(xmlHttp.responseText==20){

						form2.submit();
					}
					return false;
				}
				else
				{
					document.getElementById(showplace).innerHTML=xmlHttp.responseText;
				}
			}
		}
	}
}
function checknum(str)
{
	var isnum=true;
	for(i=0;i<str.length;i++)
	{
		if((str.charAt(i)<"0"||str.charAt(i)>"9")&&str.charAt(i)!=".")
		{
			isnum=false;
		}
	}
	return isnum;
}
function Request(url)
{
	createXMLHttpRequest();
	xmlHttp.onreadystatechange=Callback;
	xmlHttp.open("GET",url,true);
	//xmlHttp.setRequestHeader("If-Modified-Since","0"); //禁止IE缓存
	if(values!=null)
	{
		xmlHttp.setRequestHeader("Content-Type","application/x-www-form-urlencoded;");	
	}
	xmlHttp.send(values);
}
function Callback()
{
	if(xmlHttp.readyState==4)
	{
		if(xmlHttp.status==200)
		{	
			document.getElementById("myzone").innerHTML=xmlHttp.responseText;
		}
	}
}
//检查注册EMail
function checkemail()
{
	showplace="checkresult";
	var email=document.getElementById("r_email").value;
	
	if(email=="")
	{
		alert("请输入登录邮箱！");
		return false;
	}else
	{
		if(email.charAt(0)=="." ||email.charAt(0)=="@"||email.indexOf('@', 0) == -1 ||email.indexOf('.', 0) == -1 ||email.lastIndexOf("@")==email.length-1 ||email.lastIndexOf(".")==email.length-1)
		{
			alert("请输入正确的邮箱！");
			return false;
		}else
		{
			return startRequest('checkemail.php?email='+email+"&currenttime="+new Date().getTime());
		}
	}
}
//检索管理员帐号
function check_user()
{
	showplace="addadministrator";
	var email=document.getElementById("email").value;
	if(email=="")
	{
		alert("请输入E-Mail！");	
		return false;
	}else
	{
		if(email.charAt(0)=="." ||email.charAt(0)=="@"||email.indexOf('@', 0) == -1 ||email.indexOf('.', 0) == -1 ||email.lastIndexOf("@")==email.length-1 ||email.lastIndexOf(".")==email.length-1)
		{
			alert("请输入正确的E-Mail！");
			return false;
		}else
		{
			return startRequest('check_user.php?email='+email+"&currenttime="+new Date().getTime());
		}
	}
}
//显示模块
function showmodule()
{
	showplace="showmodule";	
	var id=document.getElementById("group").value;
	startRequest("show_module.php?id="+id+"&currenttime="+new Date().getTime());
}
//显示符合条件的方剂
/*
function showprescription()
{
	showplace="prescription";
	var letter=document.getElementById("prename").value;
	var datediv=document.getElementById("prescription").value;
	datadiv.style.border = "black 1px solid";
	dataDiv.style.left = 392 + "px";
    dataDiv.style.top = document.getElementById("prename").bottom;
	startRequest("show_module.php?id="+id+"&currenttime="+new Date().getTime());
}
*/
function sendchatcontent()
{
	values="touser="+document.getElementById("touser").value+"&content="+document.getElementById("content").value;
	//showplace="showmain";
	startRequest("add.php");
	document.getElementById("content").value="";
}
function refreshchatobj(name)
{
	values="name="+name;
	showplace="obj";
	startRequest("refresh_obj.php");
}

function searchprescript(herb)
{
	showplace="suggestcontent";
	var letter=document.getElementById(herb).value;
	if(herbtextvalue!=letter)
	{
		keymark=1;	
		herbtextvalue=letter;
	}
	startRequest("suggest.php?keymark="+keymark+"&letter="+letter+"&tid="+herb+"&currenttime="+new Date().getTime());
	suggestspace(herb);
}
function herbtopname()
{
	showplace="suggestcontent";
	var letter=document.getElementById("topname").value;
	startRequest("suggest_tn.php?letter="+letter+"&tid=topname&currenttime="+new Date().getTime());
	suggestspace("topname");
}
function suggestspace(herb)
{
	var divid=document.getElementById("suggestcontent");
	var textid=document.getElementById(herb);
	
	//设置显示的位置
	//var end = textid.offsetWidth;
	var end=getleftx(document.getElementById(herb));
    var top = calculateOffset(textid,"offsetTop");
    divid.style.left =end+"px";
    divid.style.top =top+20+"px";
}
function editsearchprescript(herb)
{
	showplace="suggestcontent";
	var letter=document.getElementById(herb).value;
	startRequest("suggest.php?keymark="+keymark+"&letter="+letter+"&tid="+herb+"&currenttime="+new Date().getTime());
	editsuggestspace(herb)
}
function editsuggestspace(herb)
{
	var divid=document.getElementById("suggestcontent");
	var textid=document.getElementById(herb);
	
	//设置显示的位置
	var end = textid.offsetWidth;
    var top = calculateOffset(textid,"offsetTop");
    divid.style.left =getleftx(document.getElementById(herb));
    divid.style.top =top+20;	
}
//动态获取一个文本框的坐标
function   getIE(e){   
      var   t=e.offsetTop;   
      var   l=e.offsetLeft;   
      while(e=e.offsetParent){   
          t+=e.offsetTop;   
          l+=e.offsetLeft;   
      }   
      alert("top="+t+"\nleft="+l);   
} 
//动态获取文本框的横坐标
function getleftx(e)
{ 
    var   l=e.offsetLeft;   
    while(e=e.offsetParent){
        l+=e.offsetLeft;   
    }   
    return l;   
}
function calculateOffset(field, attr) 
{
    var offset = 0;
    while(field) 
	{
    	offset += field[attr]; 
        field = field.offsetParent;
    }
    return offset;
}
function clearData() 
{       
	var div=document.getElementById("suggestcontent");
	showplace="";
	keymark=1;
	div.innerHTML="";
}  
function herbisexists(herb,tid_pre)
{
	var herbname=document.getElementById(herb).value;
	var isok=true;
	for(var i=1;i<=20;i++)
	{
		if(eval("document.getElementById('"+tid_pre+i+"').value")!=""&&eval("document.getElementById('"+tid_pre+i+"').value")==herbname)
		{
			isok=false;
		}
	}
	return isok;
}
function addvaluetn(smark,tid)
{
	document.getElementById(tid).value=document.getElementById("herb"+smark+"suggest").value;
}
function addvalue(smark,tid)
{
	var tid_pre=tid.substr(0,(tid.indexOf("b")+1));
	if(herbisexists("herb"+smark+"suggest",tid_pre))
	{
		document.getElementById(tid).value=document.getElementById("herb"+smark+"suggest").value;
	}else
	{
		if(document.getElementById(tid).value!="")
		{
			document.getElementById(tid).value="";
			alert("此药已开过！");
		}
	}
}
function patientneedsknow()
{
	showplace="main_center_content";
	startRequest("patient_needs_know.php?currenttime="+new Date().getTime());
}
function sitehelp()
{
	showplace="main_center_content";
	startRequest("help.php?currenttime="+new Date().getTime());
}
function showTop(index)
{
	switch(index)
	{
		case 'leave_word':
			document.getElementById('top_title_leave_word').className="up" ;
			document.getElementById('top_title_needs_know').className="" ;
			document.getElementById('top_title_help').className="" ;
			leaveword();
			break;
		case 'needs_know':
			document.getElementById('top_title_leave_word').className="" ;
			document.getElementById('top_title_needs_know').className="up" ;
			document.getElementById('top_title_help').className="" ;
			patientneedsknow();
			break;
		case 'help':
			document.getElementById('top_title_leave_word').className="" ;
			document.getElementById('top_title_needs_know').className="" ;
			document.getElementById('top_title_help').className="up" ;
			sitehelp();
			break;
	}
}
function leaveword()
{
	showplace="main_center_content";
	startRequest("online_leave_word.php?currenttime="+new Date().getTime());	
}
function synopsis(id)
{
	showplace="synopsis";
	startRequest("synopsis.php?id="+id+"&currenttime="+new Date().getTime());
}
function showcasephoto(cid)
{
	showplace=cid;
	startRequest("show_case_photo.php?c_id="+cid+"&currenttime="+new Date().getTime());
	document.getElementById("c"+cid).innerHTML="<a href=\"javascript:void(0)\" onclick=\"concealcasephoto('"+cid+"')\">隐藏照片</a>";
}
function concealcasephoto(cid)
{
	showplace=cid;
	document.getElementById(cid).innerHTML="";
	document.getElementById("c"+cid).innerHTML="<a href=\"javascript:void(0)\" onclick=\"showcasephoto('"+cid+"')\">显示照片</a>";
}
function getprescription(clinicid,id,textid,mark)
{
	//showplace=clinicid;
	var openout=0;
	var openmark=0;
	
	for(i=1;i<=3;i++)
	{
		if(document.getElementById("clid"+clinicid+"rp_"+i).style.display==""&&document.getElementById("clid"+clinicid+"recipe_"+i).style.display=="")
		{
			openout++;
			openmark=i;
		}
	}
	if(openout==0||openout>1)
	{
		alert("此功能只能在展开一个处方时才起作用！");	
	}else
	{
		showplace="clid"+clinicid+"r"+openmark;
		startRequest("show_prescription.php?ri="+openmark+"&clinicid="+clinicid+"&id="+id+"&currenttime="+new Date().getTime());
	}
	if(textid)
	{
		document.getElementById(textid).value=document.getElementById("tranfer_pst"+mark).value;
		keymark=1;
		document.getElementById("suggestcontent").innerHTML="";
	}
}
function lasttimeprescription(clinicid,id)
{
	showplace=id;
	startRequest("last_time_prescription.php?clinicid="+clinicid+"&currenttime="+new Date().getTime());
}
function showprescription(clinicid)
{
	showplace="showprescription";
	var kind=document.getElementById("prekind").value;
	startRequest("show_prescript_name.php?clinicid="+clinicid+"&k="+kind+"&currenttime="+new Date().getTime());
}
function refreshchatcontent()
{
	showplace="showmain";
	startRequest("refresh_chat.php?currenttime="+new Date().getTime());
	setTimeout("refreshchatcontent()",971);
}
function refreshmain()
{
	showplace="cmain";
	startRequest("main.php?curenttime="+new Date().getTime());
}
function timedrefresh()
{
	showplace="cmain";
	startRequest("main.php?curenttime="+new Date().getTime());
	setTimeout("timedrefresh()",1000);
}
function leaveline(email,chatid)
{
	startRequest("leaveline.php?email="+email+"&chatid="+chatid+"&currenttime="+new Date().getTime());
}
function setscroll()
{
	//alert("fdsfds");
	var obj=document.getElementById("abc");
	obj.scrollTop=obj.scrollHeight;
}
function searchadvance(url)
{
	switch(url)
	{
		case 'zy_select.php':
			document.getElementById('zy_select').className="up" ;
			document.getElementById('fj_select').className="" ;
			document.getElementById('art_select').className="" ;
			document.getElementById('doctor_select').className="" ;
			break;
		case 'fj_select.php':
			document.getElementById('zy_select').className="" ;
			document.getElementById('fj_select').className="up" ;
			document.getElementById('art_select').className="" ;
			document.getElementById('doctor_select').className="" ;
			break;
		case 'art_select.php':
			document.getElementById('zy_select').className="" ;
			document.getElementById('fj_select').className="" ;
			document.getElementById('art_select').className="up" ;
			document.getElementById('doctor_select').className="" ;
			break;
		case 'doctor_select.php':
			document.getElementById('zy_select').className="" ;
			document.getElementById('fj_select').className="" ;
			document.getElementById('art_select').className="" ;
			document.getElementById('doctor_select').className="up" ;
			break;
	}
	showplace="searchtype";
	startRequest(url+"?curenttime="+new Date().getTime());
}
function checkbalance(user,clinicId)
{
	showplace="balance";
	startRequest("checkbalance.php?user="+user+"&clinicId="+clinicId+"&curenttime="+new Date().getTime());
}
function checkclinicid()
{
	showplace="refundment";
	var id=document.getElementById("clinicid").value;
	startRequest("checkclinicid.php?clinicid="+id+"&currenttime="+new Date().getTime());
}
function netbank()
{
	showplace="netbank";
	var money=document.getElementById("money").value;
	startRequest("inputcheck.php?money="+money+"&currenttime="+new Date().getTime());
}
function drrcheckbalance(email)
{
	showplace="error";
	var money=document.getElementById("money").value;
	startRequest("open_dr_check_balance.php?email="+email+"&money="+money+"&currenttime="+new Date().getTime());
}
function getinitial()
{
	showplace="initial";
	var c=document.getElementById("name").value;
	startRequest("get_initial.php?c="+c+"&currenttime="+new Date().getTime());
}
function checkherbname()
{
	showplace="herbhint";
	var name=document.getElementById("name").value;
	startRequest("check_herb_name.php?name="+name+"&currenttime="+new Date().getTime());		
}
function editip(tid,ip,id)
{
	showplace=tid;
	startRequest("edit_ip.php?ip="+ip+"&id="+id+"&currenttime="+new Date().getTime());		
}
function filtrateedit(tid,filtrate,id)
{
	showplace=tid;	
	startRequest("filtrate_edit.php?filtrate="+filtrate+"&id="+id+"&ct="+new Date().getTime());
}
function casefallinoper(clinicid)
{
	startRequest("../trigger/case_fallin_oper.php?clinicid="+clinicid+"&ct="+new Date().getTime());
}
function checknewcard()
{
	showplace="error_hint";	
	var p_id=document.getElementById("patient_id").value;
	if(p_id==null||p_id=="") 
	{
		form2.submit();	
	}else{
		startRequest("check_newcard.php?p_id="+p_id+"&ct="+new Date().getTime());
	}
}
function transferprescription(textid,clinicid)
{
	showplace="suggestcontent";
	var initial=document.getElementById(textid).value;
	if(transferpst!=initial)
	{
		keymark=1;
		transferpst=initial;
	}
	startRequest("suggest_pst.php?it="+initial+"&clinicid="+clinicid+"&textid="+textid+"&keymark="+keymark+"&ct="+new Date().getTime());
	//suggestspace(herb);
	//getprescription(clinicid,id)	
	var divid=document.getElementById("suggestcontent");
	//设置显示的位置
	//var end = textid.offsetWidth;
	var end=getleftx(document.getElementById(textid));
    var top = calculateOffset(document.getElementById(textid),"offsetTop");
    divid.style.left =end+"px";
    divid.style.top =top+20+"px";
}
function submitrefundment()
{
	if(document.getElementById("clinicid").value=="")
	{
		alert("请填写你要退款的病例号!");
	}else if(document.getElementById("money").value=="")
	{
		alert("退款金额不能为空!");
	}else if(!checknum(document.getElementById("money").value))
	{
		alert("退款金额只能是0-9中的数字!");
	}else
	{
		var s=document.getElementById("refundment").innerHTML;	
		if(s!="此病例不存在,请查正后再试!")
		{
			document.form1.submit();
		}
	}
}
function isdel()
{
	if(confirm("确定要删除吗?"))
	{
		return true;	
	}else
	{
		return false;	
	}
}
