var minoer_count = 0;
var maxoer_count = 0;
var maxoer_arrayid = "";
var loadintimes1,loadintimes2;
var errwindowsizes;
var usermess_closethispage = true,usermess_closethispage1 = false;
//
//弹出操作窗口，不过先要判断是否有信息提示窗口，如果有则先关闭信息提示窗口
//zindexerror
//操作窗口需要加上滚动窗口的高度
function ewindow_text(winhtml,winsize,closeclass,ipath){
		var ewdiv,ewsize,nwsize;
		zindextwindow = at.d("iw_windowid");
		ewsize = Array(document.documentElement.clientWidth,document.documentElement.clientHeight,document.documentElement.scrollHeight,document.documentElement.scrollTop,window.screen.availHeight);
		errwindow_close(zindexerror);
		if (zindextwindow){
				at.zindexcloseclear(zindextwindow);
		}
		if (errwindowtoptime){
				clearTimeout(errwindowtoptime);
		}
		if (parseInt(ewsize[2]) < parseInt(ewsize[4])){
				ewsize[2] = ewsize[4];
		}
		nwsize = Array(parseInt((ewsize[0] - winsize[0])/2),parseInt((ewsize[1] - winsize[1])/2) + ewsize[3]);
		ewdiv = "<div class='iw_bg' style='width:" + ewsize[0] + "px;height:" + ewsize[2] + "px;'></div>";
		ewdiv += "<div class='iw_window' style='width:" + winsize[0] + "px;height:" + winsize[1] + "px;left:" + nwsize[0] + "px;top:" + nwsize[1] + "px;' id='iw_windowall'>";
				ewdiv += "<div class='iw_body' style='width:" + (winsize[0] - 9) + "px;height:" + (winsize[1] - 9) + "px;' id='iw_windowbody'>" + winhtml + "</div>";
				if (closeclass !== 1){
						ewdiv += "<div class='iw_close iw_close_out' onmouseover='at.eclass(this,0,1)' onclick='ewindow_fun();ewindow_textclose();' ></div>";
				}
		ewdiv += "</div>";
		zindextwindow = at.addobject("iw_windowid",ewdiv,"","","","","");
		errwindowsizes = winsize[1];
		ewindow_srtop(winsize[1],ewsize[1]);
}

//
//弹出窗口始终在页面中
function ewindow_srtop(objheight,winheight){
		var wintop,windiv;
		windiv = at.d("iw_windowall");
		wintop = document.documentElement.scrollTop;
		if (!winheight)winheight = document.documentElement.clientHeight;
		windiv.style.top = parseInt(parseInt((winheight - objheight)/2) + wintop) + "px";
		errwindowtoptime = window.setTimeout(function(){ewindow_srtop(objheight,winheight)},10);
}

//
//拖动滚动条时禁用
function mobiledivtopnot(obj){
		if (errwindowtoptime){
				clearTimeout(errwindowtoptime);
		}
		obj.onmouseup = function (){
				ewindow_srtop(errwindowsizes);
		}
}

//
//用户登陆框
function loading_userlogin(path){
		var ndiv,topdiv,indiv;
		window.setTimeout(
				function(){
						xmlposthtml = at.xmlhttps(((path)?path:"") + "inc/user/userload.php?type=loginuser&path=" + path + "",true,"user=true");
						nsyhtml = function (){
								ndiv = at.addobject("",at.loadajax_xml(xmlposthtml),"","","","","none");
								topdiv = Array(at.d("load_usertopindex"),at.d("load_usershopindex"));
								indiv = Array(at.d("usertopindex"),at.d("usershopindex"));
								if (topdiv[0] && indiv[0]){
										indiv[0].innerHTML = topdiv[0].innerHTML;
								}
								if (topdiv[1] && indiv[1]){
										indiv[1].innerHTML = topdiv[1].innerHTML;
								}
								at.zindexcloseclear(ndiv,1);
								//
								//用户的竞拍数据更新
								//可整合到用户在线统计中
								//window.setTimeout(function(){loading_userauc(((path)?path:""));},500);
						}
						at.xmlposts("nsyhtml()");
				}
		,100);
		
		
}

