﻿$(document).ready(function (){
    $("#IsContent img").each(function (){
        changeImgSize(this);
    });
    SelectModle();
}); 
//-----------------------------------------------------------------------
//前台缩略图按比例缩放函数
var flag=false;
function setPicRange(ImgD,iwidth,iheight)
{
    //参数(图片,允许的宽度,允许的高度)
    var image=new Image();
    image.src=ImgD.src;
    if(image.width>0 && image.height>0)
    {
        flag=true;
        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;
            }
        }
        else
        {
            if(image.height>iheight){  
                ImgD.height=iheight;
                ImgD.width=(image.width*iheight)/image.height;        
            }
            else
            {
                ImgD.width=image.width;  
                ImgD.height=image.height;
            }
        }
    }
}
//正文图片载入大小限制
function changeImgSize(obj)
{
	$(obj).css("cursor","pointer");

	setPicRange(obj,500,500);
	
	if (!$(obj).parent().is("a"))
	{
	    $(obj).wrap("<a href='"+obj.src+"' target='_blank' title='按此在新窗口浏览图片'></a>"); 
	    $(obj).attr("border","0");
	}
}
//-----------------------------------------------------------------------
//免激活方式显示FLASH
function insertFlash(url, w, h) { 
var str = ''; 
str += '<object width="'+ w +'" height="'+ h +'" classid="clsid:D27CDB6E-AE6D-11cf-96B8-444553540000" codebase="http://download.macromedia.com/pub/shockwave/cabs/flash/swflash.cab#version=7,0,0,0">'; 
str += '<param name="movie" value="'+ url +'">'; 
str += '<param name="wmode" value="transparent">'; 
str += '<param name="quality" value="autohigh">'; 
str += '<embed width="'+ w +'" height="'+ h +'" src="'+ url +'" quality="autohigh" wmode="transparent" type="application/x-shockwave-flash" plugspace="http://www.macromedia.com/shockwave/download/index.cgi?P1_Prod_Version=ShockwaveFlash"></embed>'; 
str += '</object>'; 
document.write(str); 
}
//-----------------------------------------------------------------------
function CheckInput(ID,Str,DefauleValue)
{
    if ($.trim($('#'+ID).attr("value"))=="")
    {
        alert(Str);
        $('#'+ID).focus();
        return false;
    }
    if (DefauleValue)
    {
        if ($.trim($('#'+ID).attr("value"))==DefauleValue)
        {
            alert(Str);
            $('#'+ID).focus();
            return false;
        }
    }
    return true;
}
//-----------------------------------------------------------------------
function SelectModle(Str)
{
    $("#Moudle option").each(function (){
    if (location.href.toLowerCase().indexOf($(this).val().toLowerCase())!=-1)
        $(this).attr("selected","selected");
    });
}

function ShowSearch()
{
    if (CheckInput("Key","请输入搜索关键字！"))
    {
        var Url="NewsList.aspx";
        Url=$("#Moudle option[@selected]").val();
        this.location=Url+"?key="+$("#Key").val();
    }
}
