var STR_PB_BAE_HEADER = "RZBBBGSF";

var STR_LIMIT_AMOUNT	= "/[0-9]{1,11}[.|,]{0,1}[0-9]{0,2}/";
var STR_LIMIT_AMOUNT_NOTIF = "/[*]{1}|[0-9]{1,11}[.|,]{0,1}[0-9]{0,2}/";

var STR_LIMIT_BAE		= "/[0-9]{8}/";
var STR_LIMIT_PERSONID	= "/[0-9]{9}/";
var STR_LIMIT_FINCENTER	= "/.{1,7}/";
var STR_LIMIT_BIN		= "/[0-9]{10}|[?]{10}|[ ]|/";
var STR_LIMIT_ACCOUNT	= "/[0-9]{10}/";

var STR_LIMIT_ACCOUNT_F_CCY		= "/.{1,33}/";
var STR_LIMIT_PAYEE_NAME_F_CCY	= "/.{1,65}/";
var STR_LIMIT_CMN_NAME_F_CCY	= "/.{0,65}/";
var STR_LIMIT_PMT_CODE_F_CCY	= "/.{1,13}/";
var STR_LIMIT_CORR_BANK_F_CCY	= "/.{0,27}/";
var STR_LIMIT_DESCRIPTION_F_CCY = "/.{0,65}/";
var STR_LIMIT_VALUE_DATE_F_CCY = "/SPOT|NEXT|SAME/";

var STR_LIMIT_MANDATORY_TEXT = "/.+/";
var STR_LIMIT_MFNUMBER		= "/[0-9]{8}/";
var STR_LIMIT_BRBANKCODE	= "/.{0,10}/";
var STR_LIMIT_LATIN_10	= "/.{0,10}/";
var STR_LIMIT_DT_KT_NAME	= "/.{1,26}/";
var STR_LIMIT_BENEF	= "/.{1,26}/";
var STR_LIMIT_EGN			= "/[0-9]{10}/";
var STR_LIMIT_BULSTAT		= "/[0-9]{13}|[0-9]{9}/";
var STR_LIMIT_TAXNUMBER		= "/[0-9]{10}/";
var STR_LIMIT_DATE			= "/[0-9]{2}[.]{1}[0-9]{2}[.]{1}[0-9]{4}/";
var STR_LIMIT_TEMPLATE_NAME = "/.{1,64}/";
var STR_LIMIT_DESCRIPTIONS	= "/.{1,26}/";

var STR_LIMIT_NUMBER_STANDART = "/[0-9]{1,10}/";
var STR_LIMIT_DOCUMENT_TYPE	= "/[1-9]{1}/";
var STR_LIMIT_PARAGRAPH	= "/[0-9]{6}/";
var STR_LIMIT_BIN_PAYEE	= "/[0-9]{10}|[?]{10}/";
var STR_LIMIT_DOCUMENT_NUMBER	= "/.{0,33}/";
var STR_LIMIT_SHNAME	= "/.{1,32}/";

var STR_EXPDAYS	= "/[0-9]{1,2}/";

var STR_LIMIT_35	= "/.{1,35}/";
var STR_LIMIT_20	= "/.{1,20}/";
var STR_LIMIT_17	= "/.{1,17}/";
var STR_LIMIT_35_OPTIONAL	= "/.{0,35}/";
var STR_LIMIT_40_OPTIONAL	= "/.{0,40}/";
var STR_LIMIT_105	= "/.{1,105}/";
var STR_LIMIT_LATIN_35	= "/^[a-zA-Z0-9'][a-zA-Z0-9' ()-\\/,.]{1,35}/";
var STR_LIMIT_LATIN_70 = "/^[a-zA-Z0-9'][a-zA-Z0-9' ()-\\/,.]{1,70}/";
var STR_LIMIT_LATIN_105 = "/^[a-zA-Z0-9'][a-zA-Z0-9' ()-\\/,.]{1,105}/";
var STR_LIMIT_LATIN_105_ALL = "/.{1,105}/";
var STR_LIMIT_LATIN_105_OPTIONAL = "/.{0,105}/";
var STR_LIMIT_LATIN_140 = "/^[a-zA-Z0-9'][a-zA-Z0-9' ()-\\/,.]{1,140}/";
var STR_LIMIT_LATIN_140_OPTIONAL = "/[a-zA-Z0-9' ()-\\/,.]{0,140}/";
var STR_LIMIT_LATIN_35_OPTIONAL	= "/[a-zA-Z0-9' ()-\\/,.]{0,35}/";
var STR_LIMIT_CUSTOMERID = "/.{1,18}/";
var STR_LIMIT_BNB_NUMBER = "/[0-9]{10}|.{0}/";

