//
// JQUERY
//

$(document).ready(function() {
	// menu
	$('#sf-menu').superfish({
		delay:			200,
		speed:			'fast',
		autoArrows:	true 
	}); 
	// hodinky
	var options2 = {
		format: '%A, %d. %b %Y | %H:%M:%S' // 24-hour
	}
	$('#jclock2').jclock(options2); 
	// PNG FIX IE
	$(document).pngFix();
	// lightbox
	$("a.lightbox").fancybox({
		'padding' 	: '0',
		'margin' 	: '0',
		'titlePosition' 	: 'over',
		'titleFormat'       : function(title, currentArray, currentIndex, currentOpts) {
		    return '<span id="fancybox-title-over">' +  (currentIndex + 1) + ' / ' + currentArray.length + ' ' + title + '</span>';
		}
	});
	// nahlad stranky
	$(".preview").fancybox({
		'width'				: '75%',
		'height'			: '75%',
		'autoScale'		: false,
		//'overlayShow'	:	false,
		'padding' 	: '0',
		'margin' 	: '0',
		'titlePosition' 	: 'over',
		'type'				: 'iframe'
	});
	// zobrazenie okna
	$(".metar").fancybox({
		'width'				: 600,
		'height'			: 450,
		'padding'			: '0',
		'margin'			: '0',
		//'modal'				: true,
		'autoScale'		: false,
		'titleShow'		: false,
		'type'				: 'iframe'
	});	
	// zobrazenie okna
	$(".reakcia_inzerat").fancybox({
		'width'				: 540,
		'height'			: 470,
		'padding'			: '0',
		'margin'			: '0',
		//'modal'				: true,
		'autoScale'		: false,
		'titleShow'		: false,
		'type'				: 'iframe'
	});	
});

//
// ODOSLANIE FORMULARU
//

function move(target){
	document.getElementById('multiple_form').action = target;
	document.getElementById('multiple_form').submit();
}

//
// POTVRDENIE (ZMAZANIA)
//

function jsconfirm(thetext){
	return confirm(thetext);
}

function init(){
	if (!document.layers) return;
	var box = document.getElementById('custom-form').elements;
	for (var i=0;i<box.length;i++){
		box[i].disabled = true;
	}
}
function disableIt(obj){
	obj.disabled = !(obj.disabled);
	var z = (obj.disabled) ? 'disabled' : 'enabled';
}
function extracheck(obj){
	return !obj.disabled;
}

//
// ZOBRAZENIE, SKYTIE BLOKOV (FOTOGALERIE)
//

function toggle5(showHideDiv, switchImgTag, showImage, hideImage) {
	var ele = document.getElementById(showHideDiv);
	var imageEle = document.getElementById(switchImgTag);
	if(ele.style.display == "block") {
		ele.style.display = "none";
		imageEle.innerHTML = '<img src="'+ showImage +'" alt="zobraziť" />';
	}
	else {
		ele.style.display = "block";
		imageEle.innerHTML = '<img src="'+ hideImage +'" alt="skryť" />';
	}
}

//
// DISKUSIE
//

// pocitadlo znakov
function textCounter(source, target, maxlimit) {
	var field = document.getElementById(source);
	var status = document.getElementById(target);
	if (field.value.length > maxlimit) { 
		field.value = field.value.substring(0, maxlimit);
	}
	else {
		status.innerHTML = maxlimit - field.value.length;
	}
}

// validacia
function validate_required(field,alerttxt){
	with (field){
		if (value==null||value==""){
			alert(alerttxt);return false;
		}else{
			return true;
		}
	}
}

function validate_form(thisform){
	with (thisform){
		// kontrola nadpisu
		if (validate_required(title,"Nezadali ste nadpis Vášho príspevku")==false)
		{title.focus();return false;}
		// obsah
		if (validate_required(text,"Nezadali ste text Vášho príspevku")==false)
		{text.focus();return false;}
	}
}

function changeCommentText(id){
	// zobrazeny text 
	var comments = document.getElementById('comments_' + id);
	// originalny text
	var origComments = document.getElementById('origComments_' + id);
	// odkaz
	var link = document.getElementById('showOrig_' + id);
	
	if(comments.style.display == "block") {
		comments.style.display = "none";
		origComments.style.display = "block";
		link.innerHTML = 'skryť';		
	}
	else {
		comments.style.display = "block";
		origComments.style.display = "none";
		link.innerHTML = 'zobraziť';
	}
}

//
// STAR RATING
//

function datosServidor() {
};
datosServidor.prototype.iniciar = function() {
	try {
		// Mozilla / Safari
		this._xh = new XMLHttpRequest();
	} catch (e) {
		// Explorer
		var _ieModelos = new Array(
		'MSXML2.XMLHTTP.5.0',
		'MSXML2.XMLHTTP.4.0',
		'MSXML2.XMLHTTP.3.0',
		'MSXML2.XMLHTTP',
		'Microsoft.XMLHTTP'
		);
		var success = false;
		for (var i=0;i < _ieModelos.length && !success; i++) {
			try {
				this._xh = new ActiveXObject(_ieModelos[i]);
				success = true;
			} catch (e) {
			}
		}
		if ( !success ) {
			return false;
		}
		return true;
	}
}

datosServidor.prototype.ocupado = function() {
	estadoActual = this._xh.readyState;
	return (estadoActual && (estadoActual < 4));
}

datosServidor.prototype.procesa = function() {
	if (this._xh.readyState == 4 && this._xh.status == 200) {
		this.procesado = true;
	}
}

datosServidor.prototype.enviar = function(urlget,datos) {
	if (!this._xh) {
		this.iniciar();
	}
	if (!this.ocupado()) {
		this._xh.open("GET",urlget,false);
		this._xh.send(datos);
		if (this._xh.readyState == 4 && this._xh.status == 200) {
			return this._xh.responseText;
		}
		
	}
	return false;
}


function _gr(reqseccion,divcont) {
	remotos = new datosServidor;
	nt = remotos.enviar(reqseccion,"");
	document.getElementById(divcont).innerHTML = nt;
}


function rateImg(rating,id,state)  {
	if (state==1) {
		remotos = new datosServidor;
		nt = remotos.enviar('index.php?rating='+rating+'&comments_id='+id);
		alert('Ďakujeme za Váš hlas');
		rating = rating * 20;
		document.getElementById('current-rating-'+id).style.width = rating+'px';
		document.getElementById('ratelinks-'+id).style.display = 'none';
		document.getElementById('ratingtext-'+id).innerHTML = 'Ďakujeme za Váš hlas';
	}
	else {
		document.getElementById('ratingtext-'+id).innerHTML = 'Ľutujeme, ale Váš hlas je už zaznamenaný.';
		alert('Ľutujeme, ale Váš hlas je už zaznamenaný');
	}
}

