function insRow( tableID )
{
  
  var x=document.getElementById(tableID).insertRow(0);
  var y=x.insertCell(0);
  
}

function buildLitDisplay( tableID, uri )
{
  
  var xmlObj = null;
  if(window.XMLHttpRequest){
    xmlObj = new XMLHttpRequest();
  } else if(window.ActiveXObject){
	
    xmlObj = new ActiveXObject("Microsoft.XMLHTTP");
	
  } else {
    return;
  }
   
  xmlObj.open ('POST', uri, true);
  xmlObj.send ('');
  
  xmlObj.onreadystatechange = function(){
    if(xmlObj.readyState == 4){
	
      updateListTable(tableID, xmlObj.responseXML);	 
    }
  }

  
}

function replaceAll(OldString,FindString,ReplaceString) {
   var SearchIndex = 0;
   var NewString = ""; 
   while (OldString.indexOf(FindString,SearchIndex) != -1) {
   NewString += OldString.substring(SearchIndex,OldString.indexOf(FindString,SearchIndex));
   NewString += ReplaceString;
   SearchIndex = (OldString.indexOf(FindString,SearchIndex) + FindString.length); 
   }
   NewString += OldString.substring(SearchIndex,OldString.length);
   return NewString;
}



function updateListTable( tableID, doc ) 
{

  var tbl=document.getElementById(tableID);
  var items=doc.getElementsByTagName("item");
  var myText = "";
  var delim = "";
      
  var r0=tbl.insertRow(0);

  var design = true;    
  var print = false;
  var a=0;
  var b=0;
  for( var i=0;i<items.length ; i++) {
   
    print=false;
    if( i == 20 || i==40 || i==60 ) { print=true; }
	
	 if(a==0)
	  {
	//alert("inside a");
	//alert(a);
	//alert(i);
	var item = items[i];
	 var r = tbl.insertRow(b);
	  b++;
	}
	  else if(a==1)
	  {
	
    //alert("inside else");
	//alert(a);
	//alert(i);
	var item = items[(i-1)+a];
	var r = tbl.insertRow(b);
	b++;
	 }

	//var r = tbl.insertRow(i+1);
    //var item = items[i];
	var cols;
	var path;
	var title;
    var iHtml = "";
	
	try {
      cols = item.getElementsByTagName("columns")[0].firstChild.data;
	  
	 

    } catch(e) {
		 cols = "";
	  }
    	//if( print )  alert( "columns " + cols );
    var c0=r.insertCell(0);
	
	if(design == true){
	try{
		
		title = item.getElementsByTagName("TITLE")[0].firstChild.data;
		
		 var titletemp=replaceAll(title ,"?","&trade; ");
		path = item.getElementsByTagName("LIT_FILENAME")[0].firstChild.data;
		
		
	}catch(e){
		
		design = false;
	}
	
		if(design==true){
			var path1=path.substring(0,4);
			
			
			 if(path1=='http')
			 {
			 iHtml = "<a href="+path+">"+titletemp+"</a><br><br>";
			  
			 }
			else
			{
						
			iHtml = "<a href=http://plastics.dupont.com"+path+">"+titletemp+"</a><br><br>";
			
			}
			c0.innerHTML = iHtml;
			
		}
           
	}
	
    if( cols == 1 ) {
      var linkRef;
      try {
		  
        linkRef = item.getElementsByTagName("linkRef1")[0].firstChild.data;
		
		
      } catch(e) {
        linkRef = null;
		
      }
	  var csp=document.createAttribute("colspan");
      csp.nodeValue = "2"
      c0.setAttributeNode(csp);
	      
	  if(linkRef != null ){
		  
	  	iHtml =iHtml+"<TR><TD width=100%><BR><BR><a name=#"+linkRef+"><font color=#000000><B>"+item.getElementsByTagName("linkText1")[0].firstChild.data+"</B></font></a><HR width=100%></TD></TR>";
		
		c0.innerHTML = iHtml;		
	  }
		
      if( linkRef == null ) {
        // list header 
        var done = false;
        var counter = 0;
        var sep = "";
        while( ! done ) {
          counter++;
          try {
            var link = item.getElementsByTagName("link"+counter)[0].firstChild.data;
			 var text = item.getElementsByTagName("linkText"+counter)[0].firstChild.data;
			iHtml += sep;
			iHtml += "<a href=#"+link+">"+text+"</a>";
            sep = " | ";
          } catch(e) {
            done = true;
          }
        }
		
        c0.innerHTML=iHtml;
      } else {
        // segment header
        try {
          var link = item.getElementsByTagName("link1")[0].firstChild.data;
		  var text = item.getElementsByTagName("linkText1")[0].firstChild.data;
		   //if( print ) alert( "link/text " + link + "/" + text ); 
		   if(link!=null && text!=null)
			{
          iHtml += "<a href='#"+link+"'>"+text+"</a>";
		 
          c0.innerHTML=iHtml;
			}
        } catch(e) {
          done = true;
        }
      }
    } else if( cols == 2 ) {
		
		 try {
        var text= item.getElementsByTagName("text1")[0].firstChild.data;
		var path= item.getElementsByTagName("link1")[0].firstChild.data;
	     var link;
        var iHtml;
		
        try {	

	
	     var path1=path.substring(0,4);
			
			
			 if(path1=='http')
			 {
				 link=item.getElementsByTagName("link1")[0].firstChild.data;
			 }
			else
			{
				link="http://plastics.dupont.com"+item.getElementsByTagName("link1")[0].firstChild.data;
			}

        } catch(e) { 
          link=null;
        }
        var target;
        try {
          target=item.getElementsByTagName("target1")[0].firstChild.data;
        } catch(e) { 
          target=null;
        }
        if( link != null ) {
          iHtml += "<a href='"+link;
          if( target != null ) {
            iHtml += "' target='"+target+"'>";
          } else {
            iHtml += "'>";
          }
        }
       var temp1=replaceAll(text,"?","&reg;");
        iHtml+=temp1;
        if( link!=null) {
          iHtml+="</a>";
        }   
        c0.innerHTML=iHtml;
      } catch(e) { }
      
      var c1=r.insertCell(1);
      var text;
	   var iHtml;
       try {
        text = item.getElementsByTagName("text2")[0].firstChild.data;
	text=replaceAll(text,"?C","&deg;C");	
		if(text=='File not found')
		  {
			
		  }
		  else
		   {
			var test1=text;
			var test2;
			var test2=replaceAll(test1,"*",">");
		       var test3= replaceAll(test2,"#","<");
			

		   }

		} catch(e) {
		  
        text = "";
      }
      c1.innerHTML=""+test3+"<BR><BR>";
	  
            
    }
	else if(cols == 3)
	  {
		//added by Radha for news,engineering magazine,case studies
		 var c0=r.insertCell(0);
	  try {
        var text = item.getElementsByTagName("text1")[0].firstChild.data;
		//alert(text);
        var link;
        var iHtml;
		
        try {
          //link="http://plastics.dupont.com/V3plas"+item.getElementsByTagName("link1")[0].firstChild.data;
		  link="http://plastics.dupont.com"+item.getElementsByTagName("link1")[0].firstChild.data;
        } catch(e) { 
          link=null;
        }
        var target;
        try {
          target=item.getElementsByTagName("target1")[0].firstChild.data;
        } catch(e) { 
          target=null;
        }
        if( link != null ) {
          iHtml += "<a href='"+link;
          if( target != null ) {
            iHtml += "' target='"+target+"'>";
          } else {
            iHtml += "'>";
          }
        }
		
		var temp1=replaceAll(text,"?","&reg;");
	      iHtml+="<br><br>"+temp1;
       // iHtml+=temp1;
		
	
        if( link!=null) {
          iHtml+="</a></br>";
        }
		    
        c0.innerHTML=iHtml;
      } catch(e) { }
      
	  
        var t = tbl.insertRow(b);
		b++;
		 
	   var a=1;
	   var c1=t.insertCell(0);
       var text;
	   var iHtml;
	  
       try {
        
		text=item.getElementsByTagName("text2")[0].firstChild.data;
		//alert(text);
		if(text=='File not found')
		  {
			
		  }
		  else
		  {
			 
			var test1=text;
			var test2=replaceAll(test1,"*",">");

			test2= replaceAll(test2,"#","<");
			var temp2=replaceAll(test2,"&<","&#");
			
		    var temp3=replaceAll(temp2,"?","-");
			
		     temp3=replaceAll(temp3,": -",":\"");
			 temp3=replaceAll(temp3,"- -","\"-");
			 temp3=replaceAll(temp3,"- -","\"-");
			 temp3=replaceAll(temp3,"L-","L&#246;");
			 temp3=replaceAll(temp3,"E-","E&#153");
			 temp3=replaceAll(temp3,"N-","N&#153");
		     temp3=replaceAll(temp3,"-s","'s");
			 temp3=replaceAll(temp3,"'sh","-sh");
			 temp3=replaceAll(temp3,"-&#176;","&#176;");
			  temp3=replaceAll(temp3,"metal'sensing","metal-sensing");
			 temp3=replaceAll(temp3,"high'speed","high-speed");
             c1.innerHTML=temp3;
		  }

      } catch(e) {
		  
        text = "";
      }
//      c1.innerHTML="<div align=left><p>"+temp3+"</p></div>";
	   //c1.innerHTML="<Table align=left><TR><TD align=left>"+temp3+"</TD></TR></TABLE>";
	  //c1.innerHTML="<SPAN STYLE='text-align:left'>"+temp3+"</SPAN>";
	 
	  }
  
	  else if( cols == 4 ) {
      try {
		  //added by Radha for design ideeas
        var text = item.getElementsByTagName("text1")[0].firstChild.data;
        try{

		if(text=='File not found')
		  {
			
		  }
		  else
		   {
			var test1=text;
			
			var test2=replaceAll(test1,"*",">");
			
           test2= replaceAll(test2,"#","<");
		   }

		} catch(e) {
		  
        text = "";
      }
      

		
        var link;
        var iHtml;
        try {
          //link="http://plastics.dupont.com/V3plas"+item.getElementsByTagName("link1")[0].firstChild.data;
		 link="http://plastics.dupont.com/"+item.getElementsByTagName("link1")[0].firstChild.data;
		//link="C:/tomcat-5.0.28/webapps/V3plastics/mainhtml/appeal_BattBackpack.htm";
        } catch(e) { 
          link=null;
        }
        var target;
        try {
          target=item.getElementsByTagName("target1")[0].firstChild.data;
        } catch(e) { 
          target=null;
        }
        if( link != null ) {
          iHtml += "<a href='"+link;
          if( target != null ) {
            iHtml += "' target='"+target+"'>";
          } else {
            iHtml += "'>";
          }
        }
        iHtml+=""+test2+"<BR><BR>";
        if( link!=null) {
          iHtml+="</a>";
        }
		    //if( print ) alert( "innerHtml " + iHtml );
        c0.innerHTML=iHtml;
      } catch(e) { }
      
      var c1=r.insertCell(1);
      var text;
	   var iHtml="";
       try {
        text = item.getElementsByTagName("text2")[0].firstChild.data;
         if( link != null ) {
          iHtml += "<a href='"+link;
         if( target != null ) {
            iHtml += "' target='"+target+"'>";
          } else {
            iHtml += "'>";
          }
        }
      //  iHtml+=""+text+"<BR><BR>";
		iHtml+=text;
        if( link!=null) {
          iHtml+="</a>";
        }
		} catch(e) {
		  
        text = "";
      }
	  
      c1.innerHTML=iHtml;
	  
     }
	 //added by Radha

	 else if(cols == 5)
	  {
		 //added by Radha for Archived Edition
		 var c0=r.insertCell(0);
	  try {
        var text = item.getElementsByTagName("text1")[0].firstChild.data;
		//alert(text);
        var link;
        var iHtml;
		
        try {
			var linktest=item.getElementsByTagName("link1")[0].firstChild.data;
			linktest=replaceAll(linktest,".html",".pdf");
          //link="http://52.113.192.85/V3plas"+item.getElementsByTagName("link1")[0].firstChild.data;
		  link="http://plastics.dupont.com"+linktest;
        } catch(e) { 
          link=null;
        }
        var target;
        try {
          target=item.getElementsByTagName("target1")[0].firstChild.data;
        } catch(e) { 
          target=null;
        }
        if( link != null ) {
          iHtml += "<a href='"+link;
          if( target != null ) {
            iHtml += "' target='"+target+"'>";
          } else {
            iHtml += "'>";
          }
        }
		
		var temp1=replaceAll(text,"?","&reg;");
	      iHtml+="<br><br>"+temp1;
       // iHtml+=temp1;
		
	
        if( link!=null) {
          iHtml+="</a></br>";
        }
		    
        c0.innerHTML=iHtml;
      } catch(e) { }
      
	  
        var t = tbl.insertRow(b);
		b++;
		 
	   var a=1;
	   var c1=t.insertCell(0);
       var text;
	   var iHtml;
	  
       try {
        
		text=item.getElementsByTagName("text2")[0].firstChild.data;
		//alert(text);
		if(text=='File not found')
		  {
			
		  }
		  else
		  {
			 
			var test1=text;
			var test2=replaceAll(test1,"*",">");

			test2= replaceAll(test2,"#","<");
			var temp2=replaceAll(test2,"&<","&#");
			
		    var temp3=replaceAll(temp2,"?","-");
			
		     temp3=replaceAll(temp3,": -",":\"");
			  temp3=replaceAll(temp3,"- -","\"-");
			  
             c1.innerHTML=temp3;
		  }

      } catch(e) {
		  
        text = "";
      }
//      c1.innerHTML="<div align=left><p>"+temp3+"</p></div>";
	   //c1.innerHTML="<Table align=left><TR><TD align=left>"+temp3+"</TD></TR></TABLE>";
	  //c1.innerHTML="<SPAN STYLE='text-align:left'>"+temp3+"</SPAN>";
	 
	  }
	}
}