var STR_LIMIT_RATE	= "/[0-9]{1,5}([.|,][0-9]{1,7}){0,1}|.{0}/";//FX only
var STR_LIMIT_NUMBER_NOI_CODE = "/[0-9]{9,13}/";
var STR_LIMIT_NUMBER_NOI_NBR = "/[0-9]{1,5}/";
var STR_LIMIT_NUMBER_NOI_PERIOD = "/[0-9]{6}/";

//admin
var ID_STR_CLIENT_NAME		= "/.{1,64}/";
var ID_STR_EMAIL			= "/.+@.+[.].+/i";
var ID_STR_EMAIL_OPTIONAL   = "/(.+@.+[.].+){0,1}/i";
var ID_STR_AP_ID_CARD_NO	= "/.{1,20}/";

var STR_LIMIT_IBAN = "/BG{1}[0-9]{2}[A-Z0-9]{18}/";
var STR_LIMIT_BIC = "/[A-Z]{6}[A-Z0-9]{2}/";
var STR_LIMIT_SWIFTN = "/[A-Z]{6}[A-Z0-9]{2}([A-Z0-9]{3}){0,1}|.{0}/";//old swift davahme i malki bukwi

var STR_LIMIT_NOT_EMPTY = "/..*/";

var STR_LIMIT_EMAIL = "/.{1,}[@]{1}.{1,}[.]{1}[a-zA-Z]{2,4}/";

var STR_LIMIT_YEAR = "/[1-2]{1}[0-9]{3}/";
var STR_LIMIT_SUPPLIER_NAME = "/[a-zA-Z0-9 -]{1,100}/";
var STR_LIMIT_PRICE = "/[0-9]{3,20}/";
var STR_LIMIT_PERCENT = "/[0-9]{1,2}/";
var STR_LIMIT_HORSEPOWERS = "/[0-9]{1,3}/";

/***************************************************************
*	CheckEGN()
*	Description:	Function for validating EGN.
*	Author:			Vasil Bachvarov
*	Company:		DAIS - Software, Electronics and Trade, Ltd.
*	Date:			08.10.2003
*	Example:		8103204285
****************************************************************/
function CheckEGN(sEGN)
{
	if (sEGN.length!=10) return false;
	
	var arrWeightVector = new Array(2,4,8,5,10,9,7,3,6);
	var sum = 0;
	
	for (var k=0; k<9; k++) { 
		sum += new Number(sEGN.charAt(k).valueOf()) * arrWeightVector[k]; 
	}
	
	sum = (sum % 11) % 10;
	
	if ((new String(sum))!=sEGN.charAt(9)) return false;
	
	var nDay = new Number(sEGN.substring(4, 6));
	var nMonth = new Number(sEGN.substring(2, 4));
	var nYear = new Number(sEGN.substring(0, 2));
	
	if (31<nDay) return false;
	
	if (!((nMonth>=1 && nMonth<=12) || (nMonth>=21 && nMonth<=32) || (nMonth>=41 && nMonth<=52))) return false
	
	return true;
}

