$(document).ready(function() {
	$('.favorite.login').click(function () {
		var id = $(this).attr('id').replace('faved_', '');
		
		$(this).html('Please, <a href="'+webPath+'login">login</a> or <a href="'+webPath+'register">register</a><br /> to use this feature');
		
		$(this).removeClass('login').addClass('small');
		
		//$('html').animate({scrollTop : 0},1000);
		//$('#loginBox').slideDown();
		//window.location.href ='#header_links' ;
		//$('#login').focus();
		$(this).unbind('click');
		return false;
	});
	
	$('.add_favorite').live('click', function (){
		var id = $(this).attr('id').replace('faved_', '');
		
		faved(webPath+'ajax/fav.php','faved_'+id, id);
		
		$(this).removeClass('add_favorite').addClass('rem_favorite');
		
		$(this).html('Quote added to your <br /><a href="'+webPath+'my_account#favorites">favorites</a>'); 
		return false;
	});
	$('.rem_favorite').live('click', function (){
		//$(this).html('favorite it');
		
		//faved(webPath+'ajax/fav.php','faved_'+id, id); 
		//return false;
	});
	
	$('#profile_content').show();
	var hash = window.location.hash.replace("#", "");
	if (hash=='favorites')
	{
		change_content('favorites', '386');
		$('#profile_content').hide();
	}
	if (hash=='authors')
	{
		change_content('authors', '386');
		$('#profile_content').hide();
	}
	
	
	//
	$('.favorite_author').live('click', function (){
		var id = $(this).attr('id').replace('faved_', '');
		
		author_favorite(id);
		
		$(this).removeClass('favorite_author').addClass('rem_favorite_author');
		
		$('#author_fav').html('Author added to your <a href="'+webPath+'my_account#authors">favorites</a>'); 
		return false;
	});
	
});




function change_gallery(user,page){

var http = false;
if(navigator.appName == "Microsoft Internet Explorer") { http = new ActiveXObject("Microsoft.XMLHTTP"); } else { http = new XMLHttpRequest(); }
  http.open("GET", "http://"+window.location.hostname+"/index.php?p=flist&user="+user+"&page="+page, true);
  http.onreadystatechange=function() { if(http.readyState == 4) {document.getElementById('fp').innerHTML=http.responseText; document.getElementById("loadingimg").style.display="none";} }
  http.send(null);	
}

function next_f_page(user,page){
document.getElementById("loadingimg").style.display="block";
change_gallery(user,page)

}

function pevious_f_page(user,page){
document.getElementById("loadingimg").style.display="block";
change_gallery(user,page);

}

function gup( name )
{
  var regexS = "[\\?&]"+name+"=([^&#]*)";
  var regex = new RegExp( regexS );
  var tmpURL = window.location.href;
  var results = regex.exec( tmpURL );
  if( results == null )
    return "";
  else
    return results[1];
}

function gotoQuotePage(quotetype,page,rowcount){
var http = false;
if(navigator.appName == "Microsoft Internet Explorer") { http = new ActiveXObject("Microsoft.XMLHTTP"); } else { http = new XMLHttpRequest(); }
  http.open("GET", "http://"+window.location.hostname+"/index.php?p=qlist&page="+page+"&show="+quotetype+"&rowcount="+rowcount+"&user="+gup('user'), true);
  http.onreadystatechange=function() { if(http.readyState == 4) {document.getElementById('qlist').innerHTML=http.responseText;  }}
  http.send(null);	
}


function addStuff()
{
  var loc = document.getElementById('profile_subcontent');
  //div.scrollTop = h;
  loc.scrollTop = 30000;
}


function show_profile_subpage(user, show, tot, page){


  if(page == undefined){
  page =1;
var load_html = '<span id="quote_timer" style="margin-top:70px;visibility: hidden;"><center><img width="15" height="15" style="border: none; background: #fff;" src="/images/loading.gif"></center></span>';


  document.getElementById('profile_subcontent').innerHTML=load_html;
  }
	document.getElementById('quote_timer').style.visibility = 'visible';

	var http = false;
if(navigator.appName == "Microsoft Internet Explorer") { http = new ActiveXObject("Microsoft.XMLHTTP"); } else { http = new XMLHttpRequest(); }
  http.open("GET", "http://"+window.location.hostname+"/index.php?p=psubcontent&user="+user+"&show="+show+"&tot="+tot+"&page="+page, true);
  http.onreadystatechange=function() { if(http.readyState == 4) {	 document.getElementById('quote_timer').style.visibility = 'hidden';
  document.getElementById('profile_subcontent').innerHTML=http.responseText; document.getElementById("loadingimg").style.display="none";
  	fancybox_init();
  }
addStuff(); }
  http.send(null);	
}

function show_user_favorite(tot, page){

  if(page == undefined){
  page =1;
var load_html = '<span id="quote_timer" style="margin-top:70px;visibility: hidden;"><center><img width="15" height="15" style="border: none; background: #fff;" src="/images/loading.gif"></center></span>';


  document.getElementById('profile_subcontent').innerHTML=load_html;
  }
	document.getElementById('quote_timer').style.visibility = 'visible';

	var http = false;
if(navigator.appName == "Microsoft Internet Explorer") { http = new ActiveXObject("Microsoft.XMLHTTP"); } else { http = new XMLHttpRequest(); }
  http.open("GET", "http://"+window.location.hostname+"/index.php?p=showfavoritequotes&ajax=yes&" +"tot="+tot+"&page="+page, true);
  http.onreadystatechange=function() { if(http.readyState == 4) {	 document.getElementById('quote_timer').style.visibility = 'hidden';
  document.getElementById('favorite_container1').innerHTML=http.responseText; document.getElementById("loadingimg").style.display="none";}
addStuff(); }
  http.send(null);	
}


function show_user_author(tot, page){

  if(page == undefined){
  page =1;
  
var load_html = '<span id="quote_timer1" style="margin-top:70px;visibility: hidden;"><center><img width="15" height="15" style="border: none; background: #fff;" src="/images/loading.gif"></center></span>';

  document.getElementById('profile_subcontent').innerHTML=load_html;
  }

		document.getElementById('quote_timer1').style.visibility = 'visible';

	var http = false;
if(navigator.appName == "Microsoft Internet Explorer") { http = new ActiveXObject("Microsoft.XMLHTTP"); } else { http = new XMLHttpRequest(); }
  http.open("GET", "http://"+window.location.hostname+"/index.php?p=showfavoriteauthors&ajax=yes&" +"tot="+tot+"&page="+page, true);
  http.onreadystatechange=function() { if(http.readyState == 4) {	 document.getElementById('quote_timer1').style.visibility = 'hidden';
  document.getElementById('favorite_author_container').innerHTML=http.responseText; document.getElementById("loadingimg").style.display="none";}
addStuff(); }
  http.send(null);	
}





function getXMLHttp()
{
  var xmlHttp
  try { xmlHttp = new XMLHttpRequest(); }
  catch(e)
  {
    try { xmlHttp = new ActiveXObject("Msxml2.XMLHTTP"); }
    catch(e)
    {
      try { xmlHttp = new ActiveXObject("Microsoft.XMLHTTP"); }
      catch(e) { alert("Your browser does not support AJAX!"); return false; }
    }
  }
  return xmlHttp;
}

/* $(function() {

        $("#slider-images").jCarouselLite({
            btnNext: "#slider-next",
            btnPrev: "#slider-previous",
            			auto: 3000,
			            speed:600,
            visible:1,
            vertical:true
        });

        $("#slider-content").jCarouselLite({
            btnNext: "#slider-next",
            btnPrev: "#slider-previous",
            			auto: 3000,
			            speed:600,
            visible:1
        });	

    }); */


function change(id){

	for(i=65;i<=90;i++){
		$('#'+String.fromCharCode(i)).removeClass('selected_letter');
		$('#list_'+String.fromCharCode(i)).hide();
		$('#topics').hide();
	}
	
	$('#'+id).addClass('selected_letter');
	$('#list_'+id).fadeIn("slow");
}





function cycle(counter)
{
	var counter = counter+1;
	if (counter < 6)
	{
		cic = setTimeout('cycle('+counter+')', 5000);
	}
	else
	{
		if (counter == 7) counter = 0; 
		cic = setTimeout('cycle(0)', 5000);
	}

    //load_quote(counter);
}

function show_extra_search(id){
	if(id=='show'){$('#extra_search').fadeIn('slow');}
	if(id=='hide'){$('#extra_search').hide();}
}


