function min(num1, num2) {
	if (num1 < num2) {
		return num1;
	}
	else {
		return num2;
	}
}	

function InsertDGWebfeeds() {

	if (( News == null ) || ( Case == null ) || ( Webcast == null )) {
		document.write('<font face="Verdana, Arial,Helvetica, sans-serif" size="-1" color="white">ERROR : The JS file is unreachable !!</font>');
		return false;
	}
	
	document.write("<table bgColor='" + background_color + "' width='" + headline_width + "' border='1' cellpading='0' cellspacing='0'>\r");
	document.write("<tr>");
	document.write("<td>");

	document.write("<table height='80' bgcolor='white' width='100%' align='center' border='0' cellpading='0' cellspacing='0'>");
	document.write("<tr>");
	document.write("<td width='3'>");
	document.write("&nbsp;");
	document.write("</td>");
	document.write("<td width='110' align='right'>");
	document.write("<a href='http://www.docguide.com/webfeeds.nsf/doc?createdocument&dg=yes&wid=" + xlway + "&u=");
	document.write("GOTO//www.docguide.com/dgc.nsf/html/index.htm?Opendocument&wf=yes'>");
	document.write("<img src='http://www.docguide.com/DGCustom/DGGEsmalllogo.gif' border='0'></a>");
	document.write("</td>");
	document.write("<td width='5'>");
	document.write("&nbsp;");
	document.write("</td>");
	document.write("<td>");

	document.write("<font face='Verdana, Arial,Helvetica, sans-serif' size='2' color='black'><b>");
	document.write(unescape(unescape(condition_name)));
	document.write("</b></font>");

    document.write("</td>");
	document.write("<td width='3'>");
	document.write("&nbsp;");
	document.write("</td>");
	document.write("</tr>");
	document.write("</table>");

	document.write("<table width='90%' align='center' bgcolor='" + background_color + "' border='0' cellpading='0' cellspacing='0'>");

	if ( layout == "News" )	{
		InsertNews('LATEST NEWS', number_headlines, News);
	}
	else {
		switch ( number_headlines ) {
			case "3" :
				InsertNews('LATEST NEWS', 1, News);
				InsertNews('LATEST CASES', 1, Case);
				InsertNews('LATEST WEBCASTS', 1, Webcast);
				break;
			case "5" :
				InsertNews('LATEST NEWS', 3, News);
				InsertNews('LATEST CASES', 1, Case);
				InsertNews('LATEST WEBCASTS', 1, Webcast);
				break;
			case "10" :
				InsertNews('LATEST NEWS', 6, News);
				InsertNews('LATEST CASES', 2, Case);
				InsertNews('LATEST WEBCASTS', 2, Webcast);
				break;
			case "15" :
				InsertNews('LATEST NEWS', 9, News);
				InsertNews('LATEST CASES', 3, Case);
				InsertNews('LATEST WEBCASTS', 3, Webcast);
				break;
			case "20":	
				InsertNews('LATEST NEWS', 12, News);
				InsertNews('LATEST CASES', 4, Case);
				InsertNews('LATEST WEBCASTS', 4, Webcast);
				break;
			default :
				InsertNews('LATEST NEWS', number_headlines, News);
		}
	}

	document.write("<br>");
	document.write("</td></tr>");
	document.write("<tr><td width='10'>");
	document.write("&nbsp;");
	document.write("</td>");
	document.write("<td align=left'>");
	document.write("<font size='-2' face='Verdana, Arial,Helvetica, sans-serif' color='" + headline_font_color + "'>");
	document.write("Powered by Doctor's Guide");
	document.write("<br>");
	document.write("<a href='http://www.docguide.com/webfeeds.nsf/doc?createdocument&dg=yes&wid=" + xlway + "&u=");
	document.write("GOTO//www.docguide.com/dgc.nsf/html/index.htm?Opendocument&wf=yes'><font color='" + headline_font_color + "'>www.docguide.com</a>");
	document.write("</font>");
	document.write("</td></tr>");
	document.write("</table>");
	document.write("<br>");
	document.write("</td></tr>");
	document.write("</table>");

	if ( xlway != '' ) {
		document.write("<img src='http://www.docguide.com/webfeeds/webfeed.gif?dn=" + xlway + "'>");
	}
}


function InsertNews(StrTitle, Number, TheNewsArray)	{

	document.write("<tr>");
	document.write("<td colspan='2'>");
	document.write("<font CLASS='other'><b><u>");
	document.write(StrTitle + "</u></b></font>");
	document.write("<br>");
	document.write("<br>");
	document.write("</td>");
	document.write("</tr>");

	var x=0;

	for (x=0 ; x < min(TheNewsArray.length, Number) ; x++) {
		document.write("<tr>");
		document.write("<td width='10'>");
		document.write("&nbsp;");
		document.write("</td>");
		document.write("<td>");
		document.write("<a target='_blank' CLASS='headline' href='http://www.docguide.com/webfeeds.nsf/");
		document.write("doc?createdocument&wid=" + xlway + "&u=" + TheNewsArray[x].url + "'>");
		document.write("<font CLASS='headline'>");
		document.write(unescape(TheNewsArray[x].title) + "</font></a>");

		document.write("<font CLASS='other'>");

		if ( TheNewsArray[x].date != "" ) {
			document.write("<br>");
			document.write(TheNewsArray[x].date);
		}

		if ( StrTitle == "LATEST NEWS" ) {
			document.write("<br>");
			document.write("(<b>" + TheNewsArray[x].type);
			if (TheNewsArray[x].journal != "") {
				if (TheNewsArray[x].type == "")	{
					document.write("</b>" + TheNewsArray[x].journal + ")")
				}
				else {
					document.write("</b> - " + TheNewsArray[x].journal + ")");
				}
			}
			else {
				document.write("</b>)");		 
			}
		}

		document.write("</font>");
		document.write("<br>");
		document.write("<br>");
		document.write("</td>");
		document.write("</tr>");
	}
}

function getCookie(name) {
	alert("Function get cookie");
	var cname = name + "=";
	var dc = document.cookie;
	if(dc.length > 0) {
		begin = dc.indexOf(cname);
		if(begin != -1)	{
			begin += cname.length;
			end = dc.indexOf(";", begin);
			if(end==-1) {
				end = dc.length;
			}
			return unescape(dc.substring(begin, end));
		}
	}
	return null;
}