/*
========================
FOR NGACN ONLY
------------
(c) 2005 Zeg All Rights Reserved
========================
广告列表生成 广告生成 通用程序 v1.01
written by zeg 2007/12/14
========================
*/

ngaAds.objClone = function(obj){
if(obj == null || typeof(obj) != 'object')return obj;
var temp = new obj.constructor();
for(var key in obj)temp[key] = this.objClone(obj[key]);
return temp;
}

ngaAds.genadslist = function (ads)
{
var date = new Date;
var now = (date.getMonth()+1)+'/'+date.getDate()+'/'+date.getFullYear();
var nowtime = Date.parse(now);
var xxoo = date.getTime();
var rateSum = new Array;
var rnd = new Array;
var ads2 = new Array;
var tempDate = null;
var tempShow = false;
var tempi = 0;
for (k in ads)
	{
		
		if (typeof(ads[k])=='function'){
			ads2[k]=ads[k];
			continue;
			}
		if (ads[k]['id'] && ads[k]['date'])
		{
			ads[k]['date'] =  ads[k]['date'].replace(/(^| |\/)0/g,'$1');
			tempShow = false;
			if (ads[k]['date'] == 'all')
			{
				tempShow = true;
			}
			else
			{
				var ni = -1;
				var od;
				tempDate = ads[k]['date']+' ';
				while (tempDate && ((ni = tempDate.indexOf(' ')) != -1) )
				{
					od = tempDate.substr(0,ni);
					tempDate = tempDate.substr(ni+1);
					if (od.length>11)
					{
						od = od.split('-');
						if (od[1])
							{
								if (nowtime>=Date.parse(od[0]) && nowtime<=Date.parse(od[1]))
									{
										tempShow = true;
										break;
									}
							}
					}
					else
					{
						if (now == od)
							{
								tempShow = true;
								break;
							}
					}
				}
			}
			if (tempShow)
			{
				if (!rateSum[ads[k]['id']])
				{
					rateSum[ads[k]['id']] = 0;
				}
				if (!rnd[ads[k]['id']])
				{
					rnd[ads[k]['id']] = Math.floor(Math.random()*100);
					//if (window.location.href.indexOf('debug')!=-1) document.title+=ads[k]['id']+':'+rnd[ads[k]['id']]+' ';
				}
				//if (!ads[k]['rate'])
				//{
				//	ads[k]['rate'] = 100;
				//}
				rateSum[ads[k]['id']] = rateSum[ads[k]['id']] + ads[k]['rate'];
				if (rnd[ads[k]['id']]<rateSum[ads[k]['id']] && !ads2[ads[k]['id']])
				{
					if (!ads2[ads[k]['id']])
					{
						ads2[ads[k]['id']] = new Array;
					}
					ads2[ads[k]['id']] = this.objClone(ads[k])
					ads2[ads[k]['id']]['now'] = nowtime;
					rnd[ads[k]['id']] = 1000;
				}
			}
		}
	}
return ads2;
}
//fe

//-------------------------------
ngaAds = ngaAds.genadslist(ngaAds);//<-------------------
ngaAds.googleAD = new Array
ngaAds.googleADloop = 0
ngaAds.googleADnum = 0
ngaAds.objClone = function(o) {
var tmp = new Object
for (var k in o)
	{
	if (typeof(o[k])=='object')
		{
		tmp[k] = ngaAds.objClone(o[k])
		}
	else
		{
		tmp[k] = o[k]
		}
	}
return tmp
} 
//-------------------------------

ngaAds.genAdsCount = function (obj,u)
{
ngaAds['clickedlink'] = obj;
window.setTimeout("ngaAds.genAdsCountAct(ngaAds['clickedlink'],'"+u+"')",100)
}
//fe

ngaAds.genAdsCountAct = function (obj,u)
{
var x = document.createElement('iframe');
x.src = u;
x.style.display='none';
obj.parentNode.appendChild(x)
}
//fe

