// JavaScript Document

//-----------------------
//替换函数
//-----------------------
function ReplaceAll(str, sptr, sptr1){
	while (str.indexOf(sptr) >= 0)
	{
	   str = str.replace(sptr, sptr1);
	}
	return str;
}

//-----------------------
//图片收缩函数
//-----------------------
function DrawImage(ImgD,FitWidth,FitHeight){
 var image=new Image();
 image.src=ImgD.src;
 if(image.width>0 && image.height>0){
  if(image.width/image.height>= FitWidth/FitHeight){
   if(image.width>FitWidth){
    ImgD.width=FitWidth;
    ImgD.height=(image.height*FitWidth)/image.width;
   }else{
    ImgD.width=image.width;
    ImgD.height=image.height;
   }
  } else{
   if(image.height>FitHeight){
    ImgD.height=FitHeight;
    ImgD.width=(image.width*FitHeight)/image.height;
   }else{
    ImgD.width=image.width;
    ImgD.height=image.height;
   }
  }
 }
}

//加载js文件
function LoadFile(path){	
	document.write('<script type="text/javascript" src="'+path+'"></script>');
	
	}

//加载css
function LoadFile_Css(path){	
	document.write('<link href="'+path+'" rel="stylesheet" type="text/css">');
	}

//圆角函数，需加载圆角类库curvycorners.src.js
function initCorners(Element,tl,tr,bl,br){
	var settings = {
	  tl: { radius: tl },
	  tr: { radius: tr },
	  bl: { radius: bl },
	  br: { radius: br },
		antiAlias: true
	}
	
	curvyCorners(settings, Element);
}

//判断ie6浏览器函数
function IsIE6(){
	if (window.XMLHttpRequest) { // Mozilla, Safari,IE7
		return 'Mozilla, Safari,IE7 ';
	if (!window.ActiveXObject) { // Mozilla, Safari,
		return 'Mozilla, Safari';
	} else {
		return 'IE7';
	}
	} else {
		return 'IE6';
	}
	
}

//图片弹出函数
this.imagePreview = function(){
	$(document.body).append("<div id='preview'></div>")
/* CONFIG */
   xOffset = 10;
   yOffset = 30;
   // 可以自己设定偏移值
/* END CONFIG */
$("a.preview").hover(function(e){
   $("#preview").html("<img src='/templates/pic/loading-min.gif' />");   
   $("#preview").html("<img src='"+$(this).find("img").attr("id")+"' onLoad='JavaScript:DrawImage(this,400,400)' /><b>"+$(this).find("img").attr("title")+"</b>");         
   $("#preview")
    .css("top",(e.pageY - xOffset) + "px")
    .css("left",(e.pageX + yOffset) + "px")
    .show();      
    },
function(){
   $("#preview").hide();
    }); 
$("a.preview").mousemove(function(e){
   $("#preview")
    .css("top",(e.pageY - xOffset) + "px")
    .css("left",(e.pageX + yOffset) + "px");
});   
};


this.imagePreview2 = function(){ 
/* CONFIG */
  $(document.body).append("<div id='preview'></div>")
   xOffset = 10;
   yOffset = 30;
  
   // 可以自己设定偏移值

  
/* END CONFIG */
$(".preview").mouseover(function(e){
	var imgurl = $(this).attr("src")
	imgurl = imgurl.replace("-min.",".")
	$("#preview").html("<img src='/pic/loading-min.gif' />");   
   $("#preview").html("<img src='"+imgurl+"' onLoad='JavaScript:DrawImage(this,400,400)' />");         
   $("#preview")
    .css("top",(e.pageY - xOffset) + "px")
    .css("left",(e.pageX + yOffset) + "px")
    .show();      
    },
function(){
   $("#preview").hide();
    }); 

$(".preview").mouseout(function(e){
   $("#preview").hide();
});

$(".preview").mousemove(function(e){
   $("#preview")
    .css("top",(e.pageY - xOffset) + "px")
    .css("left",(e.pageX + yOffset) + "px");
});   
};

