﻿function show_pic(dir, pic_id) {
	w=screen.availWidth/2-350;
	h=screen.availHeight/2-350;

	window.open("show.php?dir="+dir+"&pic_id="+pic_id,"","menubar=no, scrollbars=yes, width=700, height=700, top="+h+", left="+w+", resizable=yes")
	}

function show_big(e, pic_id) {
  if (zoom==0) return;
  if( !e ) {
    if( window.event ) {
      e = window.event;
    } else {
      return;
    }
  }
  if( typeof( e.pageX ) == 'number' ) {
    var xcoord = e.pageX;
    var ycoord = e.pageY;
  } else if( typeof( e.clientX ) == 'number' ) {
    var xcoord = e.clientX;
    var ycoord = e.clientY;
    var badOldBrowser = ( window.navigator.userAgent.indexOf( 'Opera' ) + 1 ) ||
     ( window.ScriptEngine && ScriptEngine().indexOf( 'InScript' ) + 1 ) ||
     ( navigator.vendor == 'KDE' )
    if( !badOldBrowser ) {
      if( document.body && ( document.body.scrollLeft || document.body.scrollTop ) ) {
          xcoord += document.body.scrollLeft;
        ycoord += document.body.scrollTop;
      } else if( document.documentElement && ( document.documentElement.scrollLeft || document.documentElement.scrollTop ) ) {
         xcoord += document.documentElement.scrollLeft;
        ycoord += document.documentElement.scrollTop;
      }
    }
  } else {
    return;
  }
//	window.alert('Mouse coordinates are ('+xcoord+','+ycoord+')');

	pic_div=document.getElementById("div_pic");
	picture=document.getElementById("big_pic");
	
    picture.src=dir+"/thumbs/"+pictures[pic_id]
    
    pic_div.style.top=ycoord-picture.height-35+"px";
    pic_div.style.left=xcoord+15+"px";


    if (picture.complete) pic_div.style.display="block";
    
}


	
function hide_big() {
    document.getElementById("div_pic").style.display="none";
}

function zoom_switch() {
	if(zoom==1) {
		zoom=0;
		document.getElementById("z_switcher").innerHTML="Zapnout lupu";
	} else {
		zoom=1;
		document.getElementById("z_switcher").innerHTML="Vypnout lupu";
	}
}

var play=0

        function next_pic(){
            pic_id++;
            if (pic_id==pictures.length){pic_id=0};
            change_pic();
        }

        function prev_pic(){
            pic_id--;
            if (pic_id==-1){pic_id=pictures.length-1};
	    change_pic()
	}

	function first_pic() {
		pic_id=0;
	 	change_pic();
	}

	function last_pic() {
		pic_id=pictures.length-1;
	 	change_pic();
	}

	function change_pic(){
            source=dir+pictures[pic_id];
            document.images.picture.src=source;
	    document.getElementById("pic_no").innerHTML=pic_id+1;
	    document.getElementById("pic_name").innerHTML=pictures[pic_id];
		
            }

	

         function slide_show() {
           if (play==0) {
             play=1
	     document.images.slide.src="img/stop.gif";
             timeoutID=setInterval("next_pic()", 3000)
             }
           else {
             play=0
	     document.images.slide.src="img/play.gif";
             clearTimeout(timeoutID)
             }
            }

function check_select (formular) {
	if (formular[0].value!="#") return true;
	else {alert ("Vyber galerii!"); return false;}
	}

function test_order(obj) {
	err=false;
	var zprava="";
	for (i=0; i<pics; i++) {
		if (obj[i].value=="") obj[i].value=0;
		else if (isNaN(obj[i].value)) {
			err=true;
			obj[i].style.backgroundColor="red";
		} else obj[i].style.backgroundColor="white";
		
	}
	if (err==true) {
		alert ("Pozor! U některých fotek není zadané správné číslo");
		return false;
	} else return true;
}

function count_order(cena1, cena2) {

	obj=document.getElementById('order_form');
	if (test_order(obj)) {
		suma=0
		for (i=0; i<pics; i++) {
			val=parseInt(obj[i].value);
			suma+=val;	
		}

	if (document.getElementById('10x15').checked==true) cena=cena1;
	else cena=cena2;


	
	document.getElementById('count').innerHTML=suma;
	document.getElementById('price').innerHTML=suma*cena;
	}
}

function disable_address(obj) {
	adr=document.getElementById('address');
	mailPrice=document.getElementById('mail_price');
	adrTit=document.getElementById('dis');
	if (obj.value=="postou") {
			adr.disabled=false;
			adrTit.style.color="black";
			mailPrice.style.display="inline"
			}
	else {adr.disabled=true;
			adrTit.style.color="gray";
			mailPrice.style.display="none"
		}
}

function disable_cdprice(obj) {
	cdPrice=document.getElementById('cd_price');
	if (obj.checked==true) {
			cdPrice.style.display="inline"
			}
	else {
			cdPrice.style.display="none"
		}
}

// ----------------------------------AJAX zatim nevyuzito----------------------------------------------
var xmlHttp = createXmlHttpRequestObject(); 


function createXmlHttpRequestObject() {	
  var xmlHttp;
  if(window.ActiveXObject) {
    try
    {
      xmlHttp = new ActiveXObject("Microsoft.XMLHTTP");
    }
    catch (e) 
    {
      xmlHttp = false;
    }
  } else {
    try 
    {
      xmlHttp = new XMLHttpRequest();
    }
    catch (e) 
    {
      xmlHttp = false;
    }
  }
  if (!xmlHttp)
 
    alert("Error creating the XMLHttpRequest object.");
  else 
    return xmlHttp;
}

 
function process() {
  if (xmlHttp.readyState == 4 || xmlHttp.readyState == 0)
  {
    name = encodeURIComponent(document.getElementById("myName").value);
    xmlHttp.open("GET", "quickstart.php?name=" + name, true);  
    xmlHttp.onreadystatechange = handleServerResponse;
    xmlHttp.send(null);
  }
  else
    setTimeout('process()', 1000);
  }


function handleServerResponse() 
{
  if (xmlHttp.readyState == 4) 
  {

    if (xmlHttp.status == 200) 
    {

      xmlResponse = xmlHttp.responseXML;
      xmlDocumentElement = xmlResponse.documentElement;
      helloMessage = xmlDocumentElement.firstChild.data;
      document.getElementById("divMessage").innerHTML = helloMessage;
      setTimeout('process()', 1000);
    } 
    else 
    {
      alert("There was a problem accessing the server: " + xmlHttp.statusText);
    }
  }
}

