function $(el){
	if(typeof el == 'string')
		return document.getElementById(el);
	if(typeof el == 'object')
		return el;
	return null;
}
var CookieManager = {
	getExpiresDate:function(days, hours, minutes) {
	    var ExpiresDate = new Date();
	    if (typeof days == "number" && typeof hours == "number" && 
	        typeof hours == "number") {
	        ExpiresDate.setDate(ExpiresDate.getDate() + parseInt(days));
	        ExpiresDate.setHours(ExpiresDate.getHours() + parseInt(hours));
	        ExpiresDate.setMinutes(ExpiresDate.getMinutes() + parseInt(minutes));
	        return ExpiresDate.toGMTString();
	    }
	},  
	_getValue:function(offset) {
	    var endstr = document.cookie.indexOf (";", offset);
	    if (endstr == -1) {
	        endstr = document.cookie.length;
	    }
	    return unescape(document.cookie.substring(offset, endstr));
	},
	get:function(name) {
	    var arg = name + "=";
	    var alen = arg.length;
	    var clen = document.cookie.length;
	    var i = 0;
	    while (i < clen) {
	        var j = i + alen;
	        if (document.cookie.substring(i, j) == arg) {
	            return this._getValue(j);
	        }
	        i = document.cookie.indexOf(" ", i) + 1;
	        if (i == 0) break; 
	    }
	    return "";
	},
	set:function(name, value, expires, path, domain, secure) {
	    document.cookie = name + "=" + escape (value) +
	        ((expires) ? "; expires=" + expires : "") +
	        ((path) ? "; path=" + path : "") +
	        ((domain) ? "; domain=" + domain : "") +
	        ((secure) ? "; secure" : "");
	},
	remove:function(name,path,domain) {
	    if (this.get(name)) {
	        document.cookie = name + "=" +
	            ((path) ? "; path=" + path : "") +
	            ((domain) ? "; domain=" + domain : "") +
	            "; expires=Thu, 01-Jan-70 00:00:01 GMT";
	    }
	},
	clear:function(){
		var cookies = document.cookie.split(';');
		for(var i=0; i < cookies.length; i++)
			this.remove(cookies[i].split('=')[0]);
	}
}
function FlashWriter(args){
	this.params = {};
	this.variables = {};
	this.properties = { url:'', width:300, height:225,id:''};
	for(var i in args)
		this.properties[i] = args[i];
}
FlashWriter.prototype = {
	render:function(){
		var html='<object  classid="clsid:d27cdb6e-ae6d-11cf-96b8-444553540000" codebase="http://fpdownload.macromedia.com/pub/shockwave/cabs/flash/swflash.cab#version=6,0,0,0" width="'+ this.properties.width +'" height="'+ this.properties.height +'"  id="'+this.properties.id+'"  name="'+this.properties.id+'">';
		html += '<param name="movie" value="'+this.properties.url+'">';
        html += '<param name="FlashVars" value="'+this.getVariableString()+'">';
		//html += '<param name="wmode" value="opaque">';
		html += this.getParamString(true);
        html += '<embed src="'+this.properties.url+ '" width="'+ this.properties.width +'" height="'+this.properties.height+'"  id="'+this.properties.id+'" name="'+this.properties.id+'"'+this.getParamString(false)+' FlashVars="'+this.getVariableString()+'" type="application/x-shockwave-flash" pluginspage="http://www.macromedia.com/go/getflashplayer" />';  
        html+='</object>';

        return html;
	},
	addParam:function(name, value){
		this.params[name] = value;
	},
	addVariable:function(name, value){
		this.variables[name] = value;
	},
	getVariableString:function(){
		var arr = [];
		for(var i in this.variables)
			arr.push(i+"="+this.variables[i])
		return arr.join('&');
	},
	getParamString:function(isIE){
		var arr = [];
		for(var i in this.params)
			if(isIE)
				arr.push('<param name="'+i+'" value="'+this.params[i]+'">');
			else
				arr.push(i+"="+this.params[i]);
		return arr.join(' ');
	},
	write:function(el){
		var o = document.getElementById(el);
		if(o == null) return;
		
		if(CookieManager.get('userid').length > 0)
			this.addVariable('uid',CookieManager.get('userid'));
		else
			this.addVariable('userid','');	
		
		if(CookieManager.get('sid').length > 0)	
			this.addVariable('sid',CookieManager.get('sid'));
		else
			this.addVariable('sid','');	
		if(CookieManager.get('location').length > 0)
			this.addVariable('locid',CookieManager.get('location'));
		else
			this.addVariable('locid','');		
		var ref = location.href;	
		if(ref.indexOf('#')!=-1)
		{
			if(ref.substr(ref.indexOf('#')).length>5)//#号有有内容			
			this.addVariable('pageurl',ref);
		}

	    fo.addVariable("from","live");
	    fo.addVariable("adcpid",1210);
	
		o.innerHTML = this.render();
	}
}


