﻿//var online=new Array();
var apache=0;
var intWnd=null;
var bInit=false;
var showad = true;
var Toppx = 60;			//上端位置
var AdDivW = 80;		//宽度
var AdDivH = 240;		//高度
var PageWidth = 800;	//页面多少宽度象素下正好不出现左右滚动条
var MinScreenW = 1024;	//显示广告的最小屏幕宽度象素

var ClosebuttonHtml = '<div align="right" style="position: absolute;top:0px;right:0px;margin:2px;padding:2px;z-index:2000;"><a href="javascript:;" onclick="hidead()" style="color:red;text-decoration:none;font-size:12px;">关闭</a></div>'
var AdContentHtmlLeft = '<div align="center" style="color:green;font-size:23pt;font-family:黑体;"><img src="/images/ad.gif" /></div>';
var AdContentHtmlRight = '<div align="center" style="color:green;font-size:23pt;font-family:黑体;"><img src="/images/ad.gif" /></div>';
        
if (!document.layers)
document.write('<div id=divStayTopLeft style="position:absolute;">');
//document.write('<script src="http://webpresence.qq.com/getonline?Type=1&592726946:517760295:156238827:"></script>');
document.write('<table cellSpacing="0" cellPadding="0" width="110" border="0" id="qqtab">');
document.write('    <tr>');
document.write('      <td width="110" onclick="if(document.all.qqtab.style.display==\'none\'){document.all.qqtab.style.display=\'\'} else {document.all.qqtab.style.display=\'none\'}"><img src="images/top.gif" border="0"></td>');
document.write('    </tr>');
document.write('    <tr id="qqstab">');
document.write('      <td valign="middle" align="center" background="images/middle.gif">');
document.write('<table border="0" width="90" cellSpacing="0" cellPadding="0">');
document.write('  <tr>');
document.write('    <td width="90" height="5" border="0" colspan="2"></td>');
document.write('  </tr>');
document.write('  <tr>');
    document.write('    <td width="25" height="29" valign="middle" align="center">');
    document.write('<img src="http://wpa.qq.com/pa?p=1:156238827:4" border="0" hspace="3">');
    document.write('    </td>');
    document.write('    <td width="65" height="29" valign="middle" align="left">');
    document.write('<a href="http://wpa.qq.com/msgrd?V=1&Uin=156238827&Site=www.kingtennis.com&Menu=no" target="blank"><font style="font-size:12px;TEXT-DECORATION:none;color:#000000;">华景余教练</font></a><br>');
    document.write('    </td>');
document.write('  </tr>');
document.write('  <tr>');
    document.write('    <td width="25" height="29" valign="middle" align="center">');
    document.write('<img src="http://wpa.qq.com/pa?p=1:592726946:4" border="0" hspace="3">');
    document.write('    </td>');
    document.write('    <td width="65" height="29" valign="middle" align="left">');
    document.write('<a href="http://wpa.qq.com/msgrd?V=1&Uin=592726946&Site=www.kingtennis.com&Menu=no" target="blank"><font style="font-size:12px;TEXT-DECORATION:none;color:#000000;">总部小美</font></a><br>');
    document.write('    </td>');
document.write('  </tr>');

document.write('  <tr>');
    document.write('    <td width="25" height="29" valign="middle" align="center">');
    document.write('<img src="http://wpa.qq.com/pa?p=1:504864092:4" border="0" hspace="3">');
    document.write('    </td>');
    document.write('    <td width="65" height="29" valign="middle" align="left">');
    document.write('<a href="http://wpa.qq.com/msgrd?V=1&Uin=504864092&Site=www.kingtennis.com&Menu=no" target="blank"><font style="font-size:12px;TEXT-DECORATION:none;color:#000000;">马场谢教练</font></a><br>');
    document.write('    </td>');
document.write('  </tr>');

document.write('  <tr>');
document.write('<td> </td>');
document.write('  </tr>');

