<!--
var displayType = "none";     //  for hiding or showing the login form
var mouseOvers = new Array();
var mouseOuts = new Array();
var XMLHttp;
nOpac = 50
nPlus = 2
nMin = 1
speed = 30
timer = null; 
timer2 = null;
var ie5=(document.all && document.getElementById);
var ns6=(!document.all && document.getElementById);
var apl;


if( window.XMLHttpRequest )       // If native XMLHttpRequest object
{
  XMLHttp = new XMLHttpRequest();
}
else                              // If IE/Windows ActiveX version
{
  XMLHttp = new ActiveXObject( "Microsoft.XMLHTTP" );
}


/**************************************************************************\
  This function calls SetScreen tot set the screen to ablank screen
  when a user cancels a Form
\*************************************************************************/
function CancelSubmitForm()
{
  SetScreen('Blank');

}

function CancelQAForm()
{
  SetScreen('Qa');
}


/**************************************************************************\
  This function calls a servlet and passes the given parameters
\*************************************************************************/
function CallServlet( servlet, params )
{
  if( XMLHttp )
  {
    XMLHttp.open( "POST", "/Intranet/" + servlet, false );
    XMLHttp.setRequestHeader( "Content-Type", "application/x-www-form-urlencoded" );
    XMLHttp.send( params );
  }
  else
  {
    alert( "XMLHttp object does not exist!" );
  }
}


/**************************************************************************\
  This function is called from  fadeImg2 or fadeImgend2 to change opacity
  of an object apl[]
\**************************************************************************/

function changes()
{
 next_loop = true;
 for (i=1;i<apl.length;i++)
 {
  obj = link_table.rows[i].cells[0];
  opacity = apl[i][0];
  if (apl[i][1] == "Up")
  {
     opacity += nPlus;
     apl[i][0] = opacity;
     if (apl[i][0] > 105) 
     {
      apl[i][1] = "";
     }
     else
     {
      next_loop = false;
     }
	   nOpac = opacity;
  }
  else
  {
    if (apl[i][1] == "Down")
    {
      opacity -= nMin;
      apl[i][0] = opacity;
      if (apl[i][0] < 45) 
      {
       apl[i][1] = "";
      }
      else
      {
       next_loop = false;
      }
	    nOpac = opacity;
    }
  }
  if(ie5)
  { 
	  obj.style.filter="alpha(opacity="+opacity+")";
  }
  if(ns6)
  { 
   	obj.style.MozOpacity = opacity + '%';
  }
 }
 if (next_loop == false)
  {
    timer = setTimeout("changes()",speed);
  }
  else
  {
    clearTimeout(timer);
  }
}



/**************************************************************************\
  This function closes an opem menu section if a user clicks om another  one
  called from the toggleVisibility(divID) finction
\**************************************************************************/
function closeOpenMenuSection(divID)
{   

  //get all the rows in the MenuSection (table)
  var oItem = document.all.MenuSection.rows;
  //alert (oItem.length);
  //alert("Leave open"+ divID);  
  //loop through every row to find the MenuCategory
  for (i=0; i<oItem.length; i++) 
  {
     if (oItem[i].id=="MenuCategory")
     {
        var divs = oItem[i].getElementsByTagName( "div" );
        //alert("Class Name: "+ divs[0].id+ " "+divs[0].className) ;
        //if another menu section is open , close it     
        if(divs[0].className=="ShowBlockElement" && divs[0].id!=divID)
        {
          divs[0].className="HideBlockElement";
        }     
     }
   }
}



/**************************************************************************\
    This function creates an array of objects which will be used in fadeImg2
    to manupulate opacity.This function is ran in onload event. This ieffect 
    used on Emploees screen so far    
\**************************************************************************/

function createArray(count)
{
  apl = new Array();
  for (i=0; i<count; i++)
  {
    apl[i] = new Array(45,"");
  }
}


function deleteEvent(formId)
{
    SetSessionVariable( '', '', 'DeleteEvent', 'true' );   
    document.getElementById( formId ).submit();
}



