/**
 * AJAX Functions:
 * ----------------
 */

/*-- 
 * sends the forgotten password by email
 * callback function  
 *--	
 */
AjaxRequest.sendPassword = function () {
	if (AjaxRequest.checkReadyState() == "200") {
		var eroare = AjaxRequest.getResponse().getElementsByTagName('eroare')[0].firstChild.data;
		var succes = AjaxRequest.getResponse().getElementsByTagName('success')[0].firstChild.data;
		
		if (eroare == '') {
			$('forgetPassError').style.color = '#000000';
			$('forgetPassError').style.border = '1px solid #000000';
			$('forgetPassError').innerHTML = succes;
		} else {
			$('forgetPassError').style.color = '#ff7b11';
			$('forgetPassError').innerHTML = eroare;
		}
	}
}

AjaxRequest.trimite_avertisment = function () {
	if (AjaxRequest.checkReadyState() == "200") {
	/*	var eroare = AjaxRequest.getResponse().getElementsByTagName('eroare')[0].firstChild.data;
		var succes = AjaxRequest.getResponse().getElementsByTagName('success')[0].firstChild.data;
		
		if (eroare == '') {
			$('forgetPassError').style.color = '#000000';
			$('forgetPassError').style.border = '1px solid #000000';
			$('forgetPassError').innerHTML = succes;
		} else {
			$('forgetPassError').style.color = 'red';
			$('forgetPassError').style.border = '1px solid red';
			$('forgetPassError').innerHTML = eroare;
		}
	*/
	}
}

AjaxRequest.trimite_mesaj = function () {
	
	if (AjaxRequest.checkReadyState() == "200") {
		var eroare = AjaxRequest.getResponse().getElementsByTagName('eroare')[0].firstChild.data;
		var succes = AjaxRequest.getResponse().getElementsByTagName('success')[0].firstChild.data;
		var id_comentariu = AjaxRequest.getResponse().getElementsByTagName('id_comentariu')[0].firstChild.data;
		var button = AjaxRequest.getResponse().getElementsByTagName('button')[0].firstChild.data;
		
		if (eroare == '') {
			$('messageBox'+id_comentariu).style.color = '#000000';
			$('messageBox'+id_comentariu).style.border = '1px solid #000000';
			$('messageBox'+id_comentariu).innerHTML = succes+button;
		} else {
			$('MesajError').style.color = 'red';
			$('comments'+id_comentariu).style.border = '1px solid red';
			$('comments'+id_comentariu).innerHTML = eroare;
		}
	
	}
}

AjaxRequest.adaugaFavorite = function () {
					if (AjaxRequest.checkReadyState() == "200") {
							
						}
				}

AjaxRequest.vot_comentariu = function () {
	
	if (AjaxRequest.checkReadyState() == "200") {
		var eroare = AjaxRequest.getResponse().getElementsByTagName('eroare')[0].firstChild.data;
		var succes = AjaxRequest.getResponse().getElementsByTagName('success')[0].firstChild.data;
		var id_comentariu = AjaxRequest.getResponse().getElementsByTagName('id_comentariu')[0].firstChild.data;
				
		if (eroare == '') {
			
			$('starRating'+id_comentariu).innerHTML = succes;
		} else {
			
			$('starRating'+id_comentariu).innerHTML = eroare;
		}
	
	}
}

AjaxRequest.show_calendar = function()
{
	if (AjaxRequest.checkReadyState() == "200") {
		var eroare = AjaxRequest.getResponse().getElementsByTagName('eroare')[0].firstChild.data;
		var succes = AjaxRequest.getResponse().getElementsByTagName('success')[0].firstChild.data;
		
		if (eroare == '') {
			$('showcalendar').innerHTML = succes;
		} else {
			$('showcalendar').style.color = 'red';
			$('showcalendar').innerHTML = eroare;
		}
	
	}
}


