var uploadsuccess=false;
var uploader;
var query='';
var gettime='';
var getcinema='';
var getmovies='';
var getmetro='';
var getgenres='';
var tstr='';
var obj;
var obj2;
var count;
var i;
var fullcount;
textquery=new Array();


function getAfisha()
{
 if(!uploadsuccess) uploader_init();
 var raspdiv = document.getElementById("rt");
 raspdiv.innerHTML="<p>Загружается расписание&hellip;</p>";
 query='city='+city;
 if(getdate!='') query+='&date='+getdate;
 if(gettime!='') query+='&time='+gettime;
 if(getcinema!='') query+='&cinema='+getcinema;
 if(getmovies!='') query+='&movies='+getmovies;
 if(getmetro!='') query+='&metro='+getmetro;
 if(getgenres!='') query+='&genres='+getgenres;
 setTimeout("uploader_go('" + query + "');",200);
}


function dateSubmit()
{
	var selectwindowBlocks = as.$('div.selectwindow');
 for (var i=0;i<selectwindowBlocks.length;i++){
	 selectwindowBlocks[i].style.display = 'none';
	}
 document.getElementById('dateselect').style.display='none';
 document.getElementById('afishawindow').style.display='none';
 obj = document.dateform.datevalue;
 for(i=0;i<obj.length;i++) if(obj[i].checked)
 {
  getdate = obj[i].value;
  document.getElementById('datequery').innerHTML=document.dateform.datename[i].value;
 }
}


function timeSubmit()
{
	var selectwindowBlocks = as.$('div.selectwindow');
 for (var i=0;i<selectwindowBlocks.length;i++){
	 selectwindowBlocks[i].style.display = 'none';
	}
 document.getElementById('timeselect').style.display='none';
 document.getElementById('afishawindow').style.display='none';
 textquery.splice(0,textquery.length);
 obj = document.getElementsByName('timevalue[]');
 gettime='';
 count=0;
 fullcount=obj.length;
 for(i=0;i<obj.length;i++) if(obj[i].checked)
 {
  if(obj[i].value=='morning') textquery[textquery.length]='утром';
  if(obj[i].value=='day') textquery[textquery.length]='днем';
  if(obj[i].value=='afternoon') textquery[textquery.length]='вечером';
  gettime += obj[i].value + '|';
  count++;
 }
 tstr='';
 for(i=0;i<textquery.length;i++)
 {
  if((tstr!='') && (i+1<textquery.length)) tstr+=', ';
  if((tstr!='') && (i+1==textquery.length)) tstr+=' или&nbsp;';
  tstr+=textquery[i];
 }
 if(tstr!='' && count<fullcount)
 {
  document.getElementById('timequery').style.display='inline';
  document.getElementById('timequery').innerHTML=tstr;
  document.getElementById('timelnk').className='select';
 }
 else
 {
  document.getElementById('timequery').innerHTML='';
  document.getElementById('timequery').style.display='none';
  document.getElementById('timelnk').className='';
  gettime='';
 }
}


function cinemaSubmit()
{
	var selectwindowBlocks = as.$('div.selectwindow');
 for (var i=0;i<selectwindowBlocks.length;i++){
	 selectwindowBlocks[i].style.display = 'none';
	}
 document.getElementById('cinemaselect').style.display='none';
 document.getElementById('afishawindow').style.display='none';
 textquery.splice(0,textquery.length);
 obj = document.getElementsByName('cinemavalue[]');
 obj2 = document.getElementsByName('cinemaname[]');
 getcinema='';
 count=0;
 fullcount=obj.length;
 for(i=0;i<obj.length;i++) if(obj[i].checked)
 {
  textquery[textquery.length] = obj2[i].value;
  getcinema += obj[i].value + '|';
  count++;
 }
 tstr='';
 if(count<6)
 {
  for(i=0;i<textquery.length;i++)
  {
   if((tstr!='') && (i+1<textquery.length)) tstr+=', ';
   if((tstr!='') && (i+1==textquery.length)) tstr+=' или&nbsp;';
   tstr+='&laquo;' + textquery[i] + '&raquo;';
  }
  tstr='в&nbsp;кинотеатре ' + tstr;
 }
 else
 {
  tstr='в&nbsp;одном из&nbsp;' + count;
  if(count%10==1 && count>20) tstr+='&nbsp;кинотеатра';
  else tstr+='&nbsp;кинотеатров';
 }
 document.getElementById('cinemaquery').style.display='inline';
 document.getElementById('metroquery').innerHTML='';
 if(document.getElementById("metrolnk")!=null) document.getElementById('metrolnk').className='';
 if(document.getElementById("metroquery")!=null) document.getElementById('metroquery').style.display='none';
 clearSelect('metrovalue[]');
 getmetro='';
 if(count>0 && count<fullcount)
 {
  document.getElementById('cinemaquery').innerHTML=tstr;
  document.getElementById('cinemalnk').className='select';
 }
 else
 {
  document.getElementById('cinemaquery').innerHTML='выберите кинотеатр';
  document.getElementById('cinemalnk').className='';
  getcinema='';
 }
}