/**************************************************************************\
    This function changes a style of all inputBoxes & comboBoxes of a
    selected row to editable, and resets the rest of the rows to
    read only style(EditScheduleGetScreen.java)
\**************************************************************************/
function editEvent(recordId)
{
   //EditEvents table contains all records
   var allRecords = document.all.EditEvents.rows;
   
   for (var i=1; i<allRecords.length; i++) //skip header
   {             
      //tr element's id is equal eventIdentity
      var recId=allRecords[i].id;
      //hidden <tr>'s that contain Cancel, Edit & Update buttons have Class=HideBlockElement or 
      //ShowBlockElement depending of the row's visibility
      if(allRecords[i].className!="HideBlockElement" &  allRecords[i].className!="ShowBlockElement")
      {   
          var inputs=allRecords[i].getElementsByTagName("input");
          var comboBox=allRecords[i].getElementsByTagName("select");
          var cells=allRecords[i].cells;
             
          if (recId!=recordId)
          {          
            //change the color of a not selected row
            allRecords[i].style.backgroundColor="#E8F1ED";
            for (var d=0;d<inputs.length;d++)
            {
               inputs[d].className="InputBoxDisguised";
               inputs[d].readOnly=true;
            } 
            for (var c=0;c<comboBox.length;c++)
            {
               comboBox[c].className="InputBoxDisguised";  
               comboBox[c].disabled=true; 
            }
            
            //for a fact,the first cell is an option button
            var optionEdit=cells[0].getElementsByTagName("input");
            //unselect the rest of option buttons, 
            //there is only one option in a row, so there is no need to loop
            optionEdit[0].checked=false;
            optionEdit[0].style.backgroundColor="#9CBFB8";
          }
          else
          {
            //make selected row look like it's editable
            allRecords[i].style.backgroundColor="#DDE6E2";
            for (var d=0;d<inputs.length;d++)
            {
               inputs[d].className="inputBox";
               inputs[d].readOnly=false;
            } 
            for (var c=0;c<comboBox.length;c++)
            {
              comboBox[c].className="inputBox"; 
              comboBox[c].disabled=false;
            } 
          } 
       }//end of hidden div check
       else //hide the rest of the buttons
       {
          var showButtons=document.getElementById(recId);         
          if (recId=="HiddenDiv"+recordId)
          {             
             showButtons.className="ShowBlockElement"; 
          }
          else
          {
             showButtons.className="HideBlockElement";
          }        
       }
   }//end of for
}//end of function

/**************************************************************************\
    This function makes ENTER to submit the login form
\**************************************************************************/
function entsub(loginform) 
{
  if (window.event && window.event.keyCode == 13)
  {
    loginform.submit();
  }
  else
  {
   return true;
  }
}



function fadeImg2(teller)
{
 apl[teller][1] = "Up";
 changes();
}


function fadeImgend2(teller)
{
 apl[teller][1] = "Down";
 setTimeout("changes()",50);
}


/**************************************************************************\
    This function determins the height of iframes on idex.jsp
\**************************************************************************/
function getIframeHeight()
{
  var screenHeight = document.body.clientHeight;
  //deduct the height of the top frame
  var frameHeight = screenHeight - 127;
  document.getElementById( 'SideMenu' ).height = frameHeight;
  document.getElementById( 'my_frame' ).height = frameHeight;
}