function add_fav(id_quote) {
	//alert(window.location.hostname);//alert(rate);
	$("#q_"+id_quote).hide(); $("#loading_"+id_quote).fadeIn(); 
var http = false;
if(navigator.appName == "Microsoft Internet Explorer") { http = new ActiveXObject("Microsoft.XMLHTTP"); } else { http = new XMLHttpRequest(); }

  http.open("GET", "http://"+window.location.hostname+"/add_fav.php?id_quote="+id_quote, true);
  http.onreadystatechange=function() { if(http.readyState == 4) {$("#loading_"+id_quote).hide(); document.getElementById("response_"+id_quote).innerHTML = http.responseText;  } }
  http.send(null);
}


function change_gallery(id,sid){
	for (i=1;i<=444;i++){
		if(i!=id){
			$('#gb_'+i).hide();
		}else{
			$('#gb_'+i).fadeIn("slow");
				}
	}
	$('#av').hide();//for users gallery(hide avatar)
var http = false;
if(navigator.appName == "Microsoft Internet Explorer") { http = new ActiveXObject("Microsoft.XMLHTTP"); } else { http = new XMLHttpRequest(); }
  http.open("GET", "http://"+window.location.hostname+"/select_items.php?id="+sid, true);
  http.onreadystatechange=function() { if(http.readyState == 4) {} }
  http.send(null);	
}





function next_page(id){
	var idd=id-1;
$('#p'+(idd)).hide();
$('#p'+(id)).fadeIn();
}

function pevious_page(id){
	var idd=id+1;
$('#p'+(idd)).hide();
$('#p'+(id)).fadeIn();
}



function next_fq_page(id){
	var idd=id-1;
$('#fq_p'+(idd)).hide();
$('#fq_p'+(id)).fadeIn();
}

function pevious_fq_page(id){
	var idd=id+1;
$('#fq_p'+(idd)).hide();
$('#fq_p'+(id)).fadeIn();
}


function next_fm_page(id){
	var idd=id-1;
$('#fm_p'+(idd)).hide();
$('#fm_p'+(id)).fadeIn();
}

function pevious_fm_page(id){
	var idd=id+1;
$('#fm_p'+(idd)).hide();
$('#fm_p'+(id)).fadeIn();
}


function next_fc_page(id){
	var idd=id-1;
$('#fc_p'+(idd)).hide();
$('#fc_p'+(id)).fadeIn();
}

function pevious_fc_page(id){
	var idd=id+1;
$('#fc_p'+(idd)).hide();
$('#fc_p'+(id)).fadeIn();
}



function next_f_page(id){
	var idd=id-1;
$('#fp'+(idd)).hide();
$('#fp'+(id)).fadeIn();
}

function pevious_f_page(id){
	var idd=id+1;
$('#fp'+(idd)).hide();
$('#fp'+(id)).fadeIn();
}


function next_inbox_page(id){
	var idd=id-1;
$('#ip'+(idd)).hide();
$('#ip'+(id)).fadeIn();
}

function pevious_inbox_page(id){
	var idd=id+1;
$('#ip'+(idd)).hide();
$('#ip'+(id)).fadeIn();
}


function next_sent_page(id){
	var idd=id-1;
$('#sp'+(idd)).hide();
$('#sp'+(id)).fadeIn();
}

function pevious_sent_page(id){
	var idd=id+1;
$('#sp'+(idd)).hide();
$('#sp'+(id)).fadeIn();
}

function become_fan_author(id) {
	//alert(window.location.hostname);//alert(rate);
	$("#q_"+id).hide(); $("#loading_"+id).fadeIn(); 
var http = false;
if(navigator.appName == "Microsoft Internet Explorer") { http = new ActiveXObject("Microsoft.XMLHTTP"); } else { http = new XMLHttpRequest(); }

  http.open("GET", "http://"+window.location.hostname+"/become_fan_author.php?id="+id, true);
  http.onreadystatechange=function() { if(http.readyState == 4) {$("#loading_"+id).hide(); document.getElementById("response_"+id).innerHTML = http.responseText;  } }
  http.send(null);
}

function become_fan_movie(id) {
	//alert(window.location.hostname);//alert(rate);
	$("#q_"+id).hide(); $("#loading_"+id).fadeIn(); 
var http = false;
if(navigator.appName == "Microsoft Internet Explorer") { http = new ActiveXObject("Microsoft.XMLHTTP"); } else { http = new XMLHttpRequest(); }

  http.open("GET", "http://"+window.location.hostname+"/become_fan_movie.php?id="+id, true);
  http.onreadystatechange=function() { if(http.readyState == 4) {$("#loading_"+id).hide(); document.getElementById("response_"+id).innerHTMLHTML = http.responseText;  } }
  http.send(null);
}

function hide_div(id) {$("#"+id).hide();}

function show_div(id,id_celeb) {
	//alert(window.location.hostname);//alert(rate);
	
var http = false;
if(navigator.appName == "Microsoft Internet Explorer") { http = new ActiveXObject("Microsoft.XMLHTTP"); } else { http = new XMLHttpRequest(); }

  http.open("GET", "http://"+window.location.hostname+"/authors/edit_celebrity.php?id="+id_celeb, true);
  http.onreadystatechange=function() { if(http.readyState == 4) {document.getElementById(id).innerHTML = http.responseText; $("#"+id).show(); } }
  http.send(null);
}

function show_div_movies(id,id_celeb) {
	//alert(window.location.hostname);//alert(rate);
	
var http = false;
if(navigator.appName == "Microsoft Internet Explorer") { http = new ActiveXObject("Microsoft.XMLHTTP"); } else { http = new XMLHttpRequest(); }

  http.open("GET", "http://"+window.location.hostname+"/movies/edit_movie.php?id="+id_celeb, true);
  http.onreadystatechange=function() { if(http.readyState == 4) {document.getElementById(id).innerHTML = http.responseText; $("#"+id).show(); } }
  http.send(null);
}

function show_div_q(id,id_celeb) {
	$("#"+id).show(); 
}


function vote(selected_field,id,table,field,rate) {
	$('#vote').hide(); $('#voting_results').hide();
	$('#voting').show();setTimeout("$('#voting').hide()",1250);

var http = false;
if(navigator.appName == "Microsoft Internet Explorer") { http = new ActiveXObject("Microsoft.XMLHTTP"); } else { http = new XMLHttpRequest(); }

  http.open("GET", "http://"+window.location.hostname+"/vote.php?selected_field="+selected_field+"&id="+id+"&table="+table+"&field="+field+"&rate="+rate, true);
  http.onreadystatechange=function() { if(http.readyState == 4) { document.getElementById(rate).innerHTML = http.responseText;  } }
  http.send(null);
  
 setTimeout("$('#voting_results').fadeIn()",1250);
  setTimeout("$('#voted').fadeIn()",1250);
}




function report_quote(id, id_reported) {
	//alert(window.location.hostname);//alert(rate);
	$("#qr_"+id).hide(); $("#loading_"+id).fadeIn(); 
var http = false;
if(navigator.appName == "Microsoft Internet Explorer") { http = new ActiveXObject("Microsoft.XMLHTTP"); } else { http = new XMLHttpRequest(); }

  http.open("GET", "http://"+window.location.hostname+"/quotes/abuse.php?id="+id+"&id_reported="+id_reported, true);
  http.onreadystatechange=function() { if(http.readyState == 4) {$("#loading_"+id).hide(); document.getElementById("response_r"+id).innerHTML = http.responseText;  } }
  http.send(null);
}




function show_user_contributions(userid,module_name) {
	//alert(window.location.hostname);//alert(rate);

	$("f_c").fadeIn("slow"); $("loading").fadeIn(); 
var http = false;
if(navigator.appName == "Microsoft Internet Explorer") { http = new ActiveXObject("Microsoft.XMLHTTP"); } else { http = new XMLHttpRequest(); }

  http.open("GET", "http://"+window.location.hostname+"/users/user_contributions.php?userid="+userid+"&module_name="+module_name, true);
 
  http.onreadystatechange=function() { if(http.readyState == 4) {$("#loading").hide(); document.getElementById("f_c").innerHTML = http.responseText;  } }
  http.send(null);
}


function show_user_favourite(userid,module_name) {
	//alert(window.location.hostname);//alert(rate);

	$("f_c").fadeIn("slow"); $("loading").fadeIn(); 
var http = false;
if(navigator.appName == "Microsoft Internet Explorer") { http = new ActiveXObject("Microsoft.XMLHTTP"); } else { http = new XMLHttpRequest(); }

  http.open("GET", "http://"+window.location.hostname+"/users/user_favourites.php?userid="+userid+"&module_name="+module_name, true);
 
  http.onreadystatechange=function() { if(http.readyState == 4) {$("#loading").hide(); document.getElementById("f_c").innerHTML = http.responseText;  } }
  http.send(null);
}






