// JavaScript Document

g_actual_hidden_foto_id = "";
g_actual_pic_id = "";
g_actual_pic_popis_id = "";

g_konference = 0;
g_ubytovani = 0;
g_bonusy = 0;

function showLayer( id )
{
    obj = document.getElementById( id );
    class_name = obj.className;
    obj.className = class_name.replace( /hide/, "show" );
}

function hideLayer( id )
{
    obj = document.getElementById( id );
    class_name = obj.className;
    obj.className = class_name.replace( /show/, "hide" );
}


//+ display input 
function displayInput(e, id)
{
//    g_actual_hidden_foto_id = "v_" + id;
//    g_actual_hidden_foto_popis_id = "v_" + id + "_popis";
//    g_actual_pic_id = id + "_pic";
//    g_actual_pic_popis_id = id + "_popis";

//    document.getElementById( "popis" ).value = document.getElementById( g_actual_hidden_foto_popis_id ).value;

    obj = document.getElementById( "data_input" );
    obj.style.display = "block";
    obj.style.left = ( mouseX(e) + 70 ) + "px";
    obj.style.top = ( getScrollY() + mouseY(e) - 10 ) + "px";
}

function hideInput()
{
    obj = document.getElementById( "data_input" );
    obj.style.display = "none";
}
//- display input 

//+ callback implementation
function startCallback()
{
    // make something useful before submit (onStart)
    return true;
}

function completeCallback(response)
{
    // make something useful after (onComplete)
/*    popiska = document.getElementById( "popis" ).value;
    document.getElementById( g_actual_pic_id ).src = response;
    if( response != "" )
    {   
        obj_pic = document.getElementById( g_actual_pic_id );
        obj_pic.height = "100";
        obj_pic.parentNode.style.height = "100px";
    }
    document.getElementById( g_actual_pic_popis_id ).innerHTML = popiska;
    document.getElementById( g_actual_hidden_foto_id ).value = response;
    document.getElementById( g_actual_hidden_foto_popis_id ).value = popiska;
*/
    hideInput();
//    document.getElementById( "gen_menu" ).innerHTML = response;
}
//- callback implementation

//+ help functions
function getScrollY()
{
  var scrOfX = 0, scrOfY = 0;
  if( typeof( window.pageYOffset ) == 'number' ) {
    //Netscape compliant
    scrOfY = window.pageYOffset;
    scrOfX = window.pageXOffset;
  } else if( document.body && ( document.body.scrollLeft || document.body.scrollTop ) ) {
    //DOM compliant
    scrOfY = document.body.scrollTop;
    scrOfX = document.body.scrollLeft;
  } else if( document.documentElement && ( document.documentElement.scrollLeft || document.documentElement.scrollTop ) ) {
    //IE6 standards compliant mode
    scrOfY = document.documentElement.scrollTop;
    scrOfX = document.documentElement.scrollLeft;
  }
  return scrOfY;
}

function mouseX(e)
{
    curX = 0;
    //ie
    if(document.all) { curX = event.clientX; }
    //netscape 4
    if(document.layers) { curX = e.pageX; }
    //mozilla
    if(document.getElementById) { curX = e.clientX; }
    return curX;
}

function mouseY(e)
{
    curY = 0;
    //ie
    if(document.all) { curY = event.clientY; }
    //netscape 4
    if(document.layers) { curY = e.pageY; }
    //mozilla
    if(document.getElementById) { curY = e.clientY; }
    return curY;
}

function keyEscape(e)
{
    if (!e) var e = window.event;

    if(e.keyCode == 27) return true; //keyCode returns the ASCII value of the key pressed.
    else return false;
}

function conditionalClose(e)
{
    if( keyEscape(e) ) hideInput();
}
//- help functions


function checkState( obj )
{
	if( obj.checked )
	{
		obj.value = "ano";
	}
	else
	{
		obj.value = "ne";
	}
}



