// lezding zero
function LZ(str, len){
	str = trim(str);
	while(str.length < len)
		str = '0'+str;
	return str;
}

//
//	Form validation functions
//	by W.P.Dauchy @1996-2000
//

// ValidateSelect
function ValidateSelect(theMenu)
{
	if (	theMenu == null ||
		theMenu.selectedIndex == -1 ||
		theMenu.selectedIndex == null ||
		theMenu.options[theMenu.selectedIndex].value == "")
		return false;
	return true;
}


// ValidateRadio
function ValidateRadio(theRadio, cnt)
{
	if (cnt == null)
		cnt = (theRadio.length ? theRadio.length : 1)
	if (cnt == 1)
		return (theRadio.checked);
	for (i=0; i<cnt; i++)
		if (theRadio[i].checked) return true;
	return false;
}

// ValidateTel
function ValidateTel(strValue)
{
	strValue = strValue.value ? strValue.value : strValue;
	return strValue.replace(/[\. \-]/g, '').match(/^\d{10}$/);
}

// ValidateEmail
function ValidateEmail(what)
{
	return what.value.match(/^[a-z0-9\.\-\_]+@([a-z0-9\-\_]+\.)+[a-z]{2,3}$/i);
}

// ValidateDate()
function ValidateDate(strValue)
{
	strValue = strValue.value ? strValue.value : strValue;
	if (!strValue.match(/^\d{2}[\/\-\:]\d{2}[\/\-\:]\d{4}$/)) return false;
	var a = strValue.split(/[\/\-\:]/), d = new Date(a[2], a[1]-1, a[0]);
	return (!isNaN( d ) && a[2] > 0 && d.getYear()%100==a[2]%100 && d.getMonth()==a[1]-1 && d.getDate()==a[0]);
}

// ValidateDateTime
function ValidateDateTime(strValue)
{
	return ValidateDate(strValue);
}

// trim
function trim(s) { return s.replace(/(^\s*)|(\s*$)/g,''); }
String.prototype.trim = function(){ return trim(this); }

// checkRIB
function checkRIB(rib)
{
	rib = rib.toUpperCase().replace(/\s*/g, '');
	var dict = {"0":0, "1":1, "2":2, "3":3, "4":4, "5":5, "6":6, "7":7, "8":8, "9":9, "A":1, "B":2, "C":3, "D":4, "E":5, "F":6, "G":7, "H":8, "I":9,"J":1, "K":2, "L":3, "M":4, "N":5, "O":6, "P":7, "Q":8, "R":9,"S":2, "T":3, "U":4, "V":5, "W":6, "X":7, "Y":8, "Z":9};
	for (var num = "", i=0; i < rib.length; i++)
	{
		num += dict[rib.substr(i,1)];
	}
	var cle = parseFloat(num.substr(num.length-2, num.length));
	if (cle < 1 || cle > 97)
		return false;
	a = num.substr(0,7);
	b = num.substr(7,7);
	c = num.substr(14,7);
	return cle == 97 - ( ( 62*a + 34*b + 3*c ) % 97 );
}