//
//弹出用户登陆窗口，如果已经弹出窗口则直接更新窗口的内容
function user_loadwin(loghtml,pagenames,objectid,ipath){
		var userhtml;
		//如果有弹出的窗口则先关闭弹出窗口
		ewindow_textclose();
		at.loadjavacss(((!ipath)?"../":ipath) + "inc/js/reglogin.js","js");
		//打开登陆的窗口
		if (!loghtml || loghtml == ""){
				xmlposthtml = at.xmlhttps(((!ipath)?"../":ipath) + "inc/user/userload.php?type=loginwindow&id=" + objectid,true,"user=true&pagenames=" + e__c(pagenames));
				nsyhtml = function (){
						ewindow_text(xmlposthtml,Array(720,450));
						evalscript(xmlposthtml,1);
				}
				at.xmlposts("nsyhtml()");
		}else{
				ewindow_text(loghtml,Array(720,450));
		}
}

//
//取更多的值（显示更多内容）
//urltextin:取值的类型（格式在upload.php文件中查看）
//divname：赋值的div对象
function openalltexts(obj,urltextin,urlclass,divname,zoomclass,ipath){
		var divs,ndiv,hhtml,sinput;
		divs = at.d(divname);
		if (divs){
				xmlposthtml = at.xmlhttps(((!ipath)?"../":ipath) + "inc/const.load.php?type=openalltext_list",true,"urltextin=" + (urltextin + "," + urlclass + "," + divname + "," + zoomclass));
				nsyhtml = function (){
						if (urlclass == 0){
								ndiv = at.addobject("",xmlposthtml,"","","","","none");
								sinput = at.d(divname + "_input");
								if (sinput){
										hhtml = sinput.value;
								}
								at.zindexcloseclear(ndiv);
						}else{
								hhtml = xmlposthtml;
						}
						divs.innerHTML = hhtml;
						obj.onclick = "";
						obj.onclick = function (){
								openalltexts(this,urltextin,urlclass,divname,(zoomclass == 0?1:0),ipath);
						}
				}
				at.xmlposts("nsyhtml()");
		}
}

//
//加载高级搜索信息
function loading_searchall(ipath){
		var searchclass,advanced_div;
		searchclass = at.d("searchclass");
		advanced_div = at.d("advanced_div");
		if (advanced_div){
				xmlposthtml = at.xmlhttps(((!ipath)?"../":ipath) + "inc/const.load.php?type=searchall&classtype=" + searchclass.value,true,"user=true");
				nsyhtml = function (){
						advanced_div.innerHTML = xmlposthtml;
						evalscript(xmlposthtml,1);
				}
				at.xmlposts("nsyhtml()");
		}
}

//
//执行ajax返回数据中的script代码
//ajaxhtml:返回的数据
//evalclass:留空为执行(<script><//script>)，否则执行(<script_ajax><//script_ajax>)
function evalscript(ajaxhtml,evalclass){
		var newjs,ni,replsc,evclass;
		evclass = (!evalclass)?"script":"script_ajax";
		if (!browser){
				ajaxhtml = ajaxhtml.replace(/[\r\n]/g,'');
		}
		if (!evalclass){
				newjs = ajaxhtml.match(/\<script((.|\n)*?)\<\/script\>/gi);
		}else{
				newjs = ajaxhtml.match(/\<script_ajax((.|\n)*?)\<\/script_ajax\>/gi);
		}
		if (newjs){
				for (ni = 0;ni < newjs.length;ni ++){
						replsc = newjs[ni].replace("<" + evclass + ">","");
						replsc = replsc.replace("</" + evclass + ">","");
						eval(replsc);
				}
		}
}


//
//用户竞拍数据更新
//load_reluser_data("1,0,0",0,ipath);
//function loading_userauc(ipath){
//		xmlposthtml = at.xmlhttps(((!ipath)?"../":ipath) + "inc/const.load.php?type=user_aucloading",true,"user=true");
//		nsyhtml = function (){
//				//alert(xmlposthtml);
//				//divs.innerHTML = xmlposthtml;
//		}
//		at.xmlposts("nsyhtml()");
//}

