var xmlHttp;
var wItems, ItemsNo;
var wCategory, CategoryASP;
var wWidth, wHeight;
if (typeof wWidth == 'undefined') {	wWidth = 200;}
if (typeof wHeight == 'undefined') { wHeight = 250;}

var xWidth, xHeight;
xWidth = parseInt(wWidth) - 20;
xHeight = parseInt(wHeight) - 58;

//alert(wWidth);
//wItems = 5;
//wCategory = "PHOTO";

if (wItems == 5)
{
	ItemsNo = 6;
} else {
	ItemsNo = 11;
}

if (wCategory == "Photos")
{
	CategoryASP = "http://www.wcg.com/6th/fun/widget/photo_com.asp"
} else {
	CategoryASP = "http://www.wcg.com/6th/fun/widget/news_com.asp"
}

function createXMLHttpRequest() {
    if (window.ActiveXObject) {
        xmlHttp = new ActiveXObject("Microsoft.XMLHTTP");
    }
    else if (window.XMLHttpRequest) {
        xmlHttp = new XMLHttpRequest();
    }
}

function startRequest() {
    createXMLHttpRequest();
    xmlHttp.onreadystatechange = handleStateChange;
    xmlHttp.open("GET", CategoryASP, true);
    xmlHttp.send(null);
}

function handleStateChange() {
    if(xmlHttp.readyState == 4) {
        if(xmlHttp.status == 200) {
			var xml = xmlHttp.responseXML;

			if (wCategory == "Photos")
			{
				var Imagelink	= xml.getElementsByTagName("imagelink")
				var arrImagelink	= new Array();
			}

			var	Title		= xml.getElementsByTagName("title")
			var	Links		= xml.getElementsByTagName("link")
			var	Description	= xml.getElementsByTagName("description")
			var arrTitle	= new Array();
			var arrLink		= new Array();
			var arrDesc		= new Array();

			for (var i=1; i<ItemsNo ; i++)
			{
				if (wCategory == "Photos")
				{
					arrImagelink[i] = Imagelink.item(i).firstChild.nodeValue;
				}

				arrTitle[i] = Title.item(i).firstChild.nodeValue;
				arrLink[i] = Links.item(i).firstChild.nodeValue;
				arrDesc[i] = Description.item(i).firstChild.nodeValue;

			}


var embedObj;

//embedObj = ' <body topmargin="0" leftmargin="0"> '
embedObj =			  ' <table width='+wWidth+' height='+xHeight+' border="0" cellspacing="0" cellpadding="0"  bgcolor="#e1e1df"> '
embedObj = embedObj + ' 	<tr> '
embedObj = embedObj + ' 		<td bgcolor="#e1e1df" style="padding: 10px 10px 5px 10px;"> '
embedObj = embedObj + ' 			<table width="100%" border="0" cellspacing="0" cellpadding="0"> '
embedObj = embedObj + ' 				<tr> '
embedObj = embedObj + ' 					<td width="64%" style="font-family: Tahoma;font-size: 12px; color:#3a3838;"><b>WCG '+wCategory+' </b></td> '
embedObj = embedObj + ' 					<td width="36%" align="right"><a href="http://www.wcg.com" target="_blank"><img src="http://www.wcg.com/images/6th/alliance/pre_logo.gif" width="72" height="23" border="0" /></a></td> '
embedObj = embedObj + ' 				</tr> '
embedObj = embedObj + ' 			</table> '
embedObj = embedObj + ' 		</td> '
embedObj = embedObj + ' 	</tr> '
embedObj = embedObj + ' 	<tr> '
embedObj = embedObj + ' 		<td style="padding:0 10px"> '
embedObj = embedObj + ' 		<div style="overflow:auto; width:'+xWidth+'; height:'+xHeight+' "> '
embedObj = embedObj + ' 			<table width="100%" border="0" cellpadding="0" cellspacing="0" bgcolor="#FFFFFF"> '
for (var i=1; i<ItemsNo ; i++) {
	if (wCategory == "Photos") {
embedObj = embedObj + ' 				<tr> '
embedObj = embedObj + ' 					<td width="70" style="padding:5px;"><a href="http://www.wcg.com/6th/fun/photogallery/photogallery.asp" target="_blank"><img src="'+arrImagelink[i]+'" width="70" height="53" border="0"></a></td> '
embedObj = embedObj + ' 					<td style="padding:5px;font-family: Tahoma; font-size:11px; color:#000000; line-height: 14px;"><a href="http://www.wcg.com/6th/fun/photogallery/photogallery.asp" target="_blank" style="color:#000000; text-decoration:none;">'+arrTitle[i]+'</a></td> '
embedObj = embedObj + ' 				</tr> '
	} else {
embedObj = embedObj + ' 				<tr> '
embedObj = embedObj + ' 					<td style="padding:10px; font-family: Tahoma; font-size:11px; color:#000000; line-height: 14px;"><a href="'+arrLink[i]+'" target="_blank" style="color:#000000; text-decoration:none;"> '
embedObj = embedObj + ' 					<b>'+arrTitle[i]+'</b><br>'+arrDesc[i]+'</a></td> '
embedObj = embedObj + ' 				</tr> '
	}
}
embedObj = embedObj + ' 			</table> '
embedObj = embedObj + ' 		</div> '
embedObj = embedObj + ' 		</td> '
embedObj = embedObj + ' 	</tr> '
embedObj = embedObj + ' 	<tr> '
embedObj = embedObj + ' 		<td align="center"><a href="http://www.wcg.com" target="_blank" style="font-family: Tahoma; font-size:10px; color:#757575;">Provided by WCG</a></td> '
embedObj = embedObj + ' 	</tr> '
embedObj = embedObj + ' </table> '
//embedObj = embedObj + ' </body> '


widget.innerHTML = embedObj;

        }
    }
}


