//----------- basic ---------------------
function ap_getObj(name) { 
  		if (document.getElementById)
   		 	return document.getElementById(name);
  		else
    	if (document.all)
      		return document.all[name];
}
//----------- foto open -----------------
function foto_open(image,action){
   var page = "main_newfotodetail.php" ;
   var value = "soubor="+image ;
   var date = new Date() ;
   dhtmlmodal.open("detail", "iframe", page+"?"+value+"&action="+action, "Detail fotografie", 
   "width=680px,height=510px,center=1,scrolling=0,resize=1", "recal");
}

//----------- fotogalerie open -----------------
function gallery_open(page_path,description){
   var date = new Date() ;
   dhtmlmodal.open("detail", "iframe", page_path+"?"+date, description, 
   "width=750px,height=600px,center=1,scrolling=0,resize=1", "recal");
}

//------------- video open -------------------
function video_open(videofile,description){
   var page = "flash_video_player.php" ;
   var freevideo = "videofile="+videofile ;
   var action = "play" ;
   var date = new Date() ;
   reload(videofile);
   dhtmlwindow.open("detail", "iframe", page+"?"+freevideo+"&"+"&action="+action, description, 
   "width=520px,height=450px,center=1,scrolling=0,resize=0", "recal");
}

//------------- AJAX -------------------------
var result = "" ;
function makeRequest(url, parameters, isAsync){
		if (window.XMLHttpRequest) { // Mozilla, Safari,...
			http_request = new XMLHttpRequest();
			if (http_request.overrideMimeType){
				http_request.overrideMimeType('text/xml');
			}
		}else 
		if (window.ActiveXObject) { // IE
			try {
				http_request = new ActiveXObject("Msxml2.XMLHTTP");
			} catch (e) {
				try {
					http_request = new ActiveXObject("Microsoft.XMLHTTP");
				} catch (e) {}
			}
		}
		
		if (!http_request) {
			alert('Cannot create XMLHTTP instance');
			return false;
		}
		if (isAsync){
		    http_request.onreadystatechange = alertContents;	
		}
		http_request.open('GET', url + parameters, isAsync);
		http_request.send(null);
		if (!isAsync){
			result = http_request.responseText;
		}
	}
	
	function alertContents() {
		if (http_request.readyState == 4) {
			if (http_request.status == 200) {
				//alert(http_request.responseText);
				result = http_request.responseText;
			} else {
				//alert('There was a problem with the request.'+http_request.status);
				result = 'There was a problem with the request.'+http_request.status ;
			}
		}
	}

    function reload(file) {
       now = new Date();
       makeRequest("cmp_download_counter.php","?action=setcounter&filename="+file,false) ;
       //alert (result) ;
    }
  


//----------- banner ------------------

function show_index_banner(caption,page){
   var date = new Date() ;
   var win = dhtmlmodal.open("banner_1", "iframe", page+"?"+date, caption, 
   "width=740px,height=610px,center=1,scrolling=0,resize=0", "recal");
   
   win.onclose=function(){ 
       return true ;
   }
}
//---------- Admin Message ---------------------
var admin_msg = new Array() ;
function show_admin_msg(dbid,caption,position){
	var page = "index_adminmsg.php" ;
   	var date = new Date() ;
   	var top = 200 + (25*position);
   	if (!isArray(admin_msg)){
   		admin_msg = new Array() ;
   	}
   	admin_msg[dbid] = dhtmlwindow.open("admin_msg_"+dbid, "iframe", page+"?dbid="+dbid+"&"+date, caption, 
   	"width=500px,height=300px,center=0,leftcenter=1,top="+top+"px,scrolling=0,resize=1", "recal");
   	admin_msg[dbid].dbid = dbid ;
   	
   	admin_msg[dbid].onclose = function(){ 
		var date = new Date() ;
		params = "action=read_message&dbid="+admin_msg[dbid].dbid+"&"+date;
		result = makePHPRequest("index_adminmsg.php","?"+params,false) ;
		//alert(result) ;
		//mistoZobrazeni.innerHTML = result;
       	return true ;
   }
}

//--------- HIGHSLIDES ----------------------

    hs.graphicsDir = 'highslide/graphics/';
    // Identify a caption for all images. This can also be set inline for each image.
    hs.captionId = 'the-caption';    
    hs.outlineType = 'rounded-white';
    hs.align = 'center';
    hs.Expander.prototype.onImageClick  = function (sender) {
       this.close() ;
       hs.next() ;
       return true ;
    }
    
//--------- IFRAME --------------------------
function setIframeHeight(iframeName) {
		  //var iframeWin = window.frames[iframeName];
		  var iframeEl = document.getElementById? document.getElementById(iframeName): document.all? document.all[iframeName]: null;
		  if (iframeEl) {
		  iframeEl.style.height = "auto"; // helps resize (for some) if new doc shorter than previous
		  //var docHt = getDocHeight(iframeWin.document);
		  // need to add to height to be sure it will all show
		  var h = alertSize();
		  var new_h = (h-148);
		  iframeEl.style.height = new_h + "px";
		  //alertSize();
		  }
}

function alertSize() {
		  var myHeight = 0;
		  if( typeof( window.innerWidth ) == 'number' ) {
		    //Non-IE
		    myHeight = window.innerHeight;
		  } else if( document.documentElement && ( document.documentElement.clientWidth || document.documentElement.clientHeight ) ) {
		    //IE 6+ in 'standards compliant mode'
		    myHeight = document.documentElement.clientHeight;
		  } else if( document.body && ( document.body.clientWidth || document.body.clientHeight ) ) {
		    //IE 4 compatible
		    myHeight = document.body.clientHeight;
		  }
		  //window.alert( 'Height = ' + myHeight );
		  return myHeight;
}
 
