// JavaScript Document
// czyta elementy globalne dla servisu igik.edu.pl
var xmlDoc

function loadXML(xmlfile)
{
//load xml file
// code for IE
//alert("Load " + xmlfile)
if (window.ActiveXObject)
{
xmlDoc = new ActiveXObject("Microsoft.XMLDOM");
xmlDoc.async=false;
xmlDoc.load(xmlfile);
getData()
}
// code for Mozilla, etc.
else if (document.implementation &&
document.implementation.createDocument)
{
// alert('Mozilla i Netscape i Opera')
xmlDoc = document.implementation.createDocument("","",null);
xmlDoc.load(xmlfile);
// alert('plik xml zaladowany')
xmlDoc.onload=getData
}
else
{
alert('Your browser cannot handle this script');
}
}
function findNode0(theNode, theNodeName, theAttrName, theAttrValue)
// szuka podwezla wezla theNode o nazwie theNodeName i atrybucie theAttrName o danej 
// wartosci
{
 var childNode, childName, theAttr
 var attributes, attenAttr
 if( theNode == null) return theNode
  
 theAttr = new String(theAttrValue);
 
 if (theNode.childNodes.length > 0) {     
 for (var loopIndex = 0; loopIndex <
     theNode.childNodes.length; loopIndex++) 
 {
      childNode = theNode.childNodes[loopIndex]
      // alert(childNode.nodeName)
      childName = new String(childNode.nodeName);
	if (childName == theNodeName){  // znaleziony
 	if(theAttrName){
      attributes = childNode.attributes
      attenAttr = attributes.getNamedItem(theAttrName)
      if (theAttr == attenAttr.value) return childNode
      } else 
        return childNode
      }
 }  
 return null  // nie ma takiego dziecka
 }
 else return null   // nie ma dzieci w ogole	
}
function findNode(theNode, theNodeName, theAttrName, theAttrValue)
// szuka podwezla wezla theNode o nazwie theNodeName i atrybucie theAttrName o danej 
// wartosci
{
 var childNode, childName, theAttr
 var attributes, attenAttr
 if( theNode == null) return theNode 

 x=theNode.childNodes
 
 for (i = 0; i < x.length; i++)  {
      childNode = x[i]       
      if ( childNode.nodeName == theNodeName )
	{
 	 if(theAttrName)
       {
        attributes = childNode.attributes
        attenAttr = attributes.getNamedItem(theAttrName)
        if (theAttrValue == attenAttr.value) return childNode
       } 
       else return childNode
      }
 }  
 return null  // nie ma takiego dziecka	
}


function findNodeRekurs(theNode, theNodeName, theAttrName, theAttrValue)
// szuka podwezla wezla theNode o nazwie theNodeName i atrybucie theAttrName o danej 
// wartosci
{
 var myNode, theName, theAttr
 var attributes, attenAttr
 if( theNode == null) return theNode
 theName = new String(theNode.nodeName);
 theAttr = new String(theAttrValue);
 if (theName.localeCompare(theNodeName) == 0){    
 	if(theAttrName){
      attributes = theNode.attributes
      attenAttr = attributes.getNamedItem(theAttrName)
      if (theAttr.localeCompare(attenAttr.value) == 0) return theNode  
	}
	else return theNode
 }
 // alert(theNode.childNodes.length) 
 if (theNode.childNodes.length > 0) {     
 	for (var loopIndex = 0; loopIndex <
	     theNode.childNodes.length; loopIndex++) {

		 myNode = findNode(theNode.childNodes[loopIndex], theNodeName,theAttrName, theAttrValue) 

		 if (myNode != null) return myNode          
		 }		
	}	
  else return null 	
}
// parsowanie dokumentu
function iterateChildren(theNode, indentSpacing)
{
 var typeData
 switch (theNode.nodeType) {
   case 1:
     typeData = "element"
     break;	
   case 2:
     typeData = "atrybut"
     break;	
   case 3:
     typeData = "tekst"
     break;	
   case 4:
     typeData = "sekcja CDATA"
     break;	
   case 5:
     typeData = "odwolanie do encji"
     break;	
   case 6:
     typeData = "encja"
     break;	
   case 7:
     typeData = "instrukcja przetwarzania"
     break;	
   case 8:
     typeData = "komentarz"
     break;	
   case 9:
     typeData = "dokument"
     break;	
   case 10:
     typeData = "typ dokumentu"
     break;	
   case 11:
     typeData = "fragment dokumentu"
     break;	
   case 12:
     typeData = "notacja"
     break;	

 } 
 var code = indentSpacing + theNode.nodeName + "<br>" 
 
 if (theNode.nodeValue != null) {
  code = indentSpacing + theNode.nodeName
         + "&nbsp; = " + theNode.nodeValue
         + "&nbsp; (typ wezla: " + typeData
         + ")<BR>"
  }
  else {
   code = indentSpacing + theNode.nodeName
          + "&nbsp; (Typ wezla: " + typeData
          + ")<BR>"
       } 
 
 if (theNode.childNodes.length > 0) {
 	for (var loopIndex = 0; loopIndex <
	     theNode.childNodes.length; loopIndex++) {
		 code += iterateChildren(theNode.childNodes(loopIndex),
		 indentSpacing + "&nbsp;&nbsp;&nbsp;&nbsp;")
		 }
 }
 return code
 }
