﻿var $$=function(objID){return document.getElementById(objID)}

var count=0;
function loginState()
{
    var retMsg="";
    $.ajax({
        type:"GET",
        async:true,
        url:"/aspx/LogState.aspx?act=state",
        data:"",
        success:function(msg){
            retMsg = msg;
        }
    });
    return retMsg;
}

//层的显示 和 隐藏---madeby hq--------老版本
var BlockAndNone = function(objBlock,objNone,blockClass,NoneClass)//例 BlockAndNone('显示1,显示2,显示3','隐藏1,隐藏2,隐藏3')
{

	//隐藏  
	objNone=objNone.split(",");    
	for (var i=0;i<objNone.length ;i++ )    
	{    
		if($$(objNone[i]))
		{
			$$(objNone[i]).style.display="none";
            $$(objNone[i]+"1").className=NoneClass;
		}
	} 
	
    //显示
	objBlock=objBlock.split(",");     
	for (var i=0;i<objBlock.length ;i++ )    
	{
		if($$(objBlock[i]))
		{
			$$(objBlock[i]).style.display="block";
            $$(objBlock[i]+"1").className=blockClass;
		}
	} 
}
//评论列表
/*function CommentsList(objID,objPage)
{
    document.Domain = "www0.iportalcms.cn";
    $.ajax({
        type:"GET",
        async:true,
        url:"http://www0.iportalcms.cn/aspx/Commend.aspx",
        data:"p="+objPage+"&"+objID,
			success:function(msg){
        }
    });
}*/