document.write('</table>');
document.write('</td>');
document.write('    </tr>');
document.write('    <tr>');
document.write('<td width="110"><a href="javascript:void(0)" onclick="loadMessage()"><img src="images/bottom.gif" border="0"></a></td>');
document.write('    </tr>');
document.write('</table>');
var verticalpos="frombottom"
if (!document.layers)
document.write('</div>')
function scrollqq()
{
  var posXqq,posYqq;
 if (window.innerHeight)
 {
  posXqq=window.pageXOffset;
  posYqq=window.pageYOffset;
   }
   else if (document.documentElement && document.documentElement.scrollTop)
      {
    posXqq=document.documentElement.scrollLeft;
    posYqq=document.documentElement.scrollTop;
    }
    else if (document.body)
      {
    posXqq=(document.body.scrollLeft==0?document.documentElement.scrollLeft:document.body.scrollLeft);
    posYqq=(document.body.scrollTop==0?document.documentElement.scrollTop:document.body.scrollTop);
      }
     var divStayTopLeft=document.getElementById("divStayTopLeft");
    divStayTopLeft.style.top=(posYqq+450)+"px";
  divStayTopLeft.style.left=(posXqq+screen.width-181)+"px";
  setTimeout("scrollqq()",500);
    }
      scrollqq();
      
      
function createMessageDiv(){
    var oFrame=document.createElement("<iframe id=\"bgframe\" width=\"100%\" height=\"100%\" src=\"about:blank\" frameborder=\"0\" style=\"z-index:1000; width:678px; height:384px; position:absolute;top: 72px;left: 88px;\"></iframe>");
    
    oFrame.style.display="none";
    
    document.body.appendChild(oFrame);
    

    var oDiv=document.createElement("<form id=\"formmessage\" onsubmit=\"return addNewMessage(this);\"></form>");
    
    oDiv.innerHTML="<div id=\"message\"><div id=\"title\"><a href=\"javascript:void(0)\" onclick=\"closeMessage()\"><span style=\"font-family:Marlett; font-size:14px\">r</span></a></div><div id=\"form\"><div id=\"forms\"><div id=\"formline\"><div id=\"caption\">主题：</div><div id=\"formitem\"><input type=\"text\" name=\"title\" style=\"width:298px; border:1px solid #666666; height:18px; padding-left:2px; padding-top:2px; font-weight:bold\" onfocus=\"this.style.background='#fcffe6'; this.style.border='1px solid #088310'\" onblur=\"this.style.background=''; this.style.border='1px solid #888888'\" />&nbsp;<select id=\"msgtype\" name=\"msgtype\" style=\"width:100px\"><option value=\"球约\">球约</option><option value=\"产品\">产品</option><option value=\"课程\">课程</option><option value=\"比赛\">比赛</option><option value=\"其它\">其它</option></select></div></div><div id=\"formline\"><div id=\"caption\">电话：</div><div id=\"formitem\"><input type=\"text\" name=\"phone\" id=\"phone\" style=\"width:152px; border:1px solid #666666; height:18px; padding-left:2px; padding-top:2px; font-weight:bold\" onfocus=\"this.style.background='#fcffe6'; this.style.border='1px solid #088310'\" onblur=\"this.style.background=''; this.style.border='1px solid #888888'\" /></div></div><div id=\"formline\"><div id=\"caption\">邮箱：</div><div id=\"formitem\"><input type=\"text\" name=\"email\" id=\"email\" style=\"width:157px; border:1px solid #666666; height:18px; padding-left:2px; padding-top:2px; font-weight:bold\" onfocus=\"this.style.background='#fcffe6'; this.style.border='1px solid #088310'\" onblur=\"this.style.background=''; this.style.border='1px solid #888888'\" /></div></div><div id=\"formline\"><div id=\"caption\">内容：</div><div id=\"formitem\"><textarea name=\"content\"  style=\"width: 398px; height: 199px; border:1px solid #666666;\" onfocus=\"this.style.background='#fcffe6'; this.style.border='1px solid #088310'\" onblur=\"this.style.background=''; this.style.border='1px solid #888888'\"></textarea></div></div></div><div id=\"control\"><div id=\"infoline\">请填写主题以及留言类型！</div><div id=\"intro\">欢迎您访问本公司网站，如果您有任何意见或建议，请在这里填写，您的提议将是我们最为宝贵的财富，再次感谢您的支持！</div><div id=\"buttongroup\"><input type=\"submit\" value=\"\" style=\"border-style: none; border-color: inherit; border-width: medium; background: url('images/btn_submit.gif') no-repeat left top; width: 133px; height: 47px; \" /><br /></div></div></div></div>";
    
    oDiv.style.display="none";
    
    document.body.appendChild(oDiv);
}