ngaAds.genAds = function (a)
{
	function cut(f)
	{
		return f.replace(/^http:\/\/.+?\/misc\//i,'').replace(/\/|\./g,'_');
	}
if(!window._ngaAdsObjList)window._ngaAdsObjList = {};
if (a['type']=='js')
	{
		return "<scr"+"ipt type='text/javascr"+"ipt' src='"+a['file']+"'></scr"+"ipt>"
	}
else if (a['type']=='alimama')
	{
		var sizecode='12';
		if (a['width'] == 950)
		{
			sizecode='15';
		}
		else if (a['width'] == 760)
		{
			sizecode='11';
		}
		alimama_pid=a['file']; 
		alimama_titlecolor="0000FF"; 
		alimama_descolor ="000000"; 
		alimama_bgcolor="444444"; 
		alimama_bordercolor="E6E6E6"; 
		alimama_linkcolor="008000"; 
		alimama_bottomcolor="FFFFFF"; 
		alimama_anglesize="0"; 
		alimama_bgpic="0"; 
		alimama_icon="0"; 
		alimama_sizecode=sizecode; 
		alimama_width=a['width']; 
		alimama_height=a['height']; 
		alimama_type=2;
		return "<scr"+"ipt type='text/javascr"+"ipt' src='http://a.alimama.cn/inf.js'></scr"+"ipt>"
	}
else if (a['type']=='baidu')
	{
		this.googleAD.push(this.objClone(a))
		return ""
	}
else if (a['type']=='txt')
	{
		return a['file']
	}
else if (a['type']=='iframe')
	{
		var id = 'ngaAdsObj'+Math.random().toString().substr(2)
		window._ngaAdsObjList[id] = a['file'];
		a['width'] = ' ;width:'+a['width']+'px ';
		a['height'] = ' ;height:'+a['height']+'px ';
		return "<ifr"+"ame style='margin:0px"+a['width']+a['height']+";overflow:hidden' scrolling='no' frameborder='0' src='"+a['file']+"' style='border:1px solid #000' id='"+id+"'></ifr"+"ame>";
	}
else
	{
		var id = 'ngaAdsObj'+Math.random().toString().substr(2)
		window._ngaAdsObjList[id] = a['file'];
		var log = '';
		if (!a['nolog'])
			{
			log = " onclick='ngaAds.genAdsCount(this,\"http://old.ngacn.cc/clicklog/clicklog.php?id="+a['id']+"&time="+a['now']+"&from="+cut(a['file'])+"\");'"
			}
		if (typeof(a['file'])=='string' && a['file'].substr((a['file'].length-3),3) == 'swf')
		{
			var img = '<object classid="clsid:d27cdb6e-ae6d-11cf-96b8-444553540000" codebase="http://download.macromedia.com/pub/shockwave/cabs/flash/swflash.cab#version=6,0,0,0" style="background:#000" width="'+a['width']+'" height="'+a['height']+'" id="'+id+'"><param value="transparent" name="wmode"/><param name="movie" value="'+a['file']+'"/><embed wmode="transparent" src="'+a['file']+'" width="'+a['width']+'" height="'+a['height']+'"/></object>';
			if (a['url'])
			{
				if (typeof(__COMMONIMG_PATH)=='undefined') __COMMONIMG_PATH = 'http://img.ngacn.cc/web/res';
				img = "<a href='"+a['url']+"' style='display:block;width:"+a['width']+"px;height:"+a['height']+"px;margin:auto;overflow:hidden;line-height:0px;font-size:0px' target='_blank' title='"+a['title']+"'>"+img+"<img src='"+__COMMONIMG_PATH+"/null.gif' style='width:"+a['width']+"px;height:"+a['height']+"px;position:relative;top:-"+a['height']+"px;margin-bottom:-"+a['height']+"px'"+log+"/></a>";
			}
			return img
		}
		else
		{
			if (a['width'])
			{
				a['width'] = ' ;width:'+a['width']+'px ';
			}
			if (a['height'])
			{
				a['height'] = ' ;height:'+a['height']+'px ';
			}
			var img = "<img id='"+id+"' src='"+a['file']+"' title='"+a['title']+"' style='border:1px solid #000000;"+a['width']+a['height']+"'"+log+"/>";
			if (a['url'])
			{
				img = "<a href='"+a['url']+"' target='_blank' title='"+a['title']+"'>"+img+"</a>";
			}
			return img;
		}
	}
}
//fe

ngaAds.applyGoogleAD =function ()
{
if (this.googleADnum)
	{
	var f = document.getElementsByTagName('iframe')
	for (var i=0; i<f.length; i++)
		{
		if (f[i].name=='google_ads_frame')
			{
			if (f[i].parentNode.getAttribute('adscontainerid'))
				{
				id2e(f[i].parentNode.getAttribute('adscontainerid')).appendChild(f[i]);
				}
			else if (f[i].previousSibling.previousSibling.getAttribute('adscontainerid'))
				{
				id2e(f[i].previousSibling.previousSibling.getAttribute('adscontainerid')).appendChild(f[i]);
				}
			}
		else if (f[i].src.toLowerCase().indexOf('http://cpro.baidu.com/')!=-1)
			{
			//window.alert(f[i].contentWindow.document.body.innerHTML)
			if (f[i].parentNode.getAttribute('adscontainerid'))
				{
				id2e(f[i].parentNode.getAttribute('adscontainerid')).appendChild(f[i]);
				}
			else if (f[i].previousSibling.previousSibling.getAttribute('adscontainerid'))
				{
				id2e(f[i].previousSibling.previousSibling.getAttribute('adscontainerid')).appendChild(f[i]);
				}
			}
		}
	if (f.length<this.googleADnum && this.googleADloop<100)
		{
		this.googleADloop ++
		window.setTimeout(ngaAds.applyGoogleAD,200);
		}
	}
}
//fe

ngaAds.loadOneGoogleAD=function ()
{
if (this.googleAD.length)
	{
	if (!this.googleADnum)
		{
		this.googleADnum = this.googleAD.length
		}

	var g = this.googleAD.shift();
	if (g)
		{
		for (var k in g['args'])
			{
			window[k] = g['args'][k]
			}
		document.write ("<div style='display:none' name='cgfvyhjvf' adscontainerid='"+g['ads_container_id']+"'>");
		document.write ("<sc"+"ript type='text/javasc"+"ript' src='"+g['file']+"'></sc"+"ript>");
		document.write ("</div>");
		}


	}
}
//fe