var edi_upload_xmlload;
var edi_upload_browser = (window.ActiveXObject)?true:false;
var edi_upload_files = false;
var edi_upload_inint,edi_upload_parint,edi_upload_partime;
var edi_type_s,edi_type_sp;
var edi_regin_time,edi_reginchange;
var edi_difnewtext = true;


//随机产生一个文件名称
function edi_editnewfilename() {
	var newFileName = "";
	var allTotal = "abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ1234567890";
	var decomposition = allTotal.split("");
	for (var i = 0;i < 16;i ++){
			var sRandom = Math.floor(Math.random() * 62);
			newFileName += decomposition[sRandom];
	}
	return newFileName;
}

//是否取不同的图像处理值
function edi_uwidthheight(ret){
		var editype,ew,ew_input,eh,eh_input;
		evalue = ret;
		if (ret !== "null"){
				editype = ret.split(",");
				if (parseInt(editype[0]) == 1){
						ew_input = at.d(editype[1]);
						eh_input = at.d(editype[2]);
						if (ew_input)ew = ew_input.value;
						if (eh_input)eh = eh_input.value;
						if (ew == "" || eh == ""){
								parent.az.error(2,"","请先设置图片的尺寸！");
						}
				}else{
						ew = editype[1];
						eh = editype[2];
				}
				evalue = (ew == "" || eh == "")?"false":ew + "," + eh;
		}
		return evalue;
}

//js上传完成后返回上传文件的信息
function edi_completeData(ret){
		var returns,ret_html,ret_value,ret_i;
		if (ret !== ""){
				//at.d("ccc").innerHTML = ret;&;
				//name=900x600_6J95TRJQ05RQ0001.jpg&;creator=undefined&;type=.jpg&;size=29781&;creationDate=Thu Oct 21 00:44:20 GMT+0800 2010&;modificationDate=Thu Oct 21 00:43:35 GMT+0800 2010&;newfilenames=nDoMW1MvTTxCgwdb&;newfiletype=photo&;file_batch=1
				//"name="+file.name+"&;creator="+file.creator+"&;type="+file.type+"&;size="+file.size+"&;creationDate="+file.creationDate+"&;modificationDate="+file.modificationDate+"&;newfilenames="+maptype+"&;newfiletype="+up_sty+"&;file_batch="+photourl+"&;uploadid="+up_id+"&;imageedit="+photoedit+"&;up_editor="+up_editor+""
				//原文件名，后缀，大小，新文件名，类型，上传路径，id
				returns = ret.split("&;");
				ret_value = Array();
				ret_i = 0;
				for (var i = 0;i < returns.length;i ++){
						ret_html = returns[i].split("=");
						if (i == 0 || i == 2 || i == 3 || i == 6 || i == 7 || i == 8 || i == 9 || i == 10 || i == 11 || i == 12){
								ret_value[ret_i] = ret_html[1];
								ret_i += 1;
						}
				}
				
				edi_tloaddiv(ret_value);
		}else{
				return false;
		}
}

//
//点击上传按钮时，同步当前input与上层input的值，以防止刷新子框架时，上层框架的input的值仍然存在
//regclass = 0时不同步
//判断当前的数量是否超限制了
function edi_regifrinput(regclass){
		var i_input,pr_id,pr_input,regc_type,reg_value;
		regc_type = regclass.split("|");
		if (regc_type[0] * 1 == 1){
				i_input = at.d("upload_more_" + regc_type[1] + "_" + regc_type[2] + "_i");
				//i_input.style.display = "";
				if (zin_editor_class == false){
						pr_id = window.frameElement;
						pr_input = parent.at.d("edi_" + regc_type[1] + "_values_" + pr_id.id + "_" + regc_type[2]);
				}else{
						pr_input = at.d("edi_" + regc_type[1] + "_values_photos_" + regc_type[2]);
				}
				if (i_input && pr_input){
						pr_input.value = i_input.value;
						//
						//超出上传的数量限制了
						reg_value = i_input.value.split("‖‖");
						if (reg_value.length * 1 >= regc_type[3] * 1 && i_input.value !== ""){
								if (zin_editor_class == false){
										parent.az.error(2,"","当前只能上传 " + regc_type[3] + " 个文件，请删除已经上传的文件后重新上传!");
								}else{
										errwindow(1,"当前只能上传 " + regc_type[3] + " 个文件!","请先删除已经上传的文件，然后再重新上传!","");
								}
								return "false";
						}else{
								return "true";
						}
				}
				
		}
}

