jQuery.fn.slider = function(sleep){
    var divs = $(this).find("div");
    var divs_p = $(this).find("div p");
    var setTime = null;
    for (var i=0; i<divs.length; i++)
    {
        divs.eq(i).css("left",i*33+"px");
        divs_p.eq(i).fadeOut(400);
        divs.eq(i).data("index",i);
        divs.eq(i).mouseover(function(){
            clearInterval(setTime);
            setLeft($(this).data("index"));
            clearInterval(setTime);
        });
        divs.eq(i).mouseout(function(element){
            var index = $(this).data("index")+1;
            setTime = setTimeout(function(){ setLeft(index) },sleep);
        });
    }
    setLeft(0);
            
    function setLeft(elenemt)
    {
        for (var i=0; i<divs.length; i++)
        {
            divs.eq(i).stop(true);
            divs_p.eq(i).stop(true);
            if (elenemt > i){
                if (parseInt(divs.eq(i).css("left")) > i*33)  divs.eq(i).animate({ left: i*33+'px'},400);
            }
            else if(elenemt < i){
                if (parseInt(divs.eq(i).css("left")) < i*33+208) divs.eq(i).animate({ left: i*33+208+'px'},400);
            }
            else if(elenemt == i){
                divs.eq(i).animate({ left: (i*33)+'px'},400);
                //divs_p.eq(i).fadeOut(0);
                divs_p.eq(i).fadeIn(500);
            }
        }
        elenemt++;
        if (elenemt >= 5) elenemt=0;
        setTime = setTimeout(function(){ setLeft(elenemt) },sleep);
    }
}

jQuery.fn.Server = function(sleep){
    var btnlist =  $(this).find("a");
    var setT = null;
    var PcdetaiText = [
    "<h1><b>M3-</b>M享主机新贵登场</h1><p>· 支持.net，SQL Server2000(Win2003)</p><p>· 支持PHP4/5切换,MySQL5(UNIX)</p><p>· 300M网页空间，50M数据库空间</p><p>· 月流量30G</p><p>· 3G邮箱空间</p><font><b>1280 </b>元/年</font>",
    "<h1><b>G1-</b>G享主机倾情奉献</h1><p>· Windows2008+IIS7</p><p>· 1G独立网页空间，3G邮箱空间</p><p>· 支持.net1.0\2.0\3.5，支持PHP4\5切换</p><p>· SQL Server2005数据库300M</p><p>· MySQL5数据库300M</p><font><b>1980 </b>元/年</font>",
    "<h1><b>J1-</b>J享主机上品之作</h1><p>· 2G网页空间，800M数据库空间，5G邮箱</p><p>· 支持Tomcat5.5/6.0，支持JDK1.5/1.6</p><p>· 独享Tomcat</p><p>· 支持PHP4/5切换，支持MYSQL5.0</p><font><b>3280 </b>元/年</font>"
    ];
    for (var i=0;i<btnlist.length; i++)
    {
        btnlist.eq(i).data("index",i);
        btnlist.eq(i).mouseover(function() {
            clearTimeout(setT);
            if (parseInt($("#PC_img").css("background-position-y")) != parseInt("-"+$(this).data("index")*191)) {
                Onnext($(this).data("index"));
                clearTimeout(setT);
            }
        });
        
        btnlist.eq(i).mouseout(function(){
            clearTimeout(setT);
            var thisi = $(this).data("index")+1;
            $("#PC_img").data("index",thisi);
            setT = setTimeout(function(){Onnext(thisi)},sleep);
        });
    }
    setT = setTimeout(function(){Onnext(1)},sleep);
    
    $("#PC_img").mouseover(function(){
        clearTimeout(setT);
    });
    $("#PC_img").mouseout(function(){
        setT = setTimeout(function(){Onnext($("#PC_img").data("index"))},sleep);
    });
    
    $("#pcdetail").mouseover(function(){
        clearTimeout(setT);
    });
    $("#pcdetail").mouseout(function(){
        setT = setTimeout(function(){Onnext($("#PC_img").data("index"))},sleep);
    });
    
    function Onnext(ix){
        if (ix>=3) ix=0;
        $("#PC_img").stop(true);
        if (document.all)
            $("#PC_img").animate({ backgroundPositionY: '-'+ix*191+'px'},500, function(){setDetail(ix)});
        else
            $("#PC_img").animate({ backgroundPosition: '0px -'+ix*191+'px'},500, function(){setDetail(ix)});
        
        var ii = ix+1;
        if (ii>=3) ii=0;
        setT = setTimeout(function(){Onnext(ii)},sleep);
    }
    
    function setDetail(si){
        $("#pcdetail").html(PcdetaiText[si]);
        $("#pcdetail *").fadeOut(0);
        $("#pcdetail *").fadeIn(500);
    }
}