//名称：面板切换函数 ShowTablePanel
//参数：hClass 所在集合,thisid当前元素ID,sClass,当前类,contentclass对于内容类
//作用：实现tablepanel功能
//说明：此函数只能用在按照顺序对应的集合块中
function ShowTablePanel(hClass,thisid,sClass,contentclass){
	//$(hClass).hide();
	var cid=0;
	$(hClass).each(function(i){
		if($(this).text() == $(thisid).text()){
			cid = i; //循环找到当前活动菜单的集合ID值
		}
			
	})

	$(hClass).removeClass(sClass)
	$(thisid).addClass(sClass)
	$(thisid).show(); //显示菜单
	
	//寻找菜单集合ID对应的内容集合
	$(contentclass).hide();
	$(contentclass).eq(cid).show();
	
}

//名称：弹出层函数 OpenDiv
//参数：_Dw宽 _DH高 _Desc内容
//作用：弹出层显示内容
//说明：层里面的样式要自定义
var OverH,OverW,ChangeDesc,ChangeH=50,ChangeW=50;
var loadingid="#open_Loading"
function OpenDiv(_Dw,_Dh,_Desc) {
var arrayPageSize   = getPageSize();//调用getPageSize()函数
var arrayPageScroll = getPageScroll();//调用getPageScroll()函数
$(loadingid).html("");
OverH=_Dh;OverW=_Dw;ChangeDesc=_Desc;
$(loadingid).show();
if(_Dw>_Dh){ChangeH=Math.ceil((_Dh-10)/((_Dw-10)/50))}else if(_Dw<_Dh){ChangeW=Math.ceil((_Dw-10)/((_Dh-10)/50))}
$(loadingid).css("top",(document.documentElement.clientHeight-10)/2+"px");
$(loadingid).css("left",(document.documentElement.clientWidth-10)/2+"px");
//
//$(loadingid).css("top",arrayPageScroll[1] + (arrayPageSize[3] - arrayConSize[1]) / 2-50 + 'px');
//$(loadingid).css("left",(arrayPageSize[0] - arrayConSize[0]) / 2 -30 + 'px');      
    
OpenNow()
}
var Nw=10,Nh=10;
function OpenNow() {
if (Nw>OverW-ChangeW)ChangeW=2;
if (Nh>OverH-ChangeH)ChangeH=2;
Nw=Nw+ChangeW;Nh=Nh+ChangeH;

if(OverW>Nw||OverH>Nh) {
if(OverW>Nw) {
$(loadingid).css("width",Nw+"px");
$(loadingid).css("left",(document.documentElement.clientWidth-Nw)/2+"px");
}
if(OverH>Nh) {
$(loadingid).css("height",Nh+"px");
$(loadingid).css("top",(document.documentElement.clientHeight-Nh)/2+arrayPageScroll[1]+"px");
}
else
{
//$(loadingid).css("height",Nh+"px");
$(loadingid).css("top",(document.documentElement.clientHeight-200)/2+arrayPageScroll[1]+"px");	
}
window.setTimeout("OpenNow()",10)
}else{
Nw=10;Nh=10;ChangeH=50;ChangeW=50;
$(loadingid).html('<div style="text-align:right;"><a href="javascript:;" onclick="$(\''+loadingid+'\').hide();">Close</a></div>')
$(loadingid).append(ChangeDesc);
$(loadingid).find("li").show();
$(loadingid).css("top",(document.documentElement.clientHeight-$(loadingid).height())/2+arrayPageScroll[1]+"px");	
}
}


