<?php

$submit = getuserdata('submit');
$eroare = '';

function procesare_modul()
{
}

function scripturi_modul()
{
}

function afisare_modul()
{
	global $id_modul, $imagesroot, $pagina, $submit;
	$id_imagine = getuserdata('id_imagine', 0);
	?>

	<script type='text/javascript'>
        
        function centerDiv(obj)
        {
			// First, determine how much the visitor has scrolled

            var scrolledX, scrolledY;
            if (window.pageYoffset)
            {
                scrolledX = window.pageXoffset;
                scrolledY = window.pageYoffset;
            }
            else if( document.documentElement && document.documentElement.scrollTop ) 
            {
                scrolledX = document.documentElement.scrollLeft;
                scrolledY = document.documentElement.scrollTop;
            }
            else if( document.body ) 
            {
                scrolledX = document.body.scrollLeft;
                scrolledY = document.body.scrollTop;
            }

            // Next, determine the coordinates of the center of browser's window

            var centerX, centerY;
            if (self.innerHeight)
            {
                centerX = self.innerWidth;
                centerY = self.innerHeight;
            }
            else if( document.documentElement && document.documentElement.clientHeight ) 
            {
                centerX = document.documentElement.clientWidth;
                centerY = document.documentElement.clientHeight;
            }
            else if( document.body ) 
            {
                centerX = document.body.clientWidth;
                centerY = document.body.clientHeight;
            }

            // Xwidth is the width of the div, Yheight is the height of the
            // div passed as arguments to the function:
            var leftoffset = scrolledX + (centerX - obj.offsetWidth) / 2;
            var topoffset = scrolledY + (centerY - obj.offsetHeight) / 2;
            // The initial width and height of the div can be set in the
            // style sheet with display:none; divid is passed as an argument to // the function
            var r = obj.style;
            r.position = 'absolute';
            r.top = topoffset + 'px';
            r.left = leftoffset + 'px';
            //r.display = "block";           
        }

        function afterImageLoad(image)
        {
            var img_layer = document.getElementById("img_layer");
            var loading_layer = document.getElementById("loading_layer");
			var img = document.getElementById("imagine");
			img_layer.style.display = "block";
			centerDiv(img_layer);
			loading_layer.style.display = 'none';
		}
		
        function showimage(imagine)
        {
			var loading_layer = document.getElementById("loading_layer");
			loading_layer.style.display = 'block';
		    centerDiv(loading_layer);		    
		    document.getElementById("img_id").value = imagine;
        	var imgform = document.getElementById("img_form");
			document.frm_image.submit();
		}
		
		function hideimage()
		{
			var img_layer = document.getElementById("img_layer");
			img_layer.style.display = "none";
		}
		
		function submitImage(submitname)
		{
		    var scr_form = document.getElementById("frm_capturi");
		    var scr_form_submit = document.getElementById("scr_form_submit");
		    scr_form_submit.value = submitname;
		    document.frm_capturi.submit();
		}
		
	</script>
	<?
    $submit = getuserdata('scr_form_submit', '');
    echo "<h1>Imagini</h1>";
    echo "<p>BizMedica este un progam destinat medicilor specialiști din domeniile Medicină de familie, Cardiologie, Alergologie, Oftalmologie, O.R.L.</p>";
    echo "<p>Faceți clic pe imagine pentru a vizualiza capturi din programul BizMedica.</p>";
    echo "<form action='{$_SERVER['PHP_SELF']}' method='POST' name='frm_capturi' id='frm_capturi'>";
    echo "<input type='hidden' name='pagina' value='$pagina'>";
    echo "<input type='hidden' name='id_modul' value='$id_modul'>";
    $qc = mysql_query("SELECT * FROM imagini_categorii ORDER BY nr_crt ASC");
    while ($rc = mysql_fetch_assoc($qc))
    {
        echo "<p><b><a name='{$rc['id']}'></a>{$rc['categorie']}</b></p>";
        if ($submit == "ant_{$rc['id']}") $id_imagine = getuserdata("id_imagine_ant_{$rc['id']}");
        else if ($submit == "urm_{$rc['id']}") $id_imagine = getuserdata("id_imagine_urm_{$rc['id']}");
        else $id_imagine = getuserdata("id_imagine_{$rc['id']}", 0);
        $q = mysql_query("SELECT * FROM imagini WHERE id = $id_imagine");
        if (!mysql_num_rows($q)) $q = mysql_query("SELECT * FROM imagini WHERE id_categorie = {$rc['id']} ORDER BY nr_crt");
        $last_id = 0;
        while ($r = mysql_fetch_assoc($q))
        {
            echo "<a href='{$imagesroot}capturi/{$r['imagine']}' rel='lightbox-{$rc['id']}' title='{$r['descriere']}'>";
            if ($last_id != $rc['id'])
            {
                echo "<img src='{$imagesroot}capturi/{$r['imagine']}' width='400' height='300' style='border: solid 2px green; cursor: pointer'>";
                $last_id = $rc['id'];
            }
            echo "</a>";
    	    /*$id_imagine = $r['id'];
    	    $id_categorie = $r['id_categorie'];
		    echo "<table class='imagini'><tr><td class='stanga'>";
		    $q1 = mysql_query("SELECT * FROM imagini WHERE nr_crt < (SELECT nr_crt FROM imagini WHERE id = $id_imagine) ".
                              "AND id_categorie = $id_categorie ORDER BY nr_crt DESC");
		    if ($r1 = mysql_fetch_assoc($q1))
		    {
		        echo "<input type='hidden' name='id_imagine_ant_{$rc['id']}' value={$r1['id']}>";
		        echo "<a href='#{$rc['id']}' onClick='submitImage(\"ant_{$rc['id']}\")'><img src='{$imagesroot}/btnimg_ant.png'></a>";
            }
		    echo "</td><td><img src='{$imagesroot}capturi/{$r['imagine']}' width='400' height='300' style='border: solid 2px green; cursor: pointer' ".
		         "onClick='showimage({$r['id']})'>";
            echo "<input type='hidden' name='id_imagine_{$rc['id']}' value={$r['id']}>";
            echo "</td><td class='dreapta'>";
		    $q1 = mysql_query("SELECT * FROM imagini WHERE nr_crt > (SELECT nr_crt FROM imagini WHERE id = $id_imagine) ".
                              "AND id_categorie = $id_categorie ORDER BY nr_crt ASC");
		    if ($r1 = mysql_fetch_assoc($q1))
		    {
		        echo "<input type='hidden' name='id_imagine_urm_{$rc['id']}' value={$r1['id']}>";
		        echo "<a href='#' onClick='submitImage(\"urm_{$rc['id']}\")'><img src='{$imagesroot}/btnimg_urm.png'></a>";
            }
		    echo "</td></tr><tr><td colspan='3' style='text-align: center'>{$r['descriere']}</td></tr></table>";*/
        }
    }
    echo "<input type='hidden' name='scr_form_submit' id='scr_form_submit' value='0' style='display: none'>";
    echo "</form>";
    echo "<form class='hidden_form' name='frm_image' id='frm_image' method='POST' action='imagini.php' target='img_frame'>".
         "<input type='hidden' name='id_imagine' id='img_id' value='0'>".
		 "<input type='submit' name='submitt' style='display: none'>";
		 "</form>";
}

?>