// JScript File
function changeCase(frmObj) {
var index;
var tmpStr;
var tmpChar;
var preString;
var postString;
var strlen;
tmpStr = Trim(frmObj.value.toLowerCase());
strLen = tmpStr.length;
if (strLen > 0)  {
for (index = 0; index < strLen; index++)  {
if (index == 0)  {
tmpChar = tmpStr.substring(0,1).toUpperCase();
postString = tmpStr.substring(1,strLen);
tmpStr = tmpChar + postString;
}
else {
tmpChar = tmpStr.substring(index, index+1);
if (tmpChar == " " && index < (strLen-1))  {
tmpChar = tmpStr.substring(index+1, index+2).toUpperCase();
preString = tmpStr.substring(0, index+1);
postString = tmpStr.substring(index+2,strLen);
tmpStr = preString + tmpChar + postString;
         }
      }
   }
}
frmObj.value = tmpStr;
}

//  Format functions -->

// -------------------- FormatPhoneNumber -B.S. 31.1.2007 rutine for klientside formatering ved onblur-------------------
function FormatPhoneNumber(frmObj) {
var re, prestr, tmpStr;
tmpStr = Trim(frmObj.value);
re = /(\s+)/g;
tmpStr = tmpStr.replace(re,"");

if(tmpStr.length==8){
tmpStr = tmpStr.substr(0,2) + " " + tmpStr.substr(2,2) + " " + tmpStr.substr(4,2) + " " + tmpStr.substr(6,2);
}
else{
if(tmpStr.length>8){
prestr= tmpStr.substr(0,tmpStr.length-8); 
tmpStr= tmpStr.substr(tmpStr.length-8); 
tmpStr =  prestr + " " + tmpStr.substr(0,2) + " " + tmpStr.substr(2,2) + " " + tmpStr.substr(4,2) + " " + tmpStr.substr(6,2);
}
}
frmObj.value = tmpStr;
}
// -------------------- FormatMobileNumber -B.S. 31.1.2007 rutine for klientside formatering ved onblur-------------------
function FormatMobileNumber(frmObj) {
var re, prestr, tmpStr;
tmpStr = Trim(frmObj.value);
re = /(\s+)/g;
tmpStr = tmpStr.replace(re,"");

if(tmpStr.length==8){
tmpStr = tmpStr.substr(0,3) + " " + tmpStr.substr(3,2) + " " + tmpStr.substr(5,3);
}
else{
if(tmpStr.length>8){
prestr= tmpStr.substr(0,tmpStr.length-8); 
tmpStr= tmpStr.substr(tmpStr.length-8); 
tmpStr =  prestr + " " + tmpStr.substr(0,2) + " " + tmpStr.substr(0,3) + " " + tmpStr.substr(3,2) + " " + tmpStr.substr(7,3);
}
}
frmObj.value = tmpStr;
}
// -------------------- FormatAccountNumber -B.S. 31.1.2007 rutine for klientside formatering ved onblur-------------------
function FormatAccountNumber(frmObj) {
var re, prestr, tmpStr;
var tmpChar;
tmpStr = Trim(frmObj.value);
re = /([.,\s]+)/g;
tmpStr = tmpStr.replace(re,"");

if(tmpStr.length==11){
tmpStr = tmpStr.substr(0,4) + "." + tmpStr.substr(4,2) + "." + tmpStr.substr(6);
}
else{
if(tmpStr.length>11){
prestr= tmpStr.substr(0,tmpStr.length-11); 
tmpStr= tmpStr.substr(tmpStr.length-11); 
tmpStr =  prestr + "." + tmpStr.substr(0,4) + "." + tmpStr.substr(4,2) + "." + tmpStr.substr(6);
}
}
frmObj.value = tmpStr;
}

//  Trim functions -->

function Trim(TRIM_VALUE){
if(TRIM_VALUE.length < 1){
return "";
}
TRIM_VALUE = RTrim(TRIM_VALUE);
TRIM_VALUE = LTrim(TRIM_VALUE);
if(TRIM_VALUE==""){
return "";
}
else{
return TRIM_VALUE;
}
} //End Function

function RTrim(VALUE){
var w_space = String.fromCharCode(32);
var v_length = VALUE.length;
var strTemp = "";
if(v_length < 0){
return "";
}
var iTemp = v_length -1;

while(iTemp > -1){
if(VALUE.charAt(iTemp) == w_space){
}
else{
strTemp = VALUE.substring(0,iTemp +1);
break;
}
iTemp = iTemp-1;

} //End While
return strTemp;

} //End Function

function LTrim(VALUE){
var w_space = String.fromCharCode(32);
if(v_length < 1){
return"";
}
var v_length = VALUE.length;
var strTemp = "";

var iTemp = 0;

while(iTemp < v_length){
if(VALUE.charAt(iTemp) == w_space){
}
else{
strTemp = VALUE.substring(iTemp,v_length);
break;
}
iTemp = iTemp + 1;
} //End While
return strTemp;
} //End Function


//  End -->