function parseDocument(idXML)
{
 documentXML = document.all(idXML).XMLDocument
 return iterateChildren(documentXML,"")
}
// koniec

function writeText(theNode, text)
{
 var  childNode 
 // alert("pisze")
 if( theNode == null) return ""
 childNode = findNode(theNode, "#text", "","")
 
 if(childNode != null) childNode.nodeValue = text
 // alert(childNode.nodeValue )
 }

	 		
 function readText(theNode)
// czyta wezel textowy
{
 var  childNode
 if( theNode == null ) return "" 
 childNode = findNode(theNode, "#text", "","") 
 if(childNode == null) return ""  
 keyword = getCookie("search")
 if ( keyword != null && keyword != "" )
 { 
 if ( keyword.search(childNode.nodeValue) != -1)
 {
 return "<span style='color:#FFFFEA; background-color:#333333'>" + childNode.nodeValue + "</span>"
 }
 else
 {
 //alert(childNode.nodeValue)   
 if (childNode.nodeValue.search(keyword) != -1)
 return childNode.nodeValue.replace(keyword, "<span style='color:#FFFFEA; background-color:#333333'>" + keyword + "</span>")
 else return childNode.nodeValue  
 }
 }
 else return childNode.nodeValue
 }
function readTextinLang(theNode, ilang)
// czyta wezel typu TextType(dwujezyczny)
{
 var  childNode, text 
 var theName = (ilang == 0) ? "pl" : "ang"
 if( theNode == null) return ""
 //if ( ilang != 0) { alert('czyta ang'); alert(theName); } 
 childNode = findNode(theNode, theName, "","") 
 //alert(childNode.nodeName)
 text = readText(childNode)
 
 return text
 }
  // czyta wezel telefon
 function readTelefony(theNode)
 {
  var attributes, filepath, theNode
  var theName = new String("telefon")
  var code = "<table>"
    
    if( theNode == null) return "" 
    do{
       if(theName == theNode.nodeName) 
       {
       code += '<tr><td><span class="tel">'  
       attributes = theNode.attributes
       filepath = attributes.getNamedItem("typ")	 
       if( filepath == null ) 
             	code += "<small>" + "tel." + "</small>" + "+48 "
       else  
       {
       	switch(filepath.value) {
			case "1":  	   
		 	code += "<small>" + "tel."  + "</small>" + "+ 48 "	
			break
		      case "2":  	   
		 	code += "<small>" + "tel./fax."  + "</small>" + "+ 48 "
			break	 
                  case "3":  	   
		 	code += "<small>" + "fax."  + "</small>" + "+ 48 "	
			break	 
                  case "4":  	   
		 	code += "<small>" + "mobil."  + "</small>"
			break
            }
       }
	 code += readText(theNode) 
       code += "</span></td></tr>"
       }
       theNode = theNode.nextSibling        
    }while( theNode != null)  
    code += "</table>"
   
    return code 
 }
function readTyt(tytNode)
{
 var tyt = new String( readText(tytNode));
 if (getLang() == 1) 
 { 
  tyt = tyt.search("Prof")!=-1 ? "Prof." :  tyt; 
  tyt = tyt.search("Dr")!=-1 ? "Dr" : tyt;
  tyt = tyt.search("Mgr")!=-1 ? "M.Sc." : tyt;
 }
 return tyt;
}
function readTelefon(theNode)
{
 return readTelefony(theNode)
}

 // czyta i formatuje wezel Data
 function readData(theNode)
 {
  var childNode
  var code = ""
       if( theNode == null) return ""   
         code += readText(theNode)
		return code 
 }
function readEmail(theNode)
{
var code = ""
if( theNode == null) return code
code += "<small>e-mail:&nbsp; </small>"
code += '<span class="mail"><a href="mailto:' + readText(theNode)
       + '"><span class="pers">'
       + readText(theNode)
       + "</span></a></span>"  
return code
}
// czyta wezeł typu OsobaType
 function readOsobaType(theNode, ilang)
 {
 var  funNode,tytNode, imNode,nazNode,telNode,emailNode
 var code = ""
       
       if( theNode == null) return ""  
             funNode = findNode(theNode, "Funkcja","","")
  		 tytNode = findNode(theNode, "tytul","","")
  		 imNode = findNode(theNode, "Imie","","")
  		 nazNode = findNode(theNode, "Nazwisko","","")
  		 telNode = findNode(theNode, "telefon","","")
  		 emailNode = findNode(theNode, "Email","","")
  		 code += '<span class="pers">' + readTextinLang(funNode, Lang) + "  </span>" 
                  + '<span class="persbf">' + readText(tytNode) + "&nbsp;" 
                  + readText(imNode) + "&nbsp;" + readText(nazNode) 
                  + "</span>"          
                  + readTelefon(telNode)
                  + readEmail(emailNode)+  "<br><br>";
    
     return code
 }

