function ShowOptInOptions()
{

	
	
	
	var ovalue = document.newbroadcastgroupform.puboptin.value;

	switch(ovalue)
	{
		case '0':							// Not Allowed
			
			document.getElementById("sp1").style.visibility="hidden";
			document.getElementById("sp2").style.visibility="hidden";
			document.getElementById("sp3").style.visibility="hidden";
			break;

		case '1':							// Web
			
			document.getElementById("sp1").style.visibility="visible";
			document.getElementById("sp2").style.visibility="visible";
			document.getElementById("sp3").style.visibility="visible";

			break;

		case '2':							// SMS
			
			document.getElementById("sp1").style.visibility="visible";
			document.getElementById("sp2").style.visibility="hidden";
			document.getElementById("sp3").style.visibility="visible";

			break;

		case '3':							// Web + SMS
			
			document.getElementById("sp1").style.visibility="visible";
			document.getElementById("sp2").style.visibility="visible";
			document.getElementById("sp3").style.visibility="visible";

			break;




	}





}

//----------------------------------------------------------

function ShowEditOptInOptions()
{

	
	
	
	var ovalue = document.editbroadcastgroupform.puboptin.value;

	switch(ovalue)
	{
		case '0':							// Not Allowed
			
			document.getElementById("sp1").style.visibility="hidden";
			document.getElementById("sp2").style.visibility="hidden";
			document.getElementById("sp3").style.visibility="hidden";

			break;

		case '1':							// Web
			
			document.getElementById("sp1").style.visibility="visible";
			document.getElementById("sp2").style.visibility="visible";
			document.getElementById("sp3").style.visibility="visible";

			break;

		case '2':							// SMS
			
			document.getElementById("sp1").style.visibility="visible";
			document.getElementById("sp2").style.visibility="hidden";
			document.getElementById("sp3").style.visibility="visible";

			break;

		case '3':							// Web + SMS
			
			document.getElementById("sp1").style.visibility="visible";
			document.getElementById("sp2").style.visibility="visible";
			document.getElementById("sp3").style.visibility="visible";

			break;




	}





}
//-------------------------------------------------------------------------------------------------------


//-------------------------------- Function to count the number of messages and characters in sms text typed by user --------------------

function countCharacters_broadcast(charcount,smscount)
{



	var valueofmessage = document.broadcastSendSmsform.smsmessagebox.value;

	var lengthofmessage = document.broadcastSendSmsform.smsmessagebox.value.length;
			
	var numberofenterkeys = CountEnterKey_broadcast(valueofmessage); 		// javascript treats carriage return as 2 chars but we have to treat is as 1 therefore, no. of carriage returns(1) is subtracted from fulllength(2)

	var actualmessagelength=document.broadcastSendSmsform.actuallength.value;			// will hold actual message length with carriage return counted as 2

	lengthofmessage = lengthofmessage - numberofenterkeys;
	
	if(lengthofmessage>765)
	{
		alert("Maximum Length is Reached");
		TruncateExtraText_broadcast(actualmessagelength);
	}
	else
	{	
		actualmessagelength = lengthofmessage + numberofenterkeys;
		document.broadcastSendSmsform.actuallength.value = actualmessagelength;
	

	
	var remchar = 765 - lengthofmessage;

	var numofsms=0;
	if(lengthofmessage > 160)
	{
		if((lengthofmessage % 153) ==0)				// sms length in multiples of 153
		numofsms = (lengthofmessage / 153);
		else									// sms length not in multiples of 153 and remainder is present therefore increase sms count by 1
		numofsms = (parseInt(lengthofmessage / 153)) + 1;
	}

	else if((lengthofmessage > 0) && (lengthofmessage <= 160))
	{
		numofsms=1;				// sms less that 160 chars therefore sms count is only 1
	}

	document.broadcastSendSmsform.charcount.value = lengthofmessage;
	document.broadcastSendSmsform.remcharcount.value = remchar;
	document.broadcastSendSmsform.smscount.value = numofsms;
	document.broadcastSendSmsform.numsms.value = numofsms;
	
var numberofrecipients = document.broadcastSendSmsform.numrecipients.value;
document.broadcastSendSmsform.totalsms.value = numberofrecipients * numofsms;

	
}
		

}

//-------------------- Returns no. of carriage returns in a message / string ----------------------
function CountEnterKey_broadcast(message)
{

var len = message.length;	
var counter=0;

for(var i=0;i<len;i++)
	{
		var c= message.charCodeAt(i);
		if(c==13)				// 13 and 10 both values are printed when a carriage return is encountered
		counter++;
		

	}

return counter;

}
//--------------------------------- Trucates extra text entered in message text area -----------------------------

function TruncateExtraText_broadcast(actualmessagelength)
{
	var valueofmessage = document.broadcastSendSmsform.smsmessagebox.value;

	valueofmessage = valueofmessage.substring(0,actualmessagelength);
	
	document.broadcastSendSmsform.smsmessagebox.value = valueofmessage;
	
	
}

