// JavaScript Document
	
	function show_box($name) {
		document.getElementById($name).style.visibility = "visible";
	}
	
	function hide_box($name) {
		document.getElementById($name).style.visibility = "hidden";
	}
	
	
//--------------------SMS-Functions--------------------------------------------------------	
	
  function prepareSMS(smsText){
	var smsEscaped = "";

    for (i = 0; i < smsText.length; i++){
        c = smsText.charAt(i);
        
        if ((c == '^' || c == '{' || c == '}' || c == '\\' || c == '[' 
            || c == '~' || c == ']' || c == '|' || c == '€') || 
            (c == '\n' && (navigator.appName == "Netscape"))){
	    	smsEscaped += String.fromCharCode(27) + c;
        } else {
            smsEscaped += c;
        }
   	}
   	
    if (smsEscaped.length > 160) {
        for (i = 151; i < smsEscaped.length; i += 152){
            if (smsEscaped.charCodeAt(i) == 27){
                smsEscaped =
                    smsEscaped.substring(0, i)
                        + " "
                        + smsEscaped.substring(i);
            }
        }
    }
    
    return smsEscaped;
  }

  function refreshSMSCount(){
    var smsText = document.form1.SMS_BODYTEXT.value;
	var smsEscaped = prepareSMS(smsText);
   	var smsLength = smsEscaped.length;
	
    var smsParts;
    var smsRemainingChars;

    if (smsLength > 160){
		smsParts = Math.floor((smsLength + 151) / 152);
		smsRemainingChars = 152 - ((smsLength - 1) % 152) - 1;
    } else {
		smsParts = 1;
		smsRemainingChars = 160 - smsLength;
    }
    
    document.getElementById("charsLeft").firstChild.data =
            "SMS: " + smsParts + " | " + smsRemainingChars;

    return true;
	
  }
