﻿// JScript File
var host = window.location.host;
if(window.location.href.indexOf('https') >= 0)
    host = 'https://' + host;
else 
    host = 'http://' + host;
if(window.location.href.toLowerCase().indexOf('/ep/') > 0)
    host += '/ep';
    
var index = 0;    
var indexFF = 0; 

var doc = null;
var tbl = null;	
var timerID = null;
var rawXML = null;

function loadPreview(xmlDoc)
{   
    if (navigator.appName == 'Netscape')
    {
         var parser=new DOMParser();
         doc=parser.parseFromString(xmlDoc,"text/xml");       
         loadProfileNetscape(indexFF);	        
    }
    else
    {
        doc = new ActiveXObject("Microsoft.XMLDOM");
        doc.async="false"; 
        rawXML = xmlDoc;      
	    doc.loadXML(xmlDoc);
	    loadProfile(index);	
    }		
}

function loadProfile(num)
{
try
{
    clearTimeout(timerID);
    //document.write(rawXML);
    
    if(num >= doc.documentElement.childNodes.length)
    {
        index = 0;
        num = index;
    }
    
    tbl = document.getElementById('navTable');
    if(tbl != null)
    {
	    while (tbl.rows.length > 0)
		    tbl.deleteRow(0);
		
        mouid = doc.documentElement.childNodes.item(num).childNodes.item(0).text
        name = doc.documentElement.childNodes.item(num).childNodes.item(1).text;
	    profileIcon = doc.documentElement.childNodes.item(num).childNodes.item(2).text;		
	    description = doc.documentElement.childNodes.item(num).childNodes.item(3).text;

    	var desArr = description.split(" ");    	
    	
    	
    	for(i=0; i<desArr.length; ++i)
    	{
    	    if(desArr[i].length > 20)    	        
    	        description = description.replace(desArr[i], desArr[i].split("", 20)).replace(/,/g,"");    	    
    	}
    	
	    var newRow = tbl.insertRow(0);//creation of new row 												
        var newCell1 = newRow.insertCell(0);
        var newCell2 = newRow.insertCell(1);
        
        newCell1.style.width = "1%";
        newCell1.style.padding = "0 7px 0 0";
        
        newCell1.innerHTML = "<div style=\"padding: 10px 0 5px 5px;\"><a href=\""+ host + "/blog/myMossyOak.aspx?itemType=Page&viewType=Profile&defaultId=3&itemId=" + mouid + "&mouid=" + mouid +"\"><img style=\"width:90px; height:67px; border: solid 1px white;\" src=\""+ profileIcon +"\"></a></div>";
        newCell2.innerHTML = "<a class=\"mem_spotlight_txt\" href=\""+ host + "/blog/myMossyOak.aspx?itemType=Page&viewType=Profile&defaultId=3&itemId=" + mouid + "&mouid=" + mouid +"\">"+ name +"</a>";
        newCell2.innerHTML += "<br>" + description;
        
        index += 1;
        timerID = setTimeout("loadProfile(" + index + ")", 15000);
    }
}
catch(err)
    {
      txt="There was an error on this page.\n\n"
      txt+="Error description: " + err.description + "\n\n"
      txt+="Click OK to continue.\n\n"
      //alert(doc.parseError.reason + " \n Line: " + doc.parseError.line + "\n Src: " + doc.parseError.srcText)
    }
}


function loadProfileNetscape(num)
{
try
{
    clearTimeout(timerID);
    
    if(num >= doc.documentElement.childNodes.length)
    {
        indexFF = 0;
        num = indexFF;
    }
    
    tbl = document.getElementById('navTable');
    
    if(tbl != null)
    {
	    while (tbl.rows.length > 0)
		    tbl.deleteRow(0);
		
		if(doc.getElementsByTagName("mouid")[num].childNodes[0])
            mouid = doc.getElementsByTagName("mouid")[num].childNodes[0].nodeValue;        
        
        if(doc.getElementsByTagName("name")[num].childNodes[0])
            name = doc.getElementsByTagName("name")[num].childNodes[0].nodeValue; 
        
        if(doc.getElementsByTagName("profileIcon")[num].childNodes[0])       
	        profileIcon = doc.getElementsByTagName("profileIcon")[num].childNodes[0].nodeValue;	
	        
	    if(doc.getElementsByTagName("description")[num].childNodes[0])	
	        description = doc.getElementsByTagName("description")[num].childNodes[0].nodeValue;
	    else
    	    description = "";
    	
    	var desArr = description.split(" ");    	
    	for(i=0; i<desArr.length; ++i)
    	{
    	    if(desArr[i].length > 20)    	        
    	        description = description.replace(desArr[i], desArr[i].split("", 20)).replace(/,/g,"");    	    
    	}
    	  
	    var newRow = tbl.insertRow(0);//creation of new row 												
        var newCell1 = newRow.insertCell(0);
        var newCell2 = newRow.insertCell(1);
        
        newCell1.style.width = "1%";
        newCell1.style.padding = "0 7px 0 0";
        
        newCell1.innerHTML = "<div style=\"padding: 10px 0 5px 5px;\"><a class=\"mem_spotlight_txt\" href=\""+ host + "/blog/myMossyOak.aspx?itemType=Page&viewType=Profile&defaultId=3&itemId=" + mouid + "&mouid=" + mouid +"\"><img style=\"width:90px; height:67px; border: solid 1px white;\" src=\""+ profileIcon +"\"></a></div>";
        newCell2.innerHTML = "<a class=\"mem_spotlight_txt\" href=\""+ host + "/blog/myMossyOak.aspx?itemType=Page&viewType=Profile&defaultId=3&itemId=" + mouid + "&mouid=" + mouid +"\">"+ name +"</a>";
        newCell2.innerHTML += "<br>" + description;
        
        indexFF += 1;
        timerID = setTimeout("loadProfileNetscape(" + indexFF + ")", 15000);
    }
}
catch(err)
    {
      txt="There was an error on this page.\n\n"
      txt+="Error description: " + err.description + "\n\n"
      txt+="Click OK to continue.\n\n"
      //alert(txt)
    }
}
