/******************************************************************************************
* 程序设计: http://www.ad189.com/	rick									    ***
******************************************************************************************/

//站点的根目录
var board_url = "./";


/*
全局通用对象
*/
function LGlobal()
{
	this.n = navigator.userAgent.toLowerCase();
	this.db = (document.compatMode && document.compatMode.toLowerCase() != "backcompat")?
		document.documentElement
		: (document.body || null);

	this.op = !!(window.opera && document.getElementById);
	this.op6 = !!(this.op && !(this.db && this.db.innerHTML));
	if (this.op && !this.op6) document.onmousedown = new Function('e',
		'if (((e = e || window.event).target || e.srcElement).tagName == "IMAGE") return false;'
	);
	this.ie = !!(this.n.indexOf("msie") >= 0 && document.all && this.db && !this.op);
	this.iemac = !!(this.ie && this.n.indexOf("mac") >= 0);
	this.ie4 = !!(this.ie && !document.getElementById);
	this.n4 = !!(document.layers && typeof document.classes != "undefined");
	this.n6 = !!(typeof window.getComputedStyle != "undefined" && typeof document.createRange != "undefined");
	this.w3c = !!(!this.op && !this.ie && !this.n6 && document.getElementById);
	this.ce = !!(document.captureEvents && document.releaseEvents);
	this.px = (this.n4 || this.op6)? '' : 'px';
}

var LGlobal = new LGlobal();

LGlobal.evt = function(d_e)
{
	this.but = (this.e = d_e || window.event).which || this.e.button || 0;
	this.button = (this.e.type == 'mousedown')? this.but
		: (LGlobal.e && LGlobal.e.button)? LGlobal.e.button
		: 0;
	this.src = this.e.target || this.e.srcElement || null;
	this.src.tag = (this.src.tagName || this.src).toString().toLowerCase();
	this.toEle = this.e.toElement;
	this.fromEle = this.e.fromElement;
	
	this.x = LGlobal.Int(this.e.pageX || this.e.clientX || 0);
	this.y = LGlobal.Int(this.e.pageY || this.e.clientY || 0);
	if (LGlobal.ie)
	{
		this.x += LGlobal.getScrollX() - (LGlobal.ie && !LGlobal.iemac)*1;
		this.y += LGlobal.getScrollY() - (LGlobal.ie && !LGlobal.iemac)*1;
	}
	this.modifKey = this.e.modifiers? (this.e.modifiers&Event.SHIFT_MASK || this.e.modifiers&Event.CONTROL_MASK)
		: (this.e.shiftKey || this.e.ctrlKey || false);
};

LGlobal.Int = function(d_x, d_y)
{
	return isNaN(d_y = parseInt(d_x))? 0 : d_y;
};

LGlobal.getScrollX = function()
{
	return LGlobal.Int(window.pageXOffset || (LGlobal.db? LGlobal.db.scrollLeft : 0));
};

LGlobal.getScrollY = function()
{
	return LGlobal.Int(window.pageYOffset || (LGlobal.db? LGlobal.db.scrollTop : 0));
};


function $(id)
{
	return document.getElementById(id);	
}

//创建XMLRequest对象
function create_xml_request() 
{
	var xmlrequest = false;
	
	if(window.XMLHttpRequest) 
	{
		xmlrequest = new XMLHttpRequest();
		if(xmlrequest.overrideMimeType)
		{
			xmlrequest.overrideMimeType('text/xml');
		}	
		
	} 
	else if(window.ActiveXObject) 
	{
		if(window.xmlHttpRequest) 
		{
			xmlrequest= new ActiveXObject(xmlHttpRequest);
		}
		else 
		{
			var versions = ["MSXML.XMLHTTP","Microsoft.XMLHTTP","Msxml2.XMLHTTP.7.0", "Msxml2.XMLHTTP.6.0", "Msxml2.XMLHTTP.5.0", "Msxml2.XMLHTTP.4.0", "MSXML2.XMLHTTP.3.0", "MSXML2.XMLHTTP"];
			for(var i = 0; i < versions.length ; i++) 
			{
				try 
				{
					xmlrequest = new ActiveXObject(versions[i]);
					if(xmlrequest) 
					{
						xmlHttpRequest = versions[i];
						ajaxExcetpion = null;
						break;
					}
				}
				catch (objException) 
				{
					ajaxExcetpion = objException;
				} 
			}
		}
	}

	return xmlrequest;
}

