var mail_im_user_id = 0;
var mail_im_working = false;
var mail_im_check_timeout;
	var flooding_maxnum = 10;
	var flooding_interval = 5000;
	var flooding_warnings = 2;
	var flooding_expireinterval = 600000;	
	var mail_im_tmp1 = '';//form.lasttimes.value
	var mail_im_tmp2 = '';//form.last_warning.value;
	var mail_im_tmp3 = '';//form.numwarnings.value
function chat_im(id){
	up_launchWM(user_id,id);
/*	var wnd_im = window.open(base_url+'mail/im/new/'+id,'im_'+id,"menubar=no,location=no,resizable=yes,scrollbars=yes,status=yes,width=620,height=460");
	if (typeof wnd_im == 'undefined' || wnd_im.closed ) 
		alert('A pop-up blocker has blocked an IM window.');
*/
}
function mail_im_check_flood(){
	var now=(new Date()).getTime();
	if (flooding_maxnum<=0 || flooding_interval<=0)
		return;
	var value=mail_im_tmp1;
	var lasttime="";
	var newvalue="";
	for (i=0;i<flooding_maxnum;i++)
	{
		if (value.lastIndexOf(" ")>=0)
		{
			if (i==flooding_maxnum-1)
				lasttime=value.substring(value.lastIndexOf(" ")+1,value.length);
			else
				newvalue=" "+value.substring(value.lastIndexOf(" ")+1,value.length)+newvalue;
			value=value.substring(0,value.lastIndexOf(" "));
		}
	}
	newvalue+=" "+now;
	mail_im_tmp1 = newvalue;

	if (lasttime!="" && now-lasttime<flooding_interval)
	{
		if (flooding_expireinterval > 0 && now - mail_im_tmp2 > flooding_expireinterval)
			mail_im_tmp3 = 0;
		mail_im_tmp3++;
		mail_im_tmp2 =now;
		if (mail_im_tmp3 > flooding_warnings)
		{
			alert('Flood Check: Bye.');
			window.close();
		}
		else
		{
			if (mail_im_tmp3==1)
			alert('Flood check: Cool down.');
			else
			alert('Flood check: I said Cool down.');
		}
		mail_im_tmp1="";
	}
}
function mail_im_submit(){
	clearTimeout(mail_im_check_timeout);
	if (mail_im_working==true) { setTimeout("mail_im_submit();",100); return; }
	mail_im_working = true;
	mail_im_check_flood();
	var message = $('#message').val();
	$('#message').val("");
	$.ajax({
		type: "POST",
		url: base_url+"mail/im/send/"+mail_im_user_id,
		data: 'message='+message,
		async: true,
		success: function(html){
			mail_im_working = false;
			$('#messages_list').append(html);
			var obj = document.getElementById("messages_list");
			obj['scrollTop']+=100;
			mail_im_check_timeout = setTimeout("mail_im_check();",1000);
		}
	});
}
function mail_im_check(){
	if (mail_im_working==true) { mail_im_check_timeout = setTimeout("mail_im_check();",100); return; }
	mail_im_working = true;
	$.ajax({
		type: "POST",
		url: base_url+"mail/im/receive/"+mail_im_user_id,
		async: true,
		success: function(html){
			mail_im_working = false;
			$('#messages_list').append(html);
			if (html.length>10) window.focus();
			var obj = document.getElementById('messages_list');
			obj['scrollTop']+=100;
			mail_im_check_timeout = setTimeout("mail_im_check();",1000);
		}
	});
}
function mail_im_startup(id){
	mail_im_user_id = id;
	mail_im_check();
}
function mail_im_any_message(){
	$.ajax({
		type: "POST",
		url: base_url+"mail/im/check/",
		async: true,
		success: function(html){
			if (parseInt(html)>0)
				chat_im(parseInt(html));
			if( html.indexOf('Plase log in') == -1 && html.indexOf('NoRefresh') == -1 && html.indexOf('account/billing/noacc/chat') == -1 )
				setTimeout("mail_im_any_message();",Math.round(Math.random()*5000)+5000);
			
		}
	});
}
$(document).ready(function(){
	if ($('#messages_list').length==0)//it's not a chat window...
		setTimeout("mail_im_any_message();",3000);
});
//MAIL
function mail_flirt_swap(id){
	$('.flirt_cat_title').removeClass("yellow_left");
	$('.flirt_cat_title').addClass("small_light_gray");
	$('.flirt_cat_full').hide();
	$('#flirts_'+id).show();
	$('#flirt_link_'+id).removeClass("small_light_gray");
	$('#flirt_link_'+id).addClass("yellow_left");
	$("#flirts_"+id+" input").eq(0).attr("checked","checked");
}
function mail_flirt(id){
	tb_show('',base_url+'mail/ajax/flirt/'+id+'?height=400&width=630&modal=true','');
}
function mail_flirt_submit(){
	$.ajax({
		type: "POST",
		url: base_url+"mail/ajax/sendflirt/",
		async: false,
		data: $("#FlirtCompose").serialize(),
		success: function(html){
			$('#thickbox_content').html(html);
		}
	});
}
function mail_submit(){
	$.ajax({
		type: "POST",
		url: base_url+"mail/ajax/send/",
		async: false,
		data: $("#MailCompose").serialize(),
		success: function(html){
			$('#thickbox_content').html(html);
		}
	});
}
function mail_send(id){
	tb_show('',base_url+'mail/ajax/new/'+id+'?height=400&width=550&modal=true','');
}
function mail_reply(id){
	tb_show('',base_url+'mail/ajax/reply/'+id+'?height=400&width=550&modal=true','');
}
function mail_details(id){
	tb_show('',base_url+'mail/ajax/details/'+id+'?height=400&width=550&modal=true','');
}
function mail_action_fromthickbox(action,id){
	if (action!='reply')
	{
		$('input#action').val(action);//set action
		$("input[name^='message']").attr("checked","");//uncheck all messages
		$("input#message_"+id).attr("checked","checked");//check requested message
		tb_remove();
		mail_action_submit();
	}else{
		//tb_remove();
		mail_reply(id);
	}
}
function mail_action_submit(){
	if($("input[name^='message']:checked").length==0){
			alert('Please select at least one message.'); return false;
	}
	setTimeout("$('#MailAction').submit();",100);
}
function mail_move(){
	if ($('#move_folder_id').val()==-1){
		alert('Please select a folder.'); return false;
	}
	$('input#action').val('move');mail_action_submit();
}
function mail_delete(){$('input#action').val('delete');mail_action_submit();}
function mail_block(){$('input#action').val('block');mail_action_submit();}
function mail_unread(){$('input#action').val('unread');mail_action_submit();}
function mail_check_all(){
	if ($('#all_messages').attr("checked")==true)
		$("input[name^='message']").attr("checked","checked");
	else
		$("input[name^='message']").attr("checked","");
}
function mail_check_one(){
	if ($("input[name^='message']").length==$("input[name^='message']:checked").length)
		$('#all_messages').attr("checked","checked");
	else
		$('#all_messages').attr("checked","");
}
function mail_folders_submit(){
	setTimeout("$('#FoldersManage').submit();",100);
}

