function adlistshow(AdList, AdName, CheckShow, ShowType, Interface, LimitWidth, LimitHeight, Extra){
	this.myid=AdName;
	this.checkshow=CheckShow;
	this.limitwidth=LimitWidth;
	this.limitheight=LimitHeight;
	this.showtype=ShowType;
	this.face=Interface;
	this.delay=15000;
	if (typeof(Extra) == 'undefined') {this.extra='';} else {this.extra=Extra;}
	switch (ShowType) {
		case 0:	case 4:	case 5: case 6: this.readtype=0; break;
		default: this.readtype=1; break;
	}
	var arTemp = new Array();
	var i, j, k, no, showcount;
	i=0;j=-1;k=0;no=-1;showcount=1;
	if (this.readtype==0){
		for (i=0,j=0;i<AdList.length;i++){
			if (this.checkShowThis(AdList[i])){
				arTemp[j]=AdList[i];
				j++;
			}
		}
	}
	else{
		for (i=0;i<AdList.length;i++){
			if (AdList[i][5]!=no){
				no=AdList[i][5];
				if (showcount>0) j++;
				showcount=0;
				k=0;
			}
			if (this.checkShowThis(AdList[i])){
				if (k==0) arTemp[j] = new Array();
				arTemp[j][k] = AdList[i];
				showcount++;
				k++;
			}
		}
	}
	this.itemcount=j+1;
	this.listvalue=arTemp;
	this.initialize();
}

adlistshow.prototype.initialize=function(){
	switch (this.showtype) {
		case 0: this.displayrotatorbanner(); break;
		case 1: case 7: this.displaylistbanner(); break;
		case 2: this.displayfloatbanner(0); break;
		case 3: this.displayfloatbanner(1); break;
		case 4: this.displayfloatbanner(2); break;
		case 5: this.displaypopupbanner(false); break;
		case 6: this.displaypopupbanner(true); break;
		default: break;
	}
}

adlistshow.prototype.checkLastObj=function(index){
	if (this.readtype==0){
		return true;
	}
	else {
		if (this.listvalue.length==index+1){
			return true;
		}
		else {
			return false;
		}
	}
}

adlistshow.prototype.displayrotatorbanner=function(){
	document.write('<table ', (this.limitwidth>0)?'width='.concat(this.limitwidth):'', ' cellspacing=0 cellpadding=0 border=0>');
	this.writerotatorbanner(this.listvalue,0);
	document.write('</table>');
}

adlistshow.prototype.displaylistbanner=function(){
	if (this.face==0){
		document.write('<table ', (this.limitwidth>0)?'width='.concat(this.limitwidth):'', ' cellspacing=0 cellpadding=0 border=0 align=center>');
	}
	for (var i=0;i<this.listvalue.length;i++){
		if (this.listvalue[i][0][5]<100){
			this.writerotatorbanner(this.listvalue[i],i,this.checkLastObj(i));
		}
		else {
			this.writerandombanner(this.listvalue[i],this.checkLastObj(i));
		}
	}
	if (this.face==0){
		document.write('</table>');
	}
}

adlistshow.prototype.displayfloatbanner=function(type){
	if (type==2){
		document.write('<DIV id="floatdiv',this.myid,'" style="position:absolute;overflow:hidden;left:-200;',(this.limitheight>0)?'height:'.concat(this.limitheight):'180',';',(this.limitwidth>0)?'width:'.concat(this.limitwidth):'100',';">');
		this.writebottomupbanner(this.listvalue);
	}
	else{
		document.write('<DIV id="floatdiv',this.myid,'" style="position:absolute;left:-200;',(this.limitwidth>0)?'width:'.concat(this.limitwidth):'100',';">');
		if (RelatedFolder==1000 && type==1) document.writeln('<iframe width="120" height="600" noresize scrolling=No frameborder=0 marginheight=0 marginwidth=0 src="http://rotator.adjuggler.com/servlet/ajrotator/196652/0/vh?z=newmediaww&dim=193431"><script language=JavaScript src="http://rotator.adjuggler.com/servlet/ajrotator/196652/0/vj?z=newmediaww&dim=193431&abr=$scriptiniframe"></script><noscript><a href="http://rotator.adjuggler.com/servlet/ajrotator/196652/0/cc?z=newmediaww"><img src="http://rotator.adjuggler.com/servlet/ajrotator/196652/0/vc?z=newmediaww&dim=193431&abr=$imginiframe" width="120" height="600" border="0"></a></noscript></iframe>');
		this.displaylistbanner();
	}
	document.write('</DIV>');
	FloatTopDiv('floatdiv'.concat(this.myid),type);
}

