jQuery(document).ready(function() {
	var tips_on = readCookie('tips_on');
	if(tips_on != 'not')
	{		
	    var afisat  = readCookie('afisat');
		if(afisat == 'fals')
		{
			createCookie('afisat','true',14);
			var tips = new Array();
			
			tips[0]  = 'Cel mai important lucru este sa aduci puncte pentru candidatul tau.<br /> Sfatuieste-ti prietenii sa se lase recrutati in loc sa intre in joc pe cont propriu, caci sistemul de recrutare, prin bonusurile oferite recrutorului, aduce puncte suplimentare.';
			tips[1]  = 'Atunci cand ajungi la un grad ce iti permite folositea atacurilor (presa, internet, radio, TV) si a sabotajului, concerteaza-ti actiunile cu colegii din acelati judet ca sa actionati cu totii impotriva celui mai puternic dintre candidatii adversi. Astfel, veti scadea puncte din zestrea celui mai primejdios adversar.';
			tips[2]  = 'Daca situatia in judetul tau pare clar transata in favoarea candidatului preferat, sfatuieste-te cu colegii de judet daca este oportun ca tu singur, sau impreuna cu alti colegi, sa te muti si sa activezi in alt judet, unde situatia candidatului tau nu este atat de buna. Atentie la alegerea facuta, caci aceasta trecere este definitiva!';
			tips[3]  = 'Organizeaza cat de des poti actiuni de strangere de fonduri, caci acestea iti aduc sume suplimentare de fonduri.';
			
			var rand_no = Math.floor(Math.random()*4);
			Sexy.error('<span style="float:left;width:100%;font-weight:bold;text-align:center;clear:both;">INDICIU</span><br />'+ tips[rand_no]+'');
		}
	}
});

function popup_change_box(nume,prenume,adresa,oras,profesie,email)
{
	Boxy.alert("<form style=\"height:140px;.height:130px;\" id=\"change_account\" name=\"change_account\"><div style=\"float:left\"><span style=\"font-family:Arial;font-size:12px;padding:2px;font-weight:bold;color:#244f71;\">Nume:</span><br /><input style=\"border:1px solid #244f71;width:167px;font-family:Arial;font-size:12px;padding:2px;clear:left;color:#244f71;font-weight:bold;float:left;margin-bottom:3px;\" id=\"nume\" type=\"text\" name=\"nume\" value=\""+nume+"\" /></div><div style=\".width:150px;.margin-top:-4px;float:left;margin-left:4px;\"><span style=\"float:left;font-family:Arial;font-size:12px;padding:2px;font-weight:bold;color:#244f71;margin-left:-2px;.margin-left:3px;\">Prenume:</span><br /><input style=\"border:1px solid #244f71;width:167px;font-family:Arial;font-size:12px;padding:2px;color:#244f71;clear:left;font-weight:bold;float:left;margin-bottom:3px;\" id=\"prenume\" type=\"text\" name=\"prenume\" value=\""+prenume+"\" /></div><span style=\"float:left;font-family:Arial;font-size:12px;padding:2px;font-weight:bold;color:#244f71;margin-left:-2px;\">Adresa:</span><br /><input style=\"clear:left;border:1px solid #244f71;width:167px;font-family:Arial;font-size:12px;padding:2px;color:#244f71;font-weight:bold;float:left;margin-bottom:3px;\" id=\"adresa\" type=\"text\" name=\"adresa\" value=\""+adresa+"\" /><div style=\".width:150px;.margin-top:-4px;float:right;\"><div style=\"float:left;.margin-left:-200px;.width:150px;.margin-top:24px;\"><span style=\"float:left;font-family:Arial;font-size:12px;padding:2px;font-weight:bold;color:#244f71;margin-left:-2px;\">Oras:</span><br /><input style=\"border:1px solid #244f71;width:167px;font-family:Arial;font-size:12px;padding:2px;color:#244f71;font-weight:bold;float:right;margin-bottom:3px;\" id=\"oras\" type=\"text\" name=\"oras\" value=\""+oras+"\" /></div><div style=\"float:right;.float:left;.width:150px;.margin-top:29px;margin-left:-20px;\"><span style=\"float:left;font-family:Arial;font-size:12px;padding:2px;font-weight:bold;color:#244f71;margin-left:-2px;margin-top:-42px;\">Email:</span><br /><input style=\"margin-top:-16px;border:1px solid #244f71;width:167px;font-family:Arial;font-size:12px;margin-top:-44px;padding:2px;color:#244f71;font-weight:bold;float:right;margin-bottom:3px;\" id=\"email\" type=\"text\" name=\"email\" value=\""+email+"\" /></div><div style=\"float:right;.float:left;margin-left:-20px;.margin-top:-4px;\"><span style=\"float:left;font-family:Arial;font-size:12px;margin-top:-20px;padding:2px;font-weight:bold;color:#244f71;margin-left:-2px;\">Profesie:</span><br /><input style=\"margin-top:-20px;border:1px solid #244f71;width:167px;font-family:Arial;font-size:12px;padding:2px;color:#244f71;font-weight:bold;float:right;margin-bottom:3px;\" id=\"profesie\" type=\"text\" name=\"profesie\" value=\""+profesie+"\" /></div></form>",submit_change_form, {title: 'Modifica Date Personale',closeable:true});	
}

