//<script  language ="JavaScript1.2">

//
function SetFocus(object)
	{
		object.focus();
		return (false);
	}

//
function MessageBox(text)
	{
		alert(text);
	}


// Ali je izpolnjen checkbox ali textbox, vsaj eden mora biti izpolnjen

function Stroski(forma1, forma2, komentar)
{
if (!forma1.checked && forma2.value == "")
 { MessageBox(komentar);
   return SetFocus(forma2);
 }
return (true);
}

function Telefon(forma1, forma2,forma3, forma4, forma5, forma6, forma7, komentar)
{
if ((forma1.value == "" || forma2.value == "" || forma3.value == "") && (forma4.value == "" || forma5.value == "" || forma6.value == "" ||forma7.value == "" ))
 { MessageBox(komentar);
   return SetFocus(forma2);
 }
return (true);
}



//Vrne false, če je znesek manjši od 0 in sporočilo
function AliPozitiven(edit, opozorilo)
	{
	var vrednost = conCurrencyDouble(edit.value);
	if (vrednost < 0)
		{
			MessageBox(opozorilo);
			return(false);
		}
	else
		return (true);
	}

// Vrne Razliko v milisekundah med dvema datumoma
function DateDifference(dateToday, dateTest) 
	{ 		
		var milSec1, milSec2;

		milSec1 = Date.UTC(dateToday.getFullYear(),dateToday.getMonth(),dateToday.getDate(),0,0,0);
		milSec1 = milSec1/86400000;
		milSec2 = Date.UTC(dateTest.getFullYear(),dateTest.getMonth(),dateTest.getDate(),0,0,0);
		milSec2 = milSec2/86400000;

		return milSec2 - milSec1;
	}

//Ali je vsaj eden v selectu izbran
function CheckSelect(select, message)
{
	if (select.selectedIndex < 0)
	{
		MessageBox(message);
		return SetFocus(select);
	}
	return (true);
}

	
// ali je vsaj en v Radiobox grupi izbran
function CheckRadio(radio, message)
{
	var radioSelected = false;
	for (i = 0; i < radio.length; i++)
	{
		if (radio[i].checked)
		{
			radioSelected = true;
		}
	}
	if (!radioSelected)
	{
		MessageBox(message);
		return (false);
	}
	return (true);
}

function CheckRadio2(radio, message)
{
	var radioSelected = false;
	for (i = 0; i < radio.length; i++)
	{
		if (radio[i].checked)
		{
			radioSelected = true;
		}
	}
	if (!radioSelected)
	{
		MessageBox(message);
    	return SetFocus(radio[0]);
	}
	return (true);
}



//Pregleda ali je vnosno polje prazno
function CheckNotEmpty(edit, name, message)
	{
		if (edit.value == "")
		{
			if(message == "")
			{
				MessageBox("Vpišite vrednost v polje " + name + ".");
			}
			else
			{
				MessageBox(message);
			}
			return SetFocus(edit);
		}
		return (true);
	}


//Pregleda, če je vsaj ena skupina polj izpolnjena, GSM, tel
function CheckTel(edit1,edit2,edit3,edit4,edit5,edit6,edit7,message)
	{
		if (edit1.value == "" && edit2.value == "" && edit3.value == "" && edit4.value == "" && edit5.value == "" && edit6.value == "" && edit7.value == "")
		{
		MessageBox(message);
		return SetFocus(edit1);
		}		
		return (true);
	}


function  CheckDrugi(edit1,edit2,edit3,edit4,edit5,edit6,edit7,message)
	{
		if (edit1.value != "" || edit2.value != "" || edit3.value != "")
		{

		if (edit1.value == "" || edit2.value == "" || edit3.value == "" )			
		{
			MessageBox(message);
			return SetFocus(edit1);
		}
			

		}		
		return (true);
	}