//拖动
Array.prototype.extend=function(C){for(var B=0,A=C.length;B<A;B++){this.push(C[B]);}return this;}
function divDrag(){
	
		var A,B,$$cn;
        var zIndex=1;
        this.dragStart=function(e){
                e=e||window.event;
                if((e.which&&(e.which!=1))||(e.button&&(e.button!=1)))return;
                var pos=this.$$pos;
				$$cn=this.parent||this;
				if(document.defaultView){
					_top=document.defaultView.getComputedStyle($$cn,null).getPropertyValue("top");
					_left=document.defaultView.getComputedStyle($$cn,null).getPropertyValue("left");}
				else{
					if($$cn.currentStyle){_top=$$cn.currentStyle["top"];_left=$$cn.currentStyle["left"];}}
                pos.ox=(e.pageX||(e.clientX+document.documentElement.scrollLeft))-parseInt(_left);
                pos.oy=(e.pageY||(e.clientY+document.documentElement.scrollTop))-parseInt(_top);
				if(!!A){
					 if(document.removeEventListener){
                        document.removeEventListener("mousemove",A,false);
                        document.removeEventListener("mouseup",B,false);}
					else{
                        document.detachEvent("onmousemove",A);
                        document.detachEvent("onmouseup",B);}}
				A=this.dragMove.create(this);
                B=this.dragEnd.create(this);
                if(document.addEventListener){
					document.addEventListener("mousemove",A,false);
                    document.addEventListener("mouseup",B,false);}
				else{
					document.attachEvent("onmousemove",A);
                    document.attachEvent("onmouseup",B);}
                $$cn.style.zIndex=(++zIndex);
                this.stop(e);
        }
        this.dragMove=function(e){
				e=e||window.event;
				var pos=this.$$pos;
				$$cn=this.parent||this;
                $$cn.style.top=(e.pageY||(e.clientY+document.documentElement.scrollTop))-parseInt(pos.oy)+'px';
                $$cn.style.left=(e.pageX||(e.clientX+document.documentElement.scrollLeft))-parseInt(pos.ox)+'px';
				this.stop(e);}
        this.dragEnd=function(e){
                var pos=this.$$pos;              
                e=e||window.event;
				if((e.which&&(e.which!=1))||(e.button&&(e.button!=1)))return;
				$$cn=this.parent||this;
				if(!!(this.parent)){this.style.backgroundColor=pos.color}
                if(document.removeEventListener){
                        document.removeEventListener("mousemove",A,false);
                        document.removeEventListener("mouseup",B,false);}
				else{
                        document.detachEvent("onmousemove",A);
                        document.detachEvent("onmouseup",B);}
				A=null;
				B=null;
                $$cn.style.zIndex=(++zIndex);
                this.stop(e);
        }
		this.shiftColor=function(){
			//this.style.backgroundColor="#80b4e6";	
		}
        this.position=function (e){ 
                var t=e.offsetTop;
                var l=e.offsetLeft;
                while(e=e.offsetParent){ 
                                t+=e.offsetTop; 
                                l+=e.offsetLeft;}
                return {x:l,y:t,ox:0,oy:0,color:null}
        }
        this.stop=function(e){
                if(e.stopPropagation){e.stopPropagation();}else{e.cancelBubble=true;}
				if(e.preventDefault){e.preventDefault();}else{e.returnValue=false;}
        }
		this.stop1=function(e){
			e=e||window.event;
            if(e.stopPropagation){e.stopPropagation();}else{e.cancelBubble=true;}
		}
        this.create=function(bind){
                var B=this;
                var A=bind;
                return function(e){return B.apply(A,[e]);}
		}
        this.dragStart.create=this.create;
        this.dragMove.create=this.create;
        this.dragEnd.create=this.create;
		this.shiftColor.create=this.create;
		this.initialize=function(){
                for(var A=0,B=arguments.length;A<B;A++){
                        C=arguments[A];
						if(!(C.push)){C=[C];}
                        $$C=(typeof(C[0])=='object')?C[0]:(typeof(C[0])=='string'?$$(C[0]):null);
                        if(!$$C)continue;
                        $$C.$$pos=this.position($$C);
                        $$C.dragMove=this.dragMove;
                        $$C.dragEnd=this.dragEnd;
                        $$C.stop=this.stop;
						if(!!C[1]){$$C.parent=C[1];$$C.$$pos.color=$$C.style.backgroundColor;}
                        if($$C.addEventListener){
							$$C.addEventListener("mousedown",this.dragStart.create($$C),false);
							if(!!C[1]){$$C.addEventListener("mousedown",this.shiftColor.create($$C),false);}}
						else{$$C.attachEvent("onmousedown",this.dragStart.create($$C));
							if(!!C[1]){$$C.attachEvent("onmousedown",this.shiftColor.create($$C));}}
                }
		}
        this.initialize.apply(this,arguments);
}
//拖动 End
var getInfo=function (o){//取得坐标
        var to=new Object();
        to.left=to.right=to.top=to.bottom=0;
        var twidth=o.offsetWidth;
        var theight=o.offsetHeight;
        while(o!=document.body){
            to.left+=o.offsetLeft;
            to.top+=o.offsetTop;
            o=o.offsetParent;
        }
        to.right=to.left+twidth;
        to.bottom=to.top+theight;
        return to;
}
function showBackPage(obj,QuoteID){
    $$("QuoteID").value=QuoteID;
    var div = $$("backpage");
    if($$("backpage").style.display!="block")
    {
        $$("backpage").style.display="block";
    }
    var o = getInfo(obj);
    div.style.top = (o.bottom)+"px";
    div.style.left = (o.left-450)+"px";
    document.body.appendChild(div);
}

function SupportOrAgainst(obj,commentID,flag)
{
     $.ajax({
        type:"GET",
        async:true,
        url:"Commend.aspx?act=sora&id="+commentID+"&f="+flag,
        data:"",
        success:function(msg){
            obj.innerHTML=msg;
        }
    });
}
function CloseDiv(){$$("backpage").style.display="none";}

//js提交标点判断
var trim = function(str){return str.replace(/^\s*|\s*$/g, "");}
function frmValidate(frm)
{
	if(frm.CommentState)
	{
		if(!frm.CommentState.checked )//匿名
		{
			alert("请您登陆。");return false;
		}
	}
	if(trim(frm.backMsg.value)=="")
	{
		frm.backMsg.focus();
		alert("请输入内容。");
		return false;
	}
	if(trim(frm.ChkCode.value)=="")
	{
		frm.ChkCode.focus();
		alert("请输入验证码。");
		return false;
	}
	else
	{
		var RetChkCode = ChkCode(trim(frm.ChkCode.value))
		if(RetChkCode==-1)//验证不通过
		{
			alert("验证码输入有误。");
			return false;
		}
	}
}
//验证码是否正确判断
function ChkCode(ChkCode)
{
    var errMsg="";
     $.ajax({
        type:"GET",
        async:false,
        url:"/aspx/LogState.aspx?act=chkcode&ChkCode="+ChkCode,
        data:"",
        success:function(msg){
           errMsg = msg;
        }
    });
    return errMsg;
}
//验证码 end

