var base_src="http://mt.hosted.pl/lab_aue/_data/txt/";
var base_src="http://http://www.put.poznan.pl/~deskur/WirtLabAUE/_data/txt/";
var base_src="http://localhost/~elektronika/web/_data/txt/";
var base_src="http://localhost/~elektronika/web/_data/txt/";
//var base_src="http://localhost/~AIDAN_SITE/szablon/";
//var base_src="http://mt.hosted.pl/dentes/_data/";

var base_src="http://digital-point.pl/tcp/_data/";
var base_src="http://www.thecheesepantry.com/tmp/_data/";
var base_src="http://tubeplayer.eu/tcp/_data/";
var base_src="http://127.0.0.1/~AIDAN_SITE/szablon/New_Data/_data/";
var base_src="/dev/_data/";


var base_src="http://localhost/aidan/_data/";
var base_src="/_data/";



if (window.XMLHttpRequest)		http_request1 = new XMLHttpRequest(); 
else if (window.ActiveXObject)	http_request1 = new ActiveXObject("Microsoft.XMLHTTP"); 

function set_page(site){
  get_page(site,'content_text',false,http_request1);
}
function set_page_txt(site){
  if(site==2){
    get_page(site+'&txt=1','td21',false,http_request1);
  }else if(site==4){
    get_page(site+'&txt=1','td21',false,http_request1);
  }else{
    get_page(site+'&txt=1','content_text',false,http_request1);
  }
}


function set_page_2(site, par, val){
	get_page(site+'?'+par+'='+val,'content',true,http_request1);
}

function get_page(src, trg_name, is_get, http_request){
	src='connect.php?site='+src;
	//if(src.indexOf('.php')==-1)src+='.php';
	var trg=document.getElementById(trg_name);
	trg.innerHTML = '<div style="text-align:center;margin-top:10px;"><img src="_data/img/loading.gif" alt="loading..."/></div>';
	if(is_get)var full_url=base_src+src+"&amp;rand="+Math.random();
	else var full_url=base_src+src+"&rand="+Math.random();
	
	//alert(full_url);
	if(http_request){
		http_request.open('GET', full_url, true);
		http_request.send(null);
		http_request.onreadystatechange = function(){
			if (http_request.readyState == 4){
				if (http_request.status == 200) {
          var response=http_request.responseText;
					//if(testchar>=0 && 1==0){
					var testchar=response.indexOf('JavaScriptExectueMe');
					if(testchar>=0){
            var new_arr=response.split('JavaScriptExectueMe');
            eval(new_arr[0]);
            response=new_arr[1];
					}					
					//eval('alert(123)');
					//alert(new_arr[0]);
					trg.innerHTML=response;
				}
				else{
					//trg.innerHTML='<div style="text-align:center; width:100%; font-weight:bold; margin-top:50px;">Connection error</div>';
				}				
			}
			else{
				//trg.innerHTML='<div style="text-align:center;margin-top:40px;margin-bottom:20px;"><img src="_data/img/loading.gif" alt="loading..."/></div>';
			}
		}
	} 
	//return false;
}


function otworz(adres, width, height) {
width=width+20;
height=height+5;
noweOkno = window.open('_data/applet/applet.php?applet='+adres+'&width='+width+'&height='+height, 'okienko', 'menubar=no, toolbar=no, location=no, scrollbars=no, resizable=no, status=no, width='+width+', height='+height);
}

var photo1='_data/img/img2.png';
var photo2='_data/img/img3.png';
var last_picture_open=1;

