﻿// JScript File



function OpenTimeZoneWindow()
{
   
    win = window.open('TimeZone.aspx', 'TimeZoneWindow_OSI', 'resizable=0,width=445,height=460');
    win.focus();
    return false;
}

function UpdateTimeZone()
{
   
    __doPostBack('TimeZoneLink','');
}

function OpenHelpWindow()
{
    
    win = window.open('CenterOfBoxHelp.htm', 'MainHelpWindow_OSI', 'resizable=1,scrollbars=1,width=450,height=400');
    win.focus();    
    return false;
}

function OpenTermsOfUseWindow()
{
   
    win = window.open('TermsOfUse.htm', 'TermsOfUseWindow_OSI', 'resizable=1,scrollbars=1,width=450,height=425');
    win.focus();
    return false;
}

var DHTML = (document.getElementById || document.all || document.layers);
function getObj(name)
{
      
    if (document.getElementById)
    {
        this.obj = document.getElementById(name);
        this.style = document.getElementById(name).style;
    }
    else if (document.all)
    {
        this.obj = document.all[name];
        this.style = document.all[name].style;
    }
    else if (document.layers)
    {
        this.obj = document.layers[name];
        this.style = document.layers[name];
    }
}




function validate()
{
    //force the user to select at least one report
   
    var cob = document.Form1.cbList_0;
    var kop = document.Form1.cbList_1;
 
    var isValid = true;
    var typeValidator = new getObj('TypeValidator');

    if(!cob.checked && !kop.checked)
    {
        typeValidator.obj.innerHTML = '(Select a calculation)';
        typeValidator.style.visibility = 'visible';
        isValid = false;
    }
    else
    {
        typeValidator.style.visibility = 'hidden';
    }
   //inputs to validate
    var startDate = document.Form1.StartDate;
    var endDate = document.Form1.EndDate;

    //validators
    var startValidator = new getObj('StartValidator');
    var endValidator = new getObj('EndValidator');

    //necessary numbers
    var start = Date.parse(startDate.value);
    var end = Date.parse(endDate.value);
    if(isNaN(start))
    {
        if(startDate.value == '')
            startValidator.obj.innerHTML = '(Required)';
        else
        startValidator.obj.innerHTML = '(Invalid Date Format)';
        startValidator.style.visibility = 'visible';
        isValid = false;
    }
    else
    {
        startValidator.style.visibility = 'hidden';
    }

    if(isNaN(end))
    {
        if(endDate.value == '')
            endValidator.obj.innerHTML = '(Required)';
        else
          endValidator.obj.innerHTML = '(Invalid Date Format)';
          endValidator.style.visibility = 'visible';
          isValid = false;
    }
    else
    {
               
        endValidator.style.visibility = 'hidden';
    }

   
    //since both dates were given
    if( isValid)
    {
        if(end < start)
        {
            startValidator.obj.innerHTML = '(Start Date > End Date)';
            startValidator.style.visibility = 'visible';
            isValid = false;
        }
        else
        {
            startValidator.style.visibility = 'hidden';
        }
    }
 
    
    return isValid;
}

/*Issue with calendar extender: does not update the highlighted date in the calendar
   * if date entered in text box is not in its default format.Hence converting user
   * entered date to correct format for both the start and the end date textboxes*/
   
   function onBlurStartDate()
   {
      var startDate = document.Form1.StartDate;
      var start = Date.parse(startDate.value);
      if(isNaN(start))
      {
         if(startDate.value != '')
         {
            var startValidator = new getObj('StartValidator');
            startValidator.obj.innerHTML = '(Invalid Date Format)';
            startValidator.style.visibility = 'visible';
         }
      }
     else
     { //check dates validity and return it in the format "dd MMM yyyy HH:mm:ss"
        
       CenterOfBoxWebService.CheckDateValidity(startDate.value,GetStartValidity);
     } 
   }
   
   function GetStartValidity(result)
   {   
        document.getElementById('StartDate').value= result;
        var start = new Date(result);
        $find('StartCalendar').set_selectedDate(start);
   }
  
  function onBlurEndDate()
  {
      var endDate = document.Form1.EndDate;
      var end = Date.parse(endDate.value);
     if(isNaN(end))
     {
       if(endDate.value != '')
       {
          var endValidator = new getObj('EndValidator');
          endValidator.obj.innerHTML = '(Invalid Date Format)';
          endValidator.style.visibility = 'visible';
       }
     }
     else
     {
       //check dates validity and return it in the format "dd MMM yyyy HH:mm:ss"
       CenterOfBoxWebService.CheckDateValidity(endDate.value,GetEndValidity);
     } 
   }
   
   function GetEndValidity(result)
   {
        document.getElementById('EndDate').value= result;
        var end = new Date(result);
        $find('EndCalendar').set_selectedDate(end);
   }
   
   
  function OnSatelliteChanged()
  {
     var satelliteCombo = document.Form1.ddlSatellites;
     if(satelliteCombo != null && satelliteCombo.selectedIndex != -1)
     {  
        var satSystem = satelliteCombo.options[satelliteCombo.selectedIndex].value;
        CenterOfBoxWebService.GetEndDate(satSystem,SetEndDate);
     }
  }
  
  //sets the start and end date text boxes
  function SetEndDate(result,eventArgs)
  {
    var value = result.split('@');
    if( value.length==4)
    {
      document.getElementById('StartDate').value=value[0];
      document.getElementById('EndDate').value=value[1];
      var start = new Date(value[0]);
      var end = new Date(value[1]);
      //updates the highlighted dates in the calendars
      $find('StartCalendar').set_selectedDate(start);
      $find('EndCalendar').set_selectedDate(end);
    }
  }
  