/* DEFAULT PREMENNE */
var show_extended_popis = 0;
var now_playing = 0;

/* COOKIES */
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);
}

/* MANIPULACIA S FORMULARMI */
function clearSelect(el) {
	loops = el.options.length;
	for (f = 0; f < loops; f++) {
		el.options[0] = null;
	}
}

function selectActive(el,val) {
	for (f = 0; f < el.options.length; f++) {
		if (el.options[f].value == val) {
			el.options[f].selected = true;
			break;
		}
	}			
}

function fillSelect(el,pid) {
	clearSelect(el);
	el.options[0] = new Option('Model:',0);
	loop = 1;
	for (ph in makers[pid]) {
		el.options[loop] = new Option(ph,makers[pid][ph]);
		loop++;
	}
}

var checkedBoxes = 0;
var maxCheckedFields = 0;
function keepMaxValues(el) {
	if (el.checked == true) {
		checkedBoxes++;
		if (checkedBoxes > maxCheckedFields) {
			el.checked = false;
			checkedBoxes--;
			window.alert('Po\u010Det maxim\u00E1lne vybrate\u013En\u00FDch prvkov: ' + maxCheckedFields);
		}
	} else checkedBoxes--;
}

function copyMSISDN(direction) {
	el = getElement('mms');
	if (direction == 'to_rcpt') {
		el.tel_cislo.value = el.tel_cislo_payment.value;
		el.predvolba.value = el.predvolba_payment.value;
	} else if (direction == 'to_sender') {
		el.tel_cislo_payment.value = el.tel_cislo.value;
		el.predvolba_payment.value = el.predvolba.value;
	}
	checkCopy();
}

function checkCopy() {
	el = getElement('mms');
	same_number = (el.tel_cislo.value == el.tel_cislo_payment.value && el.predvolba.value == el.predvolba_payment.value) ? 1 : 0;
	getElement('copy_to_rcpt').style.display = (el.tel_cislo_payment.value.length == 6 && !same_number) ? 'inline' : 'none';
	getElement('copy_to_sender').style.display = (el.tel_cislo.value.length == 6 && !same_number) ? 'inline' : 'none';
}

function submitSearch(el) {
	var retVal = true;
	if (el.search_string.value.length > 2) {
		id = (el.id && el.id.value) ? el.id.value : 1401;
		switch (el.sid.value) {
			case '-1':
				location.href = '!pages.get?partner=c3&id=1404&follow='+encodeURL('/tzones/java/content.php?search_string='+el.search_string.value);
				retVal = false;
				break;
			default:
				location.href = '!pages.get?partner=c2&id='+id+'&follow='+encodeURL('index?sid='+el.sid.value+'&search_string='+el.search_string.value+'&log=1');
				retVal = false;
				break;
		}
	} else {
		alert('H\u013Eadan\u00FD re\u0165azec mus\u00ED ma\u0165 najmenej 3 znaky.');
		retVal = false;
	}
	return retVal;
}

/* MANIPULACIA S OKNAMI */
function openVTWin(url,win) {
	newWindow = window.open(url,win,'top=200,left=300,width=450,height=372');
	if (newWindow && window.focus) {
		setTimeout('newWindow.focus();','500');
	}
}

function changeGroup(gr) {
	var c2_url = '/sk/!pages.get?partner=c2&id=1401&follow=index%3Faction%3Dcustom%26group%3D' + gr;
	document.location.href = c2_url;
}

function popup(name, url, height, width)
{
	var str = "height="+height+",innerHeight="+height;
	str += ",width="+width+",innerWidth="+width+",scrollbars=no,menubar=no,toolbar=no,status=no,resizable=no";
	str += ",left=0,screenX=0";
	str += ",top=0,screenY=0";
	window.open(url, name, str);
}

/* ROZNE */
function rnd(limit) {
	if (limit > 0) {
		return Math.floor(Math.random()*limit);
	} else {
		return 0;
	}
}

function c2_disclaimer_lite() {
	retVal = false;
	if (readCookie('c2_disclaimer')) {
		retVal = true;
	} else {
		if (confirm('Pre vstup do tejto sekcie musíte mať viac ako 18 rokov')) {
			createCookie('c2_disclaimer', 1, 1);
			retVal = true;
		}
	}
	return retVal;
}

// escape URL
function encodeURL(str) {
	str = str.replace(/\//g,"%2F");
	str = str.replace(/\?/g,"%3F");
	str = str.replace(/=/g,"%3D");
	str = str.replace(/&/g,"%26");
	str = str.replace(/@/g,"%40");
	return str;
}

/* FLASH MP3 PREVIEW */
function getFlashMovieObject(movieName) {
	if (window.document[movieName]) {
		return window.document[movieName];
	}
	if (navigator.appName.indexOf("Microsoft Internet")==-1){
		if (document.embeds && document.embeds[movieName])
			return document.embeds[movieName]; 
		} else { // if (navigator.appName.indexOf("Microsoft Internet")!=-1)
		return document.getElementById(movieName);
	}
}

function playMe(mid) {
	if (!mid) return false;
	var flashMovie=getFlashMovieObject('backgroundPlayer');
	if (!flashMovie) return false;

	if (mid != now_playing) {
		flashMovie.SetVariable('mid_frm',mid);
		flashMovie.Rewind();
		flashMovie.Play();
		now_playing = mid;
	} else {
		flashMovie.SetVariable('mid_frm',0);
		flashMovie.Stop();
		now_playing = 0;
	}
}

/* MOUSE AND ELEMENTS STUFF */
function getElement(el) {
	if (document.getElementById) {
		el = document.getElementById(el);
	} else if (document.all) {
		el = document.all.item(el);
	} else {
		el = null;
	}
	return el;
}

function getElementsByClass(searchClass,node,tag) {
	var classElements = new Array();
	if ( node == null )
		node = document;
	if ( tag == null )
		tag = '*';
	var els = node.getElementsByTagName(tag);
	var elsLen = els.length;
	var pattern = new RegExp('(^|\\s)'+searchClass+'(\\s|$)');
	for (i = 0, j = 0; i < elsLen; i++) {
		if ( pattern.test(els[i].className) ) {
			classElements[j] = els[i];
			j++;
		}
	}
	return classElements;
}

function highlightLogin(status) {
    el = getElementsByClass('c0pravemenu', document.getElementById('LoginBox'), 'div');
   	if (el[0]) el[0].style.backgroundColor = status ? '#E20074' : '#E4E4E4';
}


function displayFintuSend() {
	getElement('mms').innerHTML += '<inp'+'ut typ'+'e="hi'+'dden" nam'+'e="fi'+'nta" va'+'lue="zapn'+'uta">';
}

function search()
{
	if(document.c2_search_form.search_string.value == '') {
		window.alert('Zadaj názov skladby, meno interpreta alebo kapely!');
		return false;
	}
	if(document.c2_search_form.search_string.value.length < 2) {
		window.alert('Názov skladby, meno interpreta alebo kapely musé mať aspoň 2 znaky!');
		return false;
	}
	document.c2_search_form.submit();
	return true;
}