function CheckSWIFT(sSWIFT)
{
	
	if (sSWIFT.length!=8 && sSWIFT.length!=11 ) return false;
	
	for (var k=0; k<6; k++)
	{
		var c = sSWIFT.charAt(k);
		
		if((c>='A' && c<='Z') || (c>='a' && c<='z')) 
			{
							
			}
		else
		{
			return false;
		}
	}
	return true;
}

/***************************************************************
*	CheckTaxNumber()
*	Description:	Function for validating tax number.
*	Author:			Vasil Bachvarov
*	Company:		DAIS - Software, Electronics and Trade, Ltd.
*	Date:			08.10.2003
*	Example:		1212121220
****************************************************************/
function CheckTaxNumber(sTaxNumber)
{
	if (sTaxNumber.length!=10) return false;

	var arrWeightVector = new Array(4,3,2,7,6,5,4,3,2);
	var sum = 0;
	
	for (var k=0; k<9; k++)
	{
		sum += new Number(sTaxNumber.charAt(k).valueOf()) * arrWeightVector[k];
	}
	
	sum = (11-sum%11)%11;
	
	return ((new String(sum))==sTaxNumber.charAt(9));
}

/***************************************************************
*	CheckBULSTAT_9()
*	Description:	Function for validating BULSTAT 9.
*	Author:			Vasil Bachvarov
*	Company:		DAIS - Software, Electronics and Trade, Ltd.
*	Date:			08.10.2003
*	Example:		121212114
****************************************************************/
function CheckBULSTAT_9(sBULSTAT)
{
	if (sBULSTAT.length!=9) return false;

	var arrWeightVector = new Array(1,2,3,4,5,6,7,8);
	var arrWeightVector1 = new Array(3,4,5,6,7,8,9,10);
	var sum = 0;
	
	for (var k=0; k<8; k++)
	{
		sum += new Number(sBULSTAT.charAt(k).valueOf()) * arrWeightVector[k];
	}
	
	sum = sum%11;
	
	if (10==sum)
	{
		sum = 0;
		for (var k=0; k<8; k++)
		{
			sum += new Number(sBULSTAT.charAt(k).valueOf()) * arrWeightVector1[k];
		}
		
		sum = (sum%11)%10;
	}
	
	return ((new String(sum))==sBULSTAT.charAt(8));
}

/***************************************************************
*	CheckBULSTAT_13()
*	Description:	Function for validating BULSTAT 9.
*	Author:			Vasil Bachvarov
*	Company:		DAIS - Software, Electronics and Trade, Ltd.
*	Date:			08.10.2003
*	Example:		1212121140008
****************************************************************/
function CheckBULSTAT_13(sBULSTAT)
{
	if (sBULSTAT.length!=13) return false;
	
	if (!CheckBULSTAT_9(sBULSTAT.substring(0, 9))) return false;

	var arrWeightVector = new Array(2,7,3,5);
	var arrWeightVector1 = new Array(4,9,5,7);
	var sum = 0;
	
	for (var k=8; k<12; k++)
	{
		sum += new Number(sBULSTAT.charAt(k).valueOf()) * arrWeightVector[k-8];
	}
	
	sum = sum%11;
	
	if (10==sum)
	{
		sum = 0;
		for (var k=8; k<12; k++)
		{
			sum += new Number(sBULSTAT.charAt(k).valueOf()) * arrWeightVector1[k-8];
		}
		
		sum = (sum%11)%10;
	}
	
	return ((new String(sum))==sBULSTAT.charAt(12));
}

function CheckBULSTAT(sBULSTAT)
{
	if (CheckBULSTAT_9(sBULSTAT)) return true;
	if (CheckBULSTAT_13(sBULSTAT)) return true;
	return false;
}

