var Info_Key_Value="输入要查找的新闻资讯的关键词";
var Bizinfo_Key_Value="输入要查找的供求商机关键词";
var Corporation_Key_Value="输入要查找企业、公司、组织等名称的关键词";
var Sale_Key_Value="输入要查找的产品信息名称的关键词";
var Recruitment_Key_Value="输入要查找的二手信息的关键词";
var Picture_Key_Value="输入要查找的图片信息的关键词";
var CopyAppend="\r\n该信息来自[神州站] http://www.cnz8.net 网站建设推广专家 自助智能建站平台 打造最具影响力的B2B电子商务平台";

$(document).ready(function(){
     $("#Content_Display img").each(function (){
        changeImgSize(this);
    });

    if (document.location.href.indexOf("Info")!=-1)
    {
        $("#Select_Info").click();
    }
    else if (document.location.href.indexOf("Bizinfo")!=-1)
    {
        $("#Select_Bizinfo").click();
    }
    else if (document.location.href.indexOf("Sale")!=-1)
    {
        $("#Select_Sale").click();
    }
    else if (document.location.href.indexOf("Recruitment")!=-1)
    {
        $("#Select_Recruitment").click();
    }
    else if (document.location.href.indexOf("Picture")!=-1)
    {
        $("#Select_Picture").click();
    }

    SearchShowAlt($("#Bizinfo_Key"),Bizinfo_Key_Value);    
    SearchShowAlt($("#Info_Key"),Info_Key_Value);
    SearchShowAlt($("#Corporation_Key"),Corporation_Key_Value);
    SearchShowAlt($("#Sale_Key"),Sale_Key_Value);
    SearchShowAlt($("#Recruitment_Key"),Recruitment_Key_Value);
    SearchShowAlt($("#Picture_Key"),Picture_Key_Value);
    
    $("#EliteInfo div:first").Scroll({lineH:113,timer:5000});
    
    LoadList("CorporationClass");
    LoadList("Area");
    LoadList("InfoClass");
    LoadList("RecruitmentAddress");
    
    SetShowAndHide($("#ChinaArea"),$("#ChinaAreaContent"),"A_On","");
    
    document.body.oncopy=function(){ 
        event.returnValue=false; 
        CopyToClipboard(document.selection.createRange().text+CopyAppend);
    } 

});

//-----------------------------------------------------------------------
//正文图片载入大小限制
function changeImgSize(obj)
{
	var maxImageWidth = 500;	//图片的最大宽度
	$(obj).css("cursor","pointer");

	if($(obj).attr("width") > maxImageWidth)
	{
		$(obj).attr("width",maxImageWidth);
		$(obj).css("width",maxImageWidth);
	}
	
	if (!$(obj).parent().is("a"))
	{
	    $(obj).attr("alt","按此在新窗口浏览图片");
	    $(obj).bind("click",function(){window.open(obj.src);});
	}
}

function SearchShowAlt(e,Value)
{
    SetSearchAlt(e,Value);
    
    e.focus(function(){
        if (e.val()==Value)
        {
            e.val("");
            e.attr("class","TextBox");
        }
    });
    
    e.blur(function(){
        SetSearchAlt(e,Value);
    });
}

function SetSearchAlt(e,Value)
{
    if (e.val()=="")
    {
        e.val(Value);
        e.attr("class","TextBoxB");
    }
}
//-----------------------------------------------------------------------
//前台缩略图按比例缩放函数
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 ShowSearch(mode)
{
    HideSearch();
    $("#Find"+mode).show();
    $("#Current_Select_Val").html($("#Select_"+mode).html());
}

