﻿// JavaScript Document
function SelectNav(n, c){
	ClearNav(c);
	$('nav_' + n).className = 'action';
	DisplayNav(n, c);

	switch(n){
		case 1:
			$('space_1').style.display = 'none';
			break;
		case c:
			$('space_' + (c - 1)).style.display = 'none';
			break;
		default:
			$('space_' + n).style.display = 'none';
			$('space_' + (n - 1)).style.display = 'none';
			break;
	}
}

function DisplayNav(n, c){
	var oRect = $('nav_' + n).getBoundingClientRect();

	if (oRect.left >= 700) $('snav_' + n).style.left = oRect.left - 150 + 'px';
	else $('snav_' + n).style.left = oRect.left + 27 + 'px';
	$('snav_' + n).style.display = 'block';
}

function ClearNav(c){
	for (var i=1; i<=c; i++){
		$('nav_' + i).className = '';
		$('snav_' + i).style.display = 'none';
		if (i<c) $('space_' + i).style.display = 'block';
	}
}

function NLabel(n, c){
	for (var i=1; i<=c; i++){
		$('nlabel_' + i).className = '';
		$('ndiv_' + i).className = 'none';
	}
	$('nlabel_' + n).className = 'action';
	$('ndiv_' + n).className = '';
}

String.prototype.Trim = function(){
	return this.replace(/(^\s*)|(\s*$)/g, "");
}

function checkMessageFrm(o){
	if (o.topic.value.Trim() == ''){
		window.alert('请您输入标题！');
		o.topic.focus();
		return false;
	}
	if (o.content.value.Trim() == ''){
		window.alert('请您输入内容！');
		o.content.focus();
		return false;
	}
	if (o.validatorcode.value.Trim() == ''){
		window.alert('请您输入验证码！');
		o.validatorcode.focus();
		return false;
	}
	if (o.validatorcode.value.Trim().length < 5){
		window.alert('您输入的验证码错误！');
		o.validatorcode.focus();
		return false;
	}
	return true;
}

function checkRegFrm(o){
	if (SelectRadio('expid') == ''){
		window.alert('请您选择要预约挂号的专家！');
		return false;
	}
	if (SelectRadio('regtime') == ''){
		window.alert('请您选择挂号时间！');
		if (SelectRadio('expid') !== '') RegDateTableHtml(SelectRadio('expid'), '');
		return false;
	}
	if (o.name.value.Trim() == ''){
		window.alert('请您输入姓名！');
		o.name.focus();
		return false;
	}
	var str = /[^\u4E00-\u9FA5]/;	
	if (str.test(o.name.value.Trim())){
		window.alert('姓名输入错误，请检查！');
		o.name.focus();
		return false;
	}
	if (o.idcard.value.Trim() == ''){
		window.alert('请您输入身份证！');
		o.idcard.focus();
		return false;
	}
	if (o.idcard.value.Trim().length !== 15 && o.idcard.value.Trim().length !== 18){
		window.alert('身份证输入错误，请检查！');
		o.idcard.focus();
		return false;
	}
	var str = /(^[0-9]{14,17}[0-9xX]{1}$)/;
	if (!str.test(o.idcard.value.Trim())){
		window.alert('身份证输入错误，请检查！');
		o.idcard.focus();
		return false;
	}
	if (o.mobile.value.Trim() == ''){
		if (o.tel.value.Trim() == ''){
			window.alert('手机或联系电话至少填写一项目！');
			o.mobile.focus();
			return false;
		}else{
			var str = /(^[0-9]{3,4}\-[0-9]{7,8}$)|(^[0-9]{7,8}$)|(^\([0-9]{3,4}\)[0-9]{3,8}$)|(^0{0,1}1[0-9]{10}$)/;
			if (!str.test(o.tel.value.Trim())){
				window.alert('联系电话输入错误，请检查！');
				o.tel.focus();
				return false;
			}
		}
	}else{
		var str = /(^0{0,1}1[0-9]{10}$)/;
		if (!str.test(o.mobile.value.Trim())){
			window.alert('手机输入错误，请检查！');
			o.mobile.focus();
			return false;
		}
	}
	if (o.validatorcode.value.Trim().length == ''){
		window.alert('请您输入验证码！');
		o.validatorcode.focus();
		return false;
	}
	if (o.validatorcode.value.Trim().length !== 5){
		window.alert('验证码输入错误，请检查！');
		o.validatorcode.focus();
		return false;
	}
	return true;
}

