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){
     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();
    return true;
 
}


function showAll()
{

  document.location = '?context=ir.access.jsp\x26ir_client_id=2656\x26ir_option=RNS_HEADLINES\x26transform=newsSearch\x26publicationGroup=RNS';


}


