﻿
//图片按比例缩放
function DrawImage(ImgD,iwidth,iheight){
//参数(图片,允许的宽度,允许的高度)
    var image=new Image();
    image.src=ImgD.src;
    if(image.width>0 && image.height>0){
        if(image.width/image.height>=iwidth/iheight){
            if(image.width>iwidth){  
                ImgD.width=iwidth;
                ImgD.height=(image.height*iwidth)/image.width;
            }else{
                ImgD.width=image.width;  
                ImgD.height=image.height;
            }
            ImgD.alt=image.width+"×"+image.height;
        }else{
            if(image.height>iheight){  
                ImgD.height=iheight;
                ImgD.width=(image.width*iheight)/image.height;        
            }else{
                ImgD.width=image.width;  
                ImgD.height=image.height;
            }
            ImgD.alt=image.width+"×"+image.height;
        }
    }
}

function ShowToday() {
	var day="";
	var month="";
	var ampm="";
	var ampmhour="";
	var myweekday="";
	var year="";
	mydate=new Date();
	myweekday=mydate.getDay();
	mymonth=mydate.getMonth()+1;
	myday= mydate.getDate();
	myyear= mydate.getYear();
	year=(myyear > 200) ? myyear : 1900 + myyear;
	if(myweekday == 0)
	weekday=" 星期日 ";
	else if(myweekday == 1)
	weekday=" 星期一 ";
	else if(myweekday == 2)
	weekday=" 星期二 ";
	else if(myweekday == 3)
	weekday=" 星期三 ";
	else if(myweekday == 4)
	weekday=" 星期四 ";
	else if(myweekday == 5)
	weekday=" 星期五 ";
	else if(myweekday == 6)
	weekday=" 星期六 ";
	document.write(year+"年"+mymonth+"月"+myday+"日 "+weekday);
}

function ShowTimes(obj,time){
    var AfterTime= new Date(time);
    LeaveTime = AfterTime - new Date();
    LeaveDays=Math.floor(LeaveTime/(1000*60*60*24));//天
    LeaveHours=Math.floor(LeaveTime/(1000*60*60)%24);//时
    LeaveMinutes=Math.floor(LeaveTime/(1000*60)%60);//分
    LeaveSeconds=Math.floor(LeaveTime/1000%60);//秒
    obj.innerHTML=LeaveDays+"天"+LeaveHours+"时"+LeaveMinutes+"分"+LeaveSeconds+"秒";
}

function search4() {
	var form=document.getElementById("websearch");
    if(form.google.checked)
    window.open("http://www.google.com/search?hl=zh-CN&inlang=zh-CN&ie=GB2312&oe=GB2312&q="+form.search_key.value,"mspg6");
    if(form.baidu.checked)
    window.open("http://www.baidu.com/baidu?tn=verywind&word="+form.search_key.value,"mspg9");
    if(form.sina.checked)
    window.open("http://search.sina.com.cn/cgi-bin/search/search.cgi?_searchkey="+form.search_key.value,"mspg0"); 
    if(form.yahoo.checked)
    window.open("http://www.yisou.com/search?p="+form.search_key.value,"mspg2");
    return false;   
}

function checkValue(obj) {
    if(obj.className.indexOf("gray")>0) {
        obj.value='';
        obj.className=obj.className.replace("gray","");
    }
}

function submitForm(obj) {
    var key=obj.form.search_key;
    if(key.value=='' || key.className.indexOf("gray")>0){
        alert("请输入要搜索的关键字");
	    key.focus();
	    return false;
    }else {
        obj.form.action+="&key="+key.value;
        obj.form.submit();
    }
}


function CleanWhitespace(element){
    //element = document.getElementById(element);
    for (var i= 0; i < element.childNodes.length; i++) {
        var node = element.childNodes[i];
        var s=/\S/;
        if(node.nodeType == 3)
            element.removeChild(node);
    }
}

function ScrollLeft(obj,speed){
    var step=2;
    if (obj.offsetLeft!=-obj.offsetWidth) {
        obj.style.marginLeft=(obj.offsetLeft-step)+"px";
    }else {
        obj.style.marginLeft=obj.parentNode.offsetWidth+"px";
    }
    window.setTimeout(function(){ScrollLeft(obj,speed);},speed);
}

function Marquee(divId,speed) {
    var txtDiv=document.getElementById(divId);
    var moveDiv=txtDiv.cloneNode(true);
    txtDiv.innerHTML="";
    txtDiv.appendChild(moveDiv);
    moveDiv.style.position = "relative";
    moveDiv.style.width="auto";
    ScrollLeft(moveDiv,speed);
}


function marquee2(mqdivid,lh,speed,delay){ 
    var t; 
    var p=false; 
    var o=document.getElementById(mqdivid); 
    o.innerHTML+=o.innerHTML; 
    o.onmouseover=function(){p=true} 
    o.onmouseout=function(){p=false} 
    o.scrollTop = 0; 
    function start(){ 
        t=setInterval(scrolling,speed); 
        if(!p) o.scrollTop += 2; 
    } 
    function scrolling(){ 
        if(o.scrollTop%lh!=0){ 
            o.scrollTop += 2; 
            if(o.scrollTop>=o.scrollHeight/2) o.scrollTop = 0; 
        }else{ 
            clearInterval(t); 
            setTimeout(start,delay); 
        } 
    } 
    setTimeout(start,delay); 
} 
//startmarquee('mq',17,50,3000); 
/**startmarquee(div,一次滚动高度,速度,停留时间);**/
 
 $(document).ready(function(){
$("a[rel='external']").attr("target","_blank");
$(".tab dt").children("a").bind("mousemove",function(){SwitchTab($(this))});
    ScrollTab($("#rss_news"),5000);
    
	function SwitchTab($obj){
	    var $dd=$obj.parent().siblings("dd").eq($obj.prevAll("a").length);
		$obj.addClass("curr").siblings("a.curr").removeClass("curr");
		$dd.show().siblings("dd").hide();
	};
	function ScrollTab($tab,speed){
        $tab.each(function(){
            var $obj=$(this);
            var mr=window.setInterval(function(){Scrolling($obj);},speed);
            $obj.hover(function(){clearInterval(mr)},function(){mr=setInterval(function(){Scrolling($obj);},speed)});
            window.setTimeout(function(){Scrolling($obj);},speed);
        });
	    function Scrolling($obj){
	        var $a=$obj.find("dl dt a.curr");
	        SwitchTab($a.next("a").length>0?$a.next("a"):$a.prevAll("a:last"));
	    };
	};
});