function picture(num, obj){
	var photo_src='';
	if(num==1)photo_src=photo1;
	if(num==2)photo_src=photo2;

	var d=new Date(); 
	var e=d.getTime()/1000; 
	//alert(e+' > '+last_picture_open);
	if(e>(last_picture_open+2)){
		window.status=photo_src;
		last_picture_open=e;
		
		
			// prep objects
	var objOverlay = document.getElementById('overlay');
	var objLightbox = document.getElementById('lightbox');
	var objCaption = document.getElementById('lightboxCaption');
	var objImage = document.getElementById('lightboxImage');
	var objLoadingImage = document.getElementById('loadingImage');
	var objLightboxDetails = document.getElementById('lightboxDetails');

	
	var arrayPageSize = getPageSize();
	var arrayPageScroll = getPageScroll();

	// center loadingImage if it exists
	if (objLoadingImage) {
		objLoadingImage.style.top = (arrayPageScroll[1] + ((arrayPageSize[3] - 35 - objLoadingImage.height) / 2) + 'px');
		objLoadingImage.style.left = (((arrayPageSize[0] - 20 - objLoadingImage.width) / 2) + 'px');
		objLoadingImage.style.display = 'block';
	}

	// set height of Overlay to take up whole page and show
	objOverlay.style.height = (arrayPageSize[1] + 'px');
	objOverlay.style.display = 'block';

	// preload image
	//var pre=new Image(photo_src);
	//pre.src=photo_src;
	//var ww=imgPreload.width;
	//var hh=imgPreload.height;
	//pre.onload=show_picture0(photo_src,ww,hh);
	
	var imgPreload = new Image();
	imgPreload.src=photo_src;
	var ww=imgPreload.width;
	var hh=imgPreload.height;
	imgPreload.onload=show_picture(photo_src,ww,hh);
//////////////////////////////////////////////////////////
//////////////////////////////////////////////////////////
	}
}


function show_picture0(photo_src,ww,hh){
	imgPreload = new Image();
	imgPreload.src=photo_src;
	var ww=imgPreload.width;
	var hh=imgPreload.height;
	imgPreload.onload=show_picture(photo_src,ww,hh);
}

function show_picture(photo_src,ww,hh){
	var objx = document.getElementById('loadingImage');
	objx.src=photo_src;
	objx.style.width = ww + 'px';
	objx.style.height = hh + 'px';
	objx.style.border = '3px solid #888';
}














function ajax_submit_form(form_id){
	if (window.XMLHttpRequest)		 http_request1 = new XMLHttpRequest(); 
	else if (window.ActiveXObject)	 http_request1 = new ActiveXObject("Microsoft.XMLHTTP"); 
	var form_div=document.getElementById(form_id+'_div');
	var form_div_stat=document.getElementById(form_id+'_div_stat');
	var src='';
	var empty_me=true;
	//var empty_newsletter=false;
	var form_len=document.forms[form_id].elements.length;

	for(var i=0; i<form_len; i++){
		if(document.forms[form_id].elements[i].name == false )continue;
		//if(document.forms[form_id].elements[i].name == 'newsletter_email')empty_newsletter=true;
		if(document.forms[form_id].elements[i].name == 'emp' && document.forms[form_id].elements[i].value == '0')empty_me=false;
		if(document.forms[form_id].elements[i].type=='radio' && !document.forms[form_id].elements[i].checked)continue;
		
		src+=document.forms[form_id].elements[i].name+'='+document.forms[form_id].elements[i].value+'&';
	}
	var full_url=base_src+'connect.php?'+src+'rand='+Math.random();
	//alert(full_url);
	
	
	
  //form_div.innerHTML='<div style="text-align:center;margin-top:40px;margin-bottom:00px;"><img src="_data/img/loading.gif" alt="loading..."/></div>';
	
	if(http_request1){
		http_request1.open('GET', full_url, true);
		http_request1.send(null);
			
		http_request1.onreadystatechange = function(){
			if (http_request1.readyState == 4){
				if (http_request1.status == 200) {
					var response=http_request1.responseText;
					//form_div.innerHTML=response;		
					form_div.innerHTML=response;		
					//if(empty_me && response.indexOf('<')==-1)setTimeout("empty_div(\'"+form_id+'_div'+"\');",3000);		
					//if(empty_newsletter)setTimeout("empty_div(\'"+form_id+'_div'+"\');",3000);			
				}else{
					//form_div.innerHTML='<div style="text-align:center; width:100%; font-weight:bold; margin-top:50px;">Error while connection</div>';
					///setTimeout("empty_div(\'"+form_id+'_div'+"\');",3000);
				}				
			}
			else{
				//form_div.innerHTML='<div style="text-align:center;margin-top:40px;margin-bottom:40px;"><img src="_data/img/loading.gif" alt="loading..."/></div>';
			}
		}
	}
}









