function chkLength(field,fieldname,min,max) {
//Checks for field lendth is lower from max and greater than min
if (field.value.length > max || field.value.length < min) {
	alert(fieldname + " field must be minimum " + min + ", maksimum " + max + " characters!");
	field.focus();
	field.select();
	return false;
}
return true;
} //chkLength

function isExpiryDate(month,year) {
today = new Date();
expiry = new Date(year, month);
if (today.getTime() > expiry.getTime()){
	alert("Please Select a valid Expiry Date");
	return false;
	}
else{
	return true;
	}
} //isExpiryDate

function isText(field,fieldname) {
//Checks for if the user enters some text
if (( field.value=="" ) || ( field.value=="  " )  ||( field.value=="   " )  ||( field.value=="    " )  ||( field.value=="     " )) {
	alert(fieldname + " alanını boş bırakmayınız!");
	field.focus();
	field.select();
	return false;
}
return true;
} //isText

function isSelected(field,fieldname) {
//Checks for if the user select a value from selectbox
if (( field.value=="" )) {
	alert(fieldname + " alını seçilmelidir!");
	field.focus();
	return false;
}
return true;
} //isSelected

function isChecked(field,fieldname) {
//Checks for if the user select a value from radiobuttons
var blnChecked = false
for (x=0 ; x<field.length; x++) {
	if (field[x].checked) {blnChecked = true}
}
if (!blnChecked)(alert(fieldname + " alını seçilmelidir!"))
return blnChecked
} //isChecked

function isNumber(field,fieldname) {
//Checks for if the value of the field is numerical
var valid = "0123456789."
var ok = "yes";
var temp;
for (var i=0; i<field.value.length; i++) {
	temp = "" + field.value.substring(i, i+1);
	if (valid.indexOf(temp) == "-1" || valid.value == "" ) ok = "no";
}
if ((ok == "no") || (field.value=="")) {
	alert(fieldname + " field must be numerical!");
	field.value="0";
	field.focus();
	field.select();
	return false;
}
return true;
} // isNum

function isNum(){	
//Checks for enter pressed a number
//onKeyPress="return isNum()"
if ((event.keyCode < 58) && (event.keyCode > 47)) 
	event.returnValue = true
else
	event.returnValue = false;	
}

function isEmail(field,fieldname){
//Checks for if the value of the field is a valid email address
if (field.value.indexOf ('@',0) == -1 || field.value.indexOf ('.',0) == -1 || field.value == "")
{
	alert(fieldname + " alanı email adresi olmalıdır!");
	field.select();
	field.focus();
	return false;
}
return true;
} //isEmail

function isSame(field1,field2,fieldname1,fieldname2){
//Checks for if the value of the both field is same. For Password validation
if (field1.value != field2.value) {
	alert(fieldname1 + ", " + fieldname2 + " fields must be the same!");
	field1.focus();
	return false; 
}
return true;
} //isSame

function isDate(field,fieldname,seperator,format,focus){
//Checks for if the value of the field is a valid date
//field			text field of the date (not value of the text!)
//fieldname		text fields caption for alerting
//seperator		"/",".","," or smth. else
//format		2=mm dd yyyy 1=dd mm yyyy
//focus			1=focus the textbox after alert 2=not

var strDate
var blnIsDate
var intFirstSep
var intSecSep
var intday
var intMonth
var intYear
var Temp
var DaysArray = new Array(12)

for (var i = 1; i <= 12; i++) {
	DaysArray[i] = 31
	if (i==4 || i==6 || i==9 || i==11) {DaysArray[i] = 30}
	if (i==2) {DaysArray[i] = 29}
} 

strDate=field.value
blnIsDate = true

if (isNaN(field.value.substring(field.value.length-1,field.value.length))){
	blnIsDate = false	
}

intFirstSep = strDate.indexOf(seperator)
intSecSep = strDate.indexOf(seperator,intFirstSep+1)

intday=parseInt(strDate.substring(0,intFirstSep),10)
intMonth=parseInt(strDate.substring(intFirstSep+1,intSecSep),10)
intYear=parseInt(strDate.substring(intSecSep+1,10),10)

if ( isNaN(intday) || isNaN(intMonth) || isNaN(intYear)){blnIsDate = false}

if (format==2 ) {
	Temp=intday
	intday=intMonth
	intMonth=Temp
}

if (intday>31 || intday<1) {blnIsDate = false}
if (intMonth>12 || intMonth<1) {blnIsDate = false}
if (intYear>3000 || intYear<1000) {blnIsDate = false}

if (((intMonth==2) && (intday>(((intYear % 4 == 0) && ( (!(intYear % 100 == 0)) || (intYear % 400 == 0))) ? 29 : 28 ))) || (intday > DaysArray[intMonth])){
	blnIsDate= false
}

if (blnIsDate) {
		return true 
	} else {
		alert(fieldname + " field must be a valid date!");
		if (focus==1){
		field.select();
		field.focus();
	}
	return false;
}

}