// JavaScript Document
//var HTTP_HOST = "http://localhost";
var HTTP_HOST = "http://lhpromotion.eu";
var global_timer = 0;

function return_false(){
	return false;
}


if (!Array.prototype.forEach)
{
  Array.prototype.forEach = function(fun /*, thisp*/)
  {
    var len = this.length;
    if (typeof fun != "function")
      throw new TypeError();

    var thisp = arguments[1];
    for (var i = 0; i < len; i++)
    {
      if (i in this)
        fun.call(thisp, this[i], i, this);
    }
  };
}

function my_confirm( question ) {
	return confirm( question );
}

function hide(id) {
	el = document.getElementById(id).style;
	el.display = (el.display == 'block' || el.display == '' )? 'none' : 'block';
}

function inhide(id) {
	el = document.getElementById(id).style;
	if( el.display == "" ) el.display = 'inline-block';
	el.display = (el.display != 'inline-block')?'inline-block':'none';
}


function groupHide(element, index, array) {
	document.getElementById(array[index]).style.display = "none";	
}

function getChild(id, tag) {
	elements = document.getElementById(id).getElementsByTagName(tag);
	return element[0];
}
/*
** ==== CISTENI INPUTU ====
*/
function clearonclick(element, text) {
	if(element.value == text) {
		element.value = "";
	}
}

function fillonblur( element, text ) {
	if(element.value == "") {
		element.value = text;
	}
}

/*
** ==== CLANKY ====
*/
function show_part( id, element ) {
	if( element.value == 1 || element.value == 2 || element.value == 3 ) // nahradit necim jako IN ARRAY
		document.getElementById(id).style.display = "block";
	else
		document.getElementById(id).style.display = "none";
	
	if( element.value == 3 ) {
		document.getElementsByName("menu")[0].disabled = true;
		document.getElementById("upoutavka").style.display = "block";
		//document.getElementById("sub_article").style.display = "block";
	}else{
		document.getElementsByName("menu")[0].disabled = false;
		document.getElementById("upoutavka").style.display = "none";
		//document.getElementById("sub_article").style.display = "none";
	}
	
}

function resize_image( id, step ) {
	elm	= document.getElementById(id);
	if( parseInt( elm.getAttribute("width") ) + parseInt( step ) > 0 ) 
		elm.setAttribute("width", parseInt( elm.getAttribute("width") ) + parseInt( step ) );
	else
		elm.setAttribute("width", 0);
}

var button = 0;
function edit_item ( id, in_button ) {
	elm		= document.getElementById(id);
	elm.childNodes;
	text	= elm.innerHTML;
	elm.innerHTML = '<textarea id="'+id +'_edit" class="w400 h100">'+ text +'</textarea>'
	elm.innerHTML +='<br /><input type="button" value="Uložit" onclick="save(\''+ id +'\')" />';
	button = in_button;
}

function save( id ) {
	text = document.getElementById(id +'_edit');
	document.getElementById(id).innerHTML = text.value;
	document.getElementById(id).appendChild( button );
}

function redirect( url ) {
	window.location = url;
}

function load_image( id, src ) {
	document.getElementById(id).style.backgroundImage = "url("+ src +")";
}

var y = -1;
function slideshow( images, show_id, delay ) {
	var x = images.length;
	
	if( y == -1 )
		y = Math.floor( Math.random()* parseInt(x) + 1 );
	
	load_image( show_id, images[y] );
	y++;
	
	if( y == x )
		y = 0;
	
	setTimeout('slideshow(images, "'+show_id+'", "'+delay+'")', delay);
}

function intval (mixed_var, base) {
    // Get the integer value of a variable using the optional base for the conversion  
    // 
    // version: 1009.2513
    // discuss at: http://phpjs.org/functions/intval
    // +   original by: Kevin van Zonneveld (http://kevin.vanzonneveld.net)
    // +   improved by: stensi
    // +   bugfixed by: Kevin van Zonneveld (http://kevin.vanzonneveld.net)
    // +   input by: Matteo
    // +   bugfixed by: Brett Zamir (http://brett-zamir.me)
    // *     example 1: intval('Kevin van Zonneveld');
    // *     returns 1: 0
    // *     example 2: intval(4.2);
    // *     returns 2: 4
    // *     example 3: intval(42, 8);
    // *     returns 3: 42
    // *     example 4: intval('09');
    // *     returns 4: 9
    // *     example 5: intval('1e', 16);
    // *     returns 5: 30
    var tmp;
 
    var type = typeof( mixed_var );
 
    if (type === 'boolean') {
        return (mixed_var) ? 1 : 0;
    } else if (type === 'string') {
        tmp = parseInt(mixed_var, base || 10);
        return (isNaN(tmp) || !isFinite(tmp)) ? 0 : tmp;
    } else if (type === 'number' && isFinite(mixed_var) ) {
        return Math.floor(mixed_var);
    } else {
        return 0;
    }
}

