<!-- BEGIN #

function checkSenderID() {
	senderID = document.fm_sendsms.sms_from.value;
	message = document.fm_sendsms.message.value;
	regtest = /^[+]?([0-9 ])+$/;
	if(regtest.test(senderID)) {
		senderID = senderID.replace(/([^0-9])/g, "");
		if(senderID.length > 16) {
			alert('Sender IDs may not be longer than 16 digits!');
			return false;
		}
		else
			return true;
	}
	if(senderID.length > 11) {
		alert('Non numeric sender IDs must be at most 11 characters long!');
		return false;
	}
	if(message.length < 1) {
		alert('You haven\'t entered a message yet!');
		return false;
	}
	if(document.fm_sendsms.msg_schedule.checked && !document.fm_sendsms.msg_schedule_date.value.length){
		alert('If you want to schedule the SMS, you must enter a date too!');
		return false;
	}
	if(document.getElementById('InfoCharCounter').innerHTML.search("unicode") != -1) {
		if(!confirm('Are you sure you want to send a message with unicode characters in it?'))
			return false;
	}
	return true;
}

function checkToNum() {
	num = document.fm_sendsms.p_cellphone.value;
	if(num.length < 7) {
		alert('The number to be sent to is too short!');
		return false;
	}
	return true;
}

function checkToList() {
	num = document.fm_sendsms.textlist.value;
	if(num.length < 7) {
		alert('The list of numbers to be sent to is too short!');
		return false;
	}
	return true;
}

function checkToContacts() {
	num = document.fm_sendsms['p_cellphone[]'];
	if(num.length < 1) {
		alert('You haven\'t chosen any contacts to send to!');
		return false;
	}
	return true;
}

function checkToGroup() {
	num = document.fm_sendsms['gp_name[]'];
	if(num.length < 1) {
		alert('You haven\'t chosen any groups to send to!');
		return false;
	}
	return true;
}

function updateTextBoxCounter() {

   var w = ("abcdefghijklmnopqrstuvwxyz"
       + "ABCDEFGHIJKLMNOPQRSTUVWXYZ0123456789@$_ !#%&()*+,-./:;<=>?\"\'");
   var whash = {};
   for (var i = 0; i < w.length; i++)
       whash[w.charAt(i)] = true;

   var unicodeFlag = 0;
   var extraChars = 0;
   var msgCount = 0;

   var msg = document.forms.fm_sendsms.message.value;
   var agent = navigator.userAgent.toLowerCase()
   if(agent.indexOf('firefox') > 0)
		msg = msg.replace(/\n/g, "\r\n");
   if(agent.indexOf('safari') > 0)  {
		msg = msg.replace(/\n$/g, "");
		msg = msg.replace(/\n/g, "\r\n");
   }
   var m = msg.length;
   for(i=0; i<m && !unicodeFlag; i++) {
      if (whash[msg.charAt(i)]) {
      }
      else if (msg.charCodeAt(i) == 0xA3) {
      }
      else if (msg.charCodeAt(i) == 0xA5) {
      }
      else if (msg.charCodeAt(i) == 0xE8) {
      }
      else if (msg.charCodeAt(i) == 0xE9) {
      }
      else if (msg.charCodeAt(i) == 0xF9) {
      }
      else if (msg.charCodeAt(i) == 0xEC) {
      }
      else if (msg.charCodeAt(i) == 0xF2) {
      }
      else if (msg.charCodeAt(i) == 0xC7) {
      }
      else if (msg.charCodeAt(i) == 0x0A) {
      }
      else if (msg.charCodeAt(i) == 0x0D) {
      }
      else if (msg.charCodeAt(i) == 0xD8) {
      }
      else if (msg.charCodeAt(i) == 0xF8) {
      }
      else if (msg.charCodeAt(i) == 0xC5) {
      }
      else if (msg.charCodeAt(i) == 0xE5) {
      }
      else if (msg.charCodeAt(i) == 0x394) {
      }
      else if (msg.charCodeAt(i) == 0x3A6) {
      }
      else if (msg.charCodeAt(i) == 0x393) {
      }
      else if (msg.charCodeAt(i) == 0x39B) {
      }
      else if (msg.charCodeAt(i) == 0x3A9) {
      }
      else if (msg.charCodeAt(i) == 0x3A0) {
      }
      else if (msg.charCodeAt(i) == 0x3A8) {
      }
      else if (msg.charCodeAt(i) == 0x3A3) {
      }
      else if (msg.charCodeAt(i) == 0x398) {
      }
      else if (msg.charCodeAt(i) == 0x39E) {
      }
      else if (msg.charCodeAt(i) == 0xC6) {
      }
      else if (msg.charCodeAt(i) == 0xE6) {
      }
      else if (msg.charCodeAt(i) == 0xDF) {
      }
      else if (msg.charCodeAt(i) == 0xC9) {
      }
      else if (msg.charCodeAt(i) == 0xA4) {
      }
      else if (msg.charCodeAt(i) == 0xA1) {
      }
      else if (msg.charCodeAt(i) == 0xC4) {
      }
      else if (msg.charCodeAt(i) == 0xD6) {
      }
      else if (msg.charCodeAt(i) == 0xD1) {
      }
      else if (msg.charCodeAt(i) == 0xDC) {
      }
      else if (msg.charCodeAt(i) == 0xA7) {
      }
      else if (msg.charCodeAt(i) == 0xBF) {
      }
      else if (msg.charCodeAt(i) == 0xE4) {
      }
      else if (msg.charCodeAt(i) == 0xF6) {
      }
      else if (msg.charCodeAt(i) == 0xF1) {
      }
      else if (msg.charCodeAt(i) == 0xFC) {
      }
      else if (msg.charCodeAt(i) == 0xE0) {
      }
      else if (msg.charCodeAt(i) == 0x391) {
      }
      else if (msg.charCodeAt(i) == 0x392) {
      }
      else if (msg.charCodeAt(i) == 0x395) {
      }
      else if (msg.charCodeAt(i) == 0x396) {
      }
      else if (msg.charCodeAt(i) == 0x397) {
      }
      else if (msg.charCodeAt(i) == 0x399) {
      }
      else if (msg.charCodeAt(i) == 0x39A) {
      }
      else if (msg.charCodeAt(i) == 0x39C) {
      }
      else if (msg.charCodeAt(i) == 0x39D) {
      }
      else if (msg.charCodeAt(i) == 0x39F) {
      }
      else if (msg.charCodeAt(i) == 0x3A1) {
      }
      else if (msg.charCodeAt(i) == 0x3A4) {
      }
      else if (msg.charCodeAt(i) == 0x3A5) {
      }
      else if (msg.charCodeAt(i) == 0x3A7) {
      }
      else if (msg.charAt(i) == '^') {
         extraChars++;
      }
      else if (msg.charAt(i) == '{') {
         extraChars++;
      }
      else if (msg.charAt(i) == '}') {
         extraChars++;
      }
      else if (msg.charAt(i) == '\\') {
         extraChars++;
      }
      else if (msg.charAt(i) == '[') {
         extraChars++;
      }
      else if (msg.charAt(i) == '~') {
         extraChars++;
      }
      else if (msg.charAt(i) == ']') {
         extraChars++;
      }
      else if (msg.charAt(i) == '|') {
         extraChars++;
      }
      else if (msg.charCodeAt(i) == 0x20AC) {
         extraChars++;
      }
      else {
         unicodeFlag = 1;
      }
   }

   msgCount = m + extraChars;
   if (unicodeFlag) {
      if (msgCount <= 70) {
         msgCount = 1;
      }
      else {
         msgCount += (67-1);
         msgCount -= (msgCount % 67);
         msgCount /= 67;
      }
	  // "Linked" to make it viewable for the visually impaired
      document.getElementById('InfoCharCounter').innerHTML = "<a href='#' style='text-decoration: none; color: #646464;'>" + (m) + " unicode characters, " + msgCount + " SMS message(s)</a>";
   }
   else {
      if (msgCount <= 160) {
         msgCount = 1;
      }
      else {
         msgCount += (153-1);
         msgCount -= (msgCount % 153);
         msgCount /= 153;
      }
	  // "Linked" to make it viewable for the visually impaired
      document.getElementById('InfoCharCounter').innerHTML = "<a href='#' style='text-decoration: none; color: #646464;'>" + (m + extraChars) + " characters, " + msgCount + " SMS message(s)</a>";
   }
}

