$ = function (objectId) {
	return document.getElementById(objectId);
}

setHomepage = function () {
	if (document.all) {
		document.body.style.behavior='url(#default#homepage)';
        document.body.setHomePage('http://www.co188.com/');
    } else if (window.sidebar) {
        if(window.netscape) {
            try {
                netscape.security.PrivilegeManager.enablePrivilege("UniversalXPConnect");
            } catch(e) {
                alert("当前设置不允许设为首页!请手工设置!");
            }
         }
         var prefs = Components.classes['@mozilla.org/preferences-service;1'].getService(Components. interfaces.nsIPrefBranch);
         prefs.setCharPref('browser.startup.homepage','http://www.co188.com/');
     }
}

AddFavorite = function () {
    try {
        window.external.addFavorite('http://www.co188.com/', '网易电子样本');
    } catch (e) {
        try {
            window.sidebar.addPanel('网易电子样本', 'http://www.co188.com/', "");
        } catch (e) {
            alert("加入收藏失败，请使用Ctrl+D进行添加");
        }
    }
}

AddSearch = function () {
	if (window.external || window.external.AddSearchProvider) {
        window.external.AddSearchProvider('http://www.co188.com/search.xml');
    } else if (window.sidebar && window.sidebar.addSearchEngine) {
		window.sidebar.addSearchEngine("http://www.co188.com/search.xml", "favicon.ico", "网易电子样本", "中国最大最全的电子样本服务提供商" );
    }
}

goUrl = function (url) {
	window.location = url;
}


Util = {};
Util.version = {Copyright : '1.0', Update : '2007/11/8', Author : 'MF'};

Util.AJAX = function () {
    Util.AJAX.Obj = this;
	this.request = null;
	this.requestType = 'XML';
	this.responseData = null;
	this.call = null;
}

Util.AJAX.prototype.createXmlhttp = function () {
	try {
		if (window.XMLHttpRequest) {
    		this.request = new XMLHttpRequest();
    		if (this.request.overrideMimeType) this.request.overrideMimeType('text/xml');
		} else if (window.ActiveXObject) {
    		this.request = new ActiveXObject('Microsoft.XMLHTTP');
		}
    } catch (e) {
        this.request = null;
    }
	return this.request ? true : false;
}

Util.AJAX.prototype.requestUrl = function (url, method, asyn, type, call) {
	this.request = null;
	if (!this.request) {
		if (!this.createXmlhttp()) {
			window.alert('请使用IE或者FIREFOX浏览本页面!');
			return;
		}
	}
	
	method = method.toUpperCase();
	this.requestType = type.toUpperCase();
	this.call = call;
	this.request.onreadystatechange = this.callBack;
	this.request.open(method, url, asyn);
	if (method == 'POST') {
		this.request.setRequestHeader('Content-Type', 'application/x-www-form-urlencoded');
	} else {
		this.request.setRequestHeader('If-Modified-Since','Wed, 15 Nov 1995 00:00:00 GMT');
	}
	
	this.request.send(null);
}

Util.AJAX.prototype.callBack = function () {
	
	if (Util.AJAX.Obj.request.readyState == 4 && Util.AJAX.Obj.request.status == 200 ) {
		Util.AJAX.Obj.responseData = (Util.AJAX.Obj.requestType == 'XML') ? Util.AJAX.Obj.request.responseXML : Util.AJAX.Obj.request.responseText;
		if (Util.AJAX.Obj.call) Util.AJAX.Obj.call(Util.AJAX.Obj.responseData);
	}
}

Util.XElement = {};

Util.XElement.point = {x : 0, y : 0};

Util.XElement.getPointByEvt = function (e) {
	var evt = Util.XEvent.createEvent(e);
	Util.XElement.point.x = (evt.clientX ? evt.clientX : evt.pageX);
	Util.XElement.point.y = (evt.clientY ? evt.clientY : evt.pageY);
	return Util.XElement.point;
}

Util.XElement.getPointByObj = function (objectid) {
    if (!$(objectid)) return;
    _obj = $(objectid);
	Util.XElement.point.x = _obj.offsetLeft;
	Util.XElement.point.y = _obj.offsetTop;
	Util.XElement.point.y += _obj.offsetHeight;
 	while (_obj = _obj.offsetParent) {
 		Util.XElement.point.y += _obj.offsetTop; 
 		Util.XElement.point.x += _obj.offsetLeft; 
 	}
	return Util.XElement.point;
}

Util.XElement.setAttribute = function (objectid, attr, value) {
	if (!$(objectid)) return;
	$(objectid).setAttribute(attr, value);
}

Util.XElement.getAttribute = function (objectid, attr) {
	if (!$(objectid)) return;
	return $(objectid).getAttribute(attr);
}

Util.XElement.setStyle = function (objectid, attr, value) {
	if (!$(objectid)) return;
	$(objectid).style[attr] = value;
}

Util.XDiv = function () {
    Util.XDiv.Obj = this;
	this.id = '';
	this.parentObj = null;
	this.cssName = '';
	this.doc = null;
}

Util.XDiv.prototype.createDiv = function () {
	this.doc = document.getElementsByTagName('body').item(0);
	if ($(this.id)) {
		this.removeDiv(this.id);
	}
	
	var oDiv = document.createElement("div");
	oDiv.id = this.id;
	this.parentObj ? this.parentObj.appendChild(oDiv) : this.doc.appendChild(oDiv);
	if (this.cssName != "") {
		Util.XElement.setAttribute(this.id, 'class', this.cssName);
		Util.XElement.setAttribute(this.id, 'className', this.cssName);
	}
	return $(this.id);
}

Util.XDiv.prototype.attachDiv = function (id) {
	if (!$(id)) return;
	this.id = id;
	this.parentObj = (($(id).parentNode.id != '') ? $(id).parentNode : this.doc);
	this.cssName = $(id).className;
}

Util.XDiv.prototype.removeDiv = function (id) {
	this.attachDiv(id);
	if (!$(id)) return;
	this.parentObj ? this.parentObj.removeChild($(id)) : this.doc.removeChild($(id));
}