function showPopup(){
    createMessageDiv();
    
    var oFrame = document.getElementById("bgframe");
    var oDiv=document.getElementById("message");
    var oForm=document.getElementById("formmessage");
        
    if(undefined != oForm){
        oForm.style.display="block";
    }
    
    if(undefined==oDiv){
        return;
    }
        
    var w=oDiv.offsetWidth;
    var h=oDiv.offsetHeight;
    
    var pl=parseInt((document.documentElement.clientWidth == 0) ? document.body.clientWidth : document.documentElement.clientWidth);
    var pt=parseInt((document.documentElement.clientHeight == 0) ? document.body.clientHeight : document.documentElement.clientHeight);
    var st=parseInt((document.documentElement.scrollTop == 0)?document.body.scrollTop:document.documentElement.scrollTop);
    
    oFrame.style.left =String((pl-w)/2) + "px";
    oFrame.style.top = String((pt-h)/2 + st) + "px";
    oDiv.style.left =String((pl-w)/2) + "px";
    oDiv.style.top = String((pt-h)/2 + st) + "px";
    
    bInit=true;
}

function changeApache(){
    apache+=10;
    
    var oDiv=document.getElementById("message");
    
    if(oDiv.style.display!=""){
        oDiv.style.display="";
    }
    
    oDiv.style.filter="alpha(opacity="+ apache +")";
    
    if(apache>=100){
        clearInterval(intWnd);
        apache=100;
    }
}

function hidelayer(){
    var oDiv=document.getElementById("message");
    
    apache-=10;
    
    if(apache<=0){
        clearInterval(intWnd);
        apache=0;
        
        var oForm=document.getElementById("formmessage");
        var oFrame = document.getElementById("bgframe");
        
        if(undefined != oFrame){
            oFrame.style.display="none";
            oFrame.removeNode(true);
        }
        
        if(undefined != oForm){
            oForm.style.display="none";
            oForm.removeNode(true);
        }
        
        if(oDiv.style.display!="none"){
            oDiv.style.display="none";
            oDiv.removeNode(true);
        }
        
        return;
    }
    
    oDiv.style.filter="alpha(opacity="+ apache +")";            
}

function loadMessage(){
    //if(!bInit){
        showPopup();
    //}
    
    var oFrame = document.getElementById("bgframe");
    
    if(undefined == oFrame){
        return;
    }else{
        oFrame.style.display="block";
    }
    
    var oForm=document.getElementById("formmessage");
    if(undefined != oForm){
        oForm.style.display="block";
    }
    
    intWnd = setInterval("changeApache()",1);
}

function closeMessage(){
    clearInterval(intWnd);            
    intWnd = setInterval("hidelayer()",1);
}

function postData(fun,args){
    var xmlObj=new ActiveXObject("MSXML2.XMLHttp");
	
    xmlObj.open("post","ajax.asmx/" + fun,false);
    xmlObj.setRequestHeader("Content-Length",args.length);
    xmlObj.setRequestHeader("Cache-Control","no-cache");
    xmlObj.setRequestHeader("Content-Type","application/x-www-form-urlencoded");
    xmlObj.send(encodeURI(args));
	
    return xmlObj.responseText;
}

function checkPhoneNumber(value){
    var f="0123456789-";
    
    if(value==""){
        return false;
    }
    
    if(value.length<10 || value.length>12){
        return false;
    }
    
    for(var i=0;i<value.length;i++){
        var mstr=value.substring(i,i+1);
        
        var ipos=f.indexOf(mstr);
        
        if(ipos==-1){
            return false;
        }
    }
    
    if(checkRepeat(value,"-")>1){
        return false;
    }else{
        return true;
    }
}