/**************************************************************************\
    This function searches an array, that contains data of a particular
    record type. When a match is found, it displays data
    in the correponding fields. The function is called from Marketing.java
\**************************************************************************/
function getRecords(recordType)
{
  var type=recordType+"_name";
  //get listBox object
  var obj= document.getElementById( type )

  var company=obj.selectedIndex;
  var companyIdentity=obj.options[company].value;
  //alert(companyIdentity);
  var arrayOfCompanies=eval(recordType);
  for (var r=0;r<arrayOfCompanies.length; r++)
  {
    if (arrayOfCompanies[r][4]==companyIdentity)
   {
        //alert("found Match");
        var editDiv="Edit"+recordType+"Div";
        var editDivObj=document.getElementById(editDiv);
        if (editDivObj!=null)
        {
          editDivObj.className="ShowBlockElement";
          var compNameObj=document.getElementById("Edit"+recordType+"Name");
          compNameObj.innerText=arrayOfCompanies[r][3];
          var compAppNameObj=document.getElementById("Edit"+recordType+"AppName");
          compAppNameObj.innerText=arrayOfCompanies[r][0];
          var compFuncObj=document.getElementById("Edit"+recordType+"Functionality");
          compFuncObj.innerText=arrayOfCompanies[r][1];
          var compWebObj=document.getElementById("Edit"+recordType+"WebSite");
          compWebObj.innerText=arrayOfCompanies[r][2]; 
          var compId=document.getElementById("Edit"+recordType+"CompanyIdentity");
          compId.value=companyIdentity; 
          //alert(compId.value);
        }
     }
   }   
}


/**************************************************************************\
  This function is called from the CS CalendarGetScree. java
  it sets Department variable , which is read by the EnterEventGetScreen.  
\**************************************************************************/
function GoToEnterEvent(department)
{
  var frame;
  SetSessionVariable( '', '', 'ScreenName', 'EnterEvent' );
  SetSessionVariable( '', '', 'Department', department );//depending on the department, certain fields will be hidden
  frame = parent.document.getElementById("DataFrame");
  frame.contentWindow.location.reload();
}




/**************************************************************************\
  This function set the style of the cell next to the 
  selectedmenu Item to visible  and resets style s of the cell  for
  the rest of menus
\**************************************************************************/
function showSelection(objId,numOfMenus)
{
  var objCell=document.getElementById(objId);

  objCell.className="ItemSelected";
  var linkId;
  var linkObj;
  for (i=0; i< numOfMenus; i++) //11 menu items so far
  {
      linkId="link"+i;
      var objLI=document.getElementById(linkId);
      if( linkId!=objId )
      {  
        linkObj= document.getElementById( linkId );
        if(linkObj!=null)
        {    
           linkObj.className="ItemUnselected";
        }
      }
   }
}


/**************************************************************************\
  This function submits the Logout form
\**************************************************************************/
function logout()
{
  SetScreen( 'Blank' );
  document.getElementById( "LogoutForm" ).submit();
}

function mouseGoesOver()
{
  this.src=mouseOvers[this.number].src;
}



function mouseGoesOut()
{
  this.src=mouseOuts[this.number].src;
}


function GotoLogin()
{
  window.location = "Login.jsp";
}



function HighlightLinkCategory(obj)
{
  obj.className="LinkCategoryOver";
}



function InitImages()
{
  var nav = document.getElementById( 'mouseovers' );
  var imgs = nav.getElementsByTagName( 'img' );
  var i;
  
  for( i = 0; i < imgs.length; i++ )
  {
    imgs[i].onmouseover = mouseGoesOver;
    imgs[i].onmouseout = mouseGoesOut;
    var suffix = imgs[i].src.substring( imgs[i].src.lastIndexOf('.') );
    mouseOuts[i] = new Image();
    mouseOuts[i].src = imgs[i].src;
    mouseOvers[i] = new Image();
    mouseOvers[i].src = imgs[i].src.substring( 0, imgs[i].src.lastIndexOf('.') ) + "_over" + suffix;
    imgs[i].number = i;
  }
}



/**************************************************************************\
  This function submits the login form
\**************************************************************************/
function Login()
{
  document.getElementById( "LoginForm" ).submit();
}


/**************************************************************************\
  This function moves the screen position of the window to the top
\**************************************************************************/
function moveToTop()
{ 
  window.scrollTo(0,0) 
}