function user_actions(from,to,action) {
	//alert(window.location.hostname);
	//alert(action);

	$("#"+action).hide(); $("#loading_"+action).fadeIn(); 
var http = false;
if(navigator.appName == "Microsoft Internet Explorer") { http = new ActiveXObject("Microsoft.XMLHTTP"); } else { http = new XMLHttpRequest(); }

  http.open("GET", "http://"+window.location.hostname+"/users/actions.php?from="+from+"&to="+to+"&action="+action, true);
 
  http.onreadystatechange=function() 
	{ 
		if(http.readyState == 4) 
		{
		  $("#loading_"+action).hide(); 
		  document.getElementById(action).innerHTML = http.responseText;
		  $("#"+action).show();  
		} 
	}
  http.send(null);
}




function change_content(action,id) {
	//alert(window.location.hostname);
	//alert(action);
	$("#new_message").removeClass('sel');
	$("#inbox").removeClass('sel');
	$("#sent").removeClass('sel');
	$("#personal_details").removeClass('sel');
	$("#manage_photos").removeClass('sel');
	$("#friends").removeClass('sel');
	$("#fans").removeClass('sel');
	$("#comments").removeClass('sel');
	$("#account_settings").removeClass('sel');
	$("#approve").removeClass('sel');
	$("#favorites").removeClass('sel');
	$("#authors").removeClass('sel');
	$("#myquotes").removeClass('sel');
	$("#contacts").removeClass('sel');
	$("#frnd_li"+id).removeClass('sel');
	
	//$("#myquotes").removeClass('sel');
	//$("#authors").removeClass('sel');
	//$("#favorites").removeClass('sel');
	
    $("#to").html("");
	
	$("#show_email").hide();
	$("#show_email_sent").hide();
	$("#show_approve").hide();
	$("#show_friend_approve").hide();
	$("#"+id).hide();
	$("#show_del1").hide();
	$("#inbox"+id).hide();
	$("#show_new_message").hide();
	$("#show_frnds").hide();
	$("#show_favorites").hide();
	$("#show_authors").hide();
	$("#show_contacts").hide();
	$("#show_myquotes").hide();
	$("#show_profile_update").hide();
	
	$("#content_new_message").hide();
	$("#show_request_sent").hide();
	$("#content_new_message").hide();
	$("#content_inbox").hide();
	$("#content_sent").hide();
	$("#content_personal_details").hide();
	$("#content_manage_photos").hide();
	$("#content_friends").hide();
	$("#content_fans").hide();
	$("#content_comments").hide();
	$("#content_account_settings").hide();
	$("#content_approve").hide();
	$("#content_favorites").hide();
	$("#content_authors").hide();
	$("#content_myquotes").hide();
	$("#content_contacts").hide();
	$("#content_del1").hide();
	$("#frnd_li"+id).hide();
	$("#content_personal_details").hide();
	
	
	
	
	$("#"+action).addClass('sel');
	$("#profile_content").hide();
	$("#content_"+action).hide();
	$("#loading").fadeIn(); 
/*	
var http = false;
if(navigator.appName == "Microsoft Internet Explorer") { http = new ActiveXObject("Microsoft.XMLHTTP"); } else { http = new XMLHttpRequest(); }

  http.open("GET", "http://"+window.location.hostname+"/quotes/users/manage_users_actions.php?id="+id+"&action="+action, true);
 
  http.onreadystatechange=function() { if(http.readyState == 4) {$("#loading").hide(); document.getElementById("profile_content").innerHTML = eval("http.responseText"); $("#profile_content").show();  } }
  http.send(null);*/
  $("#loading").hide(); 
  $("#content_"+action).show();
 
}


function show_mail(id,read) {
	//alert(window.location.hostname);
	//alert(action);
	
	$("#content_inbox").hide();
	
	$("#loading").fadeIn(); 

var http = false;
if(navigator.appName == "Microsoft Internet Explorer") { http = new ActiveXObject("Microsoft.XMLHTTP"); } else { http = new XMLHttpRequest(); }

 /*  http.open("GET", "http://"+window.location.hostname+"/users/do_manage_users_actions.php?show_email="+id, true); */
  
  http.open("GET", "http://"+window.location.hostname+"/index.php?p=showmail&show_email="+id, true);
  
  

  http.onreadystatechange=function() { if(http.readyState == 4) {$("#loading").hide(); document.getElementById("show_email").innerHTML = eval("http.responseText"); $("#show_email").show();  } }

if(read==0){ 
var tot =  parseInt($("#tot_message").text());
	if(tot>0)
	tot=tot-1;
	$("#tot_message").text(tot);
	$("#inbox" + id).removeClass('msg_new');
}
	http.send(null);
}




function show_mail_sent(id) {
	//alert(window.location.hostname);
	//alert(action);
	
	$("#content_sent").hide();
	
	$("#loading").fadeIn(); 

	var http = false;
	if(navigator.appName == "Microsoft Internet Explorer") { http = new ActiveXObject("Microsoft.XMLHTTP"); } else { http = new XMLHttpRequest(); }

	http.open("GET", "http://"+window.location.hostname+"/index.php?p=sentmail&show_email_sent="+id, true);
 
	http.onreadystatechange=function() { if(http.readyState == 4) {$("#loading").hide(); document.getElementById("show_email_sent").innerHTML = eval("http.responseText"); $("#show_email_sent").show();  } }
	http.send(null);
}


/////////////////////////////////////////// Approve friends//////////////////////////////////////////////////////////////////


function approve(id) {

	
	
	$("#loading").fadeIn(); 

	var http = false;
	if(navigator.appName == "Microsoft Internet Explorer") { http = new ActiveXObject("Microsoft.XMLHTTP"); } else { http = new XMLHttpRequest(); }
  
    http.open("GET", "http://"+window.location.hostname+"/index.php?p=approve&approve_id="+id, true);

 
    http.onreadystatechange=function() { 
	   if(http.readyState == 4) {
		   $("#loading").hide(); 
		   
		   $("#show_friend_approve").html( "<p>"+$("#"+id).find('h3:first').html()+" fue agreagdo a tu lista !</p>"); 
		   $("#show_friend_approve").show();  
		   var tot =  parseInt($("#tot_approval").text());
		   if(tot>0)
			tot=tot-1;
			$("#tot_approval").text(tot);
						
			$("#"+id).hide();		
			if(tot==0){
				$("#content_approve").html('<div class="scroll"><p style="color:#4F82CB"><b>No tienes solucitudes de amistad</b></p></div>');
			}
			
			var tot =  parseInt($("#tot_friend").text());
			if(tot==0)
			$("#content_approve_friends").html("");
			tot=tot+1;
			$("#tot_friend").text(tot);	
			$("#content_approve_friends").append(eval("http.responseText"));
			$("#del_friend_btn").show();
			
					
	   } 
    }

 
	

   
	http.send(null); 
}

//////////////////////////////////////Deny friends//////////////////////////////////////////////////////////////////////////
function deny(id) {
	//alert(window.location.hostname);
	//alert(action);

	
	$("#loading").fadeIn(); 

	var http = false;
	if(navigator.appName == "Microsoft Internet Explorer") { http = new ActiveXObject("Microsoft.XMLHTTP"); } else { http = new XMLHttpRequest(); }

    http.open("GET", "http://"+window.location.hostname+"/index.php?p=deny&deny_id="+id, true);

    http.onreadystatechange=function() { 
	   if(http.readyState == 4) {
		   $("#loading").hide(); 
		   $("#show_friend_approve").html(eval("http.responseText")); 
		   $("#show_friend_approve").show();  
		   var tot =  parseInt($("#tot_approval").text());
		   if(tot>0)
			tot=tot-1;
			$("#tot_approval").text(tot);
			if(tot==0){
				$("#content_approve").html('<div class="scroll"><p style="color:#4F82CB"><b>No tienes solicitudes de amistad.</b></p></div>');
			}
			$("#"+id).hide();			
	   }   
    }
    http.send(null); 
}
///////////////////////////////////////////////////