//HOTLISTS
function hotlist_add(list_id,user_id){
	tb_show('',base_url+"search/addhotlists1/"+list_id+"/"+user_id+'?height=160&width=430&modal=true','');
/*	$.ajax({
		type: "POST",
		url: base_url+"search/addhotlists1/"+list_id+"/"+user_id,
		async: true,
		success: function(html){
			alert(html);
		}
	});
*/}
function hotlist_add1(){
	var list_id = 0;
	var user_id = 0;
	list_id = $('#hotlist_add').val();
	user_id = $('#hotlist_user_id').val();
	hotlist_add2(list_id,user_id);	
}
function hotlist_add2(list_id,user_id){
		$.ajax({
		type: "POST",
		url: base_url+"search/addhotlists/"+list_id+"/"+user_id,
		async: true,
		success: function(html){
			alert(html);
			tb_remove();
		}
	});
}
function hotlists_manage_submit(){
	setTimeout("$('#HotlistsManage').submit();",100);
}
//SEARCH
function search_home_submit(){
	var your_email = $('#your_email').val();
	if (your_email.length<6) { alert('Please fill in your email address.'); return false;}
	if (your_email.indexOf('@')<1 || your_email.indexOf('.')<3) {alert('Invalid e-mail address.'); return false;} 
	return true;
}
function search_photo(){
	setTimeout("$('#PhotoSearch').submit();",100);
}
function search_within(){
	var within = $('#within').val();
	if (within=='usa'||within=='uk'||within=='ca'||within=='entire')
		$('#within_of_div').hide();
	else
		$('#within_of_div').show();
}
function search_location(){
	tb_show('',base_url+'search/location?height=200&width=530&modal=true','');
}
function search_location_submit(){
	if (search_location_ziptest==false) {search_location_to_submit=true; search_zipcode(); return false; }
	if (search_location_wait==true)
	{
		search_location_to_submit=true;
		alert('Please wait...'); return false;
	}
	if($('#country').val()==1 && $('#zipcode').val().length!=5){
		alert('Invalid ZIP Code.'); return false;	
	}
	if ($('#country').val()==1 && $('#zipcode').val()!=zipok){
		alert('Invalid ZIP Code.'); return false;
	}
	if ($('#country').val()!=1 && $('#city').val().length<2){
		alert('Please fill in a City name.'); return false;
	}
	$.ajax({
		type: "POST",
		url: base_url+"search/location/save",
		async: false,
		data: $("#SearchLocation").serialize(),
		success: function(html){
			$('#thickbox_content').html(html);
			$('#within_of').html($('#to_within_of').html());
		}
	});
}
var search_location_ziptest = false;
var search_location_wait = false;
var search_location_to_submit =false;
function search_country() {
	if ($('#country').val()==1){
		$('#search_city').hide();
		$('#search_zipcode').show();
	}else{
		$('#search_zipcode').hide();
		$('#search_city').show();		
	}
}//ok
function search_zipcode() {
	if ($('#zipcode').val().length!=5) { alert('Invalid ZIP Code.'); return false; }
	$('#search_zipcode_wait').text('Validating ZIP Code...');
	search_location_wait = true;
	search_location_ziptest = true;
	$.ajax({
		type: "POST",
		url: base_url+"search/location/validatezip/",
		data: 'zipcode='+$('#zipcode').val(),
		async: true,
		success: function(html){
			search_location_wait = false;
			if (html=='OK') {
				zipok = $('#zipcode').val();
				if (search_location_to_submit) search_location_submit();
			}else{
				zipok = '';
				alert('Invalid ZIP Code.');
			}
			$("#search_zipcode_wait").text("");
		}
	});
}
function search_preferences_checkbox(f,obj){
	var sp_text = '';
	var sp_any = false;
	var sp_one = false;
	$("input[name^='"+f+"']:checked").each(function(){
		if ($(this).val()=='0') sp_any=true; else sp_one = true;
	})
	if (sp_any==true && sp_one==true)
	{
		if ($(obj).val()=='0')
		{//if any & other option selected, and just clicked any, deselect all but any
			$("input[name^='"+f+"']:checked").attr("checked","");
			$('#'+f+'_0').attr("checked","checked");
		}else
		{//deselect any
			$('#'+f+'_0').attr("checked","");
		}
	}
	if (sp_any==false && sp_one==false) $('#'+f+'_0').attr("checked","checked");
	$("input[name^='"+f+"']:checked").each(function(){
		sp_text += (sp_text.length>0?', ':'')+$(this).attr("title");
	})
	$('#'+f+'_val').text(sp_text);
}
function search_preferences_height(asd){
	var sp_text = '';
	var tmp = '';
	var obj;
	obj = document.getElementById('height_from');
	tmp = obj.options[obj.selectedIndex].title;
	if (tmp.length==0) tmp = 'any';
	sp_text = tmp+' - ';
	obj = document.getElementById('height_to');
	tmp = obj.options[obj.selectedIndex].title;
	if (tmp.length==0) tmp = 'any';
	sp_text += tmp;
	$('#height_val').text(sp_text);
}
//PROFILE
function profile_animals(){
	$("input[name^='animals']").each(function(){
		var id_breed = $(this).val();
		if ($(this).attr("checked")==true)
			$('#breeds_'+id_breed).show();
		else
			$('#breeds_'+id_breed).hide();
	});
}
function profile_add_breed(id){
	var text = $('#breeds').val();
	var text2 = $('#breeds__'+id).val();
	if (text2.length>0 && text.indexOf(text2)==-1)text += (text.length>0?', ':'')+text2;
	$('#breeds').val(text);
}
function profile_photos_check(){
	if ($('#photo_1').val()==$('#photo_2').val() ||
		$('#photo_1').val()==$('#photo_3').val() ||
		$('#photo_1').val()==$('#photo_4').val() ||
		$('#photo_2').val()==$('#photo_3').val() ||
		$('#photo_2').val()==$('#photo_4').val() ||
		$('#photo_3').val()==$('#photo_4').val()){
		alert('Duplicate order. Please select a correct order.'); return false;
	}
	return true;
}
function profile_photos_submit(){
	setTimeout("$('#ProfilePhotos').submit();",100);
}
function profile_email(){
	tb_show('',base_url+'account/ajax/change_email?height=200&width=530&modal=true','');
}
function profile_password(){
	tb_show('',base_url+'account/ajax/change_password?height=200&width=530&modal=true','');
}
function profile_email_submit(){
	if($('#old_email').val().length<6){
		alert('Please fill in your old e-mail address.'); return false;
	}
	if($('#new_email').val().length<6){
		alert('Please fill in your new e-mail address.'); return false;
	}
	if($('#new_email').val()!=$('#new_email2').val()){
		alert('The e-mails doesn\'t match.'); return false;
	}
	$.ajax({
		type: "POST",
		url: base_url+"account/ajax/change_email_save",
		async: false,
		data: $("#ChangeEmail").serialize(),
		success: function(html){
			$('#thickbox_content').html(html);
		}
	});
	
}
function profile_password_submit(){
	if($('#old_password').val().length<5){
		alert('Please fill in your old password.'); return false;
	}
	if($('#new_password').val().length<5){
		alert('Your password must be at least 5 characters long.'); return false;
	}
	if($('#new_password').val()!=$('#new_password2').val()){
		alert('The passwords doesn\'t match.'); return false;
	}
	$.ajax({
		type: "POST",
		url: base_url+"account/ajax/change_password_save",
		async: false,
		data: $("#ChangePassword").serialize(),
		success: function(html){
			$('#thickbox_content').html(html);
		}
	});
}
var profile_wait = false;
var profile_nowaitalert = false;
var profile_to_submit = false;
function profile_submit(){
	if (profile_wait==true)
	{
		profile_to_submit=true;
		if (!profile_nowaitalert) alert('Please wait...'); return false;
	}
	if($('#country').val()==1 && $('#zipcode').val().length!=5){
		alert('Invalid ZIP Code.'); return false;	
	}
	if ($('#country').val()==1 && $('#zipcode').val()!=zipok){
		alert('Invalid ZIP Code.'); return false;
	}
	if ($('#country').val()!=1 && $('#city').val().length<2){
		alert('Please fill in your City name.'); return false;
	}
	if ($('#username').val().length<5){
		alert('Your username must be at least 5 characters long.'); return false;
	}
	if ($('#real_name').val().length<2){
		alert('Please fill in your name.'); return false;
	}	
}
function profile_country() {
	if ($('#country').val()==1){
		$('#profile_city').hide();
		$('#profile_zipcode').show();
	}else{
		$('#profile_zipcode').hide();
		$('#profile_city').show();		
	}
}
function profile_zipcode() {
	profile_nowaitalert = true;
	setTimeout("profile_nowaitalert=false;",1000);
	if ($('#zipcode').val().length!=5) { alert('Invalid ZIP Code.'); return false; }
	$('#profile_zipcode_wait').text('Validating ZIP Code...');
	profile_wait = true;
	$.ajax({
		type: "POST",
		url: base_url+"account/ajax/validatezip/",
		data: 'zipcode='+$('#zipcode').val(),
		async: true,
		success: function(html){
			profile_wait = false;
			if (html=='OK') {
				zipok = $('#zipcode').val();
				if (profile_to_submit==true) setTimeout("$('#PersonalInfo').submit();",100);
			}else{
				zipok = '';profile_to_submit=false;
				alert('Invalid ZIP Code.');
			}
			$("#profile_zipcode_wait").text("");
		}
	});
}
function profile_photo_change(id) {
	$('#photo_big').attr("src",eval("imgLoader_"+id+".src"));
}
function blog_submit()
{
	if ($('#title').val().length<5)
	{
		alert('The title must have at least 5 characters.');
		return false; 	
	}
	if ($('#content').val().length<50)
	{
		alert('The content must have at least 50 characters.');
		return false; 	
	}
	setTimeout("$('#Blog').submit();",100);
	return true;
}
//REGISTER
var step=1;
var wait=false;
var zipok = '';
var usernameok = '';
var emailok = '';
var ignore_unload = false;
function register_paint() {
	var text ="Create Your Profile - ";
	if (step<=3) text += "Basics";
	else if (step<=6) text+= "Lifestyle";
	else if (step<=8) text+= "User Account";
	else if (step==9) text+= "More About You";
	else if (step==10) text+= "Photos";
	else text += "Misc.";
	$('#RegisterStepTitle').text(text);
	for (i=1;i<=11;i++)
	{
		$('#step_'+i).hide();
		$('#step_'+i+'_progress').css("background-color","#cdcdcd");
		if (i!=11)
			$('#step_'+i+'_progress2').children().attr('src',base_url+'images/sel_nesel.gif');
	}
	if (step!=11)
		$('#step_11_progress2').children().attr('src',base_url+'images/sel_end_nesel.gif');
	else 
		$('#step_11_progress2').children().attr('src',base_url+'images/sel_end_sel.gif');
	$('#step_'+step).show();
	$('#step_'+step+'_progress').css("background-color","#ff9c00");
	if (step!=11)
	$('#step_'+step+'_progress2').children().attr('src',base_url+'images/sel_st.gif');
	if (step>1)
		$('#step_'+(step-1)+'_progress2').children().attr('src',base_url+'images/sel_dr.gif');
}
function register_next() {
	if ( $.browser.msie == true )ignore_unload = true;
	if (wait==true) alert('Please wait..');
	if (step==1){
		if ($('#gender_m').attr("checked")!=true && $('#gender_f').attr("checked")!=true){
			alert('Please select your gender.'); return false;
		}
		if ($('#orientation_m').attr("checked")!=true && $('#orientation_f').attr("checked")!=true){
			alert('Please select your orientation.'); return false;
		}
	}else if (step==2){
		if($("input[name^='looking']:checked").length==0){
			alert('Please select what type of relationship you are looking for.'); return false;
		}
		if($('#status').val()==-1){
			alert('Please select your current relationship status.'); return false;
		}
	}else if (step==3){
		if($('#country').val()==-1){
			alert('Please select your country.'); return false;
		}
		if ($('#country').val()!=1 && $('#city').val().length<2){
			alert('Please fill in your City name.'); return false;
		}
		if ($('#country').val()==1 && $('#zipcode').val().length!=5){
			alert('Invalid ZIP Code.'); return false;
		}
		if ($('#country').val()==1 && $('#zipcode').val()!=zipok) { register_zipcode();return false;}
	}else if (step==4){
		if($('#smoking').val()==-1){
			alert('Please select your smoking habits.'); return false;
		}
		if($('#drinking').val()==-1){
			alert('Please select your drinking habits.'); return false;
		}
	}else if (step==5){
		if($('#education').val()==-1){
			alert('Please select your education level.'); return false;
		}
		if($('#career').val()==-1){
			alert('Please select what you do.'); return false;
		}
		if($('#ethnicity').val()==-1){
			alert('Please select your ethnicity.'); return false;
		}		
	}else if (step==6){
		if($("input[name^='animals']:checked").length==0){
			alert('Please select what animals you like or own.'); return false;
		}
		if($("#breeds").val().length==0){
			alert('Please fill in "Breeds I like or own".'); return false;
		}
		if($("#pets").val()==-1){
			alert('Please select how many pets do you have.'); return false;
		}
	}else if (step==7){
		if ($('#username_').val().length<5){
			alert('Your username must be at least 5 characters long.'); return false;
		}
		if($('#month').val()==-1){
			alert('Please select your birth month.'); return false;
		}		
		if($('#day').val()==-1){
			alert('Please select your birth day.'); return false;
		}		
		if($('#year').val()==-1){
			alert('Please select your birth year.'); return false;
		}
		if ($('#username_').val()!=usernameok) { register_username();return false;}
	}else if (step==8){
		if ($('#email').val().length<6){
			alert('Invalid e-mail address.'); return false;
		}
		if ($('#real_name').val().length<2){
			alert('Please fill in your name.'); return false;
		}
		if ($('#password_').val().length<5){
			alert('Your password must be at least 5 characters long.'); return false;
		}
		if ($('#password_').val()!=$('#password2').val()){
			alert('Passwords doesn\'t match.'); return false;
		}
		if ($('#email').val()!=emailok) { register_email();return false;}
	}else if (step==9){
		if ($('#essay').val().length<50){
			alert('Your essay should be at least 50 characters long.'); return false;
		}
	}else if (step==10) {
		//photos.. 
	}else if (step==11) {
		if ($('#agree').attr("checked")!=true){
			alert('You must read and agree to the Terms and Conditions of Service.'); return false;
		}
	}
	if(step<11) step++;
	else
	{//submit the form?
		$('step_11').hide();
		ignore_unload = true;
		setTimeout("ignore_unload=true;$('#RegisterForm').submit();",100);
	}
	register_paint();
	return false;
}
function register_prev() {
	if ( $.browser.msie == true) ignore_unload = true;
	if (step>1) step--;
	register_paint();
	return false;
}
function register_username() {
	$('#username_wait').text('Validating username...');
	wait = true;
	$.ajax({
		type: "POST",
		url: base_url+"main/ajaxsignup/validateusername/",
		data: 'username='+$('#username_').val(),
		async: true,
		success: function(html){
			wait = false;
			if (html=='OK') {
				usernameok = $('#username_').val();
				register_next();
			}else{
				alert(html);
			}
			$("#username_wait").text("");
		}
	});
}
function register_email() {
	$('#email_wait').text('Validating email...');
	wait = true;
	$.ajax({
		type: "POST",
		url: base_url+"main/ajaxsignup/validateemail/",
		async: true,
		data: 'email='+$('#email').val(),
		success: function(html){
			wait = false;
			if (html=='OK') {
				emailok = $('#email').val();
				register_next();
			}else{
				alert(html);
			}
			$("#email_wait").text("");
		}
	});
}
function register_country() {
	if ($('#country').val()==1){
		$('#register_city').hide();
		$('#register_zipcode').show();
	}else{
		$('#register_zipcode').hide();
		$('#register_city').show();		
	}
	if ($('#country').val()==-1) $('#register_city').hide();
}
function register_zipcode() {
	$('#zipcode_wait').text('Validating ZIP Code...');
	wait = true;
	$.ajax({
		type: "POST",
		url: base_url+"main/ajaxsignup/validatezip/",
		data: 'zipcode='+$('#zipcode').val(),
		async: true,
		success: function(html){
			wait = false;
			if (html=='OK') {
				zipok = $('#zipcode').val();
				register_next();
			}else{
				alert('Invalid ZIP Code.');
			}
			$("#zipcode_wait").text("");
		}
	});
}
function register_hear(){
	if($('#hear').val()==4)
		$('#hear_website_table').show();
	else
		$('#hear_website_table').hide();
}
//contact
function contact_check(){
	if ($('#name').val().length<2){
		alert('Please fill in your name.'); return false;
	}
		if ($('#email').val().length<6){
		alert('Please fill in your e-mail address.'); return false;
	}
	if ($('#subject').val().length<3){
		alert('Please fill in the subject.'); return false;
	}
	if ($('#message').val().length<5){
		alert('Please fill in the message.'); return false;
	}
	return true;
}
function tell_me_submit(){
	setTimeout("$('#TellMe').submit();",100);
}
//
/*function mail_action_fromthickbox(action,id){
	if (action!='reply')
	{
		$('input#action').val(action);//set action
		$("input[name^='message']").attr("checked","");//uncheck all messages
		$("input#message_"+id).attr("checked","checked");//check requested message
		tb_remove();
		mail_action_submit();
	}else{
		//tb_remove();
		mail_reply(id);
	}
}*/
function adm_one(id,action)
{
	$('input#action').val(action);
	$('input#one_id').val(id);
	setTimeout("$('#FormAction').submit();",100);
}
function adm_action_one(str,action)
{
	//uncheck all
	$("input[name^='"+str.substring(0,str.indexOf('_'))+"']").attr("checked","");
	$('input#'+str).attr('checked','checked');
	$('input#action').val(action);
	setTimeout("$('#FormAction').submit();",100);
}
function adm_action_submit(str,action){
	$('input#action').val(action);
	if($("input[name^='"+str+"']:checked").length==0){
			alert('Empty selection.'); return false;
	}
	setTimeout("$('#FormAction').submit();",100);
}
function adm_check_all(str){
	if ($('#all_'+str+'s').attr("checked")==true)
		$("input[name^='"+str+"']").attr("checked","checked");
	else
		$("input[name^='"+str+"']").attr("checked","");
}
function adm_check_one(str){
	if ($("input[name^='"+str+"']").length==$("input[name^='"+str+"']:checked").length)
		$('#all_'+str+'s').attr("checked","checked");
	else
		$('#all_'+str+'s').attr("checked","");
}
function getH(){
	var h;
	if(document.innerHeight){ h=document.innerHeight;
	} else if(document.documentElement.clientHeight){ h=document.documentElement.clientHeight;
	} else if(document.body){ h=document.body.clientHeight; }
	return h;
}
function adm_tpc(id)
{
	tb_show('',base_url+'admin/users/tpc/'+id+'?TB_iframe=true&KeepThis=true&height=250&width=520&modal=true','');
}

