﻿function blockNumbers(e) {
  //In FireFox Back-Space Key Code=8 , Tab KeyCode=0
  //In IE Back-Space Key Code=Null , Tab KeyCode=9
  isIE = document.all ? 1 : 0
  keyEntry = !isIE ? e.which : event.keyCode;
  if (!(((keyEntry >= '65') && (keyEntry <= '90')) || ((keyEntry >= '97') && (keyEntry <= '122')) || (keyEntry == '46') || keyEntry == '45' || keyEntry == '0' || keyEntry == '8' || keyEntry == '9')) {
    alert("Only Alphabets,Periods,Dash allowed");
    return false;
  }
}


//This Javascript function is used to check if atleast
//one Application Item is selected or not in the registration page.  

function validateCheckbox() {
  var oInputs;
  var bln;
  bln = "unchecked";

  oInputs = document.getElementsByTagName('input');

  for (i = 0; i < oInputs.length; i++) {
    // loop through and find <input type="checkbox"/>        
    if (oInputs[i].type == 'checkbox') {

      if (oInputs[i].checked) {
        bln = "checked";
        document.getElementById('ctl00_cphContent_lblValidateMsg').innerHTML = "";
        event.returnValue = true;
      }
    }
  }

  if (bln == "unchecked") {
    document.getElementById('ctl00_cphContent_lblValidateMsg').innerHTML = "One Application Mandatory";
    event.returnValue = false;
  }

}



function GetSearchData(hits, query, offset, Linkclick) {


  if (Linkclick == 'no') {
    hits = document.getElementById('ctl00_cphContent_hidHits').value;
    var id2 = query;
    var query = document.getElementById(id2).value ;
    var Orginalquery = query;
    query = '%22' + encodeURIComponent(query) + '%22';
    var strSearch = "query=" + query + "&hits=" + hits + "&offset=" + offset;
    document.getElementById('ctl00_cphContent_hfIsSearchSubmit').value = "Yes";
  }

  else if (Linkclick == 'yes') {


  var Orginalquery = document.getElementById('ctl00_cphContent_txtSearch').value;
  var query = Orginalquery;
  query = '%22' + encodeURIComponent(query) + '%22';
  var strSearch = "query=" + query + "&hits=" + hits + "&offset=" + offset;
    
  }


  document.getElementById('ctl00_cphContent_hidHits').value = hits;
  document.getElementById('ctl00_cphContent_hidquery').value = query;
  document.getElementById('ctl00_cphContent_hidOffset').value = offset;
  
   document.getElementById('ctl00_cphContent_txtSearch2').value =  Orginalquery;
   document.getElementById('ctl00_cphContent_txtSearch').value = Orginalquery;
 

}
  
  

//This function will display the State,Zipcode & Distance which are inside the panel if US is selected
//else the Panel is hiddden.
//This function is called from Location.aspx Page

function IndexChanged(s) {

  var Code = (document.getElementById('ctl00_cphContent_ddlCountry').value)
  if (Code == 'US') {       
      document.getElementById('ctl00_cphContent_panelUS').style.display = 'block';
  }
  else {    
      document.getElementById('ctl00_cphContent_panelUS').style.display = 'none';
  }

}

/////////////////////////////////////////// Start for Side Navigation ///////////////////////////////////////////////////////

var imgArrowVal = 1;  //For changing the arrow image while collapse and expand.
var fullHeight = 1;  //The full height of the side navigation menu.

function SideNavigation(id) {
  if (!document.getElementById || !document.getElementsByTagName)  //When there are no controls in the page.
    return false;
  this.speed = 1;    //The speed at which expand and collapse happens.
  this.init(id);
}

//This method checks for whether expand are collapse to be handled with imgArrowVal value and changes the image accordingly.
//For the elments within the 'span' tag, click events are handled.
SideNavigation.prototype.init = function(id) {
  var mainInstance = this;
  var sideMenu = document.getElementById(id);
  var parentMenu = sideMenu.getElementsByTagName("span");
  var sideSubMenu = document.getElementById('divSideSubNav'); //gets the div containing the list of side navs' menu - apart from parent 

  parentMenu[0].onclick = function() {
    if (imgArrowVal == 1) {  //change the arrow from expand to collapse and call collapse method
      document.getElementById('imgArrow').src = "../Images/SideMenuArrow.gif";
      mainInstance.collapseMenu(sideSubMenu);
    }
    else {      //change the arrow from collapse to expand and call expand method
      document.getElementById('imgArrow').src = "../Images/ddArrow.gif";
      mainInstance.expandMenu(sideSubMenu);
    }
    imgArrowVal = imgArrowVal * -1;
  };
};