/***************************************************************
*	CheckAccountNumber()
*	Description:	Function for validating account number and BIN.
*	Author:			Vasil Bachvarov
*	Company:		DAIS - Software, Electronics and Trade, Ltd.
*	Date:			24.10.2003
*	Example:		1234567890
****************************************************************/
function CheckAccountNumber(strAccNo)
{
	
	if (strAccNo.length!=10) return false;
	
	var arrWeightVector = new Array(2,4,8,5,10,9,7,3,6);
	var sum = 0;
	
	for (var k=0; k<9; k++) { 
		sum += new Number(strAccNo.charAt(k).valueOf()) * arrWeightVector[k]; 
	}
	
	sum = (sum % 11) % 10;
	
	if ((new String(sum))!=strAccNo.charAt(9)) return false;
	
	return true;
}

function CheckBIN(strBIN)
{
	if (""==strBIN) return true;
	if ("0000000000"==strBIN) return false;
	return CheckAccountNumber(strBIN);
}


/***************************************************************
*	CheckIBAN()		
*	Description:	Function for validating BG IBANs
*	Author:			Anelia Brezoeva, Vladi kaza kak da smqtam modul-a
*	Company:		DAIS - Software
*	Date:			12.4.2006
*	Example:		BG33AAAA12311012345678
****************************************************************/
function IBANCheckDefinition(pISOCode, pCountryName, pIBANPrefix, pIBANLength)
{
    this.ISOCode = pISOCode;
    this.IBANLength = pIBANLength;
    this.CountryName = pCountryName;
    this.IBANPrefix = pIBANPrefix;
}


var countryIBANDefByPref = new Object();
var countryIBANDefByISO = new Object();

