﻿//Author:Kenny(梅子溪)
//Contact:Kennytian@msn.com
//Date:2007-11-30  14:26:06


//提交预约表单
function submitReservation() {
  var name = $("name1").value;
  if(2 > name.length) {
    showMsg("Div1","请认真填写姓名!","#F00",3);
    $("name1").focus(); return;
  }
  var phone = $("tel").value;
  if(2>phone.length || 15<phone.length) {
    showMsg("Div1","请认真填写电话!","#F00",3);
    $("tel").focus(); return;
  }
  var remark = $("remark").value;
  if(2 > remark.length) {
    showMsg("Div1","请认真预约备注!","#F00",3);
    $("remark").focus(); return;
  }
  doReservationSubmit(name,phone,remark)
}
function doReservationSubmit(name,phone,remark) {
  var reservationData = "name="+encodeURIComponent(name)+"&phone="+encodeURIComponent(phone)+"&remark="+encodeURIComponent(remark);
  var ajax = new Ajax("Ajax.aspx","insertReservation",1,reservationData, doSuccessTip)
  ajax.POST();
}

//文章搜索
function SearchSubmit() {
  var k = $("keyword").value;
  var f = getRdoOrChkValue("field");
  window.open("search.aspx?keyword="+encodeURIComponent(k)+"&field="+f);
}

///订单提交开始
function submitOrder() {
  var t1 = $("t1").value;
  if(2 > t1.length) {
    showMsg("Div1","请认真填写姓名!","#F00",3);
    $("t1").focus(); return;
  }
  var t2 = $("t2").value; ///性别
  var t3 = $("t3").value;
  if (1>t3.length || isNaN(t3)) {
    showMsg("Div2","请输入合法年龄","#F00",3);
    $("t3").focus(); return;
  }
  var t4 = $("t4").value;
  if(6 > t4.length || isNaN(t4)) {
    showMsg("Div3","请认真填写电话!","#F00",3);
    $("t4").focus(); return;
  }
  var t5 = $("t5").value; ///电子邮件
  var t6 = $("t6").value;
  if(3 > t6.length || 15 < t6.length) {
    showMsg("Div4","请认真填写发病日期!","#F00",3);
    $("t6").focus(); return;
  }
  var t7 = $("t7").value;
  if(3 > t7.length) {
    showMsg("Div5","请认真填写发病过程!","#F00",3);
    $("t7").focus(); return;
  }
  var t8 = $("t8").value;
  if(4 > t8.length) {
    showMsg("Div6","请认真填写服药情况!","#F00",3);
    $("t8").focus(); return;
  }
  var t9 = $("t9").value;
  if(4 > t9.length) {
    showMsg("Div7","请认真填写病情描述!","#F00",3);
    $("t9").focus(); return;
  }
  var t10 = getRdoOrChkValue("t10");
  if(7 > t10.length) {
    showMsg("Div8","请选择对会诊的具体要求!","#F00",3);
    return;
  }
  doOrderSubmit(t1,t2,t3,t4,t5,t6,t7,t8,t9,t10);
}
//提交订单数据
function doOrderSubmit(t1,t2,t3,t4,t5,t6,t7,t8,t9,t10) {
  var orderData = "t1="+encodeURIComponent(t1)+"&t2="+encodeURIComponent(t2)+"&t3="+encodeURIComponent(t3)+"&t4="+encodeURIComponent(t4)+"&t5="+encodeURIComponent(t5)+"&t6="+encodeURIComponent(t6)+"&t7="+encodeURIComponent(t7)+"&t8="+encodeURIComponent(t8)+"&t9="+encodeURIComponent(t9)+"&t10="+encodeURIComponent(t10);
  var ajax = new Ajax("Ajax.aspx","insertOrder",1,orderData, doSuccessTip)
  ajax.POST();
}
//弹出提示
function doSuccessTip() {
  showMsg('msgSuccess','恭喜: 您的操作已成功!','green',7);
  ClearAll();
}

///等比缩放图片,Kennytian@msn.com
///<img src="images/KennyLogo.gif" border="0" style="zoom: 0.1" onload="resizeImage(this, 80, 60)"/>
function resizeImage(obj, width, height) {
  myImage = new Image();
  myImage.src = obj.src;
  if (myImage.width>0 && myImage.height>0) {
    var rate = 1;
    if (myImage.width>width || myImage.height>height)
    {
      if (width/myImage.width<height/myImage.height)
        rate = width/myImage.width;
      else
        rate = height/myImage.height;
    }
    if (window.navigator.appName == "Microsoft Internet Explorer")
      obj.style.zoom = rate;
    else {
      obj.width = myImage.width*rate;
      obj.height = myImage.height*rate;
    }
  }
}

///取得验证码
function fGetCode(id,path) {
  var vcode = $(id);
  vcode.src = path + '?randNum='+Math.random();
}
//UI层Js结束///////////////////////////////////////////////////////////////////////////////////////////////////////////////