function  CheckTret(edit1,edit2,edit3,edit4,edit5,edit6,edit7,message)
	{
		if (edit4.value != "" || edit5.value != "" || edit6.value != "" || edit7.value != "")
		{

		if (edit4.value == "" || edit5.value == "" || edit6.value == "" || edit7.value == "" )			
		{
			MessageBox(message);
			return SetFocus(edit4);
		}
			

		}		
		return (true);
	}




//Pregleda ce je sploh izbral kaj iz option seznama - v bazi je zgornji zapis vedno prazen v smislu --- vnesi! ---- da lahko to preverimo

function CheckOption(edit, name, message)
	{
		if (edit.value == "0")
		{
			if(message == "")
			{
				MessageBox("Vpišite vrednost v polje " + name + ".");
			}
			else
			{
				MessageBox(message);
			}
			return SetFocus(edit);
		}
		return (true);
	}






//Pregleda ali je vnosno polje prazno

function CheckNotEmpty(edit, name, message)
	{
		if (edit.value == "")
		{
			if(message == "")
			{
				MessageBox("Vpišite vrednost v polje " + name + ".");
			}
			else
			{
				MessageBox(message);
			}
			return SetFocus(edit);
		}
		return (true);
	}

//Aleš-popravjeno 25.4.2003
//Pregleda datum
function CheckDate(edit, name, checkWorkDay, checkSunday, offset)
	{
		var value = edit.value;

		if (value == "")
		{
			return (true);
		}
				
		var bTmp = ValidString(edit,'1234567890.');		
		if (!bTmp) {
			MessageBox('Datum ne obstaja! Prosim preverite vnos!\nDatum vnesite v obliki dd.mm.llll!');
			return SetFocus(edit);					
		}
		
		var nSeparators = 0;
		var nDay = "";
		var nMonth = "";
		var nYear = "";
					
		for (i = 0;  i < value.length; i++)
		{
			ch = value.charAt(i);
			if(ch == ".")
			{
				nSeparators++;
				if(nSeparators > 2)
				{
					break;
				}
			}
			else
			{
				if(nSeparators == 0)
				{
					nDay += ch;
				}
				else if(nSeparators == 1)
				{
					nMonth += ch;
				}
				else if(nSeparators == 2)
				{			
					nYear += ch;
				}
			}
		}		
		nDay = parseFloat(nDay);		
		nMonth = parseFloat(nMonth);
		nYear = parseFloat(nYear);		
		
		
		if(isNaN(nDay) || isNaN(nMonth)  || isNaN(nYear)){
			MessageBox('Datum ne obstaja! Prosim preverite vnos!\nDatum vnesite v obliki dd.mm.llll!');
			return SetFocus(edit);
		}
		else
		{
			
			edit.value =nDay+'.'+nMonth+'.'+nYear;
		}
			
		
		var strDay = nDay + '';
		var strMonth = nMonth + '';
		var strYear = nYear + '';
		
		if(strDay.length > 2 || strMonth.length > 2)
		{
			MessageBox('Datum ne obstaja! Prosim preverite vnos!\nDatum vnesite v obliki dd.mm.llll!');
			return SetFocus(edit);
		}
		

		var dateTest;
		dateTest = new Date(nYear, nMonth-1, nDay);

		if(dateTest.getFullYear() != nYear || dateTest.getMonth() != nMonth-1 || dateTest.getDate() != nDay)
		{
			MessageBox('Datum ne obstaja! Prosim preverite vnos!\nDatum vnesite v obliki dd.mm.llll!');
			return SetFocus(edit);
		}

		if(nSeparators != 2)
		{
			MessageBox("Napaka v polju " + name + ".\nDatum ni v pravi obliki (dan.mesec.leto).");
			return SetFocus(edit);
		}

		var dateLow;
		dateLow = new Date(1800, 1, 1);
		if(DateDifference(dateTest, dateLow) > 0)
		{
			MessageBox("Datum v polju " + name + " ni veljaven!\nDatum vnesite v obliki dd.mm.llll!");
			return SetFocus(edit);
		}

		nDay = nDay + parseFloat(offset);
		dateTest = new Date(nYear, nMonth-1, nDay);

		if(checkWorkDay)
		{
			if(dateTest.getDay() == 0 || dateTest.getDay() == 6)
			{
				MessageBox("V polje " + name + " vnesite delovni dan (ponedeljek - petek)!");
				return SetFocus(edit);
			}
		}

		if(checkSunday)
		{
			if(dateTest.getDay() == 0)
			{
				MessageBox("Obdobje, ki ste ga vnesli, se ne zaključi na delovni dan, zato vnesite ustrezno obdobje z zaključkom na delovni dan!");
				return false;
			}
		}

		return (true);
	}



