// JavaScript Document
/*
Xuat 1 banner
input: bannerArr1: mang chua thong tin ve banner
outbut: banner
*/
function BannerAD(bannerArr)
{	
	var bannerArrLength = bannerArr.length-1;
	
	var theOutputString = "";	
			
	for(var i=0; i<=bannerArrLength; i++)
	{					
		
		switch (bannerArr[i][0])
		{
			case "99":
				//hinh gif
				if (bannerArr[i][4] != "")
				{
					if (bannerArr[i][5] != "" && bannerArr[i][5] != "_blank")
					{							
						theOutputString += "<a href='" + bannerArr[i][4] + "' target='" + bannerArr[i][5] + "' onclick='return OpenWindow(\"" + bannerArr[i][4] + "\",\"" + bannerArr[i][5] + "\")' ><img src='" + bannerArr[i][3] + "' border='0' alt='" + bannerArr[i][6] + "'></a>";
					}
					else
					{
						theOutputString += "<a href='" + bannerArr[i][4] + "' target='" + bannerArr[i][5] + "'><img src='" + bannerArr[i][3] + "' border='0' alt='" + bannerArr[i][6] + "'></a>";		
					}
				
				}
				else
				{
					theOutputString += "<img src='" + bannerArr[i][3] + "' border='0' alt='" + bannerArr[i][6] + "'>";	
				}
				
				break;
			case "103":
				// hinh flash
				theOutputString += '<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="' + bannerArr[i][1] + '" height="' + bannerArr[i][2] + '"><param name="movie" value="' + bannerArr[i][3] + '?clicktag=' + bannerArr[i][4] + '"><param name="quality" value="high"><embed src="' + bannerArr[i][3] + '?clicktag=' + bannerArr[i][4] + '" quality="high" pluginspage="http://www.macromedia.com/go/getflashplayer" type="application/x-shockwave-flash" width="' + bannerArr[i][1] + '" height="' + bannerArr[i][2] + '"></embed></object>';
	
				break;
		}//end switch		
	}//end for					
	document.write(theOutputString);
}

/*
Xuat 1 banner
input: bannerArr1: mang chua thong tin ve banner
outbut: banner
*/
function BannerAD2(bannerArr)
{	
	var bannerArrLength = bannerArr.length-1;
	
	var theOutputString = "";	
			
	for(var i=0; i<=bannerArrLength; i++)
	{						
		theOutputString += "<div class='part" + (i+1) + "'>";
		switch (bannerArr[i][0])
		{
			case "99":
				//hinh gif
				if (bannerArr[i][4] != "")
				{
					if (bannerArr[i][5] != "" && bannerArr[i][5] != "_blank")
					{							
						theOutputString += "<a href='" + bannerArr[i][4] + "' target='" + bannerArr[i][5] + "' onclick='return OpenWindow(\"" + bannerArr[i][4] + "\",\"" + bannerArr[i][5] + "\")' ><img src='" + bannerArr[i][3] + "' border='0' alt='" + bannerArr[i][6] + "'></a>";
					}
					else
					{
						theOutputString += "<a href='" + bannerArr[i][4] + "' target='" + bannerArr[i][5] + "'><img src='" + bannerArr[i][3] + "' border='0' alt='" + bannerArr[i][6] + "'></a>";		
					}
				
				}
				else
				{
					theOutputString += "<img src='" + bannerArr[i][3] + "' border='0' alt='" + bannerArr[i][6] + "'>";	
				}
				
				break;
			case "103":
				// hinh flash
				theOutputString += '<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="' + bannerArr[i][1] + '" height="' + bannerArr[i][2] + '"><param name="movie" value="' + bannerArr[i][3] + '?clicktag=' + bannerArr[i][4] + '"><param name="quality" value="high"><embed src="' + bannerArr[i][3] + '?clicktag=' + bannerArr[i][4] + '" quality="high" pluginspage="http://www.macromedia.com/go/getflashplayer" type="application/x-shockwave-flash" width="' + bannerArr[i][1] + '" height="' + bannerArr[i][2] + '"></embed></object>';
	
				break;
		}//end switch
		theOutputString += "</div>";
	}//end for					
	document.write(theOutputString);
}

