//rejestracja sklepu - uzyj danych osobowych do rejestracji sklepu
var classname_err_msg = 'error';

//prostsze pobieranie de...
function de(id) {
    return document.getElementById(id);
}
function dc(name) {
    return document.getElementsByClassName(name);
}

function putFlash(sPath, iWidth, iHeight, sID) {
    with (document) {
        write('<object classid="clsid:d27cdb6e-ae6d-11cf-96b8-444553540000" codebase="http://download.macromedia.com/pub/shockwave/cabs/flash/swflash.cab#version=5,0,0,0" width="'+iWidth+'" height="'+iHeight+'" id="'+sID+'">');
        write('  <param name="movie" value="'+sPath+'" />');
        write('  <param name="quality" value="high" />');
        write('  <param name="wmode" value="transparent" />');
        write('  <param name="menu" value="false" />');
        write('  <embed src="'+sPath+'" quality="high" wmode="transparent" menu="false" width="'+iWidth+'" height="'+iHeight+'" swLiveConnect=true name="'+sID+'" align="middle" allowScriptAccess="sameDomain" type="application/x-shockwave-flash" pluginspage="http://www.macromedia.com/go/getflashplayer" />');
        write('</object>');
    }
}

function imageChange(fname, imgname, spname, fsize, wmax, hmax) {
    thumbnailSize = fsize;
    imgObj = new Image();
    imgObj.onload = function() {
        w = this.width; h = this.height; t = document.getElementById(imgname);
        //sprawdzanie rozmiaru fotki
        if ( (w > wmax) || (h > hmax) ) {
            alert ("Wybrany plik jest za duży, zmniejsz jego rozmiary do co najwyżej "+wmax+" px ");
            return false;
        }
        if (w > thumbnailSize || h > thumbnailSize)
        if (w > h) {
            h = Math.round(h * thumbnailSize / w);
            w = thumbnailSize;
        } else {
            w = Math.round(w * thumbnailSize / h);
            h = thumbnailSize;
        }
        with (t.style) {
            width = w+'px';
            height = h+'px';
            display = 'inline';
        }
        t.src = "file://" + document.getElementById(fname).value;
        document.getElementById(spname).innerHTML = this.width + ' x ' + this.height;
    };
    imgObj.onerror = function() {
        document.getElementById(imgname).style.display = 'none';
        document.getElementById(spname).innerHTML = 'Error';
    };
    imgObj.src = "file://" + document.getElementById(fname).value;
}



function updateObjects(fname, imgname, spname, fsize, wmax, hmax) {

    inputObj = document.getElementById(fname);
    //	alert(inputObj);
    if (document.all) {
        inputObj.onchange = function() { imageChange(fname, imgname, spname, fsize, wmax, hmax) };
    } else {
        inputObj.onclick = function() { imageChange(fname, imgname, spname, fsize, wmax, hmax) };
    }
}


function hide_obj(name) {
    var agt=navigator.userAgent.toLowerCase();
    var is_ie5 = ((parseInt(navigator.appVersion) == 4) && (agt.indexOf("msie 5.0")!=-1) && (agt.indexOf("opera") == -1));

    if (document.getElementById && !is_ie5) {
        obj=document.getElementById(name).style.visibility = "hidden";
        document.getElementById(name).style.display = "none";
    } else if (document.layers) {
        obj=document.layers[name].visibility = "hide";
        document.layers[name].display = "none";
    } else if (document.all) {
        obj=document.all[name].style.visibility = "hidden";
        document.all[name].display = "none";
    } else {
        obj=false;
    }
}

function show_obj(name) {
    var agt=navigator.userAgent.toLowerCase();
    var is_ie5 = ((parseInt(navigator.appVersion) == 4) && (agt.indexOf("msie 5.0")!=-1) && (agt.indexOf("opera") == -1));
    if (document.getElementById && !is_ie5) {
        obj=document.getElementById(name).style.visibility = "visible";
        document.getElementById(name).style.display = "inline";
    } else if (document.layers) {
        obj=document.layers[name].visibility = "show";
        document.layers[name].display = "inline";
    } else if (document.all) {
        obj=document.all[name].style.visibility = "visible";
        document.all[name].display = "inline";
    } else {
        obj=false;
    }
}

function lupka_foto(strona) {
    lupka (strona, "", "", 'yes');
}

