var G_home = "http://kartes.delfi.lv/";
//var G_home = "http://localhost/delfi/";
var G_rekl = 0;

var stringFromFlash;

window.addEvent('domready', function() {
  var req_arr = req_uri.split('/');
  if(array_search(req_arr,'uznemumi') != false) window.location.hash="uznemumi"; ;
});

function array_search (array,val) {
  for (var i = 0; i < array.length; i++) {
    if (array[i] == val) {
      return i;
    }
  }
  return false;
};

var ObjIdGlobal = '';
function OpenObj(pictoId, ObjId) {
  ObjIdGlobal = ObjId;
  sendTab('1');
  sendIconId('0');
  zoomlatvia('do');
  sendIconId(pictoId);
  var OpenObjReq = new Request({
    method: 'get',
    url: G_home + 'ajax_uznemumi.php',
    data: 'officecat=' + pictoId + '&flashString=' + stringFromFlash,
    onSuccess: function(result){
      $('ajax').set('html', result);
      infopage_view(ObjIdGlobal);
    }
  }).send();
 
  //ajaxFunction('<?php echo $home; ?>?officecat=<?php echo $row['id_picto']; ?>&flashString='+stringFromFlash+'',3, 0);
}

function showhide(n, type, n2, f1, f2, f3) {
  if (type == 1) {
    if (document.getElementById("smallerMenu"+n).style.display == 'none') {
      document.getElementById("smallerMenu"+n).style.display='';
    } else {
      document.getElementById("smallerMenu"+n).style.display='none';
    }
  }
}

function showhide(id, id2) {
   if (document.getElementById(id).style.display == 'none') {
     document.getElementById(id).style.display='';
     document.getElementById(id2).style.display='none';
   } else {
     document.getElementById(id).style.display='none';
     document.getElementById(id2).style.display='';
     document.getElementById('ajaxx').scrollTop = 0;
   }
}

function uznbiglogo(img) {
	document.getElementById('uznbigphoto').innerHTML = "<img style='margin:5px;width:280px' src='"+img+"' alt='' title='assa'>";
}	

function go_anchor(n){
//alert(document.getElementById(n).offsetTop);
document.getElementById("ajaxx").scrollTop = document.getElementById(n).offsetTop-document.getElementById("ajaxx").offsetTop+10;
}

function ajaxFunction_new() {
  var xmlHttp;
  try
  {
  // Firefox, Opera 8.0+, Safari
  xmlHttp=new XMLHttpRequest();
  }
  catch (e)
  {
  // Internet Explorer
  try
    {
    xmlHttp=new ActiveXObject("Msxml2.XMLHTTP");
    }
  catch (e)
    {
    try
      {
      xmlHttp=new ActiveXObject("Microsoft.XMLHTTP");
      }
    catch (e)
      {
      return false;
      }
    }
  }
  return xmlHttp;
}

function bannerRotate() {
  if (G_rekl == 1) {
  	document.getElementById('frame1').src=G_home + 'delfi_banner.inc';
  	document.getElementById('frame2').src=G_home + 'bottombanners.inc';
  	httpquery = ajaxFunction_new();
  	
  	httpquery.onreadystatechange=function()
  	    {
  	    if(httpquery.readyState==4)
  	      {
  	      document.getElementById("topbanner").innerHTML=httpquery.responseText;
  	      }
  	    }
  	httpquery.open("GET", G_home+"topbanner.php" , true);
  	httpquery.send(null);
  }
}

var runing = false;
function singleTimer(val, idd, singlename, singlelogo) {
//alert(idd);
	//printids = false;
	if(runing) {
		clearTimeout(timer);
	}
	timer = setTimeout("ajaxFunction('ajax_singleobj.php?singleid="+idd+"&name="+singlename+"&logo="+singlelogo+"&searchvar="+val+"', 0, 0)", 100);
	runing = true;
}

var NiBack = '';