//Pregleda uro
function CheckTime(edit, name, message)
{
	var value = edit.value;

	if (value == "")
	{
		return (true);
	}
		
	var nSeparators = 0;
	var nHour = "";
	var nMinute = "";

	for (i = 0;  i < value.length; i++)
	{
		ch = value.charAt(i);
		if(ch == ":")
		{
			nSeparators++;
			if(nSeparators > 1)
			{
				break;
			}
		}
		else
		{
			if(nSeparators == 0)
			{
				nHour += ch;
			}
			else if(nSeparators == 1)
			{
				nMinute += ch;
			}
		}
	}

	nHour = parseFloat(nHour);
	nMinute = parseFloat(nMinute);

	if(isNaN(nHour) || isNaN(nMinute) || nSeparators != 1)
	{
		MessageBox("Napaka v polju " + name + ".\nČas ni v pravi obliki (ura:minuta).");
		return SetFocus(edit);
	}

	if(nHour < 0 || nHour > 23)
	{
		MessageBox("Napaka v polju " + name + ".\nUra mora biti med 0 in 23.");
		return SetFocus(edit);
	}
	if(nMinute < 0 || nMinute > 59)
	{
		MessageBox("Napaka v polju " + name + ".\nMinuta mora biti med 0 in 59.");
		return SetFocus(edit);
	}
		
	return (true);
}

//Ali je vnešena številka
function CheckNumber(edit, name, message)
{
	var value = edit.value;
	var validText = "0123456789";
	var allValid = true;
	for (i = 0;  i < value.length; i++)
	{
		ch = value.charAt(i);
		for (j = 0;  j < validText.length;  j++)
			if (ch == validText.charAt(j))
				break;
			if (j == validText.length)
			{
				allValid = false;
				break;
			}
	}
	if (!allValid)
	{
		if(message == "")
		{
			MessageBox("V polje " + name + " vpišite samo številke.");
		}
		else
		{
			MessageBox(message);
		}
		return SetFocus(edit);
	}
	return (true);
}

//Ali je vnešena številka znotraj omejitev

function CheckNumberLim(edit, name, message, omejitev_spodaj, omejitev_zgoraj)
{
	var value = edit.value;
	
	value = parseInt(value,10);
	omejitev_spodaj = parseInt(omejitev_spodaj);
        omejitev_zgoraj = parseInt(omejitev_zgoraj);
	if (value  > omejitev_zgoraj || value < omejitev_spodaj)
			{
				if(message == "")
					{
						MessageBox("V polje " + name + " vpišite samo številke.");
					}
				else
					{
						MessageBox(message);
					}
				return SetFocus(edit);
			}
        return (true);
}