function metroSubmit()
{
	var selectwindowBlocks = as.$('div.selectwindow');
 for (var i=0;i<selectwindowBlocks.length;i++){
	 selectwindowBlocks[i].style.display = 'none';
	}
 document.getElementById('metroselect').style.display='none';
 document.getElementById('afishawindow').style.display='none';
 textquery.splice(0,textquery.length);
 obj = document.getElementsByName('metrovalue[]');
 obj2 = document.getElementsByName('metroname[]');
 getmetro='';
 count=0;
 fullcount=obj.length;
 for(i=0;i<obj.length;i++) if(obj[i].checked)
 {
  textquery[textquery.length] = obj2[i].value;
  getmetro += obj[i].value + '|';
  count++;
 }
 tstr='';
 if(count<6)
 {
  for(i=0;i<textquery.length;i++)
  {
   if((tstr!='') && (i+1<textquery.length)) tstr+=', ';
   if((tstr!='') && (i+1==textquery.length)) tstr+=' или&nbsp;';
   tstr+='&laquo;' + textquery[i] + '&raquo;';
  }
  tstr='рядом со&nbsp;станцией метро ' + tstr;
 }
 else
 {
  tstr='рядом с&nbsp;одной из&nbsp;' + count;
  if(count%10==1 && count>20) tstr+='&nbsp;станции метро';
  else tstr+='&nbsp;станций метро';
 }
 if(count>0 && count<fullcount)
 {
  document.getElementById('cinemaquery').innerHTML='';
  document.getElementById('cinemalnk').className='';
  document.getElementById('cinemaquery').style.display='none';
  document.getElementById('metroquery').style.display='inline';
  document.getElementById('metroquery').innerHTML=tstr;
  document.getElementById('metrolnk').className='select';
  clearSelect('cinemavalue[]');
 }
 else
 {
  document.getElementById('metroquery').innerHTML='';
  document.getElementById('metrolnk').className='';
  document.getElementById('metroquery').style.display='none';
  document.getElementById('cinemaquery').style.display='inline';
  document.getElementById('cinemaquery').innerHTML='выберите кинотеатр';
  document.getElementById('cinemalnk').className='';
  getmetro='';
 }
 getcinema='';
}


function moviesSubmit()
{
	var selectwindowBlocks = as.$('div.selectwindow');
 for (var i=0;i<selectwindowBlocks.length;i++){
	 selectwindowBlocks[i].style.display = 'none';
	}
 document.getElementById('moviesselect').style.display='none';
 document.getElementById('afishawindow').style.display='none';
 textquery.splice(0,textquery.length);
 obj = document.getElementsByName('moviesvalue[]');
 obj2 = document.getElementsByName('moviesname[]');
 getmovies='';
 count=0;
 fullcount=obj.length;
 for(i=0;i<obj.length;i++) if(obj[i].checked)
 {
  textquery[textquery.length] = obj2[i].value;
  getmovies += obj[i].value + '|';
  count++;
 }
 tstr='';
 if(count<6)
 {
  for(i=0;i<textquery.length;i++)
  {
   if((tstr!='') && (i+1<textquery.length)) tstr+=', ';
   if((tstr!='') && (i+1==textquery.length)) tstr+=' или&nbsp;';
   tstr+='&laquo;' + textquery[i] + '&raquo;';
  }
  tstr='фильм ' + tstr;
 }
 else
 {
  tstr='один из&nbsp;' + count;
  if(count%10==1 && count>20) tstr+='&nbsp;фильма';
  else tstr+='&nbsp;фильмов';
 }
 document.getElementById('moviesquery').style.display='inline';
 document.getElementById('genresquery').innerHTML='';
 document.getElementById('genreslnk').className='';
 document.getElementById('genresquery').style.display='none';
 clearSelect('genresvalue[]');
 getgenres='';
 if(count>0 && count<fullcount)
 {
  document.getElementById('moviesquery').innerHTML=tstr;
  document.getElementById('movieslnk').className='select';
 }
 else
 {
  document.getElementById('moviesquery').innerHTML='выберите фильм';
  document.getElementById('movieslnk').className='';
  getmovies='';
 }
}


