/*this script created by Now Wireless Limited  http://www.nowsms.com */
function updateTextBoxCounter() 
{
var unicodeFlag = 0;
var extraChars = 0;
var msgCount = 0;
for (var i = 0; (!unicodeFlag && (i < document.forms[0].CreateText1_Text.value.length)); i++) {
	if ((document.forms[0].CreateText1_Text.value.charAt(i) >= '0') && (document.forms[0].CreateText1_Text.value.charAt(i) <= '9')) {
	}
	else if ((document.forms[0].CreateText1_Text.value.charAt(i) >= 'A') && (document.forms[0].CreateText1_Text.value.charAt(i) <= 'Z')) {
	}
	else if ((document.forms[0].CreateText1_Text.value.charAt(i) >= 'a') && (document.forms[0].CreateText1_Text.value.charAt(i) <= 'z')) {
	}
	else if (document.forms[0].CreateText1_Text.value.charAt(i) == '@') {
	}
	else if (document.forms[0].CreateText1_Text.value.charCodeAt(i) == 0xA3) {
	}
	else if (document.forms[0].CreateText1_Text.value.charAt(i) == '$') {
	}
	else if (document.forms[0].CreateText1_Text.value.charCodeAt(i) == 0xA5) {
	}
	else if (document.forms[0].CreateText1_Text.value.charCodeAt(i) == 0xE8) {
	}
	else if (document.forms[0].CreateText1_Text.value.charCodeAt(i) == 0xE9) {
	}
	else if (document.forms[0].CreateText1_Text.value.charCodeAt(i) == 0xF9) {
	}
	else if (document.forms[0].CreateText1_Text.value.charCodeAt(i) == 0xEC) {
	}
	else if (document.forms[0].CreateText1_Text.value.charCodeAt(i) == 0xF2) {
	}
	else if (document.forms[0].CreateText1_Text.value.charCodeAt(i) == 0xC7) {
	}
	else if (document.forms[0].CreateText1_Text.value.charAt(i) == '\r') {
	}
	else if (document.forms[0].CreateText1_Text.value.charAt(i) == '\n') {
		extraChars++;
	}
	else if (document.forms[0].CreateText1_Text.value.charCodeAt(i) == 0xD8) {
	}
	else if (document.forms[0].CreateText1_Text.value.charCodeAt(i) == 0xF8) {
	}
	else if (document.forms[0].CreateText1_Text.value.charCodeAt(i) == 0xC5) {
	}
	else if (document.forms[0].CreateText1_Text.value.charCodeAt(i) == 0xE5) {
	}
	else if (document.forms[0].CreateText1_Text.value.charCodeAt(i) == 0x394) {
	}
	else if (document.forms[0].CreateText1_Text.value.charAt(i) == '_') {
	}
	else if (document.forms[0].CreateText1_Text.value.charCodeAt(i) == 0x3A6) {
	}
	else if (document.forms[0].CreateText1_Text.value.charCodeAt(i) == 0x393) {
	}
	else if (document.forms[0].CreateText1_Text.value.charCodeAt(i) == 0x39B) {
	}
	else if (document.forms[0].CreateText1_Text.value.charCodeAt(i) == 0x3A9) {
	}
	else if (document.forms[0].CreateText1_Text.value.charCodeAt(i) == 0x3A0) {
	}
	else if (document.forms[0].CreateText1_Text.value.charCodeAt(i) == 0x3A8) {
	}
	else if (document.forms[0].CreateText1_Text.value.charCodeAt(i) == 0x3A3) {
	}
	else if (document.forms[0].CreateText1_Text.value.charCodeAt(i) == 0x398) {
	}
	else if (document.forms[0].CreateText1_Text.value.charCodeAt(i) == 0x39E) {
	}
	else if (document.forms[0].CreateText1_Text.value.charCodeAt(i) == 0xC6) {
	}
	else if (document.forms[0].CreateText1_Text.value.charCodeAt(i) == 0xE6) {
	}
	else if (document.forms[0].CreateText1_Text.value.charCodeAt(i) == 0xDF) {
	}
	else if (document.forms[0].CreateText1_Text.value.charCodeAt(i) == 0xC9) {
	}
	else if (document.forms[0].CreateText1_Text.value.charAt(i) == ' ') {
	}
	else if (document.forms[0].CreateText1_Text.value.charAt(i) == '!') {
	}
	else if (document.forms[0].CreateText1_Text.value.charAt(i) == '\"') {
	}
	else if (document.forms[0].CreateText1_Text.value.charAt(i) == '#') {
	}
	else if (document.forms[0].CreateText1_Text.value.charCodeAt(i) == 0xA4) {
	}
	else if (document.forms[0].CreateText1_Text.value.charAt(i) == '%') {
	}
	else if (document.forms[0].CreateText1_Text.value.charAt(i) == '&') {
	}
	else if (document.forms[0].CreateText1_Text.value.charAt(i) == '\'') {
	}
	else if (document.forms[0].CreateText1_Text.value.charAt(i) == '(') {
	}
	else if (document.forms[0].CreateText1_Text.value.charAt(i) == ')') {
	}
	else if (document.forms[0].CreateText1_Text.value.charAt(i) == '*') {
	}
	else if (document.forms[0].CreateText1_Text.value.charAt(i) == '+') {
	}
	else if (document.forms[0].CreateText1_Text.value.charAt(i) == ',') {
	}
	else if (document.forms[0].CreateText1_Text.value.charAt(i) == '-') {
	}
	else if (document.forms[0].CreateText1_Text.value.charAt(i) == '.') {
	}
	else if (document.forms[0].CreateText1_Text.value.charAt(i) == '/') {
	}
	else if (document.forms[0].CreateText1_Text.value.charAt(i) == ':') {
	}
	else if (document.forms[0].CreateText1_Text.value.charAt(i) == ';') {
	}
	else if (document.forms[0].CreateText1_Text.value.charAt(i) == '<') {
	}
	else if (document.forms[0].CreateText1_Text.value.charAt(i) == '=') {
	}
	else if (document.forms[0].CreateText1_Text.value.charAt(i) == '>') {
	}
	else if (document.forms[0].CreateText1_Text.value.charAt(i) == '?') {
	}
	else if (document.forms[0].CreateText1_Text.value.charCodeAt(i) == 0xA1) {
	}
	else if (document.forms[0].CreateText1_Text.value.charCodeAt(i) == 0xC4) {
	}
	else if (document.forms[0].CreateText1_Text.value.charCodeAt(i) == 0xD6) {
	}
	else if (document.forms[0].CreateText1_Text.value.charCodeAt(i) == 0xD1) {
	}
	else if (document.forms[0].CreateText1_Text.value.charCodeAt(i) == 0xDC) {
	}
	else if (document.forms[0].CreateText1_Text.value.charCodeAt(i) == 0xA7) {
	}
	else if (document.forms[0].CreateText1_Text.value.charCodeAt(i) == 0xBF) {
	}
	else if (document.forms[0].CreateText1_Text.value.charCodeAt(i) == 0xE4) {
	}
	else if (document.forms[0].CreateText1_Text.value.charCodeAt(i) == 0xF6) {
	}
	else if (document.forms[0].CreateText1_Text.value.charCodeAt(i) == 0xF1) {
	}
	else if (document.forms[0].CreateText1_Text.value.charCodeAt(i) == 0xFC) {
	}
	else if (document.forms[0].CreateText1_Text.value.charCodeAt(i) == 0xE0) {
	}
	else if (document.forms[0].CreateText1_Text.value.charCodeAt(i) == 0x391) {
	}
	else if (document.forms[0].CreateText1_Text.value.charCodeAt(i) == 0x392) {
	}
	else if (document.forms[0].CreateText1_Text.value.charCodeAt(i) == 0x395) {
	}
	else if (document.forms[0].CreateText1_Text.value.charCodeAt(i) == 0x396) {
	}
	else if (document.forms[0].CreateText1_Text.value.charCodeAt(i) == 0x397) {
	}
	else if (document.forms[0].CreateText1_Text.value.charCodeAt(i) == 0x399) {
	}
	else if (document.forms[0].CreateText1_Text.value.charCodeAt(i) == 0x39A) {
	}
	else if (document.forms[0].CreateText1_Text.value.charCodeAt(i) == 0x39C) {
	}
	else if (document.forms[0].CreateText1_Text.value.charCodeAt(i) == 0x39D) {
	}
	else if (document.forms[0].CreateText1_Text.value.charCodeAt(i) == 0x39F) {
	}
	else if (document.forms[0].CreateText1_Text.value.charCodeAt(i) == 0x3A1) {
	}
	else if (document.forms[0].CreateText1_Text.value.charCodeAt(i) == 0x3A4) {
	}
	else if (document.forms[0].CreateText1_Text.value.charCodeAt(i) == 0x3A5) {
	}
	else if (document.forms[0].CreateText1_Text.value.charCodeAt(i) == 0x3A7) {
	}
	else if (document.forms[0].CreateText1_Text.value.charAt(i) == '^') {
		extraChars++;
	}
	else if (document.forms[0].CreateText1_Text.value.charAt(i) == '{') {
		extraChars++;
	}
	else if (document.forms[0].CreateText1_Text.value.charAt(i) == '}') {
		extraChars++;
	}
	else if (document.forms[0].CreateText1_Text.value.charAt(i) == '\\') {
		extraChars++;
	}
	else if (document.forms[0].CreateText1_Text.value.charAt(i) == '[') {
		extraChars++;
	}
	else if (document.forms[0].CreateText1_Text.value.charAt(i) == '~') {
		extraChars++;
	}
	else if (document.forms[0].CreateText1_Text.value.charAt(i) == ']') {
		extraChars++;
	}
	else if (document.forms[0].CreateText1_Text.value.charAt(i) == '|') {
		extraChars++;
	}
	else if (document.forms[0].CreateText1_Text.value.charCodeAt(i) == 0x20AC) {
		extraChars++;
	}
	else {
		unicodeFlag = 1;
	}
}
if(unicodeFlag)
{
	msgCount = document.forms[0].CreateText1_Text.value.length;
	if (msgCount <= 70)
	{
		msgCount = 1;
	}
else
{
	msgCount += (67-1);
		msgCount -= (msgCount % 67);
	msgCount /= 67;
}
	document.forms[0].CreateText1_InfoCharCounter.value = "" + document.forms[0].CreateText1_Text.value.length + ' символов';
	document.forms[0].CreateText1_InfoCoding.value = "UCS2";
	document.forms[0].CreateText1_InfoCostCounter.value = "" + msgCount + " кредитов";
} 
else
{
msgCount = document.forms[0].CreateText1_Text.value.length + extraChars;
if (msgCount <= 160) {
	msgCount = 1;
}
else
{
	msgCount += (153-1);
	msgCount -= (msgCount % 153);
	msgCount /= 153;
}
	document.forms[0].CreateText1_InfoCharCounter.value = "" + (document.forms[0].CreateText1_Text.value.length + extraChars)  + " символов";
	document.forms[0].CreateText1_InfoCoding.value = "7bit";
	document.forms[0].CreateText1_InfoCostCounter.value = "" + msgCount + " кредитов";
	}
}

