var SKIN_PATH = '/changesnet/Tpl/new/Public/'
var isIE = (document.all && window.ActiveXObject && !window.opera) ? true : false;
var isChrome = navigator.userAgent.indexOf('Chrome') != -1;
var isGecko = navigator.userAgent.indexOf('WebKit') != -1;
var dgX = dgY = 0; var dgDiv;



function inputText() {
	document.getElementById('preview').innerHTML += '<div><input type="text" name="text[]" value="输入项名" />&nbsp;&nbsp;<input type="text" style="width:260px;" readonly/><span style="cursor:pointer" onclick="remove(this)">[删除]</span></div>';
}
function inputUpload() {
	document.getElementById('preview').innerHTML += '<div><input type="text" name="upload[]" value="输入认证文件名：" />&nbsp;&nbsp;<input type="text" style="width:260px;" readonly/><img src="{$Think.config.PUBLIC_PATH}/images/upload.png" /><img src="{$Think.config.PUBLIC_PATH}/images/serfdj02.png" /><img src="{$Think.config.PUBLIC_PATH}/images/delete.png" /><span onclick="remove(this)" style="cursor:pointer">[删除]</span></div>';
}
function remove(_element) {
	var parent = _element.parentNode;
	parent.parentNode.removeChild(parent);
}

function mkDialog3(u, c, t, w, s, p, px, py) {
	var w = w ? w : 300;
	var u = u ? u : '';
	var c = c ? c : (u ? '<iframe src="'+u+'" width="'+(w-25)+'" height="0" border="0" vspace="0" hspace="0" marginwidth="0" marginheight="0" framespacing="0" frameborder="0" scrolling="no"></iframe>' : '');
	var t = t ? t : '系统提示';
	var s = s ? s : 0;
	var p = p ? p : 0;
	var px = px ? px : 0;
	var py = py ? py : 0;
	var body = document.documentElement || document.body;
	if(isGecko) body = document.body;
	var cw = body.clientWidth;
	var ch = body.clientHeight;
	var bsw = body.scrollWidth;
	var bsh = body.scrollHeight;
	var bw = parseInt((bsw < cw) ? cw : bsw);
	var bh = parseInt((bsh < ch) ? ch : bsh);
	if(!s) {
		var Dmid = document.createElement("div");
		with(Dmid.style){zIndex = 998; position = 'absolute'; width = '100%'; height = bh+'px'; overflow = 'hidden'; top = 0; left = 0; border = "0px"; backgroundColor = '#EEEEEE';if(isIE){filter = " Alpha(Opacity=50)";}else{opacity = 50/100;}}
		Dmid.id = "Dmid";
		document.body.appendChild(Dmid);
	}
	var sl = px ? px : body.scrollLeft + parseInt((cw-w)/2);
	var st = py ? py : body.scrollTop + parseInt(ch/2) - 100;
	var Dtop = document.createElement("div");
	with(Dtop.style){zIndex = 999; position = 'absolute'; width = w+'px'; left = sl+'px'; top = st+'px'; if(isIE){filter = " Alpha(Opacity=0)";}else{opacity = 0;}}
	Dtop.id = 'Dtop';
	document.body.appendChild(Dtop);
	document.getElementById('Dtop').innerHTML = '<div class="dbody"><div class="dhead" ondblclick="cDialog();" onmousedown="dragstart(\'Dtop\', event);"  onmouseup="dragstop(event);" onselectstart="return false;"><span onclick="cDialog();">'+sound('tip')+'&nbsp;&nbsp;&nbsp;&nbsp;</span>&nbsp;'+t+'</div><div class="dbox">'+c+'</div></div>';
	sDialog('Dtop', 100, '+');
}
function cDialog() {sDialog('Dtop', 100,  '-');}
function sDialog(i, v, t) {
	if(t == '+') {
		if(isIE) {document.getElementById(i).style.filter = 'Alpha(Opacity='+v+')';} else {document.getElementById(i).style.opacity = v/100;}
		if(v == 100) {Eh(); return;}
		if(v+25 < 100) {window.setTimeout(function(){sDialog(i, v+25, t);}, 1);} else {sDialog(i, 100, t);}
	} else {
		try{document.getElementById(i).style.display = 'none'; document.body.removeChild(document.getElementById('Dtop')); document.getElementById('Dmid').style.display = 'none'; document.body.removeChild(document.getElementById('Dmid')); Es();} catch(e){}
	}
}