// czyta wezeł typu Obrazek
function readObrazekType(theNode, ilang, max, mini, minwidth )
 {
  var attributes, filepath, file_en, file, label, ind, file_mini, file_max
  var code = ""  
  
  if(theNode == null) return code  
  attributes = theNode.attributes
  if( attributes == null) return code  
  filepath = attributes.getNamedItem("href")  
  if(filepath == null) return code
  file = new String(filepath.value )
  
  if(ilang == 1)
  {
   ind = file.indexOf(".")
   file_en = file.substr(0, ind) + "_ang" + file.substr(ind) 
   file = file_en 
   //alert(file_en) 
   // teraz trzeba sprawdzic czy istnieje na dysku i podmienic
  }
  file_mini = filepath.value
  file_max = file
  
  if(mini == 1)
  {
  ind = file_mini.indexOf(".")
  file_mini = file_mini.substr(0, ind) + "_mini" + file_mini.substr(ind) 
  //alert(file_mini )
  }
  if(max == 1 && ilang == 0)
  {
  ind = file_max.indexOf(".")
  file_max = file_max.substr(0, ind) + ""  + file_max.substr(ind) 
  //alert(file_max )
  }

  if (max)
  {  
    
     code += "<a onclick='" 
          + "window.open("
          + '"' + file_max + '"'
          + ',"_blank","toolbar=no, location=no, scrollbars=yes, resizable=yes, width=500, height=500")' 
          + "'>"
     code += '<img src="' + file_mini + '"' 
     code += ' border=0 alt="Wi&#281;ksze w oknie" style="cursor:hand;"'

  }
  else
  {
     code += '<img src="' + filepath.value  + '"' 
     code += ' border=0 '
  }
  
  if (minwidth == 0) code += "/>"
  else  code += ' width=' + minwidth + '/>' 
  
  if(max) code += "</a>"
  
  label = findNode(theNode, "Podpis", "", "")
  if( label == null) return code 
  if (minwidth == 0) 
  	code += "<br>" +  '<div class="podpis">' 
  else  
  	code += "<br>" +  '<div style="width:' + minwidth + 'px;" class="podpis">'   
  code += readTextinLang(label,ilang)+  "</div>"  
  
  return code    
 }

 // adres w 2 wierszach
 function readAdres2(theNode, ilang)
{
var childNode
var code = ""
if( theNode == null) return code   
code += '<table>'
code += "<tr><td> ul."
    childNode = findNode(theNode, "Ulica","","")
code += readText(childNode)
	childNode = findNode(theNode, "Nr","","")
code += readText(childNode)
code +=	"</td></tr>"
code += "<tr><td>"
    childNode = findNode(theNode, "KodPocztowy", "", "")
	code += readText(childNode)+ "&nbsp;"
	childNode = findNode(theNode, "Miasto","","")
	code += readTextinLang(childNode,ilang) +"<br>" // poprawic
code +=	"</td></tr>"  
code += "</table>"
return code
}
 //  czyta wezel ktory zawiera serie paragrafow 
function readParagraphs(theNode, ilang)
{
 var theNode, paragNode, childNode
 var theName = new String("par")
 var  code = ""  
 if(theNode == null) return code
 childNode = theNode.firstChild
 if(childNode == null) return code
 do{
    if (theName == childNode.nodeName)
    {
	code += "<p>"
	code += readTextinLang(childNode, ilang)
	code += "</p>"
   //   alert(code)
    } 	     
    childNode = childNode.nextSibling    
  }
  while(childNode != null) 
 return code
}
 // element w formie listy
function readLista(theNode, ilang)
{
var  theNode, parNode, childNode
var theName = new String("Pozycja")
var  code = ""
if( theNode == null) return code
childNode = theNode.firstChild
if( childNode == null) return code
code += "<ul>"
do
{
 if (theName == childNode.nodeName) 
 {
  code += '<li>'
  code += readTextinLang(childNode, ilang)
  code += "</li>"
 }
 childNode = childNode.nextSibling
}
while(childNode != null)
code += "</ul>" 
return code
}

 // czyta wezel ktory zawiera serie Sekcji i zwraca Tytul w Sekcji o atrybucie lab
