var selectedService="",selectedStation="",ref,l,m;



function getReference()
{
var xmlData=document.getElementById("Contacts");
var keyServiceContacts=[],keyContact,serviceReq,stationReq,name=[],pic=[],desig=[],phoneLine=[],mobile=[],facs=[],eml1=[],eml2=[],star=[],comm=[];
var keyPersons=xmlData.getElementsByTagName("KeyPerson");

var ind,k,stations,l,temp,z=0,tempType,y;

for(ind=0;ind<keyPersons.length;ind++)
		{
		keyContact=keyPersons[ind];
		stationReq=keyContact.getElementsByTagName("City")[0].firstChild.data;
		serviceReq=keyContact.getElementsByTagName("Designation")[0].getAttribute("type");
		k=stationReq.localeCompare(selectedStation);
		l=serviceReq.localeCompare(selectedService);
		if(k==0 && l==0)
			{
			name.push(keyContact.getElementsByTagName("Name")[0].firstChild.data);
			star.push(keyContact.getElementsByTagName("Rank")[0].firstChild.data);
			desig.push(keyContact.getElementsByTagName("Designation")[0].firstChild.data);
			facs.push(keyContact.getElementsByTagName("Facsimile")[0].firstChild.data);
			eml1.push(keyContact.getElementsByTagName("Email1")[0].firstChild.data);
			eml2.push(keyContact.getElementsByTagName("Email2")[0].firstChild.data);
			pic.push(keyContact.getElementsByTagName("Picture")[0].firstChild.data);
			comm.push(keyContact.getElementsByTagName("SITA")[0].firstChild.data);
			temp=keyContact.getElementsByTagName("Phone");
			for(z=0;z<temp.length;z++)
				{
				tempType=keyContact.getElementsByTagName("Phone")[z].getAttribute("type");
				y=tempType.localeCompare("landLine");
				if(y==0)
					phoneLine.push(keyContact.getElementsByTagName("Phone")[z].firstChild.data);
				else
					mobile.push(keyContact.getElementsByTagName("Phone")[z].firstChild.data);
				}
			}/***********closing if block************/
		}/************closing for loop*************/
		win = window.open("KeyPersons.htm","","toolbar=no, menubar=no, status=yes, scrollbar=yes,width=500,height=600");
		win.document.write('<Link href="stylesheets/table_design[1].css" rel="stylesheet" type="text/css">');
		if(selectedStation=="")
			{
			selectedStation=="no station is selected";
			win.document.write('<table><tr><td bgColor="#ededed" align="left" ><img src="images/sapsLogoSmall.gif"></td><td bgColor="#ededed" align="left" width="200"><font class="sans">List of SAPS keypersons</font></td></tr><tr><td colspan="2"><font class="sans" align="center">no station is selected</font></td></tr></table>');
			}
		else if(selectedService=="")
			{
			selectedService=="no service is selected";
			win.document.write('<table><tr><td bgColor="#ededed" align="left" ><img src="images/sapsLogoSmall.gif"></td><td bgColor="#ededed" align="left" width="200"><font class="sans">List of SAPS keypersons</font></td></tr><tr><td colspan="2"><font class="sans" align="center">no service is selected</font></td></tr></table>');
			}
		else if(selectedService=="" && selectedStation=="")
		{
		selectedService=="no service is selected";
		selectedStation=="no station is selected";
		win.document.write('<table><tr><td bgColor="#ededed" align="left"><img src="images/sapsLogoSmall.gif"></td><td bgColor="#ededed" width="200"><font class="sans">'+ selectedStation +'<br>'+selectedService+'</font></td></tr></table>');
		}
		else
		{
		win.document.write('<table><tr><td bgColor="#ededed" align="left" ><img src="images/sapsLogoSmall.gif"></td><td bgColor="#ededed" align="left" width="200"><font class="sans">List of SAPS keypersons</font></td></tr><tr><td colspan="2"><font class="Title" align="center"><small>'+'"'+selectedService+'"'+" related key contacts in "+'"'+selectedStation+'"'+'</small></font></td></tr><br>');
		win.document.write('<tr><td colspan="2"><font class="listTitle">'+"Key Contacts List"+'</font><br></td></tr>');
		if(name.length>0)
		{
		win.document.write('<tr><td colspan="2"><table>');
		y=name.length;
		z=0;
			do	{
				win.document.write('<tr><td rowspan="2"><img style="border:1pt solid #444444" src="'+pic.pop()+'" alt="Picture not found"></img></td><td rowspan="1" style="background:#eeeeee"><font class="sans">'+star.pop()+'</font><font class="p"><b>'+" "+ name.pop()+'</b></font></td></tr>');
				win.document.write('<tr><td rowspan="1" ><p class="p">'+desig.pop()+'<br>'+"Phone: "+phoneLine.pop()+'<br>'+"Mobile: "+ mobile.pop()+"       Fax: "+ facs.pop()+'<br>'+"Email: "+eml1.pop()+'<br>'+"Email: "+eml2.pop()+'<br>'+"SITA: "+comm.pop()+'</p></td></tr>');
				z++;
			}while(z<y);		
		win.document.write('</table></td></tr><tr><td colspan="2" background="#ededed"><font class="sans"><small>information service by TREES</small></font></td></tr></table>');
		}
		else
		 win.document.write('<tr><td><font class="listTitle">'+"No "+selectedService+" related persons found in "+selectedStation+'</font><br></td></tr><tr><td colspan="2" background="#ededed"><font class="sans"><small>information service by TREES</small></font></td></tr></table>');
		}
		
}


function getService(){
selectedService=document.all.reqService.options[reqService.selectedIndex].value;
}

function getCity()
{selectedStation=document.all.serviceStation.options[serviceStation.selectedIndex].value;
}