jQuery.fn.checkhos = function(){
    var thisElt = $(this);
    thisElt.find(":radio").eq(0).click(function(){
        setBox(true);
    });
    thisElt.find(":radio").eq(1).click(function(){
        setBox(false);
    });
    thisElt.find("#GotoCheck").click(function(){
        var Domain = thisElt.find("#hosName").val();
        checkDomain(Domain);
    });
    
    function checkDomain(Domain)
    {
        if(Trim(Domain) == "")
	    {
    	    alert("请输入要查询的域名！");
		    return false;
	    }
	    else if (Domain.length > 60)
	    {
		    alert("请不要输入超过60个字符！");
		    return false;		
	    } 
	    
	    if(IsChDomain(Domain))
		{
		    if (thisElt.find(":radio").eq(0).attr("checked"))
		    {
		        alert('请输入英文或数字');
		        return false;
		    }
		}
		if(IsEnDomain(Domain))
	    {
	        if (thisElt.find(":radio").eq(1).attr("checked"))
		    {
		        alert('请输入中文');
		        return false;
		    }
	    }
	    
        for (var i=0;i<=Domain.length-1;i++)
        {
	        aa=Domain.charAt(i);
	        if (aa==' ')
	        {
		        alert("域名不能有空格！");
		        return false;
	        }else if (aa=='.')
	        {
		        alert("不能直接输入带后缀的域名,只要输入想注册域名的名称即可查询！");
		        return false;
	        }
        }
        window.location = "CheckDomain.aspx?Domain="+Domain+"&Suffix="+getcom();
    }
    
    function getcom(){
        var boxlist = thisElt.find(":checkbox");
        var resultStr = "";
        for (var i=0; i<boxlist.length;i++)
        {
            if (boxlist.eq(i).attr("checked"))
            {
                if (resultStr != "") resultStr+="|";
                resultStr += boxlist.eq(i).val();
            }
        }
        return resultStr;
    }
    
    function IsChDomain(argString)
	{
		var flag=false;
		var compStr="ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz-1234567890";
		var length1=argString.length;
		for(var chrIndex=0;chrIndex<length1;chrIndex++)
			{
				var temp=argString.charCodeAt(chrIndex)
				if(temp>=10000) 
					flag=true;
				else
				{
					var temp1=compStr.indexOf(argString.charAt(chrIndex));
					if(temp1==-1)
					{
						flag=false;
						break;							
					}
				}
			}
		return flag;
	}

    function IsEnDomain(argValue) 
	{
		var flag1=false;
		var compStr="ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz-.1234567890";
		var length2=argValue.length;
		for (var iIndex=0;iIndex<length2;iIndex++)
			{
				var temp1=compStr.indexOf(argValue.charAt(iIndex));
				if(temp1==-1) 
					{
						flag1=false;
						break;							
					}
				else
					{
						flag1=true;
					}
			}
		return flag1;
	}
	
	function Trim(info)
    {
        return info.replace(/(^\s*)|(\s*$)/g, "");
    }

    function setBox(bool){
       thisElt.find(":checkbox[value='cn']").attr("checked", bool);
       thisElt.find(":checkbox[value='com.cn']").attr("checked", bool);
       
       thisElt.find(":checkbox[value='公司']").attr("checked", !bool);
       thisElt.find(":checkbox[value='网络']").attr("checked", !bool);
       thisElt.find(":checkbox[value='中国']").attr("checked", !bool);
       
       thisElt.find(":checkbox[value='公司']").attr("disabled", bool);
       thisElt.find(":checkbox[value='网络']").attr("disabled", bool);
       thisElt.find(":checkbox[value='中国']").attr("disabled", bool);
       
       thisElt.find(":checkbox[value='cn']").attr("disabled", !bool);
       thisElt.find(":checkbox[value='mobi']").attr("disabled", !bool);
       thisElt.find(":checkbox[value='tel']").attr("disabled", !bool);
       thisElt.find(":checkbox[value='asia']").attr("disabled", !bool);
       thisElt.find(":checkbox[value='org']").attr("disabled", !bool);
       thisElt.find(":checkbox[value='name']").attr("disabled", !bool);
       thisElt.find(":checkbox[value='me']").attr("disabled", !bool);
       thisElt.find(":checkbox[value='com.cn']").attr("disabled", !bool);
       thisElt.find(":checkbox[value='net.cn']").attr("disabled", !bool);
       thisElt.find(":checkbox[value='org.cn']").attr("disabled", !bool);
       thisElt.find(":checkbox[value='gov.cn']").attr("disabled", !bool);
       thisElt.find(":checkbox[value='info']").attr("disabled", !bool);
    }
}

$(function(){
    $("#server_ul").slider(8000);
    $("#PC_btnlist").Server(5000)
    $(".where-3w").checkhos();
});