var OnResizeIsRunning 	= false;
var ContentHeight 	= 0;
var ScreenWidth	 	= 0;
var ScreenHeight 	= 0;
var GalleryImage;

function OnResize() {

    if (OnResizeIsRunning) {
        return true; 
    } else {
	OnResizeIsRunning = true;
    }

    // height
    var theHeight = 0;
    if (window.innerHeight) {
     theHeight=window.innerHeight;
    } else 
      if (document.documentElement && document.documentElement.clientHeight) {
         theHeight=document.documentElement.clientHeight;
      } else 
        if (document.body) {
          theHeight=document.body.clientHeight;
        }
    ScreenHeight = theHeight;
    
    // width
    var theWidth = 0;
    if (window.innerWidth) {
     theWidth=window.innerWidth;
    } else 
      if (document.documentElement && document.documentElement.clientWidth) {
         theWidth=document.documentElement.clientWidth;
      } else 
        if (document.body) {
          theWidth=document.body.clientWidth;
        }
    ScreenWidth = theWidth;

    // design
    if (theHeight != 0) {
	theHeight = theHeight - 340;
	if (theHeight > 480) 
	  theHeight = 480;
	document.getElementById('design_i').style.height   = theHeight + "px";
	document.getElementById('design_i1').style.height  = theHeight + "px";
	document.getElementById('design_i2a').style.height = theHeight + "px";
	document.getElementById('design_i2b').style.height = (theHeight - 16) + "px";
	ContentHeight = theHeight;
    }

    OnResizeIsRunning = false;
}

function ContentReload(URL) {

    var request = null;
    try { 
	request = new XMLHttpRequest();
    }
    catch(e) {
	try { 
	    request = new ActiveXObject('Microsoft.XMLHTTP'); 
	}
	catch(e) {
        }
    }
  
    if (request != null) {
	request.onreadystatechange = function() {
    	    if (request.readyState == 4) {
    		if (request.status == 200) {
    		    document.getElementById("design_i2b").innerHTML = request.responseText;
    		}
            }
	}
    }

    request.open("GET", URL, true);
    request.send(null);

}

// Item1, 75 (alpha)
function SetOpacity(Name, Opacity) {

    var Control = document.getElementById(Name);
    if (Control) {
	Control.style.opacity = Opacity / 100;
	Control.style.filter  = 'alpha(opacity=' + Opacity + ')';
    }
}

// gallery show
function GalleryShow(URL) {

    var Control = document.getElementById("gallery_show");
    var Pic = document.getElementById("gallery_picture");
    var GS = document.getElementById('gallery_show');
    var GSP = document.getElementById('gallery_show_picture');

    function GalleryResize(NewWidth, NewHeight) {

	if (NewWidth == 0) {
	  NewWidth = 400;
	}
	if (NewHeight == 0) {
	  NewHeight = 400;
	}
	GSP.style.left	 = "16px";
	GSP.style.top	 = "16px";
	GSP.style.width  = NewWidth + "px";
	GSP.style.height = NewHeight + "px";
	GS.style.left    = ((ScreenWidth-NewWidth-32) / 2) + "px";
	GS.style.top     = ((ScreenHeight-NewHeight-32) / 2) + "px";
	GS.style.width   = (NewWidth+32) + "px";
	GS.style.height  = (NewHeight+32) + "px";
    }

    function ImageLoaded() {
	
	// RESIZE WINDOW
//	alert(GalleryPicture.width + "x" + GalleryPicture.height);
	var NewWidth 	 = GalleryImage.width;
	var NewHeight	 = GalleryImage.height;
	var Prop	 = 0;
	if (NewWidth == 0)   
	    NewWidth = 400;
	if (NewHeight == 0)   
	    NewHeight = 400;
	if ((NewWidth > ScreenWidth - 64) || (NewHeight > ScreenHeight - 64)) {
	    if ((NewWidth / (ScreenWidth - 64)) <= (NewHeight / (ScreenHeight - 64))) {	        
	        Prop 	  = (NewHeight / (ScreenHeight - 64));
		if (Prop > 0) {
		    NewWidth  = NewWidth / Prop;
		    NewHeight = NewHeight / Prop;
		}
	    } else {	    
	        Prop 	  = (NewWidth / (ScreenWidth - 64));
		if (Prop > 0) {
		    NewWidth  = NewWidth / Prop;
		    NewHeight = NewHeight / Prop;
		}
	    }
	}	
	
	GalleryResize(NewWidth, NewHeight);
	Pic.width 	= NewWidth;
	Pic.height	= NewHeight;
	Pic.src 	= GalleryImage.src;
//	alert(Pic.width + "x" + Pic.height);
    }
    

    if (Control) {
	Control.style.display = "block";
	Pic.src = '1pt.gif';
	if ((GSP.style.width.replace(/px/,"") == 0) || (GSP.style.width.replace(/px/,"") == 0))
	    GalleryResize(400, 400);

	// PRELOAD IMAGES
	GalleryImage      = new Image();
	GalleryImage.onload = ImageLoaded;
	GalleryImage.src  = URL;
    }
}

// gallery hide
function GalleryHide() {
    var Control = document.getElementById("gallery_show");
    if (Control) {
	Control.style.display = "none";
    }
}

// Client centrum
var ClientLastPicName = "";
function SetClientPic(DivName, PicName) {
    var Pic0Div = document.getElementById("clcentrum_picture0");
    var Pic0Img = document.getElementById("pic0");
    var PicXDiv = document.getElementById(DivName);
    var PicXImg = document.getElementById(PicName);

    if (ClientLastPicName != PicName) 
    {
	ClientLastPicName = PicName;
        Pic0Img.src    = '1pt.gif';
	Pic0Div.style.top    = (PicXDiv.style.top.replace(/px/,"")-15) + 'px';
	Pic0Div.style.left   = (PicXDiv.style.left.replace(/px/,"")-10) + 'px';
        Pic0Img.src    = PicXImg.src;
	Pic0Img.height = (PicXImg.height + 30);
        Pic0Img.width  = (PicXImg.width + 20);
    }
}

function validate_required(field, alerttxt) {
	    if (field.value == '') {
		alert(alerttxt); 
	        return false;
    	    } else { return true; }  
        }
    
function validate_form(thisform) {
	    with (thisform)	{
		if (validate_required(Meno,'Meno / názov firmy je povinné')==false)
	        {Meno.focus();return false}
		if (validate_required(Email,'E-mail je povinný')==false)
	        {Email.focus();return false}

	    }
}