function CheckNumberType(edit, name, type)
{
	if(type != "DECIMAL" && type != "DB2DECIMAL" && type != "WUSET" && type != "MINDEPOZIT" && type != "MINDEPOZIT5" &&
		type != "CICSDECIMAL" && type != "CICSMIN")
	{
		if (!CheckNumber(edit, name, ""))
			return (false);
	}

	var value = edit.value;
	var max, min;

	if(type == "DECIMAL")
	{
		value = parseFloat(value) * 100;
		if (value % 10 == 0)
		{
			value = value / 10;
			if (value % 10 == 0)
			{
				value = value / 10;
			}
		}
	}

	if(type == "SMALL")
	{
		max = 32768;
	}
	else if(type == "LONG")
	{
		max = 2147483648;
	}
	else if(type == "DECIMAL")
	{
		max = 920000000000000;
	}
	else if(type == "DB2DECIMAL")
	{
		max = 10000000000000;
	}
	else if(type == "CICSDECIMAL")
	{
		max = 99999999999;
	}
	else if(type == "WUSET")
	{
		max = 1700001;
	}
		
	if(type == "MINDEPOZITDAYS")
	{
		if(value < 31)
		{
			var text;
			text = "Najkrajše obdobje kratkoročne vezave depozita je 31 dni.";
			MessageBox(text);
			return SetFocus(edit);
		}
	}

	if(type == "MAXDEPOZITDAYS")
	{
		if(value > 365)
		{
			var text;
			text = "Najdaljše obdobje kratkoročne vezave depozita je 365 dni.";
			MessageBox(text);
			return SetFocus(edit);
		}
	}

	if(type == "MINDEPOZITMONTHS")
	{
		if(value < 12)
		{
			var text;
			text = "Najkrajše obdobje dolgoročne vezave depozita je 12 mesecev.";
			MessageBox(text);
			return SetFocus(edit);
		}
	}

	if(type == "DB2DECIMAL" || type == "WUSET" || type == "MINDEPOZIT" || type == "MINDEPOZIT5" || type == "CICSDECIMAL" ||
		type == "CICSMIN")
	{
		all = value.split('.');
		tmpvalue = '';
		for (i=0; i < all.length; i++)
		{
			tmpvalue += all[i];
		}
		all = tmpvalue.split(',');
		value = all[0];
	}
		
	if(type == "MINDEPOZIT")
	{
		if (value < 30000)
		{
			var text;
			text = "V polju " + name + " mora biti znesek vsaj 30.000 SIT.";
			MessageBox(text);
			return SetFocus(edit);
		}
	}

	if(type == "MINDEPOZIT5")
	{
		if (value < 150000)
		{
			var text;
			text = "V polju " + name + " mora biti znesek vsaj 150.000 SIT.";
			MessageBox(text);
			return SetFocus(edit);
		}
	}

	if(type == "CICSMIN")
	{
		if (value == 0)
		{
			var text;
			text = "V polju " + name + " mora biti znesek vsaj 1,00 SIT.";
			MessageBox(text);
			return SetFocus(edit);
		}
	}

	if(value >= max)
	{
		var text;
		if(type == "DECIMAL")
		{
			text = "V polju " + name + " mora biti število manjše od 920.000.000.000.000 .";
		}
		else if(type == "DB2DECIMAL")
		{
			text = "V polju " + name + " mora biti število manjše od 10.000.000.000.000 .";
		}
		else if(type == "CICSDECIMAL")
		{
			text = "V polju " + name + " mora biti število manjše od 100.000.000.000 .";
		}
		else if(type == "WUSET")
		{
			text = "V polju " + name + " mora biti število manjše od 1.700.001 .";
		}
		else
		{
			text = "V polju " + name + " mora biti število manjše od " + max + ".";
		}
		MessageBox(text);
		return SetFocus(edit);
	}

	if(type == "DECIMAL")
	{
		if (!CheckCurrency(edit, name))
			return (false);
	}


	return (true);
}


