	var kuva_esilla;
    var kuvia_yhteensa;

	function suljePortfolio(){
	  	if(document.getElementById('kelluva_portfolio')){
		    document.getElementById('kelluva_portfolio').style.display='none';
		    
		    var kuvat = document.getElementById('portfolio_kuvat').getElementsByTagName('img');
		    
		    for (var i=0; i<kuvat.length; i++){
			  	kuvat[i].style.display='none';
			}//end for
		}//end if
	}//end function


	function naytaLinkki(id,sty){
	  	if(document.getElementById(id)){
		    document.getElementById(id).style.display=sty;
		}//end if
	}//end function

	function vaihdaCursor(tyyppi){
		if(tyyppi=='hand'){
		  	document.body.style.cursor='pointer';
		  	document.body.style.cursor='hand';
		}else{
  		  	document.body.style.cursor='default';
		}//end if 
	}//end function
	
    
    function naytaKuva(luku){   
        document.getElementById('kuva_' + kuva_esilla).style.display='none';
        
        kuva_esilla+=parseInt(luku);

		

        if(kuva_esilla==0){ kuva_esilla=kuvia_yhteensa; }
        if(kuva_esilla>kuvia_yhteensa){ kuva_esilla=1; }

        document.getElementById('kuva_' + kuva_esilla).style.display='';

/*
        var img = new Image();
        img =document.getElementById('kuva_' + kuva_esilla);
        
        var leveys  = img.width + 200;
        var korkeus = img.height + 380;
        
        if(leveys<600){ leveys=600; }
        if(korkeus<500){ korkeus=500; }

        window.resizeTo(leveys, korkeus);
*/
    }//end function
   

	function avaaSivu(tyyppi,id,kuva,url){
        var img = new Image();
        img.src=url;
        
        var leveys  = img.width + 200;
        var korkeus = img.height + 380;
        
        if(leveys<600){ leveys=600; }
        if(korkeus<500){ korkeus=500; }
        
        var vasen = (screen.width - leveys)/2;


        var win = window.open('kuva.php?tyyppi=' + escape(tyyppi) + '&id=' + escape(id) + '&kuva=' + escape(kuva),
          'popup',
          'width=' + leveys + ', height=' + korkeus + ', ' +
          'screenX=' + vasen + ', left=' + vasen + ', ' +
          'screenY=50, top=50, ' +
          'location=no, menubar=no, ' +
          'status=no, toolbar=no, scrollbars=no, resizable=no');

        win.resizeTo(leveys, korkeus);
        win.focus();
    }//end function


    function vaihdaKuva(url,id){
        var img     = document.getElementById(id);
        img.setAttribute('src', url);
    }//end function

    function handleGalleria(){
        if (xmlhttp.readyState == 4) {
            /* If the data was retrieved successfully */
       	    if (xmlhttp.status == 200){
                var xmlDocument = xmlhttp.responseXML;
                var kuvat = xmlDocument.getElementsByTagName('kuva');
				
				document.getElementById('kelluva_kuvaosio').innerHTML="";

                var table = document.createElement('table');
                var tbody = document.createElement('tbody');
                                
                table.appendChild(tbody);
                table.className="leveys";

                tr  = document.createElement('tr');
                td  = document.createElement('td');

				tbody.appendChild(tr);
				tr.appendChild(td);

				tbody.setAttribute('id','portfolio_kuvat');
				
                for(i=0; i<kuvat.length; i++){
                    source  = kuvat[i].getAttribute('src');
                    id      = kuvat[i].getAttribute('id');
                    
                    img = document.createElement('img');
                    
                    img.setAttribute('id',id);
                    img.setAttribute('src',source);
                    img.setAttribute('title','');
                    img.setAttribute('alt','');
                    img.className="valkoisetKehykset";
                    
                    img.style.display='none';
                    
                    td.appendChild(img);                    
                }//end for
                                
				var leveys	= 750;
				var yla		= 50;
				var vasen = (screen.width - leveys)/2;
				
                document.getElementById('kelluva_kuvaosio').appendChild(table);
                
				document.getElementById('kelluva_portfolio').style.top= yla + 'px';    
				document.getElementById('kelluva_portfolio').style.left = vasen + 'px'; 
				
				kuvia_yhteensa=kuvat.length;
				            
            }//end if
        }//end if
    }//end function



    function handleUutinen(){
        if (xmlhttp.readyState == 4) {
            /* If the data was retrieved successfully */
       	    if (xmlhttp.status == 200){
                var xmlDocument = xmlhttp.responseXML;
                var kuvat = xmlDocument.getElementsByTagName('kuva');
				
				document.getElementById('kelluva_kuvaosio').innerHTML="";

                var table = document.createElement('table');
                var tbody = document.createElement('tbody');
                                
                table.appendChild(tbody);
                table.className="leveys";

                tr  = document.createElement('tr');
                td  = document.createElement('td');

				tbody.appendChild(tr);
				tr.appendChild(td);

				tbody.setAttribute('id','portfolio_kuvat');
				
                for(i=0; i<kuvat.length; i++){
                    source  = kuvat[i].getAttribute('src');
                    id      = kuvat[i].getAttribute('id');
                    
                    img = document.createElement('img');
                    
                    img.setAttribute('id',id);
                    img.setAttribute('src',source);
                    img.setAttribute('title','');
                    img.setAttribute('alt','');
                    img.className="valkoisetKehykset";
                    
                    img.style.display='none';
                    
                    td.appendChild(img);                    
                }//end for
                                
				var leveys	= 750;
				var yla		= 30;
				var vasen = (screen.width - leveys)/2;
				
                document.getElementById('kelluva_kuvaosio').appendChild(table);
                
				document.getElementById('kelluva_portfolio').style.top= yla + 'px';    
				document.getElementById('kelluva_portfolio').style.left = vasen + 'px'; 
				
				kuvia_yhteensa=kuvat.length;
				     
				avaaGalleriakuva(1,'uutiskuva');
					        
            }//end if
        }//end if
    }//end function
		

	function sulje(id){
	  	for(i=0; i<kuvia_yhteensa; i++){
		    document.getElementById('kuva_' + i).style.display='none';
		}//end for
	  
	    document.getElementById(id).style.display='none';
	}//end function
    
    
    function avaaGalleriakuva(nro){
      	var alku;
		kuva_esilla=parseInt(nro);
		
		if(arguments[1]){
	      	if(document.getElementById('kuva_' + nro)){
			  	alku = arguments[1];
      	
		      	var taulu	= findPos(document.getElementById(alku + '_' + nro));
			    var vasen 	= (screen.width-750)/2;
			    var yla 	= taulu[1] - 270;
			    
			    if(yla<0){ yla=50; }

				document.getElementById('kelluva_portfolio').style.top= yla + 'px';    
				document.getElementById('kelluva_portfolio').style.left = vasen + 'px'; 

			  	document.getElementById('kelluva_portfolio').style.display='';		  	
			  	document.getElementById('kuva_' + nro).style.display='';
			}//end if
		}else{
		  	alku = 'galleriakuva';
      	
	      	if(document.getElementById('kuva_' + nro)){
		      	var taulu	= findPos(document.getElementById(alku + '_' + nro));
			    var vasen 	= taulu[0] - 330;
			    var yla 	= taulu[1] - 500;
			    
			    if(yla<0){ yla=0; }
			    
			    document.getElementById('kelluva_portfolio').style.left = vasen + 'px';
			    document.getElementById('kelluva_portfolio').style.top  = yla + 'px';
			  	document.getElementById('kelluva_portfolio').style.display='';		  	
			  	document.getElementById('kuva_' + nro).style.display='';
			}//end if
		}//end if
		
	}//end function
    


