function sendmail(user,domain) {
	locationstring = "mailto:" + user + "@" + domain ;
	window.location = locationstring; 
}
function checkformjs(jezyk) {
	var formularz = document.forms[0];
	if (formularz.comment.value == "") {
		if (jezyk == "pl") {
			alert( "Nie wprowadziłeś tekstu!" );
		} else {
			alert( "Please enter your message" );
		}
		formularz.comment.focus();
		return false;
	}
}
function checknewsformjs() {
	var formularz = document.forms[0];
	if (formularz.where.value == "--") {
		alert( "Choose where the news should be added" );
		formularz.where.focus();
		return false;
	}
}
function checkcompetitionformjs(jezyk) {
	var formularz = document.forms[0];
	if (formularz.imie.value == "") {
		if (jezyk == "pl") {
			alert( "Nie podałeś imienia" );
		} else {
			alert( "Please enter your name" );
		}
		formularz.imie.focus();
		return false;
	}
	if (formularz.nazwisko.value == "") {
		if (jezyk == "pl") {
			alert( "Nie podałeś nazwiska" );
		} else {
			alert( "Please enter your surname" );
		}
		formularz.nazwisko.focus();
		return false;
	}
	if (formularz.email.value == "") {
		if (jezyk == "pl") {
			alert( "Nie podałeś adresu e-mail" );
		} else {
			alert( "Please enter e-mail address" );
		}
		formularz.email.focus();
		return false;
	}
	if (formularz.odp.value == "") {
		if (jezyk == "pl") {
			alert( "Nie podałeś odpowiedzi!" );
		} else {
			alert( "Please enter your answer" );
		}
		formularz.odp.focus();
		return false;
	}
}

function ShowGallery(aid, fid, lng)
{
	var newwindow = '';
	var url = "gallery-" + aid + "-" + fid + "-" + lng +".html";
	
	if (!newwindow.closed && newwindow.location) {
		newwindow.location.href = url;
	}
	else
	{
		newwindow=window.open(url, "gwin", "width=800, height=465");
		if (!newwindow.opener) newwindow.opener = self;
	}
	if (window.focus) 
	{
		newwindow.focus()
	}
	
}

function ShowCompetition(sec, sid, lng)
{
	window.open("competition.php?section=" + sec + "&id=" + sid + "&lang=" + lng, "comp", "width=300, height=500");
}

function ShowFS(img, lng)
{
	window.open("showfs.php?img=" + img + "&lang=" + lng, "fswin", "fullscreen=yes, scrollbars=auto");
}

function OpenInParent(uid)
{
	var url = "board/profile.php?mode=viewprofile&u=" + uid;
	top.opener.location.href = url;
	top.opener.focus();
	self.close();
}

function PopUp(plink)
{
	window.open(plink, "whelp", "width=300, height=500");
}

function ReloadandClose()
{
	opener.location.reload(true);
	self.close();
}
function getAjax() {
	var xmlHttp;
	try {
		// Firefox, Opera 8.0+, Safari
		xmlHttp=new XMLHttpRequest();
	}
	catch (e) {
		// Internet Explorer
		try {
			xmlHttp=new ActiveXObject("Msxml2.XMLHTTP");
		}
	catch (e) {
		try {
			xmlHttp=new ActiveXObject("Microsoft.XMLHTTP");
	    }
    catch (e) {
			alert("Your browser does not support HTTP Requests!");
			return false;
		}
	}
	}
return xmlHttp;
}