function HideSearch()
{
    $("#FindBizinfo").hide();
    $("#FindCorporation").hide();
    $("#FindInfo").hide();
    $("#FindSale").hide();
    $("#FindRecruitment").hide();
    $("#FindPicture").hide();
}
//---------------------------------------------------
function ShowBan(ID,Count,Name,Class)
{
    for (i=1;i<=Count;i++)
    {
        $("#"+Name+"_Title_"+i).removeAttr("class");
        $("#"+Name+"_Content_"+i).hide();
    }
    $("#"+Name+"_Title_"+ID).attr("class",Class);
    $("#"+Name+"_Content_"+ID).show();
}
//---------------------------------------------------
var TheLoadID=0;
var TheType="";
function ShowContact(e,id,Type)
{
    if (id!=TheLoadID || TheType!=Type)
    {
        $("#TheContact ul").html("数据载入中...");
        
        $.ajax({
            url: "1.html",
            success: function(html){$("#TheContact div:first").html(html);}
        });
        TheLoadID=id;
        TheType=Type;
    }
    
    $("#TheContact").css("left",getElementPos(e).x-280).css("top",getElementPos(e).y-40);
    COnContact();
}
function HideContact()
{
    $("#TheContact").hide();
}
function COnContact()
{
    $("#TheContact").show();
}
//---------------------------------------------------
function ShowIndexElite(e,ImgSrc,Href)
{
    $("#TheEliteImg").css("left",getElementPos(e).x-2).css("top",getElementPos(e).y+40);
    $("#TheEliteImg img").attr("src",ImgSrc);
    COnIndexElite();
}
function HideIndexElite()
{
    $("#TheEliteImg img").attr("src","/images/2009/Loading.gif");
    $("#TheEliteImg").hide();
}
function COnIndexElite()
{
    $("#TheEliteImg").show();
}
//---------------------------------------------------
function SetShowAndHide(button,content,buttonOverClass,buttonOutClass)
{
    $(button).mouseover(function(){
        IsShow(button,content,buttonOverClass);
    });

    $(button).mouseout(function(){
        IsHide(button,content,buttonOutClass);
    });
    
    $(content).mouseover(function(){
        IsShow(button,content,buttonOverClass);
    });
    
    $(content).mouseout(function(){
        IsHide(button,content,buttonOutClass);
    });
}

function IsShow(button,content,buttonOverClass)
{
    $(button).attr("class",buttonOverClass);
    $(content).show();
}

function IsHide(button,content,buttonOutClass)
{
    $(button).attr("class","");
    $(content).hide();
}
//---------------------------------------------------
$(document).click(function(){HideSelect();});

SelectMode=0;

function HideSelect()
{
    if (SelectMode==0)
    {
        $("#CorporationClassList").hide();
        $("#AreaList").hide();
        $("#InfoClassList").hide();
        $("#RecruitmentCharacterList").hide();
        $("#RecruitmentAddressList").hide();
        $("#Select_Mode").hide();
    }
    else
        SelectMode=0;
}

function Select(Type)
{
    HideSelect();
    SelectMode=1;
    $("#"+Type+"List").show();
}

function ListIsClick()
{
    SelectMode=1;
}

function IsSelect(Type,Text,Value)
{
    if (CheckLength(Text)>16)
        $("#"+Type+"Selected").text(StringCut(Text,14)+"...");
    else
        $("#"+Type+"Selected").text(Text);
    
    $("#"+Type+"Val").val(Value);
    $("#"+Type+"List").hide();
}


function ShowSlectMode()
{
    HideSelect();
    SelectMode=1;
    $("#Select_Mode").show();
}

function LoadList(Type)
{
   $.ajax({
    url: "Ajax/"+Type+"List.aspx",
    success: function(html){$("#"+Type+"List").html(html);}
   });
}
//---------------------------------------------------
//免激活方式显示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 CheckLength(str)
{
    var num=str.length;
    var arr=str.match(/[^\\\\\\\\\\\\\\\\x00-\\\\\\\\\\\\\\\\x80]/ig);
        if(arr!=null)num+=arr.length;
        
    return num;
}