function Login(userName,Password)
{
    var errMsg="";
     $.ajax({
        type:"GET",
        async:false,
        url:"/aspx/LogState.aspx?act=login&userName="+userName+"&Password="+Password,
        data:"",
        success:function(msg){
           errMsg= msg;
        }
    });
    return errMsg;
}
function UserLogin()
{
	var frm = $$("myfrm");
	if(trim(frm.username.value)=="")
	{
		//frm.username.focus();
		alert("请输入用户名。");
		return false;
	}
	if(trim(frm.password.value)=="")
	{
		//frm.password.focus();
		alert("请输入密码。");
		return false;
	}
	var RetMsg = Login(frm.username.value,frm.password.value);
	if(RetMsg.indexOf("发")!=-1)
	{
		$$("logState").innerHTML=RetMsg;
	}
	else
	{
		alert(RetMsg);
	}
}
//顶或踩
function SupportOrAgainst(obj,commentID,flag)
{
     $.ajax({
        type:"GET",
        async:true,
        url:"/aspx/Comment.aspx?act=sora&ID="+commentID+"&f="+flag,
        data:"",
        success:function(msg){
            $$(obj).innerHTML=msg;
            //alert($$(obj));
        }
    });
}
function SetHome(obj,vrl){
        try{
                obj.style.behavior='url(#default#homepage)';obj.setHomePage(vrl);
        }
        catch(e){
                if(window.netscape) {
                        try {
                                netscape.security.PrivilegeManager.enablePrivilege("UniversalXPConnect");  
                        }  
                        catch (e)  { 
                                alert("此操作被浏览器拒绝！\n请在浏览器地址栏输入“about:config”并回车\n然后将[signed.applets.codebase_principal_support]设置为'true'");  
                        }
                        var prefs = Components.classes['@mozilla.org/preferences-service;1'].getService(Components.interfaces.nsIPrefBranch);
                        prefs.setCharPref('browser.startup.homepage',vrl);
                 }
        }
}

function AddFavo(Msg)
{
    window.external.addFavorite(window.location.href,'苏州热线'+Msg);
}

//madeby hq
//图片轮换效果--Begin
var Ex=function (o){for(var k in o)this[k]=o[k];return this}
var UI=function (id){return document.getElementById(id)}
var UIs=function (tag){return Ex.call([],this.getElementsByTagName(tag))}
var Each=function (a,fn){for(var i=0;i<a.length;i++)fn.call(a[i],i,a)}
var dhooo=function (ini){
	this.bind(ini,this);
	this.autoIndex=0;
};
Ex.call(dhooo.prototype,{
	bind:function (ini,me){
		var dir=ini.dir=='top'?'scrollTop':'scrollLeft',pan=UI(ini.contentID);
		var start=function (o){
				Each(ini.btns,function(){this.className=''});
				o.className=ini.className;
				me.autoIndex=o.index;
				me.begin(o.index,pan,ini.len,dir);		
		};
		pan.onmouseover=function (){me.stop=true};
		Each(ini.btns,function (i){
			this.index=i;
			this.onmouseover=function (){me.stop=true;start(this)};
			pan.onmouseout=this.onmouseout=function(){me.stop=false}
		});
		var auto=function(){
				if(!me.stop){
					me.autoIndex=me.autoIndex==4?0:++me.autoIndex;
					start(ini.btns[me.autoIndex]);
				}
		};
		if(ini.auto)this.autoPlay=window.setInterval(auto,3000);
	}
	,begin:function (i,o,len,dir){
		(function (me){
			clearInterval(me.only);
			me.only=setInterval(function (){
				var diff=(i*len-o[dir])*0.1;
				o[dir]+=Math[diff>0?'ceil':'floor'](diff);
				if(diff==0)clearInterval(me.only);
			},10)
		})(this)
	}
})
//例1
/*new dhooo({
	btns:UIs.call(UI('myTab_btns1'),'LI')
	,className:'hot'
	,contentID:'main1'
	,len:360
});*/
//例1
/*new dhooo({
	btns:UIs.call(UI('myTab_btns2'),'LI')
	,className:'hot'
	,contentID:'main2'
	,len:190
	,dir:'top'
	,auto:true
});*/
//图片轮换效果--END