/**************************************************************************\
  This function  prints part of a page: elment_id is div to print
  A screen needs to be refreshed to show all elements again
\**************************************************************************/
function PrintForm(element_id)
{

   var obj=document.getElementById(element_id);
   obj.className="show";
   //alert(element_id);
   window.print();
}


   window.onbeforeprint =
  function ( )
  {
    var divs = document.getElementsByTagName("div");


    for (i=0; i<divs.length; i++) 
    {        
       if (divs[i].className =="hide_for_print")    
       {
         //alert("hide: "  + divs[i].id);
         divs[i].style.display = "none";
       }
     } 
 }


 window.onafterprint=function ()
 {
    var divs = document.getElementsByTagName("div");
      for (i=0; i<divs.length; i++) 
  {        
      if(divs[i].className =="hide_for_print") 
      {
         divs[i].style.display = "block";     
       } 
  } 
}


/**************************************************************************\
  This function sets the focus onto the username field
\**************************************************************************/
function SetLoginFocus( id )
{
  document.getElementById( id ).focus();
}



/**************************************************************************\
  This function sets the focus onto the username field
\**************************************************************************/
function SetMyDate()
{
  current_date = ThisDay + " - " + MonthName.slice( 0, 3 ) + " - " + ThisYear;
  var test= document.getElementById( "my_date" );
  document.getElementById( "my_date" ).innerHTML = current_date;
}



/**************************************************************************\
  This function calls a servlet and passes the given parameters
\**************************************************************************/
function SetScreen( screenName )
{
  var frame;
  SetSessionVariable( '', '', 'ScreenName', screenName );
  //alert(screenName);
  frame = parent.document.getElementById("DataFrame");
  frame.contentWindow.location.reload();
}

function SetScreenNameToParent(parent)
{
  SetSessionVariable( '', '', 'ScreenName', parent );
}

/**************************************************************************\
  This function calls a servlet and passes the given parameters
\**************************************************************************/
function SetScreenSection( screenName,sectionName,projectName,parentName)
{

  var frame;
  SetSessionVariable( '', '', 'ScreenName', screenName );
  if(projectName!='')
  {
     SetSessionVariable( '', '', 'ProjectName', projectName );
  }
  SetSessionVariable( '', '', 'ParentName', parentName );
  frame =document.getElementById(sectionName);
  frame.contentWindow.location.reload(); 
}



function submitForm(formName)
{
  var myForm=document.getElementById(formName);
  if (myForm!=null)
  {
     myForm.submit();
  }
  else
  {
    alert("Error. Could not submit the form");
  }
}

/**************************************************************************\
  This function removes a session variables value on the server.
\**************************************************************************/
function RemoveSessionVariable( window, section, variable )
{
  var params = "Window=" + window + "&Section=" + section + "&Variable=" + variable;
  CallServlet( "RemoveSessionVariable", params );
}
/**************************************************************************\
  This function sets a session variables value on the server.
\**************************************************************************/
function SetSessionVariable( window, section, variable, value )
{
  var params = "Window=" + window + "&Section=" + section + "&Variable=" + variable + "&Value=" + escape( value );

  CallServlet( "SetSessionVariable", params );
}



function showLogin()
{
  var loginObj = document.getElementById( "showLogin" );
  var fieldObj;
  
  // If the login block is hidden
  if( loginObj.className == "HideBlockElement" )
  {
    // Then reveal it to the user
    loginObj.className = "ShowBlockElement";
    
    // Put the cursor on the login field
    fieldObj = document.getElementById( "Username" );
    fieldObj.focus();
  }
  else // Otherwise it must be visible
  {
    // So hide it (toggle the display)
    loginObj.className = "HideBlockElement";
  }
}