function popup_change_box_2(nume,prenume,adresa,oras,profesie,email)
{
	Boxy.alert("<form style=\"height:140px;.height:130px;\" id=\"change_account\" name=\"change_account\"><div style=\"float:left\"><span style=\"font-family:Arial;font-size:12px;padding:2px;font-weight:bold;color:#244f71;\">Nume:</span><br /><input style=\"border:1px solid #244f71;width:167px;font-family:Arial;font-size:12px;padding:2px;clear:left;color:#244f71;font-weight:bold;float:left;margin-bottom:3px;\" id=\"nume\" type=\"text\" name=\"nume\" value=\""+nume+"\" /></div><div style=\".width:150px;.margin-top:-4px;float:left;margin-left:4px;\"><span style=\"float:left;font-family:Arial;font-size:12px;padding:2px;font-weight:bold;color:#244f71;margin-left:-2px;.margin-left:3px;\">Prenume:</span><br /><input style=\"border:1px solid #244f71;width:167px;font-family:Arial;font-size:12px;padding:2px;color:#244f71;clear:left;font-weight:bold;float:left;margin-bottom:3px;\" id=\"prenume\" type=\"text\" name=\"prenume\" value=\""+prenume+"\" /></div><span style=\"float:left;font-family:Arial;font-size:12px;padding:2px;font-weight:bold;color:#244f71;margin-left:-2px;\">Adresa:</span><br /><input style=\"clear:left;border:1px solid #244f71;width:167px;font-family:Arial;font-size:12px;padding:2px;color:#244f71;font-weight:bold;float:left;margin-bottom:3px;\" id=\"adresa\" type=\"text\" name=\"adresa\" value=\""+adresa+"\" /><div style=\".width:150px;.margin-top:-4px;float:right;\"><div style=\"float:left;.margin-left:-200px;.width:150px;.margin-top:24px;\"><span style=\"float:left;font-family:Arial;font-size:12px;padding:2px;font-weight:bold;color:#244f71;margin-left:-2px;\">Oras:</span><br /><input style=\"border:1px solid #244f71;width:167px;font-family:Arial;font-size:12px;padding:2px;color:#244f71;font-weight:bold;float:right;margin-bottom:3px;\" id=\"oras\" type=\"text\" name=\"oras\" value=\""+oras+"\" /></div><div style=\"float:right;.float:left;.width:150px;.margin-top:29px;margin-left:-20px;\"><span style=\"float:left;font-family:Arial;font-size:12px;padding:2px;font-weight:bold;color:#244f71;margin-left:-2px;margin-top:-42px;\">Email:</span><br /><input style=\"margin-top:-16px;border:1px solid #244f71;width:167px;font-family:Arial;font-size:12px;margin-top:-44px;padding:2px;color:#244f71;font-weight:bold;float:right;margin-bottom:3px;\" id=\"email\" type=\"text\" name=\"email\" value=\""+email+"\" /></div><div style=\"float:right;.float:left;margin-left:-20px;.margin-top:-4px;\"><span style=\"float:left;font-family:Arial;font-size:12px;margin-top:-20px;padding:2px;font-weight:bold;color:#244f71;margin-left:-2px;\">Profesie:</span><br /><input style=\"margin-top:-20px;border:1px solid #244f71;width:167px;font-family:Arial;font-size:12px;padding:2px;color:#244f71;font-weight:bold;float:right;margin-bottom:3px;\" id=\"profesie\" type=\"text\" name=\"profesie\" value=\""+profesie+"\" /></div></form>",submit_change_form, {title: 'Adresa de email este obligatorie',closeable:true});	
}

function submit_change_form()
{
	var nume = document.getElementById('nume').value;
	var prenume = document.getElementById('prenume').value;
	var adresa = document.getElementById('adresa').value;
	var oras = document.getElementById('oras').value;
	var profesie = document.getElementById('profesie').value;
	var email = document.getElementById('email').value;
	
	if( email != '' )
	{
		$.ajax({
	   type: "POST",
	   url: "/users/update_cont",
	   data:'first_name='+nume+'&last_name='+prenume+'&address='+adresa+'&city='+oras+'&profession='+profesie+'&email='+email,
	   success: function(msg)
	   {
	   	  //alert(msg);	
	   }
	 });
	}
	else
	{
		popup_change_box_2(nume,prenume,adresa,oras,profesie,email);	
	}
}

function toggle()
{
	if(document.getElementById('mesaj_nou').style.display == 'none')
	{
		document.getElementById('mesaj_nou').style.display = 'inline';
	}
	else
	{
		document.getElementById('mesaj_nou').style.display = 'none';
	}
}

function toggle_2()
{	
	if(document.getElementById('arhiva_mesaje').style.display == 'none')
	{
		document.getElementById('arhiva_mesaje').style.display = 'inline';
		document.getElementById('sterge_mesaje_bifate').style.display = 'inline';
	}
	else
	{
		document.getElementById('arhiva_mesaje').style.display = 'none';
		document.getElementById('sterge_mesaje_bifate').style.display = 'none';
	}
}


function check_submit_box()
{
	if(document.getElementById('termeni').checked == true)
	{
		submit_form();
	}
	else
	{
		document.getElementById('error').style.display = 'block';
	   	document.getElementById('error').innerHTML = '<span style="color:red;clear:both;margin-left:8px;margin-bottom:4px;"> trebuie sa fiti de acord cu termenii realitatea.net </span>';
	}
}


function submit_form()
{
	var str = '';
	var elem = document.getElementById('register').elements;
	for(var i=0;i < elem.length;i++)
	{
		
		if(i==0)
		{
				str += elem[i].name + "=" + elem[i].value
		}
		else
		{
				str += "&" + elem[i].name + "=" + elem[i].value
		}
		
	}
	   $.ajax({
	   type: "POST",
	   url: "/users/register",
	   data: str,
	   success: function(msg)
	   {
	   		if(msg == 'ok')
	   		{
	     		document.getElementById('register').innerHTML = '<span style="margin-left:25px;">Cont creat cu succes</span>';
	     		setTimeout("document.getElementById('hideshow').style.visibility='hidden'",3000);
	     		setTimeout("location.reload(true)",3200);
	   		}
	   		else
	   		{
	   			//alert(msg);
	   			document.getElementById('error').style.display = 'block';
	   			document.getElementById('error').innerHTML = '<span style="color:red;clear:both;margin-left:8px;margin-bottom:4px;">'+ msg +'</span>';
	   		}
	   }
	 });
}

