﻿
PhotoUploader = {
	
	"ChangeImagePreview"   : function SPU_ChangeImagePreview (eleInputFile) {		
		if (eleInputFile.value) {
			if (document.all) {
				$("FileUpload1preview").filters.item("DXImageTransform.Microsoft.AlphaImageLoader").src = eleInputFile.value;
				$("FileUpload1image").style.display = "none";
			} else {
				$("FileUpload1image").src = eleInputFile.value;
			}
			$("FileUpload1cleaner").style.display = "";
		} else {
			if (document.all) {
				$("FileUpload1image").style.display = "";				
			} else {
				$("FileUpload1image").src="/images/invalid.gif";
			}
			$("FileUpload1cleaner").style.display = "none";
		}
		
    	},
	"Start"                : function SPU_Start () {
	    var ErrMsg="";
		if($("ctl00$ContentPlaceHolder1$photo_Title").value==""||$("ctl00$ContentPlaceHolder1$photo_Title").value==null)
		{
		   ErrMsg="请输入照片名称!";
		   //dialog.showPage("err.aspx?err="+ErrMsg);
		   alert(ErrMsg);		  
		   return false;
		}
		else
		{
		  if($("ctl00$ContentPlaceHolder1$FileUpload1").value==""||$("ctl00$ContentPlaceHolder1$FileUpload1").value==null)
		    {
		     ErrMsg="请选择上传图!";
		     //dialog.showPage("err.aspx?err="+ErrMsg);
		     alert(ErrMsg);
		     return false;
		    }
		    else
		    {
		       var photo=new UpLoadFileCheck(); 
		       photo.IsImg=true;
		       photo.AllowImgFileSize=300;
		       photo.AllowImgHeight=800;
		       photo.AllowImgWidth=800;
		       if(photo.CheckExt($("ctl00$ContentPlaceHolder1$FileUpload1"))==true)
		       {		      
		         Dialog.showMess();
		         return true;
		       }
		       else
		       {
		         return false;
		       }
		     }	       
		}
	},
	"RemoveQueuedFile"     : function SPU_RemoveQueuedFile (eleInputFile) {
		var oInput = document.createElement("input");
		oInput.setAttribute("type", "file");
		var sName = eleInputFile.getAttribute("name");
		oInput.setAttribute("name", sName);
		oInput.setAttribute("value", "");
		eleInputFile.parentNode.appendChild(oInput);
		eleInputFile.remove();
		with (oInput) {
			className = "component2";
			id = sName;
			onkeydown = function SPU_RemoveQueuedFile_keydown () {
				return false;
			}
			onpaste = function SPU_RemoveQueuedFile_paste () {
				return false;
			}
			onchange = function SPU_RemoveQueuedFile_change () {
				PhotoUploader.ChangeImagePreview(oInput);
			}
		}
		return this.ChangeImagePreview(oInput);
	}
	
};

