
function StandardNewsJSWidget() {

    this.width=200;
	this.height=200;
	this.scroll_direction="Down";
	this.story_height=30;
	this.background_light="FFFFFF";
	this.background_dark="F3F3F3";
	this.border="EEEEEE";
	this.border_inner="EEEEEE";
	this.feed="";
	this.div_name="";
	this.vpadding=4;
	this.hpadding=4;
	this.limit_dir="Down";
	this.limit_amount=2;
	this.size_type="Adjust";
	this.scroll_width=17;
	
	this.title_height=16;
	this.title_color="000000";
	this.text_color="000000";
	this.date_color="999999";

    this.draw = function () {
		var browser = navigator.appName;
		if(browser == "Microsoft Internet Explorer"){
			this.scroll_width=19;
		}
		if(this.title_color==""){
			this.title_color="000000";
		}
		if(this.text_color==""){
			this.text_color="000000";
		}
		if(this.date_color==""){
			this.date_color="000000";
		}
		document.write('<div id="' + this.div_name + '_output"></div>');
		PrepSN_Bridge_Draw(this.div_name,this.feed,this.div_name + ".checker();",this.div_name + ".sendBack([RESULT]);");
    };
	this.checker = function (){
		return true;
	}
	this.sendBack = function ( the_xml ){

		try{ //Internet Explorer
			xmlDoc=new ActiveXObject("Microsoft.XMLDOM");
			xmlDoc.async="false";
			xmlDoc.loadXML( the_xml );
		}catch(e){
			try{ //Firefox, Mozilla, Opera, etc.
		
				parser=new DOMParser();
				xmlDoc=parser.parseFromString( the_xml ,"text/xml");
			}catch(e){
				alert(e.message);
				return;
			}
		}
		var len = xmlDoc.getElementsByTagName("item").length;

		var output="";

		var maxr=0;
		var maxc=0;
		
		if(this.size_type=="Adjust"){
			if(this.scroll_direction=="None"){
				max_width=this.width - this.hpadding;
				
				this.height=parseInt(this.vpadding,10) + parseInt((this.limit_amount * (parseInt(this.title_height,10) + parseInt(this.story_height,10) + parseInt(this.vpadding,10))),10);
				maxc=this.limit_amount;
				maxr=Math.ceil(len/this.limit_amount);

			}else{
				var max_width=this.width - (2 * this.hpadding) - this.scroll_width;
				var max_per_row=1;
				var per_col=len;
				var rem=0;

				maxr=max_per_row;
				maxc=per_col;
			}
		}else{
			if(this.scroll_direction=="None"){
				var max_width=this.width - this.hpadding;
				maxr=1;
				maxc=Math.floor(max_height / ( parseInt(this.title_height,10) + parseInt(this.story_height,10) + parseInt(this.vpadding,10) ));
				
				if(maxr * maxc > len){
					len=maxr + maxc;
				}	
			}else{
				var max_width=this.width - (2 * this.hpadding) - this.scroll_width;
				var max_per_row=1;
				var per_col=len;
				var rem=0;

				maxr=max_per_row;
				maxc=per_col;
			}
		}

		output += '<div style="width:' + this.width + 'px;height:' + this.height + 'px;';
		if(this.border!=""){
			output += 'border:1px solid #' + this.border + ';';
		}
		if(this.scroll_direction=="None"){
			output += 'overflow:hidden;';
		}else{
			output += 'overflow:auto;';
		}
		output += '" align=left><table cellspacing="0" cellpadding="0">';
		
		
		for(i=1;i<=len;i++){

			var fetch=i;
			var cur_col=0;
			var cur_row=0;
			
			cur_col = i % maxr;
			if(cur_col==0){ cur_col = maxr; }
			cur_row = Math.ceil( i / maxr );
			
			var media = xmlDoc.getElementsByTagName("item")[fetch-1];

			var vals = new Array();
			if(typeof(media.getElementsByTagName("title")[0].textContent)!="undefined"){
				vals["title"]=media.getElementsByTagName("title")[0].textContent;
				vals["description"]=media.getElementsByTagName("description")[0].textContent;
				vals["link"]=media.getElementsByTagName("link")[0].textContent;
				vals["pubDate"]=media.getElementsByTagName("pubDate")[0].textContent;
			}else{
				vals["title"]=media.getElementsByTagName("title")[0].firstChild.nodeValue;
				vals["description"]=media.getElementsByTagName("description")[0].firstChild.nodeValue;
				vals["link"]=media.getElementsByTagName("link")[0].firstChild.nodeValue;
				vals["pubDate"]=media.getElementsByTagName("pubDate")[0].firstChild.nodeValue;
			}
			temp=vals["pubDate"].split(" ");
			month="";
			day="";
			try{
				month=temp[2];
				day=parseInt(temp[1],10);
			}catch(e){

			}

			rpadding=0;
			bpadding=0;

			if(cur_col==maxr){
				rpadding=this.hpadding;
			}
			if(cur_row==maxc){
				bpadding=this.vpadding;
			}
			if(i%2==0){
				if(this.background_light!=""){
					bg= 'background:#' + this.background_light + ';';
				}else{
					bg="";
				}

			}else{
				if(this.background_dark!=""){
					bg= 'background:#' + this.background_dark + ';';
				}else{
					bg="";
				}
			}
			if(this.border_inner!="" && i!=len){
				bo='border-bottom:1px solid #' + this.border_inner + ';';
			}else{
				bo="";
			}

			var a1='<a href="' + vals['link'] + '" style="background:none;text-decoration:none;font-family:arial;font-weight:bold;font-size:11px;color:#' + this.title_color + ';">';
			var a2='<a href="' + vals['link'] + '" style="background:none;text-decoration:none;font-family:arial;font-weight:none;font-size:11px;color:#' + this.text_color + ';">';

			var add = '<td style="' + bo + '' + bg + 'padding:' + this.vpadding + 'px ' + rpadding + 'px ' + bpadding + 'px ' + this.hpadding + 'px"><div style="overflow:hidden;width:' + max_width + 'px;height:' + this.title_height + 'px;"><span style="font-size:11px;font-family:arial;font-weight:bold;color:#' + this.date_color + '">' + month + ' ' + day + '</span> ' + a1 + vals['title'] + '</a></div><div style="padding-left:15px;overflow:hidden;width:' + ( max_width - 15 ) + 'px;height:' + this.story_height + 'px;">' + a2 + vals['description'] + '</a></div></td>';
			
			if((i-1)%maxr==0){
				output += '<tr>';
			}
			output += add;
			if(i%maxr==0){
				output += '</tr>';
			}
		}

		output += '</table></div>';
		

		document.getElementById(this.div_name + "_output").innerHTML=output;
	
	}
}
