var __Upload = {
    Control : function (v,n,action){
        var s = new Array();
        s.push('<div id="ajaxUploadControlItems">');
        for(var i = 0; i< parseInt(n); i++)
        {
            s.push('<div class="item" id="ajaxUploadPanel">');
           
            s.push('<p style="text-align:left;"><img src="../images/nopic.gif" alt="图片预览" id="ajaxResultView' + i + '" class="img"   width="100px"; height="100px"/></p>');
//            s.push('<p><img src="/images/upsm.gif" id="btnAjaxUploadBottom' + i + '" alt="上传图片" title="上传图片" class="hand" /> </p>');
            s.push("<p  style=\"text-align:left; margin-top:-15px;\"><iframe src=\"../upload.aspx?id="+ i + "&action=true\" id=\"ifUpload" + i + "\" frameborder=\"no\" scrolling=\"no\" style=\"width:400px; height:28px;\"></iframe><div class=\"uploading\" id=\"uploading"+ i + "\" style=\"display:none;\" ></div> </p>");
            s.push('<input id="ajaxHiddenResultUrl' + i + '" name="ajaxHiddenResultUrl' + i + '" type="hidden" runat="server" /></div>');
        }
       // s.push('<div id="ajaxUploadControl" style=\" margin-top:-40px;\">默认上传图片格式：<font color="red">jpg</font> | <font color="red">jpeg</font> | <font color="red">gif</font> ，大小以500K以内为宜。</div></div>');
        $("#" + v).html(s.join("")).show("slow");
        var me = this;
        for(var i = 0; i < parseInt(n); i++)
            $("#btnAjaxUploadBottom" + i).bind("click", 
            function()
            {
            var url = new me.Operation();url.Create(this.id.replace("btnAjaxUploadBottom",""),action);
            }
         );
            
            var hidImg = document.getElementById("ctl00_ContentPlaceHolder1_hidImg");
         
        if(hidImg.value=="")return;
       
        
        var AryImg = hidImg.value;
      
    
    
    
        for(var i=0;i<AryImg.length;++i)
        {
            $("#ajaxResultViewLink" + i).attr("href",AryImg.replace("s_",""));
            $("#ajaxResultView" + i).attr("src",AryImg);
            $("#ajaxHiddenResultUrl" +  i).val(AryImg);
        }
    
          
           
    },
    Operation : function(){
        var currItemID = 1; 
        var loadingUrl = "../images/loading.gif";
        var me = this;
        this.Create = function(itemid,action)
        {
            currItemID ++;
            if(itemid == null) itemid = currentItemID;
            $("#ajaxUploadControl").html(action ? "<iframe src=\"/upload.aspx?id=" + itemid + "&action=true\" id=\"ifUpload" + itemid + "\" frameborder=\"no\" scrolling=\"no\" style=\"width:400px; height:28px;\"></iframe><div class=\"uploading\" id=\"uploading" + itemid + "\" style=\"display:none;\" ></div>" : "<iframe src=\"/upload.aspx?id=" + itemid + "&action=\" id=\"ifUpload" + itemid + "\" frameborder=\"no\" scrolling=\"no\" style=\"width:400px; height:28px;\"></iframe><div class=\"uploading\" id=\"uploading" + itemid + "\" style=\"display:none;\" ></div>");
        }
        this.uploading = function(imgsrc,itemid)
        {
            var el = $("#uploading" + itemid);
            $("#ifUpload" + itemid).fadeOut("fast");
            el.fadeIn("fast");
            el.html("<img src='" + loadingUrl + "' align='absmiddle' /> 上传中...");
            return el;
        }
        this.uploadSuccess = function(SourceImage,ThumbnailImage,WaterAndFontImage,WaterFontImage,WaterImage,itemid,action)
        {
            $("#uploading" + itemid).html("上传成功. <a href='javascript:void(0);' id='ajaxUploadArgin" + itemid + "'>[<font color='red' title='重新上传'>重新上传</font>]</a>");
            $("#ajaxUploadArgin" + itemid).bind("click", function(){me.uploadArgin(itemid);});
            this.Result(SourceImage,ThumbnailImage,WaterAndFontImage,WaterFontImage,WaterImage,itemid,action)
        }
        this.uploadError = function(itemid)
        {
            alert("error: " + itemid + " upload error");
            this.uploadArgin(itemid);
        }
        this.uploadArgin = function(itemid)
        {
            currItemID ++;
            $("#uploading" + itemid).fadeOut("fast",function(){$("#ifUpload" + itemid).fadeIn("fast");$("#panelViewPic" + itemid).fadeOut("fast");});
        }
        this.Result = function(SourceImage,ThumbnailImage,WaterAndFontImage,WaterFontImage,WaterImage,itemid,action)
        {
            var picurl = "";
            var re = /^.+.(gif|jpg|jpeg)$/i; 
            if(re.test(SourceImage))
                picurl = SourceImage;
            else if(re.test(ThumbnailImage))
                picurl = ThumbnailImage;
            else if(re.test(WaterAndFontImage))
                picurl = WaterAndFontImage;
            else if(re.test(WaterFontImage))
                picurl = WaterFontImage;
            else if(re.test(WaterImage))
                picurl = WaterImage;
            else
                picurl = "/themes/deepblue/nopic.gif";
            if(action == "true")
            {
                SourceImage = re.test(SourceImage) ? SourceImage : "../images/nopic.gif";
                $("#ajaxResultView" + itemid).attr("src",SourceImage);
                var o = document.getElementById("PicUrl");
                if(o) $("#PicUrl").val(SourceImage);
                $("#ajaxHiddenResultUrl" +  itemid).val(SourceImage);
               
                  var hidImg = document.getElementById("ctl00_ContentPlaceHolder1_hidImg");
                    hidImg.value = "";
                 hidImg.value+= document.all("ajaxHiddenResultUrl" +  itemid).value;
               
                   
            }
            else
            {
                ThumbnailImage = re.test(ThumbnailImage) ? ThumbnailImage : "";
                SourceImage = re.test(SourceImage) ? SourceImage : "";
                WaterAndFontImage = re.test(WaterAndFontImage) ? WaterAndFontImage : "";
                WaterFontImage = re.test(WaterFontImage) ? WaterFontImage : "";
                $("#ajaxResultView" + itemid).attr("src",picurl);
                $("#ajaxHiddenResultUrl" +  itemid).val(ThumbnailImage + "|" + SourceImage + "|" + WaterAndFontImage + "|" + WaterFontImage);
                  var hidImg = document.getElementById("ctl00_ContentPlaceHolder1_hidImg");
                   hidImg.value = "";
                hidImg.value+= document.all("ajaxHiddenResultUrl" +  itemid).value;
              
            }
        }
        
        
    }
}