function lupka(plik_strony, w, h, przew) {
    if (!w) {w=500;}
    if (!h) {w=400;}
    if (!przew) {przew='yes';}

    if (window.screen){
        aw=screen.availWidth;
        ah=screen.availHeight;
    } else{
        aw=640;
        ah=450;
    }

    ustawienia=
    "left=" + (aw-w)/2 + ","
    +"top=" + (ah-h)/2 + ","
    +"screenX=" + (aw-w)/2 + ","
    +"screenY=" + (ah-h)/2 + ","
    +"width=" + w + ","
    +"height=" + h + ","
    +"innerWidth=" + w + ","
    +"innerHeight=" + h + ","
    +"toolbar=no,"
    +"location=no,"
    +"directories=no,"
    +"status=now,"
    +"menubar=no,"
    +"scrollbars=" +przew+ ","
    +"resizable=yes"
    self.window.name='glowne';
    noweOkienko = window.open(plik_strony,'noweOkienko',ustawienia);

    noweOkienko.document.close();
    noweOkienko.focus();
}

//window.onload = startList;

function showImage(sender) {
    lImg = document.getElementById("largeimage");
    if (!(!lImg)) {
        lImg.src = sender.childNodes[0].src.replace('web_thumbs', 'web');
        lImg.alt = sender.childNodes[0].alt;
    }
}

var ind = 1;


function prev() {
    if (ind==1)
    ind = ln;
    else
    ind--;
    tImg = document.getElementById("pic"+ind);
    if (!(!tImg))
    showImage(tImg.parentNode);
}
function next() {
    if (ind==ln)
    ind = 1;
    else
    ind++;
    tImg = document.getElementById("pic"+ind);
    if (!(!tImg))
    showImage(tImg.parentNode);
}

function popupImg(sender) {
    obj = document.getElementById("divPop");
    if (!(!obj)) 
    obj.parentNode.removeChild(obj);
    
    divPop = document.createElement('div');
    divPop.id = 'divPop';
    divPop.style.diplay = 'block';
    divPop.style.backgroundColor = '#ffffff';
    divPop.style.position = 'absolute';
    divPop.style.left = '50px';
    divPop.style.top = '50px';
    divPop.style.padding = '5px';
    divPop.onclick = function () {
        this.parentNode.removeChild(this);
    }
    document.body.appendChild(divPop);
    getScrolling('divPop');
    new_src = sender.src.replace('web', 'web_large');
    /*//tworzenie obrazka
    tImg = document.createElement('img');
    tImg.src = sender.src.replace('web', 'web_large');
    tImg.style.width = tImg.width+'px';
    tImg.style.height = tImg.height+'px';
    tImg.style.cursor = 'pointer';
    tImg.alt = tImg.src;
    divPop.appendChild(tImg);*/
    divPop.innerHTML = '<img src="'+new_src+'" onclick="hide_obj(\'popupImg\')" />';
}
/*function popupImg(sender) {
//lImg = document.getElementById("largeimage");
//show_obj('popupImg');
getScrolling('popupImg');
divPop = document.getElementById('popupImg');
//divPop.style.diplay = 'block';
divPop.style.width = (sender.width+10)+'px';
divPop.style.height = (sender.height+20)+'px';

new_src = sender.src.replace('web', 'web_large');

//tworzenie obrazka
//    tImg = document.createElement('img');
//    tImg.alt = 'close';
//    tImg.src = sender.src.replace('web', 'web_large');
//    tImg.width = sender.width+'px';
//    tImg.height = sender.height+'px';
//    alert(tImg);
//    divPop.appendChild(tImg);
divPop.innerHTML = '<img src="'+new_src+'" onclick="hide_obj(\'popupImg\')" />';

}*/


function getScrolling(divName) {
    var x = 0; var y = 0;
    if( typeof( window.pageYOffset ) == 'number' ) {
        //Netscape compliant
        y = window.pageYOffset;
        x = window.pageXOffset;
    } else if( document.body && ( document.body.scrollLeft ||
    document.body.scrollTop ) ) {
        //DOM compliant
        y = document.body.scrollTop;
        x = document.body.scrollLeft;
    } else if( document.documentElement &&
    ( document.documentElement.scrollLeft ||
    document.documentElement.scrollTop ) ) {
        //IE6 standards compliant mode
        y = document.documentElement.scrollTop;
        x = document.documentElement.scrollLeft;
    }
    //alert(x+","+y);
    showMyDiv(divName, y);
    //return x+","+y;
    return y;
}

function showMyDiv(name, y) {
    //show_obj(name);
    //centrowanie wzledem poziomu
    var main = de("main");
    leftVal = (Math.round(main.offsetWidth/2))-(Math.round(de(name).offsetWidth/2));

    de(name).style.top = (y+20) +"px";
    de(name).style.left = leftVal +"px";
}


//function showImage(id) {

//var img_swap_name="largeimage";
//var img_swap_obj=document.images[img_swap_name];

//img_swap_obj.src=images[id].src;
//    document.getElementById('largeimage').src = imgs[id];
//document.getElementById('largepic').innerHTML = '<img src="'+images[id]+'" />';
//}