function adm_msg(id)
{
	var height = getH()-30;
	if (height<100) height = 500;
	height = Math.min(height,700);
	tb_show('',base_url+'admin/users/messages/view/'+id+'?height='+height+'&width=800&modal=true','');
}

function adm_approve(id)
{
	var height = getH()-30;
	if (height<100) height = 500;
	height = Math.min(height,700);
	tb_show('',base_url+'admin/users/new/approve/'+id+'?height='+height+'&width=800&modal=true','');
}
var crop_last_x = 0; var crop_last_y = 0;
var crop_last_w = 0; var crop_last_h = 0;

function start_crop(prm_width,prm_height){
	$('#first_preview').hide();
	$('#crop_div').show();
	crop_last_x = $('#crop_last_x').val();
	crop_last_y = $('#crop_last_y').val();
	crop_last_w = $('#crop_last_w').val();
	crop_last_h = $('#crop_last_h').val();
	$('#resizeMe').Resizable({
		ratio: 1.25,
		minWidth: Math.min(100,prm_width),
		minHeight: Math.min(100,prm_height),
		maxWidth: prm_width,
		maxHeight: prm_height,
		minTop: '0',
		minLeft: '0',
		maxRight: prm_width,
		maxBottom: prm_height,
		dragHandle: true,
		onDrag: function(x, y){
			this.style.backgroundPosition = '-' + (x ) + 'px -' + (y ) + 'px';
			crop_last_x = x;
			crop_last_y = y;
		},
		handlers: {
			se: '#resizeSE',
			e: '#resizeE',
			ne: '#resizeNE',
			n: '#resizeN',
			nw: '#resizeNW',
			w: '#resizeW',
			sw: '#resizeSW',
			s: '#resizeS'
		},
		onResize : function(size, position) {
			crop_last_w = size.width;
			crop_last_h = size.height;
			crop_last_x = position.left;
			crop_last_y = position.top;
			this.style.backgroundPosition = '-' + (position.left ) + 'px -' + (position.top ) + 'px';
		}
	});
}
var crop_submited = false;
function save_crop(to_delete){
	if (to_delete==1) 
	{
		if (!confirm('Are you sure you want to delete this photo?')) return;
		$('#delete_photo').val('1');
	}
	else $('#delete_photo').val('0');
	var height = getH()-30;
	if (height<100) height = 500;
	height = Math.min(height,700);
	var id = $('#user_to_approve_id').val();

	if(crop_submited==true) return;
	crop_submited = true;
	$('#crop_last_x').val(crop_last_x);
	$('#crop_last_y').val(crop_last_y);
	$('#crop_last_w').val(crop_last_w);
	$('#crop_last_h').val(crop_last_h);
	$.ajax({
		type: "POST",
		url: base_url+"admin/user/new/approve/",
		data: $('#Crop').serialize(),
		async: true,
		success: function(html){
			crop_submited=false;
			if (html.indexOf('OK')>-1 || html=='OK')
				tb_show('',base_url+'admin/users/new/approve/'+id+'?height='+height+'&width=800','');
			else
				parent.location=base_url+'admin/users/new';
		}
	});
}
function show_terms(){
	if ( $.browser.msie == true) ignore_unload = true;
	var height = getH()-80;
	if (height<100) height = 500;
	height = Math.min(height,700);
	$('#main_flash_div').hide();
	tb_show('',base_url+'main/terms?height='+height+'&width=850&modal=true','');
}
function tb_remove_register(){
	if ( $.browser.msie == true ) ignore_unload = true;
	tb_remove();
	$('#main_flash_div').show();
}
/*userplane*/
function up_launchWM( userID, destinationUserID, destinationName )
{
	up_localUserID = userID;
		
	window.open( "http://therightbreed.com/userplane/wm_ads.php?strDestinationUserID=" + destinationUserID, "WMWindow_" + up_replaceAlpha(userID) + "_" + up_replaceAlpha(destinationUserID), "width=700,height=750,toolbar=0,directories=0,menubar=0,status=0,location=0,scrollbars=0,resizable=1" );
}
function up_launchUL()
{		
	window.open( "http://therightbreed.com/userplane/ul_ads.php" , "ULWindow" , "width=700,height=750,toolbar=0,directories=0,menubar=0,status=0,location=0,scrollbars=0,resizable=1" );
}
function up_replaceAlpha( strIn )
{
	var strOut = "";
	for( var i = 0 ; i < strIn.length ; i++ )
	{
		var cChar = strIn.charAt(i);
		if( ( cChar >= 'A' && cChar <= 'Z' )
			|| ( cChar >= 'a' && cChar <= 'z' )
			|| ( cChar >= '0' && cChar <= '9' ) )
		{
			strOut += cChar;
		}
		else
		{
			strOut += "_";
		}
	}
	
	return strOut;
}
function up_launchChat()
{
	window.open( "http://therightbreed.com/userplane/wc_ads.php", "UserplaneChatWindow", "width=700,height=750,toolbar=0,directories=0,menubar=0,status=0,location=0,scrollbars=0,resizable=1" );
}