// JScript File

var xmlDoc;
var RootURL ="http://192.197.232.103/";

function VerfiySubscriber() {

    var SubscriberID = getQueryVariable("id");
    var URL = "/VerifySubscriber.jsp?id=" + SubscriberID;
    
    xmlhttp=null
    // code for Mozilla, etc.
    if (window.XMLHttpRequest)
    {
        xmlhttp=new XMLHttpRequest()
    }
    // code for IE
    else if (window.ActiveXObject)
    {
        xmlhttp=new ActiveXObject("Microsoft.XMLHTTP")
    }
    if (xmlhttp!=null)
    {
        xmlhttp.onreadystatechange=state_Change
        xmlhttp.open("GET",URL,true)
        xmlhttp.send(null)
    }
    else
    {
        alert("Your browser does not support XMLHTTP.")
    }
}

function state_Change()
{
    // if xmlhttp shows "loaded"
    if (xmlhttp.readyState==4)
    {
    // if "OK"
        if (xmlhttp.status==200)
        {
            document.getElementById("VerifyDiv").outerHTML =xmlhttp.responseText
        }
        else
        {
            alert("Problem retrieving data:" + xmlhttp.statusText)
        }
    }
}
	
function ShowAllTips()
{
    var CategoryID = getQueryVariable("CatID");
    var Title=getQueryVariable("Title");
    xmlFile = "/TipsByCategory.jsp?CatID=" + CategoryID;
    LoadXML(xmlFile, "ShowAllTips", Title)
    
}

function ShowTipOfWeek()
{
    var xmlFile;

    if(getQueryVariable("TipID"))
    {
        xmlFile = "/HotTipOfTheWeek.jsp?TipID=" + getQueryVariable("TipID");
    }
    else
    {
        xmlFile = "/HotTipOfTheWeek.jsp";
    }
    
    LoadXML(xmlFile, "ShowTip")
}

function LoadXML(xmlFile, fnToCall, Title)
{

    if (document.implementation && document.implementation.createDocument)
    {
    		
	    xmlDoc = document.implementation.createDocument("", "", null);
    	if(fnToCall=="ShowTip"){
	        xmlDoc.addEventListener("load", createTipView(xmlDoc), false);
    	}else{
	        xmlDoc.addEventListener("load", createViewAll(xmlDoc,Title), false);
    	}
    }
    else if (window.ActiveXObject)
    {
        xmlDoc = new ActiveXObject("Microsoft.XMLDOM");
	    xmlDoc.onreadystatechange = function () {
		    if (xmlDoc.readyState == 4)
	        {
	            if(fnToCall=="ShowTip"){
		            createTipView(xmlDoc);
		        }else{
		            createViewAll(xmlDoc,Title);
		        }
            }
		};
	    
    }
    else
    {
	    alert('Your browser can\'t handle this script');
    }
    try
    {
    	xmlDoc.load(xmlFile);
    }
    catch(err)
    {}
}



function createViewAll(xmlDoc,Title)
{

	var OutputString = "";
	
	var tipTitle = "";
	var tipDescription = "";
	var tipDate = "";
    var tipID = "";
    	
	var x = xmlDoc.getElementsByTagName('tip');
	
	OutputString = OutputString + "<div id=\"header\"><span class=\"AHUheader\">"+URLDecode(Title)+"</span></div>";

	for (i=0;i<x.length;i++)
	{
		for (j=0;j<x[i].childNodes.length;j++)
		{
			if (x[i].childNodes[j].nodeType != 1) continue;
			
			switch (j){
			    case 0:
			        tipDate = x[i].childNodes[j].firstChild.nodeValue;
			        break;
			    case 1:
			        tipTitle = x[i].childNodes[j].firstChild.nodeValue;
			        break;
			    case 2:
			        tipDescription = x[i].childNodes[j].firstChild.nodeValue;
			        break;
			    case 3:
			        tipID = x[i].childNodes[j].firstChild.nodeValue;
			        break;
			}
		}
	    OutputString = OutputString + "> <b><a href= \"/HotTipOfWeek.htm?TipID=" + tipID + "\">" + URLDecode(tipTitle) + "</a></b>";
	    OutputString = OutputString + " <em>" + URLDecode(tipDate) + "</em><br>";
	}
	
	var tipElement = document.getElementById('tipOfTheWeek');
	
	if (tipElement)
	{
		tipElement.outerHTML = OutputString;
	}

}

function createTipView(xmlDoc)
{
	
	var OutputString = "";
	
	var tipTitle = "";
	var tipDescription = "";
	var tipDate = "";
	var tipSource1 = "";
	var tipLink1 = "";
	var tipSource2 = "";
	var tipLink2 = "";
	var tipCategory = "";
	
	var x = xmlDoc.getElementsByTagName('tip');
	
	for (i=0;i<x.length;i++)
	{
		for (j=0;j<x[i].childNodes.length;j++)
		{
			if (x[i].childNodes[j].nodeType != 1) continue;
			
			switch (j){
			    case 0:
			        tipDate = x[i].childNodes[j].firstChild.nodeValue;
			        break;
			    case 1:
			        tipTitle = x[i].childNodes[j].firstChild.nodeValue;
			        break;
			    case 2:
			        tipDescription = x[i].childNodes[j].firstChild.nodeValue;
			        break;
			    case 3:
			        tipSource1 = x[i].childNodes[j].firstChild.nodeValue;
			        break;
			    case 4:
			        tipLink1 = x[i].childNodes[j].firstChild.nodeValue;
			        break;
			    case 5:
			        tipSource2 = x[i].childNodes[j].firstChild.nodeValue;
			        break;
			    case 6:
			        tipLink2 = x[i].childNodes[j].firstChild.nodeValue;
			        break;
			}
		}
	}
	
	
	OutputString = OutputString + "<div id=\"header\"><span class=\"AHUheader\">Hot Tip of the Week</span></div>";
	OutputString = OutputString + "<span class=\"AHU_sub_header\"><em>" + URLDecode(tipDate) + "</em></span><br><br>";
	OutputString = OutputString + "<b>" + URLDecode(tipTitle) + "</b><br>";
	OutputString = OutputString + URLDecode(URLDecode(tipDescription)) + "<br /><br />";
	
	//Confirm that there are valid values in the source and link
	if (Test_For_Source(tipSource1) && Test_For_Link(tipLink1))
	{
	    
	    OutputString = OutputString + "<b>Get more information: </b>"; 
	    OutputString = OutputString + "<a href=\"" + URLDecode(tipLink1) + "\">" + URLDecode(tipSource1) + "</a>";

	    if (Test_For_Source(tipSource2) && Test_For_Link(tipLink2))
	    {
	        OutputString = OutputString + " and "; 
	        OutputString = OutputString + "<a href=\"" + URLDecode(tipLink2) + "\">" + URLDecode(tipSource2) + "</a>";
	    }
	}
	
	OutputString = OutputString + "<br /><br /><b>Looking for more helpful tips?</b><br />"; 
	OutputString = OutputString + "> <a href=\"/TipsArchive.htm?CatID=2&Title=Active Living Tips\">Active Living Tips</a><br />"; 
	OutputString = OutputString + "> <a href=\"/TipsArchive.htm?CatID=1&Title=Healthy Eating Tips\">Healthy Eating Tips</a>"; 
	
	var tipElement = document.getElementById('tipOfTheWeek');
	
	if (tipElement)
	{
		tipElement.outerHTML = OutputString;
	}

}