function cleraLeft(){
  document.getElementById("bottom_left_img_id").innerHTML='';
}









function submit_form_cheese(){
	if (window.XMLHttpRequest)		 http_request1 = new XMLHttpRequest(); 
	else if (window.ActiveXObject)	 http_request1 = new ActiveXObject("Microsoft.XMLHTTP"); 

  var form_id='cheese_form_id';
	var src='';
	src+='style=' +document.forms[form_id].elements['search_style'].value+'&';
	src+='milk='  +document.forms[form_id].elements['search_milk'].value+'&';
	src+='country='   +document.forms[form_id].elements['search_country'].value+'&';
	src+='search='  +document.forms[form_id].elements['search_search_id'].value+'&';
	
	
/*
	src+='style=' +document.forms[form_id].elements[0].value+'&';
	src+='milk='  +document.forms[form_id].elements[1].value+'&';
	src+='rennet='  +document.forms[form_id].elements[2].value+'&';
	src+='producer='+document.forms[form_id].elements[3].value+'&';
	src+='country='   +document.forms[form_id].elements[4].value+'&';
	src+='maturing='  +document.forms[form_id].elements[5].value+'&';
	src+='search='  +document.forms[form_id].elements[6].value+'&';
*/
	var full_url='2&search_cheeses=1&'+src+'rand='+Math.random();
	//alert(full_url);
  //alert(document.forms[form_id].elements['search_milk'].value);
	
  //alert(full_url);
	set_page(full_url);
}



function submit_form_wine(){
	if (window.XMLHttpRequest)		 http_request1 = new XMLHttpRequest(); 
	else if (window.ActiveXObject)	 http_request1 = new ActiveXObject("Microsoft.XMLHTTP"); 

  var form_id='wine_form_id';
	var src='';
	src+='style=' +document.forms[form_id].elements['search_style'].value+'&';
	src+='colour='  +document.forms[form_id].elements['search_colour'].value+'&';
	src+='country='   +document.forms[form_id].elements['search_country'].value+'&';
	src+='search='  +document.forms[form_id].elements['search_search_id'].value+'&';

	var full_url='4&search_wines=1&'+src+'rand='+Math.random();
	set_page(full_url);
}





var style_bool=0;
var milk_bool=0;
var country_bool=0;