function clearTextBox() 
{
	document.forms[0].CreateText1_Text.value = "";
	clearTextBoxCounter();
}

function clearTextBoxCounter() 
{
	document.forms[0].CreateText1_InfoCostCounter.value = "0";
	document.forms[0].CreateText1_InfoCoding.value = "--";
	document.forms[0].CreateText1_InfoCharCounter.value = "0";
}

function doAddrBook()
{
	window.open('AddRecipient.aspx' , '_blank', 'toolbar=no,location=no,status=no,menubar=no,scrollbars=no,width=310,height=312,resizable=no');				
}

			
function addPhoneNumber(phoneNumber) {

   var tempString = "";
   var alreadyInList = 0;
   for (var i = 0; i < window.document.forms[0].CreateText1_PhoneNumber.value.length; i++) {
      if (window.document.forms[0].CreateText1_PhoneNumber.value.charAt(i) != ',') {
         tempString += window.document.forms[0].CreateText1_PhoneNumber.value.charAt(i);
      }
      else {
         if (tempString == phoneNumber) {
            alreadyInList = 1;
         }
         tempString = "";
      }
   }

   if (tempString.length) {
      if (tempString == phoneNumber) {
         alreadyInList = 1;
      }
   }

   if (!alreadyInList) {
      if (window.document.forms[0].CreateText1_PhoneNumber.value.length) {
         window.document.forms[0].CreateText1_PhoneNumber.value += ",";
      }
      window.document.forms[0].CreateText1_PhoneNumber.value += phoneNumber;
   }

}

function setPhoneNumber(phoneNumber) {
   var tempString = "";
   for (var i = 0; i < phoneNumber.length; i++) {
      if (phoneNumber.charAt(i) != ',') {
         tempString += phoneNumber.charAt(i);
      }
      else {
         addPhoneNumber(tempString);
         tempString = "";
      }
   }

   if (tempString.length) {
      addPhoneNumber(tempString);
   }

}