function yesno( val ){
	if( val == 0 || val == "" || val == null ) {
		return "Ne";
	}else{
		return "Ano";
	}
}

function yesno_radio( val, id, xtable ){
	if( val == 0 || val == "" || val == null ) {
		cache =	'A<input type="radio" value="1" name="active'+id+'" onclick="xactivate(\''+xtable+'\', '+id+', 1)" /> | '+
				'N<input type="radio" value="1" name="active'+id+'" onclick="xactivate(\''+xtable+'\', '+id+', \'0\')" checked="checked" />';
		
		return cache;
	}else{
		cache =	'A<input type="radio" value="1" name="active'+id+'" onclick="xactivate(\''+xtable+'\', '+id+', 1)" checked="checked" /> | '+
				'N<input type="radio" value="1" name="active'+id+'" onclick="xactivate(\''+xtable+'\', '+id+', \'0\')" />';
		
		return cache;
	}
}


function clear_inputs( url ) {
	var input = document.getElementsByTagName("input");
	
	for( x = 0; x < input.length; x++ ) {
		if( input[x].getAttribute("type") == "text" || input[x].getAttribute("name") == "id" )
			input[x].value = "";
	}
	
	document.inup_form.action = url;
}
/*
** ESHOP:
*/

function recount_price( method, dph_id ) {
    var dph_sel = document.getElementById( "dph_sel" );
	
	if( dph_sel.getElementsByTagName("option").length > 0 ) {
		
		dph = 1 + ( dph_sel.options[ dph_sel.selectedIndex ].title / 100 );
	
		switch( method ) {
			case 1:
				$('#price').val( Math.floor( $('#price_dph').val() / dph ) );
				break;
			
			case 0:
				$('#price_dph').val( Math.ceil( $('#price').val() * dph ) );
				break;
		}
	
	}
}

function recount_price2( method, dph_id ) {
    var dph_sel = document.getElementById( "dph_sel" );
	
	if( dph_sel.getElementsByTagName("option").length > 0 ) {
		
	dph = 1 + ( dph_sel.options[ dph_sel.selectedIndex ].title / 100 );
	
		switch( method ) {
			case 1:
				$('#price2').val( Math.floor( $('#price_dph2').val() / dph ) );
				break;
			
			case 0:
				$('#price_dph2').val( Math.ceil( $('#price2').val() * dph ) );
				break;
		}
	
	}
}

/*
** MENU:
*/
function menu_insert_new() {
	document.menu_form.text.value	= "";
	document.menu_form.url.value	= ""
	document.menu_form.id.value		= ""
	document.menu_form.action		= "/admin/menu/pridat"
}

function input_clear( name ) {
	document.getElementsByName( name ).item(0).value = "";
}

/*
** CLENOVE / uzivatele
*/
function mem_load_address() {
	var x = document.getElementById("mem_addr_list");
	string = x.options[x.selectedIndex].text;
	
	parts	= string.split(", ");
	koko	= parts[0].split(" ");
	strpc	= parts[2].split(" ");
	
	document.addr_form.id.value			= x.options[x.selectedIndex].value;
	document.addr_form.name.value		= koko[0];
	document.addr_form.surname.value	= koko[1];
	document.addr_form.city.value		= parts[1];
	
	if( strpc.length == 2 ) {
		document.addr_form.street.value		= strpc[0];
		document.addr_form.house_num.value	= strpc[1];
	}else{
		document.addr_form.street.value = "";
		for( x = 0; x < strpc.length - 1; x++ ) {
			document.addr_form.street.value += strpc[ x ] + " ";
		}
		
		document.addr_form.house_num.value	= strpc[ (strpc.length - 1) ];
	}
	
	document.addr_form.zip_code.value	= parts[3];
	document.addr_form.country.value	= x.options[x.selectedIndex].title;
}

/**********/

