﻿//使用onload=DrawImage(this,长,宽);
function DrawImage(ImgD,w,h)
{
	var image=new Image();
	image.src=ImgD.src;
	if(image.width>0 && image.height>0)
	{
		flag=true;
		if(image.width/image.height>= w/h)
		{
			if(image.width>w)
			{
				ImgD.width=w;
				ImgD.height=(image.height*w)/image.width;
			}
			else
			{
				ImgD.width=image.width;
				ImgD.height=image.height;
			}
		//ImgD.alt=image.width+"×"+image.height;
		}
		else{
			if(image.height>h)
			{
				ImgD.height=h;
				ImgD.width=(image.width*h)/image.height;
			}
			else
			{
				ImgD.width=image.width;
				ImgD.height=image.height;
			}
		//ImgD.alt=image.width+"×"+image.height;
		}
	}
}


var control=new ElementControl();
window.onload=function pageinit(){
	__defnav();
}
function __defnav(){
	var h = control.getCookies("phoenix_magnet_nav");
	var e = control.$("leftnav").getElementsByTagName("a");
	if(h!=null) h=h;
	else h = 1;
	for(var i=0;i<e.length;i++){
		tz=(e[i].id).toString()
		if(e[i].className=="ln-link-std" && tz.indexOf("cat")!=-1){
		tmp=tz.replace("cat","");
		e[i].value=tmp;
		e[i].onclick=new Function("control.setCookies('phoenix_magnet_nav',this.value)");
		}
	}
	ShowHideElement("catmenu"+h);
	
}
function ElementControl(){
	//个人收集的JavaScript函数集合
	this.IsNegative=function(num){
		//判断是否为负数
		if(num=="") return true;
		if(IsNegative>0) return true;
		return false;
	}
	this.IsInteger=function(num){
		//判断是否为整数
		var $tmp=num-parseInt(num);
		if($tmp==0) return true;
		else return false;
	}
	this.$=function(id){
		//返回ID指定的控件
		return document.getElementById(id);
	}
	this._$=function(id){
		//返回Name指定的控件
		return document.getElementsByTagName(id);
	}
	this._e=function(){
		return window.event.srcElement;
	}
	this.jsLoader=function(url){
		//加载JS文件
		var jsFile=document.createElement("script");
		jsFile.setAttribute("type","text/javascript");
		jsFile.setAttribute("src",url);
		try{
			document.body.appendChild(jsFile);
		}
		catch(e){
			throw new Error('Load Js File '+url+' Error:'+e);
		}
	}
	this._k=function(){
		return window.event.keyCode;
	}
	this._date=function($mat){
		//返回当前目期
		if(!$mat) $mat="-";
		var $tmp=new Date();
		if($tmp.getMonth()<9) $month="0"+$tmp.getMonth();
		else $month=$tmp.getMonth();
		if($tmp.getDay()<9) $day="0"+$tmp.getDay();
		else $day=$tmp.getDay();
		return $tmp.getFullYear()+$mat+$month+$mat+$day;
	}
	this._now=function(){
		//返回当前时间
		var $tmp=new Date();
		return this._date()+" "+$tmp.getHours()+":"+$tmp.getMinutes()+":"+$tmp.getSeconds()
	}
	this._Rndstr=function($length){
		//返回一个$length位的系统随机码
		var rnd,tmp="",tnp;
		for(var $_o=0;$_o<$length;$_o++){
			rnd=Math.round(Math.random()*2);
		if(rnd==0){
			rnd=97+Math.round(Math.random()*25);
			tmp+=String.fromCharCode(rnd).toUpperCase();
		}
		else if(rnd==1){
			rnd=97+Math.round(Math.random()*25);
			tmp+=String.fromCharCode(rnd);
		}
		else if(rnd==2){
			tmp+=Math.round(Math.random()*9);
		}
	
		}
		return tmp;
	}
	this._rnd=function($length){
		//返回一个$length内的随机数
		return Math.round(Math.random()*$length);
	}
	this._sethome=function(url){
		if(!url) url=window.location;
		document.body.style.behavior="url(#default#homepage)";
		document.body.setHomePage(url);
	}
	this._addfav=function(url,til){
		if(!url) url=window.location;
		if(!til) til=window.location;
		window.external.AddFavorite(url,til);
	}
	this.Iscookies=function(){
		return navigator.cookieEnabled;
	}
	this.CookExpires;
	this.setCookies=function(name, value){
		//设定Cookie值
		if(!this.Iscookies) {
			alert("您的浏览器不支持Cookie功能，请开启它！");
			return false;
		}
		var expdate=new Date();
		var argv=this.setCookies.arguments;
		var argc=this.setCookies.arguments.length;
		var expires=(argc > 2) ? argv[2] : null;
		var path=(argc > 3) ? argv[3] : null;
		var domain=(argc > 4) ? argv[4] : null;
		var secure=(argc > 5) ? argv[5] : false;
		if(expires!=null) expdate.setTime(expdate.getTime() + ( expires * 1000 ));
		document.cookie=name + "=" + escape (value) +((expires == null) ? "" : ("; expires="+ expdate.toGMTString()))+((path == null) ? "" : ("; path=" + path)) +((domain == null) ? "" : ("; domain=" + domain))+((secure == true) ? "; secure" : "");
	}
	this.getCookies=function(name){
		//读取Cookie值
		if(document.cookie.length>0){
			var $tmp=document.cookie.indexOf(name+"=");
			if($tmp!=-1){
				$tmp+=(name+"=").length;
				var $omp=document.cookie.indexOf(";",$tmp);
				if($omp==-1) $omp=document.cookie.length;
				return unescape(document.cookie.substring($tmp,$omp));
			}
		}
		else return null;
	}
	this.RemoveCookies=function(name){
		//删除Cookie
		var exp = new Date();
		exp.setTime (exp.getTime() - 1);
		var cval = GetCookie (name);
		document.cookie=name+"="+cval+";expires="+exp.toGMTString();
	}
	this._param=function(name){
		//取引用地址SRC地址的参数
		var $scr=document.getElementsByTagName('SCRIPT');
		var $elh=$scr[$scr.length-1].src;
		var $tmp=$elh.match(new RegExp("[\?\&]" + item + "=([^\&]*)(\&?)","i"));
		return $tmp ? $tmp[1] : $tmp;
	}
	this.$_param=function(name){
		//取URL地址参数
		var reg=new RegExp("(^|&)"+name+"=([^&]*)(&|$)");   
		var tmp=window.location.search.substr(1).match(reg);   
		if(tmp!=null) return unescape(tmp[2]);
		else return null;
	}
}