function luoTilausrivi(kuvaID,kauppaID){
  	if(!document.getElementById('tuote_' + kuvaID).checked || document.getElementById('tuotekpl_' + kuvaID).value==""){
		//Poistetaan tilausrivi
		if(document.getElementById('tilausrivi_' + kuvaID)){
		  	var pois = document.getElementById('tilausrivi_' + kuvaID);
		  	pois.parentNode.removeChild(pois);
		  	
		}//end if
	}//end if

	var param="kauppaID=" + kauppaID;

	var chk = document.getElementsByTagName('input');
	
	for(i=0; i<chk.length; i++){
	  	if(chk[i].type=="checkbox" && chk[i].checked){
			var id 		= chk[i].getAttribute('id');
			var finalID = id.substring(6,id.length);
			var kpl 	= document.getElementById('tuotekpl_' + finalID).value;

			if(is_numeric(kpl)){
				if(param!=""){ param = param + "&"; }
				param = param + 'kuva[' + finalID + ']=' + escape(document.getElementById('tuotekpl_' + finalID).value);
			}//end if
		}//end if
	}//end for

  	teeAjaxKutsu('ajax/tilaus.php', param, handleTilausrivi);  
}//end function



function handleTilausrivi(){
    if (xmlhttp.readyState == 4) {
        /* If the data was retrieved successfully */
   	    if (xmlhttp.status == 200){
            var xmlDocument = xmlhttp.responseXML;
            var tuote = xmlDocument.getElementsByTagName('tuote');
            var summa = xmlDocument.getElementsByTagName('summa');

			if(tuote.length==0){
			  	document.getElementById('tilauksen_summataulu').style.display="none";
			  	document.getElementById('tilaustuotteet').style.display="none";			  
			  	document.getElementById('tilausotsikko').style.display="none";			  
			}else{
			  	document.getElementById('tilauksen_summataulu').style.display="";
			  	document.getElementById('tilaustuotteet').style.display="";
			  	document.getElementById('tilausotsikko').style.display="";			  
			  	
				var riveja = document.getElementById('tilaustuotteet').rows.length;
			
				for(i=0; i<tuote.length; i++){
				  	id 			= tuote[i].getAttribute('id');
				  	tunniste 	= tuote[i].getAttribute('tunniste');
				  	hinta 		= tuote[i].getAttribute('hinta');
				  	kpl 		= tuote[i].getAttribute('kpl');
				  	rivisumma 	= tuote[i].getAttribute('rivisumma');
					
					if(document.getElementById('tilausrivi_' + id)){
						//Päivitys
						asetaTeksti(document.getElementById('tilausrivikpl_' + id),kpl);
						asetaTeksti(document.getElementById('tilausrivisumma_' + id),rivisumma + " \u20AC");						
					}else{
					  	//Uusi rivi
					  	var uusi_rivi 	= document.getElementById('tilaustuotteet').insertRow(riveja);
						var td0			= uusi_rivi.insertCell(0);
						var td1			= uusi_rivi.insertCell(1);
						var td2			= uusi_rivi.insertCell(2);
						var td3			= uusi_rivi.insertCell(3);
				
						uusi_rivi.setAttribute('id','tilausrivi_' + id);
						
						asetaTeksti(td0,tunniste );
						asetaTeksti(td1,hinta + " \u20AC");
						asetaTeksti(td2,kpl);
						asetaTeksti(td3,rivisumma + " \u20AC");
						
						td1.className='tilaussolu';
						td2.className='tilaussolu';
						td3.className='tilaussolu';
						
						td2.setAttribute('id','tilausrivikpl_' + id);
						td3.setAttribute('id','tilausrivisumma_' + id);
					}//end if
				}//end for
				
				
				asetaTeksti(document.getElementById('tilauksen_summa'),summa[0].getAttribute('sum') + " \u20AC");
				asetaTeksti(document.getElementById('toimituskulut_summa'),summa[0].getAttribute('toim') + " \u20AC");
				asetaTeksti(document.getElementById('yhteensa_summa'),summa[0].getAttribute('yht') + " \u20AC");
			}//end if
	
		}//end if
	}//end if
}//end function






    function haeGalleria(id){      	
      	teeAjaxKutsu('ajax/galleria.php','id=' + escape(id),handleGalleria);  
    }//end function

    function haeUutinen(id){      	
      	teeAjaxKutsu('ajax/uutinen.php','id=' + escape(id),handleUutinen);  
    }//end function