function inbox_delete1(ids) {
var namelist = '';

with(document.myform2) {
var j = 0;
for(var i = 0; i < del_in.length; i++){
if(del_in[i].checked) {

namelist += ((j==0) ? '' : ',') + del_in[i].value;

j++;
}
}
}

if(namelist == '')

{
alert("Por favor, alija por lo menos uno");
return;

}

if(!confirm("Borrar mensaje?")) return;

	$("#loading").fadeIn(); 

var http = false;
if(navigator.appName == "Microsoft Internet Explorer") { http = new ActiveXObject("Microsoft.XMLHTTP"); } else { http = new XMLHttpRequest(); }

 /*  http.open("GET", "http://"+window.location.hostname+"/users/do_manage_users_actions.php?show_email="+id, true); */
  
  http.open("GET", "http://"+window.location.hostname+"/index.php?p=delete_inbox1&mail_id1="+namelist, true);

 
   http.onreadystatechange=function() { if(http.readyState == 4) {$("#loading").hide(); document.getElementById("show_email").innerHTML = eval("http.responseText"); $("#show_email").show();  
setTimeout("document.getElementById('show_email').style.display='none'",2000);    } }
  http.send(null); 
	  
	  
var namelist_arr = namelist.split(',');
for (var key in namelist_arr)
{
if(!namelist_arr.hasOwnProperty(key)) continue;
var id = namelist_arr[key];
	 // $("#user_info_"+id).remove();
	 $("#inbox"+id).remove();
}

}

function inbox_delete12(ids) {
var id = '';
var y = 0;
for(var x=0; x<ids.length; x++){
if(ids[x].checked == true){
//id += (y == 0 ? '' : ',') + ids[x].value;
//$("#inbox"+ids[x].value).hide();
id = ids[x].value;
	
	$("#loading").fadeIn(); 

var http = false;
if(navigator.appName == "Microsoft Internet Explorer") { http = new ActiveXObject("Microsoft.XMLHTTP"); } else { http = new XMLHttpRequest(); }

 /*  http.open("GET", "http://"+window.location.hostname+"/users/do_manage_users_actions.php?show_email="+id, true); */
  
  http.open("GET", "http://"+window.location.hostname+"/index.php?p=delete_inbox1&mail_id1="+id, true);

 
   http.onreadystatechange=function() { if(http.readyState == 4) {$("#loading").hide(); document.getElementById("show_email").innerHTML = eval("http.responseText"); $("#show_email").show();  
setTimeout("document.getElementById('show_email').style.display='none'",2000);    } }
  http.send(null); 
  $("#inbox"+id).hide();
y++;
}
}
}

	
/////////////////////////////////////////////////


function inbox_delete2(id) {
	//alert(window.location.hostname);
	//alert(action);
	$("#show_email").hide();
	
	
	$("#loading").fadeIn(); 

var http = false;
if(navigator.appName == "Microsoft Internet Explorer") { http = new ActiveXObject("Microsoft.XMLHTTP"); } else { http = new XMLHttpRequest(); }

  http.open("GET", "http://"+window.location.hostname+"/index.php?p=delete_inbox&mail_id2="+id, true);


   http.onreadystatechange=function() { if(http.readyState == 4) {$("#loading").hide(); document.getElementById("show_del1").innerHTML = eval("http.responseText"); $("#show_del1").show(); 	$("#inbox"+id).hide(); } }
   
  http.send(null); 
}

//////////////*******************************************///////////////////

/////////////////////////************** Outbox delete***************////////////////////////////

function outbox_delete1(ids) {
var namelist = '';

with(document.myform3) {
var j = 0;
for(var i = 0; i < del_out.length; i++){
if(del_out[i].checked) {

namelist += ((j==0) ? '' : ',') + del_out[i].value;

j++;
}
}
}

if(namelist == '')

{
alert("Por favor, elige por lo menos uno");
return;

}
if(!confirm("Borrar mensaje?")) return;

	$("#loading").fadeIn(); 

var http = false;
if(navigator.appName == "Microsoft Internet Explorer") { http = new ActiveXObject("Microsoft.XMLHTTP"); } else { http = new XMLHttpRequest(); }

 /*  http.open("GET", "http://"+window.location.hostname+"/users/do_manage_users_actions.php?show_email="+id, true); */
  
  http.open("GET", "http://"+window.location.hostname+"/index.php?p=delete_outbox1&mail_id1="+namelist, true);

 
   http.onreadystatechange=function() { if(http.readyState == 4) {$("#loading").hide(); document.getElementById("show_email").innerHTML = eval("http.responseText"); $("#show_email").show();  
setTimeout("document.getElementById('show_email').style.display='none'",2000);    } }
  http.send(null); 
	  
	  
var namelist_arr = namelist.split(',');
for (var key in namelist_arr)
{
if(!namelist_arr.hasOwnProperty(key)) continue;
var id = namelist_arr[key];
	 // $("#user_info_"+id).remove();
	 $("#inbox"+id).remove();
}
}

////////////////////////////////////////////////////////////////////////////////////////////////

/////////////////////////////////////////////////


function outbox_delete2(id) {
	//alert(window.location.hostname);
	//alert(action);
	$("#show_email_sent").hide();
	
	
	$("#loading").fadeIn(); 

var http = false;
if(navigator.appName == "Microsoft Internet Explorer") { http = new ActiveXObject("Microsoft.XMLHTTP"); } else { http = new XMLHttpRequest(); }

  http.open("GET", "http://"+window.location.hostname+"/index.php?p=delete_outbox2&mail_id2="+id, true);


   http.onreadystatechange=function() { if(http.readyState == 4) {$("#loading").hide(); document.getElementById("show_del1").innerHTML = eval("http.responseText"); $("#show_del1").show(); 	$("#inbox"+id).hide(); } }
   
  http.send(null); 
}

//////////////*******************************************///////////////////

function new_mail() {

var name = document.getElementById('to').value;
if (name==null || name=="")
  {
  alert("Falta el usuario!");
  return false;
  }

var subject = document.getElementById('subject').value;
if (subject==null || subject=="")
  {
  alert("Falta el asunto!");
  return false;
  }

var body = document.getElementById('body').value;
if (body==null || body=="")
  {
  alert("Falta el mensaje!");
  return false;
  }
var captcha = document.getElementById('captcha27').value;
if (captcha==null || captcha=="")
  {
  alert("captcha field is empty!");
  return false;
  }
	//$("#loading").fadeIn();
document.getElementById('loading').style.display = 'block';	

var http = false;
if(navigator.appName == "Microsoft Internet Explorer") { http = new ActiveXObject("Microsoft.XMLHTTP"); } else { http = new XMLHttpRequest(); }


	http.open("GET", "http://"+window.location.hostname+"/index.php?p=newmail&username="+name+"&sub="+subject+"&body="+body + "&captcha27=" + captcha, true);
	
 
  // http.onreadystatechange=function() { if(http.readyState == 4) {$("#loading").hide(); document.getElementById("show_approve").innerHTML = eval("http.responseText"); $("#show_approve").show();  } }
   http.onreadystatechange=function() { if(http.readyState == 4) {document.getElementById('loading').style.display = 'none';	 document.getElementById("show_approve").innerHTML = eval("http.responseText"); document.getElementById('show_approve').style.display = 'block';new_image1();	  } }

  http.send(null); 
  
  
}

///////////////////************Reply****************//////////////////////

function mail_reply(uname){

	
	$("#show_email").hide();
	
	$("#to").val(uname);
	
	$("#content_new_message").show();


	
}
////////////////////////////////////////////////////////////////////////////////
/////////////////////////************** Delete Friend***************////////////////////////////

function delete_friend(ids) {

var namelist = '';
with(document.myform7) {
var j = 0;
for(var i = 0; i < del_fr.length; i++){

if(del_fr[i].checked) {
 
namelist += ((j==0) ? '' : ',') + del_fr[i].value;

j++;
}
}
}

if(namelist == '')

{
alert("Por favor, elije por lo menos uno");
return;

}

if(!confirm("Deseas quitar de favoritos?")) return;
	
	$("#loading").fadeIn(); 

var http = false;
if(navigator.appName == "Microsoft Internet Explorer") { http = new ActiveXObject("Microsoft.XMLHTTP"); } else { http = new XMLHttpRequest(); }

 /*  http.open("GET", "http://"+window.location.hostname+"/users/do_manage_users_actions.php?show_email="+id, true); */
  
  http.open("GET", "http://"+window.location.hostname+"/index.php?p=delallmyfriend&friend_id="+namelist, true);

 http.onreadystatechange=function() { 
	 if(http.readyState == 4) {		 
		 $("#loading").hide(); 
		 document.getElementById("show_email").innerHTML = eval("http.responseText"); 
		 $("#show_email").show();
		 
	 }  
 }
 http.send(null); 
 
 var namelist_arr = namelist.split(',');
for (var key in namelist_arr)
{
if(!namelist_arr.hasOwnProperty(key)) continue;
var id = namelist_arr[key];
	 // $("#user_info_"+id).remove();	 
	  $("#friend_li"+id).remove();
	 
}

		 var tot =  parseInt($("#tot_friend").text());
		 tot=tot-namelist_arr.length;
		 $("#tot_friend").text(tot);
		 if(tot<=0)
		 $("#del_friend_btn").hide();
		 var empty="No tienes amigos todavia";
		 $("#content_approve_friends").text(empty);
		 
 
		 y++; 
}


