﻿// It removes '0' and ' ' from the beggining of the string strFrom and 
// returns integer value
function strToInt(strFrom)
 {
   while ((strFrom.charAt(0)=='0') || (strFrom.charAt(0)==' ') )
       strFrom=strFrom.substr(1);
   var temp=parseInt(strFrom);
   if (isNaN(temp))
            return 0;
       else
            return temp;
  }
  
function strToFloat(strFrom)
 {
   while ((strFrom.charAt(0)=='0') || (strFrom.charAt(0)==' ') )
       strFrom=strFrom.substr(1);
   var temp=parseFloat(strFrom);
   if (isNaN(temp))
            return 0;
       else
            return temp;
  }

 // global replacing function
 function replaceSTR(s, del, ins) 
 {
  eval("repl =/" + del + "/g"); // /g - global replace 
  return s.replace(repl,ins);
 }

  // global replacing function
 function myReplaceSTR(s, del, ins) 
 {
  var pos = 0, len1 = del.length, len2 = ins.length;
  while ((pos=s.indexOf(del,pos))>-1)
   {
    s = s.substring(0,pos) + ins + s.substring(pos+len1);
	pos+=len2-len1-1;
   }
  return s;
 }

 function replaceAll(strVal,strVal1,strVal2)
 {
  var re = new RegExp(strVal1,"g");
  var r = strVal.replace(re,strVal2);
  return r;
 }
 
 // it replaces " with '' in all form field values 
 function replaceAllInForm()
 {
  for (i=0;i<document.forms[0].length;i++)
   if (document.forms[0].item(i).name!="")
    document.forms[0].item(i).value = replaceAll(document.forms[0].item(i).value,"\"","''");
 }
 
function InStr(vstr1,vstr2)
{ 
     var i;
     for (i = 0;  i < vstr1.length;  i++)
	    if (vstr2.indexOf(vstr1.charAt(i))==-1)
            return false;
	 return true;
}

  function getChars(vstr1,vstr2){
   retValue = "";
   for(i=0; i<vstr1.length; i++) {
    tmp = vstr1.charAt(i);
	if (vstr2.indexOf(tmp) !== -1 ) retValue += tmp;
   }
   return retValue;
  }
  
function reversal(s) 
 {
  var len = s.length;
  var trans = "";
  for (i=0; i<len; i++)    
  { 
   trans = trans + s.substring(len-i-1, len-i); 
  }
  s = trans;
  return s;
 }

function toStrLen1(strFrom,numLen)
 {
   var i=(numLen-strFrom.length)*2;
   var j,strTemp="";
   for (j=1; j <= i; j++) strTemp+=" ";
   strFrom = strTemp + strFrom;
   return strFrom;
  }
   
 function clipRows(strValue, numRows, lenRow)
 {
  var ind=0, indOld = 0;
  window.status = lenRow;
  var searchSTR = "\r\n";
  var counters = 0;
  while (true)
   { 
    ind = strValue.indexOf(searchSTR, ind);
	if (ind==-1)
      return strValue;
	counters++; 
	if (counters==numRows)
	 return strValue.substring(0,ind);
	 
	 //var large_number = "212,0,456,0,67889";
     //var reg3 = /,\d,/;
     //var numberList = large_number.split(re);
     // numberList = ["212","456","67889"] array

    //tmpRows = parseInt((ind-indOld)/lenRow);
	//if (tmpRows>0) 
	//  if ((counters + tmpRows)>=numRows))
	//    return strValue.substring(0,indOld + lenRow*(numRows-counters));
	//   else
	//    counters+=tmpRows;
	
	indOld = ind;
	ind+=2;
   }
 }
   
 function howMany(strValue, strSearch){
   intValue = 0;
   intPos = 0;
   while (true){
    intPos = strValue.indexOf(strSearch, intPos);
	if (intPos == -1) break;
	intValue++;
	intPos += strSearch.length;
   }
   return intValue;
  }
   
 function replaceTags(strValue) {
  var pos1, pos2, strRet = strValue;
  while (true) {
    var pos1 = strRet.indexOf("<");
    var pos2 = strRet.indexOf(">");
	if (pos1!=-1 && pos2!=-1) strRet = strRet.substr(0,pos1) + strRet.substr(pos2+1);
	 else break;
  }
  return strRet;
 }