function SelectRadio(n){
	var obj = document.getElementsByName(n);
    for (i=0; i<obj.length; i++){
		if(obj[i].checked) break;
	}
	if (i == obj.length){
		return '';
	}else{
		return obj[i].value;
	}
}

function LoadFrmData(id, date){
	if (id !== ''){
		SelectExpert('expid_'+ id);
		RegDateTableHtml(id, date);
		if (date !== '') RegNumMsg(id, date.replace('_', ' '));
	}
}

function DateTableHtml(id){
	var ajx = new Ajax.Request('/inc/script.asp?type=datetable&id='+ id +'&'+ Math.random(), {method: 'get', onComplete: DateTableHtmlOut});
}

function RegDateTableHtml(id, date){
	$('RegNum').innerHTML = '';
	$('DateTable').innerHTML = '<span class="text">正在加载日期数据...</span>';
	var ajx = new Ajax.Request('/inc/script.asp?type=regdatetable&id='+ id +'&date='+ date +'&'+ Math.random(), {method: 'get', onComplete: DateTableHtmlOut});
}

function RegNumMsg(id, date){
	$('RegNum').innerHTML = '<div class="text">正在加载数据...</div>';
	var ajx = new Ajax.Request('/inc/script.asp?type=regnum&id='+ id +'&date='+ date +'&'+ Math.random(), {method: 'get', onComplete: RegNumMsgOut});
}

function DateTableHtmlOut(o){
	$('DateTable').innerHTML = o.responseText;
}

function RegNumMsgOut(o){
	var n = o.responseText;
	if (n > 0){
		$('RegNum').innerHTML = '<div class="result">以上时间，该专家还有<strong>'+ n +'</strong>名在线挂号名额.</div>';
		RegFrmMode(false);
	}else{
		$('RegNum').innerHTML = '<div class="result">以上时间，该专家在线挂号名额已满.</div>';
		RegFrmMode(true);
	}
}

function RegFrmMode(t){
	$('regFrm').onsubmit = t ? function(){window.alert('以上时间，该专家在线挂号名额已满！\n请选择其他时间或其他专家进行挂号。');return false;} : function(){return checkRegFrm(this);};
}

function SelectExpert(id){
	$(id).checked = 'checked';
}

function IsNew(d)
{
	var d = new Date(d.replace(/\-/g,"/"));
	if (DateDiff(new Date().toLocaleDateString(), d.toLocaleDateString()) <= 5)
	document.write('<img class="new" align="absmiddle" alt="" src="/image/icon_new.gif" />');
}

function DateDiff(sDate1, sDate2)
{
	var aDate, oDate1, oDate2, iDays;
	aDate = sDate1.split("-");
	oDate1 = new Date(aDate[1] + '-' + aDate[2] + '-' + aDate[0]); //转换为12-18-2002格式
	aDate = sDate2.split("-");
	oDate2 = new Date(aDate[1] + '-' + aDate[2] + '-' + aDate[0]);
	iDays = parseInt(Math.abs(oDate1 - oDate2) / 1000 / 60 / 60 /24); //把相差的毫秒数转换为天数
	return iDays;
}

function OpenPrintWindow(id){
	window.open('?type=print&id='+ id, "newwindow", "height=320, width=370, toolbar=no, menubar=no, scrollbars=no, resizable=no, location=no, status=no, top=0, left=0");
}

function ReFresh(id){
	$(id).src = '/inc/validator.asp?'+ Math.random();
}