UpLoadFileCheck=function()
	{		
			this.AllowExt=".jpg";//允许上传的文件类型 0为无限制 每个扩展名后边要加一个"," 小写字母表示 
			this.AllowImgFileSize=0;//允许上传文件的大小 0为无限制 单位：KB 
			this.AllowImgWidth=0;//允许上传的图片的宽度 0为无限制　单位：px(像素) 
			this.AllowImgHeight=0;//允许上传的图片的高度 0为无限制　单位：px(像素) 
			this.ImgObj=new Image();
			this.ImgFileSize=0;
			this.ImgWidth=0;
			this.ImgHeight=0;
			this.FileExt="";
			this.ErrMsg="";
			this.IsImg=false;//全局变量
				
	}
	
	UpLoadFileCheck.prototype.CheckExt=function(obj)
	{
		this.ErrMsg=""; 
		this.ImgObj.src=obj.value; 
		//this.HasChecked=false; 	
		if(obj.value=="")
		{
			this.ErrMsg="\n请选择一个文件";				
		}
		else
		{			
			this.FileExt=obj.value.substr(obj.value.lastIndexOf(".")).toLowerCase(); 
			if(this.AllowExt!=0&&this.AllowExt.indexOf(this.FileExt)==-1)//判断文件类型是否允许上传 
			{ 
				this.ErrMsg="\n该文件类型不允许上传。请上传 "+this.AllowExt+" 类型的文件，当前文件类型为"+this.FileExt; 		
			}
		} 
		if(this.ErrMsg!="") 
		{
			this.ShowMsg(this.ErrMsg,false); 
			return false;
		}
		else			
			return this.CheckProperty(obj); 			
	}
	
	UpLoadFileCheck.prototype.CheckProperty=function(obj)
	{
		if(this.ImgObj.readyState!="complete")//
			{ 
				sleep(1000);//一秒使用图能完全加载				
			} 		
			
		if(this.IsImg==true)
		{
			this.ImgWidth=this.ImgObj.width;//取得图片的宽度 
			this.ImgHeight=this.ImgObj.height;//取得图片的高度
			if(this.AllowImgWidth!=0&&this.AllowImgWidth<this.ImgWidth) 
			this.ErrMsg=this.ErrMsg+"\n图片宽度超过限制。请上传宽度小于"+this.AllowImgWidth+"px的文件，当前图片宽度为"+this.ImgWidth+"px"; 
	
			if(this.AllowImgHeight!=0&&this.AllowImgHeight<this.ImgHeight) 
			this.ErrMsg=this.ErrMsg+"\n图片高度超过限制。请上传高度小于"+this.AllowImgHeight+"px的文件，当前图片高度为"+this.ImgHeight+"px";  
		}
	
		this.ImgFileSize=Math.round(this.ImgObj.fileSize/1024*100)/100;//取得图片文件的大小 	
		if(this.AllowImgFileSize!=0&&this.AllowImgFileSize<this.ImgFileSize) 
			this.ErrMsg=this.ErrMsg+"\n文件大小超过限制。请上传小于"+this.AllowImgFileSize+"KB的文件，当前文件大小为"+this.ImgFileSize+"KB"; 
	
		if(this.ErrMsg!="") 
		{
			this.ShowMsg(this.ErrMsg,false); 
			return false;
		}
		else 
			return true; 
	}	
	
	UpLoadFileCheck.prototype.ShowMsg=function(msg,tf)//显示提示信息 tf=false 显示错误信息 msg-信息内容 
	{ 
		/*msg=msg.replace("\n","<li>"); 
		msg=msg.replace(/\n/gi,"<li>"); 
		 */
		//alert(msg);
		
		//dialog.showPage("err.aspx?err="+msg);
		alert(msg);
	}
	function   sleep(num)   
	  {   
		  var   tempDate=new   Date();   
		  var   tempStr="";   
		  var   theXmlHttp   =   new   ActiveXObject(   "Microsoft.XMLHTTP"   );   
		  while((new   Date()-tempDate)<num   )   
		  {   
		  tempStr+="\n"+(new   Date()-tempDate);   
		  try{   
		  theXmlHttp   .open(   "get",   "about:blank?JK="+Math.random(),   false   );   
		  theXmlHttp   .send();   
		  }   
		  catch(e){;}   
		  }   
		 //containerDiv.innerText=tempStr;   
	  return;   
	  }   

	function c(obj)
	{
		var d=new UpLoadFileCheck(); 
		d.IsImg=true;
		d.AllowImgFileSize=200;
		d.AllowImgHeight=800;
		d.AllowImgWidth=800;
		if(d.CheckExt(obj)==true)
		{
		  PhotoUploader.ChangeImagePreview(obj);
		}
	}


function showSending(optype) {
	if(optype == "send.x" )
	{
		Dialog.showMess();
	}	
	
	}


function setCanshu()
{
    var strContent = $("ctl00$ContentPlaceHolder1$TextBox3").value ;
    strContent = strContent + "===================================================" + String.fromCharCode( 10,13) ;
    strContent = strContent + "相机：" + String.fromCharCode( 10,13) ;
    strContent = strContent + "镜头：" + String.fromCharCode( 10,13) ;
    strContent = strContent + "光圈：" + String.fromCharCode( 10,13) ;
    strContent = strContent + "速度：" + String.fromCharCode( 10,13) ;
    strContent = strContent + "拍摄方式：" + String.fromCharCode( 10,13) ;
    strContent = strContent + "===================================================" + String.fromCharCode( 10,13) ;
    $("ctl00$ContentPlaceHolder1$TextBox3").value= strContent ;
    $("ctl00$ContentPlaceHolder1$TextBox3").focus () ;
}