//Ali denarni znesek
function CheckCurrency(box, name) //checkiram, če je znesek v standardni obliki
{
	var value = retString(box.value,'-','');

	if (value.length==0) return(true);

	var validText = "-0123456789.,";
	var allValid = true;
	var length = box.value.length;
	var comma=false;

		for (i = 0;  i < value.length; i++)
		{
			ch = value.charAt(i);
			for (j = 0;  j < validText.length;  j++)
				if (ch == validText.charAt(j))
					break;
				if (j == validText.length)
				{
					allValid = false;
					break;
				}
		}

	    if (!allValid)
	    {
			MessageBox("V polje " + name + " vpišite samo številke.");
			box.focus();
			return(false);
	    }
	    if (value.charAt(0)==',')
	    {
			MessageBox("V polje " + name + " pravilno postavite decimalno vejico.");
			box.focus();
			return(false);
	    }

	      while (value.charAt(0)=='0') // vodilne nicle odpadejo
		{
			value=value.substring(1,box.value.length);
		}
		dec=-1;
		for (i=value.length-1; i>=0; i--)
		{
			if (value.charAt(i)==',') {		// nasel sem vejico
				if (!(dec==-1))
				{
					MessageBox("V polje " + name + " pravilno postavite decimalno vejico.");
					box.focus();
					return (false);
				}
				comma=true;
				dec=i;
			}
			if (value.charAt(i)=='.') {		// nasel sem piko
				if (dec==-1) dec=value.length;
				if (!((dec-i)%4==0))
				{
					MessageBox("V polje " + name + " pravilno postavite piko oz. decimalno piko nadomestite z decimalno vejico.");
					box.focus();
					return (false);
				} 
				if (i==0)
				{
					MessageBox("V polje " + name + " pravilno postavite piko oz. decimalno piko nadomestite z decimalno vejico.");
					box.focus();
					return (false);
				} 
			}
		}										// preverjene pozicije pik in vejic (xxx.xxx.xxx,xxxxxxxx...)

		all=value.split('.');
		tmpvalue='';
		for (i=0; i < all.length; i++)
		{
			tmpvalue+=all[i].replace(',','.');
		}
		if (comma) {
			tmpvalue=Math.round(parseFloat(tmpvalue)*100)/100;
			if ((tmpvalue%1)==0){
				value=tmpvalue+'';
				n=value.length;
				for (i=1; i<((n-1)-((n-1)%3))/3+1; i++) {
					value=value.substring(0,value.length-3*(i)-i+1)+'.'+value.substring(value.length-3*(i)-i+1, value.length);
				}
			}
			else {
				value=tmpvalue+'';
				value=value.replace(/\./, ',');
				if (value.charAt(value.length-2)==',') value+='0';
				n=value.length;
				for (i=1; i<((n-1)-((n-1)%3))/3; i++) {
					value=value.substring(0,value.length-2-4*(i))+'.'+value.substring(value.length-2-4*(i), value.length);
				}
			}
		}
		else{
			value=tmpvalue+'';
			n=value.length;
			for (i=1; i<((n-1)-((n-1)%3))/3+1; i++) {
				value=value.substring(0,value.length-3*(i)-i+1)+'.'+value.substring(value.length-3*(i)-i+1, value.length);
			}
		}
	if (value.search(',')==-1) {
		value+=',00';
	}
	if (value.charAt(0)==',') value='0'+value;
	box.value=value;
	return(true);

}


