// JavaScript Document
function emailvalidation(entered, alertbox)
{
// E-mail Validation by Henrik Petersen / NetKontoret
// Explained at www.echoecho.com/jsforms.htm
// Please do not remove this line and the two lines above.
with (entered)
{
apos=value.indexOf("@"); 
dotpos=value.lastIndexOf(".");
lastpos=value.length-1;
if (apos<1 || dotpos-apos<2 || lastpos-dotpos>3 || lastpos-dotpos<2) 
{if (alertbox) {alert(alertbox);} return false;}
else {return true;}
}
} 

function valuevalidation(entered, min, max, alertbox, datatype)
{
// Value Validation by Henrik Petersen / NetKontoret
// Explained at www.echoecho.com/jsforms.htm
// Please do not remove this line and the two lines above.
with (entered)
{
value2=value.replace(".","")
checkvalue=parseFloat(value2.replace(",",""));
if (datatype)
{smalldatatype=datatype.toLowerCase();
if (smalldatatype.charAt(0)=="i") {checkvalue=parseInt(value.replace(".",""))};
}
if ((parseFloat(min)==min && checkvalue<min) || (parseFloat(max)==max && checkvalue>max) || value.replace(".","")!=checkvalue)
{if (alertbox!="") {alert(alertbox);} return false;}
else {return true;}
}
} 

function digitvalidation(entered, min, max, alertbox, datatype)
{
// Digit Validation by Henrik Petersen / NetKontoret
// Explained at www.echoecho.com/jsforms.htm
// Please do not remove this line and the two lines above.
with (entered)
{
checkvalue=parseFloat(value);
if (datatype)
{smalldatatype=datatype.toLowerCase();
if (smalldatatype.charAt(0)=="i") 
{checkvalue=parseInt(value); if (value.indexOf(".")!=-1) {checkvalue=checkvalue+1}};
}
if ((parseFloat(min)==min && value.length<min) || (parseFloat(max)==max && value.length>max) || value!=checkvalue)
{if (alertbox!="") {alert(alertbox);} return false;}
else {return true;}
}
} 

function emptyvalidation(entered, alertbox)
{
// Emptyfield Validation by Henrik Petersen / NetKontoret
// Explained at www.echoecho.com/jsforms.htm
// Please do not remove this line and the two lines above.
with (entered)
{
if (value==null || value=="")
{if (alertbox!="") {alert(alertbox);} return false;}
else {return true;}
}
} 

function emptyvalidation_(entered)
{
 with (entered)
 {
	if (value==null || value=="")
	{
		return false;
	}
	else { return true; }
 }
} 

function zerovalidation(entered, alertbox)
{
// Emptyfield Validation by Henrik Petersen / NetKontoret
// Explained at www.echoecho.com/jsforms.htm
// Please do not remove this line and the two lines above.
with (entered)
{
if (value==0)
{if (alertbox!="") {alert(alertbox);} return false;}
else {return true;}
}
} 


function charsvalidation(entered, noofchars, alertbox)
{
with (entered)
{
if (value.length<noofchars)
{if (alertbox!="") {alert(alertbox);} return false;}
else {return true;}
}
} 

function dateformatvalidation(entered,alerta)
{
	day=entered.value.substr(0,2);
	month=entered.value.substr(3,2);
	year=entered.value.substr(6,4);
	if (intvalidation(year, 1900, 3000, alerta.concat(" Anul nu este corect!"))==false) return false;
	if (intvalidation(month, 1, 12, alerta.concat(" Luna nu este corecta!"))==false) return false;
	if (intvalidation(day, 1, 31, alerta.concat(" Ziua nu este corecta!"))==false) return false;
	//verify if the day in month is correct (eg: February)
	data = new Date(year, month-1);//, date, hour, minute, second) )
	data.setDate(day);
	if ( month!=data.getMonth()+1)
	{
		alert(alerta.concat(" Data nu este valida!"));
		return false;
	}
	return true;
}

function intvalidation( number, minval, maxval, errormessage)
{
	if ( number<minval || number>maxval ) {
		alert( errormessage);
		return false;
	};
	return true;
}