function login()
{
	var username   = document.getElementById('username').value;
	var password   = document.getElementById('password').value;
	var keep_login = document.getElementById('keep_login').checked;
	
	document.getElementById('error_login').innerHTML = '';
	
	$.ajax({
   	type: "POST",
   	url: "/users/login",
   	data:"username="+username+"&parola="+password+"&keep_login="+keep_login,
   	success: function(msg)
   	{
   		if(msg != 'error')
   		{
			location.href = msg;
   		}
   		else if (msg == 'error')
   		{
   			//document.getElementById('username').style.borderColor = 'red';
   			//document.getElementById('password').style.borderColor = 'red';
   			document.getElementById('error_login').innerHTML = 'Username sau parola gresite';
   		}
   	}
 	});
}

function logout()
{	
	$.ajax({
   	type: "POST",
   	url: "/users/logout",
   	data:'',
   	success: function(msg)
   	{
   		location.reload(true);
   	}
 	});
}

function error(poza,nume,cost,repetare,puncte,user_id,action_id,rank,show_upgrade_message) 
{
	var mesaj_upgr = '';
	if(show_upgrade_message == 'ok')
	{
		mesaj_upgr = 'poti efectua aceasta actiune devenind jucator <a style="text-decoration:none;color:#F60;font-weight:bold;" href="/upgrade">special</a>';
	}
	else if (show_upgrade_message == 'false')
	{
		mesaj_upgr = 'pentru a avansa in rang mai repede recruteaza cat mai multi jucatori';
	}
	else if(show_upgrade_message == 'ok2')
	{
		mesaj_upgr = 'jucatorii <a style="text-decoration:none;color:#F60;font-weight:bold;" href="/upgrade">speciali</a> pot efectua de 2 ori mai des aceasta actiune';
	}
	
	if(repetare == 1)
	{
	Sexy.error('<span style="float:left;width:100%;text-align:center;clear:both;">Ai ales sa efectuezi urmatoarea actiune</span><br /><span style="float:right;font-size:20px;margin-top:20px;"><b>'+ nume +'</b></span><br/><img style="border:2px solid #3779af;" src="/styles/default/images/actiuni/'+ poza +'" /><p style="width:100%;float:left;clear:both;margin-top:5px;">Din pacate aceasta actiune nu o poti efectua decat odata pe zi atunci cand ai mai mult de '+ cost +' fonduri in cont si rang minim de '+rank+'. <br /> '+ mesaj_upgr +' </p>');	
	}
	else
	{
	Sexy.error('<span style="float:left;width:100%;text-align:center;clear:both;">Ai ales sa efectuezi urmatoarea actiune</span><br /><span style="float:right;font-size:20px;margin-top:20px;"><b>'+ nume +'</b></span><br/><img style="border:2px solid #3779af;" src="/styles/default/images/actiuni/'+ poza +'" /><p style="width:100%;float:left;clear:both;margin-top:5px;">Din pacate aceasta actiune nu o poti efectua decat odata la '+ repetare +' zile atunci cand ai mai mult de '+ cost +' fonduri in cont si rang minim de '+rank+'. <br /> '+ mesaj_upgr +' </p>');
	}
}

function error2(poza,nume,cost,repetare,puncte,user_id,action_id,nume_candidat) 
{
	Sexy.error('<span style="float:left;width:100%;text-align:center;clear:both;">Ai ales sa efectuezi urmatoarea actiune</span><br /><span style="float:right;font-size:20px;margin-top:20px;"><b>'+ nume +'</b></span><br/><img style="border:2px solid #3779af;" src="/styles/default/images/actiuni/'+ poza +'" /><p style="width:100%;float:left;clear:both;margin-top:5px;"></p>');
}

function error_demo(poza,nume,cost,repetare,puncte,action_id,show_upgrade_message) 
{
	var mesaj_upgr ='';
	if(show_upgrade_message == 'ok')
	{
		mesaj_upgr = 'poti efectua aceasta actiune devenind jucator <a style="text-decoration:none;color:#F60;font-weight:bold;" href="/upgrade">special</a>';
	}
	else if (show_upgrade_message == 'false')
	{
		mesaj_upgr = 'pentru a avansa in rang mai repede recruteaza cat mai multi jucatori';
	}
	Sexy.error('<span style="float:left;width:100%;text-align:center;clear:both;">Ai ales sa efectuezi urmatoarea actiune</span><br /><span style="float:right;font-size:20px;margin-top:20px;"><b>'+ nume +'</b></span><br/><img style="border:2px solid #3779af;" src="/styles/default/images/actiuni/'+ poza +'" /><p style="width:100%;float:left;clear:both;margin-top:5px;">Din pacate in versiunea demo nu poti efectua nici o actiune!.<br /> '+ mesaj_upgr +'</p>');
}

function info(poza,nume,cost,repetare,puncte,user_id,action_id,nume_candidat) 
{
	if(repetare == 1)
	{
		Sexy.info('<span style="float:left;width:100%;text-align:center;clear:both;">Ai ales sa efectuezi urmatoarea actiune</span><br /><span style="float:right;font-size:20px;margin-top:20px;"><b>'+ nume +'</b></span><br/><img style="border:2px solid #3779af;" src="/styles/default/images/actiuni/'+ poza +'" /><p style="width:100%;float:left;clear:both;margin-top:5px;">cost : <b>'+ cost +'</b>, frecventa : la o zi</b>, puncte : <b>'+ puncte +'</b></p>',{onComplete: function(returnvalue){ do_req(returnvalue,action_id,user_id,puncte,nume_candidat); }});		
	}
	else
	{
		Sexy.info('<span style="float:left;width:100%;text-align:center;clear:both;">Ai ales sa efectuezi urmatoarea actiune</span><br /><span style="float:right;font-size:20px;margin-top:20px;"><b>'+ nume +'</b></span><br/><img style="border:2px solid #3779af;" src="/styles/default/images/actiuni/'+ poza +'" /><p style="width:100%;float:left;clear:both;margin-top:5px;">cost : <b>'+ cost +'</b>, frecventa : la <b>'+ repetare +' zile</b>, puncte : <b>'+ puncte +'</b></p>',{onComplete: function(returnvalue){ do_req(returnvalue,action_id,user_id,puncte,nume_candidat); }});
	}
}

