// TRIM FUNCTION

function leftTrim(sString)
{
while (sString.substring(0,1) == ' ')
{
sString = sString.substring(1, sString.length);
}
return sString;
}

function rightTrim(sString)
{
while (sString.substring(sString.length-1, sString.length) == ' ')
{
sString = sString.substring(0,sString.length-1);
}
return sString;
}


function trimAll(sString)
{
while (sString.substring(0,1) == ' ')
{
sString = sString.substring(1, sString.length);
}
while (sString.substring(sString.length-1, sString.length) == ' ')
{
sString = sString.substring(0,sString.length-1);
}
return sString;
}

function TAreaLength(areaName,counter,limit)
{
if (areaName.value.length>limit)
areaName.value=areaName.value.substring(0,limit);
else
counter.value = limit - areaName.value.length;
}

function SecureWords(theValue) {

var myArray = new Array('select','insert','update','delete','*','=','"');

	for (var i=0;i<=myArray.length;i++) {
		theValue = theValue.toLowerCase().replace(myArray[i],'');				
	}	
	
return theValue; 	
}

function Newslet() {
if (trimAll(document.frm.EM.value) == '' || document.frm.EM.value == 'το email σας εδώ') {																																		  
	alert('Συμπληρώστε το email σας!');	
}
else {
	document.frm.Action.value = 'Newslet';	
	document.frm.submit();
}	
}


function Register() {
//if (trimAll(document.frm.mem_childname.value) == '' || trimAll(document.frm.mem_parname.value) == '' || trimAll(document.frm.mem_tel.value) == '' || trimAll(document.frm.mem_address.value) == '' || trimAll(document.frm.mem_city.value) == '' || trimAll(document.frm.mem_pcode.value) == '' || trimAll(document.frm.mem_em.value) == '' || trimAll(document.frm.mem_birthdate.value) == '' || 
//	document.frm.mem_childname.value == '* Όνοματεπώνυμο παιδιού' || document.frm.mem_parname.value == '* Όνοματεπώνυμο κηδεμόνα' || document.frm.mem_tel.value == '* Tηλέφωνο' || document.frm.mem_address.value == '* Διεύθυνση' || document.frm.mem_city.value == '* Πόλη' || document.frm.mem_pcode.value == '* Τ.Κ.' || document.frm.mem_em.value == '* email' || document.frm.mem_birthdate.value == '* ημ. γέννησης') {																																		  
if (trimAll(document.frm.mem_childname.value) == '' || trimAll(document.frm.mem_parname.value) == '' || trimAll(document.frm.mem_tel.value) == '' || trimAll(document.frm.mem_address.value) == '' || trimAll(document.frm.mem_city.value) == '' || trimAll(document.frm.mem_pcode.value) == '' || trimAll(document.frm.mem_birthdate.value) == '' || 
	document.frm.mem_childname.value == '* Όνοματεπώνυμο παιδιού' || document.frm.mem_parname.value == '* Όνοματεπώνυμο κηδεμόνα' || document.frm.mem_tel.value == '* Tηλέφωνο' || document.frm.mem_address.value == '* Διεύθυνση' || document.frm.mem_city.value == '* Πόλη' || document.frm.mem_pcode.value == '* Τ.Κ.' || document.frm.mem_birthdate.value == '* ημ. γέννησης') {																																		  
	alert('Συμπληρώστε όλα τα πεδία!');	
}
else {
	document.frm.Action.value = 'Register';	
	document.frm.submit();
}	
}

function Contact() {
if (trimAll(document.frm.FNAME.value) == '' || trimAll(document.frm.TEL.value) == '' || trimAll(document.frm.EM.value) == '' || trimAll(document.frm.COMMENTS.value) == '' || 
	document.frm.FNAME.value == 'Ονοματεπώνυμο' || document.frm.TEL.value == 'Tηλέφωνο' || document.frm.EM.value == 'Email' || document.frm.COMMENTS.value == 'Σχόλια') {																																		  
	alert('Συμπληρώστε όλα τα πεδία!');	
}
else {
	document.frm.Action.value = 'Contact';	
	document.frm.submit();
}	
}

// ------------------------------------------------------------------

function IsValidMail( str )
	{
		var	found = 0,
			nm = 0,
			ps = 0;

		for ( var i = 0; i < str.length - 1; i++ )	{
			if ( str.charAt( i ) == "@" )	{
				found++;
				ps = i;
				break;
 			}
 			if ( str.charAt( i ) == " " && nm )
	 			return ( false );
 			if ( !found && str.charAt( i ) != " " )
 				nm++;
		}
		if ( ( !nm ) || ( !found ) )
			return ( false );
		nm = 0;
		found = 0;

		for ( var i = ++ps; i < str.length - 1; i++ )	{
			if ( str.charAt( i ) == " " )
				return ( false );
			if ( str.charAt( i ) == "@" )
				return ( false );
			if ( str.charAt( i ) == "." )	{
				found++;
				break;
 			}
			nm++;
		}
		if ( nm && found )
			return ( true );
		return ( false );
	}	

	function checkEmail( aField )
	{
		if ( aField.value != "" )
			if ( !IsValidMail( aField.value ) ) {
				alert('Το Email σας δεν είναι έγκυρο...');
				aField.focus();
			}
	}

	function checkEmail_en( aField )
	{
		if ( aField.value != "" )
			if ( !IsValidMail( aField.value ) ) {
				alert('Your Email is not valid...');
				aField.focus();
			}
	}
	
	function IsNumeric( aField )
	{
		if ( aField.value != "" )	{
			for( var i=0; i<=aField.value.length-1; i++ ) {
				if ( ( aField.value.charAt( i ) < '0' ) || ( aField.value.charAt( i ) > '9' ) )	{
					alert( "Η τιμή που δώσατε δεν είναι αριθμητική!" );
					aField.focus();
					return false;
				}
			}
		}
		return true;
	}
	

// ------------------------------------------------------------------

function MM_preloadImages() { //v3.0
  var d=document; if(d.images){ if(!d.MM_p) d.MM_p=new Array();
    var i,j=d.MM_p.length,a=MM_preloadImages.arguments; for(i=0; i<a.length; i++)
    if (a[i].indexOf("#")!=0){ d.MM_p[j]=new Image; d.MM_p[j++].src=a[i];}}
}

function MM_swapImgRestore() { //v3.0
  var i,x,a=document.MM_sr; for(i=0;a&&i<a.length&&(x=a[i])&&x.oSrc;i++) x.src=x.oSrc;
}

function MM_findObj(n, d) { //v4.01
  var p,i,x;  if(!d) d=document; if((p=n.indexOf("?"))>0&&parent.frames.length) {
    d=parent.frames[n.substring(p+1)].document; n=n.substring(0,p);}
  if(!(x=d[n])&&d.all) x=d.all[n]; for (i=0;!x&&i<d.forms.length;i++) x=d.forms[i][n];
  for(i=0;!x&&d.layers&&i<d.layers.length;i++) x=MM_findObj(n,d.layers[i].document);
  if(!x && d.getElementById) x=d.getElementById(n); return x;
}

function MM_swapImage() { //v3.0
  var i,j=0,x,a=MM_swapImage.arguments; document.MM_sr=new Array; for(i=0;i<(a.length-2);i+=3)
   if ((x=MM_findObj(a[i]))!=null){document.MM_sr[j++]=x; if(!x.oSrc) x.oSrc=x.src; x.src=a[i+2];}
}
//-------------------------------------------------------------------------
