function AjaxAction(action, params1, params2, params3, params4, params5){
	var ___Ajax = new Ajax();
	___Ajax.CallBackFunc = AjaxActionCallBack;
	if(___Ajax.Create()){
		var ___AjaxUrl = "ajax.php?" + action;
		if(params1)___AjaxUrl += "," + params1;
		if(typeof(params2) == "object" || typeof(params2) == "undefined"){
			//
		}else{
			___AjaxUrl += "," + params2;
		}
		if(typeof(params3) == "object" || typeof(params3) == "undefined"){
			//
		}else{
			___AjaxUrl += "," + params3;
		}
		if(typeof(params4) == "object" || typeof(params4) == "undefined"){
			//
		}else{
			___AjaxUrl += "," + params4;
		}
		if(typeof(params5) == "object" || typeof(params5) == "undefined"){
			//
		}else{
			___AjaxUrl += "," + params5;
		}
		___Ajax.Send(___AjaxUrl, null, action, params1, params2, params3, params4, params5);
	}
}

function AjaxActionCallBack(html, success){
	switch(arguments[2][0]){
		case "stat":
			$('statspan').innerHTML = html;
			break;
		case "dlist":
			var o1 = document.getElementById("s" + arguments[2][1] + "_box");
			if(arguments[2][1] == 2 || arguments[2][1] == 3)var o1 = document.getElementById("s2-3_box");
			o1.innerHTML = '<select name="s' + arguments[2][1] + '" id="s' + arguments[2][1] + '"><option value="">请选择</option>' + html +   '</select>';
			break;
		case "dlistgradeselect":
			var o1 = document.getElementById(arguments[2][3] + "_box");
			o1.innerHTML = html;
			if(arguments[2][5])AddInFunc("form1");
			break;
		case "upload":
			___Dialog[arguments[2][0]].DialogSetHtml(html);			
			break;
		default:
			break;
	}
}
function AjaxActionSubmit(action, form){
	var ___Ajax = new Ajax();
	___Ajax.CallBackFunc = AjaxActionSubmitCallBack;
	___Ajax.XmlMethod = "POST";
	if(___Ajax.Create()){
		var ___AjaxUrl = ___AjaxUrl = "ajax.php?" + action;
		var ___Form = new Form();
		var ___AjaxRequest = ___Form.GetFormToRequest(form);
		___Ajax.Send(___AjaxUrl, ___AjaxRequest, action, form);
	}
	return false;
}

function AjaxActionSubmitCallBack(html, success){
	switch(arguments[2][0]){
		case "sendmail":
			try{
				if(html == "1"){
					//alert("邮件发送成功！");
					arguments[2][1].email.value = "";
					arguments[2][1].button32.value = "完成，继续发送邮件";
				}else{
					//alert("对不起，邮件发送失败！");
					arguments[2][1].button32.value = "错误，重新发送邮件";
				}
				arguments[2][1].button32.disabled = false;
			}catch(e){}
			return false;
			break;
		case "memberaccount":
			if(html == "1"){
				alert('对不起，账号已存在，请重新选择！');
			}else{
				alert('恭喜你，账号可以使用！');
			}
			break;
		default:
			break;
	}
}

function ValidateCode(obj){
	var o = typeof(obj) == "object" ? obj : document.getElementById(obj);
	o.src = "includes/validatecode.inc.php?r=" + Math.random();
}

function AjaxDListGradeSelect(o, tid, obj, parentv, validator){
	var value = typeof(o) == "object" ? o.options[o.selectedIndex].getAttribute("v") : o;
	AjaxAction("dlistgradeselect", tid, value, obj, parentv, validator);
	try{
		if(typeof(o) == "object"){
			var hobj = document.getElementById(obj.substr(0,obj.length - 3));
			var mobj = document.getElementById(obj + "_multiple");				
			if(mobj){
				if(o.value){
					var harr = hobj.value.split(",");
					if(in_array(o.value, harr) == -1){
						if(hobj.value == ""){
							hobj.value = o.value;
						}else{
							hobj.value += "," + o.value;
						}
						mobj.innerHTML += '<div class="ajax_dlist_grade_select_multiple" id="' + obj + '_multiple_' + o.value + '">' + AjaxDListGradeSelectTitle(o.form, obj) + ' <a href="javascript:void(0)" onclick="AjaxDListGradeSelectDelete(\'' + obj + '\', \'' + o.value + '\')">删除</a></div>';
					}
				}
			}else{
				hobj.value = o.value;
			}
		}
	}catch(e){}
}

function AjaxDListGradeSelectDelete(obj, v){
	try{
		var hobj = document.getElementById(obj.substr(0,obj.length - 3));
		var mobj = document.getElementById(obj + "_multiple_" + v);
		var harr = hobj.value.split(",");
		harr = del_array(v, harr);
		hobj.value = harr.join(",");
		mobj.parentNode.removeChild(mobj);
	}catch(e){}
}

function AjaxDListGradeSelectTitle(frm, obj){
	var objs = frm.elements[obj];
	var title = '';
	if(objs.tagName == "SELECT"){
		if(objs.value != "")title += objs.options[objs.selectedIndex].text;
	}else{
		for(var i = 0; i < objs.length; i ++){
			if(title != '')title += " > ";
			title += objs[i].options[objs[i].selectedIndex].text;
			if(objs[i].value != "")break;
		}
	}
	return title;
}

function AjaxDListGradeSelectReset(obj){
	try{
		var mobj = document.getElementById(obj + "_multiple");
		eval('mobj.innerHTML = ' + obj.substr(0,obj.length - 2) + '_default;');
	}catch(e){}
}

