var GLCodice=null;
var GLTitolo=null;


function OnImageZoom ( ItemName ) {
    var url = '/image_zoom.php?ImageName=' + GLCodice + '&ImageUrl=' + document.getElementById(ItemName).src + '&ImageTitle=' + GLTitolo;
    window.open(url, '', 'toolbar=no, location=no, status=no, menubar=no, scrollbars=no, resizable=no');
    }

function ZoomImage ( ItemId, Codice, Titolo ) {
    GLCodice = Codice;
    GLTitolo = Titolo;
    document.getElementById("MainImage").src = document.getElementById(ItemId).src;
    }

function OpenGallery ( codice, lista_foto, materiale, lavorazione, dimensioni, prezzo ) {
    var new_page = '/get_images_gallery.php?Codice=' + codice + '&Foto=' + lista_foto + '&Materiale=' + materiale + '&Lavorazione=' + lavorazione + '&Dimensioni=' + dimensioni + '&Prezzo=' + prezzo;
    // location.href = new_page;
    ShowUrlOnDiv(new_page, 'divGallery');    
    obj = document.getElementById("page");
    if (obj) obj.style.display='none';
    location.href='#divGalleryTop';
    }
    
function CloseGallery() {
    obj = document.getElementById("divGallery");
    if (obj) obj.style.display='none';
    obj = document.getElementById("page");
    if (obj) obj.style.display='';    
    }

function OpenBid ( codice ) {
    var new_page = '/bid_modify.php?Codice=' + codice;
    location.href = new_page;
    }

function OpenOrder ( codice, id ) {
    var new_page = '/order_modify.php?';
    if (codice) {
        new_page += 'Codice=' + codice;
        }
    if (id) {
        new_page += '&Id=' + id;
        }
    location.href = new_page;
    }
   
function CheckBidStatus ( id_offerta ) {
    var new_page = '/bid_status_check.php?IDOfferta=' + id_offerta;
    location.href = new_page;
    }
       
function CheckOrderStatus ( id_ordine ) {
    // var new_page = '/order_status_check.php?IDOrdine=' + id_ordine;
    // location.href = new_page;
    }

function SendContact ( title ) {    
    var new_page = 'mailto:ideedilana@tiscali.it?Subject='+title;
    location.href = new_page;
    }

function OnMouseOver ( Obj ) {    
    if (Obj) {
        Obj.style.borderLeftWidth='2px';
        Obj.style.borderLeftColor='#c2e200';
        Obj.style.borderTopWidth='2px';
        Obj.style.borderTopColor='#c2e200';
        Obj.style.borderRightWidth='2px';
        Obj.style.borderRightColor='#AECD01';
        Obj.style.borderBottomWidth='2px';
        Obj.style.borderBottomColor='#AECD01';
        document.body.style.cursor='hand';
        }
    }

    
function OnMouseOut ( Obj ) {    
    if (Obj) {
        Obj.style.borderLeftWidth='2px';
        Obj.style.borderTopWidth='2px';
        Obj.style.borderRightWidth='2px';
        Obj.style.borderBottomWidth='2px';
        Obj.style.borderLeftColor='transparent';
        Obj.style.borderTopColor='transparent';
        Obj.style.borderRightColor='transparent';
        Obj.style.borderBottomColor='transparent';
        document.body.style.cursor='';
        }
    }



function OnCursorOver ( Obj ) {    
    if (Obj) {
        document.body.style.cursor='hand';
        }
    }

    
function OnCursorOut ( Obj ) {    
    if (Obj) {
        document.body.style.cursor='';
        }
    }

    

var xmlhttp = new XMLHttpRequest();
var xmlhttp_busy = false;

function debug_handler () {
    http_result=null;
    if (xmlhttp) {
        alert('readyState:' + xmlhttp.readyState);
        if (xmlhttp.readyState == 4 && xmlhttp.status == 200) {
            if (xmlhttp.responseText) {
                http_result=xmlhttp.responseText;
                // alert(xmlhttp.responseText);
                // location.href='manage_games.php#my_challenges';
                }                    
            }
        }
    }
    
function ShowUrlOnDiv(url, divName) {
    if (xmlhttp_busy) return;
    object = document.getElementById(divName); 
    if (object) {
        if (object.style.display=='none') {
            object.style.display='';
            }
        if (url) {
            if (xmlhttp) {
                xmlhttp_busy=true;
                http_result=null; 
                xmlhttp.onreadystatechange = null;                        
                xmlhttp.open("GET",url, false);
                xmlhttp.setRequestHeader( "If-Modified-Since", "Sat, 1 Jan 2000 00:00:00 GMT" );
                xmlhttp.send(null);
                if (xmlhttp.status == 200) {
                    div_obj=document.getElementById(divName); 
                    if (div_obj) {
                        div_obj.innerHTML=xmlhttp.responseText;
                        }
                    } else {
                    alert ('server error : '+xmlhttp.status);
                    }
                xmlhttp_busy=false;
                }
            }
        }
    }


    
    
function ShowImageOnDiv(imageURL, divName) {
    object = document.getElementById(divName); 
    if (object) {
        if (object.style.display=='none') {
            object.style.display='';
            if (imageURL) {
                var Code = '<img alt="" src="' +imageURL+'" style="border:1px solid gray; "/>';
                object.innerHTML=Code;
                }
            }
        }
    }

function CloseImageOnDiv(object) {
    if (object) {
        object.style.display='none';
        }
    }





var GLIsFiltering = false;
var GLTimerRunning = false;
var GLTimerState=0;
var GLLoopTime=30;
var GLTimerCounter=0;