/* 漂浮广告开始 */
function addEvent(obj,evtType,func,cap){
    cap=cap||false;
	if(obj.addEventListener){
	    obj.addEventListener(evtType,func,cap);
		return true;
	}else if(obj.attachEvent){
        if(cap){
	        obj.setCapture();
	        return true;
	    }else{
		    return obj.attachEvent("on" + evtType,func);
		}
	}else{
		return false;
    }
}
function getPageScroll(){
    var xScroll,yScroll;
	if (self.pageXOffset) {
		xScroll = self.pageXOffset;
	} else if (document.documentElement && document.documentElement.scrollLeft){
		xScroll = document.documentElement.scrollLeft;
	} else if (document.body) {
		xScroll = document.body.scrollLeft;
	}
	if (self.pageYOffset) {
		yScroll = self.pageYOffset;
	} else if (document.documentElement && document.documentElement.scrollTop){
		yScroll = document.documentElement.scrollTop;
	} else if (document.body) {
		yScroll = document.body.scrollTop;
	}
	arrayPageScroll = new Array(xScroll,yScroll);
	return arrayPageScroll;
}
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){
        xScroll = document.body.scrollWidth;
        yScroll = document.body.scrollHeight;
    } else {
        xScroll = document.body.offsetWidth;
        yScroll = document.body.offsetHeight;
    }
    var windowWidth, windowHeight;
    if (self.innerHeight) {
        windowWidth = self.innerWidth;
        windowHeight = self.innerHeight;
    } else if (document.documentElement && document.documentElement.clientHeight) {
        windowWidth = document.documentElement.clientWidth;
        windowHeight = document.documentElement.clientHeight;
    } else if (document.body) {
        windowWidth = document.body.clientWidth;
        windowHeight = document.body.clientHeight;
    }	
    if(yScroll < windowHeight){
        pageHeight = windowHeight;
    } else { 
        pageHeight = yScroll;
    }
    if(xScroll < windowWidth){	
        pageWidth = windowWidth;
    } else {
        pageWidth = xScroll;
    }
    arrayPageSize = new Array(pageWidth,pageHeight,windowWidth,windowHeight) 
    return arrayPageSize;
}
/* 广告脚本文件 AdMove.js */
/*
<div id="Div">
    ***** content ******
</div>
var ad=new AdMove("Div");
ad.Run();
*/
////////////////////////////////////////////////////////
var AdMoveConfig=new Object();
AdMoveConfig.IsInitialized=false;
AdMoveConfig.ScrollX=0;
AdMoveConfig.ScrollY=0;
AdMoveConfig.MoveWidth=0;
AdMoveConfig.MoveHeight=0;
AdMoveConfig.Resize=function(){
    var winsize=GetPageSize();
    AdMoveConfig.MoveWidth=winsize[2];
    AdMoveConfig.MoveHeight=winsize[3];
    AdMoveConfig.Scroll();
}
AdMoveConfig.Scroll=function(){
    var winscroll=getPageScroll();
    AdMoveConfig.ScrollX=winscroll[0];
    AdMoveConfig.ScrollY=winscroll[1];
}
addEvent(window,"resize",AdMoveConfig.Resize);
addEvent(window,"scroll",AdMoveConfig.Scroll);
function AdMove(id){
    if(!AdMoveConfig.IsInitialized){
        AdMoveConfig.Resize();
        AdMoveConfig.IsInitialized=true;
    }
    var obj=document.getElementById(id);
    obj.style.position="absolute";
    var W=AdMoveConfig.MoveWidth-obj.offsetWidth;
    var H=AdMoveConfig.MoveHeight-obj.offsetHeight;
    var x = W*Math.random(),y = H*Math.random();
    var rad=(Math.random()+1)*Math.PI/6;
    var kx=Math.sin(rad),ky=Math.cos(rad);
    var dirx = (Math.random()<0.5?1:-1), diry = (Math.random()<0.5?1:-1);
    var step = 1;
    var interval;
    this.SetLocation=function(vx,vy){x=vx;y=vy;}
    this.SetDirection=function(vx,vy){dirx=vx;diry=vy;}
    obj.CustomMethod=function(){
        obj.style.left = (x + AdMoveConfig.ScrollX) + "px";
        obj.style.top = (y + AdMoveConfig.ScrollY) + "px";
        rad=(Math.random()+1)*Math.PI/6;
        W=AdMoveConfig.MoveWidth-obj.offsetWidth;
        H=AdMoveConfig.MoveHeight-obj.offsetHeight;
        x = x + step*kx*dirx;
        if (x < 0){dirx = 1;x = 0;kx=Math.sin(rad);ky=Math.cos(rad);} 
        if (x > W){dirx = -1;x = W;kx=Math.sin(rad);ky=Math.cos(rad);}
        y = y + step*ky*diry;
        if (y < 0){diry = 1;y = 0;kx=Math.sin(rad);ky=Math.cos(rad);} 
        if (y > H){diry = -1;y = H;kx=Math.sin(rad);ky=Math.cos(rad);}
    }
    this.Run=function(){
        var delay = 10;
        interval=setInterval(obj.CustomMethod,delay);
        obj.onmouseover=function(){clearInterval(interval);}
        obj.onmouseout=function(){interval=setInterval(obj.CustomMethod, delay);}
    }
}
/* 漂浮广告结束 */