////////////////////////////////////////////////////////////////////////////////////////////////


function delete_author(ids) {


var namelist = '';

with(document.myform9) {
var j = 0;
for(var i = 0; i < del_a.length; i++){

if(del_a[i].checked) {
 
namelist += ((j==0) ? '' : ',') + del_a[i].value;

j++;
}
}
}

if(namelist == '')

{
alert("Por favor, elige por lo menos uno");
return;

}

if(!confirm("Deseas quitar favoritos?")) return;

	$("#loading").fadeIn(); 
var http = false;
if(navigator.appName == "Microsoft Internet Explorer") { http = new ActiveXObject("Microsoft.XMLHTTP"); } else { http = new XMLHttpRequest(); }

 /*  http.open("GET", "http://"+window.location.hostname+"/users/do_manage_users_actions.php?show_email="+id, true); */
  
  http.open("GET", "http://"+window.location.hostname+"/index.php?p=delauthor&author_id="+namelist, true);

 http.onreadystatechange=function() { if(http.readyState == 4) {$("#loading").hide(); document.getElementById("show_authors").innerHTML = eval("http.responseText"); $("#show_authors").show();  } }
  http.send(null); 
  
  
var namelist_arr = namelist.split(',');
for (var key in namelist_arr)
{
if(!namelist_arr.hasOwnProperty(key)) continue;
var id = namelist_arr[key];
	 // $("#user_info_"+id).remove();	 
	  $("#author_del_"+id).remove();
	 
}
			

		}

function delete_author_single(id) {

if(!confirm("Deseas quitar de favoritos?")) return;

$("#loading").fadeIn(); 

var http = false;
if(navigator.appName == "Microsoft Internet Explorer") { http = new ActiveXObject("Microsoft.XMLHTTP"); } else { http = new XMLHttpRequest(); }

 /*  http.open("GET", "http://"+window.location.hostname+"/users/do_manage_users_actions.php?show_email="+id, true); */
  
  http.open("GET", "http://"+window.location.hostname+"/index.php?p=delauthor&author_id="+id, true);

 http.onreadystatechange=function() { if(http.readyState == 4) {$("#loading").hide(); document.getElementById("show_authors").innerHTML = eval("http.responseText"); $("#show_authors").show();  } }
  http.send(null); 
  $("#author_del_"+id).hide();
  

}

////////////////////////////////////////////////////////////////////////////////////////////////


function delete_quote(ids) {

var namelist = '';

with(document.myform8) {
var j = 0;
for(var i = 0; i < del_q.length; i++){

if(del_q[i].checked) {
 
namelist += ((j==0) ? '' : ',') + del_q[i].value;

j++;
}
}
}

if(namelist == '')

{
alert("Please select atleast one");
return;

}

if(!confirm("Are you sure you want to unfavorite this?")) return;


				
				$("#loading").fadeIn(); 

			var http = false;
			if(navigator.appName == "Microsoft Internet Explorer") { http = new ActiveXObject("Microsoft.XMLHTTP"); } else { http = new XMLHttpRequest(); }

			 /*  http.open("GET", "http://"+window.location.hostname+"/users/do_manage_users_actions.php?show_email="+id, true); */
			  
			  http.open("GET", "http://"+window.location.hostname+"/index.php?p=delfavorite&quote_id="+namelist, true);

			 http.onreadystatechange=function() { if(http.readyState == 4) {$("#loading").hide(); document.getElementById("show_favorites").innerHTML = eval("http.responseText"); $("#show_favorites").show();} }
			  http.send(null); 
			  
  var namelist_arr = namelist.split(',');
for (var key in namelist_arr)
{
if(!namelist_arr.hasOwnProperty(key)) continue;
var id = namelist_arr[key];
	 // $("#user_info_"+id).remove();	 
	  $("#quote_del_"+id).remove();
	 
}
			

		}


function delete_single_quote(id) {
				
			$("#loading").fadeIn(); 

			var http = false;
			if(navigator.appName == "Microsoft Internet Explorer") { http = new ActiveXObject("Microsoft.XMLHTTP"); } else { http = new XMLHttpRequest(); }

			 /*  http.open("GET", "http://"+window.location.hostname+"/users/do_manage_users_actions.php?show_email="+id, true); */
			  
			  http.open("GET", "http://"+window.location.hostname+"/index.php?p=delfavorite&quote_id="+id, true);

			 http.onreadystatechange=function() { if(http.readyState == 4) {$("#loading").hide(); document.getElementById("show_favorites").innerHTML = eval("http.responseText"); $("#show_favorites").show();  $("#quote_del_"+id).hide();} }
			  http.send(null); 
			  

			

		
	
}


////////////////////////////////////////////////////////////////////////////////////////////////
function show_user_quotes(tot, page){

  if(page == undefined){
  page =1;
  
var load_html = '<span id="quote_timer2" style="margin-top:70px;visibility: hidden;"><center><img width="15" height="15" style="border: none; background: #fff;" src="/images/loading.gif"></center></span>';

  document.getElementById('profile_subcontent').innerHTML=load_html;
  }

		document.getElementById('quote_timer2').style.visibility = 'visible';
	
//$("#loading").fadeIn(); 

var http = false;
if(navigator.appName == "Microsoft Internet Explorer") { http = new ActiveXObject("Microsoft.XMLHTTP"); } else { http = new XMLHttpRequest(); }
  
	http.open("GET", "http://"+window.location.hostname+"/index.php?p=showmyquote&page="+page+"&tot="+tot, true);
	http.onreadystatechange=function() { if(http.readyState == 4) {
	document.getElementById('quote_timer2').style.visibility = 'hidden';
	//$("#loading").hide(); document.getElementById("myquote").innerHTML = eval("http.responseText"); 
	document.getElementById('myquote').innerHTML=http.responseText; document.getElementById("loadingimg").style.display="none";
 //$("#show_myquotes").show();  
 } 
addStuff();
}
http.send(null); 
	
}

function delete_myquote(ids) {



var namelist = '';

with(document.myform10) {
var j = 0;
for(var i = 0; i < del_mq.length; i++){
if(del_mq[i].checked) {

namelist += ((j==0) ? '' : ',') + del_mq[i].value;

j++;
}
}
}

if(namelist == '')

{
alert("Por favor, elege por lo menos uno");
return;

}

if(!confirm("Borrar frases?")) return;

	$("#loading").fadeIn(); 

var http = false;
if(navigator.appName == "Microsoft Internet Explorer") { http = new ActiveXObject("Microsoft.XMLHTTP"); } else { http = new XMLHttpRequest(); }

 /*  http.open("GET", "http://"+window.location.hostname+"/users/do_manage_users_actions.php?show_email="+id, true); */
  
  http.open("GET", "http://"+window.location.hostname+"/index.php?p=delmyquote&quote_id="+namelist, true);

 http.onreadystatechange=function() { if(http.readyState == 4) {
 
 $("#loading").hide(); document.getElementById("show_myquotes").innerHTML = eval("http.responseText"); 

 $("#show_myquotes").show();  
 } 
 }
 http.send(null); 

  var namelist_arr = namelist.split(',');
for (var key in namelist_arr)
{
if(!namelist_arr.hasOwnProperty(key)) continue;
var id = namelist_arr[key];
	 // $("#user_info_"+id).remove();
	  $("#myquote_del_"+id).remove();
	  
	 
}

}


function delete_myquote_single(id) {

if(!confirm("Borrar esta frase?")) return;
$("#loading").fadeIn(); 

var http = false;
if(navigator.appName == "Microsoft Internet Explorer") { http = new ActiveXObject("Microsoft.XMLHTTP"); } else { http = new XMLHttpRequest(); }
  
  http.open("GET", "http://"+window.location.hostname+"/index.php?p=delmyquote&quote_id="+id, true);

 http.onreadystatechange=function() { if(http.readyState == 4) {
 
 $("#loading").hide(); document.getElementById("show_myquotes").innerHTML = eval("http.responseText"); 
 $("#myquote_del_"+id).hide();
 $("#show_myquotes").show();  
 } 
 }
 http.send(null); 

  
}