function dspPhotos(path, aImg, id, key) {
	var mainImg = path + "375/" + aImg[id][0];
	var currImg = path + "thumbs/" + aImg[id][0];
	if (aImg[id-1]) {
		var prevImg = path + "thumbs/" + aImg[id-1][0];
	}
	if (aImg[id+1]) {
		var nextImg = path + "thumbs/" + aImg[id+1][0];
	}
	var hitsUrl = "/_ajax/hits.php?section=photos&id=" + aImg[id][1] + "&key=" + key + "&" + Math.random();
	
	//save hit
	if (!path.match("artists")) {
		xmlHttp = getAjax();
		xmlHttp.open("GET", hitsUrl, true);
		xmlHttp.send(null);
	}
	
	document.getElementById("nphoto").innerHTML = '(' + (id+1) + '/' + aImg.length + ')';
	
	//replace images
	//document.getElementById("loader").style.display="block";
	document.getElementById("mainImg").src=mainImg;
	document.getElementById("mainImg").alt=aImg[id][0];
	//document.getElementById("loader").style.display="none";
	
	document.getElementById("currImg").src=currImg;
	document.getElementById("currImg").alt=aImg[id][0];
	
	var prev = document.getElementById("prevImg");
	var next = document.getElementById("nextImg");
	
	if (aImg[id-1]) {
		prev.src=prevImg;
		prev.alt=aImg[id-1][0];
		prev.onclick = function() {dspPhotos(galleryPath, aImg, curImgId-1, key)};
		prev.onmouseover = function() {this.style.cursor='pointer'};
		prev.className = 'left mb5';
		prev.style.display = 'block';
	} else {
		prev.alt="";
		prev.onmouseover = function() {this.style.cursor='default'};
		prev.src="";
		prev.style.display = 'none';
	}
	
	if (aImg[id+1]) {
		next.src=nextImg;
		next.alt=aImg[id+1][0];
		next.onclick = function() {dspPhotos(galleryPath, aImg, curImgId+1, key)};
		next.onmouseover = function() {this.style.cursor='pointer'};
		next.className = 'left mb5';
		next.style.display = 'block';
	} else {
		next.alt="";
		next.onmouseover = function() {this.style.cursor='default'};
		next.src="";
		next.style.display = 'none';
	}

	curImgId = id;
	
}

function dspPhotoFS(path, aImg, id) {
	var mainImg = path + aImg[id][0];
	
	window.open(mainImg, "fswin", "width=820, height=820");
	curImgId = id;
}


function saveVote(section, section_id, category_id, vote, nofcat, lang, token) {
	var divId = 'cat'+category_id;
	var saveUrl = '/_ajax/rating.php?action=save&section=' + section + '&section_id=' + section_id + '&category=' + category_id + '&vote=' + vote +'&token=' + token + '&rnd=' + Math.random();

	document.getElementById(divId).style.width = vote * 18 + 'px';
	document.getElementById('user_all').innerHTML = (lang == 'pl'? 'Twój głos' : 'Your vote');
	document.getElementById('whose_votes').innerHTML = (lang == 'pl'? 'Wszystkie głosy' : 'All users rating');
	
	var x=document.getElementById("nvotes");
	if (x) {
		x.parentNode.removeChild(x);
	}
	
	var xmlHttp = getAjax();
	xmlHttp.onreadystatechange=function() {
		if(xmlHttp.readyState==4) {
			document.getElementById('errormsg').innerHTML = xmlHttp.responseText;
			setTimeout("clearElementText('errormsg');", 1000);
			getUserVotes(section, section_id, nofcat);
		}
    }	
	xmlHttp.open("GET", saveUrl, true);
	xmlHttp.send(null);
}

function clearElementText(id) {
	document.getElementById(id).innerHTML = '';
}

function getUserVotes(section, section_id, nofcat) {
	var ajaxUrl = '/_ajax/rating.php?action=getuser&section=' + section + '&section_id=' + section_id + '&nofcat=' + nofcat + '&rnd=' + Math.random();

	var xmlHttp = getAjax();
	xmlHttp.onreadystatechange=function() {displayVotes(xmlHttp);};
	xmlHttp.open('GET', ajaxUrl, true);
	xmlHttp.send(null);
}

function getAllVotes(section, section_id, nofcat) {
	var ajaxUrl = '/_ajax/rating.php?action=getall&section=' + section + '&section_id=' + section_id + '&nofcat=' + nofcat + '&rnd=' + Math.random();

	var xmlHttp = getAjax();
	xmlHttp.onreadystatechange=function() {displayVotes(xmlHttp);};
	xmlHttp.open('GET', ajaxUrl, true);
	xmlHttp.send(null);
}