function jstab(pix, idx, len){
	for(var i = 1; i <= len; i ++){
		$(pix + 'btn' + i).className = '';
		$(pix + 'box' + i).style.display = 'none';
	}
	$(pix + 'btn' + idx).className = 'selected';
	$(pix + 'box' + idx).style.display = '';
}
function jsmenu(id, op){
	var o = $(id);
	o.style.display = op ? "" : "none";
	//for(var i = 2; i < arguments.length; i ++){
	//	try{
	//		$(arguments[i]).style.visibility = op ? "hidden" : "";
	//	}catch(e){}
	//}
	/*
	var ie = window.navigator.userAgent.indexOf("MSIE") != -1;
	if(ie){
		var p = GetObjectPos(o);
		var epos = {
				EX1 : p.x,
				EX2 : o.offsetWidth + p.x,
				EY1 : p.y,
				EY2 : o.offsetHeight + p.y
			}
		HideShowObject(epos, op);
	}
	*/
}
///////////////////
function HideShowObject(epos, op){
	var tags = new Array("object", "applet", "iframe", "select");
	var cpos = {el:null, CX1:0, CX2:0, CY1:0, CY2:0};
	var cp = {x:0, y:0};

	for (var k = tags.length; k > 0; ) {
		var ar = document.getElementsByTagName(tags[--k]);
		var cc = null;
	
		for (var i = ar.length; i > 0;) {
			cc = ar[--i];
	
			cp = GetObjectPos(cc);
			cpos = {
				CX1 : cp.x,
				CX2 : cc.offsetWidth + cp.x,
				CY1 : cp.y,
				CY2 : cc.offsetHeight + cp.y
			}
			
			if(!cc.getAttribute("object_hideshow_object_visibility"))
				if(cc.currentStyle.visibility)
					cc.setAttribute("object_hideshow_object_visibility", cc.currentStyle.visibility);
			if (op && !HideShowObjectCheck(epos, cpos)) {
				cc.style.visibility = cc.getAttribute("object_hideshow_object_visibility");
			}else if(!HideShowObjectCheck(epos, cpos)){
				cc.style.visibility = cc.getAttribute("object_hideshow_object_visibility");
			} else {
				cc.style.visibility = "hidden";
			}
		}
	}		
}
function HideShowObjectCheck(epos, cpos){//in:true
	if((cpos.CX1 > epos.EX2) || (cpos.CX2 < epos.EX1) || (cpos.CY1 > epos.EY2) || (cpos.CY2 < epos.EY1)){
		return false;
	}else{				
		return true;
	}
}
function GetObjectPos(el) {
	var SL = 0, ST = 0;
	var is_div = /^div$/i.test(el.tagName);
	if (is_div && el.scrollLeft)
		SL = el.scrollLeft;
	if (is_div && el.scrollTop)
		ST = el.scrollTop;
	var r = { x: el.offsetLeft - SL, y: el.offsetTop - ST };
	if (el.offsetParent) {
		var tmp = GetObjectPos(el.offsetParent);
		r.x += tmp.x;
		r.y += tmp.y;
	}
	return r;
}
///////////////////
function formatnumber(fnumber,fdivide,fpoint,fround){
	
    var ff = (fnumber + '').substr(0, 1);
    var fnum = fnumber + '';
    if(ff == "-")fnum = fnum.substr(1);
    var revalue="";

    if(fnum==null){
        for(var i=0;i<fpoint;i++)revalue+="0";
        return "0."+revalue;
    }
    fnum = fnum.replace(/^\s*|\s*$/g,'');
    if(fnum==""){
        for(var i=0;i<fpoint;i++)revalue+="0";
        return "0."+revalue;
    }

    fnum=fnum.replace(/,/g,"");

    if(fround){
        var temp = "0.";
        for(var i=0;i<fpoint;i++)temp+="0";
        temp += "5";

        fnum = Number(fnum) + Number(temp);
        fnum += '';
    }

    var arrayf=fnum.split(".");

    if(fdivide){
        if(arrayf[0].length>3){
            while(arrayf[0].length>3){
                revalue=","+arrayf[0].substring(arrayf[0].length-3,arrayf[0].length)+revalue;
                arrayf[0]=arrayf[0].substring(0,arrayf[0].length-3);
            }
        }
    }
    revalue=arrayf[0]+revalue;

    if(arrayf.length==2&&fpoint!=0){
        arrayf[1]=arrayf[1].substring(0,(arrayf[1].length<=fpoint)?arrayf[1].length:fpoint);

        if(arrayf[1].length<fpoint)
            for(var i=0;i<fpoint-arrayf[1].length;i++)arrayf[1]+="0";
        revalue+="."+arrayf[1];
    }else if(arrayf.length==1&&fpoint!=0){
        revalue+=".";
        for(var i=0;i<fpoint;i++)revalue+="0";
    }

    return ff == "-" ? "-" + revalue : revalue;
}

function iimgFix(im,x,y){		
	y = y || 99999
	im.removeAttribute("width");
	im.removeAttribute("height");			
	if( im.width/im.height > x/y  && im.width >x ){
		im.height = im.height * (x/im.width)
		im.width = x
		im.parentNode.style.height = im.height * (x/im.width) + 'px'
	}else if( im.width/im.height <= x/y && im.height >y){
		im.width = im.width * (y/im.height)
		im.height = y
		im.parentNode.style.height = y + 'px'
	}
	//im.style.visibility = 'visible'	
}

function in_array(vl, arr){
	for(var i = 0; i < arr.length; i ++){
		if(vl == arr[i])return i;
	}
	return -1;
}
function del_array(vl, arr){
	var temp = new Array();
	for(var i = 0; i < arr.length; i ++){
		if(vl != arr[i]){
			temp.push(arr[i]);
		}
	}
	return temp;
}

function $(id){
	return document.getElementById(id);
}