///////////////////////////////////////////////////////////////////////////////
//////////////////////////////////////////////////////////////////////////////
function myquoteedit (id)
{
	//alert(id);
	var quoteDiv = $('#myquote_del_'+id);
	var val = $("#quote_" + id).text();
	var val_author = $('.readmore', quoteDiv).text();
	var author_id = $('.readmore', quoteDiv).attr('id').replace('author-', '');
	
	$('#quote_'+id).hide();
	$('#myquote_'+id).hide();
	$('#del_'+id).hide();
	$('#edit_'+id).hide();
	$('.readmore', quoteDiv).hide();
	/*
	 * create the edit inputs and their actions
	 */
	
	
	//<label for="quote-author-'+id+'">Author:</label>
	//'<input type="text" name="author" id="quote-author-'+id+'" value="'+val_author+'" />'+
	var elem = $('<div id="div-'+id+'">'+
		'<label for="quote-text-'+id+'">Frase:</label><input class="input_quote" type="text" name="quote" id="quote-text-'+id+'" value="'+val+'" />'+
		' '+val_author+
		'<input class="button_small btn_save" id="save_'+id+'" type="button" value="Save" /> '+
		'<input class="button_small btn_cancel" id="cancel_'+id+'" type="button" value="Cancel" /> '+
		'</div>'
		);
	$('#myquote_del_'+id+' p').append(elem);
	
	$('.btn_save').click(function (){
		var id = $(this).attr('id').replace('save_', '');
		var quoteDiv = $('#myquote_del_'+id);
		
		var quote = $('#quote-text-'+id).val();
		var author = $('#quote-author-'+id).val();
		
		$.get('/editmyquote', { 'quote': quote, 'quote_id': id}, function(data) {
			$("#quote_" + id).text(quote);
			$('.readmore', quoteDiv).text(author);
			
			$('#div-'+id).remove();
			$('#quote_'+id).show();
			$('#myquote_'+id).show();
			$('#del_'+id).show();
			$('#edit_'+id).show();
			$('.readmore', quoteDiv).show();
			
			//alert('Load was performed.');
		});
		
	});
	$('.btn_cancel').click(function (){
		
		var id = $(this).attr('id').replace('cancel_', '');
		$('#div-'+id).remove();
		var quoteDiv = $('#myquote_del_'+id);
		//alert(id);
		$('#quote_'+id).show();
		$('#myquote_'+id).show();
		$('#del_'+id).show();
		$('#edit_'+id).show();
		$('.readmore', quoteDiv).show();
		
		return false;
	});
	
	
	/*$("#show_myquotes").html(''); 
	$("#myquote").hide();
	$("#quote_edit").val($("#quote_" + id).text());
	$("#edit_quote_id").val(id);
	$("#myquote_edit").show();
	*/
	
}

//////////////////////////////////////////////////////////////////////////////
function edit_myquote (id, quote)
{

	$("#loading").fadeIn(); 

	var http = false;
	if(navigator.appName == "Microsoft Internet Explorer") { http = new ActiveXObject("Microsoft.XMLHTTP"); } else { http = new XMLHttpRequest(); }
	
	 /*  http.open("GET", "http://"+window.location.hostname+"/users/do_manage_users_actions.php?show_email="+id, true); */
	  
	  http.open("GET", "http://"+window.location.hostname+"/index.php?p=editmyquote&quote_id="+id+"&quote=" + quote, true);
	
	 http.onreadystatechange=function() { if(http.readyState == 4) {$("#loading").hide(); document.getElementById("show_myquotes").innerHTML = eval("http.responseText"); $("#show_myquotes").show();  } }
	  http.send(null); 
	  
	$("#myquote_del_"+id).hide();
	  
	$("#myquote").show();
	$("#myquote_edit").hide();
	
	var tot = $("#quote_"+id).text();
	var edit= $("#quote_edit").val();
	$("#quote_"+id).text(edit);	

}


//////////////////////////////////////////////////////////////////////////////


 function edit_friend_selection(ids)
{
 
var id = '';
var y = 0;
if(ids.length >= 1){
$("#btn_edit_select").hide();
$("#btn_delete_all").hide();
$("#btn_edit_save").show();
$("#btn_edit_cancel").show();

//document.getElementsByName('delete_selected').style.visibility='hidden';
}
for(var x=0; x<ids.length; x++){
if(ids[x].checked == true){

$("#user_info_" + ids[x].value).hide();
$("#update_" + ids[x].value).show();

}
}

}
////////////////////////////////////////////////////////////////////////////////


function cancel_edit(ids){
var id = '';
var y = 0;
for(var x=0; x<ids.length; x++){

$("#update_" + ids[x].value).hide();
$("#user_info_" + ids[x].value).show();
$("#btn_edit_select").show();
$("#btn_delete_all").show();
$("#btn_edit_save").hide();
$("#btn_edit_cancel").hide();

}
}
//////////////////////////////////////////////////////////////////////////////

function edit_friend_save(ids){
var id = '';
var y = 0;
for(var x=0; x<ids.length; x++){
if(ids[x].checked == true){
	$("#loading").fadeIn(); 

var http = false;
if(navigator.appName == "Microsoft Internet Explorer") { http = new ActiveXObject("Microsoft.XMLHTTP"); } else { http = new XMLHttpRequest(); }

 /*  http.open("GET", "http://"+window.location.hostname+"/users/do_manage_users_actions.php?show_email="+id, true); */
  
  http.open("GET", "http://"+window.location.hostname+"/index.php?p=editfriendsave&save=true&friend_id="+ids[x].value+ "&fullname_save=" + $("#edit_name_" + ids[x].value).val() + "&email_save=" + $("#edit_email_" + ids[x].value).val(), true);

 http.onreadystatechange=function() { if(http.readyState == 4) {$("#loading").hide(); document.getElementById("show_myquotes").innerHTML = eval("http.responseText"); $("#show_myquotes").show();  } }
  http.send(null); 

$("#user_info_name_" + ids[x].value).text($("#edit_name_" + ids[x].value).val());
$("#user_info_email_" + ids[x].value).text($("#edit_email_" + ids[x].value).val());

$("#update_" + ids[x].value).hide();
$("#user_info_" + ids[x].value).show();

}
}


$("#btn_edit_save").hide();
$("#btn_edit_select").show();

}

///////////////////////////////////////////////////////////////////////////////

function delete_single_friend(id){

var name = $.trim($("#user_info_name_" + id).text());
var email = $.trim($("#user_info_email_" + id).text());
var confirm = "Are you sure you want to remove your friend <b>" + name + "</b> (" + email + ") from database?";
confirm += '<a href="#yes" onclick="delete_myfriend(' + id + ')"><br> Yes </a> | <a href="#no" onclick="document.getElementById(\'del_confirm\').style.display = \'none\'; return false;"> No </a>';


$("#del_confirm").html(confirm);
$("#del_confirm").show();
}

function delete_myfriend(id){

$("#del_confirm").hide();

	$("#loading").fadeIn(); 

var http = false;
if(navigator.appName == "Microsoft Internet Explorer") { http = new ActiveXObject("Microsoft.XMLHTTP"); } else { http = new XMLHttpRequest(); }

 /*  http.open("GET", "http://"+window.location.hostname+"/users/do_manage_users_actions.php?show_email="+id, true); */
  
 http.open("GET", "http://"+window.location.hostname+"/index.php?p=delmyfriend&friend_id="+id, true);

 http.onreadystatechange=function() { if(http.readyState == 4) {$("#loading").hide(); document.getElementById("del_confirm").innerHTML = eval("http.responseText"); $("#del_confirm").show();
setTimeout("document.getElementById('del_confirm').style.display='block'",2000); } }
http.send(null);
  
$("#user_info_" + id).remove();


}

///////////////////////////////////////////////
function stristr (haystack, needle, bool) {
    var pos = 0;
 
    haystack += '';
    pos = haystack.toLowerCase().indexOf( (needle+'').toLowerCase() );    if (pos == -1){
        return false;
    } else{
        if (bool) {
            return haystack.substr( 0, pos );        } else{
            return haystack.slice( pos );
        }
    }
}