function ajaxFunction(page,type,numb,marshtype,fflash) {
  //page = G_home + 'ajax_1stpage.php';
  //alert(page);
  bannerRotate();
  	
  	if (type == 3) {
  		show('dab');
  	}
	if (type==1) {
		switch(marshtype)
		{
			case 'R11':
			showsab('tr1','display');
			break;    
			case 'R12':
			showsab('tr2','display')
			break;
			case 'R13':
			showsab('tr3','display')
			break;    
			case 'L11':
			showsab('tr4','display')
			break;
			case 'L13':
			showsab('tr5','display')
			break;
		}
	}
//alert(page);
  var xmlHttp;
  try
  {
  // Firefox, Opera 8.0+, Safari
  xmlHttp=new XMLHttpRequest();
  }
  catch (e)
  {
  // Internet Explorer
  try
    {
    xmlHttp=new ActiveXObject("Msxml2.XMLHTTP");
    }
  catch (e)
    {
    try
      {
      xmlHttp=new ActiveXObject("Microsoft.XMLHTTP");
      }
    catch (e)
      {
      return false;
      }
    }
  }
  xmlHttp.onreadystatechange=function()
    {
    if(xmlHttp.readyState==4)
      {
      document.getElementById('ajaxx').scrollTop = 0;
        if (type == 1) {
          if ($("ost"+numb).innerHTML != "" && fflash != 'flash') {
            $("ost"+numb).innerHTML="";
          } else {
            $("ost"+numb).innerHTML=xmlHttp.responseText;
            go_anchor('anc'+numb);
          }
        } else if (type == 2) {
		      $("ost"+numb).innerHTML=xmlHttp.responseText;
        } else {
          $("ajax").innerHTML=xmlHttp.responseText;
        }
        if(page.split('ajax_ni.php')[1] != undefined && type != 5) {
          NiBack = xmlHttp.responseText;
          //alert('1');
          //NiAjaxSearch();
          NiShowMap(1);
          addNiShow($('nip_type').value);
        }
        if(page.split('ajax_ni.php')[1] != undefined) {
          ChngClr();
          addNiShow($('nip_type').value);
        }
      }
    }
  xmlHttp.open("GET",page,true);
  xmlHttp.send(null);
}



function clickhide(what) {
  document.getElementById(what).innerHTML="<img width=15 height=15 src='"+G_home+"files/ajax-loader.gif'>";
}

function receivedFromFlash(str) {
  //x,y,level,width,height,search,heading,group,objects
  var str1=str.split("#");
  var str=str1[0];
  stringFromFlash = str1[0];
  var home=str1[1];
  var string=str.split(",");
  document.getElementById("coord").innerHTML=home+"?showcoord=1&xcoord="+string[0]+"&ycoord="+string[1]+"&lvl="+string[2];
  if (string[7]) {    ajaxFunction(G_home+'ajax.php?objects='+string[8]+'&group='+string[7]+'&x='+string[0]+'&y='+string[1]+'&level='+string[2]+'&width='+string[3]+'&height='+string[4], 0, 0);
  }
  if (string[5]) {  ajaxFunction(G_home+'ajax.php?objects=1&search='+string[5]+'&x='+string[0]+'&y='+string[1]+'&level='+string[2]+'&width='+string[3]+'&height='+string[4], 0, 0);
  }
}

function fPrint() {
  //alert(veloid);
  //var sendstr = '';
  if(veloid != '' && veloid != 'undefined') var sendstr = "&velo=" + veloid; else var sendstr = "";
  window.open(G_home+'printpage.php?flashstr='+stringFromFlash+sendstr, 'DelfiKartes', 'width=700,height=720,left=100')
  //alert(stringFromFlash);
}

var resized = 0;
function searchresult(txt) {
//alert(aaa);
	if (txt == 'on' && resized == 0) {
		
		//document.getElementById('maps4').height = document.getElementById('maps4').height - 100;
		//alert(document.getElementById('flashcontent3').style.height);
		height = parseInt(document.getElementById('flashcontent3').style.height.split("px")[0]);
		document.getElementById('flashcontent3').style.height = (height - 100) + "px";
		//alert(document.getElementById('flashkarte').style.height);
		height = parseInt(document.getElementById('addressList').height);
		document.getElementById('addressList').height = height + 100;
		resized = 1; 
		
	}
}

function thisMovie(movieName) {
    if (navigator.appName.indexOf("Microsoft") != -1) {
        return window[movieName];
    }
    else {
        return document[movieName];
    }
}
function sendText4(txt) {
	thisMovie("maps4").sendText4(txt);
  //alert('1 ' +txt);
}