AjaxRequest.trimite_compliment = function () {
	
	if (AjaxRequest.checkReadyState() == "200") {
		var eroare = AjaxRequest.getResponse().getElementsByTagName('eroare')[0].firstChild.data;
		var succes = AjaxRequest.getResponse().getElementsByTagName('success')[0].firstChild.data;
		var id_comentariu = AjaxRequest.getResponse().getElementsByTagName('id_comentariu')[0].firstChild.data;
		var button = AjaxRequest.getResponse().getElementsByTagName('button')[0].firstChild.data;
		
		if (eroare == '') {
			$('commentBox'+id_comentariu).style.color = '#000000';
			$('commentBox'+id_comentariu).style.border = '1px solid #000000';
			$('commentBox'+id_comentariu).innerHTML = succes+button;
		} else {
			$('MesajError').style.color = 'red';
			$('comments'+id_comentariu).style.border = '1px solid red';
			$('comments'+id_comentariu).innerHTML = eroare;
		}
	
	}
}

AjaxRequest.adauga_newsl = function () {
	
	if (AjaxRequest.checkReadyState() == "200") {
		var eroare = AjaxRequest.getResponse().getElementsByTagName('eroare')[0].firstChild.data;
		var succes = AjaxRequest.getResponse().getElementsByTagName('success')[0].firstChild.data;
		
		if (eroare == '') {
			$('newslBox').style.color = '#000000';
			$('newslBox').innerHTML = succes;
		} else {
			$('newslBox').style.color = 'red';
			$('newslBox').innerHTML = eroare;
		}
	
	}
}

AjaxRequest.actualizeaza_complimente = function () {
	
	if (AjaxRequest.checkReadyState() == "200") {
		var eroare = AjaxRequest.getResponse().getElementsByTagName('eroare')[0].firstChild.data;
		var succes = AjaxRequest.getResponse().getElementsByTagName('success')[0].firstChild.data;
		var id_compliment = AjaxRequest.getResponse().getElementsByTagName('id_compliment')[0].firstChild.data;
		var tip_afis = AjaxRequest.getResponse().getElementsByTagName('tip_afis')[0].firstChild.data;
	
	
		if (tip_afis == 0){
			
		$('complBox'+id_compliment).innerHTML =  '<a style=\"cursor:pointer\" onclick=\"javascript:AjaxRequest.Update(\'POST\', \''+BASE_URL+'AjaxRequest.php?do=actualizeaza_complimente\', \'id='+id_compliment+'&tip=2\', \'VotError\', true, AjaxRequest.actualizeaza_complimente); alert(\'Complimentul a fost aprobat!\');" class=\"aproba\">aproba</a>';
		$('complBox'+id_compliment).innerHTML +=  '<a style=\"cursor:pointer\" onclick=\"javascript:AjaxRequest.Update(\'POST\', \''+BASE_URL+'AjaxRequest.php?do=actualizeaza_complimente\', \'id='+id_compliment+'&tip=1\', \'VotError\', true, AjaxRequest.actualizeaza_complimente); alert(\'Complimentul a fost sters!\');" class=\"erase\">sterge</a>';
		$('complBox'+id_compliment).innerHTML +=  '<a style=\"cursor:pointer\" onclick=\"javascript:AjaxRequest.Update(\'POST\', \''+BASE_URL+'AjaxRequest.php?do=actualizeaza_complimente\', \'id='+id_compliment+'&tip=3\', \'VotError\', true, AjaxRequest.actualizeaza_complimente); alert(\'Complimentul a fost blocat!\');" class=\"blocheaza\">blocheaza</a>';
		}
		
		if (tip_afis == 1){
			
		
			$('complBox'+id_compliment).innerHTML =  '<a style=\"cursor:pointer\" onclick=\"javascript:AjaxRequest.Update(\'POST\', \''+BASE_URL+'AjaxRequest.php?do=actualizeaza_complimente\', \'id='+id_compliment+'&tip=1\', \'VotError\', true, AjaxRequest.actualizeaza_complimente); alert(\'Complimentul a fost sters!\');" class=\"erase\">sterge</a>';
			$('complBox'+id_compliment).innerHTML +=  '<a style=\"cursor:pointer\" onclick=\"javascript:AjaxRequest.Update(\'POST\', \''+BASE_URL+'AjaxRequest.php?do=actualizeaza_complimente\', \'id='+id_compliment+'&tip=5\', \'VotError\', true, AjaxRequest.actualizeaza_complimente); alert(\'Complimentul a fost blocat!\');" class=\"blocheaza\">blocheaza</a>';
			
		}
		
		if (tip_afis == 2){
			
			$('complBox'+id_compliment).innerHTML =  '<a style=\"cursor:pointer\" onclick=\"javascript:AjaxRequest.Update(\'POST\', \''+BASE_URL+'AjaxRequest.php?do=actualizeaza_complimente\', \'id='+id_compliment+'&tip=4\', \'VotError\', true, AjaxRequest.actualizeaza_complimente); alert(\'Complimentul a fost deblocat!\');" class=\"blocheaza\">deblocheaza</a>';
		}
		
		if (tip_afis == 3){
			
		
			$('complBox'+id_compliment).innerHTML =  '<a style=\"cursor:pointer\" onclick=\"javascript:AjaxRequest.Update(\'POST\', \''+BASE_URL+'AjaxRequest.php?do=actualizeaza_complimente\', \'id='+id_compliment+'&tip=1\', \'VotError\', true, AjaxRequest.actualizeaza_complimente); alert(\'Complimentul a fost sters!\');" class=\"erase\">sterge</a>';
			$('complBox'+id_compliment).innerHTML +=  '<a style=\"cursor:pointer\" onclick=\"javascript:AjaxRequest.Update(\'POST\', \''+BASE_URL+'AjaxRequest.php?do=actualizeaza_complimente\', \'id='+id_compliment+'&tip=5\', \'VotError\', true, AjaxRequest.actualizeaza_complimente); alert(\'Complimentul a fost blocat!\');" class=\"blocheaza\">blocheaza</a>';
			
		} 
		
		
		
	}
}