function CheckCurNeg(box, name) //checkiram, če je znesek v standardni obliki
{
	var value = box.value;

	if (value.length==0) return(true);

	var validText = "-0123456789.,";
	var allValid = true;
	var length = box.value.length;
	var comma=false;

		for (i = 0;  i < value.length; i++)
		{
			ch = value.charAt(i);
			for (j = 0;  j < validText.length;  j++)
				if (ch == validText.charAt(j))
					break;
				if (j == validText.length)
				{
					allValid = false;
					break;
				}
		}

	    if (!allValid)
	    {
			MessageBox("V polje " + name + " vpišite samo številke.");
			box.focus();
			return(false);
	    }
	    if (value.charAt(0)==',')
	    {
			MessageBox("V polje " + name + " pravilno postavite decimalno vejico.");
			box.focus();
			return(false);
	    }

	      while (value.charAt(0)=='0') // vodilne nicle odpadejo
		{
			value=value.substring(1,box.value.length);
		}
		dec=-1;
		for (i=value.length-1; i>=0; i--)
		{
			if (value.charAt(i)==',') {		// nasel sem vejico
				if (!(dec==-1))
				{
					MessageBox("V polje " + name + " pravilno postavite decimalno vejico.");
					box.focus();
					return (false);
				}
				comma=true;
				dec=i;
			}
			if (value.charAt(i)=='.') {		// nasel sem piko
				if (dec==-1) dec=value.length;
				if (!((dec-i)%4==0))
				{
					MessageBox("V polje " + name + " pravilno postavite piko oz. decimalno piko nadomestite z decimalno vejico.");
					box.focus();
					return (false);
				} 
				if (i==0)
				{
					MessageBox("V polje " + name + " pravilno postavite piko oz. decimalno piko nadomestite z decimalno vejico.");
					box.focus();
					return (false);
				} 
			}
		}										// preverjene pozicije pik in vejic (xxx.xxx.xxx,xxxxxxxx...)

		all=value.split('.');
		tmpvalue='';
		for (i=0; i < all.length; i++)
		{
			tmpvalue+=all[i].replace(',','.');
		}
		if (comma) {
			tmpvalue=Math.round(parseFloat(tmpvalue)*100)/100;
			if ((tmpvalue%1)==0){
				value=tmpvalue+'';
				n=value.length;
				for (i=1; i<((n-1)-((n-1)%3))/3+1; i++) {
					value=value.substring(0,value.length-3*(i)-i+1)+'.'+value.substring(value.length-3*(i)-i+1, value.length);
				}
			}
			else {
				value=tmpvalue+'';
				value=value.replace(/\./, ',');
				if (value.charAt(value.length-2)==',') value+='0';
				n=value.length;
				for (i=1; i<((n-1)-((n-1)%3))/3; i++) {
					value=value.substring(0,value.length-2-4*(i))+'.'+value.substring(value.length-2-4*(i), value.length);
				}
			}
		}
		else{
			value=tmpvalue+'';
			n=value.length;
			for (i=1; i<((n-1)-((n-1)%3))/3+1; i++) {
				value=value.substring(0,value.length-3*(i)-i+1)+'.'+value.substring(value.length-3*(i)-i+1, value.length);
			}
		}
	if (value.search(',')==-1) {
		value+=',00';
	}
	if (value.charAt(0)==',') value='0'+value;
	box.value=value;
	return(true);

}


//Pretvori Currency znesek v Double    1.000.000,50 v 1000000.50
//znesek je tipa string
function conCurrencyDouble(znesek)
{
	var RetVal = znesek;
	
	RetVal = RetVal.replace('.', '');
	RetVal = RetVal.replace('.', '');
	RetVal = RetVal.replace('.', '');
	RetVal = RetVal.replace('.', '');
	RetVal = RetVal.replace('.', '');
	RetVal = RetVal.replace(',', '.');
	return(RetVal)
}

//Zamenja devcimalno piko z vejico    1.000.000,50 v 1000000.50
//znesek je tipa string
function conPikaVejica(znesek)
{
	var RetVal = znesek;
	
	RetVal = RetVal.replace('.', ',');
	return(RetVal)
}

//Odšteje znesek v polju edit2 od zneska v polju edit1
function OdstejZnesek(edit1, edit2)
{
	var RetVal = true;
	var Znesek;
	var ZnesekMinus;
	var Rezultat;
	
	Znesek = edit1.value.toString();
	Znesek = conCurrencyDouble(Znesek);
	
	ZnesekMinus = edit2.value.toString();
	ZnesekMinus = conCurrencyDouble(ZnesekMinus);
	
	Rezultat = Znesek - ZnesekMinus;
	
	edit1.value = Rezultat;
	RetVal = CheckCurrency(edit1, 'Znesek')
}