var veloid;
function sendVelo(txt) {
  //alert(txt);
  veloid = txt;
  thisMovie("maps4").sendVelo(txt);
}

function sendVeloPointId(txt) {
  //alert(txt);
  thisMovie("maps4").sendVeloPointId(txt);
}

function sendText5(txt) {
//alert('2 '+txt);
	thisMovie("maps4").sendText5(txt);
}

function sendTab(txt) {
//alert('3 '+txt);
	thisMovie("maps4").sendTab(txt);
}

function sendIconId(txt) {
	thisMovie("maps4").sendIconId(txt);
}

function sendStop(txt) {
// alert(txt);
 thisMovie("maps4").sendStop(txt);
 bannerRotate();
 
}
function sendRoute(txt) {
	thisMovie("maps4").sendRoute(txt);
}
function sendni(txt) {
	thisMovie("maps4").sendni(txt);
}

function sendObject(txt) {
//	alert("4 "+txt);
	thisMovie("maps4").sendObject(txt);
}
function singleObjects(txt) {
//	alert("5 "+txt);
	thisMovie("maps4").sendClientsId(txt);
}
function zoomlatvia(txt) {
	thisMovie("maps4").zoomlatvia(txt);
}
function flashResize(txt) {
	thisMovie("maps4").flashResize(txt);
}				
function legendaFromFlash (txt2) {
	document.getElementById('info_div').style.display = 'none';
	document.getElementById("legenda").style.display='';
	document.getElementById("legenda").innerHTML=txt2;	
	document.getElementById("ajaxx").scrollTop = 0; 
}

function sendfromstop(txt) {
//var txt = 'Maris,547750,602250'; 
	thisMovie("sabtrans").sendfromstop(txt);
}	
function sendtostop(txt) {
//var txt = 'Maris,533050,610225'; 
	thisMovie("sabtrans").sendtostop(txt);
}  

function infopage_view(idd, name, img, text) {
  //alert(idd+", "+name+", "+img+", "+text);
	//document.getElementById('info_name').innerHTML = name;
	//document.getElementById('info_picto').src = img;
	//document.getElementById('info_text').innerHTML = text;*/
	httpquery = ajaxFunction_new();
	
	httpquery.onreadystatechange=function()
	    {
	    if(httpquery.readyState==4)
	      {
			document.getElementById("info_div").innerHTML=httpquery.responseText;
	    document.getElementById('ajaxx').scrollTop = 0;
			document.getElementById('legenda').style.display = 'none';
			document.getElementById('info_div').style.display = '';
	      }
	    }
	httpquery.open("GET", G_home+"ajax_uzninfo.php?idd="+idd , true);
	httpquery.send(null);
}

function niinfopage_view(idd, name, img, text) {
  //alert(idd+", "+name+", "+img+", "+text);
	//document.getElementById('info_name').innerHTML = name;
	//document.getElementById('info_picto').src = img;
	//document.getElementById('info_text').innerHTML = text;*/
	httpquery = ajaxFunction_new();
	
	httpquery.onreadystatechange=function()
	    {
	    if(httpquery.readyState==4)
	      {
			document.getElementById("info_div").innerHTML=httpquery.responseText;
	      	document.getElementById('ajaxx').scrollTop = 0;
			document.getElementById('legenda').style.display = 'none';
			document.getElementById('info_div').style.display = '';
	      }
	    }
	httpquery.open("GET", G_home+"ajax_niinfo.php?idd="+idd , true);
	httpquery.send(null);
}

var tabShow;
function show(what) {
 /* if (what == 'sab') {
  	tabShow = 2;
    document.getElementById("sab").style.backgroundColor='#ffcc00';
    document.getElementById("sab1").src=G_home+'files/corn2.gif';
    document.getElementById("dab").style.backgroundColor='#e4e4e4';
    document.getElementById("dab1").src=G_home+'files/corn1.gif';
	document.getElementById("sabtrans2").style.display = '';
  } else {
 	tabShow = 1;
    document.getElementById("dab").style.backgroundColor='#ffcc00';
    document.getElementById("dab1").src=G_home+'files/corn2.gif';
    document.getElementById("sab").style.backgroundColor='#e4e4e4';
    document.getElementById("sab1").src=G_home+'files/corn1.gif';
		document.getElementById("sabtrans2").style.display = 'none';
  }*/
}
function showsab(n,view) {
    if (document.getElementById(n).style.display == 'none') {
      document.getElementById(n).style.display='';
    } else if(view != 'display') {
      document.getElementById(n).style.display='none';
    }
    bannerRotate();
}