//创建XMLRequest对象
function g_lead_create_xmlhttp()
{
	if(typeof XMLHttpRequest!="undefined")        
	{
			return new XMLHttpRequest();
	}
	else if(typeof ActiveXObject!="undefined")
	{
			var xmlHttp_ver  = false;
			var xmlHttp_vers = ["MSXML2.XmlHttp.5.0","MSXML2.XmlHttp.4.0","MSXML2.XmlHttp.3.0","MSXML2.XmlHttp","Microsoft.XmlHttp"];
			if(!xmlHttp_ver){
					for(var i=0;i<xmlHttp_vers.length;i++){
							try{
									new ActiveXObject(xmlHttp_vers[i]);
									xmlHttp_ver = xmlHttp_vers[i];
									break;
							}catch(oError){;}
					}
			}
			if(xmlHttp_ver){
					return new ActiveXObject(xmlHttp_ver);
			}else{
					throw new Error("Could not create XML HTTP Request.");
			}
	}else{
			throw new Error("Your browser doesn't support an XML HTTP Request.");
	}
}

//选择全部复选框
function check_all(form, name, checked)
{
	var eles = form.elements;
	
	for(var i=0; i<eles.length; i++)
	{
		if(eles[i].name == name)
		{
			eles[i].checked = !checked;
		}
	}
}

//复制到粘贴板
function set_copy(_sTxt){
	try {
		clipboardData.setData('Text',_sTxt)
		return true;
	}
	catch(e){
		return false;
	}
}

function showmessage(msg)
{
	var msgs = msg.split("||");
	
	if(msgs[0])
		alert(msgs[0]);
	
	if(msgs[1])
		location.href = msgs[1];
}

function urlencode(text) 
{
	text = text.toString();	
	var matches = text.match(/[\x90-\xFF]/g);
	if(matches) {
		for(var matchid = 0; matchid < matches.length; matchid++) 
		{
			var char_code = matches[matchid].charCodeAt(0);		
			text = text.replace(matches[matchid], '%u00' + (char_code & 0xFF).toString(16));
		}
	}

	return escape(text).replace(/\+/g, "%2B");
}
function checkall(form,prefix) {//用于公共的
	for(var i = 0; i < form.elements.length; i++){
		var e = form.elements[i];
		if(e.name != 'chkall' && e.name !='commend_rate_id[]' &&  (!prefix || (prefix && e.name.match(prefix)))) {
			e.checked = form.chkall.checked;
		}
	}
}

function show(obj)
{
	var ab = document.getElementById(obj);
		if(ab.style.display == "none")
			ab.style.display = "";
		else
			ab.style.display = "none";			
}
function check_it(form,the_id) {//用于公共的
	for(var i = 0; i < form.elements.length; i++){
		var e = form.elements[i];
		if(e.id == the_id) {
			e.checked = true;
		}
	}
}

var imageObject;//改变图片的显示尺寸
function ResizeImage(obj, MaxW, MaxH)
{
    if (obj != null) imageObject = obj;
    var state=imageObject.readyState;
	if(state!='complete') {
        setTimeout("ResizeImage(null,"+MaxW+","+MaxH+")",50);
		return;
    }
    var oldImage = new Image();
    oldImage.src = imageObject.src;
    var dW=oldImage.width; var dH=oldImage.height;
    if(dW>MaxW || dH>MaxH) {
        a=dW/MaxW; b=dH/MaxH;
        if(b>a) a=b;
        dW=dW/a; dH=dH/a;
    }
    if(dW > 0 && dH > 0) {
        imageObject.width=dW;
		imageObject.height=dH;
	}
}