var Dialog = {
    "init":""
    ,"dialogBox":null
    ,"defWidth":400
    ,"width":0	
    /**
     * 显示窗口
     * @param title 窗口标题
     * @param url   窗口内容页面的URL
     * @param loadCss  是否加载CSS
     * @param loadJs  是否加载JS
	 * @param callbac  是否加载JS
     **/
    ,"show":function(title, url, loadCss, loadJs) {
		
        if (this.dialogBox == null) {
            //窗口不存在，自动创建
            this.create();
        }
        
        this.setWidth(this.defWidth);   //默认宽度

        

        this.dialogBox.style.display = "block";    //显示窗口
        
        this.setTitle(title); //设置标题
        
        this.loading = setTimeout("Dialog.setLoading()", 200);  //200毫秒内数据没有加载就会显示“数据加载中...”
        
        Drag.init(document.getElementById("draghead"), this.dialogBox);

        this.dialogBox.onDragEnd=function(x,y){
          Dialog.dialogBox.ox=x-Dialog.getRange().left;
          Dialog.dialogBox.oy=y-Dialog.getRange().top;
        }
        this.center();   //当浏览器不是在第一屏的位置显示窗口会看不见，所以要让它自动在当前屏幕的中间显示
        this.loadContent(url, loadCss, loadJs);  //加载窗口内容
    }
    ,"showMess":function()
       { 
        if (this.dialogBox == null) {
            //窗口不存在，自动创建
            this.create();
        }
        
        this.setWidth(200);   //默认宽度
        this.setContent("正在处理上传数据....");

        this.dialogBox.style.display = "block";    //显示窗口       
         Drag.init(document.getElementById("draghead"), this.dialogBox);
         this.dialogBox.onDragEnd=function(x,y){
          Dialog.dialogBox.ox=x-Dialog.getRange().left;
          Dialog.dialogBox.oy=y-Dialog.getRange().top;
        }
        this.center();  //当浏览器不是在第一屏的位置显示窗口会看不见，所以要让它自动在当前屏幕的中间显示
        
       }
       ,"Fraem":function(w,url)
       { 
        if (this.dialogBox == null) {
            //窗口不存在，自动创建
            this.create();
        }
        
        this.setWidth(w);   //默认宽度
        this.setContent('<iframe src=""+url+"" name="top" width="100%" height="100%" scrolling="no" frameborder="0" id="Iframe1"></iframe>..');

        this.dialogBox.style.display = "block";    //显示窗口       
         Drag.init(document.getElementById("draghead"), this.dialogBox);
         this.dialogBox.onDragEnd=function(x,y){
          Dialog.dialogBox.ox=x-Dialog.getRange().left;
          Dialog.dialogBox.oy=y-Dialog.getRange().top;
        }
        this.center();  //当浏览器不是在第一屏的位置显示窗口会看不见，所以要让它自动在当前屏幕的中间显示
        
       }
    ,"setWidth":function(width) {
        if (width != this.width) {
            this.width = width;
            this.dialogBox.style.width = width+"px";
            this.center();
            
        }
        
    }
    ,"loading":null
    ,"setLoading":function() {
        this.setContent(" &nbsp;&nbsp;&nbsp;&nbsp;数据加载中...");
    }
    ,"clearLoading":function() {
        if (this.loading != null) {
            clearTimeout(this.loading);
            this.loading = null;
        }
    }

    /**
     *  加载窗口内容
     */
    ,"loadContent":function(url, loadCss, loadJs) {  
			url2=url;
			if (url.indexOf("?")>-1) url+="&"+(new Date().getTime());
 			else url+="?"+(new Date().getTime());
			var xhttp=makeRequest();
			xhttp.onreadystatechange=function(){
				if(xhttp.readyState == 4 && (xhttp.status==200 || window.location.href.indexOf("http")==-1))
				{
					Dialog.clearLoading();
					getElement("dialogBox_content").innerHTML=xhttp.responseText;
					else_czlx=1;
					if (loadCss){
               			 Dialog.loadCss(url2+".css");
            		}
					if (loadJs) {
                Dialog.loadJs(url2+".js");
           			}					
				}
			}
			xhttp.open("GET",url,true);
			xhttp.send(null);
        //使用GET方式会有缓存问题，所以要使用POST
    }
    /**
     * 设置窗口内容（提示信息）.
     */
    ,"setContent":function(content) {
        document.getElementById("dialogBox_content").innerHTML = "<div class='dialogBox_Content'>"+content+"</div>";    
    }

    /**
    * 关闭窗口
    **/
    ,"close":function() {
        if (this.dialogBox != null) {
            this.dialogBox.style.display = "none";
        }
		admin_select_yc(1);
    }
    /**
    * 设置窗口的标题
    * @html  窗口的标题，支持HTML
    */
    ,"setTitle":function(html) {
        document.getElementById("dialogBox_title").innerHTML = html;
    }
    

    /**
    * 创建窗口
    */
    ,"create":function() {
        //this.loadCss("/bbs/css/dialog.css");
        var dialogBox = document.createElement("DIV");
        dialogBox.id = "dialogBox";
        dialogBox.className = "dialogBoxBg";
        var html = '<div id="draghead"  style="PADDING-RIGHT:1px;PADDING-LEFT:1px;PADDING-BOTTOM:1px;PADDING-TOP:1px;z-index:1001;"><div style="PADDING-RIGHT:10px;PADDING-LEFT:10px;PADDING-BOTTOM:10px;WIDTH:300px;PADDING-TOP:10px;TEXT-ALIGN:center;border:solid 1px #000; background-color:#FFF"	id="dialogBox_content"><img src="images/ajax-loading.gif" align="absMiddle"></div></div>';
        dialogBox.innerHTML = html;
        
        document.body.appendChild(dialogBox); 

        this.dialogBox = document.getElementById("dialogBox");


        this.center();  //设置窗口位置

        window.onscroll=Dialog.onBodyScroll;
    }
    
    /**
    * 加载CSS
    */
    ,"loadCss":function(filename) {
        var head = document.getElementsByTagName('HEAD').item(0);
        var style = document.createElement('link');
        style.href = filename;
        style.rel = 'stylesheet';
        style.type = 'text/css';
        head.appendChild(style);
    }
    /**
     * 加载JS
     * @param filename 脚本URL
     */
    ,"loadJs":function(filename) {
        var script = document.getElementById("js1");   //应该将filename MD5编码后作为ID使用
        if (script == null) {
            script = document.createElement("script");
        }
        script.id = "js1";
        script.src = filename;
        
        //为什么要使用insertAdjacentElement？,因为appendChild在JS文件已经存在浏览器缓存时就会出现IE崩溃的情况(Bbs.editArticle方法就会出现,postArticle则正常)
        if (document.frames) {
            document.body.insertAdjacentElement("BeforeBegin",script);
        }
        else {
            document.body.appendChild(script);  //
        }
    }
    ,"onBodyScroll":function(){
        var range=Dialog.getRange();
        var top = (range.top+Dialog.dialogBox.oy);
        var left = (range.left+Dialog.dialogBox.ox);
        if (top < 5) { top  = 5; }
        if (left< 5) { left = 5; }
        
        Dialog.dialogBox.style.top=top +"px";
        Dialog.dialogBox.style.left=left +"px";

        //document.title = "scroll:"+top;
    }

    /**
     *  设置窗口居中显示
     */
    ,"center":function() {
        var range=Dialog.getRange();

        var left = (range.width-this.width)/2;
        var top  = (range.height-400)/2;

        this.dialogBox.ox= left;
        this.dialogBox.oy= top;

        if (range.left > left) { left = range.left+left;}
        if (range.top  > top ) { top  = range.top +top;}

        this.dialogBox.style.left = left + "px";
        this.dialogBox.style.top = top + "px";

        //document.title = "center:"+top;
    }
    /**
     * 移动窗口位置
     * @left 
     * @top 
     */
    ,"move":function(left, top) {
        this.dialogBox.ox= left;
        this.dialogBox.oy= top;

        this.dialogBox.style.left = left + "px";
        this.dialogBox.style.top = top + "px";
    }


    ,"getRange":function() {
        var top     = document.documentElement.scrollTop;
        var left    = document.documentElement.scrollLeft;
        var height  = document.documentElement.clientHeight;
        var width   = document.documentElement.clientWidth;

        if (top==0 && left==0 && height==0 && width==0) {
            top     = document.body.scrollTop;
            left    = document.body.scrollLeft;
            height  = document.body.clientHeight;
            width   = document.body.clientWidth;
        }
        return  {top:top  ,left:left ,height:height ,width:width } ;
    }

}