//
//用户活动记录
//记录用户在线信息
//load_reluser_data("0,1,0",0,ipath);
//function loadsave_userrec(ipath){
//		xmlposthtml = at.xmlhttps(((!ipath)?"../":ipath) + "inc/const.load.php?type=onlineuser",true,"pageurl=" + at.jsurl(ajaxpage_url));
//		window.setTimeout(function(){loadsave_userrec(ipath)},20000);
//}

//
//更新用户竞拍
//更新用户活动记录和在线
//更新用户的短信息
//
//将用户更新信息整合到一起
//relclass = "1,1,1";
//reltime:0=不重复，>0重复
//load_reluser_data("0,1,0",0);
function load_reluser_data(relclass,reltime,ipath){
		var nreclass = relclass.split(",");
		var path = ((!ipath && ipath !== "")?"../":ipath);
		xmlposthtml = at.xmlhttps(path + "inc/const.load.php?type=reluserall&classtype=" + relclass + "&action=" + path,true,"user=true");
		//
		//短信息才执行下面的
		if (parseInt(nreclass[1]) == 1){
				//alert(xmlposthtml);
				usermess_relclassmess(0,ipath);
		}
		//
		//是否需要更新
		if (parseInt(reltime) > 0){
				window.setTimeout(function(){load_reluser_data(relclass,reltime,ipath)},parseInt(reltime));
		}
}

//
//用户的短信息提示
function usermess_relclassmess(clseclass,ipath){
		var newdiv,messinput,messdiv,messvalue = 0;
		var nremesserrid = 0;
		newdiv = at.d("usermess_bodydivs");
		if (clseclass == 1){
				if (newdiv){
						(browser)?newdiv.filters.Alpha.Opacity = 100:newdiv.style.opacity = 1;
						at.zindexopacity(newdiv,0,"none");
				}
				usermess_closethispage = false;
		}else if (clseclass == 2){
				if (newdiv){
						if (newdiv.style.display == "none"){
								(browser)?newdiv.filters.Alpha.Opacity = 0:newdiv.style.opacity = 0;
								newdiv.style.display = "";
								at.zindexopacity(newdiv,1);
								usermess_relclassmess_close(1,ipath);
						}
				}
				usermess_closethispage = true;
		}else{
				//
				//
				nsyhtml = function (){
						//alert(xmlposthtml);
						//
						//判断有没有短信，如果有则弹出短信窗口
						if (newdiv){
								newdiv.innerHTML = xmlposthtml;
						}else{
								newdiv = at.addobject("usermess_bodydivs",xmlposthtml,"user_mess_body_div","","","","none");
						}
						messinput = at.d("usermess_bodyinputs");
						if (messinput){
								//1表示有，2表示没有
								messvalue = parseInt(messinput.value);
								if (messvalue > 0){
										messdiv = Array(at.d("usermess_bodyicos"),at.d("usermess_bodydivs_bo"));
										if (messdiv[0]){
												//有
												//user_mess_body_ico_1 op_out
												//1=有，弹出窗口，3=有，但暂时不显示
												if (messvalue == 1 || messvalue == 3){
														at.editclassname(messdiv[0],"_2","_1");
														nremesserrid = messvalue;
														messdiv[0].onmouseover = function(){
																usermess_relclassmess(2,ipath);
														}
														//
														//usermess_bodydivs_bo
														//取坐标
														var larsize,bodody;
														larsize = Array(at.setparentop(messdiv[0]),at.setparenleft(messdiv[0]));
														//alert(larsize[0] + "," + larsize[1]);
														//alert(parseInt(larsize[0] + 9) + "," + parseInt(larsize[0] - 33));
														//top:21px;left:380px;
														//12,413
														messdiv[1].style.top = parseInt(larsize[0] + 9) + "px"; 
														messdiv[1].style.left = parseInt(larsize[1] - 33) + "px"; 
														//messdiv[1].style.left = "px"; 
														
												}else{
												//没有
												//user_mess_body_ico_2 op_out
												//if (messvalue == 2){
														at.editclassname(messdiv[0],"_1","_2");
														messdiv[0].onmouseover = function(){
																at.eclass(this,0,1);
														}
												}
										}
								}
								messinput.id = "";
								messinput = null;
						}
						if (nremesserrid == 1){
								if (usermess_closethispage == true){
										if (newdiv){
												if (usermess_closethispage1 == false){
														(browser)?newdiv.filters.Alpha.Opacity = 0:newdiv.style.opacity = 0;
														newdiv.style.display = "";
														at.zindexopacity(newdiv,1);
														usermess_closethispage1 = true;
												}else{
														newdiv.style.display = "";
												}
										}
								}
								
						}else if (nremesserrid !== 3){
								newdiv.id = "";
								newdiv.innerHTML = "";
								newdiv = null;
						}
				}
				at.xmlposts("nsyhtml()",true);
		}
}