function checkRepeat(value,chr){
    if(value==""){
        return false;
    }
    
    var nc=0;
    
    for(var i=0;i<value.length;i++){
        var mstr=value.substring(i,i+1);
        
        if(mstr==chr){
            nc++;
        }
    }
    
    return nc;
}

function checkEmail(value){
    if(value.indexOf("@")<=0){
        return false;
    }
    
    if(value.indexOf(".")<=2){
        return false;
    }
    
    return true;
}

function addNewMessage(obj){
    var title=obj.title.value;
    var phone=obj.phone.value;
    var email=obj.email.value;
    var content=obj.content.value;
    var msgtype=obj.msgtype.value;
    
    if(title=="" || phone=="" || email=="" || content==""){
        alert("请填写完整的留言信息！");
        return false;
    }
    
    if(!checkPhoneNumber(phone)){
        alert("请填写正确的电话号码，且该电话号码必须是由10-12位数字组城！");
        return false;
    }
    
    if(!checkEmail(email)){
        alert("请填写一个有效的电子邮箱！");
        return false;
    }
    
    try{
        var xml=postData("addNewMessage","title=" + title + "&phone=" + phone + "&email=" + email + "&content=" + content + "&url=" + location.pathname + "&msgtype=" + msgtype);
	    var doc = new ActiveXObject("Msxml2.DOMDocument"); 
	    doc.loadXML(xml);
	    var n=doc.getElementsByTagName("boolean")[0];
		
	    if(n.text=="false"){
	        alert("提交留言失败，请稍后再试！");
	    }else{
	        alert("提交留言成功，感谢您的支持！");
	    }
    }catch(e){
	    return "连接服务器失败，请稍后再试！";
    }
    
    closeMessage();
    return false;
}

function InitLayer(){
    createMessageDiv();
    scall();
}

document.onkeypress=function(){
    if(event.keyCode==27){
        closeMessage();
    }
}

document.write ('<div id="Javascript.LeftDiv" style="position: absolute;border: 1px solid #336699;background-color:#EEEEE2;z-index:1000;width:'+AdDivW+'px;height:'+AdDivH+'px;top:-1000px;word-break:break-all;display:none;">'+ClosebuttonHtml+'<div>'+AdContentHtmlLeft + '</div></div>');
document.write ('<div id="Javascript.RightDiv" style="position: absolute;border: 1px solid #336699;background-color:#EEEEE2;z-index:1000;width:'+AdDivW+'px;height:'+AdDivH+'px;top:-1000px;word-break:break-all;display:none;">'+ClosebuttonHtml+'<div>'+AdContentHtmlRight + '</div></div>');
function scall(){
	if(!showad){return;}
	if (window.screen.width<MinScreenW){
		showad = false;
		document.getElementById("Javascript.LeftDiv").style.display="none";
		document.getElementById("Javascript.RightDiv").style.display="none";
		return;
	}
	
	var pl=parseInt((document.documentElement.clientWidth == 0) ? document.body.clientWidth : document.documentElement.clientWidth);
    var pt=parseInt((document.documentElement.clientHeight == 0) ? document.body.clientHeight : document.documentElement.clientHeight);
    var st=parseInt((document.documentElement.scrollTop == 0)?document.body.scrollTop:document.documentElement.scrollTop);
    var sl=parseInt((document.documentElement.scrollLeft == 0)?document.body.scrollLeft:document.documentElement.scrollLeft);
	
	var Borderpx = ((window.screen.width-PageWidth)/2-AdDivW)/2;

	document.getElementById("Javascript.LeftDiv").style.display="";
	document.getElementById("Javascript.LeftDiv").style.top=st + Toppx;
	document.getElementById("Javascript.LeftDiv").style.left=sl + Borderpx;
	document.getElementById("Javascript.RightDiv").style.display="";
	document.getElementById("Javascript.RightDiv").style.top=st + Toppx;
	document.getElementById("Javascript.RightDiv").style.left=pl-document.getElementById("Javascript.RightDiv").offsetWidth-Borderpx;
}

function hidead()
{
	showad = false;
	document.getElementById("Javascript.LeftDiv").style.display="none";
	document.getElementById("Javascript.RightDiv").style.display="none";
}
window.onscroll=scall;
window.onresize=scall;
window.onload=InitLayer;
