$(function(){
	startbox();
    $('#zoomtueditor').on("click",".oneCloseBtn",function () {
        $('#wrapeditor').hide();
        $('#zoomtueditor').slideUp('slow');
    });	
});

function startbox(){
	var elmodal = document.createElement('div');
	elmodal.setAttribute("id", "zoomtueditor");
    /*
	elmodal.setAttribute("class", "modaleditor clearfix");ie7不支持
    */
	elmodal.className="modaleditor clearfix";
	document.body.appendChild(elmodal);
	var elwrap = document.createElement('div');
	elwrap.setAttribute("id", "wrapeditor");
	document.body.appendChild(elwrap);	
}

function cfmeditor(upfile) {
        var ztu = $('#zoomtueditor')[0];
        ztu.innerHTML = "";
        var frm = document.createElement("iframe");
        frm.setAttribute("name", "ifr_editor_upload");
        frm.setAttribute("id", "ifr_editor_upload");
        frm.setAttribute("src", "upfile.aspx?save="+upfile);
        frm.setAttribute("marginwidth", "0");
        frm.setAttribute("marginheight", "1");
        frm.setAttribute("width", "320");
        frm.setAttribute("height", "150");
        frm.setAttribute("scrolling", "no");
        frm.setAttribute("border", "0");
        frm.setAttribute("frameborder", "0");
        ztu.appendChild(frm);
	   $('<div class="clear"></div><div class="oneCloseBtn"><a href="javascript:void(0);" rel="nofollow"></a></div>').prependTo($('#zoomtueditor'));
      //  var ifr = window.frames['ifr_editor'];
       // createcfmeditor(ifr,upfile);
    }
    /*
    function createcfmeditor(ifr,upfile) {
        ifr.document.open();
        //  ifr.document.write('<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">\n'); //会提示没有权限
        ifr.document.write('<html>\n');
        ifr.document.write('<head>\n');
        ifr.document.write('<meta http-equiv="Content-Type" content="text/html; charset=gb2312" />\n');
        ifr.document.write('<style>*{margin:0px;padding:0px;}</style>\n');
        ifr.document.write('<script>function check(){if (document.form1.file2.value==""){alert("上传文件不能为空");return false;}}<\/script>\n');
        ifr.document.write('</head>\n');
        ifr.document.write('<body style="padding-top:30px;text-align:center">\n');
        ifr.document.write('<form id="form1" name="form1" method="post" enctype="multipart/form-data" onsubmit="return check();" action="'+upfile+'">\n');
        ifr.document.write('<input type="file" name="file2"  id="file2" value="" style="width:230px;height:22px;"><input style="margin-left:3px;width:73px;height:22px;"  type="submit" name="Submit" value="开始上传" ></form>');
        ifr.document.write('</body>\n');
        ifr.document.write('</html>');
        ifr.document.close();
    }
    */
function upfilebox(upfile){	
	//var text="<iframe  name='ifr' id='ifr' src='"+upfile+"' marginwidth='0' marginheight='0' width='300' height='100' scrolling='no' border='0' frameborder='0'></iframe>";
	cfmeditor(upfile);
	var ztu=$('#zoomtueditor');
	//var text = '<div class="oneCloseBtn"><a href="javascript:void(0);" rel="nofollow"></a></div>';
	//ztu.prependTo(text);	
	 $('#wrapeditor').show();		
	 var w=320;
	 var h=150;
	 ztu.width(w);
	 ztu.height(h);       
	 var br_height=document.documentElement.clientHeight;
	 var topheight =((br_height-(h + 48))/2 +$(document).scrollTop()) + "px";	
	 ztu.css("top", topheight);	
	 ztu.css("margin-left", "-" + (w + 36) / 2 + "px");
	 ztu.fadeIn('slow');
}