//This method does Collapsing the menu.
SideNavigation.prototype.collapseMenu = function(sideNavSubMenu) {
  var mainInstance = this;
  //calculates the speed at which collapse to happen.
  var moveBy = Math.round(this.speed * sideNavSubMenu.getElementsByTagName("a").length);  
  var tblSideSubNav = document.getElementById('ctl00_cphSideNavigation_ucSideNavigation_tblSideSubNav');
  fullHeight = sideNavSubMenu.offsetHeight; //Gets the total height of the side navigation menu - apart from Main menu.
  var currHeight = sideNavSubMenu.offsetHeight;
  var span = sideNavSubMenu.getElementsByTagName("span"); //gets the list of span tags (where we have the '-')
  var hyperLinks = sideNavSubMenu.getElementsByTagName("a"); //gets the list of links - apart from the Main menu.
  var linksCount = sideNavSubMenu.getElementsByTagName("a").length; // gets the count of - number of links.
  var perLinkHeight = fullHeight / linksCount;  // calculates the height of each link.
  var Count = 1;
  
  var intId = setInterval(function() {   //this function gets executed for every 30 milli seconds.
    currHeight = sideNavSubMenu.offsetHeight;
    //The height of the side nav is reduced by the calculated 'moveby' value and the controls beyond the height are made invisible, until
    //when the newheight reaches the link height.
    var newHeight = parseInt(currHeight) - parseInt(moveBy); 
    if (newHeight > 0) {
      sideNavSubMenu.style.height = parseInt(newHeight) + 'px';
      if (newHeight <= (fullHeight - (perLinkHeight * Count)) + 10) {
        if (linksCount > 0) {
        
          hyperLinks[linksCount - 1].style.visibility = 'hidden';
          span[linksCount - 1].style.visibility = 'hidden';
        }
        linksCount = linksCount - 1;
        Count++;
      }
    }
    else {//when it reaches the MainMenu - clear the interval and make invisible the whole div containing the sub menu's.
      clearInterval(intId);
      if (linksCount >= 0) {
        for (var i = 0; i < linksCount; i++) {
          hyperLinks[i].style.visibility = 'hidden';
          span[i].style.visibility = 'hidden';
        }
      }
      sideNavSubMenu.className = "divCollapseSideSubMenu";
      document.getElementById('tdSideSubNav').className = "divCollapseSideSubMenu";
    }
  }, 30);
};

//This method does Expanding the menu.
SideNavigation.prototype.expandMenu = function(sideNavSubMenu) {
  var mainInstance = this;
  document.getElementById('tdSideSubNav').className = "divExpandSideSubMenu";
  sideNavSubMenu.className = "";
  //calculates the speed at which collapse to happen.
  var moveBy = Math.round(this.speed * sideNavSubMenu.getElementsByTagName("a").length);
  var links = sideNavSubMenu.getElementsByTagName("a");  //gets the list of links - apart from the Main menu.
  var span = sideNavSubMenu.getElementsByTagName("span");  //gets the list of span tags (where we have the '-')
  var linksCount = sideNavSubMenu.getElementsByTagName("a").length; // gets the count of - number of links.
  var perLinkHeight = fullHeight / linksCount; //calculates the height of each link.
  var Count = 1;

  var intId = setInterval(function() { //this function gets executed for every 30 milli seconds.
  var currentHeight = sideNavSubMenu.offsetHeight;
  //The height of the side nav is increased by the calculated 'moveby' value and the controls within the height are made visible, until
  //the newheight reaches the full height.
    var newHeight = currentHeight + moveBy;
    if (newHeight <= fullHeight) {
      sideNavSubMenu.style.height = newHeight + "px";
      if(newHeight >= ( Count * perLinkHeight))
      {
        links[Count-1].style.visibility = 'visible';
        span[Count-1].style.visibility = 'visible';
        Count ++;
      }
    }
    else { //when it reaches the FullHeight - clear the interval.
      clearInterval(intId);
      sideNavSubMenu.style.height = "";
      sideNavSubMenu.className = "";
    }
  }, 30);
};

/////////////////////////////////////////////// End for Side Navigation //////////////////////////////////////////////////////