/*
| Script module for ajax-shoutbox
| by PolarFox aka Psc | http://unlogic.info | Build: 5
*/
var sb_max = 200 ;

function textCount(c_from, c_to){ 
if (c_from.value.length > sb_max)
c_from.value = c_from.value.substring(0, sb_max);
else 
c_to.value = sb_max - c_from.value.length;
}//stealed from http://www.bs-fusion.de

var sh_editnum = 0,now_row = 0,sh_upd_int = 0;

function ash_h(){jQuery("#sb_adiv").fadeTo("fast",0.05);}
function ash_s(){jQuery("#sb_adiv").fadeTo(400,1);}

//catch the key
function sh_center(e){
if(e.ctrlKey && (e.keyCode == 13||(e.type=='keypress'&&e.keyCode==10))){ash_send();e.returnValue=false;}//ctrl 13 + 10/webkit/
}

function ash_send() {
if(document.shout_form.shout_message.value==""){return false;}
	var t_vbps,ifedit = (sh_editnum!=0?"?s_action=edit&shout_id="+sh_editnum:"");
	with(document.shout_form){shout_message.disabled = 1;post_shout.disabled = 1;t_vbps=post_shout.value;post_shout.value="..."}
	ash_h();
	jQuery.post(sb_fldr+"ash.php"+ifedit,
 { shout_message: document.shout_form.shout_message.value ,  post_shout: "js" },
 function(data){
	sh_editnum = 0;
	with(document.shout_form){
	shout_message.disabled = 0;post_shout.disabled = 0;shout_message.value = "";post_shout.value=t_vbps;}
    jQuery("#sb_adiv").html(data);now_row = 0;
	ash_s();
  });
}

function ash_refresh(mode) {
	ash_h();
	
	jQuery.post(sb_fldr+"ash.php",{},
		function(data){
		document.shout_form.shout_message.disabled = 0;	now_row = 0;
		jQuery("#sb_adiv").html(data);
		ash_s();
	});
	
	if(mode=="0"){ash_setautor(0);}
}
function ash_edit(num) {
	jQuery.post(sb_fldr+"ash.php?ash_edit="+num,{},
		function(data){
		sh_editnum = num;
		jQuery("#sb_adiv").append(data);
	});
}
function ash_del(num) {
	ash_h();
	
	jQuery.post(sb_fldr+"ash.php?s_action=delete&shout_id="+num,{},
		function(data){
		now_row = 0;
		jQuery("#sb_adiv").html(data);
		ash_s();
	});
}
function ash_setautor(sec) {
	if(sec!=0) {
	if(typeof(sb_rtimer) != "undefined"){clearInterval(sb_rtimer);}
	var ms_arefr = (1000*sec);
	sb_rtimer = setInterval( "ash_refresh(1)" , ms_arefr);
	}
	else {
	if(typeof(sb_rtimer) != "undefined"){
	clearInterval(sb_rtimer);
	}
	}
}
function ash_addmore() {
	ash_h();
	now_row = (now_row + inc_row);
	
	jQuery.post(sb_fldr+"ash.php?row="+now_row,{},
		function(data){
		jQuery("#sb_adiv").append(data);
		ash_s();
	});
	
	ash_setautor(0);
}

function ash_mto(type,name){
var vedit,vform;
	if (type == 2) {//archive
		edit = 'archive_shout_message'; 
		form = 'archive_form';
	}
	else {//panel+ajax
		edit = 'shout_message'; 
		form = 'shout_form';
	}
insertText(edit,'[b]'+name+'[/b], ', form);
return false;
}