function clearTextBoxCounter() {

   document.getElementById('InfoCharCounter').innerHTML = "";

}


function CheckUncheckAll(the_form) 
{
    for (var i=0; i < the_form.elements.length; i++) 
    {
	if (the_form.elements[i].type=="checkbox") 
	{
	    the_form.elements[i].checked = !(the_form.elements[i].checked);
	}
    }
}


function PopupSendSms(ta, tg)
{
    var pv = "PV";
    if (ta == pv)
    {
	var url = "menu.php?inc=send_sms&op=sendsmstopv&dst_p_cellphone="+tg;
    }
    else
    {
	var url = "menu.php?inc=send_sms&op=sendsmstogr&dst_gp_code="+tg;
    }
    //newwin=window.open("","WinSendSms","scrollbars","resizable=yes")
    newwin=window.open("","_top")
    //newwin.moveTo(20,100)
    //newwin.resizeTo(500,500)
    newwin.location=url	    
}

function ConfirmURL(inputText, inputURL)
{ 
    if (confirm(inputText)) document.location=inputURL
}

function SmsCountKeyUp(maxChar)
{
    var msg  = document.forms.fm_sendsms.message;
    var left = document.forms.fm_sendsms.charNumberLeftOutput;
    var smsLenLeft = maxChar  - msg.value.length;
    if (smsLenLeft >= 0) 
    {
	left.value = smsLenLeft;
    } 
    else 
    {
	var msgMaxLen = maxChar;
	left.value = 0;
	msg.value = msg.value.substring(0, msgMaxLen);
    }
}

function SmsCountKeyDown(maxChar)
{
    var msg  = document.forms.fm_sendsms.message;
    var left = document.forms.fm_sendsms.charNumberLeftOutput;
    var smsLenLeft = maxChar  - msg.value.length;
    if (smsLenLeft >= 0) 
    {
	left.value = smsLenLeft;
    } 
    else 
    {
	var msgMaxLen = maxChar;
	left.value = 0; 
	msg.value = msg.value.substring(0, msgMaxLen);
    }
}

function linkto(url)
{
   window.location.href = url;
}


// END -->