//
//closeclass=0:关闭短信息提示显示窗口，并且暂时不显示
//closeclass=1:已打开窗口，并且继续弹出窗口提示（与上面的相反）
function usermess_relclassmess_close(closeclass,ipath){
		if (closeclass == 0)usermess_relclassmess(1,ipath);
		window.setTimeout(function(){
				at.xmlhttps(((!ipath && ipath !== "")?"../":ipath) + "inc/const.load.php?type=relusermess_close&classtype=" + closeclass,true,"user=true");
		},500);
}

//
//加好友申请
//需要判断是否登陆，当前用户是否已经是好友，当前用户是否允许加好友
function adduser_friends(userid,ipath,irr){
		var serrid;
		ewindow_textclose();
		xmlposthtml = at.xmlhttps(((!ipath)?"../":ipath) + "inc/const.load.php?type=add_userfriend&id=" + userid,true,"user=true");
		nsyhtml = function (){
				//alert(xmlposthtml);
				ewindow_text(xmlposthtml,Array(700,450));
				sinput = at.d("useraddfriends_ok");
				if (sinput){
						ewindow_textclose();
						serrid = parseInt(sinput.value);
						if (serrid == 1){
								errwindow(1,"您不能加自己为好友！","","");
						}else if (serrid == 2){
								errwindow(1,"对方已经是您的好友了！","","");
						}else if (serrid == 3){
								errwindow(1,"对方设置了拒绝好友申请！","","");
						}else if (serrid == 4){
								errwindow(1,"您已经给对方发送过好友请求了，请等待对方回应！","","");
						}else{
								errwindow(0,"好友申请已发送！","您已经向对方发送了好友加入申请，请等待对方回应。","查看我的短信|" + ((!ipath)?"../":ipath) + "user/?type=user&classtype=sms");
						}
				}
		}
		at.xmlposts("nsyhtml()");
}

//
//关闭弹出窗口后，需要执行的操作
//根据全局变量：winerrclass_id来识别类型
function ewindow_fun(){
		if (winerrclass_id && parseInt(winerrclass_id) > 0){
				switch(winerrclass_id){
						//
						//1:表示是用户解散群组后的页面跳转（跳到用户群组首页）
						case 1:
								at.url("?type=user&classtype=groups");
						break;
				}
				winerrclass_id = 0;
		}
}



