// JavaScript Document
function removeElement(elem, nr) {
	val = document.getElementById(elem).value
	document.getElementById(elem).value = val.slice(0, findIndex(val, "~", nr - 1)) + val.slice(findIndex(val, "~", nr))
}

function selLabel(obj) {
	if (obj) {
		return obj.options[obj.selectedIndex].innerHTML
	}
}

// The following 3 functions are used to manage hidden textboxes which include multiple selections devided by "~" character
function findIndex(str, cmpStr, nr) {
	var temp = 0;
	for (var i = 1; i <= nr; i++) {
		temp = temp + str.indexOf(cmpStr) + 1;
		str = str.slice(str.indexOf(cmpStr) + 1);
	}
	return temp;
}

function findOrder(str, cmpStr) {
	dt = str.split("~")
	for (i = 0; i < dt.length - 1; i++) {
		if (dt[i] == cmpStr) {
			return i + 1;
			break;
		}
	}
}

function removeElement(elem, nr) {
	val = document.getElementById(elem).value
	document.getElementById(elem).value = val.slice(0, findIndex(val, "~", nr - 1)) + val.slice(findIndex(val, "~", nr))
}

function isNumeric(sText)
{
   var ValidChars = "0123456789.,";
   var IsNumber=true;
   var Char;

 
   for (i = 0; i < sText.length && IsNumber == true; i++) 
      { 
      Char = sText.charAt(i); 
      if (ValidChars.indexOf(Char) == -1) 
         {
         IsNumber = false;
         }
      }
   return IsNumber;
   
   }

function isDate(dateStr) { // dateStr format dd/mm/yyyy

	var datePat = /^(\d{1,2})(\/|-)(\d{1,2})(\/|-)(\d{4})$/;
	var matchArray = dateStr.match(datePat); // is the format ok?
	
	if (matchArray == null) {
	return "";
	}
	
	month = matchArray[3]; // p@rse date into variables
	day = matchArray[1];
	year = matchArray[5];
	
	if ((month==4 || month==6 || month==9 || month==11) && day==31) {
		return "O "+month+"ος μήνας δεν έχει 31 ημέρες...";
	}
	
	if (month == 2) { // check for february 29th
		var isleap = (year % 4 == 0 && (year % 100 != 0 || year % 400 == 0));
		if (day > 29 || (day==29 && !isleap)) {
			return "Ο Φεβρουάριος του " + year + " δεν έχει " + day + " ημέρες...";
		}
	}
	return true; // date is valid
}
function isEmail(emailStr) {
	if (emailStr.indexOf("@") == -1 || emailStr.indexOf(".") == -1 || emailStr.lastIndexOf("@") > emailStr.lastIndexOf(".")) {
		return false;
	} else {
		return true;	
	}
}
//menu functions

	var menutimeout	= 450;
	var menuclosetimer	= 0;
	var ddmenuitem	= 0;	


function mouseOver(id){
	// cancel close timer
	mcancelclosetime();
	
	// close old layer
	if(ddmenuitem) ddmenuitem.style.visibility = 'hidden';
	// get new layer and show it
	ddmenuitem = document.getElementById(id);
	ddmenuitem.style.visibility = 'visible';

}

// close showed layer
function mclose()
{
	if(ddmenuitem) ddmenuitem.style.visibility = 'hidden';
}

// go close timer
function mouseOut()
{
	menuclosetimer = window.setTimeout(mclose, menutimeout);
}

// cancel close timer
function mcancelclosetime()
{
	if(menuclosetimer)
	{
		window.clearTimeout(menuclosetimer);
		menuclosetimer = null;
	}
}

//end of menu functions

function openCenterWin(url, width, height){
	var theTop=(screen.height/2)-(height/2);
	var theLeft=(screen.width/2)-(width/2);
	var features=
	'height='+height+',width='+width+',top='+theTop+',left='+theLeft+",scrollbars=yes, resizable=yes";
	theWin=window.open(url,'',features);
}