var Drag={
        "obj":null,
	"init":function(a, aRoot){
      a.onmousedown=Drag.start;
      a.root = aRoot;
      if(isNaN(parseInt(a.root.style.left)))a.root.style.left="0px";
      if(isNaN(parseInt(a.root.style.top)))a.root.style.top="0px";
      a.root.onDragStart=new Function();
      a.root.onDragEnd=new Function();
      a.root.onDrag=new Function();
		},
	"start":function(a){	
			var b=Drag.obj=this;
			a=Drag.fixE(a);
			var c=parseInt(b.root.style.top);
			var d=parseInt(b.root.style.left);
			b.root.onDragStart(d,c,a.clientX,a.clientY);
			b.lastMouseX=a.clientX;
			b.lastMouseY=a.clientY;
			document.onmousemove=Drag.drag;
			document.onmouseup=Drag.end;
			return false;
		},	
	"drag":function(a){
			a=Drag.fixE(a);
			var b=Drag.obj;
			var c=a.clientY;
			var d=a.clientX;
			var e=parseInt(b.root.style.top);
			var f=parseInt(b.root.style.left);
			var h,g;
			h=f+d-b.lastMouseX;
			g=e+c-b.lastMouseY;
			b.root.style.left=h+"px";
			b.root.style.top=g+"px";			
			b.lastMouseX=d;
			b.lastMouseY=c;
			b.root.onDrag(h,g,a.clientX,a.clientY);
			return false;
		},
	"end":function(){			
			document.onmousemove=null;
			document.onmouseup=null;
			Drag.obj.root.onDragEnd(parseInt(Drag.obj.root.style.left),parseInt(Drag.obj.root.style.top));
			Drag.obj=null;
		},
	"fixE":function(a){
			if(typeof a=="undefined")a=window.event;
			if(typeof a.layerX=="undefined")a.layerX=a.offsetX;
			if(typeof a.layerY=="undefined")a.layerY=a.offsetY;
			return a;
		}
};