adlistshow.prototype.displaypopupbanner=function(type){
	vIndex = this.listvalue[0][2].lastIndexOf(',');
	vID = this.listvalue[0][2].substr(vIndex + 2);
	sLink = buildLink(vID,this.listvalue[0][1]);
	var arrPara = this.listvalue[0][2].split(",");	
	openPopup(this.listvalue[0][0], sLink, 'Advertisment', arrPara[2], arrPara[9], arrPara[8], screen.height - arrPara[9] - 80, (screen.width - 770)/2 + 410 - 5, type);
}

adlistshow.prototype.writerotatorbanner=function(obj,index,lastobj){
	obj.sort(randOrd);
	if (this.face==1) {
		document.write('<tr><td id="', this.myid, '_', index, '" style="padding:4px;">');
	}
	else {
		document.write('<tr><td id="', this.myid, '_', index, '">');
	}
	document.write(buildhtml(obj[0],this.limitwidth,this.limitheight));
	if (obj.length>1){
		var idtemp = ''.concat(this.myid).concat('_').concat(index);
		var delaytime = this.delay + Math.round(Math.random()*10000);
		var limitwidth = this.limitwidth;
		var limitheight = this.limitheight;
		setTimeout(function(){changebanner(obj,0,idtemp,delaytime,limitwidth,limitheight)}, delaytime);
	}
	document.write('</td></tr>');
	if (this.face==0){
		document.write('<tr><td height="3"></td></tr>');
	}
	if (this.face==1 && (!lastobj)) {
		document.write('<tr><td height="1" bgcolor="#808080"></td></tr>');
	}
}

adlistshow.prototype.writerandombanner=function(obj,lastobj){
	obj.sort(randOrd);
	for (var i=0;i<obj.length;i++){
		if (this.face==1) {
			document.write('<tr><td style="padding:4px;">');
		}
		else{
			document.write('<tr><td>');
		}
		document.write(buildhtml(obj[i],this.limitwidth,this.limitheight));
		document.write('</td></tr>');
		if (this.face==0){
			document.write('<tr><td height="3"></td></tr>');
		}
		if (this.face==1 && (i<obj.length-1)) {
			document.write('<tr><td height="1" bgcolor="#808080"></td></tr>');
		}
	}
}

adlistshow.prototype.writebottomupbanner=function(obj){
	obj.sort(randOrd);
	document.write('<DIV id="subdiv',this.myid,'" style="position:absolute;',(this.limitheight>0)?'top:'.concat(this.limitheight):'180',';',(this.limitwidth>0)?'width:'.concat(this.limitwidth):'100',';',(this.limitheight>0)?'height:'.concat(this.limitheight):'180',';">');
	document.write(buildhtml(obj[0],this.limitwidth,this.limitheight));
	var idtemp = 'subdiv'.concat(this.myid);
	var delaytime = this.delay + Math.round(Math.random()*10000);
	var limitwidth = this.limitwidth;
	var limitheight = this.limitheight;
	var delaytime=this.delay + Math.round(Math.random()*10000);
	setTimeout(function(){startbottomupbanner(obj,0,idtemp,delaytime,limitwidth,limitheight)}, 500);
	document.write('</DIV>');
}


function buildhtml(obj,limitwidth,limitheight){
	if (!obj) {return ''}
	var sTemp = '';
	var sImageLink = (Left(obj[0],7).toLowerCase() == 'http://')?obj[0]:PageHost.concat(obj[0]);
	var imagewidth = (limitwidth<obj[3] && limitwidth>0)?limitwidth:obj[3];
	var imageheight = (limitheight<obj[4] && limitheight>0)?limitheight:obj[4];
	if (Right(obj[0],4).toLowerCase() == '.swf'){
		sTemp = sTemp.concat('<object classid="clsid:D27CDB6E-AE6D-11CF-96B8-444553540000" codebase="http://download.macromedia.com/pub/shockwave/cabs/flash/swflash.cab#version=6,0,40,0" border="0" width=').concat(imagewidth).concat(' height=').concat(imageheight).concat('>');
		sTemp = sTemp.concat('<param name="movie" value="').concat(sImageLink).concat('?link=').concat(escape(buildLink(obj[2].substring(obj[2].lastIndexOf(',')+2),obj[1]))).concat('">');
		sTemp = sTemp.concat('<param name="quality" value="High">');
		sTemp = sTemp.concat('<embed src="').concat(sImageLink).concat('?link=').concat(escape(buildLink(obj[2].substring(obj[2].lastIndexOf(',')+2),obj[1]))).concat('" pluginspage="http://www.macromedia.com/go/getflashplayer" type="application/x-shockwave-flash" width=').concat(imagewidth).concat(' height=').concat(imageheight).concat('>');
		sTemp = sTemp.concat('</object>');
	}
	else{
		if (obj[1] != '') {
			sTemp = '<a href="'.concat(obj[1]).concat('" onClick="return openMeExt(this, ').concat(obj[2]).concat(', 1)"><img src="').concat(sImageLink).concat('" border=0 width=').concat(imagewidth).concat(' height=').concat(imageheight).concat('></a></td>'); 
		}
		else {
			sTemp = '<img src="'.concat(sImageLink).concat('" border=0 width=').concat(imagewidth).concat(' height=').concat(imageheight).concat('></td>');
		}
	}
	return sTemp;
}