//
//处理好load提交的数据，一般是以id集合的方式：1,2,3,4,5,6
//所需要知道的是，每次提交几个，然后就js方法来截取好了
//idarray:ID集合
//sclass:使用直接显示的方式（1），还是带黑色半透明的飘浮层显示进度条（0）
//winaw:进度条的宽度
//posttourl:ajax提交的地址
//postdata:提交的数据（POST方式提交的）
//windivname:如果是直接显示的方式，那么就是将进度条放在哪个div块内
//javas:操作成功后执行的js代码
function loadajax_allid(idarray,sclass,winaw,posttourl,postdata,windivname,javas){
		var allcount,tocount,windiv;
		var allid;
		//
		//现在想怎么取ID的集合，首先要决定每次提交几个ID
		//规则是，数量小于10时，每次提交2个，小于100时，每次提交5个，大于300提交10个每次
		tocount = 1;
		//取当前的集合数量，并要过滤重复的ID以及空的ID
		maxoer_arrayid = allid = at.arraydatanoti(idarray,",");
		allid_count = parseInt(allid.split(",").length);
		if (allid_count > 11 && allid_count < 101){
				tocount = 5;
		}else{
				if (allid_count > 100){
						tocount = 10;
				}
		}
		if (sclass == 1){
				windiv = at.d(windivname);
				if (windiv)windiv.innerHTML = "";
		}
		maxoer_count = allcount = allid_count;
		//
		//allcount:总数量
		//tocount:每次提交的数量
		//sclass:使用直接显示的方式（1），还是带黑色半透明的飘浮层显示进度条（0）
		//windiv：如果是直接显示的方式，那么就是将进度条放在哪个div块内
		//winaw:进度条的宽度
		//posttourl:ajax提交的地址
		//postdata:提交的数据（POST方式提交的）
		loadajaxpost(allcount,tocount,0,sclass,windiv,winaw,Array(posttourl,((postdata == "" || postdata == null)?"arrayid={tourlid}":postdata)),javas);
}

//
//分解loading的id集合，主要有三个值：
//incount:起始序号
//listcount每次处理的量
//maxoer_arrayid:所有的ID集合
function rplsloadid(listcount,incount){
		var inid,inid_i,inid_array = "",inid_count = 0;
		//
		//怎么样操作？
		//1：将集合打散
		inid = maxoer_arrayid.split(",");
		//for
		for (inid_i = 0;inid_i < inid.length;inid_i ++){
				//
				//序号从当前起始id序号开始，从此开始截取
				//截取的数量，是小于当前序号+每次的批量处理数量
				if (parseInt(inid_i) >= parseInt(incount)){
						inid_count += 1;
						//当截取的值超过每次的数量后，退出
						if (parseInt(inid_count) <= parseInt(listcount)){
								//break;
								inid_array += (inid_array == ""?"":",") + inid[inid_i];
						}else{
								break;
						}
				}
		}
		return inid_array;
}

//
//批量生成传递
//allcount:总共,listcount:每次升值
function loadajaxpost(allcount,listcount,lid,winclass,windiv,winaw,postajax,eveljava){
		var l_did,min_number,max_number;
		loadings_image(allcount,listcount,lid,loadings(winaw,allcount,listcount,winclass,windiv),eveljava);
		//
		//起始值
		min_number = minoer_count;
		max_number = min_number * 1 + listcount * 1;
		minoer_count = max_number;
		l_did = lid + 1;
		xmlposthtml = at.xmlhttps(postajax[0],true,postajax[1].replace("{tourlid}",rplsloadid(listcount,min_number)));
		nsyhtml = function (){
				//alert(xmlposthtml);
				//
				if (minoer_count <= maxoer_count){
						loadintimes1 = window.setTimeout(function (){loadajaxpost(allcount,listcount,l_did,winclass,windiv,winaw,postajax,eveljava)},50);
				}
		}
		at.xmlposts("nsyhtml()");
}