function contact()
{
	Sexy.error('<span style="float:left;text-align:center;clear:both;width:100%;">CONTACT</span><br /><br />Ne puteti trimite un email la <a href="mailto:contact@presedintelemeu.ro" style="text-decoration:none;color:#F90;">contact@presedintelemeu.ro</a><br />');	
}

function mesaj(id,subiect,text) 
{
	Sexy.error('<span style="float:left;width:100%;text-align:center;clear:both;">'+ subiect +'</span><br /><span style="float:left;width:100%;text-align:left;padding:10px;clear:both;">'+ text +'</span>');
	$.ajax({
	   type: "POST",
	   url: "/mesaje/read",
	   data: 'message_id='+id
	 });
	 document.getElementById('mesaj_'+id).style.color ='#E8E6E4';
}

function mesaj_a(id,subiect,text) 
{
	Sexy.error('<span style="float:left;width:100%;text-align:center;clear:both;">'+ subiect +'</span><br /><span style="float:left;width:100%;text-align:left;padding:10px;clear:both;">'+ text +'</span>');
	 document.getElementById('mesaj_'+id).style.color ='#E8E6E4';
}

function do_req(returnvalue,action_id,user_id,puncte,nume_candidat)
{
	if(returnvalue == true)
	{
	   $.ajax({
	   type: "POST",
	   url: "/actions/do_action",
	   data: 'user_id='+user_id+'&action_id='+action_id,
	   success: function(msg)
	   {
	   		if(msg.substr(0,2) == 'ok')
	   		{
	   			//alert(msg);
				var spl  = msg.split("|");
				var banishori = spl[1];
				
   				if(action_id >0 && action_id < 9)
   				{
   					Sexy.error('<span style="float:left;width:100%;text-align:center;clear:both;">Felicitari, ati primit '+ puncte +' puncte in urma actiunii efectuate de dumneavoastra iar '+nume_candidat+' iti multumeste pentru activitatea ta!</span>',{onComplete: function(returnvalue){ location.reload(true);}});
   				}
   				else if(action_id > 8 && action_id < 14)
   				{
					Sexy.error('<span style="float:left;width:100%;text-align:center;clear:both;">Felicitari, ati primit '+ puncte +' puncte in urma actiunii efectuate de dumneavoastra iar '+nume_candidat+' iti este recunoscator pentru loialitatea de care ai dat dovada!</span>',{onComplete: function(returnvalue){ location.reload(true);}});   					
   				}
   				else if( action_id == 14)
   				{
   					Sexy.error('<span style="float:left;width:100%;text-align:center;clear:both;">Ati colectat '+ banishori +' fonduri in urma campaniei derulate.</span>',{onComplete: function(returnvalue){ location.reload(true);}});
   				}
   				else if(action_id == 15)
   				{
   					Sexy.error('<span style="float:left;width:100%;text-align:center;clear:both;">Sponsorii va sprijina cu '+ banishori +' fonduri in sustinerea lui '+nume_candidat+' .</span>',{onComplete: function(returnvalue){ location.reload(true);}});
   				}
   				
	   			//location.reload(true);
	   		}
	   		else
	   		{
	   			Sexy.error('<span style="float:left;width:100%;text-align:center;clear:both;">Ne pare rau, actiune dumneavoastra nu a putut fi efectuata, va rugam reincercati! </span>');
	   		}
	   }
	 });
	}
	else if(returnvalue == false)
	{
		return false;
	}
}

function trimite_mesaj()
{
	var subiect    = document.getElementById('subiect').value;
	var destinatar = document.getElementById('destinatar').value;
	var text       = document.getElementById('mesaj').value;
	
	$.ajax({
	   type: "POST",
	   url: "/mesaje/send",
	   data: 'subiect='+subiect+'&destinatar='+destinatar+'&text='+text,
	   success: function(msg)
	   {
	   		if(msg == 'ok')
	   		{
	   			//alert(msg);
	   			document.getElementById('form_trimite_mesaj').reset();
	   			document.getElementById('mesaj_succes').innerHTML = 'Mesaj trimis cu succes';
	     		document.getElementById('mesaj_succes').style.display = 'block';
	   		}
	   		else
	   		{
	   			//alert(msg);
	   			document.getElementById('mesaj_succes').innerHTML = 'Mesajul nu a putut fi trimis';
	   			document.getElementById('mesaj_succes').style.display = 'block';
	   		}
	   }
	 });
}

function delete_checked_inbox()
{
	$("input:checkbox[name=sterge]:checked").each(function(){
       	$.ajax({
	   		type: "POST",
	   		url: "/mesaje/delete",
	   		data: 'message_id='+$(this).val()
	 	});
	 	document.getElementById('casuta_mesaj_'+$(this).val()).style.display = 'none';
  	});
}

function delete_checked_archive()
{
	$("input:checkbox[name=sterge_arhiva]:checked").each(function(){
       	$.ajax({
	   		type: "POST",
	   		url: "/mesaje/delete",
	   		data: 'message_id='+$(this).val()
	 	});
	 	document.getElementById('casuta_mesaj_'+$(this).val()).style.display = 'none';
  	});
}