function CheckStrLen(ID,len,Str) 
{ 
    var num=CheckLength($('#'+ID).val());
        
    if (num>len)
    {
        alert(Str);
        $('#'+ID).focus();
        return false;
    }
    else
        return true;
} 
//---------------------------------------------------
function StringCut(Str,Len)
{
    var InputString = Str;
    if(isNaN(Len)||Len==null)
    {
                Len = 0;
    }
    if (Len>0)
    {
     if (CheckLength(InputString) > Len)
     {
         var ReStr="";
         for (var i=0;i<InputString.length;i++)
         {
            if (CheckLength(ReStr) + 1 == Len && CheckLength(InputString.substr(i,1)) > 1)
            {
                return ReStr;
            }
            ReStr += InputString.substr(i,1);
            if (CheckLength(ReStr) == Len)
            {
                return ReStr;
            }
         }
     }
    }
    return InputString;
}
//---------------------------------------------------
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 getElementPos(el) {
 var ua = navigator.userAgent.toLowerCase();
 var isOpera = (ua.indexOf('opera') != -1);
 var isIE = (ua.indexOf('msie') != -1 && !isOpera); // not opera spoof

 if(el.parentNode === null || el.style.display == 'none') {
  return false;
 }      
 var parent = null;
 var pos = [];     
 var box;     
 if(el.getBoundingClientRect)    //IE
 {         
  box = el.getBoundingClientRect();
  var scrollTop = Math.max(document.documentElement.scrollTop, document.body.scrollTop);
  var scrollLeft = Math.max(document.documentElement.scrollLeft, document.body.scrollLeft);
  return {x:box.left + scrollLeft, y:box.top + scrollTop};
 }else if(document.getBoxObjectFor)    // gecko    
 {
  box = document.getBoxObjectFor(el); 
  var borderLeft = (el.style.borderLeftWidth)?parseInt(el.style.borderLeftWidth):0; 
  var borderTop = (el.style.borderTopWidth)?parseInt(el.style.borderTopWidth):0; 
  pos = [box.x - borderLeft, box.y - borderTop];
 } else    // safari & opera    
 {
  pos = [el.offsetLeft, el.offsetTop];  
  parent = el.offsetParent;     
  if (parent != el) { 
   while (parent) {  
    pos[0] += parent.offsetLeft; 
    pos[1] += parent.offsetTop; 
    parent = parent.offsetParent;
   }  
  }   
  if (ua.indexOf('opera') != -1 || ( ua.indexOf('safari') != -1 && el.style.position == 'absolute' )) { 
   pos[0] -= document.body.offsetLeft;
   pos[1] -= document.body.offsetTop;         
  }    
 }              
 if (el.parentNode) { 
    parent = el.parentNode;
   } else {
    parent = null;
   }
 while (parent && parent.tagName != 'BODY' && parent.tagName != 'HTML') { // account for any scrolled ancestors
  pos[0] -= parent.scrollLeft;
  pos[1] -= parent.scrollTop;
  if (parent.parentNode) {
   parent = parent.parentNode;
  } else {
   parent = null;
  }
 }
 return {x:pos[0], y:pos[1]};
}
//---------------------------------------------------
function CopyToClipboard(meintext) 
{ 
     if (window.clipboardData)  
     { 
         window.clipboardData.setData("Text", meintext); 
     } 
     else if (window.netscape)  
     {  
	 	try {  
         netscape.security.PrivilegeManager.enablePrivilege('UniversalXPConnect');  
    	 }  
     	catch (e)  
     	{  
         alert("复制相关内容被浏览器拒绝！\n请在浏览器地址栏输入'about:config'并回车\n然后将'signed.applets.codebase_principal_support'设置为'true'");  
    	}  

         var clip = Components.classes['@mozilla.org/widget/clipboard;1'] 
                         .createInstance(Components.interfaces.nsIClipboard); 
         if (!clip) return; 

         var trans = Components.classes['@mozilla.org/widget/transferable;1'] 
                         .createInstance(Components.interfaces.nsITransferable); 
         if (!trans) return; 
         trans.addDataFlavor('text/unicode'); 

         var str = new Object(); 
         var len = new Object(); 
         var str = Components.classes["@mozilla.org/supports-string;1"] 
                         .createInstance(Components.interfaces.nsISupportsString); 
         var copytext=meintext; 
         str.data=copytext; 
         trans.setTransferData("text/unicode",str,copytext.length*2); 
         var clipid=Components.interfaces.nsIClipboard; 
         if (!clip) return false; 
         clip.setData(trans,null,clipid.kGlobalClipboard); 
     } 
     else 
     { 
         return false; 
     } 
     return false; 
}
function myAddPanel(title,url,desc){
    if ((typeof window.sidebar == 'object') && (typeof window.sidebar.addPanel == 'function'))
    //Gecko
    {window.sidebar.addPanel(title,url,desc);}
    else
    //IE
    {window.external.AddFavorite(url,title);}
}
function setHomepage(url)
{
	if (document.all)
	{
		document.body.style.behavior='url(#default#homepage)';
		document.body.setHomePage(url);
	}
    else if (window.sidebar)
    {
    	if(window.netscape)
		{
			 try
			 {
				netscape.security.PrivilegeManager.enablePrivilege("UniversalXPConnect");
			 }
			 catch(e)
			 {
				alert("Your browser permissions is denied");
			 }
		}
		var prefs = Components.classes['@mozilla.org/preferences-service;1'].getService(Components. interfaces.nsIPrefBranch);
		prefs.setCharPref('browser.startup.homepage',url);
 	}
}