//
//loadding进度条
//all_w:总宽度
//all_count:总数量
//l_count:每次增量
function loadings(all_w,all_count,l_count,winclass,windiv){
		var loadbody,loadw,loadtop,l_cous,n_cous,lowidth,lsstr;
		loadbody = at.d("load_page_loading");
		if (!loadbody){
				loadw = Array(document.documentElement.clientWidth,document.documentElement.clientHeight);
				lsstr = loadsmhtmls(all_count,winclass,all_w,loadw,parseInt((loadw[0] - all_w)/2));
				if (winclass == 0){
						loadbody = at.addobject("load_page_loading",lsstr,"umh_load_wi",Array(loadw[0],loadw[1],0,0));
						loadbody.style.zIndex = 10000;
				}else{
						if (windiv){
								loadbody = at.addobject("load_page_loading",lsstr,"umh_load_wi1","",windiv);
						}
				}
		}
		l_cous = n_cous = all_count/l_count;
		if (String(l_cous).indexOf(".") !== -1 && parseInt(l_cous) > 1){
				l_cous = parseInt(String(n_cous).split(".")[0]) + 1;
		}
		lowidth = parseInt(all_w/l_cous);
		return Array(loadbody,lowidth,l_cous,Array(at.d("load_page_loadt"),at.d("load_page_loadt1"),at.d("load_page_loadw")));
}
function loadings_image(allcount,addcount,this_id,loadimageall,erroteml){
		var a_width,a_text,a_text1,this_in_id,btext,nbtext,load_divs;
		this_in_id = this_id + 1;
		//如果增量已经等于最大值
		if (this_in_id * 1 >= loadimageall[2] * 1){
				a_width = a_text1 = "100%";
				a_text = allcount;
		}else{
				a_text = addcount * this_in_id;
				btext = nbtext = String((a_text / allcount)  * 100);
				if (btext.indexOf(".") !== -1){
						nbtext = btext.split(".")[0];
				}
				a_text1 = nbtext + "%";
				a_width = loadimageall[1] * this_in_id + "px";
		}
		load_divs = loadimageall[3];
		if (load_divs[0]){
				load_divs[0].innerHTML = a_text  + " / " + allcount;
				load_divs[1].innerHTML = a_text1;
				load_divs[2].style.width = a_width;
				if (a_width !== "100%"){
						return this_in_id;
				}else{
						if (erroteml && erroteml !== "" && erroteml !== "undefined"){
								//alert("C");
								loadintimes2 = window.setTimeout(function (){
										clearTimeout(loadintimes1);
										clearTimeout(loadintimes2);
										at.zindexcloseclear(loadimageall[0]);
										minoer_count = maxoer_count = 0;
										eval(erroteml);
										return false;
								},1000);
						}
				}
		}else{
				return false;
		}
}

//
//输出loading进度条的样式
//分为两种，一种是进度条飘浮在所有内容的最上方，并有黑色的半透明背景；另一种就是在当前的div块内
function loadsmhtmls(all_count,lclass,all_w,loadw,loadleft){
		var inwinstr,classids,cleft,csize;
		if (lclass == 0){
				classids = "";
				cleft = "left:" + loadleft + "px;";
				csize = "style='width:" + loadw[0] + "px;height:" + loadw[1] + "px;'";
		}else{
				classids = "1";
				cleft = "";
				csize = "";
		}
		inwinstr = "";
		inwinstr += "<div class='umh_load_bg" + classids + "' " + csize + "></div>";
		inwinstr += "<div class='umh_load_body" + classids + "' style='width:" + ((all_w == 0)?"100%":all_w + "px") + ";" + cleft + "'>";
		inwinstr += "<div class='umh_load_inwt'>正在发送通知，请稍候...</div>";
		inwinstr += "<div class='umh_load_inw'><div class='umh_load_in_img' id='load_page_loadw' style='width:1px;'></div></div>";
		inwinstr += "<div class='umh_load_witext1' id='load_page_loadt1'>0%</div><div class='umh_load_witext' id='load_page_loadt'>0 / " + all_count + "</div>";
		inwinstr += "</div>";
		return inwinstr;
		
}

//
//输出用户的最新浏览记录
//每过20秒自动更新一次记录
//objdiv：赋值对象
//objtype:加载类型：4商品，1日志，2相册………………，见inc/global.php文件
//objclass:每个类型下加载不同的样式，具体见具体的加载文件
function loadrecord_list(objdiv,objtype,objclass,ipath){
		var odiv;
		odiv = at.d(objdiv);
		if (odiv){
				xmlposthtml = at.xmlhttps(((!ipath)?"../":ipath) + "inc/const.load.php?type=load_recordlist&classtype=" + objtype + "&action=" + objclass,true,"user=true");
				nsyhtml = function (){
						//alert(xmlposthtml);
						odiv.innerHTML = xmlposthtml;
				}
				at.xmlposts("nsyhtml()");
		}
}



