// JavaScript Document

/* 弹出窗口 */
function OpenAlert(DivID,callBack){
//	document.body.style.overflow= "hidden";	
	if(typeof(DivID)!="string" && DivID instanceof jQuery){
			DivID.show();
	}
	else{
			var obj;
			try{
				obj=(typeof(DivID)=="string")?document.getElementById(DivID):DivID;
			}
			catch(index){
				//alert(index);
				}
			if(obj==null) return;	
			obj.style.display="block";
		}
			var bodyH=document.body.clientHeight;
			var bodyW=document.body.clientWidth;	
			var wp=document.getElementById("WPcontent");
			var title=document.getElementById("ContentTitle");
			var dragX,dragY,drageEnabled=false;
				
			var alertDIV=document.getElementById("Alert_Info");
			var bgDIV=document.getElementById("AlertBackground");
				alertDIV.style.display="block";

				bgDIV.style.display="block";
				bgDIV.style.width=bodyW+"px";
				bgDIV.style.height=bodyH+"px";
				bgDIV.style.left=0+"px";
				bgDIV.style.top=0+"px";
				bgDIV.innerHTML="<iframe src=\"about:blank\" style=\"position:absolute; visibility:inherit; top:0px; left:0px; width:100%; height:100%; z-index:-1; filter='progid:DXImageTransform.Microsoft.Alpha(style=0,opacity=0)'; filter:alpha(opacity=0);opacity:0; padding:0; margin:0; background:#000;\" frameborder=\"0\"></iframe>";
				alertDIV.style.top=(document.documentElement.scrollTop+(document.documentElement.clientHeight-alertDIV.offsetHeight)/2)+"px";
				alertDIV.style.left=(document.documentElement.scrollLeft+(document.documentElement.clientWidth-alertDIV.offsetWidth)/2)+"px"; 
				
				title.onmousedown=function(e){
						drageEnabled=true;
						var e=e||window.event;
						dragX=(e.x||e.clientX)-alertDIV.offsetLeft;
						dragY=(e.y||e.clientY)-alertDIV.offsetTop;
				}
				
				//title.onmouseout=function(){drageEnabled=false;}
				
				document.onmousemove = function(e){
						var e = e||window.event;
						if(!drageEnabled) return;
						alertDIV.style.left =( e.x || e.clientX)-dragX+ "px";
						alertDIV.style.top =( e.y || e.clientY )-dragY+ "px";
				}
				
				
				document.onmouseup = function(e){
					drageEnabled=false;
				}
				
				
				if(callBack==null) return;
				if(typeof(callBack)=="string") {eval(callBack)}
				else if(typeof(callBack)=="function") {callBack()}
	}

function CloseAlert(){
//	document.body.style.overflow= "auto";	
	var alertDIV=document.getElementById("Alert_Info");
	var bgDIV=document.getElementById("AlertBackground");
	var wp=document.getElementById("WPcontent");
		for(var i=0;i<wp.childNodes.length;i++){
				var ChildDIV=wp.childNodes.item(i);
					try{
							if(ChildDIV!="undefined" && ChildDIV !=null){
								ChildDIV.style.display="none";
							}
					}
					catch(index){
						
						}
			}
		alertDIV.style.display="none";
		bgDIV.style.display="none";
		bgDIV.innerHTML="";
	}
	
/* 单行滚动 */
function SingleLiScroll(ul, delay, speed, lineHeight) {
              var slideBox = (typeof ul == "string")?document.getElementById(ul):ul;
              var delay = delay||1000;
              var speed=speed||20;
              var lineHeight = lineHeight||20;
              var tid = null, pause = false;
              var start = function() {
                     tid=setInterval(slide, speed);
              }
	  
              var slide = function() {
                     if (pause) return;
                     slideBox.scrollTop += 2;
                     if ( slideBox.scrollTop % lineHeight == 0 ) {
                            clearInterval(tid);
                            //slideBox.appendChild(slideBox.getElementsByTagName("li")[0]);
                            //slideBox.scrollTop = 0;
                            setTimeout(start, delay);
                     }
              }
              slideBox.onmouseover=function(){pause=true;}
              slideBox.onmouseout=function(){pause=false;}
              setTimeout(start, delay);
       }
	   