countryIBANDefByISO.AD = countryIBANDefByPref.AD = new IBANCheckDefinition('AD', 'Andorra', 'AD', 24); //new 
countryIBANDefByISO.AL = countryIBANDefByPref.AL = new IBANCheckDefinition('AL', 'Albania', 'AL', 28); //new
countryIBANDefByISO.AT = countryIBANDefByPref.AT = new IBANCheckDefinition('AT', 'Austria', 'AT', 20);
countryIBANDefByISO.BA = countryIBANDefByPref.BA = new IBANCheckDefinition('BA', 'Bosnia and Herzegovina', 'BA', 20); //new
countryIBANDefByISO.BE = countryIBANDefByPref.BE = new IBANCheckDefinition('BE', 'Belgium', 'BE', 16);
countryIBANDefByISO.BG = countryIBANDefByPref.BG = new IBANCheckDefinition('BG', 'Bulgaria', 'BG', 22);
countryIBANDefByISO.HR = countryIBANDefByPref.HR = new IBANCheckDefinition('HR', 'Croatia', 'HR', 21); //new
countryIBANDefByISO.CY = countryIBANDefByPref.CY = new IBANCheckDefinition('CY', 'Cyprus', 'CY', 28);
countryIBANDefByISO.CZ = countryIBANDefByPref.CZ = new IBANCheckDefinition('CZ', 'Czech Republic', 'CZ', 24);
countryIBANDefByISO.CH = countryIBANDefByPref.CH = new IBANCheckDefinition('CH', 'Switzerland', 'CH', 21); //new
countryIBANDefByISO.DE = countryIBANDefByPref.DE = new IBANCheckDefinition('DE', 'Germany', 'DE', 22);
countryIBANDefByISO.DK = countryIBANDefByPref.DK = new IBANCheckDefinition('DK', 'Denmark', 'DK', 18);
countryIBANDefByISO.EE = countryIBANDefByPref.EE = new IBANCheckDefinition('EE', 'Estonia', 'EE', 20);
countryIBANDefByISO.ES = countryIBANDefByPref.ES = new IBANCheckDefinition('ES', 'Spain', 'ES', 24);
countryIBANDefByISO.FI = countryIBANDefByPref.FI = new IBANCheckDefinition('FI', 'Finland', 'FI', 18);
countryIBANDefByISO.FR = countryIBANDefByPref.FR = new IBANCheckDefinition('FR', 'France', 'FR', 27);
countryIBANDefByISO.GE = countryIBANDefByPref.GE = new IBANCheckDefinition('GE', 'Georgia', 'GE', 22); //new
countryIBANDefByISO.GB = countryIBANDefByPref.GB = new IBANCheckDefinition('GB', 'United Kingdom of Great Britain and Northern Ireland', 'GB', 22);
countryIBANDefByISO.IE = countryIBANDefByPref.IE = countryIBANDefByPref.GB;
countryIBANDefByISO.GI = countryIBANDefByPref.GI = new IBANCheckDefinition('GI', 'Gibraltar', 'GI', 23);
//countryIBANDefByISO.FR   //countryIBANDefByPref.FR = new IBANCheckDefinition('GP', 'Guadeloupe'                                            ,'FR', );
countryIBANDefByISO.GR = countryIBANDefByPref.GR = new IBANCheckDefinition('GR', 'Greece', 'GR', 27);
countryIBANDefByISO.HU = countryIBANDefByPref.HU = new IBANCheckDefinition('HU', 'Hungary', 'HU', 28);
countryIBANDefByISO.IE = countryIBANDefByPref.IE = new IBANCheckDefinition('IE', 'Republic of Ireland', 'IE', 22);
countryIBANDefByISO.IS = countryIBANDefByPref.IS = new IBANCheckDefinition('IS', 'Iceland', 'IS', 26);
countryIBANDefByISO.IL = countryIBANDefByPref.IL = new IBANCheckDefinition('IL', 'Israel', 'IL', 23); //new
countryIBANDefByISO.IT = countryIBANDefByPref.IT = new IBANCheckDefinition('IT', 'Italy', 'IT', 27);
countryIBANDefByISO.LB = countryIBANDefByPref.LB = new IBANCheckDefinition('LB', 'LEBANON', 'IL', 28); //new
countryIBANDefByISO.LI = countryIBANDefByPref.LI = new IBANCheckDefinition('LI', 'Liechtenstein', 'LI', 21);
countryIBANDefByISO.LT = countryIBANDefByPref.LT = new IBANCheckDefinition('LT', 'Lithuania', 'LT', 20);
countryIBANDefByISO.LU = countryIBANDefByPref.LU = new IBANCheckDefinition('LU', 'Luxembourg', 'LU', 20);
countryIBANDefByISO.LV = countryIBANDefByPref.LV = new IBANCheckDefinition('LV', 'Latvia', 'LV', 21);
countryIBANDefByISO.MK = countryIBANDefByPref.MK = new IBANCheckDefinition('MK', 'Macedonia', 'MK', 19); //new
//countryIBANDefByISO.FR   //countryIBANDefByPref.FR = new IBANCheckDefinition('MQ', 'Martinique'                                            ,'FR', );
countryIBANDefByISO.MT = countryIBANDefByPref.MT = new IBANCheckDefinition('MT', 'Malta', 'MT', 31);
countryIBANDefByISO.MU = countryIBANDefByPref.MU = new IBANCheckDefinition('MU', 'Mauritius', 'MU', 30); //new
countryIBANDefByISO.MC = countryIBANDefByPref.MC = new IBANCheckDefinition('MC', 'Monaco', 'MC', 27); //new
countryIBANDefByISO.ME = countryIBANDefByPref.ME = new IBANCheckDefinition('ME', 'Montenegro', 'ME', 22); //new
countryIBANDefByISO.NL = countryIBANDefByPref.NL = new IBANCheckDefinition('NL', 'Netherlands', 'NL', 18);
countryIBANDefByISO.NO = countryIBANDefByPref.NO = new IBANCheckDefinition('NO', 'Norway', 'NO', 15);
countryIBANDefByISO.PL = countryIBANDefByPref.PL = new IBANCheckDefinition('PL', 'Poland', 'PL', 28);
countryIBANDefByISO.PT = countryIBANDefByPref.PT = new IBANCheckDefinition('PT', 'Portugal, including Azores and Madeira', 'PT', 25);
countryIBANDefByISO.RO = countryIBANDefByPref.RO = new IBANCheckDefinition('RO', 'Romania', 'RO', 24); //new
countryIBANDefByISO.SM = countryIBANDefByPref.SM = new IBANCheckDefinition('SM', 'San Marino', 'SM', 27); //new
countryIBANDefByISO.SA = countryIBANDefByPref.SA = new IBANCheckDefinition('SA', 'Saudi Arabia', 'SA', 24); //new
countryIBANDefByISO.RS = countryIBANDefByPref.RS = new IBANCheckDefinition('RS', 'Serbia', 'RS', 22); //new
//countryIBANDefByISO.FR   //countryIBANDefByPref.FR = new IBANCheckDefinition('RE', 'Réunion'                                               ,'FR', );
countryIBANDefByISO.SE = countryIBANDefByPref.SE = new IBANCheckDefinition('SE', 'Sweden', 'SE', 24);
countryIBANDefByISO.SI = countryIBANDefByPref.SI = new IBANCheckDefinition('SI', 'Slovenia', 'SI', 19);
countryIBANDefByISO.SK = countryIBANDefByPref.SK = new IBANCheckDefinition('SK', 'Slovak Republic', 'SK', 24);
countryIBANDefByISO.TN = countryIBANDefByPref.TN = new IBANCheckDefinition('TN', 'Tunisia', 'TN', 24); //new
countryIBANDefByISO.TR = countryIBANDefByPref.TR = new IBANCheckDefinition('TR', 'Turkey', 'TR', 26); //new

