var isEmptyMsg=": Δεν επιτρέπεται κενή τιμή γι' αυτό το πεδίο."
var isLetterMsg=": Το πεδίο αυτό πρέπει να περιέχει μόνο γράμματα."
var isDigitMsg=": Το πεδίο αυτό πρέπει να περιέχει μόνο ψηφία."
var isDigitStringMsg=": Το πεδίο αυτό πρέπει να περιέχει μόνο ψηφία."
var isLetterOrDigitMsg=": Το πεδίο αυτό πρέπει να περιέχει γράμματα ή ψηφία μόνο."
var isSignedIntegerMsg=": Το πεδίο αυτό πρέπει να περιέχει μόνο σημασμένο ακέραιο."
var isPositiveIntegerMsg=": Το πεδίο αυτό πρέπει να περιέχει μόνο θετικό ακέραιο."
var isNonnegativeIntegerMsg=": Το πεδίο αυτό πρέπει να περιέχει μόνο μη αρνητικό ακέραιο."
var isIntegerInRangeMsg=": Η τιμή που δώσατε δεν είναι έγκυρη."
var isHTMLStrMsg=": Το πεδίο αυτό περιέχει εντολές HTML ή είναι κενό."
var isFilenameOrURLMsg=": Το πεδίο αυτό πρέπει να περιέχει όνομα αρχείου ή URL."
var isFilenameMsg=": Το πεδίο αυτό πρέπει να περιέχει μόνο κάποιο όνομα αρχείου."
var isURLMsg=": Το πεδίο αυτό πρέπει να περιέχει κάποιο url."
var isNonEmptyEnGrStrMsg=": Το πεδίο αυτό δεν περιέχει τη σωστή τιμή."
var isEmailMsg=": Το πεδίο αυτό πρέπει να περιέχει e-mail διεύθυνση."
var isFloatMsg=": Το πεδίο αυτό πρέπει να περιέχει αριθμό."
var isDateStrMsg=": Το πεδίο αυτό πρέπει να περιέχει ορθή μορφή ημερομηνίας."
var customSplitMsg=" value must contain at more one seperator character (|)"
var isIntegerMsg=": Το πεδίο αυτό πρέπει να περιέχει ακέραιο."
var lengthMsg=": Το πεδίο αυτό περιέχει μεγάλο αριθμό χαρακτήρων."
var isTimeMsg=": Το πεδίο αυτό δεν περιέχει σωστή μορφή ώρας (π.χ. 03:00 μμ ή 15:00 )."
//-----------------------------------------------------------------------------------------------

String.prototype.trim = function()
{
    return this.replace(/(^\s*)|(\s*$)/g, "");
}

function LinkModalDialog(obj){

	var arr=showModalDialog("../files/list_simple.asp","","dialogHeight: 600px; dialogWidth: 450px; edge: Raised; center: Yes; resizable: Yes; status: Yes; scroll: Yes; help: No;");
	if (arr) obj.value=arr;	
	arr=null;
}

function LinkModalDialog_nl(obj){

	var arr=showModalDialog("../../files/list_simple.asp","","dialogHeight: 600px; dialogWidth: 450px; edge: Raised; center: Yes; resizable: Yes; status: Yes; scroll: Yes; help: No;");
	if (arr) obj.value=arr;	
	arr=null;
}

//Check Required Fields of a form 
function CheckRequiredFields(FormName,FormFields){
	var RFByte=0;
	var RFArray=FormFields.split(',')
	for (var i=0;i<RFArray.length;i++){
		if (trim(eval(FormName+'.'+RFArray[i]+'.value'))=='') {
			RFByte=1;
		}
	}
	if (RFByte==0){return true}else{return false}
}//End check	