function displayVotes(xmlHttp){
	if(xmlHttp.readyState == 4) {
		var votes = xmlHttp.responseText;
		var x = document.getElementById('w400').getElementsByTagName("div");
		var c = 0;
		for (i = 0; i < x.length; i++) {
			if (x[i].id.substr(0,3) == 'cat') {
				var category_id = x[i].id.substr(3,1);
				document.getElementById('cat'+category_id).style.width = votes.substr(c,4) * 18 + 'px';
			}
			if (x[i].id.substr(0,5) == 'nvote') {
				var category_id = x[i].id.substr(5,1);
				document.getElementById('nvote'+category_id).innerHTML =
					(votes.substr(c,4) == '0.00' ? '-' : votes.substr(c,4));
				c+=4;
			}
		}
	}
}
function switchVotes(section, section_id, nofcat, lang) {
	if (typeof(document.user_all) == 'undefined') {
		document.user_all = 'user';
	}
	if (document.user_all == 'all') {
		getAllVotes(section, section_id, nofcat);
		document.getElementById('user_all').innerHTML = (lang == 'pl'? 'Wszystkie głosy' : 'All users rating');
		document.getElementById('whose_votes').innerHTML = (lang == 'pl'? 'Twój głos' : 'Your vote');
		document.user_all = 'user';
	} else {
		getUserVotes(section, section_id, nofcat);
		document.getElementById('user_all').innerHTML = (lang == 'pl'? 'Twój głos' : 'Your vote');
		document.getElementById('whose_votes').innerHTML = (lang == 'pl'? 'Wszystkie głosy' : 'All users rating');
		var x=document.getElementById("nvotes");
		if (x) {
			x.parentNode.removeChild(x);
		}
		document.user_all = 'all';		
	}
}
function dspVoteExplained(text, cat_id, vote) {
	dspText = vote;
	if (cat_id == 0) {
		dspText = text;
	}
	document.getElementById('nvote'+cat_id).innerHTML = dspText;
}
function dspNvote(nvote, cat_id) {
	document.getElementById('nvote'+cat_id).innerHTML = nvote;
}
function jsArtTitle(section, id) {
	xmlHttp = getAjax();
	xmlHttp.onreadystatechange=function() {
		if(xmlHttp.readyState==4) {
		  document.getElementById("arttitle").innerHTML = xmlHttp.responseText;
		}
    }	
	xmlHttp.open("GET", "_ajax/arttitle.php?section="+section+"&id="+id, true);
	xmlHttp.send(null);
}

function jsValidateFiles(aFiles) {
	var filesOK = "true";
	var title = document.getElementById("arttitle").innerHTML;
	
	if (title == 'Unknown') {
		alert("Please make sure that section and id are correct");
		filesOK = "false";
	}
	
	for (i=0; i < aFiles.length; ++i) {
		document.getElementById("error"+i).innerHTML = '';
		document.getElementById("ufile"+i).setAttribute('class', '');
	}

	if (!document.getElementById("ufile0").value) {
		alert ("First upload slot cannot be empty");
		filesOK = "false";
	}

	for (i=0; i < aFiles.length; ++i) {
	    var uFile = document.getElementById("ufile"+i).value;
		
		if (uFile) {
			if (uFile.substr(uFile.length-4).toLowerCase() !== '.jpg') {
				document.getElementById("error"+i).innerHTML = "Error: File ".fontcolor("Red") + uFile + " is not in .jpg format".fontcolor("Red");
				document.getElementById("ufile"+i).setAttribute('class', 'redborder');
				filesOK = "false";
			}
		}
	}
	if (filesOK == "false") {
		return false;
	} else {
		return true;
	}
}