function CheckIBANGeneral(sIBAN, IBANFormat)
{
    sIBAN= sIBAN.toUpperCase();
    
	if (sIBAN.length==0) return true;
	
	if (sIBAN.length!=IBANFormat.IBANLength) return false;
	if (sIBAN.substring(0,2)!=IBANFormat.IBANPrefix) return false;
	
	var arrLettersToNumbers = new Array();	
	arrLettersToNumbers[65] = 10;
	arrLettersToNumbers[66] = 11;
	arrLettersToNumbers[67] = 12;
	arrLettersToNumbers[68] = 13;
	arrLettersToNumbers[69] = 14;
	arrLettersToNumbers[70] = 15;
	arrLettersToNumbers[71] = 16;
	arrLettersToNumbers[72] = 17;
	arrLettersToNumbers[73] = 18;
	arrLettersToNumbers[74] = 19;
	arrLettersToNumbers[75] = 20;
	arrLettersToNumbers[76] = 21;
	arrLettersToNumbers[77] = 22;
	arrLettersToNumbers[78] = 23;
	arrLettersToNumbers[79] = 24;
	arrLettersToNumbers[80] = 25;
	arrLettersToNumbers[81] = 26;
	arrLettersToNumbers[82] = 27;
	arrLettersToNumbers[83] = 28;
	arrLettersToNumbers[84] = 29;
	arrLettersToNumbers[85] = 30;
	arrLettersToNumbers[86] = 31;
	arrLettersToNumbers[87] = 32;
	arrLettersToNumbers[88] = 33;
	arrLettersToNumbers[89] = 34;
	arrLettersToNumbers[90] = 35;
	
	modifiedIBAN = sIBAN.substring(4,sIBAN.length)+ sIBAN.substring(0,4);
	
	transformedIBAN="";
	
	for (var k=0; k<sIBAN.length; k++)
	{
		var c = modifiedIBAN.charAt(k);
		if(c>='A' && c<='Z') 
		{
			//letter
			transformedIBAN += arrLettersToNumbers[modifiedIBAN.charCodeAt(k)];
		}
		else if(c>='0' && c<='9')
		{
			//number
			transformedIBAN += c;
		}
		else
		{
			return false;
		}
	}
		
	strbase = transformedIBAN.substring(0,transformedIBAN.length-2)	+ "00";
	
	//ostatyk za base (bez controlno chislo)
	
	k=DAISModule(strbase,97);
	
	var ctrlNumber = new Number(sIBAN.substring(2,4))
	
	if((98 - k)!=ctrlNumber)
	{
		return false;//controlno chislo ne sywpada s izchislenoto
	}
	
	//ostatyk za IBAN
	k = DAISModule(transformedIBAN,97)
		
	if(k!=1)
	{
		return false;//newalidno kontrolno chislo
	}

	return true;
}

