var addressHREF;
var caricaDove;
var caricaDove;
var z=0;
var tagName=null;
var doveName=null;
var sitoName=null;
var visualizzaDove=null;
var visualizzaDove=null;
var nomeSito=null;
var nomeSito=null;
var  Valorelink = new Array(); 
var j=0;
var n;

	function caricaPagine()
	{
		z=0;
		tagNameTemp=document.getElementById("indirizzo");
		tagName=tagNameTemp.value.split(" --- ");
		doveNameTemp=document.getElementById("dove");
		
		doveName=doveNameTemp.value.split(" --- ");
		sitoNameTemp=document.getElementById("sitoNome");

		sitoName=sitoNameTemp.value.split(" --- ");
		caricaPagine2(0);
	}
	function caricaPagine2(z)
	{	//alert(tagName[1]);
		if (z<tagName.length)
		{
			var indirizzo=tagName[z];
			caricaDove="qui"+doveName[z];
			visualizzaDove="sito"+doveName[z];
			nomeSito=sitoName[z];

			if (window.XMLHttpRequest) {
				ricerca_pro = new XMLHttpRequest();
				ricerca_pro.onreadystatechange = ricaricaPaginaesterna;
				ricerca_pro.open("GET", "caricaFile.asp?file="+indirizzo,true);
				ricerca_pro.send(null);
				} 
			else if (window.ActiveXObject) {
				ricerca_pro = new ActiveXObject("Microsoft.XMLHTTP");
				if (ricerca_pro) {
					ricerca_pro.onreadystatechange = ricaricaPaginaesterna;
					ricerca_pro.open("GET", "caricaFile.asp?file="+indirizzo,true);
					ricerca_pro.send(null);
				}
			}
		}
	}
	function ricaricaPaginaesterna() {

		var strRes;
		var arrValori;
		if (ricerca_pro.readyState == 1) {

			//document.getElementById(visualizzaDove+"TEMP").style.display="";
			document.getElementById(visualizzaDove).innerHTML="<IMG SRC=\"immagini/caricamento.gif\">";
		
		}

		if (ricerca_pro.readyState == 4 && ricerca_pro.status==200) {
			strRes=ricerca_pro.responseText;
			document.getElementById(caricaDove).innerHTML=strRes;
		switch (nomeSito) {
			case "roadsharing": roadsharing(visualizzaDove); break;
			case "mitfahrzentrale":n=2; mitfahrzentrale(); break;
			default: ;
		}	
			z++;
			caricaPagine2(z)

		}
	}

	function caricaPaginePaginazione(indiriz,carica,visualizza,Sito)
	{	

		var indirizzo=escape(indiriz);
		caricaDove=carica;
		visualizzaDove=visualizza;
		nomeSito=Sito;


		if (window.XMLHttpRequest) {
			ricerca_pro = new XMLHttpRequest();
			ricerca_pro.onreadystatechange = ricaricaPaginaesternaPaginazione;
			ricerca_pro.open("GET", "caricaFile.asp?file="+indirizzo,true);
			ricerca_pro.send(null);
			} 
		else if (window.ActiveXObject) {
			ricerca_pro = new ActiveXObject("Microsoft.XMLHTTP");
			if (ricerca_pro) {
				ricerca_pro.onreadystatechange = ricaricaPaginaesternaPaginazione;
				ricerca_pro.open("GET", "caricaFile.asp?file="+indirizzo,true);
				ricerca_pro.send(null);
			}
		}
	}

	function ricaricaPaginaesternaPaginazione() {

		var strRes;
		var arrValori;

	if (ricerca_pro.readyState == 1) {

		//	alert(visualizzaDove)

			//document.getElementById(visualizzaDove+"TEMP").style.display="";
			document.getElementById(visualizzaDove).innerHTML="<IMG SRC=\"immagini/caricamento.gif\">";
		
		}

		if (ricerca_pro.readyState == 4 && ricerca_pro.status==200) {
			strRes=ricerca_pro.responseText;
			document.getElementById(caricaDove).innerHTML=strRes;
		switch (nomeSito) {
			case "roadsharing": roadsharing(visualizzaDove); break;
			case "mitfahrzentrale":n=1; mitfahrzentrale(); break;
			default: ;
		}	

		}
	}


	function roadsharing(visualDove) {
			var scriviDove=document.getElementById(visualDove);
			var currentPage;
			var currentPage;
			var percorso=document.getElementById("listapercorsi");

			if (!percorso)
			{
				scriviDove.innerHTML="No results found!";
				return false;
			}
				
				var DIVnumeroResult=document.getElementById("paginazionepercorsi");
				var paginazione=false;
				if (DIVnumeroResult.getElementsByTagName("div").length>0)
				{
					paginazione=true;
					var DIVnumeroPage=DIVnumeroResult.getElementsByTagName("div")[0];
					
					var AnumeroResult=DIVnumeroPage.getElementsByTagName("a")[DIVnumeroPage.getElementsByTagName("a").length-1].href;
			//		var numeroResult=AnumeroResult.href.split("doc=")[1].split("&")[0];
			//		var numeroPage=AnumeroResult.href.split("absolutepage=")[1].split("&")[0];
					var stringa="";
					for (var j=1;j<AnumeroResult.split("search")[1].split("absolutepage=")[1].split("&").length ;j++ )
					{
						if (stringa=="")
						{
							stringa=AnumeroResult.split("search")[1].split("absolutepage=")[1].split("&")[j]

						}
						else{
							stringa=stringa+"&"+AnumeroResult.split("search")[1].split("absolutepage=")[1].split("&")[j]
						}
					}
					addressHREF="/search"+AnumeroResult.split("search")[1].split("absolutepage=")[0]+stringa;
					var currentPageSpan=DIVnumeroResult.getElementsByTagName("span");
					var ultimo=1000;
						if (currentPageSpan[0].className=="noactive")
						{
							currentPage=1;
						}
						else
						{
							currentPage=currentPageSpan[0].innerHTML;
						}
						if (currentPageSpan[1])
						{
							if (currentPageSpan[1].className=="noactive")
							{
								ultimo=currentPage;
							}
						}
	//				alert(currentPage);
			//		alert(numeroResult);
			//		alert(numeroPage);
			
				}

			var righe=percorso.getElementsByTagName("tr");
				
				testo="<table class=\"visualizza\" style=\"width:90%\">"
				testo=testo+"<tr><td class=\"titolo\">Date</td><td class=\"titolo\">Departure</td><td class=\"titolo\">Arrival</td></tr>"


					for (var j = 1; j < righe.length; j++) {
						// creates a table row
						
						
						var classe="pari";

						if (j % 2== 0)
						{
							classe="dispari";
						}

						
						var colonne=righe[j].getElementsByTagName("td");
						
						var valLink="http://roadsharing.com/"+colonne[0].getElementsByTagName("a")[0].getAttribute("href");


						testo=testo+"<tr onmouseover=\"this.className='over'\" onmouseout=\"this.className=''\" onclick=\"location.href='"+valLink+"'\">"
						testo=testo+"<td class="+classe+">"+colonne[2].innerHTML+"</td>"
						testo=testo+"<td class="+classe+">"+colonne[0].getElementsByTagName("a")[0].childNodes[1].nodeValue+"</td>"
						testo=testo+"<td class="+classe+">"+colonne[1].getElementsByTagName("a")[0].childNodes[1].nodeValue+"</td>"
						testo=testo+"</tr>"

					}
				if (paginazione)
				{
					testo=testo+"<TR><TD style=\"text-align:center;\" class=\"paginazione\" colspan=\"3\">"
					if (currentPage!=1)
					{
						testo=testo+"<a href=\"javascript:void(0)\" onclick=\"caricaPaginePaginazione('http://www.roadsharing.com"+addressHREF+"&absolutepage=1','"+caricaDove+"','"+visualizzaDove+"','"+nomeSito+"');\">&lt;&lt;</a>&nbsp;<a href=\"javascript:void(0)\" onclick=\"caricaPaginePaginazione('http://www.roadsharing.com"+addressHREF+"&dpage="+(Number(currentPage)-1)+"','"+caricaDove+"','"+visualizzaDove+"','"+nomeSito+"');\">&lt;</a>&nbsp;"
					}
					for (var q=currentPage-1; q<(Number(currentPage)+2); q++)
					{
						if ((q>0) && (q<Number(ultimo)+1))
						{
							if (q==currentPage)
							{
								testo=testo+q+"&nbsp;"
							}
							else
							{
								testo=testo+"<a href=\"javascript:void(0)\" onclick=\"caricaPaginePaginazione('http://www.roadsharing.com"+addressHREF+"&absolutepage="+q+"','"+caricaDove+"','"+visualizzaDove+"','"+nomeSito+"');\">"+q+"</a>&nbsp;"
							}
						}
					}

					if (currentPage!=Number(ultimo))
					{
						testo=testo+"<a href=\"javascript:void(0)\" onclick=\"caricaPaginePaginazione('http://www.roadsharing.com"+addressHREF+"&absolutepage="+(Number(currentPage)+1)+"','"+caricaDove+"','"+visualizzaDove+"','"+nomeSito+"');\">&gt;</a>"
					}

				}
				testo=testo+"</TABLE>";


				scriviDove.innerHTML=testo;
		caricaDove="";
		visualizzaDove="";
		nomeSito="";

	}
	function mitfahrzentrale() {
		var testo="";
			var scriviDove=document.getElementById(visualizzaDove);
			var percorso=document.getElementById(caricaDove).getElementsByTagName("table");
			if (!percorso[0])
			{
		
				scriviDove.innerHTML="No results found!";
				return false;
			}
			if (percorso[0])
			{
			
				var DIVnumeroResult=document.getElementById("dres");

				var paginazione=false;
				var DIVnumeroPage=DIVnumeroResult.getElementsByTagName("div")[0];
				if (DIVnumeroPage.getElementsByTagName("a").length>0)
				{
					paginazione=true;
					
					
					var AnumeroResult=DIVnumeroPage.getElementsByTagName("a")[DIVnumeroPage.getElementsByTagName("a").length-1];
					
					
					var numeroResult=AnumeroResult.href.split("doc=")[1].split("&")[0];
					var numeroPage=AnumeroResult.href.split("dpage=")[1].split("&")[0];
					addressHREF="/suche.php"+AnumeroResult.href.split("suche.php")[1].split("&dpage=")[0]+AnumeroResult.href.split("suche.php")[1].split("&dpage=")[1].split("&")[1];

					var currentPage=DIVnumeroResult.getElementsByTagName("div")[2].innerHTML.split("| Seite")[1].split("</span>")[0];
				//	alert(currentPage);
				//	alert(numeroResult);
				//	alert(numeroPage);
				}				
				var righe=percorso[0].getElementsByTagName("tr");
					
				testo="<table class=\"visualizza\" style=\"width:90%\">"
				testo=testo+"<tr><td class=\"titolo\">Date</td><td class=\"titolo\">Departure</td><td class=\"titolo\">Arrival</td></tr>"
				
			 

						for (j = n; j < righe.length; j++) {
							if (righe[j].className=="tabbody mfz_rtrow")
							{
							
								var classe="pari";

								if (j % 2== 0)
								{
									classe="dispari";
								}

								var valLink=righe[j].onclick.toString().split("?")[1];
								valLink=valLink.split(";")[0];
								valLink="http://www.mitfahrzentrale.de/abfrage.php?"+valLink.substring(0,valLink.length-1);
								var colonne=righe[j].getElementsByTagName("td");

								testo=testo+"<tr onmouseover=\"this.className='over'\" onmouseout=\"this.className=''\" onclick=\"window.open('"+valLink+"')\">"
								testo=testo+"<td class="+classe+">"+colonne[1].innerHTML+"</td>"
								testo=testo+"<td class="+classe+">"+colonne[2].innerHTML+"</td>"
								testo=testo+"<td class="+classe+">"+colonne[3].innerHTML+"</td>"
								testo=testo+"</tr>"
									
							
							}
						}
							
			}
				if (paginazione)
				{

					testo=testo+"<TR><TD style=\"text-align:center;\" class=\"paginazione\" colspan=\"3\"><B>"+ numeroResult +"  results visualized in "+ numeroPage +" page</B><BR>"
					if (currentPage!=1)
					{
						testo=testo+"<a href=\"javascript:void(0)\" onclick=\"caricaPaginePaginazione('http://www.mitfahrzentrale.de"+addressHREF+"&dpage=1','"+caricaDove+"','"+visualizzaDove+"','"+nomeSito+"');\">&lt;&lt;</a>&nbsp;<a href=\"javascript:void(0)\" onclick=\"caricaPaginePaginazione('http://www.mitfahrzentrale.de"+addressHREF+"&dpage="+(Number(currentPage)-1)+"','"+caricaDove+"','"+visualizzaDove+"','"+nomeSito+"');\">&lt;</a>&nbsp;"
					}
					for (var q=currentPage-1; q<(Number(currentPage)+2); q++)
					{
						if ((q>0) && (q<=numeroPage))
						{
							if (q==currentPage)
							{
								testo=testo+q+"&nbsp;"
							}
							else
							{
								testo=testo+"<a href=\"javascript:void(0)\" onclick=\"caricaPaginePaginazione('http://www.mitfahrzentrale.de"+addressHREF+"&dpage="+q+"','"+caricaDove+"','"+visualizzaDove+"','"+nomeSito+"');\">"+q+"</a>&nbsp;"
							}
						}
					}

					if (Number(currentPage)<Number(numeroPage))
					{
						testo=testo+"<a href=\"javascript:void(0)\" onclick=\"caricaPaginePaginazione('http://www.mitfahrzentrale.de"+addressHREF+"&dpage="+(Number(currentPage)+1)+"','"+caricaDove+"','"+visualizzaDove+"','"+nomeSito+"');\">&gt;</a>&nbsp;<a href=\"javascript:void(0)\" onclick=\"caricaPaginePaginazione('http://www.mitfahrzentrale.de"+addressHREF+"&dpage="+numeroPage+"','"+caricaDove+"','"+visualizzaDove+"','"+nomeSito+"');\">&gt;&gt;</a>&nbsp;"
					}
				}

				testo=testo+"</TABLE>";

				
				scriviDove.innerHTML=testo;
		caricaDove="";
		visualizzaDove="";
		nomeSito="";
		
	}


