function getHTTPObject() {
	var xmlHttp = false;
	/*@cc_on @*/
	/*@if (@_jscript_version >= 5)
	try {
	  xmlHttp = new ActiveXObject("Msxml2.XMLHTTP");
	} catch (e) {
	  try {
	    xmlHttp = new ActiveXObject("Microsoft.XMLHTTP");
	  } catch (e2) {
	    xmlHttp = false;
	  }
	}
	@end @*/
	
	if (!xmlHttp && typeof XMLHttpRequest != 'undefined') {
	  xmlHttp = new XMLHttpRequest();
	}
	return xmlHttp;
}
var http = getHTTPObject(); // We create the HTTP Object
var showAnn = null;
var showRoute = null;
var showTV = null;

function AS (num) {
	document.getElementById('ASRand').value = num;
}

function announcementPic(a_id, p_id, w, h) {
	window.open("/sludinajumi_p.php?a="+a_id+"&p="+p_id, "", "resizable=1,HEIGHT="+h+",WIDTH="+w);
}

function announcementShowResponse() {
	if (http.readyState == 4) {
			document.getElementById('anndata'+showAnn).innerHTML = http.responseText;
			document.getElementById('anndata'+showAnn).style.display = 'block';
			document.getElementById('anns'+showAnn).className = 'announcement_short anns_sel';
	}
}

function announcementShow(type, id) {
	if(showAnn != null){
		document.getElementById('anndata'+showAnn).innerHTML = '';
		document.getElementById('anns'+showAnn).className = 'announcement_short';		
		document.getElementById('anndata'+showAnn).style.display = 'none'		
	}
	if(showAnn == id && document.getElementById('anns'+showAnn).className != 'announcement_short'){
		//
	}else{
		showAnn = id;
		document.getElementById('anndata'+showAnn).innerHTML += 'Ielādēju...';	
		http.open("GET", '/sludinajumi/'+type+'/'+id+'/?segment', true);
		http.onreadystatechange = announcementShowResponse;
		http.send(null);
	}
}

function routeShow (id) {
	var ua = navigator.userAgent.toLowerCase();
	isGecko = (ua.indexOf('gecko') != -1 && ua.indexOf('safari') == -1);
	
	if(!isGecko && http){
		if(id != showRoute){
			document.getElementById('bus_route_list').style.display = 'none';
			document.getElementById('route_loading').style.display = 'block';
			http.open("GET", '/autobusi/'+id+'/?segment', true);
			http.onreadystatechange = routeShowResponse;
			http.send(null);	
		}
		return false;
	}else{
		return true;
	}
}

function routeShowResponse () {
	if (http.readyState == 4) {	
		document.getElementById('route_loading').style.display = 'none';
		document.getElementById('route_results').innerHTML = http.responseText;	
		document.getElementById('route_results').style.display = 'block';	
	}
}

function routeList () {
	document.getElementById('route_results').style.display = 'none';
	document.getElementById('bus_route_list').style.display = 'block';	
}

function TVShow (id) {
	if(http){
		if(id != showTV){
			if(showTV != null){
				document.getElementById('tv_'+showTV).className='';
			}
			showTV = id;
			document.getElementById('tv_'+id).className='sel';
			document.getElementById('tv_results').innerHTML = 'Lūdzu uzgaidiet&hellip;';
			http.open("GET", '/tv/'+id+'/?segment', true);
			http.onreadystatechange = TVShowResponse;
			http.send(null);	
		}
		return false;
	}else{
		return true;
	}
}

function TVShowResponse () {
	if (http.readyState == 4) {	
		document.getElementById('tv_results').innerHTML = http.responseText;	
	}
}