function clear_cheese_img(type){
  if(type=='style'){
    if(style_bool!=1)document.getElementById('style_img_1').className='bottom_menu_item_2';
    else document.getElementById('style_img_1').className='bottom_menu_item_2_active';
    if(style_bool!=2)document.getElementById('style_img_2').className='bottom_menu_item_2';
    else document.getElementById('style_img_2').className='bottom_menu_item_2_active';
    if(style_bool!=3)document.getElementById('style_img_3').className='bottom_menu_item_2';
    else document.getElementById('style_img_3').className='bottom_menu_item_2_active';
    if(style_bool!=4)document.getElementById('style_img_4').className='bottom_menu_item_2';
    else document.getElementById('style_img_4').className='bottom_menu_item_2_active';
    if(style_bool!=5)document.getElementById('style_img_5').className='bottom_menu_item_2';
    else document.getElementById('style_img_5').className='bottom_menu_item_2_active';
  }
  
  if(type=='milk'){
    if(milk_bool!=1)document.getElementById('milk_img_1').className='top_menu_item top_menu_item4';
    else document.getElementById('milk_img_1').className='top_menu_item_active top_menu_item4';
    if(milk_bool!=2)document.getElementById('milk_img_2').className='top_menu_item top_menu_item3';
    else document.getElementById('milk_img_2').className='top_menu_item_active top_menu_item3';
    if(milk_bool!=3)document.getElementById('milk_img_3').className='top_menu_item top_menu_item2';
    else document.getElementById('milk_img_3').className='top_menu_item_active top_menu_item2';
    if(milk_bool!=4)document.getElementById('milk_img_4').className='top_menu_item top_menu_item1';
    else document.getElementById('milk_img_4').className='top_menu_item_active top_menu_item1';
  }
  
  
  if(type=='country'){
    if(country_bool!=1)document.getElementById('country_img_1').className='bottom_menu_item';
    else document.getElementById('country_img_1').className='bottom_menu_item_active';
    if(country_bool!=2)document.getElementById('country_img_2').className='bottom_menu_item';
    else document.getElementById('country_img_2').className='bottom_menu_item_active';
    if(country_bool!=3)document.getElementById('country_img_3').className='bottom_menu_item';
    else document.getElementById('country_img_3').className='bottom_menu_item_active';
    if(country_bool!=4)document.getElementById('country_img_4').className='bottom_menu_item';
    else document.getElementById('country_img_4').className='bottom_menu_item_active';
    if(country_bool!=5)document.getElementById('country_img_5').className='bottom_menu_item';
    else document.getElementById('country_img_5').className='bottom_menu_item_active';
  }
}




function clear_wine_img(type){
  /*
  if(type=='style'){
    if(style_bool!=1)document.getElementById('style_img_1').className='bottom_menu_item_2';
    else document.getElementById('style_img_1').className='bottom_menu_item_2_active';
    if(style_bool!=2)document.getElementById('style_img_2').className='bottom_menu_item_2';
    else document.getElementById('style_img_2').className='bottom_menu_item_2_active';
    if(style_bool!=3)document.getElementById('style_img_3').className='bottom_menu_item_2';
    else document.getElementById('style_img_3').className='bottom_menu_item_2_active';
    if(style_bool!=4)document.getElementById('style_img_4').className='bottom_menu_item_2';
    else document.getElementById('style_img_4').className='bottom_menu_item_2_active';
    if(style_bool!=5)document.getElementById('style_img_5').className='bottom_menu_item_2';
    else document.getElementById('style_img_5').className='bottom_menu_item_2_active';
  }
  
  */
  if(type=='milk'){
    if(milk_bool!=1)document.getElementById('milk_img_1').className='top_menu_item';
    else document.getElementById('milk_img_1').className='top_menu_item_active';
    if(milk_bool!=2)document.getElementById('milk_img_2').className='top_menu_item';
    else document.getElementById('milk_img_2').className='top_menu_item_active';
    if(milk_bool!=3)document.getElementById('milk_img_3').className='top_menu_item';
    else document.getElementById('milk_img_3').className='top_menu_item_active';
    if(milk_bool!=4)document.getElementById('milk_img_4').className='top_menu_item';
    else document.getElementById('milk_img_4').className='top_menu_item_active';
    if(milk_bool!=5)document.getElementById('milk_img_5').className='top_menu_item';
    else document.getElementById('milk_img_5').className='top_menu_item_active';
  }
  
  if(type=='country'){
    if(country_bool!=1)document.getElementById('country_img_1').className='bottom_menu_item_3';
    else document.getElementById('country_img_1').className='bottom_menu_item_3_active';
    if(country_bool!=2)document.getElementById('country_img_2').className='bottom_menu_item_3';
    else document.getElementById('country_img_2').className='bottom_menu_item_3_active';
    if(country_bool!=3)document.getElementById('country_img_3').className='bottom_menu_item_3';
    else document.getElementById('country_img_3').className='bottom_menu_item_3_active';
    if(country_bool!=4)document.getElementById('country_img_4').className='bottom_menu_item_3';
    else document.getElementById('country_img_4').className='bottom_menu_item_3_active';
    if(country_bool!=5)document.getElementById('country_img_5').className='bottom_menu_item_3';
    else document.getElementById('country_img_5').className='bottom_menu_item_3_active';
    if(country_bool!=6)document.getElementById('country_img_6').className='bottom_menu_item_3';
    else document.getElementById('country_img_6').className='bottom_menu_item_3_active';
    if(country_bool!=7)document.getElementById('country_img_7').className='bottom_menu_item_3';
    else document.getElementById('country_img_7').className='bottom_menu_item_3_active';
    if(country_bool!=8)document.getElementById('country_img_8').className='bottom_menu_item_3';
    else document.getElementById('country_img_8').className='bottom_menu_item_3_active';
    if(country_bool!=9)document.getElementById('country_img_9').className='bottom_menu_item_3';
    else document.getElementById('country_img_9').className='bottom_menu_item_3_active';
    if(country_bool!=10)document.getElementById('country_img_10').className='bottom_menu_item_3';
    else document.getElementById('country_img_10').className='bottom_menu_item_3_active';
  }
}


