﻿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) {
  var ctrl = $find('ctl00_cphContent_TabContainer1');
  // var ctrl = $find('<%=ctl00_cphContent_TabContainer1.ClientID%>');

  var tabIndex = ctrl.get_activeTab().get_tabIndex();
  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_txtSearch').value = Orginalquery;

  PopulateSearchBox2(tabIndex, Orginalquery); 
}

function RemoveText() {
  var txt = document.getElementById('ctl00_cphContent_txtSearch').value;  
if(txt == "Title or Subject")
  document.getElementById('ctl00_cphContent_txtSearch').value = "";
}

function PopulateSearchBox2(tabIndex, Orginalquery) {

  switch (tabIndex) {

    case 0: document.getElementById('ctl00_cphContent_TabContainer1_Tab1_txtSearch2').value = Orginalquery; break;
    case 1: document.getElementById('ctl00_cphContent_TabContainer1_Tab2_txtSearch2').value = Orginalquery; break;
    case 2: document.getElementById('ctl00_cphContent_TabContainer1_Tab3_txtSearch2').value = Orginalquery; break;
    case 3: document.getElementById('ctl00_cphContent_TabContainer1_Tab4_txtSearch2').value = Orginalquery; break;
  }
}
  

//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';
  }

 }

 function CountyChanged(s) {

 	var CountryCode = (document.getElementById('ctl00_cphContent_ddlCountry').value)
 	if (CountryCode == 'US') {
 		
 		document.getElementById('ctl00_cphContent_ddlState').disabled = false;
 	}
 	else { 		
 		document.getElementById('ctl00_cphContent_ddlState').disabled = true;
 		document.getElementById('ctl00_cphContent_ddlState').style.backgroundColor = "#fff";
 	}

 }

/////////////////////////////////////////// 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 //////////////////////////////////////////////////////


/* ------------------ Begin - Added by Muthu for Div Popup on Sign-in page ------------------*/

function toggle(div_id) {
  var el = document.getElementById(div_id);
  if (el.style.display == 'none') { el.style.display = 'block'; }
  else { el.style.display = 'none'; }
}
function blanket_size(popUpDivVar) {
  if (typeof window.innerWidth != 'undefined') {
    viewportheight = window.innerHeight;
  } else {
    viewportheight = document.documentElement.clientHeight;
  }
  if ((viewportheight > document.body.parentNode.scrollHeight) && (viewportheight > document.body.parentNode.clientHeight)) {
    blanket_height = viewportheight;
  } else {
    if (document.body.parentNode.clientHeight > document.body.parentNode.scrollHeight) {
      blanket_height = document.body.parentNode.clientHeight;
    } else {
      blanket_height = document.body.parentNode.scrollHeight;
    }
  }
  var blanket = document.getElementById('blanket');
  blanket.style.height = blanket_height + 'px';
  var popUpDiv = document.getElementById(popUpDivVar);
  popUpDiv_height = blanket_height / 2 - 150; //150 is half popup's height
  popUpDiv.style.top = popUpDiv_height + 'px';
}
function window_pos(popUpDivVar) {
  if (typeof window.innerWidth != 'undefined') {
    viewportwidth = window.innerHeight;
  } else {
    viewportwidth = document.documentElement.clientHeight;
  }
  if ((viewportwidth > document.body.parentNode.scrollWidth) && (viewportwidth > document.body.parentNode.clientWidth)) {
    window_width = viewportwidth;
  } else {
    if (document.body.parentNode.clientWidth > document.body.parentNode.scrollWidth) {
      window_width = document.body.parentNode.clientWidth;
    } else {
      window_width = document.body.parentNode.scrollWidth;
    }
  }
  var popUpDiv = document.getElementById(popUpDivVar);
  window_width = window_width / 2 - 175; //150 is half popup's width
  popUpDiv.style.left = window_width + 'px';
}
function popup(windowname) {
  blanket_size(windowname);
  window_pos(windowname);
  toggle('blanket');
  toggle(windowname);
}

function SetAction(action) {
  popup('popUpDiv')
  if (action == 'A') {
    window.location = "SignIn.aspx?forgotaction=resetpwd";
    //alert('aaa');
  }
  else {
    window.location = "webform2.aspx";
    //alert('bbb');

  }

}
    
/*--------------------End -------------------------------------------------------------------*/