/* 多行滚动 */
function MultilineScroll(ul, delay, speed ,lineHeight,tester) {
              var slideBox = (typeof ul == "string")?document.getElementById(ul):ul;
			  var tester = (typeof tester == "string")?document.getElementById(tester):tester;
              var delay = delay||1000;
              var speed=speed||20;
              var lineHeight = lineHeight||slideBox.clientHeight;
			  var scrollHeight=slideBox.scrollHeight;
              var tid = null, pause = false;
              var start = function() {
                     tid=setInterval(slide, speed);
              }
			  var html=slideBox.innerHTML+slideBox.innerHTML;
			  slideBox.innerHTML=html;
              var slide = function() {
                     if (pause) return;
					 if( slideBox.scrollTop >=scrollHeight){
						slideBox.scrollTop=0;
					 }
					 slideBox.scrollTop += 1;
                     if (slideBox.scrollTop % lineHeight == 0 ) {
                            clearInterval(tid);
	                        setTimeout(start, delay);
                     }
					 if(tester) tester.innerHTML=slideBox.scrollTop+":"+scrollHeight+":"+(parseInt(slideBox.scrollTop) >= parseInt(scrollHeight));
					// if(tester) tester.innerHTML=slideBox.scrollTop+":"+scrollHeight+":"+(parseInt(slideBox.scrollTop) >= parseInt(scrollHeight));
              }
              slideBox.onmouseover=function(){pause=true;}
              slideBox.onmouseout=function(){pause=false;}
              stid=setTimeout(start, delay);
       }
	   
/* 单行水平滚动 */
function SinglineHScroll(ul, delay, speed, dir) {
              var slideBox = (typeof ul == "string")?document.getElementById(ul):ul;
			  var ChildNodes=[];
			  var regExp=/^.*marquee.*$/;
			  var getCloneTarget=function(node){
				  var target=getChildNodes(node);
				  var hasPass=[];
				 for(var i=0;i<target.length;i++){
					// alert(target[i].getAttributeNode('class').value);
					try{
						/* if((target[i].getAttribute('class',2)!="marquee" && target[i].getAttributeNode('class').nodeValue !="marquee") || target[i].getAttributeNode('class').nodeValue !="marquee"){
							continue;
						 }
						 */
						 if((!regExp.exec(target[i].getAttribute('class',2)) && !regExp.exec(target[i].getAttributeNode('class').nodeValue)) || !regExp.exec(target[i].getAttributeNode('class').nodeValue)){
							continue;
						 }
						 
						return target[i];
					 }
					 catch(index){
						 }
				}
			  }
	          var getChildNodes=function(Node){
					var childNodes=ChildNodes;
					if(Node.childNodes.length>0){
						for(var i=0;i<Node.childNodes.length;i++){
							if(Node.childNodes[i].nodeName!="#text"){
								childNodes.push(Node.childNodes[i]);
								childNodes.concat(getChildNodes(Node.childNodes[i]));
							 	}
							}
						}
				return childNodes;
			 }
              var delay = delay||1000;
              var speed=speed||20;
			  var dir=dir||"left";
              var clientWidth = slideBox.clientWidth;
			  var scrollWidth =	slideBox.scrollWidth;
              var tid = null, pause = false;
			  var marquee=getCloneTarget(slideBox);
			  var marqueeParent=marquee.parentNode;
		      var marqueeParentClone=marqueeParent.cloneNode(true);
			  	  marqueeParentClone.id=marqueeParent.id+"_Clone";
			  var cloneMarquee=getCloneTarget(marqueeParentClone);
   		  		  cloneMarquee.id=marquee.id+"_Clone";

			  		
              var start = function() {
                     tid=setInterval(slide, speed);
              }
			 
              var slide = function() {
                     if (pause) return;
					 if(dir=="left"){
						 slideBox.scrollLeft += 2;
						 }
					 else if(dir=="right"){
						 slideBox.scrollLeft -= 2;
						 }
                     if ( slideBox.scrollLeft % clientWidth == 0 ) {
                            clearInterval(tid);
							if (slideBox.scrollLeft>=scrollWidth) {
									slideBox.scrollLeft=0;
								}
							else if(slideBox.scrollLeft<=0){
									slideBox.scrollLeft=scrollWidth;
								}
                            setTimeout(start, delay);
                     }
					// document.getElementById("aaa").innerHTML="新建网墓"+slideBox.scrollLeft;
              }
              slideBox.onmouseover=function(){pause=true;}
              slideBox.onmouseout=function(){pause=false;}
              if(clientWidth<scrollWidth) {
				  setTimeout(start, delay);
				  marqueeParent.parentNode.insertBefore(marqueeParentClone,marqueeParent);
				  }
				  
       }
	   
      // ( 'ullist2', 3000, 1, 20 );//停留时间，相对速度（越小越快）,每次滚动多少，最好和Li的Line-height一致。
	  