var GLDivArray= new Array( 'ListaArticoliRighe' );
var GLNumDiv=GLDivArray.length;
var GLStepArticles=1;
var GLCurArticles=0;
var GLNumArticles=13;
var GLStartY = 0;
var GLHeight = 114.0;
var GLTransictionCounter=0;
var GLTransictionArray=new Array( 0, 0, 0, 0, 1, 2, 3, 5, 5, 10, 10, 15, 20, 15, 10, 6, 5, 5, 3, 3, 2, 1, 0, 0, 0, 0);
var GLNumTransiction=25.0;
var GLVersus = 1;
var GLMode = '';



function TimerFunc() {

    GLTimerRunning = true;
    if (GLTimerState==0) {
        // Init
        for (i=0; i<GLNumDiv; i++) {
            var div1 = document.getElementById(GLDivArray[i]); 
            if (div1) {
                // div1.style.maringTop='5px';
                // div1.style.paddingTop='5px';
                // div1.style.height=GLHeight+'px';
                }
            }
        
        GLStartY = 0;
        GLTimerCounter++;            
        if (GLTimerCounter >= GLLoopTime) {
            GLTimerCounter=0;
            GLTimerState=1;
            }
        }
        
        
   
    if (GLTimerState==1) {
        // Inizio transizione
        var div1 = document.getElementById(GLDivArray[0]);
        if (div1) {
            if (GLMode=='Gallery') {
                div1.scrollTop=GLStartY;
                }
            // div1.style.display="";
            // div2.style.display="";
            // alert(div1.scrollTop);
            }
        
        GLTransictionCounter=0;
        GLTimerState=2;
        }

    if (GLTimerState==2) {
        // Transizione
        var div1 = document.getElementById(GLDivArray[0]); 
        // GLStartY += GLHeight / GLNumTransiction;
        GLStartY += GLTransictionArray[GLTransictionCounter] * GLVersus;
        if (div1) {
            div1.scrollTop = GLStartY;
            // alert('TimerFunc:'+GLTimerState+'\n\ndiv1.scrollTop:'+div1.scrollTop);
            }
        GLTransictionCounter++;
        if (GLTransictionCounter>=GLNumTransiction) {
            GLTransictionCounter=0;
            GLTimerState=3;
            }
        } 
        
    if (GLTimerState==3) {
        // Fine transizione
        /*
        var div1 = document.getElementById(GLDivArray[0]); 
        if (div1) {
            div1.style.top = '0px';
            div1.style.display="none";
            }
        */
        GLTimerState=4;
        }
        
    if (GLTimerState==4) {
        GLTimerCounter++;            
        if (GLTimerCounter >= GLLoopTime) {
            // GLStartY = 0;
            GLTimerCounter=0;
            GLTimerState=1;
            
            GLCurArticles=GLCurArticles+GLStepArticles;
            if (GLCurArticles>=GLNumArticles) {
                GLVersus = GLVersus * -1.0;
                GLStepArticles = GLStepArticles * -1;
                GLCurArticles=GLCurArticles+GLStepArticles;
                } else if (GLCurArticles<0) {
                GLVersus = GLVersus * -1.0;
                GLStepArticles = GLStepArticles * -1;
                GLCurArticles=GLCurArticles+GLStepArticles;
                }
            
                /*
                var div1 = document.getElementById(GLDivArray[GLNumDiv-1]);
                if (div1) {
                    div1.style.display="none";
                    div1.style.top="0px";
                    }
                */

            // blendimage('blenddiv', 'blendimage', GLDivArray[0], 1000);
            // blendimage('blenddiv2', 'blendimage2', GLDivArray2[0], 1000);
            }
        }
    }

    

function OnLoadFunc () {
    // alert('OnLoadFunc');
    PlayArticles('Gallery');
    }

function PlayArticles (Mode) {
    if (GLMode != Mode) {
        GLMode=Mode;
        if (GLMode=='Gallery') {
            var div1 = document.getElementById(GLDivArray[0]); 
            if (div1) {
                div1.style.height='475px';
                div1.style.overflow='hidden';
                }
            GLTimerState=0;
            if (!GLTimerRunning) setInterval("TimerFunc()",75);
            } else {
            GLTimerState=0;
            var div1 = document.getElementById(GLDivArray[0]); 
            if (div1) {
                div1.style.height='';
                div1.style.overflow='';
                }
            if (GLIsFiltering) {
                ShowUrlOnDiv('leggi_articoli.php','div_articles');
                GLIsFiltering = false;
                }
            }
        }
    }
    
    

    // Assegna il numero di articoli da visualizzare    
function SetNumArticles (NumArticles) {
    GLNumArticles = NumArticles;
    }
    
    
    
    
function preload_images() {
    
    if (document.images) {
        preload_image = new Image(16,16); 
        preload_image.src="images/tlc.gif";
        
        preload_image = new Image(16,16); 
        preload_image.src="images/trc.gif";
        
        preload_image = new Image(16,16); 
        preload_image.src="images/blc.gif";
        
        preload_image = new Image(16,16); 
        preload_image.src="images/brc.gif";

        preload_image = new Image(16,16);             
        preload_image.src="images/tb.gif";
        
        preload_image = new Image(16,16); 
        preload_image.src="images/bb.gif";
        
        preload_image = new Image(16,16); 
        preload_image.src="images/r.gif";
        
        preload_image = new Image(16,16); 
        preload_image.src="images/l.gif";            
        
        preload_image = new Image(57,16); 
        preload_image.src="images/left-corner.gif";
        
        preload_image = new Image(57,16); 
        preload_image.src="images/right-corner.gif";
        
        preload_image = new Image(760,200); 
        preload_image.src="logo.jpg";
        }
    }