function goto_field(field)
{
		field.focus();
		field.blur();
		field.select(); 
}

function check_null(this_field)
{
	if (this_field.value=="") return true;
	else  return false;
}

function LeapYear(intYear) {
	if (intYear % 100 == 0) 
			{
					if (intYear % 400 == 0) { return true; }
			}
	else {
					if ((intYear % 4) == 0) { return true; }
			  }
	return false;
}

var day;
var month;
var year;
var error;
function CheckValidDate(THISDATE) 
{
			  var correct = true;
	   		 var elems = THISDATE.value.split("/");
			 
			 // check if date is correctly formatted
			 correct = (elems.length == 3); // should be three components
			 if (correct) 
			 {
					   day = parseInt(elems[0]);
					   month = parseInt(elems[1]);
					   year = parseInt(elems[2]);
					   // Basic check
					   correct = !isNaN(month) && (month > 0) && (month < 13) &&
							!isNaN(day) && (day > 0) && (day < 32) &&
							!isNaN(year) && (elems[2].length == 4);
						if (correct) // more checks
						{
									// 30 or 31 days
								/*	if ((month == 1 || month == 3 || month == 5 || month == 7 || month == 8 || month == 10 || month == 12) && (day > 31 || day < 1)) 
									{
											return false;
									}
								Not needed because 31 days limit has been checked above
								*/ 
									if ((month == 4 || month == 6 || month == 9 || month == 11) && (day > 30 || day < 1)) 
									{
											error="Ο μήνας αυτός έχει 30 μέρες";
											return false;
									}
									// February
									if (month == 2) 
									{
											if (LeapYear(year) == true) 
											{
												if (day > 29) 	return false;
											}
											else 
											{
												if (day> 28) {error="Το έτος που εισάγατε δεν είναι δίσεκτο";return false;}
											}
								    } 
						 } else return false ;// more checks
			 } else return false;
			 return correct;
}

function CheckDate(THISDATE,startdate,enddate) 
{
	error='Η ημερομηνία πρέπει να είναι της μορφής DD/MM/YYYY π.χ. 15/8/2002';
	 if (THISDATE.value!="")
	  {		
	  		 correct=CheckValidDate(THISDATE) ;
			 if  (correct)  // check if : startdate< date entered < enddate
			 {
			 			this_date=new Date(year,month-1,day);
						var valid = true;
						 if (startdate!="-")
						 {
								 var elems_start=startdate.split("/");
								 var day_start = parseInt(elems_start[0]);
								 var month_start = parseInt(elems_start[1]);
								 var year_start= parseInt(elems_start[2]);
								 start_date=new Date(year_start,month_start-1,day_start);
								 valid=this_date>=start_date;
								 if (!valid) error='Η ημερομηνία πρέπει να είναι μεγαλύτερη από την '+startdate;
						}
						if (enddate!="-" && valid)
						{			 
								 var elems_end=enddate.split("/");
								 var day_end = parseInt(elems_end[0]);
								 var month_end = parseInt(elems_end[1]);
								 var year_end= parseInt(elems_end[2]);
								 end_date=new Date(year_end,month_end-1,day_end);
								 valid=this_date<=end_date;
								 if (!valid) error='Η ημερομηνία πρέπει να είναι μικρότερη από την '+enddate;
						}		 
			 }
			if (!correct || !valid)
			{
					alert(error);
					  // all three are needed due to the explorer bug
					THISDATE.value="";
					goto_field(THISDATE);
			}
 	  }  // if (THISDATE.value!="")
	 return true;
}

function check_float(this_number,no_of_dec)
{
	var error = false;
	var	value=this_number.value;
	
	if (!check_null(this_number))
	{
		space_exists=this_number.value.indexOf(" ");
		if (space_exists>=0) error=true;
		else
		{
				exists=this_number.value.indexOf(",");
				if (exists>=0) value=this_number.value.replace(",",".");
				temp=value;
				elems = value.split(".");
				error=(elems.length > 2); // should be at most 2 components	
				if (elems.length==2) (error=(elems[1].length>no_of_dec)); // only  no_of_dec decimal digits are allowed
				if (isNaN(value.replace(",",".")) || value.indexOf("-")>=0) {error=true;};  // επιτρέπονται μόνο θετικοί αριθμοί
		}
		if (error) {
									alert('You must an enter a positive number with '+ no_of_dec+' decimal digits and no thousand separator e.g. like 35.55' );
									this_number.value="";
									goto_field(this_number);
						}
		else this_number.value=temp;
	}
}

function num_round(num, d) { 
           n = Math.pow(10, !d ? 2 : d);
           return Math.round(num*n) / n;
   }

function check_submit_form()
{

}

function CheckFieldSize(this_field,no_of_chars)
{
		size=parseInt(no_of_chars)
		if (this_field.value.length > size) {
			alert('Το μέγιστο αποδεκτό μέγεθος κειμένου είναι ' + size + ' χαρακτήρες. Θα περικοπούν οι τελευταίοι ' + (this_field.value.length - size) + ' χαρακτήρες.');
			this_field.value = this_field.value.substring(0, size);
		};
}

/* Functions for handling user actions */

var  submit_clicked
function Submit_form(action_form)
{
	if  (submit_clicked) 
			{
				//	alert('Παρακαλούμε μην κάνετε συνεχόμενα Click... Πατήστε ΟΚ και περιμένετε να φορτώσει η σελίδα. ');
			}
   else  
   			{
				submit_clicked=true;		
				actionform.submit();
			}
}


function add_rows(field)
{
	if (check_null(field) ) field.value=0;
	field.value=parseInt(field.value) + 3;

    actionform = document.selectActionForm;
	actionform._action.value = "goto_action"; 
	actionform.target_page.value = actionform.origin_page.value;
	Submit_form(actionform);
}
  
  function init() {
	actionform = document.selectActionForm;
	actionform.target_page.value = actionform.origin_page.value;
	InsertDefault();	
	submit_clicked=false;
  }    

function check_afm(this_field) {
value1=this_field.value;
length1=value1.length;
temp=value1;
a=1;

for (i=0; i<length1; i+=1) {
        if (value1.charAt(i)==0 || value1.charAt(i)==1 || value1.charAt(i)==2 ||
value1.charAt(i)==3 || value1.charAt(i)==4 || value1.charAt(i)==5 ||
value1.charAt(i)==6 || value1.charAt(i)==7 || value1.charAt(i)==8 ||
value1.charAt(i)==9)
                a=1;
        else {
                a=0;
                break ;}
}
if (a==0) {alert("Το ΑΦΜ πρέπει να έχει μόνο αριθμητικούς χαρακτήρες");
return false;}
if ((length1==9) && (value1.charAt(0)==0)) {
        temp=temp.substring(1,9);
         }
if ((temp.length == 8) && (((temp.substring(0,1) *128 + temp.substring(1,2)
*64 + temp.substring(2,3) *32 + temp.substring(3,4) *16 +temp.substring(4,5)
*8 + temp.substring(5,6) *4 +  temp.substring(6,7) *2) % 11) ==
temp.substring(7,8))) {

        document.updateuser.usr_afm.value=temp;
        return true;}

alert("Το ΑΦΜ δεν είναι έγκυρο, παρακαλούμε διορθώστε το");
return false;
}