function get_points_user( nume_utilizator )
{
	
		$.ajax({
			   type: "POST",
			   url: "/clasament/get_points",
			   data: 'cuvant_cheie='+nume_utilizator,
			   success: function(msg)
			   {
					//do something here
			   }
		 });
	
	return response;
}

function cautare_clasament()
{
	var tip_cautare  = 'general';
	var cuvant_cheie = document.getElementById('cautare_c').value; 
	if(tip_cautare != '' || cuvant_cheie != '')
	{
		$.ajax({
		   type: "POST",
		   url: "/clasament/cautare",
		   data: 'tip_cautare='+tip_cautare+'&cuvant_cheie='+cuvant_cheie,
		   success: function(msg)
		   {
		   		if(msg != 'error')
		   		{	  
		   			var spl = msg.split("|");			
		   			$.ajax({
						   type: "POST",
						   url: "/clasament/get_points",
						   data: 'cuvant_cheie='+cuvant_cheie,
						   success: function(msg2)
						   {
								document.getElementById('clasament_general').innerHTML = '<span class="red" style="font-family:Tahoma;font-size:11px;width:100%;float:left;clear:left;text-align:left;font-weight:bold;"> &nbsp;&nbsp; '+ spl[0] +'. <a href="/profil/'+ spl[1]+ '" style="text-decoration:none;color:#fff">' + cuvant_cheie + '</a><span style="float:right;margin-right:10px;.margin-top:-13px;">'+ msg2 +' puncte</span></span>';
						   }
					 });
		   		}
		   }
		 });
	}
}

function cautare_clasament_numeric()
{
	var tip_cautare  = 'general';
	
	var cuvant_cheie = document.getElementById('cautare_c').value;
	var nr_clasament = document.getElementById('cautare_x').value; 
	
	if(nr_clasament != '' || nr_clasament != '')
	{
		$.ajax({
		   type: "POST",
		   url: "/clasament/cautare_loc",
		   data: 'tip_cautare='+tip_cautare+'&nr_clasament='+nr_clasament,
		   success: function(msg)
		   {
		   		if(msg != 'error')
		   		{	  
						var spl = msg.split("|");
						document.getElementById('clasament_general').innerHTML = '<span class="red" style="font-family:Tahoma;font-size:11px;width:100%;float:left;clear:left;text-align:left;font-weight:bold;"> &nbsp;&nbsp; '+ nr_clasament +'. <a href="/profil/'+ spl[2]+ '" style="text-decoration:none;color:#fff">' + spl[0] + '</a><span style="float:right;margin-right:10px;.margin-top:-13px;">'+ spl[1] +' puncte</span></span>';
						   
		   		}
		   }
		 });			
	}
	else if(tip_cautare != '' || cuvant_cheie != '')
	{
		$.ajax({
		   type: "POST",
		   url: "/clasament/cautare",
		   data: 'tip_cautare='+tip_cautare+'&cuvant_cheie='+cuvant_cheie,
		   success: function(msg)
		   {
		   		if(msg != 'error')
		   		{	  
		   			var spl = msg.split("|");			
		   			$.ajax({
						   type: "POST",
						   url: "/clasament/get_points",
						   data: 'cuvant_cheie='+cuvant_cheie,
						   success: function(msg2)
						   {
								document.getElementById('clasament_general').innerHTML = '<span class="red" style="font-family:Tahoma;font-size:11px;width:100%;float:left;clear:left;text-align:left;font-weight:bold;"> &nbsp;&nbsp; '+ spl[0] +'. <a href="/profil/'+ spl[1]+ '" style="text-decoration:none;color:#fff">' + cuvant_cheie + '</a><span style="float:right;margin-right:10px;.margin-top:-13px;">'+ msg2 +' puncte</span></span>';
						   }
					 });
		   		}
		   }
		 });
	}
}

function cautare_clasament_numeric_judet()
{
	var tip_cautare  = 'general';
	
	var cuvant_cheie = document.getElementById('cautare_c').value;
	var nr_clasament = document.getElementById('cautare_x').value; 
	
	if(nr_clasament != '' || nr_clasament != '')
	{
		$.ajax({
		   type: "POST",
		   url: "/clasament/cautare_loc",
		   data: 'tip_cautare='+tip_cautare+'&nr_clasament='+nr_clasament,
		   success: function(msg)
		   {
		   		if(msg != 'error')
		   		{	  
						var spl = msg.split("|");
						document.getElementById('clasament_judet').innerHTML = '<span class="red" style="font-family:Tahoma;font-size:11px;width:100%;float:left;clear:left;text-align:left;font-weight:bold;"> &nbsp;&nbsp; '+ nr_clasament +'. <a href="/profil/'+ spl[2]+ '" style="text-decoration:none;color:#fff">' + spl[0] + '</a><span style="float:right;margin-right:10px;.margin-top:-13px;">'+ spl[1] +' puncte</span></span>';
						   
		   		}
		   }
		 });			
	}
	if(tip_cautare != '' || cuvant_cheie != '')
	{
		$.ajax({
		   type: "POST",
		   url: "/clasament/cautare",
		   data: 'tip_cautare='+tip_cautare+'&cuvant_cheie='+cuvant_cheie,
		   success: function(msg)
		   {
		   		if(msg != 'error')
		   		{	
		   			 var spl = msg.split("|");	
		   			 $.ajax({
						   type: "POST",
						   url: "/clasament/get_points",
						   data: 'cuvant_cheie='+cuvant_cheie,
						   success: function(msg2)
						   {
								document.getElementById('clasament_judet').innerHTML = '<span class="red" style="font-family:Tahoma;font-size:11px;width:100%;float:left;clear:left;text-align:left;font-weight:bold;"> &nbsp;&nbsp; '+ spl[0] +'. <a href="/profil/'+ spl[1]+ '" style="text-decoration:none;color:#fff"> '+ cuvant_cheie + '<span style="float:right;margin-right:10px;.margin-top:-13px;">'+ msg2 +' puncte</span></span>';
						   }
					 });
		   		}
		   }
		 });
	}
}

