﻿/*  一些基本 通用的函数 */

// 设置基本域
// 因为和编辑器有冲突，所以屏蔽 -- by s.p
//  document.domain = "dafen7.com";

//删除
function Delete(){ return confirm('确认删除吗？'); }


String.prototype.Trim=function()
{
    return this.replace(/(^\s*)|(\s*$)/g, '');
}

// 获取绝对坐标值
var Offset = {
    GetOffSet : function(e){ 
        var t=e.offsetTop;  
        var l=e.offsetLeft;  
        while(e=e.offsetParent) {   t+=e.offsetTop;  l+=e.offsetLeft; }  
        var rec = new Array(1); 
        rec[0]  = t; 
        rec[1] = l; 
        return rec; }    ,
    X : function(e){ return this.GetOffSet(e)[1];   }   ,
    Y : function(e){ return this.GetOffSet(e)[0];   }   ,
    // 判断obj是否在容器e内
    Exists  : function(e,obj){
        if(e = obj) return true;
        while(e = e.offsetParent){ if(e == obj) return true; }
        return false;
    }
}

// 输出FLASH
function WriteFlash(url,width,height){
    document.write('<object id="MyFlash" classid="clsid:D27CDB6E-AE6D-11cf-96B8-444553540000" codebase="http://download.macromedia.com/pub/shockwave/cabs/flash/swflash.cab#version=6,0,29,0" width="' + width + '" height="' + height + '">');
    document.write('<param name="movie" value="' + url + '">');
    document.write('<param name="wmode" value="opaque">');
    document.write('<param name="menu" value="false">');
    document.write('<param name="quality" value="high">');
    document.write('<embed src="' + url + '" quality="high" pluginspage="http://www.macromedia.com/go/getflashplayer" type="application/x-shockwave-flash" width="' + width + '" height="' + height + '"></embed>');
    document.write('</object>');
}


//  拖动
Drag = {
    Move : false    ,
    dragX : 0   ,
    dragY : 0   ,
    StartDrag : function(obj){
        if(event.button==1 && event.srcElement.tagName.toUpperCase()=="DIV")
        {
            obj.setCapture();
            this.Move = true;
            this.dragX = event.clientX - Offset.X(obj);
            this.dragY = event.clientY - Offset.Y(obj);
        } 
    }  ,
    
    Drag : function(obj)                   
    {    
        if(this.Move){   
            var oldwin;
            if(obj.style.position == 'absolute')
                oldwin = obj;
            else
                oldwin = obj.parentNode;     
            
            if(oldwin.style.position != 'absolute'){
                oldwin = oldwin.parentNode;
                if(oldwin.style.position != 'absolute') return;
            }     
            oldwin.style.left = event.clientX - this.dragX;
            oldwin.style.top = event.clientY - this.dragY;
        }
    }   ,
    
    StopDrag : function(obj){
        obj.releaseCapture();
        this.Move = false;
    }
}




// 获取对象
function $(objName){
    return document.getElementById(objName);
}


/*  Request对象 */
var Request = {
    Url : null  ,
    // 获取url对象，不区分大小写
    QueryString : function(key,string){   
        var url;
        if(this.Url == null) 
            url = location.href;
        else
            url = this.Url;
        if(string!=null)
            url = string;
        url = url.indexOf('?') == -1 ? url : url.substring(url.indexOf('?') + 1);
        var q = url.split('&');
        for(i=0; i<q.length; i++){
            var s = q[i].split("=");
            if(s.length == 2){
                if(s[1].substring(s[1].length-1) == "#")
                     s[1] = s[1].substring(0,s[1].length-1);
                if(s[0].toLowerCase() == key.toLowerCase()) return s[1];
            }
        }
        return "";
    }   ,
    Host : function(){
        var url = location.href.toLowerCase().replace("http://","");
        return url.indexOf("/") == -1 ? url : url.substring(0, url.indexOf("/"));
    }
}


/*  Cookie  */
var Cookie = {
    GetValue : function(name){
        var value = null;
        var cookie = document.cookie; 
        var cookies = cookie.split(";");
        for(var i=0; i<cookies.length; i++){
            var cookieName = cookies[i].substring(0,cookies[i].indexOf("="));
            if(cookieName.Trim() == name){
               value =  cookies[i].substring(cookies[i].indexOf("=") + 1);
            }
        }
        return value;
    }   ,
    
    SetValue : function(name,value,expires){

        document.cookie = name + "=" + escape (value) + (expires == null || expires == undefined ? "" : "; expires=" + expires.toGMTString())
    }   
}