/**************************************************************************\
  This function changes a style of a selected inputBox  to visible and resets 
  the rest of the inputBoxes style to be invisible. An inputBox's id
  should start with "link0" . this function is used on QA page
\*************************************************************************/
function toggleInputVisibility(objId)
{
  var objCell=document.getElementById(objId);
  objCell.className="inputBox";
  //get all the rows in the InputSection table
  var oItem = document.all.InputSection.rows;
  var linkId;
  var inputObj;
  var num=0;
  var buttons;
  
  buttons=document.getElementById('QAFormButtons');
  //open the buttons only the fisrt time user clicks in a field
  if(buttons.className=="HideBlockElement")
  {
    buttons.className="ShowBlockElement";
  }
  
  //loop through every row 
  for (i=0; i<oItem.length; i++) 
  {      
     var col = oItem[i].cells;
     //loop through columns
     for(x=0; x<col.length; x++)
     {
        linkId="link"+num;
        num++;
        if( linkId!=objId )
        {
            inputObj= document.getElementById( linkId );
            if(inputObj!=null)
            {
              inputObj.className="InputBoxDisguised";
            }
        }
     }       
   }
}    



function toggleVisibility(divID)
{
  var objDiv=document.getElementById(divID);  
  //alert("Open section "+divID);
  if( objDiv.className == "HideBlockElement" )
  {
    // Then reveal it to the user
    objDiv.className = "ShowBlockElement";  
  }
  else // Otherwise it must be visible
  {
    // So hide it (toggle the display)
    objDiv.className = "HideBlockElement";
  } 
  //hilde any open sections
  closeOpenMenuSection(divID);
}


function toggleVisibilityMenuItem(divID)
{
  var objDiv=document.getElementById(divID); 

  
  if( objDiv.className == "HideBlockElement" )
  {
    // Then reveal it to the user
    objDiv.className = "ShowBlockElement";  
  }
  else // Otherwise it must be visible
  {
    // So hide it (toggle the display)
    objDiv.className = "HideBlockElement";
  }

}

 function isNumeric(str)
 {
  var re = /[\D]/g
  if (re.test(str)) return false;
  return true;
}

function trimSpaces(sString) 
{
  while (sString.substring(0,1) == ' ')
  {
    sString = sString.substring(1, sString.length);
  }
  while (sString.substring(sString.length-1, sString.length) == ' ')
  {
  sString = sString.substring(0,sString.length-1);
  }
  return sString;
  }


/**************************************************************************\
  This function validates numeric inputBox, and checks if an Urgent checkBox is
  selected and data exists in a corresponding Quantity IntputBox
  It stops form submittion if there are errors by displying a promt.
  Used to validatate KitchenForm & OfficeForm ( Shopping List)
\**************************************************************************/

function validateForm(FormName) 
{
    var elem;
    var errsQ=0;
    var errsU=0;
    var errorStringQuantity=""
    errorStringUrgent="";
    var data=null;
    var elName=null;
    var theform=document.getElementById(FormName);

    for(var i=0; i<theform.length; i++)
    {
      elName= theform.elements[i].name;      
      if(theform.elements[i].type=="text")
      {  
        //check quantity fields only.Quantity fields names satrt with "q_"
        if( elName.substr(0,2)=="q_")
        {
          theform.elements[i].className="inputBox"; //reset style in case of previous validation
          data =theform.elements[i].value;
          data=trimSpaces(data);
          if(data!="")
          {
             var  valid=isNumeric(data);
             if(!valid)
             {
               //alert(theform.elements[i].value);
               theform.elements[i].className="InputBoxError";
               errsQ += 1;
             }
           }    
         }
       }//end of type="text" check
       
      //now, check if Urgent checkBox is checked and make sure that
      // the quantity is set for this checkBox
      if(theform.elements[i].type=="checkbox")
      {  
        if (theform.elements[i].checked==true)
        {        
          var quantity =theform.elements[i-1].value;        
          if(trimSpaces(quantity)=="")
          {
            theform.elements[i-1].className="InputBoxError";
            errsU += 1;
          }
        }
      } //end of outer if block 
    }//end of for

    if (errsU>0)
    {
      errorStringUrgent="Error. Quantity is missing"; 
    }
     if (errsQ>0)
    {
      errorStringQuantity="Error. Quantity must numeric"; 
    }
    
    var errs=errsQ+errsU; 
    if (errs>0) alert('There are a fields which needs correction before sending\n'+errorStringUrgent +'\n'+errorStringQuantity);
    return (errs==0);
}



//-->