function cautare_clasament_numeric_candidat()
{
	var tip_cautare  = 'general';
	
	var cuvant_cheie = document.getElementById('cautare_c').value;
	var nr_clasament = document.getElementById('cautare_x').value; 
	
	if(nr_clasament != '' || nr_clasament != '')
	{
		$.ajax({
		   type: "POST",
		   url: "/clasament/cautare_loc",
		   data: 'tip_cautare='+tip_cautare+'&nr_clasament='+nr_clasament,
		   success: function(msg)
		   {
		   		if(msg != 'error')
		   		{	  
						var spl = msg.split("|");
						document.getElementById('clasament_candidat').innerHTML = '<span class="red" style="font-family:Tahoma;font-size:11px;width:100%;float:left;clear:left;text-align:left;font-weight:bold;"> &nbsp;&nbsp; '+ nr_clasament +'. <a href="/profil/'+ spl[2]+ '" style="text-decoration:none;color:#fff">' + spl[0] + '</a><span style="float:right;margin-right:10px;.margin-top:-13px;">'+ spl[1] +' puncte</span></span>';
						   
		   		}
		   }
		 });			
	}
	if(tip_cautare != '' || cuvant_cheie != '')
	{
		$.ajax({
		   type: "POST",
		   url: "/clasament/cautare",
		   data: 'tip_cautare='+tip_cautare+'&cuvant_cheie='+cuvant_cheie,
		   success: function(msg)
		   {
		   		if(msg != 'error')
		   		{	
		   			 var spl = msg.split("|");	
		   			 $.ajax({
						   type: "POST",
						   url: "/clasament/get_points",
						   data: 'cuvant_cheie='+cuvant_cheie,
						   success: function(msg2)
						   {
								document.getElementById('clasament_candidat').innerHTML = '<span class="red" style="font-family:Tahoma;font-size:11px;width:100%;float:left;clear:left;text-align:left;font-weight:bold;"> &nbsp;&nbsp; '+ spl[0] +'. <a href="/profil/'+ spl[1]+ '" style="text-decoration:none;color:#fff"> '+ cuvant_cheie + '<span style="float:right;margin-right:10px;.margin-top:-13px;">'+ msg2 +' puncte</span></span>';
						   }
					 });
		   		}
		   }
		 });
	}
}

function judet()
{
	var tip_cautare  = 'judet';
	var cuvant_cheie = document.getElementById('cautare_judet_c').value; 
	if(tip_cautare != '' || cuvant_cheie != '')
	{
		$.ajax({
		   type: "POST",
		   url: "/clasament/cautare",
		   data: 'tip_cautare='+tip_cautare+'&cuvant_cheie='+cuvant_cheie,
		   success: function(msg)
		   {
		   		if(msg != 'error')
		   		{	
		   			 var spl = msg.split("|");	
		   			 $.ajax({
						   type: "POST",
						   url: "/clasament/get_points",
						   data: 'cuvant_cheie='+cuvant_cheie,
						   success: function(msg2)
						   {
								document.getElementById('clasament_judet').innerHTML = '<span class="red" style="font-family:Tahoma;font-size:11px;width:100%;float:left;clear:left;text-align:left;font-weight:bold;"> &nbsp;&nbsp; '+ spl[0] +'. <a href="/profil/'+ spl[1]+ '" style="text-decoration:none;color:#fff"> '+ cuvant_cheie + '<span style="float:right;margin-right:10px;.margin-top:-13px;">'+ msg2 +' puncte</span></span>';
						   }
					 });
		   		}
		   }
		 });
	}
}

function candidat()
{
	var tip_cautare  = 'candidat';
	var cuvant_cheie = document.getElementById('cautare_candidat_c').value; 
	if(tip_cautare != '' || cuvant_cheie != '')
	{
		$.ajax({
		   type: "POST",
		   url: "/clasament/cautare",
		   data: 'tip_cautare='+tip_cautare+'&cuvant_cheie='+cuvant_cheie,
		   success: function(msg)
		   {
		   		if(msg != 'error')
		   		{
		   			  var spl = msg.split("|");
		   			  $.ajax({
						   type: "POST",
						   url: "/clasament/get_points",
						   data: 'cuvant_cheie='+cuvant_cheie,
						   success: function(msg2)
						   {
								document.getElementById('clasament_candidat').innerHTML = '<span class="red" style="font-family:Tahoma;font-size:11px;width:100%;float:left;clear:left;text-align:left;font-weight:bold;"> &nbsp;&nbsp; '+ spl[0] +'. <a href="/profil/'+ spl[1]+ '" style="text-decoration:none;color:#fff"> '+ cuvant_cheie + '<span style="float:right;margin-right:10px;.margin-top:-13px;">'+ msg2 +' puncte</span></span>';
						   }
					 });
		  		}
		   }
		 });
	}
}

function modifica_parola() {
    Sexy.prompt('<h1>Introduceti noua parola in campul de mai jos</h1><br /> Puteti alege ce parola doriti intre 4 si 32 de caractere alfa numerice.','Eduardo' ,{ onComplete: 
      function(returnvalue) {
        if(returnvalue)
        {
        	if(returnvalue.replace(/\s/g,"") != "")
        	{
        		
				$.ajax({
				   type: "POST",
				   url: "/users/update_pass",
				   data: 'new_password='+returnvalue,
				   success: function(msg)
				   {
				   		if(msg != 'error')
				   		{
				   			Sexy.error('<h1> Felicitari, parola schimbata cu succes!</h1><br /> Noua parola este '+ returnvalue +' ');
				  		}
				  		else
				  		{
				  			Sexy.error('<h1> Parola nu a putut fi schimbata!</h1><br />');
				  		}
				   }
				 });
        		
        	}
        }
      }
    });
}