function submit_form_cheese_show_all(){
	if (window.XMLHttpRequest)		 http_request1 = new XMLHttpRequest(); 
	else if (window.ActiveXObject)	 http_request1 = new ActiveXObject("Microsoft.XMLHTTP"); 

  var form_id='cheese_form_id';
	var src='';
	src+='style=0&';
	src+='milk=0&';
	src+='country=0&';
	src+='search=0&';

	var full_url='2&search_cheeses=1&'+src+'rand='+Math.random();
	set_page(full_url);

  style_bool=0;
  milk_bool=0;
  country_bool=0;
  clear_cheese_img('style');
  clear_cheese_img('milk');
  clear_cheese_img('country');

}


function submit_form_wine_show_all(){
	if (window.XMLHttpRequest)		 http_request1 = new XMLHttpRequest(); 
	else if (window.ActiveXObject)	 http_request1 = new ActiveXObject("Microsoft.XMLHTTP"); 

  var form_id='wine_form_id';
	var src='';
	src+='style=0&';
	src+='milk=0&';
	src+='country=0&';
	src+='search=0&';

	var full_url='4&search_wines=1&'+src+'rand='+Math.random();
	set_page(full_url);

  style_bool=0;
  milk_bool=0;
  country_bool=0;
  clear_wine_img('style');
  clear_wine_img('milk');
  clear_wine_img('country');

}








































function empty_div(div_name){
	if(document.getElementById(div_name))
		document.getElementById(div_name).style.display = 'none';
}

function empty_div2(div_name){
	if(document.getElementById(div_name))
		document.getElementById(div_name).innerHTML = '';
}






function get_page_ajax(src, trg_name, is_get, http_request){
	src='connect.php'+src;
	var full_url=base_src+src+"&rand="+Math.random();
	//full_url="http://127.0.0.1/~AIDAN_SITE/szablon/_data/connect.php?type=cheese&cid=2&rand=0.14323";
	var trg=document.getElementById('overlay');
	trg.style.display='block';
	
	if(http_request){
		http_request.open('GET', full_url, true);
		http_request.send(null);
		http_request.onreadystatechange = function(){
			if (http_request.readyState == 4){
				if (http_request.status == 200) {
					var response=http_request.responseText;
					trg.innerHTML=response;
				}
				else{
					trg.innerHTML='<div style="text-align:center; width:100%; font-weight:bold; margin-top:50px;">Błąd podczas połączenia</div>';
				}				
			}
			else{
				trg.innerHTML='<div style="text-align:center;margin-top:310px;margin-bottom:40px;"><img src="_data/img/loading.gif" alt="loading..."/></div>';
			}
		}
	} 
}