/*给每个li添加onclick事件*/
function addClick(mydiv,hot,unhot,m)
{
    if(m==undefined)
    {
        m=0;
    }
	var divID = $$(mydiv);
	var li = divID.getElementsByTagName("a");
	for(var i=0;i<li.length;i++)
	{
		(function(){
			var cur = i;
			li[i].onclick = function()
			{
				var selLi = document.getElementsByName("typeID")[m];
				li[selLi.value].className = unhot;
				li[cur].value=cur;
				li[cur].className= hot;
				selLi.value=cur;
				document.getElementsByName("type")[m].value = li[selLi.value].id;
			}
		}());
	}
}
/*END*/

/*获取点击量和 start*/
function ajaxview(id)
{
    $$("view"+id).innerHTML="1";
    $.ajax({
        type:"GET",
        async:true,
        url:"/aspx/Counting.aspx?type=1&ID="+id,
        data:"",
        success:function(msg){
            $$("view"+id).innerHTML=msg;
        }
    });
}
/*END*/
/*评论数 start*/
function ajaxcom(id)
{
    $$("com"+id).innerHTML="1";
    $.ajax({
        type:"GET",
        async:true,
        url:"/aspx/Counting.aspx?type=2&id="+id,
        data:"",
        success:function(msg){
            $$("com"+id).innerHTML=msg;
        }
    });
}
/*END*/

/*广告 start*/
function ajaxadv(AdvID)
{
//    $.getJSON(
//        "/Aspx/GetAd.aspx?id="+AdvID,
//        {},
//        function(json){        
//        for(var i=1;i<json.Count;i++)
//            {
//                $("#span"+json.IDs[i]).html(json.Contents[i]);
//            }
//         }
//        )
}
function includead(AdID)
{
    alert(AdID)  
    $("#span"+AdID).html('<!--#include file="/Template/_ad/187.shtml"-->'); 
    alert($("#span"+AdID).innerHTML+" "+AdID)    
}
/*广告End*/
var writeerr = function(id){$("span"+id).innerHTML="error!";}
function ajaxload(item,id)
{
    switch(item)
    {
       case "ad":
            //includead(id);
            //ajaxadv(id);
            CountAdID(id);
         break;
       case "com":
            if(id=="aa") 
            {
                id = $$("conid").value;
                $$("comaa").id = "com"+$$("conid").value;
            }
            ajaxcom(id);
         break;
       case "view":
            if(id=="aa") 
            {
                id = $$("conid").value;
                $$("viewaa").id = "view"+$$("conid").value;
            }
            ajaxview(id);
         break;
       case "weather":
            {
                if(id.split("|").length>1)
                    getWeather(item,id.split("|")[0],id.split("|")[1]);
                else
                    getWeather(item,id.split("|")[0],"");
            }
         break;
       case "rssread":      
            var url   = id.split("|")[0];  
            var count = id.split("|")[1];  
            var width = id.split("|")[2];
            var type  = id.split("|")[3];
            var begin = id.split("|")[4];
            var order = id.split("|")[5];
            var wid   = id.split("|")[6];
            getRssRead(url,count,width,type,begin,order,wid);
         break;
       case "train":
            var key   = id.split("|")[0];  
            var wid = id.split("|")[1];
            getStation(key,wid);
         break;
       case "validatecode":
             $("#imgVerify").attr("src","/aspx/ValidateCode.aspx"+id);
       default:
            writeerr(id);
         break;
    }
}

function CountAdID(id)
{
    count=count+","+id;
}

function ShowCountAdID()
{
    try
    {
        ajaxadv(count);
    }
    catch(err)
    {
    }
}


function getWeather(htmltag,p,typ)//%E8%8B%8F%E5%B7%9E
{
    $.ajax({
        type:"GET",
        async:true,
        url:"/aspx/plug.ashx?module=weather&p1="+p+"&p2="+typ,//%E8%8B%8F%E5%B7%9E
        data:"",
        success:function(msg){
           $$(htmltag).innerHTML=msg;
        }
    });
}


