function clearfield(arg)
{
	arg.value="";
	return true;
}	


function len_invalid(arg) // gia to search tou katalogos.inc.php
{
 if(arg.txtsearch.value.length<3)
 {
  alert("Please, use more than 2 characters!!");
  return false;
  }
  else
   return true;
 }


function selected_item(elem, elem_value,max_options)
{
	var i;
		for(i=0;i<max_options;i++)
		{
			if(elem.options[i].value==elem_value)
				elem.options[i].selected=true;
		}// end for			
}

function CountWords (this_field, show_word_count, show_char_count) {
if (show_word_count == null) {
show_word_count = true;
}
if (show_char_count == null) {
show_char_count = false;
}
var char_count = this_field.value.length;
var fullStr = this_field.value + " ";
var initial_whitespace_rExp = /^[^A-Za-z0-9]+/gi;
var left_trimmedStr = fullStr.replace(initial_whitespace_rExp, "");
var non_alphanumerics_rExp = rExp = /[^A-Za-z0-9]+/gi;
var cleanedStr = left_trimmedStr.replace(non_alphanumerics_rExp, " ");
var splitString = cleanedStr.split(" ");
var word_count = splitString.length -1;
if (fullStr.length <2) {
word_count = 0;
}
if (word_count == 1) {
wordOrWords = " word";
}
else {
wordOrWords = " words";
}
if (char_count == 1) {
charOrChars = " character";
} else {
charOrChars = " characters";
}
if (show_word_count & show_char_count) {
alert ("Word Count:\n" + "    " + word_count + wordOrWords + "\n" + "    " + char_count + charOrChars);
}
else {
if (show_word_count) {
alert ("Word Count:  " + word_count + wordOrWords);
}
else {
if (show_char_count) {
alert ("Character Count:  " + char_count + charOrChars);
      }
   }
}
if (show_char_count)
	return char_count;
if (show_word_count)	
	return word_count;
}

function openwindow(arg,w,h)
{
	var x=(screen.width-w)/2;
	var y=(screen.height-h)/2;
	window.open(arg,'popup','width='+w+',height='+h+',top='+y+',left='+x+',scrollbars=no,location=no,toolbar=no');
}

function openknow(arg1)
{
	var x=(screen.width-366)/2;
	var y=(screen.height-449)/2;
	window.open('../../../knowledge_base.php?id='+arg1+' ','popup','width=366,height=449,top='+y+',left='+x+',scrollbars=yes,location=no,toolbar=no');
}


function validation(arg)
{
	for(var i=0;i<arg.length;i++)
		if(arg.elements[i].value=="")
		{
			alert("You must fill all the fields!");
			return false;
		}
		if(!emailvalidation(arg))
			return false;
	return true;	
}

function bookvalidation(arg)
{
	if(arg.txtname.value=="" || arg.txtsurname.value=="" || arg.txtarea.value=="")
	{
		alert("Θα πρέπει να συμπληρώσετε τα πεδία με αστερίσκο ( * )!");
		return false;
	}
	if(!emailvalidation(arg))
		return false;
	return true;	
}

function group_bookvalidation(arg)
{
	if(arg.txtname.value=="" || arg.txtsurname.value=="" || arg.txtarea.value=="" || arg.txtpersons.value=="" || arg.txtrooms.value=="")
	{
		alert("Θα πρέπει να συμπληρώσετε τα πεδία με αστερίσκο ( * )!");
		return false;
	}
	if(!emailvalidation(arg))
		return false;
	return true;	
}

function emailvalidation(arg)
{
	if(arg.txtmail.value=="")
	{
		alert("Please, enter your email!");
		arg.txtmail.focus();
		return false;
	}

	var str=arg.txtmail.value;
	var at="@";
	var dot=".";
	var lat=str.indexOf(at);
	var lstr=str.length;
	var ldot=str.indexOf(dot);
	if (str.indexOf(at)==-1)
	{
		 alert("Invalid E-mail ID");
		 arg.txtmail.focus();
		 return false;
	}

	if (str.indexOf(at)==-1 || str.indexOf(at)==0 || str.indexOf(at)==lstr)
	{
		alert("Invalid E-mail ID");
		arg.txtmail.focus();
		return false;
	}

	if (str.indexOf(dot)==-1 || str.indexOf(dot)==0 || str.indexOf(dot)==lstr)
	{
		alert("Invalid E-mail ID");
		arg.txtmail.focus();
		return false;
	}

	if (str.indexOf(at,(lat+1))!=-1)
	{
		alert("Invalid E-mail ID");
		arg.txtmail.focus();
		return false;
	}

	if (str.substring(lat-1,lat)==dot || str.substring(lat+1,lat+2)==dot)
	{
		alert("Invalid E-mail ID");
		arg.txtmail.focus();
		return false;
	}

	if (str.indexOf(dot,(lat+2))==-1)
	{
		alert("Invalid E-mail ID");
		arg.txtmail.focus();
		return false;
	}
		
	if (str.indexOf(" ")!=-1)
	{
		alert("Invalid E-mail ID");
		arg.txtmail.focus();
		return false;
	}

	return true;
}