/**
 * @author Joverms
 */
//获取指定ID
$ = function (objectId) {
	return document.getElementById(objectId);
}
//定位元素
function get_TagName(eves,TagName){
		return (eves || document).getElementsByTagName(TagName);
}
//导航
goUrl = function (url) {
	window.location = url;
}
//显示切换
function fSwitch(){
	var n=arguments.length-1
	for(var i=0; i<arguments.length-1; i++){
			if ((arguments[n] == $(arguments[i]))) {
				$(arguments[i]).className = 'on';
				$("box_"+arguments[i]).style.display = 'block';
			}
			else {
				$(arguments[i]).className = 'off';
				$("box_"+arguments[i]).style.display = 'none';
			}
	}
}
//设置首页
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", "网易电子样本", "中国最大最全的电子样本服务提供商" );
    }
}
//....................AJAX类.................................
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));
}
//....................滚动类.................................
var $ = function(id){
    return "string" == typeof id ? document.getElementById(id) : id;
};

var Extend = function(destination, source){
    for (var property in source) {
        destination[property] = source[property];
    }
    return destination;
}

var CurrentStyle = function(element){
    return element.currentStyle || document.defaultView.getComputedStyle(element, null);
}

var Bind = function(object, fun){
    var args = Array.prototype.slice.call(arguments).slice(2);
    return function(){
        return fun.apply(object, args.concat(Array.prototype.slice.call(arguments)));
    }
	
}

var Tween = {
    Quart: {
        easeOut: function(t, b, c, d){
            return -c * ((t = t / d - 1) * t * t * t - 1) + b;
        }
    },
    Back: {
        easeOut: function(t, b, c, d, s){
            if (s == undefined) 
                s = 1.70158;
            return c * ((t = t / d - 1) * t * ((s + 1) * t + s) + 1) + b;
        }
    },
    Bounce: {
        easeOut: function(t, b, c, d){
            if ((t /= d) < (1 / 2.75)) {
                return c * (7.5625 * t * t) + b;
            }
            else 
                if (t < (2 / 2.75)) {
                    return c * (7.5625 * (t -= (1.5 / 2.75)) * t + .75) + b;
                }
                else 
                    if (t < (2.5 / 2.75)) {
                        return c * (7.5625 * (t -= (2.25 / 2.75)) * t + .9375) + b;
                    }
                    else {
                        return c * (7.5625 * (t -= (2.625 / 2.75)) * t + .984375) + b;
                    }
        }
    }
}


//容器对象,滑动对象,切换数量
var SlideTrans = function(container, slider, count, options){
    this._slider = $(slider);
    this._container = $(container);//容器对象
    this._timer = null;//定时器
    this._count = Math.abs(count);//切换数量
    this._target = 0;//目标值
    this._t = this._b = this._c = 0;//tween参数
    this.Index = 0;//当前索引
    this.SetOptions(options);
    
    this.Auto = !!this.options.Auto;
    this.Duration = Math.abs(this.options.Duration);
    this.Time = Math.abs(this.options.Time);
    this.Pause = Math.abs(this.options.Pause);
    this.Tween = this.options.Tween;
    this.onStart = this.options.onStart;
    this.onFinish = this.options.onFinish;
    
    var bVertical = !!this.options.Vertical;
    this._css = bVertical ? "top" : "left";//方向
    //样式设置
    var p = CurrentStyle(this._container).position;
    p == "relative" || p == "absolute" || (this._container.style.position = "relative");
    this._container.style.overflow = "hidden";
    this._slider.style.position = "absolute";
    this._slider.style.zindex = "-100";
    
    this.Change = this.options.Change ? this.options.Change : this._slider[bVertical ? "offsetHeight" : "offsetWidth"] / this._count;
};
SlideTrans.prototype = {
    //设置默认属性
    SetOptions: function(options){
        this.options = {//默认值
            Vertical: true,//是否垂直方向（方向不能改）
            Auto: true,//是否自动
            Change: 0,//改变量
            Duration: 20,//滑动持续时间
            Time: 10,//滑动延时
            Pause: 6000,//停顿时间(Auto为true时有效)
            onStart: function(){
            },//开始转换时执行
            onFinish: function(){
            },//完成转换时执行
            Tween: Tween.Quart.easeOut//tween算子
        };
        Extend(this.options, options ||
        {});
    },
    //开始切换
    Run: function(index){
        //修正index
        index == undefined && (index = this.Index);
        index < 0 && (index = this._count - 1) || index >= this._count && (index = 0);
        //设置参数
        this._target = -Math.abs(this.Change) * (this.Index = index);
        this._t = 0;
        this._b = parseInt(CurrentStyle(this._slider)[this.options.Vertical ? "top" : "left"]);
        this._c = this._target - this._b;
        
        this.onStart();
        this.Move();
		
    },
    //移动
    Move: function(){
        clearTimeout(this._timer);
        //未到达目标继续移动否则进行下一次滑动
        if (this._c && this._t < this.Duration) {
            this.MoveTo(Math.round(this.Tween(this._t++, this._b, this._c, this.Duration)));
            this._timer = setTimeout(Bind(this, this.Move), this.Time);
        }
        else {
            this.MoveTo(this._target);
            this.Auto && (this._timer = setTimeout(Bind(this, this.Next), this.Pause));
        }
		
    },
    //移动到
    MoveTo: function(i){
        this._slider.style[this._css] = i + "px";
    },
    //下一个
    Next: function(){
        this.Run(++this.Index);
    },
    //上一个
    Previous: function(){
        this.Run(--this.Index);
    },
    //停止
    Stop: function(){
        clearTimeout(this._timer);
        this.MoveTo(this._target);
    }
};
//....................绅缩函数................................
var intervalId = null;
function slideAd(id, nStayTime, sState, nMaxHth, nMinHth){
    this.stayTime = nStayTime * 1000 || 1000;
    this.maxHeigth = nMaxHth || 202;
    this.minHeigth = nMinHth || 2.5;
    this.state = sState || "down";
    var obj = document.getElementById(id);
    if (intervalId != null) 
        window.clearInterval(intervalId);
    function openBox(){
        var h = parseInt(obj.offsetHeight);
        obj.style.height = ((this.state == "down") ? (h + 10) : (h - 10)) + "px";
        if (obj.offsetHeight > this.maxHeigth) {
            window.clearInterval(intervalId);
            intervalId = window.setInterval(closeBox, this.stayTime);
        }
        if (obj.offsetHeight < this.minHeigth) {
            window.clearInterval(intervalId);
        }
    }
    function closeBox(){
        slideAd("MyMoveAd", 1, "up", 200, 0);
        
    }
    intervalId = window.setInterval(openBox, 30);
}