function edi_reginputedit(i_inputid,ipath,itype,iphsi,oldimages){
		var i_input;
		i_input = at.d("upload_more_" + itype + "_" + iphsi + "_i");
		if (i_input){
				i_input.value = i_inputid;
				edi_reginputedit_i(i_input,ipath,oldimages);
		}
}
function edi_reginputedit_i(objinput,impaths,oldimages){
		var n_input,pr_id,n_name,pr_input;
		if (objinput){
				n_input = objinput.id;
				n_name = n_input.split("_");
				if (zin_editor_class == false){
						pr_id = window.frameElement;
						pr_input = parent.at.d("edi_" + n_name[2] + "_values_" + pr_id.id + "_" + n_name[3]);
				}else{
						pr_input = at.d("edi_" + n_name[2] + "_values_photos_" + n_name[3]);
				}
				if (pr_input)pr_input.value = objinput.value;
				//更新当前图片列表
				edi_reginputedit_photo(objinput.value,objinput.id,n_name[3],((impaths)?impaths:""),oldimages);
		}
}
//
//更新图片列表
function edi_reginputedit_photo(photolist,divid,photoid,photopath,oldimages){
		//取当前input的所有值
		var all_photo,photosrc,ai,phoimage,photodiv_parent;
		var photodiv,phid_obj,newdiv,edvalue,iagesrc,ici,new_icsr,photoinput_a;
		if (zin_editor_class == false){
				edi_type_sp = parent;
		}else{
				edi_type_sp = window;
		}
		if (photolist !== ""){
				all_photo = photolist.split("‖‖");
				photodiv = at.d(divid.replace("_i",""));
				if (photodiv){
						photodiv.innerHTML = "";
						photodiv_parent = photodiv.parentNode;
						if (photodiv_parent)photodiv_parent.style.display = "";
						if (zin_editor_class == false){
								ed_irid = window.frameElement.id + "_" + photoid;
						}else{
								ed_irid = "photos_" + photoid;
						}
						edi_difnewtext = false;
						parent_hiddeninput(photolist,ed_irid);
						for (ai = 0;ai < all_photo.length;ai ++){
								phid_obj = photodiv.id + "_" + ai;
								edvalue = all_photo[ai];
								photosrc = edvalue.split("^^^");
								if (photopath == ""){
										if (photosrc[0].toLowerCase().indexOf("http://") !== -1){
										}else{
												photopath = "../";
										}
								}
								new_icsr = "";
								if (photosrc[2] * 1 == 1){
										iagesrc = photosrc[0].split("/");
										for (ici = 0;ici < iagesrc.length;ici ++){
												new_icsr += (new_icsr == ""?"":"/") + iagesrc[ici] + (((ici * 1) == (iagesrc.length * 1 - 2))?"/min":"");
										}
										new_icsr = new_icsr.replace(".","_0.");
								}else{
										new_icsr = photosrc[0];
								}
								photoinput_a = at.d(photodiv.id + "_a");
								phoimage = "<img src='" + (String(photopath) == "index"?"":photopath) + new_icsr + "' id='" + phid_obj + "_img' width='96' height='96' onclick=\"edi_type_sp.ap.edi_openmaxphoto('" + (String(photopath) == "index"?"":photopath) + "','" + photosrc[0] + "','" + ed_irid + "','" + ((zin_editor_class == false)?window.frameElement.id:"photos") + "',1)\" ><input name='edi_photo_m_as_" + photoid + "' id='edi_photo_m_as_" + photoid + "'  onclick=\"edi_photo_default(this,'" + photodiv.id + "')\" type='radio' value='" + edvalue + "' class='edi_pho_reg' ";
								if (oldimages !== "" && oldimages == edvalue || ai * 1 == 0 && oldimages == ""){
										phoimage += " checked ";
										if (photoinput_a){
												photoinput_a.value = edvalue;
										}
								}
								phoimage += "/><div class='edi_cim_out' onmouseover=\"edi_cse_photos(this,'" + phid_obj + "','" + divid + "','" + photodiv.id + "','" + edvalue + "','" + photosrc[0] + "','" + ed_irid + "')\"></div>";
								//
								//生成一个图像对象
								
								newdiv = at.addobject(phid_obj,phoimage,"edi_upic_a_out edi_cim_w","",photodiv);
								newdiv.onmouseover = function (){
										at.eclass(this,0,1);
								}
						}
				}
		}
		
}


//添加网络图片
//valueclass 不为空时则是从valueimage中取value的值，否则valueimage直接为image的src值
function edi_inwebimage(valueimage,valueclass,valuid){
		var imgsrc = "",imageinput,imgxml;
		if (valueclass == "editor"){
				imageinput = at.d(valueimage);
				if (imageinput){
						if (imageinput.value !== "" && imageinput.value.toLowerCase() !== "http://"){
								imgsrc = imageinput.value;
								imageinput.value = "";
						}
				}
		}else{
				imgsrc = valueimage;
		}
		if (imgsrc !== ""){
				imgxml = Array(imgsrc,"",0,"","photo","","1002" + valuid,0,"../../",1);
				edi_tloaddiv(imgxml,"web");
		}
}