function del_check(iname){
if (iname == ''){
alert('Please select a value');
return false;
}


var ids = document.getElementsByName(iname);
var y = 0;
var chk = false;
var confr = false;
for(var x=0; x<ids.length; x++){
if(ids[x].checked == true) chk = true;
}
if(chk){
confr = confirm("Are you sure want to delete?");
}
return confr;

}

function add_friend1(email, fullname){

if(email == '' || fullname == '') {
alert('Please fill the fields!');
return false;
}
	$("#loading").fadeIn(); 

var http = false;
if(navigator.appName == "Microsoft Internet Explorer") { http = new ActiveXObject("Microsoft.XMLHTTP"); } else { http = new XMLHttpRequest(); }

 /*  http.open("GET", "http://"+window.location.hostname+"/users/do_manage_users_actions.php?show_email="+id, true); */
  
 http.open("GET", "http://"+window.location.hostname+"/index.php?p=addmyfriend&email="+email+ "&fullname=" + fullname, true);

 http.onreadystatechange=function() { if(http.readyState == 4) {$("#loading").hide(); document.getElementById("show_email").innerHTML = eval("http.responseText"); $("#show_email").show(); 
setTimeout("document.getElementById('show_email').style.display='block'",2000); update_edit_friendlist(); } }
http.send(null);
 

}

function update_edit_friendlist(){

    var http = false;
if(navigator.appName == "Microsoft Internet Explorer") { http = new ActiveXObject("Microsoft.XMLHTTP"); } else { http = new XMLHttpRequest(); } 
 http.open("GET", "http://"+window.location.hostname+"/index.php?p=updateeditfriend");

 http.onreadystatechange=function() { if(http.readyState == 4) {$("#loading").hide(); document.getElementById("friends_edit_container").innerHTML = eval("http.responseText"); 
 } }
  http.send(null); 
  
}
//////////////////////////////////////////////
function delete_all_friends(ids) {
var namelist = '';

with(document.frs) {
var j = 0;
for(var i = 0; i < ck_friends.length; i++){
if(ck_friends[i].checked) {

namelist += ((j==0) ? '' : ',') + ck_friends[i].value;

j++;
}
}
}

	$("#loading").fadeIn(); 

	var http = false;
	if(navigator.appName == "Microsoft Internet Explorer") { http = new ActiveXObject("Microsoft.XMLHTTP"); } else { http = new XMLHttpRequest(); }

	 /*  http.open("GET", "http://"+window.location.hostname+"/users/do_manage_users_actions.php?show_email="+id, true); */
	  
	  http.open("GET", "http://"+window.location.hostname+"/index.php?p=delallfriend&delete_id="+namelist, true);

	 http.onreadystatechange=function() { if(http.readyState == 4) {$("#loading").hide(); document.getElementById("show_email").innerHTML = eval("http.responseText"); $("#show_email").show();  } }
	  http.send(null); 
	  
	  
var namelist_arr = namelist.split(',');
for (var key in namelist_arr)
{
if(!namelist_arr.hasOwnProperty(key)) continue;
var id = namelist_arr[key];
	  $("#user_info_"+id).remove();
	 $("#update_"+id).remove();
}

}



function validate(form) {

with(document.form1) {
for(var i = 0; i < ck_friends.length; i++){
if(ck_friends[i].checked) {
namelist += ck_friends[i].value + "\n";
}
}
}
if(namelist == "") {
alert("select names");
} else {
alert (namelist);
}
return false;
}


//////////////////////////////////////////////////////////////////////////////

function account_update(ids){

var pass1= $("#pass").val();
var pass2= $("#new_pass").val();
var mail= $("#update_email").val();
var msg= '0';
var ltr= '0';
var cum = '0';
var nom = '0';
if($("#daily_msg").attr("checked")){
msg = '1';
}
if( $("#monthly_newsletter").attr("checked")){
ltr = '1';
}
if( $("#show_birthday").attr("checked")){
cum = '1';
}
if( $("#show_name").attr("checked")){
nom = '1';
}
  
  var http = false;
if(navigator.appName == "Microsoft Internet Explorer") { http = new ActiveXObject("Microsoft.XMLHTTP"); } else { http = new XMLHttpRequest(); }

  http.open("GET", "http://"+window.location.hostname+"/index.php?p=accountupdate&old_password="+pass1+ "&new_password="+pass2+"&e-mail="+mail+"&cum1="+cum+"&nom1="+nom+"&dmsg="+msg+"&mltr="+ltr, true);
 
  http.onreadystatechange=function() { if(http.readyState == 4) {$("#loading").hide(); document.getElementById("show_email_sent").innerHTML = eval("http.responseText"); $("#show_email_sent").show();  } }
  http.send(null);
  
}

//////////////////////////////////////////////////


function photo_fb(ids){


var fb1 = '0';
if($("#fb_photo").attr("checked")){
fb1 = '1';
}
  
  var http = false;
if(navigator.appName == "Microsoft Internet Explorer") { http = new ActiveXObject("Microsoft.XMLHTTP"); } else { http = new XMLHttpRequest(); }

  http.open("GET", "http://"+window.location.hostname+"/index.php?p=fbphoto&fb_ph="+fb1, true);
 
  http.onreadystatechange=function() { if(http.readyState == 4) {$("#loading").hide(); document.getElementById("show_email_sent").innerHTML = eval("http.responseText"); $("#show_email_sent").show();  } }
  http.send(null);
  
}

/////////////////////////////////////////////////////////

function report_profile(profile_id,page) {
//alert(profile_id);
//alert(page);
var is = '';
if(page == 'quote') is = '_quote';

var name = document.getElementById('name'+is).value;
if (name==null || name=="")
  {
  alert("Falta el nombre!");
  return false;
  }

var email = document.getElementById('email'+is).value;
if (email==null || email=="")
  {
  alert("Falta el correo!");
  return false;
  }

var abuse = document.getElementById('abuse'+is).value;
if (abuse==null || abuse=="")
  {
  alert("Falta el abuso!");
  return false;
  }
var captcha = document.getElementById('captcha11'+is).value;

if (captcha==null || captcha=="")
  {
  alert("captcha field is empty!");
  return false;
  }
	//$("#loading").fadeIn();
document.getElementById('loading').style.display = 'block';	

var http = false;
if(navigator.appName == "Microsoft Internet Explorer") { http = new ActiveXObject("Microsoft.XMLHTTP"); } else { http = new XMLHttpRequest(); }


	http.open("GET", "http://"+window.location.hostname+"/index.php?p=reportprofile&name="+name+"&mail="+email+"&abuse="+abuse+"&captcha11="+captcha+"&id="+profile_id+"&what="+page, true);
	
 
  // http.onreadystatechange=function() { if(http.readyState == 4) {$("#loading").hide(); document.getElementById("show_approve").innerHTML = eval("http.responseText"); $("#show_approve").show();  } }
   http.onreadystatechange=function() { if(http.readyState == 4) {
   document.getElementById('loading').style.display = 'none';	 document.getElementById("abuse_form"+is).innerHTML = eval("http.responseText"); document.getElementById('abuse_form'+is).style.display = 'block';eval("new_image2"+is+"()");new_image2();  } }

  http.send(null); 
  
  

}

function report_quote(quote_id,page) {
//alert(profile_id);
//alert(page);
var is = '';
if(page == 'quote') is = '_quote';

var name = document.getElementById('name'+is).value;
if (name==null || name=="")
  {
  alert("Falta el nombre!");
  return false;
  }

var email = document.getElementById('email'+is).value;
if (email==null || email=="")
  {
  alert("Falta el correo!");
  return false;
  }

var abuse = document.getElementById('abuse'+is).value;
if (abuse==null || abuse=="")
  {
  alert("Falta el abuso!");
  return false;
  }
var captcha = document.getElementById('captcha11'+is).value;

if (captcha==null || captcha=="")
  {
  alert("captcha field is empty!");
  return false;
  }
	//$("#loading").fadeIn();
document.getElementById('loading').style.display = 'block';	

var http = false;
if(navigator.appName == "Microsoft Internet Explorer") { http = new ActiveXObject("Microsoft.XMLHTTP"); } else { http = new XMLHttpRequest(); }


	http.open("GET", "http://"+window.location.hostname+"/index.php?p=reportquoteabuse&name="+name+"&mail="+email+"&abuse="+abuse+"&captcha11="+captcha+"&id="+quote_id+"&what="+page, true);
	
 
  // http.onreadystatechange=function() { if(http.readyState == 4) {$("#loading").hide(); document.getElementById("show_approve").innerHTML = eval("http.responseText"); $("#show_approve").show();  } }
   http.onreadystatechange=function() { if(http.readyState == 4) {
   document.getElementById('loading').style.display = 'none';	 document.getElementById("abuse_form"+is).innerHTML = eval("http.responseText"); document.getElementById('abuse_form'+is).style.display = 'block';eval("new_image2"+is+"()");new_image2();  } }

  http.send(null); 
  
  

}