///Ajax
var xmlHttp;
function Ajax(url,action,recvT,stringS,resultF) { //url,receiveType,queryString,resultFunction
  this.action = action
  this.url = url;
  this.stringS = stringS;
  this.xmlHttp = this.createXMLHttpRequest();
  var objxml = this.xmlHttp;
  objxml.onreadystatechange = function (){Ajax.handleStateChange(objxml,recvT,resultF)};
}
Ajax.prototype.createXMLHttpRequest = function() {
  try {
    xmlHttp = new XMLHttpRequest();
   
  }
  catch(e) {
    var xmlhttps = ["MSXML2.XMLHTTP.5.0","MSXML2.XMLHTTP.4.0","MSXML2.XMLHTTP.3.0","MSXML2.XMLHTTP","Microsoft.XMLHTTP"];
    var xmlItemLen = xmlhttps.length;
    for(t=0; t<xmlItemLen; t++)
      xmlHttp = new ActiveXObject(xmlhttps[t]);
    
  }
  if(null == xmlHttp)
    alert("Unable to create XMLHttpRequest.");
  return xmlHttp;
}
//查询字符串
Ajax.prototype.createQueryString = function () {
 var queryString = this.stringS;
 return queryString;
}
//GET提交
Ajax.prototype.GET = function () {
 url = this.url;
 var queryString = url+"?timeStamp=" + new Date().getTime() + "&" + this.createQueryString();
 this.xmlHttp.open("GET",queryString,true);
 this.xmlHttp.send(null);
}
//POST提交
Ajax.prototype.POST = function() {
 action = this.action;
 url = this.url;
 var url = url +"?action="+action+ "&timeStamp=" + new Date().getTime();
 var queryString = this.createQueryString();
 //alert(url);//return false;
 this.xmlHttp.open("POST",url,true);
 this.xmlHttp.setRequestHeader("Content-Type","application/x-www-form-urlencoded");
 this.xmlHttp.send(queryString);
}
//状态处理
Ajax.handleStateChange = function (xmlHttp,recvT,resultF) {
  if (4 == xmlHttp.readyState) {
    if(200 == xmlHttp.status) {
      $("msgLoading").style.display = "none";
      resultF(recvT?xmlHttp.responseXML:xmlHttp.responseText); //receiveType(0xml,1text)
    }
    else
      alert("有错误发生,请联系开发人员! 错误代码：" + xmlHttp.status);
  }
  else {
    $("msgLoading").style.display = "inline";
  }
}

//显示提示
var timer;
function showMsg(msgDiv,msgText,color,iTime) {
  $(msgDiv).style.display = "inline";
  $(msgDiv).style.position = "absolute"; //这个参数很重要
  $(msgDiv).style.height = "20px";
  $(msgDiv).style.lineHeight = "20px";
  $(msgDiv).style.border = "solid 1px " + color;
  var html = "<span style=\"color:"+color+";margin:3px;font-weight:bold;\">"+msgText+"<span style=\"margin-left:20px;cursor:pointer;\" title=\"点击关闭\" onclick=\"closeMsg('"+msgDiv+"');\">×</span></span>";
  $(msgDiv).innerHTML = html;
  if(iTime!=null )
    timer = setTimeout("closeMsg('"+msgDiv+"')", iTime*1000);
}
function closeMsg(msgDiv) {
  $(msgDiv).style.display = "none";
}

//清空文本框
function ClearAll() {
  var e = document.getElementsByTagName("input");
  var isInput = false;
  for(var i=0; i<e.length; i++) {
    isInput = ("text"==e[i].type || "password"==e[i].type)
    if(isInput) e[i].value = "";
  }
  var t = document.getElementsByTagName("textarea");
  for(var j=0; j<t.length; j++) {
    t[j].value = "";
  }
}

/// <div id="timeshow"> //blog.sjzj.com.cn
/// <script language="JavaScript" type="text/javascript" defer="defer">
/// new nowTime('yy年MM月dd日 hh:mm:ss 星期WW').toShow('timeshow');
/// </script></div>
function nowTime(format) {
  var dt = new Date();
  this.Year = dt.getFullYear();
  this.Month = dt.getMonth()+1;
  this.Day = dt.getDate();
  this.Week = dt.getDay();
  this.WeekDay = '日一二三四五六'.charAt(dt.getDay());
  this.Hours24 = dt.getHours();
  this.Hours12 = this.Hours24>12 ? this.Hours24-12 : this.Hours24;
  this.Minutes = dt.getMinutes();
  this.Seconds = dt.getSeconds();
  format = format.replace("yy",this.Year);
  format = format.replace("MM",this.Month);
  format = format.replace("dd",this.Day);
  format = format.replace("HH",this.Hours24);
  format = format.replace("hh",this.Hours12);
  format = format.replace("mm",this.Minutes);
  format = format.replace("ss",this.Seconds);
  format = format.replace("ww",this.Week);
  format = format.replace("WW",this.WeekDay);
  this.toShow = function (element) {
    document.getElementById(element).innerHTML=format;
  }
}

/* 显示报错 <script type="text/javascript">window.onerror = reportError;</script> */
function reportError(msg,url,line){
  var str = "系统发现如下的的错误:\n\n";
  str += "位置: 第" + line + "行\n\n";
  str += "错误: " + msg + "\n\n";
  str += "网址: " + url;
  alert(str);
  return true;
}

//取得Radio或Check的值
function getRdoOrChkValue(sId) {
//把Checkbox的值设置为value+逗号,这样不会使值全连在一起
  var value = "";
  var tagName = $N(sId);
  for (i=0; i<tagName.length; i++) {
    if (tagName[i].checked)
      value += tagName[i].value;
  }
  return value;
}

function $T() {  /// $T('input','box')
  if (arguments.length==1)
    return document.getElementsByTagName(arguments[0]);
  else if(arguments.length==2) {
    if (typeof(arguments[1])=="object")
      return arguments[1].getElementsByTagName(arguments[0]);
    else
      return $(arguments[1]).getElementsByTagName(arguments[0]);
  }
}

function $N() {
  return document.getElementsByName(arguments[0]);
}

function $() {
  return document.getElementById(arguments[0]);
}