﻿  //搜索       
  $(function(){
            String.prototype.trim=function(){var reExtraSpace = /^\s*(.*?)\s+$/; return this.replace(reExtraSpace,"$1").replace(/</,"&lt;").replace(/>/,"&gt;");};
            $("#inputtxt").keydown(function(event){
               switch(event.keyCode)
               {
                case 13: Search();return;
               }
            });
            $("#imgSearch").click(function(){
                Search();
            });
        });
        function Search()
        {
                var sKey =$("#inputtxt").val();
                sKey=sKey.trim();
                if(sKey.length==0)
                {
                    alert("搜索关键字不能为空！");
                }
                else
                {
                  var url = window.location.href.toLowerCase();
//                  var     reg     =   new   RegExp("search.aspx");      
//                  var     r     =     url.match(reg);
                  var reg = /search.aspx/;
                  var result =  reg.exec(url);
                  if(result!=null)
                  {
                  linkurl("../cn/search.aspx?key="+escape(sKey));
                  }
                  else
                  {
                    window.open("../cn/search.aspx?key="+escape(sKey));
                  }
                }
        }
          function   linkurl(url){  
      newLink.href=url;  
      newLink.click();  
  }  
        
//图片等比例缩放
function DrawImage(objImg,maxWidth,maxHeight){ 
        var img = new Image(); 
            img.src = objImg.src; 
        var hRatio; 
        var wRatio; 
        var Ratio = 1; 
        var w = img.width; 
        var h = img.height; 
            wRatio = maxWidth / w; 
            hRatio = maxHeight / h; 
        if(maxWidth ==0 && maxHeight==0)
        { 
            Ratio = 1; 
        }
        else if(maxWidth==0)
        { 
              if (hRatio<1) 
                 Ratio = hRatio; 
        }
        else if (maxHeight==0)
        { 
            if (wRatio<1) 
                Ratio = wRatio; 
        }
        else if (wRatio<1 || hRatio<1)
        { 
            Ratio = (wRatio<=hRatio?wRatio:hRatio); 
        } 
        if (Ratio<1)
        { 
            w = w * Ratio; 
            h = h * Ratio; 
        } 
        
        objImg.height = h; 
        objImg.width = w;

        if(h<=maxHeight)
        {
                  objImg.style.paddingTop=(maxHeight-h)/2;
                  objImg.style.paddingBottom=(maxHeight-h)/2;
        }
        if(w<=maxWidth)
        {
                objImg.style.paddingLeft=(maxWidth-w)/2;
                objImg.style.paddingRight=(maxWidth-w)/2;
        }
}
//<img onload="DrawImage(this,140,120)" src="ss.jpg"/>



//设为主页
//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("此操作被浏览器拒绝！请在浏览器地址栏输入“about:config”并回车然后将[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 SetHome(obj,homepageurl){
	try{
		obj.style.behavior='url(#default#homepage)';
		obj.setHomePage(homepageurl);
	}catch(e){
		if(window.netscape){
			try{
				netscape.security.PrivilegeManager.enablePrivilege("UniversalXPConnect");
			}catch(e){
				alert("抱歉，此操作被浏览器拒绝！\n\n请在浏览器地址栏输入“about:config”并回车然后将[signed.applets.codebase_principal_support]设置为'true'");
			};
		}else{
			alert("抱歉，您所使用的浏览器无法完成此操作。\n\n您需要手动将'"+homepageurl+"'设置为首页。");
		};
	};
};
//加入收藏
function AddFavorite(sURL, sTitle)
{
try
{
window.external.addFavorite(sURL, sTitle);
}
catch (e)
{
try
{
window.sidebar.addPanel(sTitle, sURL, "");
}
catch (e)
{
alert("加入收藏失败，请使用Ctrl+D进行添加");
}
}
}
//翻滚图片js
function CreateFlash(focus,w,h,url, title, link,buttondisplay)
{
                        var so = new SWFObject("../images/focus.swf", focus, w, h, "6", "#ffffff");
                        so.addParam('wmode','transparent');
                        so.addVariable("picurl",url);
                        so.addVariable("pictext",title);
                        so.addVariable("piclink",link);
                        so.addVariable("pictime","2");
                        so.addVariable("borderwidth",w);
                        so.addVariable("borderheight",h);
                        so.addVariable("borderw","false");
                        so.addVariable("buttondisplay",buttondisplay);
                        so.addVariable("textheight","15");
                        so.write(focus);
}
    //左右底对齐
        $(function(){
        if($("#left").height()>=$("#right").height())
        {
            $("#right").height($("#left").height());
            }
            else
            {
                $("#left").height($("#right").height());
            }
        })  
        //取投票的选值
         function GetValue()
                           {
                              $("input[name*='RadioButtonList1']").each(function(i)
                              {
                                if(this.checked==true)
                                {
                                  
                                window.open("ViewVote.aspx?id="+this.value); 
                                }

                              });
                           }  
//    $(function () {
//        $('p.bg marquee').marquee().mouseover(function () {
//            $(this).trigger('stop');
//        }).mouseout(function () {
//            $(this).trigger('start');
//        })
//    });
//    
//     $(function () {
//        $('div.up marquee').marquee('pointer').mouseover(function () {
//            $(this).trigger('stop');
//        }).mouseout(function () {
//            $(this).trigger('start');
//        })
//    });
    
function externallinks() { 
if (!document.getElementsByTagName) return; 
var anchors = document.getElementsByTagName('a'); 
for (var i=0; i<anchors.length; i++) { 
var anchor = anchors[i]; 
if (anchor.getAttribute('href') && 
anchor.getAttribute('rel') == 'external') 
anchor.target = '_blank'; 
} 
} 
$(function(){
externallinks();
});

        //自适应高度
        function SetCwinHeight(obj)
        {
          var cwin=obj;
          if (document.getElementById)
          {
            if (cwin && !window.opera)
            {
              if (cwin.contentDocument && cwin.contentDocument.body.offsetHeight)
                cwin.height = cwin.contentDocument.body.offsetHeight; 
              else if(cwin.Document && cwin.Document.body.scrollHeight)
                cwin.height = cwin.Document.body.scrollHeight;
            }
          }
        }
        
    //投票提交
     function tj(obj,i,j){
      $(function(){
      $(obj).click(function(){
       var s;
               $(i).each(function()
                {

                   if ($(this).attr("checked")) 
                   {
                       s = $(this).attr("value");
 
                       if (getCookie("PID_" + $(j).val()) == null)
                       {
                           alert("投票成功！"); window.open("../cn/look.aspx?id=" + s,'win','width=550,height=450,left=0,top=0,resizable=0,scrollbars=0,status=no,toolbar=no,location=no,menu=no');
                       }
                       else
                       {
 
                           alert("已经投过票！");
                       }
                       return false;
                   }
               })
               return false;
      })
      })
}