//spremeni znesek , tako, da odšteje ali prišteje razliko med nono nrednostjo in staro vrednostjo
function SpremeniZnesek(znesek, novavrednost, staravrednost)
{
	var nova = new Number(conCurrencyDouble(novavrednost.value));
	var stara = new Number(conCurrencyDouble(staravrednost.value));
	var temp = new Number(conCurrencyDouble(znesek.value));
	var noviznesek = new Number(0);
	var strnoviznesek = new String("");
	
	noviznesek =  temp - (nova - stara);
	
	//Popravimo novi znesek
	//document.frmForm.txtZnesek.value = noviznesek;
	strnoviznesek = noviznesek.toString(10)
znesek.value = conPikaVejica(strnoviznesek)
	
		// v hidden vrednost prepišemo novo vrednost
	//staravrednost.value = novavrednost.value;
	
	return (CheckCurrency(znesek,'Znesek'))

}


//Spremeni znesek vsote za razliko nove in stare vrednosti
//Uporablja se za seštevanje zneskov na formi
function PristejZnesek(znesek, novavrednost, staravrednost)
{
	var nova = new Number(conCurrencyDouble(novavrednost.value));
	var stara = new Number(conCurrencyDouble(staravrednost.value));
	var temp = new Number(conCurrencyDouble(znesek.value));
	var noviznesek = new Number(0);
	var strnoviznesek = new String("");
	
	noviznesek =  temp + (nova - stara);
	
	//Popravimo novi znesek
	//document.frmForm.txtZnesek.value = noviznesek;
	strnoviznesek = noviznesek.toString(10)

	znesek.value = conPikaVejica(strnoviznesek)
	
		// v hidden vrednost prepišemo novo vrednost
	//staravrednost.value = novavrednost.value;
	
	
	return (CheckCurrency(znesek,'Znesek'))

}

//Prepiše novo vrednost(polja) v staro vrednost (polja)
function VStaroVrednost(novavrednost, staravrednost)
{
	// v hidden vrednost prepišemo novo vrednost
	staravrednost.value = novavrednost.value;
	return (true)
}

//Aleš
//kontrola email vnosnega polja
function CheckEposta(edit,name,message)
{
r1 =/[^@\-\.\w]|^[_@\.\-]|[\._\-]{2}|[@\.]{2}|(@)[^@]*\1/;
r2 =/@[\w\-]+\./;
r3 = /\.[a-zA-Z]{2,3}$/;
email = edit.value;
if((((email.search(r1) != -1)||
	  (email.search(r2)) == -1)||
	  (email.search(r3) == -1))&email!=""){
		alert(message);		
		return SetFocus(edit);
	}	
	else
	{
	   return(true);
	}
}

//Ali je vnešen text
function CheckString(edit, name, message)
{
	var value = edit.value;
	var validText = "0123456789";
	var allValid = true;
	for (i = 0;  i < value.length; i++)
	{
		ch = value.charAt(i);
		for (j = 0;  j < validText.length;  j++)
			if (ch == validText.charAt(j))
			{
				allValid = false;
				break;
			}		
	}
	if (!allValid)
	{
		if(message == "")
		{
			MessageBox("V polje " + name + " vpišite samo črke.");
		}
		else
		{
			MessageBox(message);
		}
		return SetFocus(edit);
	}
	return (true);
}