function CheckIBAN(sIBAN)
{
    return CheckIBANGeneral(sIBAN, countryIBANDefByPref.BG);
}

function CheckInternationIBAN(sIBAN,countryISOCode)
{
    sIBAN= sIBAN.toUpperCase();
    //alert(sIBAN);
    if (sIBAN == null) return true;
	if (sIBAN.length==0) return true;

    var firstLetter = sIBAN.substring(0,1);
    var secondLetter = sIBAN.substring(1,2);
    
    if (firstLetter >='A' && firstLetter <= 'Z' &&
        secondLetter >='A' && secondLetter <= 'Z')
    {
        var neededIBANDef = countryIBANDefByPref[sIBAN.substring(0,2)];
        var neededCountryWithIBANDef = countryIBANDefByISO[countryISOCode];
        
        if (neededCountryWithIBANDef == null)
        {
            //alert(491);
            return true;
        }
        else
        {
            if (neededIBANDef != neededCountryWithIBANDef)
            {
                //alert(489);
                return false;
            }
            else
            {
                //alert(494);
                return CheckIBANGeneral(sIBAN, neededIBANDef);
            }
        }
    }
    else
    {
        //alert(501);
        return true;
    }
}


function DAISModule(strBigNumber,SmallNumber)
{
	k=0;
	for (var i=0; i<strBigNumber.length; i++)
	{		
		k=(10*k + new Number(strBigNumber.charAt(i))) % SmallNumber;		
	
	}
	return k;
}

/***************************************************************
*	CheckDate()		
*	Description:	Function for validating date both filled or get from the calendar picker.
*	Author:			Anelia Brezoeva
*	Company:		DAIS - Software, Electronics and Trade, Ltd.
*	Date:			26.04.2004
*	Example:		not 42.13.2004
****************************************************************/


function isInteger(s){
	var i;
    for (i = 0; i < s.length; i++){   
        // Check that current character is number.
        var c = s.charAt(i);
        if (((c < "0") || (c > "9"))) return false;
    }
    // All characters are numbers.
    return true;
}

function stripCharsInBag(s, bag){
	var i;
    var returnString = "";
    // Search through string's characters one by one.
    // If character is not in bag, append to returnString.
    for (i = 0; i < s.length; i++){   
        var c = s.charAt(i);
        if (bag.indexOf(c) == -1) returnString += c;
    }
    return returnString;
}

function daysInFebruary (year){
	// February has 29 days in any year evenly divisible by four,
    // EXCEPT for centurial years which are not also divisible by 400.
    return (((year % 4 == 0) && ( (!(year % 100 == 0)) || (year % 400 == 0))) ? 29 : 28 );
}
function DaysArray(n) {
	for (var i = 1; i <= n; i++) {
		this[i] = 31
		if (i==4 || i==6 || i==9 || i==11) {this[i] = 30}
		if (i==2) {this[i] = 29}
   } 
   return this
}

