function count(){
	var txt = $('#status').val();
	var tt = txt.length;
	//alert($('#status').val());
	if(tt>140){
		txt = txt.substring(0,140);
		$('#status').val(txt);
		tt=140;
	}
	$('#charsc').html(140-tt);
}

function subtest(){
	var len = myUserids.length;
	//alert(len);
	var sub = false;
	var vars ='';
	if($('#status').val()==''){
		alert('Please provide a message to send.');
	}else{
		for(i=0;i<len;i++){
			//alert( 'checkb'+myUserids[i] + '-' + $('#checkb'+myUserids[i]).is(':checked'));
			//alert(i+'-'+len);
			if($('#checkb'+myUserids[i]).is(':checked')){
				sub = true;
				vars = vars + getVarsa(myUserids[i]);
			}
		}
		if(!sub){
			alert('You have to select accounts to send message to.');
		}else{
			//updateAccs();
			//alert(vars);
			sendMessage(vars);
			//$('#msg').submit();
		}
	}
}
function getVarsa(id){
	var namas=new Array('year','month','day','hr','min');
	var str='acc['+id+']=1&';
	for(ii=0;ii<5;ii++){
		//alert('#pt'+namas[i]+id);
		str=str+ namas[ii]+'['+id+']='+$('#'+namas[ii]+id).val()+'&';
	}
	return str;
}

function updateAccs(){
	var postvars = 'act=accs';
	$.post('ajax.php',postvars, function(data){
		//img_upd(2);
		//alert(data);
		$('#account_lines').html(data);
	});
}
var speed = 800;
function tiny(){
	var posturl='ajax.php';
	var sfw='0';
	if($('#longurl').val()==''){
		alert('Please provide url.');
	}else{
		if($('#sfw').attr('checked')){
			sfw='1';
		}
		var postvars = 'act=tinyurl&format=plain&sfw='+sfw+'&url='+encodeURIComponent($('#longurl').val());
		//alert(postvars);
		$('#tinyurl').animate({
			width:"50px"
		}, speed);
		$.post(posturl,postvars, function(data){
			//alert(data);
			data = 'http://thetiny.info/' + data;
			$('#tinyurl').val(data);
			$('#tinyurl').animate({
				width:"200px"
			}, speed);
		});
	}
	
}
function msg_del(id,nr){
	if(confirm('Are you sure?')){
		var postvars = 'act=del_msg&id='+id;
		$.post('ajax.php',postvars, function(data){
			//alert(data);
		});
		$('#tr'+nr).animate({
			opacity: "0"
		}, speed, function() {
			$('#tr'+nr).hide();
		});
	}
}

function sendMessage(vars){
	var postvars = vars + 'act=message&status='+encodeURIComponent($('#status').val());
	if($('#status').val().length > 0){
		// we send message status --> transparent
		$('#status').animate({
			opacity: "0"
		}, speed, function() {
			// Animation complete.
			$('#status').val('');
		});
		// notification to show
		$('#waiting').html('Sending Message ....');
		$('#waiting').animate({
			opacity: "1",
			top: "44px"
		}, speed, function(){
			// on finish
		});
		// sending post to ajax
		$.post('ajax.php',postvars, function(data){
			$('#waiting').html('Message send!');
			$('#status').animate({
				opacity: "1"
			}, speed, function(){
				// on finish
			});
			$('#waiting').animate({
				opacity: "0",
				top: "24px"
			}, speed, function(){
				// on finish
			});
		});
	}
}


function importa(){
	if($('#txtin').val()==''){
		alert('You have to Copy/Paste something into that field.');
	}else{
		var postvars = 'act=txtin1&txtin='+encodeURIComponent($('#txtin').val())+'&'+getVarsa(1)+'&days='+
		+$('#days').val()+'&hrs='+$('#hrs').val()+'&mins='+$('#mins').val();
		
		if($('#thetinycheck').is(':checked')){
			postvars = postvars + '&thetinycheck=1'
		}else{
			postvars = postvars + '&thetinycheck=0'
		}
		
		$.post('ajax.php',postvars, function(data){
			//alert(data);
			$('#preview').html(data);
		});
	}
}

function importc(){
	// import clean
	$('#txtin').val('');
	$('#preview').html('');
	
}
function importg(){
	// import go
	var postvars = 'act=txtin2';
	$.post('ajax.php',postvars, function(data){
		//alert(data);
		$('#preview').html(data);
	});
}