function readSekcjaTytul(theNode, attr, lab, ilang)
{
 var theNode, childNode, tytNode
 var  code = ""  
 childNode = findNode(theNode,"Sekcja",attr,lab)
 if( childNode == null) return code
 tytNode = findNode(childNode,"Tytul","","")
 code += readTextinLang(tytNode, ilang)
 return code
}
// czyta wezel ktory zawiera serie Sekcji i zwraca Opis w Sekcji o attribucie lab
function readSekcjaOpis(theNode, attr, lab, ilang)
{
 var theNode, childNode, opisNode
 var  code = ""  
 childNode = findNode(theNode,"Sekcja",attr,lab)
 if( childNode == null) return code
 opisNode = findNode(childNode,"Opis","","")
 code += readParagraphs(opisNode, ilang)
 return code
}
// czyta wezel ktory zawiera serię Sekcji i zwraca elem Lista w Sekcji o attribucie label
function readSekcjaLista(theNode, attr, lab, ilang)
{
 var theNode, childNode, listNode
 var  code = ""  
 childNode = findNode(theNode,"Sekcja",attr,lab)
 if( childNode == null) return code
 listNode = findNode(childNode,"Lista","","")
 code += readLista(listNode, ilang)
 return code
}
// czyta wezel ktory zawiera serie Sekcji i zwraca elementy Obrazek w Sekcji o attribucie label
// czy maxymalizowac w nowym oknie; mini czy do nazwy dodane jest mini
function readSekcjaObrazki(theNode, attr, lab, ilang, rows, cols, max, mini, minwidth)
{
 var theNode, childNode, sekNode, i, j
 var theName = new String("Obrazek")
 var  code = ""  
 // alert("SekcjaObrazki");
 // alert("max=" + max + " mini=" + mini + " minwidth=" + minwidth)

 sekNode = findNode(theNode,"Sekcja",attr,lab)
 if( sekNode == null) return code
 childNode = sekNode.firstChild
 //alert(childNode.nodeName)
 if( childNode == null) return code
 

 code += "<table>"   
 i = 0
 j = 0 
 do {
  if (theName == childNode.nodeName) 
  {
    //alert('jest ' + childNode.nodeName )
    do
    {
      i = i + 1;
      //alert('nowy wiersz' + ' i=' + i + ' j=' + j)
      code += "<tr>";     
      do 
      {             
        if(childNode != null)
        { 
          if (theName == childNode.nodeName) 
          { 
           code += '<td class="obrazki"><div class="box1">' 
           j = j + 1;
           //alert('nowa kolumna' + ' i=' + i + ' j=' + j) 
    	     code += readObrazekType(childNode, ilang, max, mini, minwidth);
           //alert('wstawiony ' + childNode.nodeName + '(' + i + ',' + j + ')');
           code += "</div></td>"   
           }       
           childNode = childNode.nextSibling;
           //alert("blizniak" + childNode.nodeName) 
        }        
        else  code += "<td>&nbsp;</td>";     	  
      }while(j < cols)      	
    	code += "</tr>"       
      j = 0
    }while(i < rows) 
    childNode = null; 
  }
  else childNode = childNode.nextSibling
  //alert("next: " + childNode)
 }while(childNode != null)
 code += "</table>" 
 // alert(code) 
 return code
}

function readSekcja(theNode, ilang)
{
 var childNode
 var tytName = new String("Tytul")
 var opisName = new String("Opis")
 var listaName = new String("Lista")
 var obrazekName = new String("Obrazek")
 var  code = ""  
 childNode = theNode.firstChild
 
 if(childNode == null) return code
 do {
    
    if (tytName == childNode.nodeName) 
    	{ code += '<span class="lead"><span class="bold">' + readTextinLang(childNode, ilang) + "</span></span><br><br>" }
    else if (opisName == childNode.nodeName) 
	{code += readParagraphs(childNode, ilang) + "<br>" }
    else if (listaName == childNode.nodeName) 
      {code += readLista(childNode, ilang) + "<br>" }
    else if (obrazekName == childNode.nodeName) 
    {    
      code += "<center><table width='100%'><tr>"      
      do {
           	if (obrazekName == childNode.nodeName) 
            {
            code +=  "<td>" + readObrazekType(childNode, ilang, 1, 1, 0) +"</td>"  // wymiar oryginalny    
            	
            }
            childNode = childNode.nextSibling   
            
      }while(childNode != null) 

      code += "</tr></table></center><br>"
      
    }
    if(childNode != null) { 
                            childNode = childNode.nextSibling}
   
  }while(childNode != null) 
 
 return code
}
function Footer()
{
 return "<table class='footer' width=100%><tr><td align='center'><span class='mail'><a href='mailto:alicja.malinska@igik.edu.pl'>Webmaster</a></span><span class='infor'> :: Copyright &#169; 2005 Instytut Geodezji i Kartografii</span></td></tr></table>"
}