function mkDialog(u, c, t, w, s, p, px, py) {//p没用 u 内嵌iframe的src； c 显示内容的html； t head的title； w 对话框的宽度； s 是否显示遮罩层； px py 对话框的位置；
	var w = w ? w : 300;
	var u = u ? u : '';
	var c = c ? c : (u ? '<iframe src="'+u+'" width="'+(w-25)+'" height="0" border="0" vspace="0" hspace="0" marginwidth="0" marginheight="0" framespacing="0" frameborder="0" scrolling="no"></iframe>' : '');
	var t = t ? t : '系统提示';
	var s = s ? s : 0;
	var p = p ? p : 0;
	var px = px ? px : 0;
	var py = py ? py : 0;
	var body = document.documentElement || document.body;
	//if(isGecko) body = document.body;
	var cw = body.clientWidth;
	var ch = body.clientHeight;
	var bsw = body.scrollWidth;
	var bsh = body.scrollHeight;
	var bw = parseInt((bsw < cw) ? cw : bsw);
	var bh = parseInt((bsh < ch) ? ch : bsh);

var sttop = document.body.scrollTop | document.documentElement.scrollTop;


	if(!s) {
		var Dmid = document.createElement("div");
		with(Dmid.style){zIndex = 998; position = 'absolute'; width = '100%'; height = bh+'px'; overflow = 'hidden'; top = 0; left = 0; border = "0px"; backgroundColor = '#EEEEEE';if(isIE){filter = " Alpha(Opacity=50)";}else{opacity = 50/100;}}
		Dmid.id = "Dmid";
		document.body.appendChild(Dmid);
	}
	var sl = px ? px : body.scrollLeft + parseInt((cw-w)/2);
	var st = py ? py : sttop + parseInt(ch/2) - 100;
	var Dtop = document.createElement("div");
	with(Dtop.style){zIndex = 999; position = 'absolute'; width = w+'px'; left = sl+'px'; top = st+'px'; if(isIE){filter = " Alpha(Opacity=0)";}else{opacity = 0;}}
	Dtop.id = 'Dtop';
	document.body.appendChild(Dtop);
	document.getElementById('Dtop').innerHTML = '<div class="dbody"><div class="dhead" ondblclick="cDialog();" onmousedown="dragstart(\'Dtop\', event);"  onmouseup="dragstop(event);" onselectstart="return false;"><span onclick="cDialog();">× </span>&nbsp;'+t+'</div><div class="dbox">'+c+'</div></div>';
	sDialog('Dtop', 100, '+');
}
function cDialog() {sDialog('Dtop', 100,  '-');}
function sDialog(i, v, t) {//渐显显示
	if(t == '+') {
		if(isIE) {document.getElementById(i).style.filter = 'Alpha(Opacity='+v+')';} else {document.getElementById(i).style.opacity = v/100;}
		if(v == 100) {Eh(); return;}
		if(v+25 < 100) {window.setTimeout(function(){sDialog(i, v+25, t);}, 1);} else {sDialog(i, 100, t);}
	} else {
		try{document.getElementById(i).style.display = 'none'; document.body.removeChild(document.getElementById('Dtop')); document.getElementById('Dmid').style.display = 'none'; document.body.removeChild(document.getElementById('Dmid')); Es();} catch(e){}
	}
}
function Dalert(c, w, s, t) {
	if(!c) return;
	var s = s ? s : 0; var w = w ? w : 350; var t = t ? t : 0;
	c = c + '<br style="margin-top:5px;"/><input type="button" class="btn" value=" OK " onclick="cDialog();"/>';
	mkDialog('', c, '', w, s);
	if(t) window.setTimeout(function(){cDialog();}, t);
}
function Dconfirm(c, u, w, s) {
	if(!c) return;
	var s = s ? s : 0; var w = w ? w : 350; var d = u ? "window.location = '"+u+"'" : 'cDialog()';
	c = c +'<br style="margin-top:5px;"/><input type="button" class="btn" value=" OK " onclick="'+d+'"/>&nbsp;&nbsp;<input type="button" class="btn" value=" 取消 " onclick="cDialog();"/>';
	mkDialog('', c, '', w, s);
}
function Diframe(u, w, s, l, t) {
	var s = s ? s : 0; var w = w ? w : 350; var l = l ? true : false;
	var c = '<iframe src="'+u+'" width="'+(w-25)+'" height=0" id="diframe" border="0" vspace="0" hspace="0" marginwidth="0" marginheight="0" framespacing="0" frameborder="0" scrolling="no"></iframe><br/><input type="button" class="btn" value=" OK " onclick="cDialog();"/>';
	if(l) c = '<div id="dload" style="line-height:22px;">Loading...</div>'+c;
	mkDialog('', c, t, w, s);
}
function Dtip(c, w, t) {
	if(!c) return;
	var w = w ? w : 350; var t = t ? t : 2000;
	mkDialog('', c, '', w);
	window.setTimeout(function(){cDialog();}, t);
}
function Dfile(o, i, p, a, e) {
	var e = e ? e : '';
	var c = '<iframe name="UploadFile" style="display: none" src=""></iframe>';
	c += '<form method="post" target="UploadFile" enctype="multipart/form-data" action="'+p+'" onsubmit="return isImg(\'upfile\',\''+e+'\');"><input type="hidden" name="auth_code" value="'+a+'"><input type="hidden" name="from" value="file"/><input type="hidden" name="old" value="'+o+'"/><input type="hidden" name="fid" value="'+i+'"/><table cellpadding="2"><tr><td><input id="upfile" type="file" size="20" name="upfile" onchange="if(isImg(\'upfile\',\''+e+'\')){this.form.submit();document.getElementById(\'Dsubmit\').disabled=true;document.getElementById(\'Dsubmit\').value=\'上传中\';}"/>'+(e ? '<br>允许'+e : '')+'</td></tr><tr><td><input type="submit" class="btn" value="上传" id="Dsubmit"/>&nbsp;&nbsp;<input type="button" class="btn" value="取消" onclick="cDialog();"/></td></tr></table></form>';
	mkDialog('', c, '上传文件', 250);
}
function Dthumb(w, h, o, p, a, s, i,s2,h2) {//w 上传图片默认宽度 h 上传图片默认高度; o 上次上传图片的地址 p 服务器接收ajax文件的地址 a 权限验证码 s 是否显示宽高设置栏 i 用户id; s2 是否显示预览框 h2 预览框的高度
	var s = s ?'':'none'; var s2 = s2 ?'':'none'; var i = i ? i : 'thumb'; var c = '<iframe name="UploadThumb" style="display: none" src=""></iframe>';
	c += '<form method="post" target="UploadThumb" enctype="multipart/form-data" action="'+p+'" onsubmit="return isImg(\'upthumb\');"><input type="hidden" name="auth_code" value="'+a+'"><input type="hidden" name="from" value="thumb"/><input type="hidden" name="old" value="'+o+'"/><input type="hidden" name="fid" value="'+i+'"/><table cellpadding="3"><tr><td><input id="upthumb" type="file" size="20" name="upthumb" onchange="if(isImg(\'upthumb\')){this.form.submit();document.getElementById(\'Dsubmit\').disabled=true;document.getElementById(\'Dsubmit\').value=\'上传中\';}"/></td></tr><tr style="display:'+s+'"><td>宽度 <input type="text" size="3" name="width" value="'+w+'"/> px &nbsp;&nbsp;&nbsp;高度 <input type="text" size="3" name="height" value="'+h+'"/> px </td></tr><tr><td  style="display:'+s2+';height:'+h2+'px"> </td></tr><tr><td><input type="submit" value="上传" id="Dsubmit"/>&nbsp;&nbsp;<input type="button" value="取消" onclick="cDialog();"/></td></tr></table></form>';
	mkDialog('', c,'上传图片', 250);
}
function Dalbum(f, w, h, o, s, g, p, a) {
	var s = s ? 'none' : ''; var c = '<iframe name="UploadAlbum" style="display:none" src=""></iframe>';
	c += '<form method="post" target="UploadAlbum" enctype="multipart/form-data" action="'+p+'" onsubmit="return isImg(\'upalbum\');"><input type="hidden" name="fid" value="'+f+'"/><input type="hidden" name="auth_code" value="'+a+'"><input type="hidden" name="groupid" value="'+g+'"/><input type="hidden" name="from" value="album"/><input type="hidden" name="old" value="'+o+'"/><table cellpadding="3"><tr><td><input id="upalbum" type="file" size="20" name="upalbum" onchange="if(isImg(\'upalbum\')){this.form.submit();document.getElementById(\'Dsubmit\').disabled=true;document.getElementById(\'Dsubmit\').value=\'上传中\';}"/></td></tr><tr style="display:'+s+'"><td>宽度 <input type="text" size="3" name="width" value="'+w+'"/> px &nbsp;&nbsp;&nbsp;高度 <input type="text" size="3" name="height" value="'+h+'"/> px </td></tr><tr><td><input type="submit" value="上传" id="Dsubmit"/>&nbsp;&nbsp;<input type="button" value="取消" onclick="cDialog();"/></td></tr></table></form>';
	mkDialog('', c, '上传图片', 250);
}
function Dphoto(f, w, h, o, p, a, s) {
	var s = s ? 'none' : ''; var c = '<iframe name="UploadPhoto" style="display:none" src=""></iframe>';
	c += '<form method="post" target="UploadPhoto" enctype="multipart/form-data" action="'+p+'" onsubmit="return isImg(\'upalbum\');"><input type="hidden" name="fid" value="'+f+'"/><input type="hidden" name="auth_code" value="'+a+'"><input type="hidden" name="from" value="photo"/><input type="hidden" name="old" value="'+o+'"/><table cellpadding="3"><tr><td><input id="upalbum" type="file" size="20" name="upalbum" onchange="if(isImg(\'upalbum\')){this.form.submit();document.getElementById(\'Dsubmit\').disabled=true;document.getElementById(\'Dsubmit\').value=\'上传中\';}"/></td></tr><tr style="display:'+s+'"><td>宽度 <input type="text" size="3" name="width" value="'+w+'"/> px &nbsp;&nbsp;&nbsp;高度 <input type="text" size="3" name="height" value="'+h+'"/> px </td></tr><tr><td><input type="submit" class="btn" value="上传" id="Dsubmit"/>&nbsp;&nbsp;<input type="button" class="btn" value="取消" onclick="cDialog();"/></td></tr></table></form>';
	mkDialog('', c, '上传图片', 250);
}
function getAlbum(v, i) {document.getElementById('thumb'+i).value = v; document.getElementById('showthumb'+i).src = v;}
function delAlbum(i, s) {document.getElementById('thumb'+i).value = ''; document.getElementById('showthumb'+i).src = SKIN_PATH+'images/'+s+'pic.gif';}
function Eh(t) {
	var t = t ? t : 'select';
	if(isIE) {
		var arVersion = navigator.appVersion.split("MSIE"); var IEversion = parseFloat(arVersion[1]);		
		if(IEversion >= 7 || IEversion < 5) return;
		var ss = document.body.getElementsByTagName(t);					
		for(var i=0;i<ss.length;i++) {ss[i].style.visibility = 'hidden';}
	}
}
function Es(t) {
	var t = t ? t : 'select';
	if(isIE) {
		var arVersion = navigator.appVersion.split("MSIE"); var IEversion = parseFloat(arVersion[1]);		
		if(IEversion >= 7 || IEversion < 5) return;
		var ss = document.body.getElementsByTagName(t);					
		for(var i=0;i<ss.length;i++) {ss[i].style.visibility = 'visible';}
	}
}
function isImg(i, e) {
	var v = document.getElementById(i).value;
	if(v == '') {confirm('请选择文件'); return false;}	
	var t = ext(v);
	t = t.toLowerCase();
	var a = typeof e == 'undefined' ? 'jpg|gif|png|jpeg|bmp' : e;
	if(a.length > 2 && a.indexOf(t) == -1) {confirm('限制为:'+a); return false;}
	return true;
}
function ext(v) {return v.substring(v.lastIndexOf('.')+1, v.length);}
function _preview(s, t) {
	var t = t ? true : false;
	if(s) {
		if(t) {var p = s.lastIndexOf('.thumb.'); if(p != -1) s = s.substring(0, p);}
		mkDialog('', '<img src="'+s+'" onload="document.getElementById(\'Dtop\').style.width=(this.width+20)+\'px\';if(this.width>600){document.getElementById(\'Dtop\').style.left=15+\'px\';}"/>', '预览图片');
	} else {
		Dtip('没有图片');
	}
}
function dragstart(i, e) {dgDiv = document.getElementById(i); if(!e) {e = window.event;} dgX = e.clientX - parseInt(dgDiv.style.left); dgY = e.clientY - parseInt(dgDiv.style.top); document.onmousemove = dragmove;}
function dragmove(e) {if(!e) {e = window.event;} dgDiv.style.left = (e.clientX - dgX) + 'px';  dgDiv.style.top = (e.clientY - dgY) + 'px';}
function dragstop() {dgX = dgY = 0; document.onmousemove = null;}
function _delete(n,f){if(n.value) {$.post("/Member/ftpFileDelete", {old:n.value,f:f}, function(da){n.value='';Dtip('删除成功');},"json")} else {Dtip('没有图片');}}