function displaySezona( sezonaTyp )
{
    div_id = "sezony_" + sezonaTyp; // pult alebo bh
    var domElement = document.getElementById( div_id );
    var newDiv = document.createElement('div');
    newDiv.setAttribute('id', 'new_sezona');

    domElement.appendChild( newDiv );
    
    
    var html_doc = document.getElementsByTagName('head').item(0);
    var js = document.createElement('script');
    js.setAttribute('language', 'javascript');
    js.setAttribute('type', 'text/javascript');
    js.setAttribute('src', 'generate.php?typ='+sezonaTyp );
    html_doc.appendChild( js );

    return false;
}


function addMenuItem( menu_id, position, e )
{
    if (!e) var e = window.event;

    document.getElementById( "menu_id" ).value = menu_id;
    document.getElementById( "menu_pos" ).value = position;
    if( position == "before" )
    {
        document.getElementById( "menu_typ_sub" ).disabled = "disabled";
        document.getElementById( "menu_typ_sub" ).checked = "";
        document.getElementById( "menu_typ_men" ).checked = "checked";
    }
    else
    {
        document.getElementById( "menu_typ_sub" ).disabled = "";        
    }

    displayInput( e, "");
//    	alert( "id = " + menu_id + ", position = '" + position + "'" );
}

function deleteMenuItem( menu_id, position, e )
{
    if (!e) var e = window.event;

    document.getElementById( "menu_id" ).value = menu_id;
    document.getElementById( "menu_pos" ).value = position;
    if( position == "before" )
    {
        document.getElementById( "menu_typ_sub" ).disabled = "disabled";
        document.getElementById( "menu_typ_sub" ).checked = "";
        document.getElementById( "menu_typ_men" ).checked = "checked";
    }
    else
    {
        document.getElementById( "menu_typ_sub" ).disabled = "";        
    }

    displayInput( e, "");
//    	alert( "id = " + menu_id + ", position = '" + position + "'" );
}

// -------------------------
// GALLERY RELATED
g_actual_pic_id = "";

function showBigPic( number )
{
	if( g_actual_pic_id != "" )
	{
		hideBigPic( g_actual_pic_id );
	}
	position_top = getScrollY() + 50;
	document.getElementById( "pic" + number ).style.visibility = "visible";
	document.getElementById( "pic_back" + number ).style.visibility = "visible";
	document.getElementById( "pic" + number ).style.top = position_top + "px";
	document.getElementById( "pic_back" + number ).style.top = position_top + "px";
	document.getElementById( "pic" + number ).style.left = "50%";
	document.getElementById( "pic_back" + number ).style.left = "50%";
	g_actual_pic_id = number;
}

function hideBigPic( number )
{
	document.getElementById( "pic" + number ).style.visibility = "hidden";
	document.getElementById( "pic_back" + number ).style.visibility = "hidden";
	document.getElementById( "pic" + number ).style.top = "-800px";
	document.getElementById( "pic_back" + number ).style.top = "-800px";
	document.getElementById( "pic" + number ).style.left = "-2000px";
	document.getElementById( "pic_back" + number ).style.left = "-2000px";
}

function chcol( obj )
{
	document.getElementsByName( "mlink" ).color = "#FFFFFF";
	obj.style.color = "#888888";
}

function getScrollXY()
{
  var scrOfX = 0, scrOfY = 0;
  if( typeof( window.pageYOffset ) == 'number' ) {
    //Netscape compliant
    scrOfY = window.pageYOffset;
    scrOfX = window.pageXOffset;
  } else if( document.body && ( document.body.scrollLeft || document.body.scrollTop ) ) {
    //DOM compliant
    scrOfY = document.body.scrollTop;
    scrOfX = document.body.scrollLeft;
  } else if( document.documentElement && ( document.documentElement.scrollLeft || document.documentElement.scrollTop ) ) {
    //IE6 standards compliant mode
    scrOfY = document.documentElement.scrollTop;
    scrOfX = document.documentElement.scrollLeft;
  }
  return [ scrOfX, scrOfY ];
}