function genresSubmit()
{
	var selectwindowBlocks = as.$('div.selectwindow');
 for (var i=0;i<selectwindowBlocks.length;i++){
	 selectwindowBlocks[i].style.display = 'none';
	}
 document.getElementById('genresselect').style.display='none';
 document.getElementById('afishawindow').style.display='none';
 textquery.splice(0,textquery.length);
 obj = document.getElementsByName('genresvalue[]');
 obj2 = document.getElementsByName('genresname[]');
 getgenres='';
 count=0;
 for(i=0;i<obj.length;i++) if(obj[i].checked)
 {
  textquery[textquery.length] = obj2[i].value;
  getgenres += obj[i].value + '|';
  count++;
 }
 tstr='';
 if(count<6)
 {
  for(i=0;i<textquery.length;i++)
  {
   if((tstr!='') && (i+1<textquery.length)) tstr+=', ';
   if((tstr!='') && (i+1==textquery.length)) tstr+=' или&nbsp;';
   tstr+=textquery[i];
  }
 }
 else
 {
  tstr='фильм в&nbsp;одном из&nbsp;' + count;
  if(count%10==1 && count>20) tstr+='&nbsp;жанра';
  else tstr+='&nbsp;жанров';
 }
 if(count>0 && count<obj.length)
 {
  document.getElementById('moviesquery').innerHTML='';
  document.getElementById('movieslnk').className='';
  document.getElementById('moviesquery').style.display='none';
  document.getElementById('genresquery').style.display='inline';
  document.getElementById('genresquery').innerHTML=tstr;
  document.getElementById('genreslnk').className='select';
  clearSelect('moviesvalue[]');
 }
 else
 {
  document.getElementById('genresquery').innerHTML='';
  document.getElementById('genreslnk').className='';
  document.getElementById('genresquery').style.display='none';
  document.getElementById('moviesquery').style.display='inline';
  document.getElementById('moviesquery').innerHTML='выберите фильм';
  document.getElementById('movieslnk').className='';
  getgenres='';
 }
 getmovies='';
}


function closeSelect(id)
{
var selectwindowBlocks = as.$('div.selectwindow');
 for (var i=0;i<selectwindowBlocks.length;i++){
	 selectwindowBlocks[i].style.display = 'none';
	}
 document.getElementById(id).style.display='none';
 document.getElementById('afishawindow').style.display='none';

var checks = document.getElementById(id).getElementsByTagName('input');
 for (var i=0;i<checks.length;i++){
	 checks[i].checked = false;
}
for (var i=0;i<checkedChecks.length;i++){
	checkedChecks[i].checked = true;
}
}

var checkedChecks = [];
function openSelect(id)
{
	var selectwindowBlocks = as.$('div.selectwindow');
 for (var i=0;i<selectwindowBlocks.length;i++){
	 selectwindowBlocks[i].style.display = 'none';
	}
 document.getElementById('afishawindow').style.display='block';
 document.getElementById(id).style.display='block';
	var checks = document.getElementById(id).getElementsByTagName('input');
	for (var i=0;i<checks.length;i++){
	if (checks[i].checked){checkedChecks.push(checks[i])}
}
}

function rememberCondition(id){
	
}

function clearSelect(name)
{
 obj = document.getElementsByName(name);
 for(i=0;i<obj.length;i++) obj[i].checked = false;
}


function none() { }


function rand()
{
  return(Math.floor(Math.random()*10000+1));
}


function getById(id)
{
 return document.getElementById(id);
}


function uploader_init ()
{
 if(!uploadsuccess) uploader = new clUploadData('/inc/afisha.php');
}


function uploader_go (id)
{
 uploader.upload(id);
}


function get_by_id(id)
{
	var itm = null;
	if (document.getElementById){
		itm = document.getElementById(id);
	}
	else if (document.all){
		itm = document.all[id];
	}
	else if (document.layers){
		itm = document.layers[id];
	}
	return itm;
}


function print_to_div(id, text)
{
	var d = get_by_id(id);
	if (d) {d.innerHTML = text;}
}


function clUploadData (thesrc)
{
 this.src = thesrc;
 this.src += "?";
 this.type = "text/javascript";
 this.oldScript  = document.createElement("SCRIPT");
 this.oldScript.type = this.type;
 this.callId = rand();
 document.body.appendChild(this.oldScript);
 this.upload = function(theparams)
 {
  var tParams = theparams || "";
  var newScript = document.createElement("SCRIPT");
  newScript.type = this.type;
  this.callId += 1;
  newScript.src  = this.src + "callid=" + String(this.callId) + "&" + tParams;
  document.body.replaceChild(newScript,this.oldScript);
  this.oldScript = newScript;
 }
 uploadsuccess=true;
}