function showMessageBox (id, username, id_utilizator) {
	
	
	$('messageBox'+id).innerHTML = '<div id="MesajError"></div>';
	
	$('messageBox'+id).innerHTML += '<form action="" name="comments'+ id +'" id="comments'+ id +'" method="post">';
	$('messageBox'+id).innerHTML += '<div class="handler"><b>Trimite un mesaj catre <strong>'+ username +'</strong></div>';
	$('messageBox'+id).innerHTML += '<div id="loading" style="padding:10px 0 0 10px; font-weight:bold;"></div>';
	$('messageBox'+id).innerHTML += '  <label for="username">Subiect:</label>';
	$('messageBox'+id).innerHTML += '  <input type="text" name="subiect" id="subiect" class="txt" />';
	$('messageBox'+id).innerHTML += '  <br/><textarea name="text" id="text" rows="8" cols="32"></textarea>';
    $('messageBox'+id).innerHTML += '<br />';
	$('messageBox'+id).innerHTML += '<input type="button" class="submit" name="cancel" value="Anuleaza" onclick="document.getElementById(\'messageBox'+id+'\').style.display=\'none\';">';
    $('messageBox'+id).innerHTML += '<input type="button" class="submit" name="add" value="Trimite" onclick="AjaxRequest.Update(\'POST\', \''+BASE_URL+'AjaxRequest.php?do=trimite_mesaj\', \'id_comentariu='+id+'&username='+username+'&id_utilizator='+id_utilizator+'&subiect=\'+$(\'subiect\').value+\'&text=\'+$(\'text\').value, \'MesajError\', true, AjaxRequest.trimite_mesaj); ">';
	$('messageBox'+id).innerHTML += '</form>';
	
	$('messageBox'+id).style.display  = 'block';
	$('messageBox'+id).style.position = 'absolute';
	$('messageBox'+id).style.left = '380px';
	new Draggable('messageBox'+id,false);
}

