function beforeSetDateValue(ref_field, target_field, date) {
  if (date!="") {
    var startDate=document.getElementById('date_from');
    var endDate=document.getElementById('date_to');

    if (target_field==endDate &&
        checkDate(getDateValue(startDate))==0 &&
        compareDates(getDateValue(startDate), date)>0) {
      date=getDateValue(endDate);
      alert("End Date should not be earlier than Start Date, please select again.");
    }
  }
  return date;
}

function afterSetDateValue(ref_field, target_field, date) {
  if (date!="") {
    var startDate=document.getElementById('date_from');
    var endDate=document.getElementById('date_to');
    if (target_field==startDate) {
      var endDateStart=dayOffset(date, 1);
      setRange("2", endDateStart, '');
    }    
  }
  else {
    setRange("2", "", "");
  }
}

function checkForm(form_target) 
{
    var frm = form_target.form;
    var startDate=document.getElementById('date_from');
    var endDate=document.getElementById('date_to');
    var nodates = document.getElementById('nodates');

	
  if (nodates.checked) {
	frm.submit();
  } else {
	

  if (checkDate(getDateValue(startDate))!=0) {
    alert("Please select a Start Date.");
return;
  }
  else if (checkDate(getDateValue(endDate))!=0) {
    alert("Please select an End Date.");
return;
  }
  else if (compareDates(getDateValue(startDate), getDateValue(endDate))>0) {
    alert("End Date should not be earlier than Start Date.");
return;
  }
  else {
frm.submit();
  }
}
}



//Autocomplete
	function lookup(inputString) {
	   
		if(inputString.length < 3) {
			// Hide the suggestion box.
			jQuery('#suggestions').hide();
		} else {
			jQuery.post("autocomplete.php", {queryString: ""+inputString+""}, function(data){
			   //alert(data);
				if(data.length >0) {
					jQuery('#suggestions').show();
					jQuery('#autoSuggestionsList').html(data);
				}
			});
		}
	} // lookup
	
	function fill(thisValue) {
		jQuery('#location').val(thisValue);
		setTimeout("jQuery('#suggestions').hide();", 200);
	}

function checkMail(mail)
{
	var filter  = /^([a-zA-Z0-9_\.\-])+\@(([a-zA-Z0-9\-])+\.)+([a-zA-Z0-9]{2,4})+$/;
	if (filter.test(mail)) return true;
	else return false;
}


function CheckBeforeSend(form_target) {
var frm = form_target.form;
for(var i=0; i< frm.length; i++){
	if(frm[i].type == 'text' && !frm[i].value){
		var empty = 1;
	}
	if(frm[i].type == 'text' && frm[i].name.search('email') != -1){
		if(!checkMail(frm[i].value)){
		var email = 1;
		}
	}
}
if(empty){
alert('Please fill all fields!'); 
return false;
}else if(email)
{
alert('Please enter valid e-mail address!'); 
return false;
}else{
form_target.click();
exit;
}
}