//.........................弹出窗函数...............................

var divTop, divLeft, divWidth, divHeight, docHeight, docWidth, objTimer, i = 0;
function getMsg(){


    divTop = parseInt(document.getElementById("loft_win").style.top, 10);
    divLeft = parseInt(document.getElementById("loft_win").style.left, 10);
    divHeight = parseInt(document.getElementById("loft_win").offsetHeight, 10);
    divWidth = parseInt(document.getElementById("loft_win").offsetWidth, 10);
    docHeight = (document.documentElement.clientHeight > document.documentElement.clientHeight) ? document.documentElement.clientHeight : document.body.clientHeight
    docWidth = (document.documentElement.clientWidth > document.documentElement.clientWidth) ? document.body.clientWidth : document.documentElement.clientWidth;
    document.getElementById("loft_win").style.top = (document.body.scrollTop ? document.body.scrollTop : document.documentElement.scrollTop) + docHeight + 'px';
    document.getElementById("loft_win").style.left = (document.body.scrollTop ? document.body.scrollTop : document.documentElement.scrollLeft) + docWidth - divWidth + 'px';
    document.getElementById("loft_win").style.visibility = "visible";
    objTimer = window.setInterval("moveDiv()", 10);
    
    
}

//初始化位置
function resizeDiv(){
    i += 1;
    //if(i>300) closeDiv() //想不用自动消失由用户来自己关闭所以屏蔽这句
    try {
        divHeight = parseInt(document.getElementById("loft_win").offsetHeight, 10);
        divWidth = parseInt(document.getElementById("loft_win").offsetWidth, 10);
        docWidth = document.documentElement.clientWidth;
        docHeight = document.documentElement.clientHeight;
        document.getElementById("loft_win").style.top = docHeight - divHeight + (document.body.scrollTop ? document.body.scrollTop : document.documentElement.scrollTop) - 2 + "px";
        document.getElementById("loft_win").style.left = docWidth - divWidth + (document.body.scrollTop ? document.body.scrollTop : document.documentElement.scrollLeft) + "px";
        
    } 
    catch (e) {
    }
}

//最小化
function minsizeDiv(){
    i += 1
    
    //if(i>300) closeDiv() //想不用自动消失由用户来自己关闭所以屏蔽这句
    try {
        divHeight = parseInt(document.getElementById("loft_win_min").offsetHeight, 10);
        divWidth = parseInt(document.getElementById("loft_win_min").offsetWidth, 10);
        docWidth = document.documentElement.clientWidth;
        docHeight = document.documentElement.clientHeight;
        document.getElementById("loft_win_min").style.top = docHeight - divHeight + (document.body.scrollTop ? document.body.scrollTop : document.documentElement.scrollTop) + "px";
        document.getElementById("loft_win_min").style.left = docWidth - divWidth + (document.body.scrollTop ? document.body.scrollTop : document.documentElement.scrollLeft) + "px";
    } 
    catch (e) {
    }
}

//移动
function moveDiv(){
    try {
        if (parseInt(document.getElementById("loft_win").style.top, 10) <= (docHeight - divHeight + (document.body.scrollTop ? document.body.scrollTop : document.documentElement.scrollTop))) {
            window.clearInterval(objTimer);
            objTimer = window.setInterval("resizeDiv()", 1);
        }
        divTop = parseInt(document.getElementById("loft_win").style.top, 10);
        document.getElementById("loft_win").style.top = divTop - 1 + "px";
    } 
    catch (e) {
    }
}

function minDiv(){
    closeDiv();
    document.getElementById('loft_win_min').style.visibility = 'visible';
    objTimer = window.setInterval("minsizeDiv()", 1);
}

function maxDiv(){
    document.getElementById('loft_win_min').style.visibility = 'hidden';
    document.getElementById('loft_win').style.visibility = 'visible';
    objTimer = window.setInterval("resizeDiv()", 1);
    //resizeDiv()
    getMsg();
}

function closeDiv(){
    document.getElementById('loft_win').style.visibility = 'hidden';
    document.getElementById('loft_win_min').style.visibility = 'hidden';
    if (objTimer) 
        window.clearInterval(objTimer);
}
