var userAgent = navigator.userAgent.toLowerCase();
var is_opera  = (userAgent.indexOf('opera') != -1);
var is_saf    = ((userAgent.indexOf('applewebkit') != -1) || (navigator.vendor == "Apple Computer, Inc."));
var is_webtv  = (userAgent.indexOf('webtv') != -1);
var is_ie     = ((userAgent.indexOf('msie') != -1) && (!is_opera) && (!is_saf) && (!is_webtv));
var is_firefox  = ((typeof window.sidebar == "object") && (typeof window.sidebar.addPanel == "function"));
	
function addSysFavorite(url,sitename) {
    var url = url;
    var sitename = sitename;
    if (is_ie)
    {
       window.external.addFavorite(url,sitename);
    }
    else if (is_firefox)
    {
      window.sidebar.addPanel(sitename, url , "");
    }
}

function audio(a){
	document.write( '<span style="z-index:1000;"><object classid="clsid:d27cdb6e-ae6d-11cf-96b8-444553540000" codebase="http://download.macromedia.com/pub/shockwave/cabs/flash/swflash.cab#version=7,0,0,0" width="17" height="14" align="absmiddle">' +'<param name="allowScriptAccess" value="sameDomain" />' +'<param name="movie" value="/new_sound5.swf" />' +'<param name="loop" value="false" />' +'<param name="menu" value="true" />' +'<param name="quality" value="high" />' +'<param name="FlashVars" value="f=' + a + '"><param name="wmode" value="transparent">' +'<embed src="/new_sound5.swf" loop="false" menu="true" quality="high" bgcolor="#ffffff" width="17" height="14" align="absmiddle" allowScriptAccess="sameDomain" wmode="transparent" FlashVars="f=' + a + '" type="application/x-shockwave-flash" pluginspage="http://www.macromedia.com/go/getflashplayer" />' +'</object></span>');
}


function setCookie(c_name,value,expiredays,domain, path) {
	var expire = ""; 
	if(expiredays != null) { 
		expire = new Date((new Date()).getTime() + expiredays*86400); 
		expire = "; expires=" + expire.toGMTString(); 
		if (domain) domain = "; domain=" + domain;
		if (path) path = "; path=" + path;
	}
	document.cookie = c_name + "=" + escape(value) + expire + domain + path; 

}

function getCookie(c_name) {
	if (document.cookie.length>0)
	{
		c_start=document.cookie.indexOf(c_name + "=");
		if (c_start!=-1)
		{
		  c_start=c_start + c_name.length+1;
		  c_end=document.cookie.indexOf(";",c_start);
		  if (c_end==-1) c_end=document.cookie.length
		  return unescape(document.cookie.substring(c_start,c_end));
		}
	}
	return null
}

function storeCaret (textObj){
	if(textObj.createTextRange){
			textObj.caretPos = document.selection.createRange().duplicate();
	}
}

//大图片缩小
function resizePic(ImgD,maxwidth,maxheight){
        var image=new Image();
        image.src = ImgD.src;
        ImgD.resized = false;

        iWidth  = image.width;
        iHeight = image.height;
        picwidth  = iWidth;
        picheight = iHeight;

        //大图缩小
        if(iWidth > maxwidth || iHeight > maxheight)
        {
            if (iWidth>iHeight)
            {
                if(iWidth>maxwidth)
                {
                    picwidth = maxwidth;
                    picheight = (iHeight*maxwidth)/iWidth;
                }
                if(picheight>maxheight)
                {
                    picheight = maxheight;
                    picwidth  = (iWidth*maxheight)/iHeight;
                }
            }
            else
            {
                if(iHeight>maxheight)
                {
                    picheight = maxheight;
                    picwidth  = (iWidth*maxheight)/iHeight;

                }
                if(picwidth>maxwidth)
                {
                    picwidth = maxwidth;
                    picheight = (iHeight*maxwidth)/iWidth;
                }
            }

            ImgD.resized = true;
        }
        else
        {
            //小图原样输出
            picwidth  = iWidth;
            picheight = iHeight;

        }

        ImgD.width  = parseInt(picwidth);
        ImgD.height = parseInt(picheight);
}

_$ = function (id)
{
    return document.getElementById(id);
}
googleSearch = function()
{
    var form = _$('dictF');
    var bs=_$('s');
    var gclient = _$('gclient');
    var gie = _$('gie');
    var goe = _$('goe');
    var ghl = _$('ghl');
    var gchannel = _$('gchannel');
    gclient.disabled = false;
    gie.disabled = false;
    goe.disabled = false;
    ghl.disabled = false;
    gchannel.disabled = false;
    form.action='http://www.google.com/search';
    bs.name='q';
    form.target='_blank';
    form.submit();
    gclient.disabled = true;
    gie.disabled = true;
    goe.disabled = true;
    ghl.disabled = true;
    gchannel.disabled = true;
    form.action='search';
    form.target='';
    bs.name='bs';
}

function getFlashObject(movieName)
{
	if (window.document[movieName])
	{
		return window.document[movieName];
	}
	if (navigator.appName.indexOf("Microsoft Internet")==-1)
	{
		if (document.embeds && document.embeds[movieName])
			return document.embeds[movieName];
	}
	else // if (navigator.appName.indexOf("Microsoft Internet")!=-1)
	{
		return document.getElementById(movieName);
	}
}

function asplay(c){
	var asound = getFlashObject("asound");
	if(asound){
		asound.SetVariable("f",c);
		asound.GotoFrame(1);
	}
}

function asstop(){
	var asound = getFlashObject("asound");
	if(asound){
		asound.GotoFrame(3);
	}
}