function send_koment (name, text) {
	bannerRotate();
	if (name != "" && text != "")
	{
		htmlRequest = ajaxFunction_new();
		/*htmlRequest.onreadystatechange=function()
		{
		if(htmlRequest.readyState==4)
		  {
		  document.getElementById("komentari").innerHTML="help";
		  }
		}*/
			   //alert(feasy);
		htmlRequest.open("POST", G_home+"sendkoment.php?name="+name+"&text="+text, true);
		htmlRequest.send(null);
		document.getElementById('komname').value="";
		document.getElementById('komtext').value="";
		document.getElementById('komentresult').innerHTML="<b>Paldies! Komentārs nosūtīts!</b>";
	}
}

var plus = 1;
function timed_width(wdth) {
	var obj = document.getElementById('hiddendiv');
	var flash = document.getElementById('flashkarte');
	width = obj.style.width;
	width = width.split('p')
	objwdth = parseInt(width[0]);
	//alert(objwdth);
	width = flash.style.width;
	width = width.split('p')
	flashwidth = parseInt(width[0]);
	//alert(flashwidth);
	if(objwdth < wdth)  
	{ 
		//clearTimeout(t2);
		obj.style.width = (objwdth+plus)+'px'; 
 		flash.style.width = (flashwidth-plus)+'px';
 		plus++;
		t=setTimeout('timed_width('+wdth+')',4); 
	} 
}

function changedirection(id) {
	if(document.getElementById('dir2_'+id).style.display == 'none') {
		document.getElementById('dir2_'+id).style.display = ''
		document.getElementById('dir1_'+id).style.display = 'none'
	} else {
		document.getElementById('dir2_'+id).style.display = 'none'
		document.getElementById('dir1_'+id).style.display = ''
	}
}

function get_time (marsh, pietura, direct) {
	htmlRequest = ajaxFunction_new();
	htmlRequest.onreadystatechange=function()
	{
	if(htmlRequest.readyState==4)
	  {
	  document.getElementById("flip_"+pietura+'_'+direct).innerHTML=htmlRequest.responseText;;
	  }
	}
		   //alert(feasy);
	htmlRequest.open("POST", G_home+"ajax_time.php?marsh="+marsh+"&pietura="+pietura+"&dir="+direct, true);
	htmlRequest.send(null);
}

var curr = 0;
var opened = 0;
var currdir = 0;
function flip(id,dir,marsh) {
	if ((curr == id) && (opened == 1)) {
		document.getElementById('flip_' + id + '_' + dir).style.display = 'none';
		document.getElementById('flip_' + id + '_' + dir).innerHTML = '';
		opened = 0;
	} else if (curr == id) {
		document.getElementById('flip_' + curr + '_' + currdir).style.display = '';
		get_time (marsh, curr, currdir)
		opened = 1;
	} else {
		if(curr != 0) {
		  try
 			{
 	 			document.getElementById('flip_' + curr + '_' + currdir).style.display = 'none';
 	 			document.getElementById('flip_' + curr + '_' + currdir).innerHTML = '';
			} catch (e) {}
		}
		document.getElementById('flip_' + id + '_' + dir).style.display = '';
		get_time (marsh, id, dir)
		opened = 1;
	}
	curr = id;
	currdir = dir;
}

function time_type_selection(id) {
	for(i=1;i<=3;i++) {
		document.getElementById('show_type'+i).style.display='none';
		document.getElementById('type'+i).className='time_type_deselected';
	}
	document.getElementById(id).className='time_type_selected';
	document.getElementById('show_'+id).style.display='';
	document.body.style.cursor = 'default';
}

function bigimgchange(name, link, img) {
	document.getElementById('bigname').innerHTML = name;
	document.getElementById('bigimg').src = img;
	document.getElementById('biglink').href = link;
	document.getElementById('biglink2').href = link;
}

function kasparsabcd(id) {
	thisMovie("maps4").kasparsabcd(id);
}