﻿
function zimg(dd,mystr1,mystr2){
	var imgwidth;
	var imgheight;
	imgwidth=mystr1;
	imgheight=mystr2;
 	if (dd.width>imgwidth && dd.height>imgheight){
    		if (dd.width/dd.height>imgwidth/imgheight){
     			dd.width=imgwidth;
     		}else{
                dd.height=imgheight
            }
   	}else if(dd.width>imgwidth){
   		dd.width=imgwidth
  	}else if(dd.height>imgheight){
  		dd.height=imgheight
  	}	

}


//无限分类菜单函数
function menu_nav(menucode){
	var acode="v" + menucode;
	var bcode="c" + menucode;
	var vcode;
	var ccode;
	var it=true;
	if (IsObj($d(acode))){
		$d(acode).children[1].className="v9a";
	}else{		
		return false;
	}
	for (var i=0;it;i++){
		vcode=left(acode,acode.length-4*i);
		ccode=left(bcode,acode.length-4*i);
		if (IsObj($d(vcode))){
			//更改图标样式为打开状态
			//alert($d(vcode).children[0].className.replace(/(v\d).*/g,"$1on"));
			$d(vcode).children[0].className=$d(vcode).children[0].className.replace(/(v\d).*/g,"$1on");
			//有子菜单显示
			if (IsObj($d(ccode))){$d(ccode).style.display="";}
		}else{
			it=false;
		}
	}
}


function menu_click(iobj,meval,mlv){
	var left_n=eval(meval);
	if (left_n.style.display=='none'){
		eval(meval+".style.display='';");
		iobj.children[0].className="v"+ mlv + "on";
	}else {
		eval(meval+".style.display='none';");
		iobj.children[0].className="v"+ mlv + "off";
	}
}



//顶部二级菜单
function menuFix() {
 var sfEls=$d("nav").getElementsByTagName("li");
 for (var i=0;i<sfEls.length;i++) {
  sfEls[i].onmouseover=function() {this.className+=(this.className.length>0? " ": "") + "sfhover";}
  sfEls[i].onMouseDown=function() {this.className+=(this.className.length>0? " ": "") + "sfhover";}
  sfEls[i].onMouseUp=function() {this.className+=(this.className.length>0? " ": "") + "sfhover";}
  sfEls[i].onmouseout=function() {this.className=this.className.replace(new RegExp("( ?|^)sfhover\\b"), "");}
 }
}
//window.onload=menuFix;


//以下为通用函数
function $d(ObjId){return document.getElementById(ObjId)}

function IsObj(Obj) {
	if (Obj) {
		return true;
	}return false;
}

function left(mainStr,lngLen) { 
	if (lngLen>0) {return mainStr.substring(0,lngLen)}
	else{return null} 
}

function right(mainStr,lngLen) {
	if (mainStr.length-lngLen>=0 && mainStr.length>=0 && mainStr.length-lngLen<=mainStr.length) { 
	return mainStr.substring(mainStr.length-lngLen,mainStr.length)}
	else{return null} 
} 
function mid(mainStr,starnum,endnum){ 
	if(mainStr.length>=0){ 
		return mainStr.substr(starnum,endnum) 
	}else{return null}
}