function put_content(div_id,href){//site=vote
  //div_id=overlay_txtalert();
	//var div_pointer=document.getElementById(div_id);
	//div_pointer.innerHTML='<div style="text-align:center;margin-top:40px;margin-bottom:40px;">'+
  //                      '<img src="_data/img/loading.gif" alt="loading..."/>xxx</div>';
  //var getYval=getY()+30;
  //document.getElementById('overlay_txt').style.top=getYval+'px';
  get_page_ajax(href, div_id, true, http_request1);
                        
  return false;                        
}







function closeMe(){
  document.getElementById('overlay').style.display='none'; 
  return false;
}



 
function getY(){
	var yScroll;

	 if (self.pageYOffset) {
		yScroll = self.pageYOffset;
	} else if (document.documentElement && document.documentElement.scrollTop){	 // Explorer 6 Strict
		yScroll = document.documentElement.scrollTop;
	} else if (document.body) {// all other Explorers
		yScroll = document.body.scrollTop;
	}

	return yScroll;
}








function getPageSize(){
	
	var xScroll, yScroll;
	
	if (window.innerHeight && window.scrollMaxY) {	
		xScroll = document.body.scrollWidth;
		yScroll = window.innerHeight + window.scrollMaxY;
	} else if (document.body.scrollHeight > document.body.offsetHeight){ // all but Explorer Mac
		xScroll = document.body.scrollWidth;
		yScroll = document.body.scrollHeight;
	} else { // Explorer Mac...would also work in Explorer 6 Strict, Mozilla and Safari
		xScroll = document.body.offsetWidth;
		yScroll = document.body.offsetHeight;
	}
	
	var windowWidth, windowHeight;
	if (self.innerHeight) {	// all except Explorer
		windowWidth = self.innerWidth;
		windowHeight = self.innerHeight;
	} else if (document.documentElement && document.documentElement.clientHeight) { // Explorer 6 Strict Mode
		windowWidth = document.documentElement.clientWidth;
		windowHeight = document.documentElement.clientHeight;
	} else if (document.body) { // other Explorers
		windowWidth = document.body.clientWidth;
		windowHeight = document.body.clientHeight;
	}	
	
	// for small pages with total height less then height of the viewport
	if(yScroll < windowHeight){
		pageHeight = windowHeight;
	} else { 
		pageHeight = yScroll;
	}

	// for small pages with total width less then width of the viewport
	if(xScroll < windowWidth){	
		pageWidth = windowWidth;
	} else {
		pageWidth = xScroll;
	}


	arrayPageSize = new Array(pageWidth,pageHeight,windowWidth,windowHeight) 
	return arrayPageSize;
}



var overlay_lock_val=0;
function overlay_lock(tmp){
  if(tmp==1)overlay_lock_val+=2;
  else overlay_lock_val-=1;
  //overlay_lock_val=tmp;
}

function overlay(href){
  var objOverlay = document.getElementById('overlay');
  //var objOverlay_txt = document.getElementById('overlay_txt');
  var objBody = document.getElementsByTagName("body").item(0);
	objOverlay.style.position = 'absolute';
	objOverlay.style.top = '0';
	objOverlay.style.left = '0';
	objOverlay.style.zIndex = '100';
	objOverlay.style.width = '100%';
	
	//objOverlay.onclick = function () {objOverlay.innerHTML='';objOverlay.style.display='none'; return false;}
	objOverlay.onclick = function () {
    //if(overlay_lock_val==0){
      objOverlay.innerHTML='';
      objOverlay.style.display='none'; 
      return false; 
    //}else overlay_lock(0);
  }
	objBody.insertBefore(objOverlay, objBody.firstChild);
	var arrayPageSize = getPageSize();
	objOverlay.style.height = (arrayPageSize[1] + 'px');
	objOverlay.style.display = 'block';
	//objOverlay_txt.style.display = 'block';
	put_content('overlay_txt',href);
	return false;
}