//ales
function DateCheck(date1,date2) {
//če je datum date1 prazen prevzamem današnji datum na client-strani ??:(??-> predlog Uroš 
if (date1=="") {
	var d = new Date();
	var Dat=''
	Dat += d.getDate()+ ".";
	Dat += (d.getMonth() + 1) + ".";
	Dat += d.getYear();

	var earlierdate = new Date(FormatDate(Dat));
}
else {
	var earlierdate = new Date(FormatDate(date1));
}

var laterdate = new Date(FormatDate(date2));           //Create date object.

var difference = laterdate.getTime() - earlierdate.getTime(); 


//razlika v dnevih
var daysDifference = Math.floor(difference/1000/60/60/24); 

//difference -= daysDifference*1000*60*60*24 
//ostale razlike
/*var hoursDifference = Math.floor(difference/1000/60/60); 
difference -= hoursDifference*1000*60*60 
var minutesDifference = Math.floor(difference/1000/60); 
difference -= minutesDifference*1000*60 
var secondsDifference = Math.floor(difference/1000); */
if (daysDifference > 0) 
//{ 
	return (true)
//}
else
//{
	return (false)
//}
//return(daysDifference)

} 


//Datum v ustrezni format llll/mm/dd
function FormatDate(date)
	{
		var value = date;

		if (value == "")
		{
			return (true);
		}

		var nSeparators = 0;
		var nDay = "";
		var nMonth = "";
		var nYear = "";

		for (i = 0;  i < value.length; i++)
		{
			ch = value.charAt(i);
			if(ch == ".")
			{
				nSeparators++;
				if(nSeparators > 2)
				{
					break;
				}
			}
			else
			{
				if(nSeparators == 0)
				{
					nDay += ch;
				}
				else if(nSeparators == 1)
				{
					nMonth += ch;
				}
				else if(nSeparators == 2)
				{			
					nYear += ch;
				}
			}
		}

		nDay = parseFloat(nDay);
		nMonth = parseFloat(nMonth);
		nYear = parseFloat(nYear);
		
		return(nYear+'/'+nMonth+'/'+nDay);
}		

//ales

function CheckDec(box, name) //checkiram, če je številka v standardni obliki
{
	var value = box.value;
	var icnt; //stevec vejic
	var icnt; //stevec pik

	if (value.length==0) return(true);

	var validText = "0123456789.,";
	var allValid = true;
	var length = box.value.length;	
	icnt=0;
	jcnt=0;
	for (i = 0;  i < value.length; i++)
	{
		ch = value.charAt(i);
		if (ch == ',') icnt+=1;
		if (ch == '.') jcnt+=1;
			
			
		for (j = 0;  j < validText.length;  j++)				
			if (ch == validText.charAt(j))
				break;
			if (j == validText.length)
			{
				allValid = false;
				break;
			}
	}		
	if (!allValid || icnt > 1 || jcnt > 1 ||  (icnt+jcnt) > 2 )
	    {
			MessageBox("V polje " + name + " pravilno vpišite številko.");
			box.focus();
			return(false);
	    }
	else
		{
			return(true);
		}
}

//ales
function retString(strVal, Cch,Rch)
/*
text..željeni text
Cch..iskani character
Rch..iskanega zamenjaj s tem
*/
{		
	
	var strlen = strVal.length;
	var i,ch,RetVal='';			
		for (i = 0;  i < strlen; i++)
		{
			ch = strVal.charAt(i);			
			if (ch == Cch) {
				RetVal+=Rch;				
			}
			else{
				RetVal+=ch;			
			}
		}		
		return(RetVal)				
}

function ValidString(box, validText) //checkiram, string vsebuje dovoljene znake
{
	var value = box.value;

	if (value.length==0) return(true);
	
	var allValid = true;
	var length = box.value.length;	
	icnt=0;
	jcnt=0;
	for (i = 0;  i < value.length; i++)
	{
		ch = value.charAt(i);			
			
		for (j = 0;  j < validText.length;  j++)				
			if (ch == validText.charAt(j))
				break;
			if (j == validText.length)
			{
				allValid = false;
				break;
			}
	}		
	if (!allValid)
	    {			
			return(false);
	    }
	else
		{
			return(true);
		}
}

// preveri dolžino in avtomatsko vrže v naslednje oknce
function DolzinaNaprej(polja, objekt1, objekt2)
{

var Input=objekt1.value;


if (Input.length == polja)
 {
 objekt2.focus();
 return(true);
 }

}