//开始处理
function edi_tloaddiv(htmls,inimage){
		//alert(etype[9]);
		var etype,edivid,ediv_url;
		var photodiv,photoinput,phostr,phoimage,phid_obj,photo_w,newdiv;
		var ed_irid,edvalue,ed_minimg,ed_images,eima_div,eima = 1,eimageurl = "";
		var edi_uploadflash;
		etype = htmls;
		edivid = "upload_more_" + etype[4] + "_" + etype[6] + "_i";
		eimageurl = etype[8];
		eima = parseInt(etype[9]);
		edi_type_s = window;
		if (zin_editor_class == false){
				edi_type_sp = parent;
		}else{
				edi_type_sp = window;
		}
		if (eimageurl == "../../"){
				if (os_browser.os() == "IE" || os_browser.os() == "Firefox"){
						edi_type_s = window.dialogArguments;
				}else{
						edi_type_s = window.opener;
				}
				edi_type_sp = window;
		}
		ediv_url = etype[5] + "/" + etype[3] + etype[1];
		switch(etype[4]){
				//
				//图像 upload_more_photo edi_upic_a_out addobject
				//newobjid,newobjhtml,newclassname,nw,newclass,parend
				case "photo":
						photodiv = at.d("upload_more_photo_" + etype[6]);
						//photodiv.style.display = "";
						photodiv.parentNode.style.display = "";
						//alert(photodiv.id);
						edi_upload_inint = photoinput = at.d(edivid);
						photoinput_a = at.d(edivid.replace("_i","_a"));
						if (edi_upload_partime)clearTimeout(edi_upload_partime);
						if (photodiv){
								edi_difnewtext = true;
								if (eima == 0){
										if (photoinput)photoinput.value = "";
										if (photoinput_a)photoinput_a.value = "";
										if (photodiv)photodiv.innerHTML = "";
								}
								if (zin_editor_class == false){
										ed_irid = edi_type_s.frameElement.id + "_" + etype[6];
								}else{
										ed_irid = "photos_" + etype[6];
								}
								if (!inimage){
										//上传的
										ed_images = ediv_url;
										if (parseInt(etype[7]) == 1){
												ed_minimg = eimageurl + etype[5] + "/min/" + etype[3] + "_0" + etype[1];
										}else{
												ed_minimg = eimageurl + ed_images;
										}
								}else{
										//远程的
										ed_images = ed_minimg = etype[0];
								}
								edvalue = ed_images + "^^^^^^" + ((inimage)?0:etype[7]);
								phostr = photoinput.value.split("‖‖");
								phid_obj = photodiv.id + "_" + ((photoinput.value == "")?"0":phostr.length);
								phoimage = "<img src='" + ed_minimg + "' id='" + phid_obj + "_img' width='96' height='96'>";
								if (eima !== 0){
										phoimage += "<input name='edi_photo_m_as_" + etype[6] + "' id='edi_photo_m_as_" + etype[6] + "' onclick=\"edi_photo_default(this,'" + edivid + "')\" type='radio' value='" + edvalue + "' class='edi_pho_reg' ";
										if (photoinput.value == ""){
												phoimage += " checked ";
												if (photoinput_a){
														photoinput_a.value = edvalue;
												}
										}
										phoimage += "/><div class='edi_cim_out' onmouseover=\"edi_cse_photos(this,'" + phid_obj + "','" + photoinput.id + "','" + photodiv.id + "','" + edvalue + "','" + eimageurl + "','" + ed_irid + "')\"></div>";
								}
								//
								//生成一个图像对象
								//newdiv = at.addobject(phid_obj,phoimage,"edi_upic_a_out edi_cim_w","",photodiv);
								newdiv = at.addobject(phid_obj,phoimage,"edi_upic_a_out edi_cim_w","",photodiv);
								photoinput.value += (photoinput.value == ""?"":"‖‖") + edvalue;
								photo_w = ((phostr.length + 1) * 130);
								photodiv.style.width = photo_w + "px";
								if (parseInt(etype[6]) < 1000 && eima !== 0){
										if (photo_w * 1 > photodiv.parentNode.clientWidth * 1){
												photodiv.parentNode.style.overflowX = "scroll";
										}
								}
								parent_hiddeninput(edvalue,ed_irid);
								newdiv.onmouseover = function (){
										at.eclass(this,0,1);
								}
								newdiv = at.d(phid_obj + "_img");
								if (newdiv){
										newdiv.onclick = function (){
											
												//
												//全屏弹出的窗口，针对编辑器
												if (edi_type_sp == window){
														if (browser){
																window.dialogWidth = 100;
																window.dialogHeight = 100;
														}else{
																window.moveTo(0,0);
																window.resizeTo(window.screen.width,window.screen.height);
														}
												}
												//传入一组图片也可
												//parent.ap.edi_openmaxphoto(eimageurl,ed_images,ed_irid,edi_type_s.frameElement.id);
												edi_type_sp.ap.edi_openmaxphoto(eimageurl,ed_images,ed_irid,((zin_editor_class == false)?edi_type_s.frameElement.id:"photos"),((edi_type_sp == window)?0:1));
												//
												//当前的记录框需要从上级框架中获值
												//parent_inputsave_p();
										}
								}
						}
				break;
				//flash与媒体文件
				case "media":
				case "flash":
						edi_uploadflash = edi_type_sp.at.d(edivid);
						if (edi_uploadflash){
								edi_uploadflash.value = ediv_url;
						}
				break;
				//其他文件
				case "other":
						edi_uploadflash = at.d(edivid);
						if (edi_uploadflash){
								edi_uploadflash.value = ediv_url;
						}
				break;
		}
			
			
}