function showGuestlistForm() {
	document.getElementById("guestlist").style.display="block";
}
function saveGuestlist(lang, id, token) {
	message = (lang == 'pl' ? 'Twoj glos zostal zapisany' : 'Your vote has been saved');
	name = document.getElementById("name").value;
	xmlHttp = getAjax();
	xmlHttp.onreadystatechange=function() {
		if(xmlHttp.readyState==4) {
			if (xmlHttp.responseText.substr(0,2) == 'OK') {
				document.getElementById("guestlist").style.display="none";
				document.getElementById("submit_button").style.display="none";
				document.getElementById("put_guestlist").innerHTML = message;
			} else {
				alert(xmlHttp.responseText);
			}
		}
    }	
	xmlHttp.open("GET", "_ajax/saveglist.php?id="+id+"&token="+token+"&name="+name, true);
	xmlHttp.send(null);	
}
function startDwn(id) {
	document.getElementById("dwnlink").innerHTML = "Please wait...";
	setTimeout("window.location='"+"_ajax/getdwnlink.php?id="+id+"'",500);
	document.getElementById("dwnlink").innerHTML = "Download started";
}
function validateField(type, element, required) {
	var go = true;
	if (required && element.value=='') {
		document.getElementById("m"+element.id).innerHTML = 'Error: required field'.fontcolor("Red");
		go = false;
    } else {
		document.getElementById("m"+element.id).innerHTML = 'OK'.fontcolor("Green");
		go = true;
    }
	
	if (go && type == 'email') {
		apos=element.value.indexOf("@");
		dotpos=element.value.lastIndexOf(".");
		if (apos<1 || dotpos-apos<2) {
			document.getElementById("m"+element.id).innerHTML = 'Not a valid email'.fontcolor("Red");
			go = false;
		} else {
			document.getElementById("m"+element.id).innerHTML = 'OK'.fontcolor("Green");
			go = true;
		}
    }

	if (go && type == 'www') {
		dotpos=element.value.lastIndexOf(".");
		if (dotpos<2) {
			document.getElementById("m"+element.id).innerHTML = 'Not a valid url'.fontcolor("Red");
			go = false;
		} else {
			document.getElementById("m"+element.id).innerHTML = 'OK'.fontcolor("Green");
			go = true;
		}
    }
	
	if (go && type == 'hour') {
		var time = element.value;
		cpos = element.value.indexOf(":");
		if (cpos > 2 || cpos < 1) {
			document.getElementById("m"+element.id).innerHTML = 'Not a valid time format (HH:MM)'.fontcolor("Red");
			go = false;
		}
		if (go) {
			var tmptime = time.replace(/:/, '');
			if (tmptime != parseFloat(tmptime)) {
				document.getElementById("m"+element.id).innerHTML = 'Invalid time (only numbers please)'.fontcolor("Red");
				go = false;
			}
		}
		if (go) {
			var hour = time.substr(0,cpos);
			if (hour > 24 || hour < 0) {
				document.getElementById("m"+element.id).innerHTML = 'There is no such time (hour)'.fontcolor("Red");
				go = false
			}
		}
		if (go) {
			var minutes = time.substr(cpos+1,2);
			if (minutes > 59 || minutes < 0) {
				document.getElementById("m"+element.id).innerHTML = 'There is no such time (minute)'.fontcolor("Red");
				go = false
			}
		}
	}
	
	if (!go) {
		return false;
	}
	document.getElementById("m"+element.id).innerHTML = 'OK'.fontcolor("Green");
	return true;

}
function searchClub(element) {
	//thanks to http://www.dynamicajax.com/fr/AJAX_Suggest_Tutorial-271_290_312.html
	xmlHttp = getAjax();
	if (xmlHttp.readyState == 4 || xmlHttp.readyState == 0) {
		var str = escape(element.value);
		xmlHttp.open("GET", '_ajax/searchclub.php?search=' + str, true);
		xmlHttp.onreadystatechange = handleSearchSuggest; 
		xmlHttp.send(null);
	}			
}
function handleSearchSuggest() {
	if (xmlHttp.readyState == 4) {
		var ss = document.getElementById('search_suggest')
		ss.innerHTML = '';
		var str = xmlHttp.responseText.split("\n");
		for(i=0; i < str.length - 1; i++) {
			//Build our element string.  This is cleaner using the DOM, but
			//IE doesn't support dynamically added attributes.
			var suggest = '<div onmouseover="javascript:suggestOver(this);" ';
			suggest += 'onmouseout="javascript:suggestOut(this);" ';
			suggest += 'onclick="javascript:setSearch(this.innerHTML);" ';
			suggest += 'class="suggest_link">' + str[i] + '</div>';
			ss.innerHTML += suggest;
		}
	}
}
function suggestOver(div_value) {
	div_value.className = 'suggest_link_over';
}
function suggestOut(div_value) {
	div_value.className = 'suggest_link';
}