/* 上传图片可预览 IE,FF */

var MaxSiza={width:0,height:0};


function onUploadImgChange(sender){         
    if( !sender.value.match( /.jpg|.gif|.png|.bmp/i ) ){         
        alert('图片格式无效！');         
        return false;         
    }         
             
    var objPreview = document.getElementById( 'preview' );         
    var objPreviewFake = document.getElementById( 'preview_fake' );         
    var objPreviewSizeFake = document.getElementById( 'preview_size_fake' );         

    if( sender.files &&  sender.files[0] ){         
        objPreview.style.display = 'block';         
        objPreview.style.width = 'auto';         
        objPreview.style.height = 'auto';         
        // Firefox 因安全性问题已无法直接通过 input[file].value 获取完整的文件路径         
        objPreview.src = sender.files[0].getAsDataURL();             
    }else if( objPreviewFake.filters ){          
        // IE7,IE8 在设置本地图片地址为 img.src 时出现莫名其妙的后果         
        //（相同环境有时能显示，有时不显示），因此只能用滤镜来解决         
             
        // IE7, IE8因安全性问题已无法直接通过 input[file].value 获取完整的文件路径         
        sender.select();         
        var imgSrc = document.selection.createRange().text;         
                 
        objPreviewFake.filters.item(         
            'DXImageTransform.Microsoft.AlphaImageLoader').src = imgSrc;         
        objPreviewSizeFake.filters.item(         
            'DXImageTransform.Microsoft.AlphaImageLoader').src = imgSrc;         
                 
        autoSizePreview( objPreviewFake,objPreviewSizeFake.offsetWidth, objPreviewSizeFake.offsetHeight );
        objPreview.style.display = 'none';         
    }  
}         
        
function onPreviewLoad(sender){         
    autoSizePreview( sender, sender.offsetWidth, sender.offsetHeight );         
}         
        
function autoSizePreview( objPre, originalWidth, originalHeight ){         
    var zoomParam = clacImgZoomParam( MaxSiza.width, MaxSiza.height, originalWidth, originalHeight );         
    objPre.style.width = zoomParam.width + 'px';         
    objPre.style.height = zoomParam.height + 'px';         
    objPre.style.marginTop = zoomParam.top + 'px';         
    objPre.style.marginLeft = zoomParam.left + 'px';         
}         
        
function clacImgZoomParam( maxWidth, maxHeight, width, height ){         
    var param = { width:width, height:height, top:0, left:0 };         
             
    if( width>maxWidth || height>maxHeight ){         
        rateWidth = width / maxWidth;         
        rateHeight = height / maxHeight;         
                 
        if( rateWidth > rateHeight ){         
            param.width =  maxWidth;         
            param.height = height / rateWidth;         
        }else{         
            param.width = width / rateHeight;         
            param.height = maxHeight;         
        }         
    }         
             
    param.left = (maxWidth - param.width) / 2;         
    param.top = (maxHeight - param.height) / 2;         
             
    return param;         
}   