//Replace Single Quotes with 2 single quotes
function ReplaceSingleQuotes(FormName){ 
	var FormLength = eval(FormName).length;
	for (var i=0;i<FormLength;i++){
		FormFieldValue=eval(FormName).elements[i].value;
		FormFieldValue=FormFieldValue.replace(/\'/g, "''");
		eval(FormName).elements[i].value=FormFieldValue;	
	}
}//ReplaceSingleQuotes


var tr_bgColor_selected	='7291D3'; // Defines the color of a selected <TR>
    function CheckSelectedRow(FieldName,tr_index)
    {
	var DeleteLength=FieldName.length
		if (DeleteLength>0){
		elementDescr=FieldName[tr_index]
		}
		else{
		elementDescr=FieldName
		}
		if (elementDescr.checked==true){
            eval('tr'+tr_index+'.style.backgroundColor=\''+tr_bgColor_selected+'\'');
        }else{
            eval('tr'+tr_index+'.style.backgroundColor=\'\'');
        }
    }
	
	function CheckAllRows(FieldName,ActionName)
    {
		var count=FieldName.length
		if	(count>0){
			if (ActionName=='SelectAll'){
				for (var i=0;i<count;i++){
					FieldName[i].checked=true;
			        eval('tr'+i+'.style.backgroundColor=\''+tr_bgColor_selected+'\'');
					}
			}
			if (ActionName=='DeSelectAll'){
			    for (var i=0;i<count;i++){
					FieldName[i].checked=false;
			        eval('tr'+i+'.style.backgroundColor=\'\'');
					}
		    }
		}else{
			if (ActionName=='SelectAll'){
				FieldName.checked=true
				tr0.style.backgroundColor=''+tr_bgColor_selected+''
			}
			if (ActionName=='DeSelectAll'){
				FieldName.checked=false;
			    tr0.style.backgroundColor=''
			}
		}    
    }

//+++++++++++++++++++Delete Selected Records++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
 function DeleteAllRecords(){
 	var count_length=document.DeleteAll.CheckDel.length  //Check if has checked any value
	var checked_Elements=0;
	if (count_length>0) {
		for (var i=0;i<count_length;i++){
			if (document.DeleteAll.CheckDel[i].checked==true){
				checked_Elements=1;
			}
		}
	}else{
		if (document.DeleteAll.CheckDel.checked==true){
				checked_Elements=1;
		}
	}//---
	if (checked_Elements==0){
		alert("Πρέπει να επιλέξετε τουλάχιστον μία εγγραφή")
		return;
	}
	var question = confirm("Είστε βέβαιος/η πως θέλετε να διαγράψετε τις επιλεγμένες εγγραφές;\rΟτιδήποτε σχετικό με αυτή την εγγραφή στη βάση θα διαγραφεί.")
	if (question == true) {
	document.DeleteAll.submit();
	}
 } //end
//=================================================================================================================================

//++++++++++++++++++++Add Edit Ecord++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
function AddEditRecord(FormName,id){
	document.UpdateForm.record_id.value=id
	document.UpdateForm.submit();
}//end PageNavigator
//=================================================================================================================================

//++++++++++++++++++++Quick Update++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
function UpdateRadio(up_column,up_value,id){
	document.UpdateRadioButton.record_id.value=id
	document.UpdateRadioButton.update_column.value=up_column
	document.UpdateRadioButton.update_value.value=up_value
	document.UpdateRadioButton.submit();
}//
//=================================================================================================================================

//+++++++++++++++++++++Navigation Function+++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
 function PageNavigator(FormName,page)
 	{
 		if (FormName=='forward')
		{
			document.NavigationForm.page.value=page
			document.NavigationForm.submit();
		}
	else if (FormName=='backward')
		{
			document.NavigationForm.page.value=page
			document.NavigationForm.submit();
		}
	else (FormName=='exact')
		{
			document.NavigationForm.page.value=page
			document.NavigationForm.submit();
		}	
 	}//
//=================================================================================================================================

//++++++++++++++++The Following Two Functions Create Headers in the list Page++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
function OrderFunction(order_type_value,order_by_value){
	document.OrderForm.order_by.value=order_by_value
	document.OrderForm.order_type.value=order_type_value
	document.OrderForm.submit()
}
function WriteHeaders(order_type_asp,order_by_asp,order_by_var,order_by_title){
	//Write Headers
	if (order_type_asp=='ASC' && order_by_asp==order_by_var){
		document.write("<a href=\"javascript:OrderFunction('DESC','"+order_by_var+"')\" class=\"tabhead\"><strong>"+order_by_title+"</strong></a>")
	}else if(order_type_asp=='DESC' && order_by_asp==order_by_var){
		document.write("<a href=\"javascript:OrderFunction('ASC','"+order_by_var+"')\" class=\"tabhead\"><strong>"+order_by_title+"</strong></a>")
	}else{
		document.write("<a href=\"javascript:OrderFunction('ASC','"+order_by_var+"')\" class=\"tabhead\"><strong>"+order_by_title+"</strong></a>")
	}
	//
	document.write("<br>")
	//Write common/images/
	if (order_type_asp=='ASC' && order_by_asp==order_by_var){
		document.write("<img src=\"../include/images/order_type_asc_checked.gif\" width=11 height=6 border=0>")
	}else{
		document.write("<a href=\"javascript:OrderFunction('ASC','"+order_by_var+"')\"><img src=\"../include/images/order_type_asc.gif\" width=11 height=6 border=0></a>")
	}
	document.write("&nbsp;")
	if (order_type_asp=='DESC' && order_by_asp==order_by_var){
		document.write("<img src=\"../include/images/order_type_desc_checked.gif\" width=11 height=6 border=0>")
	}else{
		document.write("<a href=\"javascript:OrderFunction('DESC','"+order_by_var+"')\"><img src=\"../include/images/order_type_desc.gif\" width=11 height=6 border=0></a>")
	}
}

var filetypes =  /[^*?"<>|\f\n\r]+\.(htm|html|jpg|jpeg|gif|pdf|doc|xls|txt|swf|bmp|pps|ppt|png|dwg)$/;
var urltypes = /\w+/;    
var htmltags =  /(<|>|&nbsp;|&lt;|&gt;)/;
var defaultEmptyOK = false;
var whitespace = " \t\n\r";
var decimalPointDelimiter = ",";
var timePat = /^(\d{1,2}):(\d{2})?(\s?(ΠΜ|πμ|ΜΜ|μμ))?$/;

function MM_displayStatusMsg(msgStr) {
  status=msgStr;
  document.MM_returnValue = true;
}

function SetFocus(theElement)	{
   theElement.focus(); 
   theElement.select();
}

function doThis(theElement, theElementName, theMsg)	{
   alert (theElementName + theMsg);
   theElement.focus(); 
   theElement.select();
}

// Check whether string s is empty.
function isEmpty(s)	{   
   return ((s == null) || (s.length == 0) || s=="");
}

// Returns true if character c is an English letter 
// (A .. Z, a..z).
//
// NOTE: Need i18n version to support European characters.
// This could be tricky due to different character
// sets and orderings for various languages and platforms.
function isLetter (c)	{   
	return ( ((c >= "a") && (c <= "z")) || ((c >= "A") && (c <= "Z")) )
}


// Returns true if character c is a digit 
// (0 .. 9).
function isDigit (c)	{   
   return ((c >= "0") && (c <= "9"));
}


// Returns true if string s is a digit string
// (0 .. 9).
function isDigitString(s)	{   
	if (isEmpty(s)) 
		if (isDigitString.arguments.length == 1) return defaultEmptyOK;
			else return (isDigitString.arguments[1] == true);
	itsOk=1;
	for (i = 0; i < s.length; i++) {
    var c = s.charAt(i);
    if (! ((c >= "0") && (c <= "9"))) 	itsOk=0;
	}
   return (itsOk==1);
}


// Returns true if character c is a letter or digit.
function isLetterOrDigit (c)	{   
   return (isLetter(c) || isDigit(c));
}


// isInteger (STRING s [, BOOLEAN emptyOK])
// 
// Returns true if all characters in string s are numbers.
//
// Accepts non-signed integers only. Does not accept floating 
// point, exponential notation, etc.
//
// We don't use parseInt because that would accept a string
// with trailing non-numeric characters.
//
// By default, returns defaultEmptyOK if s is empty.
// There is an optional second argument called emptyOK.
// emptyOK is used to override for a single function call
//      the default behavior which is specified globally by
//      defaultEmptyOK.
// If emptyOK is false (or any value other than true), 
//      the function will return false if s is empty.
// If emptyOK is true, the function will return true if s is empty.
//
// EXAMPLE FUNCTION CALL:     RESULT:
// isInteger ("5")            true 
// isInteger ("")             defaultEmptyOK
// isInteger ("-5")           false
// isInteger ("", true)       true
// isInteger ("", false)      false
// isInteger ("5", false)     true
function isInteger (s,a,b)	{
    var i;
    if (isEmpty(s)) 
       if (isInteger.arguments.length == 3) return defaultEmptyOK;
       else return (isInteger.arguments[3] == true);
    // Search through string's characters one by one
    // until we find a non-numeric character.
    // When we do, return false; if we don't, return true.
    for (i = 0; i < s.length; i++)	{   
        // Check that current character is number.
        var c = s.charAt(i);
        if (!isDigit(c)) return false;
    }

 		if (! isIntegerInRangeA(s,a,b)) return false;		

    // All characters are numbers.
    return true;
}


// isSignedInteger (STRING s [, BOOLEAN emptyOK])
// 
// Returns true if all characters are numbers; 
// first character is allowed to be + or - as well.
//
// Does not accept floating point, exponential notation, etc.
//
// We don't use parseInt because that would accept a string
// with trailing non-numeric characters.
//
// For explanation of optional argument emptyOK,
// see comments of function isInteger.
//
// EXAMPLE FUNCTION CALL:          RESULT:
// isSignedInteger ("5")           true 
// isSignedInteger ("")            defaultEmptyOK
// isSignedInteger ("-5")          true
// isSignedInteger ("+5")          true
// isSignedInteger ("", false)     false
// isSignedInteger ("", true)      true
function isSignedInteger (s,a,b)	{   
		if (isEmpty(s)) 
       if (isSignedInteger.arguments.length == 3) return defaultEmptyOK;
       else return (isSignedInteger.arguments[3] == true);

    else {
        var startPos = 0;
        var secondArg = defaultEmptyOK;

        if (isSignedInteger.arguments.length > 1)
            secondArg = isSignedInteger.arguments[1];

        // skip leading + or -
        if ( (s.charAt(0) == "-") || (s.charAt(0) == "+") )
           startPos = 1;    
		
		 		if (! isIntegerInRangeA(s,a,b)) return false;		
					 
        return (isInteger(s.substring(startPos, s.length), secondArg));
    }
}


// isPositiveInteger (STRING s [, BOOLEAN emptyOK])
// 
// Returns true if string s is an integer > 0.
//
// For explanation of optional argument emptyOK,
// see comments of function isInteger.
function isPositiveInteger (s,a,b)	{   
		var secondArg = defaultEmptyOK;
    if (isPositiveInteger.arguments.length > 3)
        secondArg = isPositiveInteger.arguments[3];

 		if (! isIntegerInRangeA(s,a,b)) return false;						
				
    // The next line is a bit byzantine.  What it means is:
    // a) s must be a signed integer, AND
    // b) one of the following must be true:
    //    i)  s is empty and we are supposed to return true for
    //        empty strings
    //    ii) this is a positive, not negative, number
    return (isSignedInteger(s, secondArg)
         && ( (isEmpty(s) && secondArg)  || (parseInt (s) > 0) ) );
}


// isNonnegativeInteger (STRING s [, BOOLEAN emptyOK])
// 
// Returns true if string s is an integer >= 0.
//
// For explanation of optional argument emptyOK,
// see comments of function isInteger.
function isNonnegativeInteger (s,a,b)	{   
		var secondArg = defaultEmptyOK;
    if (isNonnegativeInteger.arguments.length > 3)
        secondArg = isNonnegativeInteger.arguments[3];

 		if (! isIntegerInRangeA(s,a,b)) return false;						
				
    // The next line is a bit byzantine.  What it means is:
    // a) s must be a signed integer, AND
    // b) one of the following must be true:
    //    i)  s is empty and we are supposed to return true for
    //        empty strings
    //    ii) this is a number >= 0
    return (isSignedInteger(s, secondArg)
         && ( (isEmpty(s) && secondArg)  || (parseInt (s) >= 0) ) );
}


// isIntegerInRange (STRING s, INTEGER a, INTEGER b [, BOOLEAN emptyOK])
// 
// isIntegerInRange returns true if string s is an integer 
// within the range of integer arguments a and b, inclusive.
// 
// For explanation of optional argument emptyOK,
// see comments of function isInteger.
function isIntegerInRange (s, a, b)	{   
    // Catch non-integer strings to avoid creating a NaN below,
    // which isn't available on JavaScript 1.0 for Windows.
    if (!isInteger(s, false)) return false;
    // Now, explicitly change the type to integer via parseInt
    // so that the comparison code below will work both on 
    // JavaScript 1.2 (which typechecks in equality comparisons)
    // and JavaScript 1.1 and before (which doesn't).
    var num = parseInt (s);
    return ((num >= a) && (num <= b));
}

function isIntegerInRangeA (s, a, b)	{   
    var num = parseInt (s);
    return ((num >= a) && (num <= b));
}

// isHTMLStr (STRING s [, BOOLEAN emptyOK])
// 
// Returns true if string s is not HTML entry.
// This function suggests for (only) the strings validation.
function isHTMLStr(s) 
{   var reg1 = /(<|>)/;
    if (isEmpty(s)) 
       if (isHTMLStr.arguments.length == 1) return true;
       else {
			    if (isHTMLStr.arguments[1] == true) return false;
					else return true;
			 }
    // Search through string's characters 
    // until we find a reg1 character.
    // If we don't, return false; else, return true.
    if (! s.match(htmltags)) return false;
    return true;
}

// numOfChar (STRING s)
// 
// numOfChar returns the number of characters s1 that string s contains
// 
// For explanation of optional argument emptyOK,
// see comments of function isInteger.
function numOfChar(s,s1) 	{   
		num=0;
    for (i = 0; i < s.length; i++)	{   
        // Check that current character is equal to s1.
        var c = s.charAt(i);
        if (c==s1) num=num+1;
    }
    return num;
}


// isNonEmptyEnGrStr (STRING s [, BOOLEAN emptyOK])
// 
// Returns true if string s is not HTML entry.
// This function suggests for (only) the strings validation.
function isNonEmptyEnGrStr(s) 	{   
		var i;
    var reg1 = /(<|>)/;
    var engrCh = '|';
    if (isEmpty(s)) 
       if (isNonEmptyEnGrStr.arguments.length == 1) return defaultEmptyOK;
       else return (isNonEmptyEnGrStr.arguments[1] == true);

    if (reg1.test(s)) {
        return false;
    }
    else {
        if (numOfChar(s,engrCh)>1) return false;
    }
    return true;
}


// isFilenameOrURL (STRING s [, BOOLEAN emptyOK])
// 
// Returns true if string s is a suitable Filename or URL.
// Without HTML tags.
function isFilenameOrURL(s)	{
  isFilenameVar=true;
  isURLVar=true;
  if (isEmpty(s)) 
     if (isFilenameOrURL.arguments.length == 1) return defaultEmptyOK;
     else return (isFilenameOrURL.arguments[1] == true);

  if ( s.match(htmltags) )	{
     return false;
  }
  else	{
     if (! filetypes.test(s)) 	{
        isFilenameVar=false;
     }
     
     if ( s.indexOf("http://") != 0 ) 	{                           
         isURLVar=false;
     }
     else	{
        s1=s.substring(7);
        if ( ! s1.match(urltypes) )	{
           isURLVar=false;
        }
     }

     if ( ! (isFilenameVar || isURLVar) )	{
         return false; 
     }
   }
  return true;
}


// isFilename (STRING s [, BOOLEAN emptyOK])
// 
// Returns true if string s is a suitable Filename.
// Without HTML tags.
function isFilename(s)	{
  if (isEmpty(s)) 
     if (isFilename.arguments.length == 1) return defaultEmptyOK;
     else return (isFilename.arguments[1] == true);

  if ( s.match(htmltags) )	{
     return false;
  }
  else	{
     if (! filetypes.test(s)) 	{
        return false;
     }
  }
  return true;
}



// isURL (STRING s [, BOOLEAN emptyOK])
// 
// Returns true if string s is a suitable URL.
// Without HTML tags.
function isURL(s) 	{
  if (isEmpty(s)) 
     if (isURL.arguments.length == 1) return defaultEmptyOK;
     else return (isURL.arguments[1] == true);

  if ( s.indexOf("http://") != 0 ) 	{                           
      return false;
  }
  else	{
     s1=s.substring(7);
     if ( s1.match(htmltags) )	{
        return false;
     }
     else	{
        if ( ! s1.match(urltypes) )	{
           return false;
        }
     }
  }
  return true;
}


// theLTrim (STRING s)
// 
// Returns the string without the leading space/s.
function theLTrim(s) 	{
  while (1) {
    if (s.substring(0, 1) != " ")
      break;
    s = s.substring(1, s.length);
  }

  return s;
}


// theRTrim (STRING s)
// 
// Returns the string without the trailing space/s.
function theRTrim(s)	{

  while (1) {
    if (s.substring(s.length - 1, s.length) != " ")
      break;
    s = s.substring(0, s.length - 1);
  }

  return s;
}


// theTrim (STRING s)
// 
// Returns the string without the leading and the trailing space/s .
function theTrim(s)	{
  var tmpstr = theLTrim(s);
  return theRTrim(tmpstr);
}

// Returns true if string s is empty or 
// whitespace characters only.

function isWhitespace (s)	{  
		var i;
    // Is s empty?
    if (isEmpty(s)) return true;
    // Search through string's characters one by one
    // until we find a non-whitespace character.
    // When we do, return false; if we don't, return true.
    for (i = 0; i < s.length; i++)	{   
        // Check that current character isn't whitespace.
        var c = s.charAt(i);
        if (whitespace.indexOf(c) == -1) return false;
    }

    // All characters are whitespace.
    return true;
}


// isEmail (STRING s [, BOOLEAN emptyOK])
// 
// Email address must be of form a@b.c -- in other words:
// * there must be at least one character before the @
// * there must be at least one character before and after the .
// * the characters @ and . are both required
//
// For explanation of optional argument emptyOK,
// see comments of function isInteger.
function isEmail (s)	{   
		if (isEmpty(s)) 
       if (isEmail.arguments.length == 1) return defaultEmptyOK;
       else return (isEmail.arguments[1] == true);
   
    // is s whitespace?
    if (isWhitespace(s)) return false;   
    // there must be >= 1 character before @, so we
    // start looking at character position 1 
    // (i.e. second character)
    var i = 1;
    var sLength = s.length;
    // look for @
    while ((i < sLength) && (s.charAt(i) != "@"))	{ 
			i++
    }

    if ((i >= sLength) || (s.charAt(i) != "@")) return false;
    else i += 2;

    // look for .
    while ((i < sLength) && (s.charAt(i) != "."))	{ 
			i++
    }

    // there must be at least one character after the .
    if ((i >= sLength - 1) || (s.charAt(i) != ".")) return false;
    else return true;
}



// isFloat (STRING s [, BOOLEAN emptyOK])
// 
// True if string s is an unsigned floating point (real) number. 
//
// Also returns true for unsigned integers. If you wish
// to distinguish between integers and floating point numbers,
// first call isInteger, then call isFloat.
//
// Does not accept exponential notation.
//
// For explanation of optional argument emptyOK,
// see comments of function isInteger.
function isFloat (s,a,b)	{  
		var i;
    var seenDecimalPoint = false;
    if (isEmpty(s)) 
       if (isFloat.arguments.length == 3) return defaultEmptyOK;
       else return (isFloat.arguments[3] == true);

    if (s == decimalPointDelimiter) return false;
    // Search through string's characters one by one
    // until we find a non-numeric character.
    // When we do, return false; if we don't, return true.
    for (i = 0; i < s.length; i++)	{   
        // Check that current character is number.
        var c = s.charAt(i);

        if ((c == decimalPointDelimiter) && !seenDecimalPoint) seenDecimalPoint = true;
        else if (!isDigit(c)) return false;
    }

 		if (! isFloatInRange(s,a,b)) return false;	
    // All characters are numbers.
    return true;
}


// isFloatInRange (STRING s, STRING a, STRING b)
// 
// isFloatInRange returns true if string s is a float 
// within the range of float arguments a and b, inclusive.
function isFloatInRange (s, a, b)
{
    var num = parseFloat (s);
    var num1 = parseFloat (a);
    var num2 = parseFloat (b);				
    return ((num >= num1) && (num <= num2));
}


// isDateStr (STRING s [, BOOLEAN emptyOK])
// 
// Date be of form dd/mm/yyyy -- in other words:
// * there must be at least one integer before the first / betweeen 1-31
// * there must be at least one integer (1-12) before and after the second /
// * there must be at least two integers after the third /
// * the character / required
//
// For explanation of optional argument emptyOK,
// see comments of function isInteger.
function isDateStr (datestr)	{
    if (isEmpty(datestr)) 
        if (isDateStr.arguments.length == 1) return defaultEmptyOK;
        else return (isDateStr.arguments[1] == true);

    var tmp  = false;
    var reg = /[^0-9]/;
    var datelen = datestr.length;
    var pos1 = datestr.indexOf("/");
    var pos2 = datestr.lastIndexOf("/");
    var tmpday = datestr.substr(0,pos1);
    var tmpmonth= datestr.substr(pos1+1,pos2-pos1-1);
    var tmpyear= datestr.substr(pos2+1,datelen-pos2-1);
    if ((((tmpmonth==4)||(tmpmonth==6)||(tmpmonth==9)||(tmpmonth==11))&&
       ((tmpday>30)||(tmpday<1)))||
       (((tmpmonth==1)||(tmpmonth==3)||(tmpmonth==5)||(tmpmonth==7)||(tmpmonth==8)||(tmpmonth==10)||(tmpmonth==12))&&
       ((tmpday>31)||(tmpday<1)))||
       ((tmpmonth==2)&&((tmpday>28)||(tmpday<1))&&((tmpyear%4)!=0))||
       ((tmpmonth==2)&&((tmpday>29)||(tmpday<1))&&((tmpyear%4)==0))||
       ((tmpmonth>12)||(tmpmonth<1)||(tmpday>31)||(tmpday<1))||
       (tmpyear<1900)||(tmpyear.length!=4) ||
       ((String(tmpday).search(reg)!= -1) ||(String(tmpmonth).search(reg)!= -1) || (String(tmpyear).search(reg)!= -1))
    )
    {
        tmp=false;
    }
    else
    {
        tmp=true;
    }
    return tmp;
}


// makeArray (INT IntarrSize)
// 
// Create an array object.
// intArraySize is the length of the array created.
function makeArray(IntarrSize) 	{
  for (var n = 0; n < IntarrSize; n++)
    this[n] = "";
  return this;
}


// customSplit (STRING strvalue, STRING separator, STRING arrayName [, BOOLEAN emptyOK])
// 
// Split the argument string into an array of strings.
// strValue is the string to be splited with separator as the delimeter
// After spliting, array of strings are stored in new "Array" object, strArrayName. 
function customSplit(strvalue, separator, arrayName) {
  var n = 0;

  if (separator.length != 0) {
    while (strvalue.indexOf(separator) != -1) {
      eval("arr"+n+" = strvalue.substring(0, strvalue.indexOf(separator));");
      strvalue = strvalue.substring(strvalue.indexOf(separator)+separator.length,
          strvalue.length+1);
      n++;
    }
    eval("arr" + n + " = strvalue;");
    arraySize = n+1;
  }
  else {
    for (var x = 0; x < strvalue.length; x++) {
      eval("arr"+n+" = \"" + strvalue.substring(x, x+1) + "\";");
      n++;
    }
    arraySize = n;
  }

  eval(arrayName + " = new makeArray(arraySize);");

  for (var i = 0; i < arraySize; i++)
    eval(arrayName + "[" + i + "] = arr" + i + ";");

  return arraySize;
}

function openPopUpWindow(theURL,winName,features) { 
   window.open(theURL,winName,features);
}

function createSlc(targetSlc, basedOnValue, emptyTitle) {
	var x,i,j;
	for (x = targetSlc.options.length; x >= 0; x--) {
		targetSlc.options[x] = null; 	}
	if (categories != null) {
		j=0
		for (i = 0; i < categories.length; i++) {
			if (categories[i][2] == basedOnValue ) {
				if (categories[i][1] != null) {
					targetSlc.options[j] = new Option(categories[i][1]); }
				if (categories[i][0] != null) {
					targetSlc.options[j].value = categories[i][0];  }
				j++;
			}
		}
		if (j==0) {
			targetSlc.options[j] = new Option(emptyTitle);
			targetSlc.options[j].value = '-1'; 
		}
	}
}
	
	function selectValueSlc(targetSlc, selectedValue) {
		var z; var found;
		found=0;
		for (z = 0; z < targetSlc.options.length; z++) {
			if (parseInt(targetSlc.options[z].value)  == parseInt(selectedValue) ) {	
				found=1;		
				targetSlc.options[z].selected = true;
			}		
		}		
		if (found==0) {	
				targetSlc.options[0].selected = true;
		}				
	}


// isTime (STRING s, type [, BOOLEAN emptyOK])
// 
// Time string must be of form HH:MM ΠΜ/ΜΜ -- in other words:
// * there must be at least one character before the : (maximum two characters)
// * there must be at least one character after the : (maximum two characters)
// * the character : required
// * the AM/PM is optional
// type: the type of hour: 
// S = Standard Time (hour must be between 1 and 12) - You must specify AM or PM,
// M = Military Time (hour must be between 0 and 23) - You can't specify AM or PM for military time
//
// For explanation of optional argument emptyOK,
// see comments of function isInteger.
function isTime(s,type) {
	if (isEmpty(s)) 
  	if (isTime.arguments.length == 2) return defaultEmptyOK;
    else return (isTime.arguments[2] == true);

	var matchArray = s.match(timePat);
	if (matchArray == null) return false;
	hour = matchArray[1];
	minute = matchArray[2];
	ampm = matchArray[4];

	if (ampm=="") ampm = null;

	if (hour < 0  || hour > 23) return false;
	
	if (hour <= 12 && ampm == null && type == 'S') return false;

	if  (hour > 12 && ampm != null) return false;

	if (minute<0 || minute > 59) return false;

	return true;
}
function checkyear(datestr)
{
	var tmp  = 0;
	var reg = /[^0-9]/;
	if ((datestr<1972) || (datestr.length!=4) || (String(datestr).search(reg)!= -1))
	{ tmp=0; }
	else
	{ tmp=1; }
	return tmp;
}


function checkForIlegalChar(varCheck) {
		var ilegalsChar = "*?:;:αβγδεζηθικλμνξοπρστυφχψωςάέήίόύώϊϋΑΒΓΔΕΖΗΘΙΚΛΜΝΞΟΠΡΣΤΥΦΧΨΩ’ΈΉΊΌΎΏΪΫ" + String.fromCharCode(32,34,39,47,92,96)
		var i, j;
		var ONEcharforCheck, ONEilegalChar
		var ALLilegalChar = "";
		for (i=0;i<varCheck.length;i++) {
			ONEcharforCheck = varCheck.substr(i, 1);
			for (j=0;j<ilegalsChar.length;j++) {
				ONEilegalChar = ilegalsChar.substr(j, 1);
				if (ONEcharforCheck==ONEilegalChar) {
					ALLilegalChar = ALLilegalChar + ONEcharforCheck;
					break;
				}
			}
		}
		if (ALLilegalChar!=""){
			alert("Υπάρχουν χαρακτήρες στο όνομα που δεν είναι αποδεκτοί.\n[ " + ALLilegalChar + " ]");
			return false;
		}else{
			return true;
		}
}


function checkFileExtension(fileNamestr, objType){
	var isAllowed=true;
	if (objType=='file') {
		isAllowed=false;
		var AllowedFileTypes =	new Array('pps','gif','jpg','jpeg','png','swf','mid','wav','mp3','wmv','xls','csv','msg','eml','ppt','doc','txt','rar','zip','arj','htm','html','mht','shtml','css','pdf','bmp');
		var fileExt, fileExtArray;
		var i;
		fileExtArray = fileNamestr.split('.');
		fileExt = fileExtArray[fileExtArray.length-1].toLowerCase();
		for (i=0; i<AllowedFileTypes.length; i++) {
			if (AllowedFileTypes[i]==fileExt) {
				isAllowed=true;
				break;
			}
		}
	}

	if (!isAllowed) {
		alert("Δεν μπορεί το αρχείο στο Server να έχει τη κατάληξη :" + fileExt);
	}
	return isAllowed;
}