/*
Xuat nhieu banner mot luc nen moi banner duoc dat trong 1 the div
input: bannerArr1: mang chua thong tin ve banner
		divAttributes: thuoc tinh cua the div
outbut: cac banner theo hang doc
*/
function BannerADRandom(bannerArr1, divAttributes)
{
	var theOutputString = "";
	var bannerArrLength = bannerArr1.length;
	//alert(bannerArrLength);
	var ranInd = new Array();
	ranInd = Deal(bannerArr1.length);
	//alert("ran=" + ranInd);
	for(var i=0; i<bannerArrLength; i++)
	{				
		theOutputString += "<div " + divAttributes + ">";
		switch (bannerArr1[ranInd[i]][0])
		{
			case "99":
				//hinh gif
				if (bannerArr1[ranInd[i]][4] != "")
				{
					if (bannerArr1[ranInd[i]][5] != "" && bannerArr1[ranInd[i]][5] != "_blank")
					{							
						theOutputString += "<a href='" + bannerArr1[ranInd[i]][4] + "' target='" + bannerArr1[ranInd[i]][5] + "' onclick='return OpenWindow(\"" + bannerArr1[ranInd[i]][4] + "\",\"" + bannerArr1[ranInd[i]][5] + "\")' ><img src='" + bannerArr1[ranInd[i]][3] + "' border='0' alt='" + bannerArr1[ranInd[i]][6] + "' ></a>";
					}
					else
					{
						theOutputString += "<a href='" + bannerArr1[ranInd[i]][4] + "' target='" + bannerArr1[ranInd[i]][5] + "'><img src='" + bannerArr1[ranInd[i]][3] + "' border='0' alt='" + bannerArr1[ranInd[i]][6] + "' ></a>";		
					}
				
				}
				else
				{
					theOutputString += "<img src='" + bannerArr1[ranInd[i]][3] + "' border='0' alt='" + bannerArr1[ranInd[i]][6] + "'>";	
				}
				
				break;
			case "103":
				// hinh flash
				theOutputString += '<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="' + bannerArr1[ranInd[i]][1] + '" height="' + bannerArr1[ranInd[i]][2] + '"><param name="movie" value="' + bannerArr1[ranInd[i]][3] + '?clicktag=' + bannerArr1[ranInd[i]][4] + '"><param name="quality" value="high"><embed src="' + bannerArr1[ranInd[i]][3] + '?clicktag=' + bannerArr1[ranInd[i]][4] + '" quality="high" pluginspage="http://www.macromedia.com/go/getflashplayer" type="application/x-shockwave-flash" width="' + bannerArr1[ranInd[i]][1] + '" height="' + bannerArr1[ranInd[i]][2] + '"></embed></object>';
	
				break;
		}//end switch
		theOutputString += "</div>";
	}//end for
	
	document.write(theOutputString);
}

/*
Xuat nhieu banner mot luc nen moi banner duoc dat trong 1 the div
input: bannerArr1: mang chua thong tin ve banner
outbut: cac banner theo hang doc
*/
function BannerADRandomH(bannerArr1, length)
{
	var theOutputString = "";
	var ranInd = new Array();
	ranInd = Deal(bannerArr1.length);
	//alert("ran=" + ranInd);
	for(var i=0; i<length; i++)
	{				
		theOutputString += "<div class='part" + (i+1) + "'>";
		switch (bannerArr1[ranInd[i]][0])
		{
			case "99":
				//hinh gif
				if (bannerArr1[ranInd[i]][4] != "")
				{
					if (bannerArr1[ranInd[i]][5] != "" && bannerArr1[ranInd[i]][5] != "_blank")
					{							
						theOutputString += "<a href='" + bannerArr1[ranInd[i]][4] + "' target='" + bannerArr1[ranInd[i]][5] + "' onclick='return OpenWindow(\"" + bannerArr1[ranInd[i]][4] + "\",\"" + bannerArr1[ranInd[i]][5] + "\")' ><img src='" + bannerArr1[ranInd[i]][3] + "' border='0' alt='" + bannerArr1[ranInd[i]][6] + "' ></a>";
					}
					else
					{
						theOutputString += "<a href='" + bannerArr1[ranInd[i]][4] + "' target='" + bannerArr1[ranInd[i]][5] + "'><img src='" + bannerArr1[ranInd[i]][3] + "' border='0' alt='" + bannerArr1[ranInd[i]][6] + "' ></a>";		
					}
				
				}
				else
				{
					theOutputString += "<img src='" + bannerArr1[ranInd[i]][3] + "' border='0' alt='" + bannerArr1[ranInd[i]][6] + "'>";	
				}
				
				break;
			case "103":
				// hinh flash
				theOutputString += '<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="' + bannerArr1[ranInd[i]][1] + '" height="' + bannerArr1[ranInd[i]][2] + '"><param name="movie" value="' + bannerArr1[ranInd[i]][3] + '?clicktag=' + bannerArr1[ranInd[i]][4] + '"><param name="quality" value="high"><embed src="' + bannerArr1[ranInd[i]][3] + '?clicktag=' + bannerArr1[ranInd[i]][4] + '" quality="high" pluginspage="http://www.macromedia.com/go/getflashplayer" type="application/x-shockwave-flash" width="' + bannerArr1[ranInd[i]][1] + '" height="' + bannerArr1[ranInd[i]][2] + '"></embed></object>';
	
				break;
		}//end switch
		theOutputString += "</div>";
	}//end for
	
	document.write(theOutputString);
}

function Deal(N) { 
	var J, K, Q = new Array(N)
	for (J=0; J<N; J++) { 
		K = Random(J+1) ; 
		Q[J] = Q[K] ; 
		Q[K] = J 
	}
	return Q 
}

function Random(N) { return Math.floor(N*(Math.random()%1)) }

/**

 */
function getRandom(theNumber)
{
	//alert(Math.round(Math.random() * theNumber));
	return Math.round(Math.random() * theNumber);
}






