/* NÄMÄ ON /js/all_combined.js :ssä!!! */

	function get_cookie ( cookie_name )
	{
	  var results = document.cookie.match ( '(^|;) ?' + cookie_name + '=([^;]*)(;|$)' );
	
	  if ( results )
		return ( unescape ( results[2] ) );
	  else
		return null;
	}
	
	function markfavs(){
		var splitted = get_cookie("favflash").split('.');
		
		for(i = 1; i < splitted.length; i++){
			var fitem = document.getElementById("f" + splitted[i]);
			if(fitem != null) fitem.innerHTML = '<img alt="fav" class="favimg" src="/img/heart.png" />' + fitem.innerHTML;	// EI ENÄÄ KÄYTÖSSÄ
		}
	}
	
	function addfav(fid){
		var flink = document.getElementById(fid);
	
		
		if(navigator.appName == "Microsoft Internet Explorer") {
		  http = new ActiveXObject("Microsoft.XMLHTTP");
		} else {
		  http = new XMLHttpRequest();
		}
		
	
		http.open("GET", "/members/ajax_fav_add.php?id=" + fid);
		http.onreadystatechange=function() {
		  if(http.readyState == 4) {
			  if(http.responseText == "ok"){
				  flink.innerHTML = '<img width="25px" align="right" src="/img/flashloved25.png" onmouseover="this.src=\'/img/flashnotyetloved25.png\'" onmouseout="this.src=\'/img/flashloved25.png\'" alt="<3" />';
				  //flink.onclick = "remfav('"+ fid +"');";
				  flink.setAttribute('onclick','remfav('+fid+');'); 	// for FF
				  flink.onclick = function() {remfav(fid);}; 		// for IE
				  return false;
			  }else if(http.responseText.length > 1){
				  alert('ERROR: '+ http.responseText +'!');
			  }
		  }
		}
		http.send(null);
	}
	
		function remfav(fid){
		var flink = document.getElementById(fid);
	
		
		if(navigator.appName == "Microsoft Internet Explorer") {
		  http = new ActiveXObject("Microsoft.XMLHTTP");
		} else {
		  http = new XMLHttpRequest();
		}
		
	
		http.open("GET", "/members/ajax_fav_rem.php?id=" + fid);
		http.onreadystatechange=function() {
		  if(http.readyState == 4) {
			  if(http.responseText == "ok"){
				  flink.innerHTML = '<img width="25px" align="right" src="/img/flashnotyetloved25.png" onmouseover="this.src=\'/img/flashloved25.png\'" onmouseout="this.src=\'/img/flashnotyetloved25.png\'" alt="</3" />';
				  //flink.onclick = "addfav('"+ fid +"');";
				  flink.setAttribute('onclick','addfav('+fid+');'); 	// for FF
				  flink.onclick = function() {addfav(fid);}; 		// for IE
				  return false;
			  }else if(http.responseText.length > 1){
				  alert('ERROR: '+ http.responseText +'!');
			  }
		  }
		}
		http.send(null);
	}