function modifica_mesaj() {
    Sexy.prompt('<h1>Introduceti noul mesaj in campul de mai jos</h1><br /> Puteti scrie intre 4 si 200 de caractere alfa numerice.','Eduardo' ,{ onComplete: 
      function(returnvalue) {
        if(returnvalue)
        {
        	if(returnvalue.replace(/\s/g,"") != "")
        	{
        		
				$.ajax({
				   type: "POST",
				   url: "/users/update_mesaj",
				   data: 'mesaj='+returnvalue,
				   success: function(msg)
				   {
				   		if(msg != 'error')
				   		{
				   			Sexy.error('<h1> Felicitari, mesajul a fost schimbat cu succes!</h1><br /> Noul mesaj este '+ returnvalue.substr(0,200)+' ');
				  		}
				  		else
				  		{
				  			Sexy.error('<h1> Mesajul nu a putut fi schimbat!</h1><br />');
				  		}
				   }
				 });
        	}
        }
      }
    });
}

function vip() {
    Sexy.prompt('<h1>Introduceti codul primit prin sms pentru a deveni special .</h1><br /> pentru a primi un cod urmeaza instructiunile <a style="text-decoration:none;color:#F90;" href="/upgrade">de aici</a> <br /><br /> Codul trebuie sa aiba o lungime de 8 caractere.','Eduardo' ,{ onComplete: 
      function(returnvalue) {
        if(returnvalue)
        {
        	if(returnvalue.replace(/\s/g,"") != "")
        	{
        		
				$.ajax({
				   type: "POST",
				   url: "/users/vip",
				   data: 'cod='+returnvalue,
				   success: function(msg)
				   {
				   	
				   		if(msg == 'OK')
				   		{
				   			Sexy.error('<h1> Felicitari, ati devenit membru special!</h1><br />Acum beneficiati de mult mai multe actiuni');
				  		}
				  		else
				  		{
				  			Sexy.error('<h1> Codul introdus este incorect sau a mai fost folosit!</h1><br />');
				  		}
				   }
				 });
        		
        	}
        }
      }
    });
}

function succes_upload_trigger( serverRespData )
{
	var spl = serverRespData.split("|");
	//alert(spl);
	//return;
	if(spl[0] !== "error")
	{
		$.ajax({
				   type: "POST",
				   url: "/cont/rest_sess",
				   data: 'sessid='+spl[1]+'&uid='+spl[2],
				   success: function(msg)
				   {
				   	//alert(msg);	
				   }
				 });

		document.getElementById('avatar_img').innerHTML = '<img src="/files/avatars/' + spl[0] + '" width="193" height="188" />';
	}
	else
	{
		upload_error('Poza nu a putut fi incarcata','Ne pare rau poza dumneavoastra nu a putut fi incarcata, va rugam reincercati!');
	}
}

function upload_error(subiect,text) 
{
	Sexy.error('<span style="float:left;width:100%;text-align:center;clear:both;">'+ subiect +'</span><br /><span style="float:left;width:100%;text-align:left;padding:10px;clear:both;">'+ text +'</span>');
}

function change_county( old_county, new_county )
{
	Sexy.confirm('<span style="float:left;width:100%;text-align:left;clear:both;">Ai ales sa schimbi judetul in care sustii candidatul tau! <br />Poti efectua o singura data aceasta operatiune. </span><br />',
				{onComplete: function(returnvalue){ 
					if(returnvalue == true)
					{
						do_change_county(old_county,new_county);
					}
				}}
	);
}

function change_suport(old_suport,new_suport)
{
	if(new_suport == "")
	{
		Sexy.error('<span style="float:left;width:100%;text-align:left;clear:both;">Va rugam alegeti unul dintre candidati!</span>');
	}
	else
	{
		Sexy.confirm('<span style="float:left;width:100%;text-align:left;clear:both;">Ai ales sa schimbi candidatul pe care il sustii! <br />Poti efectua o singura data aceasta operatiune. </span><br />',
					{onComplete: function(returnvalue){ 
						if(returnvalue == true)
						{
							do_change_suport(old_suport,new_suport);
						}
					}}
		);
	}	
}

function do_change_county(old_id, new_id)
{
	   $.ajax({
	   type: "POST",
	   url: "/cont/change_county",
	   data: 'old_id='+old_id+'&new_id='+new_id,
	   success: function(msg)
	   {
	   		if(msg == 'ok')
	   		{
	   			location.reload(true);
	  		}
	  		else
	  		{
	  			if(msg == 'error2')
	  			{
	  				Sexy.error('<span style="float:left;width:100%;text-align:left;clear:both;">Ne pare rau, nu puteti schimba judetul decat o singura data!</span>');
	  			}
	  		}
	   }
	 });
}

function do_change_suport(old_id,new_id)
{
	$.ajax({
	   type: "POST",
	   url: "/cont/change_suport",
	   data: 'old_id='+old_id+'&new_id='+new_id,
	   success: function(msg)
	   {
	   		if(msg == 'ok')
	   		{
	   			location.reload(true);
	  		}
	  		else
	  		{
	  			if(msg == 'error2')
	  			{
	  				Sexy.error('<span style="float:left;width:100%;text-align:left;clear:both;">Ne pare rau, nu puteti schimba judetul decat o singura data!</span>');
	  			}
	  		}
	   }
	 });
}

function list_by_county( county_id )
{
	   $.ajax({
	   type: "POST",
	   url: "/clasament/search_by_county",
	   data: 'county_id='+county_id,
	   success: function(msg)
	   {
	   		document.getElementById('clasament_judet').innerHTML = msg;
	   }
	 });
}

