// CONGIF //
var webroot = '/mozaika/web/';

function checkLibs(text) {
	var Libs = eval('(' + text + ')');
	for (var i=0;i<Libs.length;i++) {
		var id = Libs[i].Lib.id;
//		alert(id);
		var status = Libs[i].Lib.status;
		var statusnaz = Libs[i].Status.nazov;
		var percent = Libs[i].Lib.progress;

		var numfoto = Libs[i].Lib.numfiles;
		var sizefoto = ((Libs[i].Lib.size/1000000)*100).round()/100;

		var stat = Libs[i].ajax.status;
		var progress = Libs[i].ajax.progress;
		var pxprogress = 140/100*progress;
//		alert(progress);

		if(status == '2') {
			$('progressbar'+id).innerHTML = statusnaz;
			$('num'+id).innerHTML = numfoto;
			$('size'+id).innerHTML = sizefoto+' MB';
			$('del'+id).appear();
		}
		else {
			$('progressbar'+id).innerHTML = percent;
		}
		$('progressbar'+id).morph('width: '+pxprogress.round()+'px;');
	}
				 
//		alert(Pics[i].Pic.id);
	}

function checkPics(text) {
	var Pics = eval('(' + text + ')');
	for (var i=0;i<Pics.length;i++) {
		var id = Pics[i].Pic.id;
		var status = Pics[i].Pic.status;
		var statusnaz = Pics[i].Status.nazov;
		var percent = Pics[i].Pic.progress;

		var imgcheck = Pics[i].ajax.img.check;
		var imgworking = Pics[i].ajax.img.working;
		var imgred = Pics[i].ajax.img.red;

		var vysledok = Pics[i].ajax.files.vysledok;
		var nahlad = Pics[i].ajax.files.nahlad;
		var nahladfull = Pics[i].ajax.files.nahladfull;

		var pxprogress = 200/100*percent;
		if (status == 1) {
			document.getElementById('status'+id).innerHTML = '<img src="'+imgworking+'" title="'+statusnaz+'">';					
			document.getElementById('progressbar'+id).innerHTML = percent;					
			document.getElementById('progresstext'+id).style.display = 'none';
			document.getElementById('del'+id).style.display = 'none';
			document.getElementById('cena'+id).style.display = 'none';
			document.getElementById('kupit'+id).style.display = 'none';
		}
		else if (status == 0) {
			document.getElementById('progressbar'+id).innerHTML = percent;					
			document.getElementById('progresstext'+id).style.display = 'none';
			document.getElementById('del'+id).style.display = 'none';
			document.getElementById('cena'+id).style.display = 'none';
			document.getElementById('kupit'+id).style.display = 'none';
		}
		else if (status == 2) {
			document.getElementById('progressbar'+id).innerHTML = statusnaz;					
			document.getElementById('status'+id).innerHTML = '<img src="'+imgcheck+'" title="'+statusnaz+'">';					
			$('progresstext'+id).innerHTML=nahladfull+' '+nahlad;
			$('progressbar'+id).blindUp();
			$('progresstext'+id).appear();
			$('del'+id).appear();
			$('cena'+id).appear();
			$('kupit'+id).appear();
		}
		$('progressbar'+id).morph('width: '+pxprogress.round()+'px;');
		 
	}
}

function checkPicsold(text) {
	var Pics = eval('(' + text + ')');
	for (var i=0;i<Pics.length;i++) {
		var id = Pics[i].Pic.id;
		var status = Pics[i].Pic.status;
		var statusnaz = Pics[i].Status.nazov;
		var percent = Pics[i].Pic.progress;

		var stat = Pics[i].ajax.status;
		var progress = Pics[i].ajax.progress;
		var akcia = Pics[i].ajax.akcia;

		document.getElementById('akcia'+id).innerHTML = akcia;
		document.getElementById('status'+id).innerHTML = stat;
		document.getElementById('progress'+id).innerHTML = progress;
		 
	}
}

// formulare

	function htmlSelectMoveDown(selectId) {	
		selectEl=selectId;
		var currentIdx=selectEl.selectedIndex;
		
		if (currentIdx < selectEl.options.length-1) {
			var currentOption=selectEl.options[currentIdx];	
			selectEl.remove(currentIdx);
			try {
				//FF
				selectEl.add(currentOption, selectEl.options[currentIdx+1]);
			} catch(ex) {
				//IE
				selectEl.add(currentOption, currentIdx+1);				
			}
		}
	}
	
	function htmlSelectMoveUp(selectId) {	
		selectEl=selectId;
		var currentIdx=selectEl.selectedIndex;
		
		if (currentIdx > 0) {
			var currentOption=selectEl.options[currentIdx];	
			selectEl.remove(currentIdx);
			try {
				//FF
				selectEl.add(currentOption, selectEl.options[currentIdx-1]);
			} catch(ex) {
				//IE
				selectEl.add(currentOption, currentIdx-1);
			}
		}
	}	
	
//cookies: http://www.quirksmode.org/js/cookies.html

function createCookie(name,value,days) {
	if (days) {
		var date = new Date();
		date.setTime(date.getTime()+(days*24*60*60*1000));
		var expires = "; expires="+date.toGMTString();
	}
	else var expires = "";
	document.cookie = name+"="+value+expires+"; path=/";
}

function readCookie(name) {
	var nameEQ = name + "=";
	var ca = document.cookie.split(';');
	for(var i=0;i < ca.length;i++) {
		var c = ca[i];
		while (c.charAt(0)==' ') c = c.substring(1,c.length);
		if (c.indexOf(nameEQ) == 0) return c.substring(nameEQ.length,c.length);
	}
	return null;
}

function eraseCookie(name) {
	createCookie(name,"",-1);
}

//klavesy:
function skontrolujEnter(e) {
	var evt=(e)?e:(window.event)?window.event:null; 
	if(evt){ 
		var key=(evt.charCode)?evt.charCode: ((evt.keyCode)?evt.keyCode:((evt.which)?evt.which:0)); 
		return key=="13"; 
	}
	return false;
}


