﻿
	var xmlHttp
	var commentId
	var frame
	
	function converForPolishWords(t){
		t = t.replace(/ą/gi,'0-0');
		t = t.replace(/ć/gi,'1-1');
		t = t.replace(/ę/gi,'2-2');		
		t = t.replace(/ł/gi,'3-3');		
		t = t.replace(/ń/gi,'4-4');		
		t = t.replace(/ó/gi,'5-5');		
		t = t.replace(/ś/gi,'6-6');		
		t = t.replace(/ź/gi,'7-7');		
		t = t.replace(/ż/gi,'8-8');		
		return t;
	}
	function ShowInfo(id,what){ 
		xmlHttp=GetXmlHttpObject()
		if (xmlHttp==null){
			alert ("Browser does not support HTTP Request")
			return
		} 

		var url="scripts/favourites.php";
		url=url+"?id="+id+"&what="+what;
		xmlHttp.onreadystatechange=stateChanged
		xmlHttp.open("GET",url,true)
		xmlHttp.send(null)
	
	}

	function addToFavourite(id){ 
		
		xmlHttp=GetXmlHttpObject()
		
		if (xmlHttp == null){
			alert ("Browser does not support HTTP Request")
			return
		} 
		
		var url="scripts/addToFavourite.php";
		url=url+"?id="+id;
		xmlHttp.onreadystatechange=stateChangedFavourite
		xmlHttp.open("GET",url,true)
		xmlHttp.send(null)
	
	}
	function addingComment(id){
		commentId = id
		addComment(id)
	}
	function addComment(id){ 
		
		xmlHttp = GetXmlHttpObject()

		if (xmlHttp == null){
			return
		} 

		var t = converForPolishWords(document.getElementById('comment_text').value);

	
		var url="scripts/addComment.php";		
		url=url+"?text="+t+"&id="+id;
		xmlHttp.onreadystatechange=stateChangedComment
		xmlHttp.open("GET",url,true)		
		xmlHttp.send(null)			
	
	}
	
	
	// ladowanie strony do diva //
	
	function loadPageToFrame(toFrame,page,code){		
		xmlHttp=GetXmlHttpObject()
		frame = toFrame;
		var url="scripts/loadPageToFrame.php";		
		xmlHttp.onreadystatechange=state2
		url=url+"?page="+page+"&id="+code;
		xmlHttp.open("GET",url,true)
		xmlHttp.send(null)		
	}
	function state2(){ 
		if (xmlHttp.readyState==4 || xmlHttp.readyState=="complete"){ 
			document.getElementById(frame).innerHTML=xmlHttp.responseText
		} 
	}	
	
	// koniec ladowania strony do diva //
	
	
	// wysylanie polecenia strony znajomemu //
	
	function sendToFriend(){ 
		xmlHttp=GetXmlHttpObject()
		var te = converForPolishWords(document.getElementById('text').value);
		var email = document.getElementById('email').value;
		var url="scripts/sendToFriend.php";
		xmlHttp.onreadystatechange=stateChangedComment
		url=url+"?email="+email+"&text="+te;
		xmlHttp.open("GET",url,true)
		xmlHttp.send(null)			
	}	
	
	// -- //


	// wysylanie bledu na stroni //
	
	function sendError(){ 

		xmlHttp=GetXmlHttpObject()
		var eve;
		if(document.getElementById('event1').checked){
			eve = 'tekst';
		}else if(document.getElementById('event2').checked){
			eve = 'tlumaczenie';
		}else if(document.getElementById('event3').checked){
			eve = 'teledysk';
		}else if(document.getElementById('event4').checked){
			eve = 'inny';
		}
			
		var te = converForPolishWords(document.getElementById("text["+eve+"]").value);

		var url="scripts/sendError.php";
		xmlHttp.onreadystatechange=stateChangedComment
		url=url+"?text="+te+"&event="+eve;
		xmlHttp.open("GET",url,true)
		xmlHttp.send(null)			
	}	
	
	// -- //
	
	
	function showComments(id){ 
		if (xmlHttp.readyState == 4){
			xmlHttp=GetXmlHttpObject()
			var url="scripts/showComments.php";
			xmlHttp.onreadystatechange=stateChangedShowComments
			url=url+"?id="+id;
			xmlHttp.open("GET",url,true)
			xmlHttp.send(null)			
		}
	}	
	function showComments2(id){ 


			xmlHttp=GetXmlHttpObject()
			
			var url="scripts/showComments.php";
			xmlHttp.onreadystatechange=stateChangedShowComments
			url=url+"?id="+id;
			xmlHttp.open("GET",url,true)
			xmlHttp.send(null)			

	}			
	
	function stateChanged(){ 
		if (xmlHttp.readyState==4 || xmlHttp.readyState=="complete"){ 
			document.getElementById("show_info").innerHTML=xmlHttp.responseText 
		} 
	}
	
	function stateChangedFavourite(){ 
		if (xmlHttp.readyState==4 || xmlHttp.readyState=="complete"){ 
			document.getElementById("page").innerHTML=xmlHttp.responseText 
		} 
	}	
	
	function stateChangedComment(){ 
		if (xmlHttp.readyState==4 || xmlHttp.readyState=="complete"){ 
			document.getElementById("page").innerHTML=xmlHttp.responseText 
			showComments(commentId)
		} 
	}	
	function stateChangedShowComments(){ 
		if (xmlHttp.readyState==4 || xmlHttp.readyState=="complete"){ 
			document.getElementById("show_comments").innerHTML=xmlHttp.responseText 
		} 
	}		
	
	// -- ocenianie piosenek //
	
	function addVote(vote,song_id){
		xmlHttp=GetXmlHttpObject()			
		var url="scripts/addVote.php";
		xmlHttp.onreadystatechange=stateChangedComment
		url=url+"?vote="+vote;
		xmlHttp.open("GET",url,true)
		xmlHttp.send(null)		
	}
	
	function updateVotes(song_id){
				
	}
	

	//-- //
	
	function GetXmlHttpObject(){
		var xmlHttp=null;
		try
			{
			// Firefox, Opera 8.0+, Safari
			xmlHttp=new XMLHttpRequest();
			}
		catch (e)
			{
				// Internet Explorer
			try
				{
				xmlHttp=new ActiveXObject("Msxml2.XMLHTTP");
				}
			catch (e)
				{
				xmlHttp=new ActiveXObject("Microsoft.XMLHTTP");
				}
			}

		return xmlHttp;
	}

	function ShowPendingImage(){
		document.getElementById("show_info").innerHTML="<image src=images/bigrotation2.gif>Trwa aktualizacja danych...</image>";
	}

	function HidePendingImage(){
		document.getElementById("show_info").innerHTML="";
	}