function setSearch(value) {
	document.getElementById('club').value = value;
	document.getElementById('search_suggest').innerHTML = '';

	idpos1=value.lastIndexOf("(");
	idpos2=value.lastIndexOf(")");
	if (idpos1==-1 || idpos2==-1 || idpos1>=idpos2) {
		document.getElementById("mclub").innerHTML = 'Not a valid club';
	} else {
		document.getElementById("mclub").innerHTML = 'OK'.fontcolor("Green");
		document.getElementById("clubid").value = value.substr(idpos1+1,idpos2-idpos1-1);
    }
}
function validateEvent() {
	if (document.getElementById('title').value == '') {
		document.getElementById('mtitle').innerHTML = 'Error: required field'.fontcolor("Red");
		document.getElementById("title").focus();
		return false;
	}
	if (document.getElementById('club').value == '') {
		document.getElementById('mclub').innerHTML = 'Error: Not a valid club'.fontcolor("Red");
		document.getElementById("club").focus();
		return false;
	}
	if (document.getElementById('genres').value == '') {
		document.getElementById('mgenres').innerHTML = 'Error: required field'.fontcolor("Red");
		document.getElementById("genres").focus();
		return false;
	}
	if (document.getElementById('cost').value == '') {
		document.getElementById('mcost').innerHTML = 'Error: required field'.fontcolor("Red");
		document.getElementById("cost").focus();
		return false;
	}
	if (document.getElementById('djs1').value == '' &&
		document.getElementById('djs2').value == '' &&
		document.getElementById('djs3').value == '') {
		alert("There's no line-up information given");
		document.getElementById("djs1").focus();
		return false;
	}
	
	var uFile = document.getElementById("image").value;
	if (uFile) {
		if (uFile.substr(uFile.length-4).toLowerCase() !== '.jpg') {
			document.getElementById("mimage").innerHTML = "Error: File "+ uFile + " is not in .jpg format".fontcolor("Red");
			document.getElementById("image").focus();
			return false;
		}
	}
	
	if (document.getElementById('give').value !== '' &&
		document.getElementById('give').value > 0 &&
		document.getElementById('email').value == '' ) {
		document.getElementById('memail').innerHTML = 'Enter e-mail address for the guestlist'.fontcolor("Red");
		document.getElementById("email").focus();
		return false;
	}
	
	if (document.getElementById('email').value !== '' ) {
		if (!validateField('email', document.getElementById('email'), true)) {
			document.getElementById("email").focus();
			return false;
		}
	}
	
	if (!document.getElementById('accept').checked) {
		document.getElementById('maccept').innerHTML = 'Error: You have to agree to the terms and conditions'.fontcolor("Red");
		document.getElementById('accept').focus();
		return false;
	}

	return true;	
}
function fetchClubEmail() {
	if (document.getElementById("email").value) {
		return;
	}
	club_id = document.getElementById("clubid").value;
	xmlHttp = getAjax();
	xmlHttp.onreadystatechange=function() {
		if(xmlHttp.readyState==4) {
			if (xmlHttp.responseText.trim !== '') {
				document.getElementById("email").value=xmlHttp.responseText;
				document.getElementById("glistclub").style.display="inline";
			}
		}
    }	
	xmlHttp.open("GET", "_ajax/clubemail.php?id="+club_id, true);
	xmlHttp.send(null);	
}
function validateClub() {
	if (document.getElementById('name').value == '') {
		document.getElementById('mname').innerHTML = 'Error: required field'.fontcolor("Red");
		document.getElementById("name").focus();
		return false;
	}
	if (document.getElementById('country').value == '') {
		document.getElementById('mcity').innerHTML = 'Error: required field'.fontcolor("Red");
		document.getElementById("country").focus();
		return false;
	}
	if (document.getElementById('city').value == '') {
		document.getElementById('mcity').innerHTML = 'Error: required field'.fontcolor("Red");
		document.getElementById("city").focus();
		return false;
	}
	if (document.getElementById('street').value == '') {
		document.getElementById('mstreet').innerHTML = 'Error: required field'.fontcolor("Red");
		document.getElementById("street").focus();
		return false;
	}
	if (document.getElementById('email').value !== '' ) {
		if (!validateField('email', document.getElementById('email'), true)) {
			document.getElementById("email").focus();
			return false;
		}
	}
	
	var uFile = document.getElementById("image").value;
	if (uFile) {
		if (uFile.substr(uFile.length-4).toLowerCase() !== '.jpg') {
			document.getElementById("mimage").innerHTML = "Error: File "+ uFile + " is not in .jpg format".fontcolor("Red");
			document.getElementById("image").focus();
			return false;
		}
	}
	
	if (!document.getElementById('accept').checked) {
		document.getElementById('maccept').innerHTML = 'Error: You have to agree to the terms and conditions'.fontcolor("Red");
		document.getElementById('accept').focus();
		return false;
	}

	return true;	
}
function validateFind() {
	if (document.getElementById('link').value == '') {
		document.getElementById('mlink').innerHTML = 'Error: required field'.fontcolor("Red");
		document.getElementById("link").focus();
		return false;
	}
	dotpos=document.getElementById('link').lastIndexOf(".");
	if (dotpos<2) {
		document.getElementById('mlink').innerHTML = 'Error: Not a valid url'.fontcolor("Red");
		return false;
	}	
	return true;	
}

function ShowPlayer(section, id)
{
	var newwindow = '';
	var url = "player.php?section=" + section + "&id=" + id;
	
	if (!newwindow.closed && newwindow.location) {
		newwindow.location.href = url;
	}
	else
	{
		newwindow=window.open(url, "pwin", "width=264, height=210");
		if (!newwindow.opener) newwindow.opener = self;
	}
	if (window.focus) 
	{
		newwindow.focus()
	}
	
}
function redirect(url) {
	window.location = 'board/login.php?redirect=' + url;
}
function regclick() {
	alert('aa');
}