function formatDate(theDay,theMonth,theYear,theFormat,theSpacer){
  var theNumber = new Array(theDay,theMonth,theYear)
  theFormat = theFormat.split(theSpacer)
  for(i=0;i <= 2;i++){
    if(theFormat[i].length == 2 && theNumber[i].length == 1){
      theNumber[i] = '0' + theNumber[i]
    } else if(theFormat[i].length == 4){
      if(theNumber[i].length == 1){
        theNumber[i] = '200' + theNumber[i]
      } else if(theNumber[i].length == 2){
        theNumber[i] = '20' + theNumber[i]
      } else if(theNumber[i].length == 3){
        theNumber[i] = '2' + theNumber[i]
      }
    }
  }
  return theNumber[0] + theSpacer + theNumber[1] + theSpacer + theNumber[2]
}

function dummyValues()
{
  var dateArray = new Array(document.search_form.from_day,document.search_form.from_month, document.search_form.from_year,document.search_form.to_day,document.search_form.to_month ,document.search_form.to_year);
  for (var i=0; i < dateArray.length; i++)
  {
    if (dateArray[i].value=="")
    dateArray[i].selectedIndex=0;

  }

}

function text_validate(){

 var period1 = document.search_form.period_input.options[document.search_form.period_input.options.selectedIndex].value;
 var fromDay = document.search_form.from_day.value;
 var fromMonth = document.search_form.from_month.value ;
 var fromYear = document.search_form.from_year.value;
 var toDay = document.search_form.to_day.value;
 var toMonth = document.search_form.to_month.value;
 var toYear = document.search_form.to_year.value;

 var startDate = new Date();
 var endDate = new Date();
 var localDate = new Date();


 startDate.setDate(fromDay);
 startDate.setMonth(fromMonth-1);
 startDate.setFullYear(fromYear);

 endDate.setDate (toDay);
 endDate.setMonth(toMonth-1);
 endDate.setFullYear(toYear);

 if (document.search_form.keyword_input.value == '' || document.search_form.keyword_input.value == 'Enter Keyword'){
     alert('Please enter your keyword');
     document.search_form.keyword_input.focus();
     return false;
 }

 if (document.search_form.time[0].checked){
     if (period1 == '-'){
         alert('Please select a time period from the list or enter dates in the space provided')
         document.search_form.period_input.focus();
         return false;
     }
 }
 
 
 
 else if (document.search_form.time[1].checked){
      
  var frm_date = document.search_form.from_day;
  var frm_month = document.search_form.from_month;
  var frm_year = document.search_form.from_year;
  var to_adate = document.search_form.to_day;
  var to_amonth = document.search_form.to_month;
  var to_ayear = document.search_form.to_year;
  
  
     
     frm_dt = frm_date.options[frm_date.options.selectedIndex].value;
     frm_mth = frm_month.options[frm_month.options.selectedIndex].value;
     frm_yr = frm_year.options[frm_year.options.selectedIndex].value;
     to_dt = to_adate.options[to_adate.options.selectedIndex].value;
     to_mth = to_amonth.options[to_amonth.options.selectedIndex].value;
     to_yr = to_ayear.options[to_ayear.options.selectedIndex].value;
     
     if ( (frm_dt == " ") || (frm_mth == " ") || (frm_yr == " ") || (to_dt == " ") || (to_mth == " ") || (to_yr == " "))
     {
         alert ("Please check the dates selected.");
         return false;
     } 
 
 
     if (startDate > endDate){
         alert('Please check the dates selected. Start date cannot be after end date');
         return false;
     }
     if (endDate > localDate){
        alert('Please check the dates selected. End date cannot be in the future');
        return false;
    }
 }

 document.search_form.submit ()
}