//获取内容层内容原始尺寸
function getConSize(conId){
	var conObj=document.getElementById(conId)
	conObj.style.position = "absolute";
	conObj.style.left=-1000+"px";
	conObj.style.display="";
	var arrayConSize=[conObj.offsetWidth,conObj.offsetHeight]
	conObj.style.display="none";
	return arrayConSize;
}
function insertAfter(newElement,targetElement){//插入
	var parent = targetElement.parentNode;
	if(parent.lastChild == targetElement){
		parent.appendChild(newElement);
	}
	else{
		parent.insertBefore(newElement,targetElement.nextSibling);
	}
}
//获取滚动条的高度
function getPageScroll(){
	var yScroll;
	if (self.pageYOffset) {
		yScroll = self.pageYOffset;
	} else if (document.documentElement && document.documentElement.scrollTop){
		yScroll = document.documentElement.scrollTop;
	} else if (document.body) {
		yScroll = document.body.scrollTop;
	}
	arrayPageScroll = new Array('',yScroll)
	return arrayPageScroll;
}
//获取页面实际大小
//返回数组 1是页面宽 2=页面高 3=窗口宽 4=窗口高
function getPageSize(){
	var xScroll,yScroll;
	if (window.innerHeight && window.scrollMaxY){
		xScroll = document.body.scrollWidth;
		yScroll = window.innerHeight + window.scrollMaxY;
	} else if (document.body.scrollHeight > document.body.offsetHeight){
		sScroll = document.body.scrollWidth;
		yScroll = document.body.scrollHeight;
	} else {
		xScroll = document.body.offsetWidth;
		yScroll = document.body.offsetHeight;
	}
	var windowWidth,windowHeight;
	//var pageHeight,pageWidth;
	if (self.innerHeight) {
		windowWidth = self.innerWidth;
		windowHeight = self.innerHeight;
	} else if (document.documentElement && document.documentElement.clientHeight) {
		windowWidth = document.documentElement.clientWidth;
		windowHeight = document.documentElement.clientHeight;
	} else if (document.body) {
		windowWidth = document.body.clientWidth;
		windowHeight = document.body.clientHeight;
	}
	var pageWidth,pageHeight
	if(yScroll < windowHeight){
		pageHeight = windowHeight;
	} else {
		pageHeight = yScroll;
	}
	if(xScroll < windowWidth) {
		pageWidth = windowWidth;
	} else {
		pageWidth = xScroll;
	}
	arrayPageSize = new Array(pageWidth,pageHeight,windowWidth,windowHeight)
return arrayPageSize;
}


//隐藏任意数目li
function HideLi(Num,obj){
	$(obj).hide();
	if(Num>0){
	for(var i=0;i<=Num;i++){
		$(obj).eq(i).show();	
	}
	}
	else{
		$(obj).show();
		}
}


//去左空格;
function ltrim(s){
	return s.replace( /^\s*/, "");
}
//去右空格;
function rtrim(s){
	return s.replace( /\s*$/, "");
}
//左右空格;
function trim(s){
	return rtrim(ltrim(s));
}

function pagenext(screenid,pi,type){
//统计离它最近的Ol的项目数
		//设置总页数
		var typecss="top"
		var screenheight = $(screenid).height()
		if(type=="width"){
			 screenheight = $(screenid).width()
			 typecss="left"
			}
		var tolpage //li 的总数,也即page总数
		var liheight = 0
		var tolli = 1
		//统计li的总高度
		$(screenid).find("ol:visible li").each(function(i){
			
				 //循环找到当前活动菜单的集合ID值	
				if(type=="width"){
					liheight += $(this).width()
					}
				else{
					liheight += $(this).height();
					}
				tolli = i
		})
		//alert(liheight/screenheight)
		tolpage = liheight/screenheight
		if(type=="height"){
		tolpage = tolpage * 2
		}
		tolpage = Math.ceil(tolpage)
		
		//当前页码
		
		var page = $(screenid).parent().find("div:visible .next_page:first").attr("title")
		if(page=="") page=1
		
		page = parseInt(page) + pi
		if (page<=1) page=1
		if (page>tolpage) page=1
		
		$(screenid).parent().find("div:visible .next_page:first").html(page+" of "+tolpage)
		$(screenid).parent().find("div:visible .next_page:first").attr("title",page)
		if(type=="height"){
			$(screenid).parent().find("div:visible .next_page:first").html((tolli+1))		
			
		}
		
		//移动显示区域\

		return (page-1)*screenheight

	//alert(liheight+'/'+screenheight+'='+tolpage)
}
function movepage(screenid,type,space){
		if(type=="width"){
			  $(screenid).find("ol:visible").animate({"left" : -(space)+'px'}, 500);
			}
		else{
			 $(screenid).find("ol:visible").animate({"top" : -(space/2)+'px'}, 500);
			}
}