adlistshow.prototype.checkShowThis=function(obj){
	var checkShow=false;

	var iCheck = obj[6];
	
	if (iCheck == 3 && this.checkshow < 4) checkShow=true;
	else if (iCheck == this.checkshow || iCheck == 0) checkShow=true;
	
	//Truong hop dac biet Son nguyen chi quang cao o muc thue va cho thue nha
	if (RelatedFolder==9998)
		if (obj[1].indexOf('http://www.sonnguyenvn.com')>=0)
		{
			if (window.location.href.indexOf("c=12")>0 || window.location.href.indexOf("c=14")>0)
				{return true} else {return false}
		}

	if (checkShow && this.showtype==7){
		checkShow=false;
		if (typeof(dtSubjectDate) == 'undefined') return;
		var dtFromDate = new Date(obj[7]);
		var dtToDate = new Date(obj[8]);
		var iFromDiff = (dtSubjectDate.getTime()-dtFromDate.getTime())/1000;
		var iToDiff   = (dtToDate.getTime()-dtSubjectDate.getTime())/1000;
		if (iFromDiff<5*86400 && iFromDiff>=0 && iToDiff>5*86400 && iToDiff>=0){
			checkShow=true;
		}
	}
	else{
		return checkShow;
	}
	return checkShow;
}

//function randOrd(){ return (Math.round(Math.random())-0.5); } 
function randOrd(){ return (Math.random()*10000)-5000; } 

function buildLink(vID, vLink){
	return concat(escape(vLink));
}

function FloatTopDiv(divid,type){
	var startX, startY;
	if (type==1) {startX = document.body.clientWidth - 120;} else {startX = 2;}
	if (type==2) {startY = document.body.clientHeight;} else {startY = 1;}
	if (document.body.clientWidth < 1000) {startX = -170};

	window.stayFloat=function(ftlObj,type)
	{
		var startX, startY;
		var ns = (navigator.appName.indexOf("Netscape") != -1);
		if (type==1) {startX = document.body.clientWidth - 102;} else {startX = 2;}
		//if (document.body.clientWidth < 980) {startX = -102};
		if (document.body.clientWidth < 1000) {
			ftlObj.style.display = 'none';
		} 
		else {
			ftlObj.style.display = '';
			
			if (document.documentElement && document.documentElement.scrollTop)
				var pY = ns ? pageYOffset : document.documentElement.scrollTop;
			else if (document.body)
				var pY = ns ? pageYOffset : document.body.scrollTop;

			if (type==2){
				startY = document.body.clientHeight-183;
			}
			else{
				if (document.body.scrollTop > 100){startY = 3} else {startY = 1};
			}
			ftlObj.y += (pY + startY - ftlObj.y)/8;
			ftlObj.style.left=startX;
			ftlObj.style.top=ftlObj.y;
		}
		setTimeout(function(){stayFloat(ftlObj,type)}, 15);
	}

	var ftlObj = document.getElementById?document.getElementById(divid):document.all?d.all[divid]:document.layers[divid];
	if(!ftlObj) return;
	ftlObj.x = startX;
	ftlObj.y = startY;
	stayFloat(ftlObj,type);
}

function Left(str, n){
	if (n <= 0)
	    return "";
	else if (n > String(str).length)
	    return str;
	else
	    return String(str).substring(0,n);
}

function Right(str, n){
    if (n <= 0)
       return "";
    else if (n > String(str).length)
       return str;
    else {
       var iLen = String(str).length;
       return String(str).substring(iLen, iLen - n);
    }
}