var f1;
var phonecounting=false;

function phonecounter_on(form) {
	phonecounting=true;
	refresh_phone(form);
}

function refresh_phone(form) {
	var phone_str = form.phonelist.value;
	phone_str = phone_str.replace(/ /gi, '@');
	phone_str = phone_str.replace(/,/gi, '@');
	phone_str = phone_str.replace(/\n/gi, '@');
	phone_str = phone_str.replace(/\r/gi, '@');
	array_str = phone_str.split('@');
	
	count = 0;
	for(i=0;i<array_str.length;i++)
	{
		if(array_str[i].length > 0)  // && !isNaN(array_str[i]))
		{
		    count++;
		}
	}

	if ( count > 200 ) { 
		alert("Phone numbers in total cannot exceed 200"); 

	}

	var lineCounterObj = document.getElementById('line_counter');
	lineCounterObj.firstChild.nodeValue = count;

	//for one4all
	if(document.sms_form.phone_num) document.sms_form.phone_num.value = count;
	//form.phone_num.value = count;


	if (phonecounting) {
		start_time=new Date();
		start_time=start_time.getTime();
		phonecounter_delay(form);
	}
}

function phonecounter_delay(form) {
	now_time=new Date();
	now_time=now_time.getTime();
	if (now_time-start_time<=500) {
		f1=form;
		if (phonecounting) { timer_id=setTimeout("phonecounter_delay(f1)",500); }
	} else {
		if (navigator.appName=="Netscape") {
			//form.phone_num.focus();
			form.phonelist.focus();
		}
		refresh_phone(form);
	}
}

function phonecounter_off(form) {
	phonecounting=false;
	clearTimeout(timer_id);
	refresh_phone(form);
}