function avatar(){

	//alert(window.location.hostname);
	//alert(action);
	
	
	
	$("#loading").fadeIn(); 

var http = false;
if(navigator.appName == "Microsoft Internet Explorer") { http = new ActiveXObject("Microsoft.XMLHTTP"); } else { http = new XMLHttpRequest(); }

  http.open("GET", "http://"+window.location.hostname+"/index.php?p=avatar", true);
 
  http.onreadystatechange=function() { if(http.readyState == 4) {$("#loading").hide(); document.getElementById("show_email_sent").innerHTML = eval("http.responseText"); $("#show_email_sent").show();  } }
  http.send(null);

}	


///////////////////////////////////////////////////////////
function profile_update(ids){

var fname= $("#fulname").val();
var dob= $("#fbyear").val() + '-' + $("#fbmonth").val() + '-' + $("#fbday").val();
var country= $("#fcountry").val();
var sex= $("#sex").val();  
var desc= $("#description").val();  


  var http = false;
if(navigator.appName == "Microsoft Internet Explorer") { http = new ActiveXObject("Microsoft.XMLHTTP"); } else { http = new XMLHttpRequest(); }


 http.open("GET", "http://"+window.location.hostname+"/index.php?p=profileupdate&fulname="+fname+ "&dob="+dob + "&country="+country + "&sex="+sex + "&desc="+desc, true);
 
  http.onreadystatechange=function() { if(http.readyState == 4) {$("#loading").hide(); document.getElementById("show_profile_update").innerHTML = eval("http.responseText"); $("#show_profile_update").show();  } } 
  http.send(null);



  
}

function add_friend(){

	var http = false;
	if(navigator.appName == "Microsoft Internet Explorer") { http = new ActiveXObject("Microsoft.XMLHTTP"); } else { http = new XMLHttpRequest(); }
	
	
	http.open("GET", window.location+"?add=friend", true);
	http.onreadystatechange=function() { 
		//console.log(http); 
		if(http.readyState == 4) {window.location.reload();} 
	} 
	http.send(null);

} 

function remove_friend(){

var http = false;
if(navigator.appName == "Microsoft Internet Explorer") { http = new ActiveXObject("Microsoft.XMLHTTP"); } else { http = new XMLHttpRequest(); }


http.open("GET", window.location+"&delete=friend", true);
http.onreadystatechange=function() { if(http.readyState == 4) {window.location.reload();} } 
http.send(null);

}
/////////////////////////////////////////////////////////////////////////////////////
function send_quote(quote_id) {

var send_mail = document.getElementById('send_mail').value;


if (send_mail==null || send_mail=="")
  {
    alert("E-mail is empty!");
  return false;
  }
  
var send_msg = document.getElementById('send_msg').value;

if (send_msg==null || send_msg=="")
  {
  alert("Message is empty!");
  return false;
  }  
  
var captcha7 = document.getElementById('captcha7').value;
if (captcha7==null || captcha7=="")
  {
  alert("captcha field is empty!");
  return false;
  }
  
var http = false;
if(navigator.appName == "Microsoft Internet Explorer") { http = new ActiveXObject("Microsoft.XMLHTTP"); } else { http = new XMLHttpRequest(); }


	http.open("GET", "http://"+window.location.hostname+"/index.php?p=sendquote&id="+quote_id+"&mails="+send_mail+"&messages="+send_msg+"&captcha7="+captcha7+"&sent=Send quote", true);
	
 
  // http.onreadystatechange=function() { if(http.readyState == 4) {$("#loading").hide(); document.getElementById("show_approve").innerHTML = eval("http.responseText"); $("#show_approve").show();  } }
   http.onreadystatechange=function() { if(http.readyState == 4) {document.getElementById('loading').style.display = 'none';	 document.getElementById("send_it").innerHTML = eval("http.responseText"); document.getElementById('send_it').style.display = 'block';new_image();	  } }

  http.send(null); 
  
  

}

function selectUser(user){

document.getElementById('to').value = user;
$('#simplemodal-overlay').hide();
$('#simplemodal-container').hide();
}


function showusers(page, sort){
 document.getElementById('ulist_timer').style.visibility = 'visible';
var http = false;
if(navigator.appName == "Microsoft Internet Explorer") { http = new ActiveXObject("Microsoft.XMLHTTP"); } else { http = new XMLHttpRequest(); }
  http.open("GET", "http://"+window.location.hostname+"/index.php?p=userlist_ajax&sort="+sort+"&page="+page, true);
  http.onreadystatechange=function() { if(http.readyState == 4) {
  document.getElementById('ulist_timer').style.visibility = 'hidden';
  document.getElementById('userlistcontainer').innerHTML=http.responseText; 
  }}
  http.send(null);	
}


////////////////////////

function importfriends(mailbox,provider,passwordbox){
if(mailbox == '' || provider == '' || passwordbox == '') {
alert('Please fill the fields!');
return false;
}

$("#loading").fadeIn();


$("#ifriend").show();

var http = false;
if(navigator.appName == "Microsoft Internet Explorer") { http = new ActiveXObject("Microsoft.XMLHTTP"); } else { http = new XMLHttpRequest(); }
  
 http.open("GET", "http://"+window.location.hostname+"/index.php?p=importfriends&email_box="+mailbox+ "&provider_box=" +provider+ "&password_box="+passwordbox + '&sent=Import friends', true);

 http.onreadystatechange=function() { if(http.readyState == 4) {$("#loading").hide();$("#friends_edit_container").hide();	 document.getElementById("ifriend").innerHTML = eval("http.responseText"); $("#ifriend").show();  } }
  http.send(null);
}


function save_import(ids) {

var id = '';
var y = 0;
for(var x=0; x<ids.length; x++){
if(ids[x].checked == true){
//id += (y == 0 ? '' : ',') + ids[x].value;
//$("#inbox"+ids[x].value).hide();
id = ids[x].value;
	
	$("#loading").fadeIn(); 

var http = false;
if(navigator.appName == "Microsoft Internet Explorer") { http = new ActiveXObject("Microsoft.XMLHTTP"); } else { http = new XMLHttpRequest(); }

 /*  http.open("GET", "http://"+window.location.hostname+"/users/do_manage_users_actions.php?show_email="+id, true); */
  
  http.open("GET", "http://"+window.location.hostname+"/index.php?p=saveimportfriends&email="+id, true);

 http.onreadystatechange=function() { if(http.readyState == 4) {$("#loading").hide(); $("#show_email").html(eval("http.responseText")); $("#show_email").show();  } }
  http.send(null); 
  
  

y++;

}
}
}

function importe_paginate(lnk){
var url = lnk.replace('p=friends', 'p=importfriends');
//alert(url);

	$("#loading").fadeIn(); 

var http = false;
if(navigator.appName == "Microsoft Internet Explorer") { http = new ActiveXObject("Microsoft.XMLHTTP"); } else { http = new XMLHttpRequest(); }

 /*  http.open("GET", "http://"+window.location.hostname+"/users/do_manage_users_actions.php?show_email="+id, true); */
  
  http.open("GET", url, true);

 http.onreadystatechange=function() { if(http.readyState == 4) {$("#loading").hide(); 
 var restxt = eval("http.responseText");
 //restxt = restxt.replace('<div id="friends_edit_container">', '');
 //restxt = restxt.replace('</div><!-- #friends_edit_container -->', '');
//alert(restxt);
 $("#ifriend").html(restxt);
 } }
  http.send(null); 
  
}

function author_favorite(id){

$("#loading").fadeIn(); 

var http = false;
if(navigator.appName == "Microsoft Internet Explorer") { http = new ActiveXObject("Microsoft.XMLHTTP"); } else { http = new XMLHttpRequest(); }
  
  http.open("GET", "http://"+window.location.hostname+"/index.php?p=authorfavorite&author_id="+id, true);

 http.onreadystatechange=function() { if(http.readyState == 4) {
 
 $("#loading").hide(); 
 
 //document.getElementById("author_confirm").innerHTML = eval("http.responseText"); $("#author_confirm").show();  
 

   $("#faved_"+id).hide();
  //setTimeout("document.getElementById('author_confirm').style.display='none'",3000); 
  
 

  
 
 } 
 }
 http.send(null);  


}