function showCommentBox(id, username, id_utilizator) {
	
	$('commentBox'+id).innerHTML = '<div id="MesajError"></div>';
	
	$('commentBox'+id).innerHTML += '<form action="" name="comments'+ id +'" id="comments'+ id +'" method="post">';

	$('commentBox'+id).innerHTML += '<div class="handler"><b>Trimite un compliment catre <strong>'+ username +'</strong></div>';
	$('commentBox'+id).innerHTML += '<div id="loading" style="padding:10px 0 0 10px; font-weight:bold;"></div>';
	$('commentBox'+id).innerHTML += '  <input type="radio" name="five" id="five" value="11" onclick="document.getElementById(\'text\').value=\'Draguta poza!\'; document.getElementById(\'id_compl\').value=11"><img src="'+TPL_WEB+'images/five/cute_pic.gif" title="Cute pic!"><input type="radio" name="five" id="five" value="7" onclick="document.getElementById(\'text\').value=\'Super comentariul!\'; document.getElementById(\'id_compl\').value=7"><img src="'+TPL_WEB+'images/five/good_writing.gif" title="Good writing!"><input type="radio" name="five" id="five" value="10" onclick="document.getElementById(\'text\').value=\'Super liste!\'; document.getElementById(\'id_compl\').value=10"><img src="'+TPL_WEB+'images/five/great_lists.gif" title="Super liste!"><input type="radio" id="five" name="five" value="2" onclick="document.getElementById(\'text\').value=\'Super poza!\'; document.getElementById(\'id_compl\').value=2"><img src="'+TPL_WEB+'images/five/great_photo.gif" title="Great photo!">';
	$('commentBox'+id).innerHTML += '  <label for="username"><input type="radio" name="five" id="five" value="1" onclick="document.getElementById(\'text\').value=\'Fierbinte!\'; document.getElementById(\'id_compl\').value=1"><img src="'+TPL_WEB+'images/five/hot_stuff.gif" title="Hot stuff!"><input type="radio" name="five" id="five" value="3" onclick="document.getElementById(\'text\').value=\'Imi place profilul tau!!\' ; document.getElementById(\'id_compl\').value=3"><img src="'+TPL_WEB+'images/five/like_youre_profile.gif" title="Imi place profilul tau!"><input type="radio" name="five" id="five" value="9" onclick="document.getElementById(\'text\').value=\'Multumesc!\'; document.getElementById(\'id_compl\').value=9"><img src="'+TPL_WEB+'images/five/thank_you.gif" title="Thank you!"></label>';
	$('commentBox'+id).innerHTML += '  <label for="username"><input type="radio" name="five" id="five" value="6" onclick="document.getElementById(\'text\').value=\'Scrie mai mult!\' ; document.getElementById(\'id_compl\').value=6"><img src="'+TPL_WEB+'images/five/write_more.gif" title="Write more"><input type="radio" name="five" value="4" id="five" onclick="document.getElementById(\'text\').value=\'Esti cool!\'; document.getElementById(\'id_compl\').value=4"><img src="'+TPL_WEB+'images/five/youre_cool.gif" title="Esti cool!"><input type="radio" name="five" value="5" id="five" onclick="document.getElementById(\'text\').value=\'Ce amuzant esti!\'; document.getElementById(\'id_compl\').value=5"><img src="'+TPL_WEB+'images/five/youre_funny.gif" title="you are funny!"></label>';
	$('commentBox'+id).innerHTML += '  <br/><textarea name="text" id="text" rows="8" cols="32"></textarea>';
    $('commentBox'+id).innerHTML += '<br />';
    $('commentBox'+id).innerHTML += '<input type="hidden" name="id_compl" id="id_compl">';
	//$('commentBox'+id).innerHTML += '<input type="button" class="submit" name="ok" value="alert" onclick="alert($(\'id_compl\').value);">';
	$('commentBox'+id).innerHTML += '<input type="button" class="submit" name="cancel" value="Anuleaza" onclick="document.getElementById(\'commentBox'+id+'\').style.display=\'none\';">';
    $('commentBox'+id).innerHTML += '<input type="button" class="submit" name="add" value="Trimite" onclick="  AjaxRequest.Update(\'POST\', \''+BASE_URL+'AjaxRequest.php?do=trimite_compliment\', \'id_comentariu='+id+'&username='+username+'&id_utilizator='+id_utilizator+'&text=\'+$(\'text\').value+\'&five=\'+$(\'id_compl\').value, \'MesajError\', true, AjaxRequest.trimite_compliment);">';
	$('commentBox'+id).innerHTML += '</form>';
	
	$('commentBox'+id).style.display  = 'block';
	$('commentBox'+id).style.position = 'absolute';
	$('commentBox'+id).style.left = '380px';
	new Draggable('commentBox'+id,false);
}