function getRssRead(url,count,width,type,begin,order,wid)
{
    $.ajax({
        type:"GET",
        async:true,
        url:"/aspx/RssReader.aspx?u="+url+"&c="+count+"&w="+width+"&b="+begin+"&o="+order+"&t="+type,
        data:"",
        success:function(msg){
           $("#rss"+wid).append(msg);
        }
    });
}

function getStation(key,id)
{
    $.ajax({
        type:"GET",
        async:true,
        url:"/aspx/Train/Ajax.aspx?key="+key,
        data:"",
        success:function(msg){
           $$("showstation"+id).innerHTML=msg;
        }
    });
}


//*评论链接**/
function addcomment(obj)
{
    //obj.href="http://www.baidu.com";///comment/{$:Content.ContentID}-0.shtml
    var ID = $$("ID").value;
    obj.href="/comment/"+ID+"-0.shtml";
}

//层切换 New
function Toggles(btn,info,hot,ice)
{
	var btncell  = $$(btn.split(',')[0]).getElementsByTagName(btn.split(',')[1]);
	var infocell = $$(info.split(',')[0]).getElementsByTagName(info.split(',')[1]);
	for(var i=0;i<btncell.length;i++)
	{
		(function(){
			var cur = i;
			btncell[i].onmouseover = function()
			{
				for(var j=0;j<btncell.length;j++)
				{
					btncell[j].className= ice;
					infocell[j].style.display ="none";
				}
				btncell[cur].className= hot;
				infocell[cur].style.display ="block";
			}
		}());
	}
}


//层切换 New1
function Toggles1(btn,info,hot,ice,plusdiv)
{
	var btncell  = $$(btn.split(',')[0]) .getElementsByTagName(btn.split(',')[1]);
	var infocell = $$(info.split(',')[0]).getElementsByTagName(info.split(',')[1]);
	var pluscell = $$(plusdiv.split(',')[0]).getElementsByTagName(plusdiv.split(',')[1]);
	for(var i=0;i<btncell.length;i++)
	{
		(function(){
			var cur = i;
			btncell[i].onmouseover = function()
			{
				for(var j=0;j<btncell.length;j++)
				{
					btncell[j].className= ice;
					infocell[j].style.display ="none";
					pluscell[j].style.display ="none";
				}
				btncell[cur].className= hot;
				infocell[cur].style.display ="block";
				pluscell[cur].style.display ="block";
			}
		}());
	}
}

//例：：  Toggles("btn,li","info,li","hot","")
function setCookie(name,value) 
{
   var today = new Date();
   var expires = new Date();
   expires.setTime(today.getTime() + 1000*60*60*24*365);
   document.cookie = name + "=" + escape(value) + "; expires=" + expires.toGMTString()+";path=/";
}

function getCookie(Name) 
{
   var search = Name + "=";
   if(document.cookie.length > 0) {
      offset = document.cookie.indexOf(search);
      if(offset != -1) {
         offset += search.length;
         end = document.cookie.indexOf(";", offset);
         if(end == -1) end = document.cookie.length;
         return unescape(document.cookie.substring(offset, end));
      }
      else return('');
   }
   else return('');
}




/*调整图片大小*/
function ImgManage(ID,MaxWidth,MaxHeight)
{
    var hyctaga = $("#"+ID+" > img");
    for(var i=0;i<hyctaga.length;i++)
    {
        reSize(hyctaga[i],MaxWidth,MaxHeight);
    }
}     


function reSize(myImg, maxWidth, maxHeight)
{
    var iniPicWidth = myImg.width;
    var iniPicHeight = myImg.height;
    var iniRate = iniPicHeight/iniPicWidth;

    if(iniPicWidth>maxWidth || iniPicHeight>maxHeight)
    {
        var newW = maxWidth;
        var newH = Math.floor(newW*iniRate);
        if (newH>maxHeight)
        {
            var newH = maxHeight;
            var newW = Math.floor(newH/iniRate);
        }
            myImg.width = newW;
            myImg.height = newH;
    }
}
