function clearfield(arg)
{
	arg.value="";
	return true;
}	


function len_invalid(arg) // gia to search tou katalogos.inc.php
{
 if(arg.txtsearch.value.length < 2)
 {
  alert("Παρακαλούμε, εισάγετε τουλάχιστον 2 χαρακτήρες!!");
  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 textCounter(field, countfield, maxlimit) 
{
if (field.value.length > maxlimit) // if too long...trim it!
	field.value = field.value.substring(0, maxlimit);
// otherwise, update 'characters left' counter
else
	countfield.value = maxlimit - field.value.length;
}
   
 
 /**
 * DHTML resetting image button forms script. 
 */
function ResetForm(which){
var pass=true
var first=-1
if (document.images){
for (i=0;i<which.length;i++){
var tempobj=which.elements[i]
 if (tempobj.type=="text"){
  eval(tempobj.value="")
  if (first==-1) {first=i}
 }
 else if (tempobj.type=="checkbox") {
  eval(tempobj.checked=0)
  if (first==-1) {first=i}
 }
 else if (tempobj.type=="radio") {
  eval(tempobj.checked=0)
  if (first==-1) {first=i}
 }
 else if (tempobj.col!="") {
  eval(tempobj.value="")
  if (first==-1) {first=i}
 }
}
}
which.elements[first].focus()
return false
}


function openwindowgal(arg)
{
	var x=(screen.width-470)/2;
	var y=(screen.height-610)/2;
	window.open('popups/gallery.php?id='+arg+' ','popup','width=470,height=610,top='+y+',left='+x+',scrollbars=yes,location=no,toolbar=no');
}

function openmap()
{
	var x=(screen.width-310)/2;
	var y=(screen.height-340)/2;
	window.open('../popups/map.html','popup','width=310,height=340,top='+y+',left='+x+',scrollbars=no,location=no,toolbar=no');
}


function validation(arg)
{
		if(arg.txtname.value=="")
		{
			alert("S'il vous plait, inserez le nom!");
			arg.txtname.focus();
			return false;
		}
		if(arg.txtsurname.value=="")
		{
			alert("S'il vous plait, inserez le prenom!");
			arg.txtsurname.focus();
			return false;
		}
		if(arg.txtmail.value=="")
		{
			alert("S'il vous plait, entrer votre e-mail!");
			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("L' adresse e-mail n' est pas valide");
		   arg.txtmail.focus();
		   return false;
		}

		if (str.indexOf(at)==-1 || str.indexOf(at)==0 || str.indexOf(at)==lstr)
		{
		   alert("L' adresse e-mail n' est pas valide");
		   arg.txtmail.focus();
		   return false;
		}

		if (str.indexOf(dot)==-1 || str.indexOf(dot)==0 || str.indexOf(dot)==lstr)
		{
		    alert("L' adresse e-mail n' est pas valide");
		    arg.txtmail.focus();
			return false;
		}

		 if (str.indexOf(at,(lat+1))!=-1)
		 {
		    alert("L' adresse e-mail n' est pas valide");
			arg.txtmail.focus();
		    return false;
		 }

		 if (str.substring(lat-1,lat)==dot || str.substring(lat+1,lat+2)==dot)
		 {
		    alert("L' adresse e-mail n' est pas valide");
			arg.txtmail.focus();
		    return false;
		 }

		 if (str.indexOf(dot,(lat+2))==-1)
		 {
		    alert("L' adresse e-mail n' est pas valide");
			arg.txtmail.focus();
		    return false;
		 }
		
		 if (str.indexOf(" ")!=-1)
		 {
		    alert("L' adresse e-mail n' est pas valide");
			arg.txtmail.focus();
		    return false;
		 }

	return true;
 }


function allcheck_validation(arg)
{
	//if(!allvalidation(arg))
		//return false;
	
	if(!validation(arg))
		return false;
	if(arg.sel_country.value=="")
	{
		alert("S'il vous plait, Choisissez un pays!");
		arg.sel_country.focus();
		return false;
	}
	if(arg.sel_info.value=="")
	{
		alert("S'il vous plait, inserez un type de grue!");
		arg.sel_info.focus();
		return false;
	}
	if(arg.txtcity.value=="")
	{
		alert("S'il vous plait, Inserez la ville!");
		arg.txtcity.focus();
		return false;
	}
	if(arg.txtphone.value=="")
	{
		alert("S'il vous plait, Inserez le numero de telephone!");
		arg.txtphone.focus();
		return false;
	}
	if(arg.txtcompany.value=="")
	{
		alert("s'il vous plait, inserez la societe!");
		arg.txtcompany.focus();
		return false;
	}
	
	return true;	
}

function allvalidation(arg)
{
	for(var i=0;i<arg.length;i++)
		if(arg.elements[i].value=="")
		{
			alert("Tous les champs avec (*) sont exiges!");
			return false;
		}
	return true;	
}


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');
}
