$(document).ready(function() {
	$('#reviewCommentForm #name').keypress(function(e) {		
		if(e.keyCode == 13) { //enter was pressed
			return false;
		}
	});
	$(".fadeLink").css("opacity", "0.6");
	$(".fadeLink").bind("mouseenter", function(){
		$(this).fadeTo("normal", 1);
	});
	$(".fadeLink").bind("mouseleave", function(){
		$(this).fadeTo("normal", 0.6);
	});
	$('#reviewSearchForm #search').keypress(function(e) {		
		if(e.keyCode == 13) { //enter was pressed
			submitReviewSearchForm();
		}
	});
	$('#newsSearchForm #newsSearch').keypress(function(e) {		
		if(e.keyCode == 13) { //enter was pressed
			submitNewsSearchForm();
		}
	});
});
function start(){
	
}

function showTracklist(oSpan){
	var parent = oSpan.parentNode;
	aSpans = parent.getElementsByTagName("span");
	for(var i = 0; i<aSpans.length; i++){
		if(aSpans[i].getAttribute('name') == "tracklist"){
			if(aSpans[i].style.display == "none"){
				aSpans[i].style.display = "block";
				oSpan.innerHTML = "(hide tracklist)";
			}
			else{ 
				aSpans[i].style.display = "none";
				oSpan.innerHTML = "(show tracklist)";
			}
		}
	}
}

function showDetails(img, artist, title){
	document.getElementById("detailImage").src = img.src;
	document.getElementById("detailArtist").innerHTML = artist;
	document.getElementById("detailTitle").innerHTML = title;

	document.getElementById("details").style.top = img.offsetTop+"px";
	document.getElementById("details").style.display = "block";
}

function hideDetails(){
	document.getElementById("details").style.display = "none";
}

function submitCommentReviewForm(){
	$("#content").val(convertWordCharacters($("#content").val()));
	$("#name").val(convertWordCharacters($("#name").val()));
	$("#addCommentButton").attr("disabled", "disabled");
	$("#reviewCommentForm").attr("action", "index.php?do=commentReviewAdd");
	$("#reviewCommentForm").submit();
}

function submitGbookEntry(){	
	$("#name").val(convertWordCharacters($("#name").val()));
	$("#city").val(convertWordCharacters($("#city").val()));
	$("#email").val(convertWordCharacters($("#email").val()));
	$("#website").val(convertWordCharacters($("#website").val()));
	$("#message").val(convertWordCharacters($("#message").val()));
	$("#submitEntryButton").attr("disabled", "disabled");
	$("#gbookForm").attr("action", "index.php?do=gbookAdd");
	$("#gbookForm").submit();
}

function submitReviewSearchForm(){
	$("#search").val(convertWordCharacters($("#search").val()));
	$("#reviewSearchForm").attr("action", "index.php?do=reviewsAll&lang=pl");
	$("#reviewSearchForm").submit();
}

function mainTopMenuLinkOn(cell){
	$(cell).css("background-color", "#652f29");
}
function mainTopMenuLinkOff(cell){
	$(cell).css("background-color", "");
}
function clearSearch(){
	var input = $("#newsSearch");
	if($(input).val() == "search"){
		$(input).val("");
	}
}
function submitNewsSearchForm(){
	$("#newsSearch").val(convertWordCharacters($("#newsSearch").val()));
	$("#newsSearchForm").attr("action", "index.php?do=main");
	$("#newsSearchForm").submit();
}

function topPickClick(artistName, title){
	if(artistName != "Various Artists"){
		$("#newsSearch").val('\"'+artistName+'\"');
	}else{
		$("#newsSearch").val('\"'+title+'\"');
	}
	submitNewsSearchForm();
	return false;
}

function convertWordCharacters(value) {
	var myRegEx = new RegExp( String.fromCharCode(8216) + "|" + String.fromCharCode( 8217 ), "g" );
	value = value.replace( myRegEx, "'" );
	var myRegEx = new RegExp( String.fromCharCode( 8220 )+ "|" + String.fromCharCode( 8221 ), "g" );
	value = value.replace( myRegEx, '"' );

	var myRegEx = new RegExp( String.fromCharCode( 61558 ) + "|" + String.fromCharCode( 8226 ) + "|" + String.fromCharCode( 61607 ), "g" );
	value = value.replace( myRegEx, String.fromCharCode( 111 ) );

	var myRegEx = new RegExp( String.fromCharCode( 8211 ), "g" );
	value = value.replace( myRegEx, "-" );

	var myRegEx = new RegExp( String.fromCharCode( 8230 ), "g" );
	value = value.replace( myRegEx, "..." );

	var myRegEx = new RegExp( String.fromCharCode( 8482 ), "g" );
	value = value.replace( myRegEx, "TM" );

	var myRegEx = new RegExp( String.fromCharCode( 169 ), "g" );
	value = value.replace( myRegEx, "(c)" );

	var myRegEx = new RegExp( String.fromCharCode( 174 ), "g" );
	value = value.replace( myRegEx, "(r)" );

	var myRegEx = new RegExp( String.fromCharCode( 187 ), "g" );
	value = value.replace( myRegEx, ">>" );

	var myRegEx = new RegExp( String.fromCharCode( 171 ), "g" );
	value = value.replace( myRegEx, "<<" );
	
	return value;
}