// PIC opacity  CHANGE
function opacity(id, opacStart, opacEnd, millisec) {
	//speed for each frame
	var speed = Math.round(millisec / 100);
	var timer = 0;

	//determine the direction for the blending, if start and end are the same nothing happens
	if(opacStart > opacEnd) {
		for(i = opacStart; i >= opacEnd; i--) {
			setTimeout("changeOpac(" + i + ",'" + id + "')",(timer * speed));
			timer++;
		}
	} else if(opacStart < opacEnd) {
		for(i = opacStart; i <= opacEnd; i++)
			{
			setTimeout("changeOpac(" + i + ",'" + id + "')",(timer * speed));
			timer++;
		}
	}
}

//change the opacity for different browsers
function changeOpac(opacity, id) {
	var object = document.getElementById(id).style; 
	object.opacity = (opacity / 100);
	object.MozOpacity = (opacity / 100);
	object.KhtmlOpacity = (opacity / 100);
	object.filter = "alpha(opacity=" + opacity + ")";
}

function shiftOpacity(id, millisec) {
	//if an element is invisible, make it visible, else make it ivisible
	if(document.getElementById(id).style.opacity == 0) {
		opacity(id, 0, 100, millisec);
	} else {
		opacity(id, 100, 0, millisec);
	}
}

function resetBack(id)
{
    document.getElementById(id).style.backgroundImage = "none";
}

function blendimage(divid, imageid, imagefile, millisec) {
	var speed = Math.round(millisec / 100);
	var timer = 0;
	
	//set the current image as background
	document.getElementById(divid).style.backgroundImage = "url(" + document.getElementById(imageid).src + ")";
	
	//make image transparent
	changeOpac(0, imageid);
	
	//make new image
//	var pic = new Image();
//    pic.src = imagefile;
//    if( pic.complete == true )
//    {
//        document.getElementById(imageid).src = pic.src;
//    }
//    else
//    {
//        pic.onload = document.getElementById(imageid).src = imagefile;
//    }
    document.getElementById(imageid).src = imagefile;

	//fade in image
	for(i = 0; i <= 100; i++) {
		setTimeout("changeOpac(" + i + ",'" + imageid + "')",(timer * speed));
//		setTimeout("changeOpac(" + (100-i) + ",'" + divid + "')",(timer * speed));
		timer++;
	}
//    setTimeout("resetBack('" + divid + "')",Math.round(millisec / 10));
//	document.getElementById(divid).style.backgroundImage = "none";
}

function currentOpac(id, opacEnd, millisec) {
	//standard opacity is 100
	var currentOpac = 100;
	
	//if the element has an opacity set, get it
	if(document.getElementById(id).style.opacity < 100) {
		currentOpac = document.getElementById(id).style.opacity * 100;
	}

	//call for the function that changes the opacity
	opacity(id, currentOpac, opacEnd, millisec)
}


// setInterval( "swapImages()", 20000 );



// ------------------------------------------------------------------------
// dealing with parts
var total_parts = 0;

function showPart( num )
{
	for( j=1; j<=total_parts; j++)
	{
		if( j == num )
		{
			document.getElementById( "div_part"+j ).style.display = "block";
			document.getElementById( "a_part"+j ).style.fontWeight = "bold";
		}
		else
		{
			document.getElementById( "div_part"+j ).style.display = "none";
			document.getElementById( "a_part"+j ).style.fontWeight = "normal";
		}
	}
}

function makePartsHidden()
{
	obj = document.getElementsByName( "a_part" );
	total_parts = obj.length;
	for( i=1; i<=total_parts; i++)
	{
		if( i > 1 )
		{
			document.getElementById( "div_part"+i ).style.display = "none";
		}
		if( i == 1 )
		{
			document.getElementById( "a_part"+i ).style.fontWeight = "bold";
		}
		document.getElementById( "a_part"+i ).href = "#self";
		eval( 'document.getElementById( "a_part'+i+'" ).onclick = function(){ showPart('+i+'); };' );
	}
}

if (window.addEventListener) // W3C standard
{
  window.addEventListener('load', makePartsHidden, false); // NB **not** 'onload'
} 
else if (window.attachEvent) // Microsoft
{
  window.attachEvent('onload', makePartsHidden);
}

// ------------------------------------------------------------------------