function parent_hiddeninput(valuecontent,ifri_id,vclass,vdel_id){
		var thispar,nparet,nip,n_value_ph,n_value_new = "";
		edi_upload_parint = nparet = edi_type_sp.at.d("edi_photo_values_" + ifri_id);
		if (nparet){
				if (vclass == "del"){
						n_value_ph = nparet.value.split("‖‖");
						for (nip = 0;nip < n_value_ph.length;nip ++){
								if (vdel_id * 1 !== nip * 1){
										n_value_new += ((n_value_new == "")?"":"‖‖") + n_value_ph[nip];
								}
						}
						nparet.value = n_value_new;
				}else{
						if (edi_difnewtext == true){
								nparet.value += (nparet.value == ""?"":"‖‖") + valuecontent;
						}
				}
		}else{
				window.setTimeout(function (){
						edi_upload_parint = edi_type_sp.at.addobject("","<input type='hidden' name='edi_photo_values_" + ifri_id + "' id='edi_photo_values_" + ifri_id + "' value=\"" + valuecontent + "\">","");
				},100);
		}
}

//取值
function edi_poivlue(photoid){
		var nphoto,nvalue_s,opi,opnew_value = "";
		nphoto = at.d("upload_more_photo_" + photoid + "_i");
		if (nphoto){
				nvalue_s = nphoto.value.split("‖‖");
				for (opi = 0;opi < nvalue_s.length;opi ++){
						if (nvalue_s[opi] !== ""){
								opnew_value += ((opnew_value == "")?"":"‖‖") + nvalue_s[opi];
						}
				}
				return opnew_value;
		}else{
				return "";
		}
}

//选当前图片为默认
function edi_photo_default(obj,prdiv_id){
		var prar_div;
		prar_div = at.d((prdiv_id.indexOf("_i") !== -1)?prdiv_id.replace("_i","_a"):prdiv_id + "_a");
		if (prar_div){
				if (obj.checked == true){
						prar_div.value = obj.value;
				}
		}
}

//关闭图片
function edi_cse_photos(obj,ophoto_id,oinput_id,odiv_id,ourl_value,eimageurl,vid){
		var inputid,ophostr,odiv,opi,photo_w,innew_div,indel_id,opnew_value = "";
		at.eclass(obj,0,1);
		obj.onmousedown = function (){
				at.zindexcloseclear(at.d(ophoto_id));
				inputid = at.d(oinput_id);
				odiv = at.d(odiv_id);
				if (inputid){
						if (edi_upload_partime)clearTimeout(edi_upload_partime);
						ophostr = inputid.value.split("‖‖");
						for (opi = 0;opi < ophostr.length;opi ++){
								if (ophostr[opi] !== ourl_value && ophostr[opi] + "^^^^^^" !== ourl_value){
										opnew_value += ((opnew_value == "")?"":"‖‖") + ophostr[opi];
								}else{
										indel_id = opi;
								}
						}
						inputid.value = opnew_value;
						parent_hiddeninput("",vid,"del",indel_id);
						photo_w = ((ophostr.length) * 130);
						odiv.style.width = photo_w + "px";
						if (photo_w * 1 <= (odiv.parentNode.clientWidth * 1 - 130)){
								odiv.parentNode.style.overflowX = "hidden";
						}
				}
		}
}

//
//提交数据时获取图片路径
function iupload_value(itype,i_id){
		var i_input;
		i_input = at.d("upload_more_" + itype + "_" + i_id + "_i");
		if (i_input){
				return e__c(i_input.value);
		}else{
				return "";
		}
}

//
//清除当前表单
function inpload_clear(objname){
		var i_input;
		i_input = at.d(objname);
		if (i_input)i_input.value = "";
}

//测试
function cc(c){
		alert(c);
}

//
//上传图片？