function unregister()
{
		Sexy.confirm('<span style="float:left;width:100%;text-align:left;clear:both;">Ai ales sa stergi contul tau pe acest site! <br />Atentie, sters contul nu mai poate fi recuperat! </span><br />',
				{onComplete: function(returnvalue){ 
					if(returnvalue == true)
					{
						$.ajax({
								   type: "POST",
								   url: "/users/unregister",
								   data: '',
								   success: function(msg)
								   {
								   		if(msg == 'ok')
								   		{
								   			Sexy.error('<h1> Userul dumneavoastra a fost sters cu succes, va multumim!</h1><br />',							{onComplete: function(returnvalue){ 
												if(returnvalue == true)
												{
													logout();
												}
											}});
								   		}
								   }
								 });		
					}
				}});
}

function list_by_candidat( candidat_id )
{
	   $.ajax({
	   type: "POST",
	   url: "/clasament/search_by_candidat",
	   data: 'candidat_id='+candidat_id,
	   success: function(msg)
	   {
	   		document.getElementById('clasament_candidat').innerHTML = msg;
	   }
	 });
}

function show_next(nr_candidati)
{
	if(document.getElementById('candidat_1').style.display != 'none')
	{
		for(var i=0;i<5;i++)
		{
			document.getElementById('candidat_'+i).style.display = 'none';
		}
		
		for(var x=5;x<nr_candidati;x++)
		{
			document.getElementById('candidat_'+x).style.display = 'block';			
		}
		document.getElementById('link_next_prev').innerHTML = 'precedentii';
	}
	else
	{
		for(var i=0;i<5;i++)
		{
			document.getElementById('candidat_'+i).style.display = 'block';
		}
		
		for(var x=5;x<nr_candidati;x++)
		{
			document.getElementById('candidat_'+x).style.display = 'none';			
		}
		document.getElementById('link_next_prev').innerHTML = 'urmatorii';
	}
}

function show_next_judet(nr_candidati)
{
	if(document.getElementById('judet_pic_1').style.display != 'none')
	{
		for(var i=0;i<5;i++)
		{
			document.getElementById('judet_pic_'+i).style.display = 'none';
		}		
		for(var x=5;x<nr_candidati;x++)
		{
			document.getElementById('judet_pic_'+x).style.display = 'block';			
		}
		document.getElementById('sit_pe_judete').innerHTML = 'precedentii';
	}
	else
	{
		for(var i=0;i<5;i++)
		{
			document.getElementById('judet_pic_'+i).style.display = 'block';
		}		
		for(var x=5;x<nr_candidati;x++)
		{
			document.getElementById('judet_pic_'+x).style.display = 'none';			
		}
		document.getElementById('sit_pe_judete').innerHTML = 'urmatorii';
	}
}

function change_field_type()
{
	document.getElementById('password2').style.display = 'none';
	document.getElementById('password').style.display = 'block';
	document.getElementById('password').focus();
	
}

/* These functions are cookie related */
function createCookie(name,value,days) {
	if (days) {
		var date = new Date();
		date.setTime(date.getTime()+(days*24*60*60*1000));
		var expires = "; expires="+date.toGMTString();
	}
	else var expires = "";
	document.cookie = name+"="+value+expires+"; path=/";
}

function readCookie(name) {
	var nameEQ = name + "=";
	var ca = document.cookie.split(';');
	for(var i=0;i < ca.length;i++) {
		var c = ca[i];
		while (c.charAt(0)==' ') c = c.substring(1,c.length);
		if (c.indexOf(nameEQ) == 0) return c.substring(nameEQ.length,c.length);
	}
	return null;
}

function eraseCookie(name) {
	createCookie(name,"",-1);
}
/* These functions are cookie related */

function dezactivare_tips()
{
	if(document.getElementById('dezactivare_tips').innerHTML == 'Dezactivare Tips')
	{
		createCookie('tips_on','not',5184000);
		document.getElementById('dezactivare_tips').innerHTML = 'Activare Tips';
		Sexy.error('<span style="float:left;width:100%;font-weight:bold;text-align:center;clear:both;">INDICII DEZACTIVATE</span><br /> Indiciile au fost dezactivate, in caz ca doriti sa le reactivati apasati butonul Activare Tips');
	}
	else
	{
		createCookie('tips_on','yes',5184000);
		document.getElementById('dezactivare_tips').innerHTML = 'Dezactivare Tips';
		Sexy.error('<span style="float:left;width:100%;font-weight:bold;text-align:center;clear:both;">INDICII ACTIVATE</span><br /> Indiciile au fost activate, in caz ca doriti sa le dezactivati apasati butonul Dezactivare Tips');
	}
}

function check_for_referer()
{
		var recrutat_de = document.getElementById('recrutat').value;
		if(recrutat_de != "")
		{
			$.ajax({
			   	type: "POST",
			   	url: "/users/search_user_suport",
			   	data: 'user_name='+recrutat_de,
			   	success: function(msg)
			   	{
			   		if(msg != 'error')
			   		{
			   			//document.getElementById('clasament_candidat').innerHTML = msg;
			   			frmchng(msg);
			   		}
			   		else
			   		{
			   			if(msg == 'error')
			   			{
			   				if(document.getElementById('candidat').disabled == true)
			   				{
			   					document.getElementById('candidat').disabled = false;
			   				}
			   			}
			   		}
			   	}
		 	});
		}
		else
		{
			document.getElementById('candidat').disabled = false;
		}
}

function frmchng(val)
{

	for(i=0;i<document.getElementById('candidat').length;i++)
	{
		if(document.getElementById('candidat').options[i].value==val)
		{
			document.getElementById('candidat').selectedIndex=i;
			document.getElementById('candidat').disabled=true;
		}
	}
}

function undisableselect()
{
	document.getElementById('candidat').selectedIndex = 0;
	document.getElementById('candidat').disabled = false;
}