function PaintStars(number, set)
{
	set = (set -1) * 5;
	min = 1 + set;
	max = 5 + set;
	number = number + set;
	
	for ( i=min ; i<=number ; i++ ) 
	{
		var image = document.getElementById("star" + i);
		image.src = TPL_WEB + "images/stea_rosie.gif";
	}
	
	for ( ; i<=max ; i++ ) 	
	{
		var image = document.getElementById("star" + i);
		image.src = TPL_WEB + "images/stea_gri.gif";
	}

}


/** 
 * -----------------
 * Yahoo! Maps     |
 * -----------------
 */

function getMarkers (latMin, latMax, lonMin, lonMax, currentLocation) {
	
	AjaxRequest.showMarkers = function () {
		
		if (AjaxRequest.checkReadyState() == "200") {
			
			var locations = AjaxRequest.getResponse().getElementsByTagName('location').length;
			
			var response  =	 AjaxRequest.getResponse();
			
			$('locatiiApropiate').innerHTML = '<b>Locatii apropiate</b><br /><br />';
			
			for (i=0; i < locations; i++) {
				
				var latitude 		= response.getElementsByTagName('lat')[i].firstChild.data;
				var longitude 		= response.getElementsByTagName('lon')[i].firstChild.data;
				var markerName		= response.getElementsByTagName('name')[i].firstChild.data;
				var markerType		= response.getElementsByTagName('type')[i].firstChild.data;
				var markerPic		= response.getElementsByTagName('poza')[i].firstChild.data;
				var markerAddress 	= response.getElementsByTagName('adresa')[i].firstChild.data;
				var link		 	= response.getElementsByTagName('link')[i].firstChild.data;
				
				
				var GeoPoint = new YGeoPoint(latitude, longitude);
				var marker = createYahooMarker(GeoPoint, markerName, markerType, markerPic, markerAddress); 
				map.addOverlay(marker); 
				

				$('locatiiApropiate').innerHTML += '<a href="' + link + '">' + markerName + '</a><br />';

				
				$('locatiiApropiate').innerHTML += 'Distance: ' + myPoint.distance(GeoPoint).kilometers.toFixed(2) + " km<br />";
			}
		}	
	}
	
	AjaxRequest.Update('GET', BASE_URL 
			+ 'location.php?' 
			+ 'lat_min=' + latMin + '&'
			+ 'lat_max=' + latMax + '&'
			+ 'lon_min=' + lonMin + '&'
			+ 'lon_max=' + lonMax + '&'
			+ 'id_locatie=' + currentLocation, 
			'', '', false, AjaxRequest.showMarkers);
			
	
}

function createYahooMarker(geopoint, label, num, poza, adresa) { 
    var myImage = new YImage(); 
    myImage.src = 'http://us.i1.yimg.com/us.yimg.com/i/us/map/aj/markerf19824.png'; 
    myImage.size = new YSize(30,33); 
    myImage.offsetSmartWindow = new YCoordPoint(15,15); 

    var marker = new YMarker(geopoint,myImage); 

    var swtext = '<div style="width:160px; font-size:12px; padding:3px;"><b>' + label + '</b></div>';
    
    if (poza != '') {
    	swtext += '<div style="width:40px; float:left;"><img src="' + BASE_URL + 'pics/locations/thumb/'+ poza +'"></div>';	
    }
    
    swtext += '<div style="width:115px; font-size:10px; float:right;color:#348b34"">' + adresa + '</div><div class="clear"></div></div>'; 
    
    var label = '<div style="margin:5px; color:#fff">' + num + '</div>'; 
    
    marker.addLabel(label); 
    marker.addAutoExpand(swtext);
    YEvent.Capture(marker,EventsList.MouseClick, function() { marker.openSmartWindow(swtext) }); 
    //YEvent.Capture(marker,EventsList.MouseOut, function() { marker.closeSmartWindow(swtext) }); 
    
    return marker; 
  }
  
  /** End Yahoo Maps functions **/
 
  
  /* Vic alte orase */
  
toggleAlteOrase=function(event){
   	$('alte_orase_link').hasClassName('up') ? $('alte_orase_link').removeClassName('up') :  $('alte_orase_link').addClassName('up');
   	Effect.toggle('d1','blind',{duration:0.8});
}

Event.observe(window, 'load', function(){
    if($('alte_orase_link')!=undefined)
        Event.observe('alte_orase_link','click',toggleAlteOrase)
})



  
     