function teeAjaxKutsu(url,parameters,funktio){
	if (xmlhttp!=null && xmlhttp.readyState !=0 && xmlhttp.readyState !=4) {
	 	//alert("edellinen menossa");
	}else{	
	    xmlhttp.open("POST", url, true);  
	    xmlhttp.onreadystatechange = funktio;
		xmlhttp.setRequestHeader("Content-type", "application/x-www-form-urlencoded");
		xmlhttp.send(parameters);
  	} //end if	
}//end function


function haeRaportti(id){
	teeAjaxKutsu('ajax/haeRaportti.php','id=' + escape(id),handleRaportti);  
}//end function


    function avaaKuva(url,leveys,korkeus){
        var win = window.open(url,
          'popup',
          'width=' + leveys + ', height=' + korkeus + ', ' +
          'location=no, menubar=no, ' +
          'status=no, toolbar=no, scrollbars=yes, resizable=no');

        win.resizeTo(leveys, korkeus);
        win.focus();
    }//end if

    function vaihdaLuokka(otus,luokka){
        document.getElementById(otus).className=luokka;
    }//end function
    
    function vaihdaLuokkaOlio(otus,luokka){
        if(otus.className!='ef_galleria_pikkukuva_painettu'){
            otus.className=luokka;
        }//end if
    }//end function


    function asetaTeksti(otus,arvo){
        if(IEselain){
            otus.innerText=arvo;
        }else{
            otus.textContent=arvo;
        }//end if
    }//end if
