﻿/// <summary>
/// F123广告，by satans17@163.com 2008.1.3
/// </summary>
/// <param name="t">广告类型</param>
/// <param name="s">广告资源</param>
/// <param name="l">广告链接</param>
/// <param name="a">鼠标提示</param>
/// <param name="w">广告宽度</param>
/// <param name="h">广告高度</param>
function F123Ad(t,s,l,a,w,h)
{
	this.type		=t?t.toLowerCase():null;
	this.source		=s;
	this.link		=l;
	this.alt		=a?a:null;
	this.width		=w?w:0;
	this.height		=h?h:0;
	this.endtime	=null;//广告的过期时间
	/// <summary>
	/// 查找对象
	/// </summary>
	/// <param name="id">要查找的对象id</param>
	/// <returns>ID为id的对象</returns>
	this.getElementById = function(id)
	{
		if (typeof(id) != "string" || id == "") return null;
		if (document.getElementById) return document.getElementById(id);
		if (document.all) return document.all(id);
		try {return eval(id);} catch(e){ return null;}
	}
}

/// <summary>
/// 获取html
/// </summary>
F123Ad.prototype.getHtml = function()
{
	if(!this.endtime)
	{
		var t = new Date(this.endtime);
		if(t>new Date())
		{
			return "<div style=\"width:"+this.width+"px;height:"+this.height+"px;text-align:center;line-height:"+this.height+"px;\">此广告位已过期</div>";
		}
	}
	switch(this.type)
	{
		case "text":
			return "<a href=\""+this.link+"\" title=\""+this.alt+"\">"+this.source+"</a>";
			break;
		case "img":
			return "<a href=\""+this.link+"\" title=\""+this.alt+"\"><img src=\""+this.source+"\" width=\""+this.width+"\" height=\""+this.height+"\" \/></a>";
			break;
		case "swf":
			return "<object classid=\"clsid:D27CDB6E-AE6D-11cf-96B8-444553540000\" codebase=\"http://download.macromedia.com/pub/shockwave/cabs/flash/swflash.cab#version=6,0,29,0\" width=\""+this.width+"\" height=\""+this.height+"\"><param name=\"movie\" value=\""+this.source+"\"><param name=\"quality\" value=\"high\"><embed src=\""+this.source+"\" quality=\"high\" pluginspage=\"http://www.macromedia.com/go/getflashplayer\" type=\"application/x-shockwave-flash\" width=\""+this.width+"\" height=\""+this.height+"\"></embed></object>";
			break;
		case "video":
			return "<div style=\"width:"+this.width+"px;height:"+this.height+"px;text-align:center;line-height:"+this.height+"px;\">还不支持视频</div>";
			break;
		case "frame":
			return "<iframe src=\""+this.source+"\" width=\""+this.width+"\" heitht=\""+this.height+"\" frameborder=\"0\" scrolling=\"no\"></iframe>";
			break;
		default:
			return "<div style=\"width:"+this.width+"px;height:"+this.height+"px;text-align:center;line-height:"+this.height+"px;\">广告招商</div>";
			break;
	}
}

/// <summary>
/// 函数初始化入口
/// <param name="i">装载广告的容器</param>
/// </summary>
F123Ad.prototype.toString = function(i)
{
	var I=this;
	if(typeof i=="string")
	{
		var b = this.getElementById(i);
		if(b)
		{
			this.getElementById(i).innerHTML=I.getHtml()
		}
		else
		{
			alert("请使用正确的容器id");
			return;
		}
	}
	else if(typeof i=="object")
	{
		i.innerHTML=I.getHtml()
	}
}