/** 弹出窗口并自动关闭 **/
function autoAlert(count,delay,background){
	
	   // 生成新的包裹DIV
		var din_autoDiv;
		var din_overlay;
		var IntervalID;
		var TimeoutID;
		var toTop;
		var toLeft;
		var hasScroll=true;
		var image=new Image(); 
		window.clearInterval(IntervalID);
		window.clearTimeout(TimeoutID);
		if(document.getElementById("din_overlay")==null || document.getElementById("din_overlay")=="undefined")
		{
			din_overlay=document.createElement("div");
			din_overlay.setAttribute("id","din_overlay");
			document.body.appendChild(din_overlay);
			}
		else{
			din_overlay=document.getElementById("din_overlay");
			}
		
		if( document.getElementById("din_autoDiv")==null || document.getElementById("din_autoDiv")=="undefined"){
				din_autoDiv=document.createElement("div");
				din_autoDiv.setAttribute("id","din_autoDiv");
				// 把包裹DIV添加到Body的尾部
				document.body.appendChild(din_autoDiv);
		}else{
				din_autoDiv=document.getElementById("din_autoDiv");
		}
		din_autoDiv.style.display="block";
		din_autoDiv.innerHTML=count;
		
		if(din_autoDiv.childNodes.length<=1) din_autoDiv.style.lineHeight=52+"px";
				if(background!=null && background!="" && background!="undefined")
				{
					image.dynsrc=background;
                    din_autoDiv.style.width=image.width-8+"px";
                    din_autoDiv.style.height=image.height-8+"px";
					din_autoDiv.style.backgroundImage="url("+background+")";
					din_autoDiv.style.lineHeight=image.height-8+"px";
			    }
		toTop=(document.documentElement.scrollTop+(document.documentElement.clientHeight-din_autoDiv.offsetHeight)/2);
		toLeft=(document.documentElement.scrollLeft+(document.documentElement.clientWidth-din_autoDiv.offsetWidth)/2);
		din_autoDiv.style.top = toTop+100+"px";
		din_autoDiv.style.left = toLeft+"px";
		
		IntervalID=window.setInterval(function(){
											   if(din_autoDiv.offsetTop<=toTop){
											   		window.clearInterval(IntervalID);
													TimeoutID=window.setTimeout(function(){din_autoDiv.style.display="none";window.clearTimeout(TimeoutID);},delay*1000);
											   }
											   else {
												var mt=din_autoDiv.offsetTop;
													mt-=10;
											  	 	din_autoDiv.style.top=mt+"px";
													window.clearTimeout(TimeoutID);
												}
											   }
											   ,1);
		
	}


/**
*返回浏览器版本
*/
function BrowerVersion(){
	/*
	var Version="";
		var Sys = {};
        var ua = navigator.userAgent.toLowerCase();
        var s;
        (s = ua.match(/msie ([\d.]+)/)) ? Version = s[1] : (s = ua.match(/firefox\/([\d.]+)/)) ? Version = s[1] :(s = ua.match(/chrome\/([\d.]+)/)) ? Version = s[1] : (s = ua.match(/opera.([\d.]+)/)) ? Version = s[1] :(s = ua.match(/version\/([\d.]+).*safari/)) ? Version = s[1] : 0;
		return Version;
	*/	
		
	var OsObject = ""; 
   if(navigator.userAgent.indexOf("MSIE")>0) { 
        return "IE"; 
   } 
   if(isFirefox=navigator.userAgent.indexOf("Firefox")>0){ 
        return "FF"; 
   } 
   if(isSafari=navigator.userAgent.indexOf("Safari")>0) { 
        return "SF"; 
   }  
   if(isCamino=navigator.userAgent.indexOf("Camino")>0){ 
        return "CO"; 
   } 
   if(isMozilla=navigator.userAgent.indexOf("Gecko/")>0){ 
        return "GK"; 
   } 

	}
	
/**   
* 根据类名获得元素   
 * 参数说明:   
 *      1、className 类名   
 *      2、tag 元素名 默认所有元素   
 *      3、elm 父元素 默认doucment   
 */   
document.getElementsByClassName = function getElementsByClassName(className,tagName){  
				 var ele=[],allEle=document.getElementsByTagName(tagName||"*");  
				 for(var i=0;i<allEle.length;i++){  
				 if(allEle[i].className.match(new RegExp('(\\s|^)'+className+'(\\s|$)'))){  
							 ele[ele.length]=allEle[i];  
						 }  
				 }  
				 return ele;  
		} 
		
/*取出数组中最大值*/		
Array.prototype.max = function(){return Math.max.apply({},this)   }		


/*取出数组中最小值*/		
Array.prototype.min = function(){return Math.min.apply({},this)   }		

/*获取标签的属性*/
function hasAttribute(elm,attribute){
　　return elm.getAttribute(attribute) != null;
　　}


/** The End **/