function CheckDate(sDateid){

	sDate=sDateid.value;
	
	if (sDate.length!=0)
	{
		if(sDate.length!=10) {
		alert(STR_INCORRECT_FORMAT+STR_DATE_FORMAT);
		sDateid.focus();
		return false;
		} 
	}else {
		return true
		}
	 
	
	var dtCh= ".";
	var minYear=1900;
	var maxYear=2100;

	var daysInMonth = DaysArray(12)
	var pos1=sDate.indexOf(dtCh)
	var pos2=sDate.indexOf(dtCh,pos1+1)
	var strDay=sDate.substring(0,pos1)
	var strMonth=sDate.substring(pos1+1,pos2)
	var strYear=sDate.substring(pos2+1)
	strYr=strYear
	if (strDay.charAt(0)=="0" && strDay.length>1) strDay=strDay.substring(1)
	if (strMonth.charAt(0)=="0" && strMonth.length>1) strMonth=strMonth.substring(1)
	for (var i = 1; i <= 3; i++) {
		if (strYr.charAt(0)=="0" && strYr.length>1) strYr=strYr.substring(1)
	}
	month=parseInt(strMonth)
	day=parseInt(strDay)
	year=parseInt(strYr)
	if (pos1==-1 || pos2==-1){
		alert(STR_INCORRECT_FORMAT+STR_DATE_FORMAT);
		sDateid.focus();
		return false
	}
	if (strDay.length<1 || day<1 || day>31 || (month==2 && day>daysInFebruary(year)) || day > daysInMonth[month]){
		alert(STR_INCORRECT_FORMAT+STR_DATE_DAY);
		sDateid.focus();
		return false
	}
	if (strMonth.length<1 || month<1 || month>12){
		alert(STR_INCORRECT_FORMAT+STR_DATE_MONTH);
		sDateid.focus();
		return false
	}
	
	if (strYear.length != 4 || year==0 || year<minYear || year>maxYear){
		alert(STR_DATE_YEAR+minYear+STR_DATE_AND+maxYear);
		sDateid.focus();
		return false
	}
	if (sDate.indexOf(dtCh,pos2+1)!=-1 || isInteger(stripCharsInBag(sDate, dtCh))==false){
		alert(STR_INCORRECT_FORMAT+STR_DATE_FORMAT);
		sDateid.focus();
		return false
	}
	return true
}

function dateCompare(d1,d2)
	{
		if (d1>d2)
		return false;
		else
		return true;
	}
	
	function string2date(sDate)
	{
	var dDate;
	
	var dtCh= ".";
	var pos1=sDate.indexOf(dtCh);
	var pos2=sDate.indexOf(dtCh,pos1+1);
	var strDay=sDate.substring(0,pos1);
	var strMonth=sDate.substring(pos1+1,pos2);
	var strYear=sDate.substring(pos2+1);
	
	dDate = new Date(strYear,strMonth-1,strDay);
		
	return dDate;
	}

function Convert2BISERASymbols(str2)
{
	var str = str2.toUpperCase();
	var l = str.length;
	var res = "";
	
	
	for (var k=0; k<l; k++)
	{
		var c = str.charAt(k);
		var c2 = str2.charAt(k);
		
		if( !(0==k && "-"==c) && 
	        (" "==c || "!"==c || '"'==c || "%"==c || "&"==c || "'"==c || "("==c || ")"==c ||
		    "*"==c || "+"==c || ","==c || "-"==c || "."==c || "/"==c || ":"==c || ";"==c ||
		    "<"==c || "="==c || ">"==c || "?"==c || (c>='0' && c<='9') || (c>='A' && c<='Z') || (c>='А' && c<='Я'))
	      ) 
	    {
		    res += c2;				
	    }
        else
        {
	        res += "?";
        }
	}
	return res;
}

function checkForBisera(strobj)
{

	var cnt = strobj.length;
	var testBisera="";

	for (var i=0; i<cnt; i++)
		{
			//var str=eval("document.forms[0]."+strobj[i]+".value");//value to check
			var str = document.getElementById(strobj[i]).value;//value to check
			
			if (str!="")
			{
				testBisera = Convert2BISERASymbols(str);

				if(str!=testBisera)
				{
				    document.getElementById(strobj[i]).value=testBisera;
					//eval("document.forms[0]."+strobj[i]+".value='"+testBisera+"';");
					
					document.getElementById(strobj[i]).focus();
					//eval("document.forms[0]."+strobj[i]+".focus();");
					
					alert(STR_BISERA_CHECK);
					return true;
				}
			}		
		}	
	return false;
	
}



