// =================================================================================================
//  Javascript methods
// =================================================================================================

//display Master page popup divs
function show(keyChar){
  var rangeDivs = new Array('A','B','C','D','E','F','H','I','L','M','N','O','P','R','S','T');
  var sty = document.getElementById(keyChar).style;
  for (i=0; i<16; i++){
    document.getElementById(rangeDivs[i]).style.display ='none';
  }
  sty.display = 'block';
}
//Hide Master page popup divs    
     function hideAllDivs()
     {
        var rangeDivs = new Array('A','B','C','D','E','F','H','I','L','M','N','O','P','R','S','T');
        
        for (i=0; i<16; i++)
        {
        var sty = document.getElementById(rangeDivs[i]).style
        sty.display ='none';
        }
     }
     //Create background for selected letter
     function hilightLetter(ctrl) {
         removeStyleFromLetters();
         ctrl.className = 'selectedLetter';
     }

     //Remove Style form the selected letters
     function removeStyleFromLetters() {
         var containerDiv = document.getElementById('drugNameInitialsDiv');
         containerDivChildren = containerDiv.childNodes;
         var ele = null;
         for (i = 0; i < containerDivChildren.length; i++) {
             ele = containerDivChildren[i];
             if (ele.type != null)
                 ele.className = 'unSelectedLetter';
         }
     }
    function Hide(kChar)
    {
      var note=document.getElementById(kChar);
      note.style.display = 'none';
      removeStyleFromLetters();
   }

   //Show and Hide element
   function hideElement(ctrl) {
       
       var elem = document.getElementById(ctrl);
       elem.style.display = 'none';
   }

   function showElement(ctrl) {
       var elem = document.getElementById(ctrl);
       elem.style.display = 'block';
      }

      function showHideElement(ctrl) {

          var elem = document.getElementById(ctrl);
          if (elem.style.display == "block") {
              elem.style.display = 'none';
           }
          else {
          elem.style.display = 'block';
          elem.style.zIndex = 999;
             }
      }
   
   
   
//Tab Click Functions
function OpenHome(){window.location="Default.aspx";}
function OpenRad(){window.location="FindDrug.aspx";}
function OpenFad(){window.location="FindAdrug.aspx";}
function OpenTrack(){window.location="SignUpForFreeReports.aspx";}
function OpenPREPP() {window.location = "StuInstruction.aspx";}          
//Hide and visible control
function makeVisible(ctrl){
  var sty=document.getElementById(ctrl).style;
  if(sty.visibility == "hidden"){sty.visibility="";sty.width="140px";}
  else{sty.visibility="hidden";sty.width="5px";}
}
//Create new window
function wopen(url, name, w, h){
var win = window.open(url,name,'width=' + w + ', height=' + h + ', ' +'location=no, menubar=no, ' + 'status=1, toolbar=no, scrollbars=1, resizable=no, left=150, top=150');
win.resizeTo(w, h);
win.focus();
}
function RemoveText(ctrl, textVal){
  if (typeof (ctrl.value) == "undefined")
    var txt = document.getElementById(ctrl);
  else
    var txt = ctrl; 
  var tex = txt.value;
  txt.style.color = '#555455';
  txt.style.fontStyle = 'normal';
  if(tex == textVal)
    txt.value = "";
  return true;
}
function AddText(ctrl, textVal){
  if (typeof (ctrl.value) == "undefined")
    var txt = document.getElementById(ctrl);
  else
    var txt = ctrl; 
  var tex = txt.value;
  if (tex == "") {
    txt.style.color = '#757575';
    txt.style.fontStyle = 'italic';
    txt.value = textVal;
  }
  return true;
}
//Print Page
function printPartOfPage(elementId){
  var printContent = document.getElementById(elementId);
  var windowUrl = 'Survey Report';
  var uniqueName = new Date();
  var windowName = uniqueName.getTime();
  
  var printWindow = window.open(windowUrl, windowName, "status=1,scrollbars=1,width=750,height=850");

  var printButton = "<div style='width: 100%; text-align: right;'>";
      printButton += "<input class='bottomPrintButton' type='button' value='Print' onclick='window.print();'/></div></div>";
            
  var styles = "<link href='StyleSheet1.css' rel='stylesheet' type='text/css' />";
  styles += "<style type='text/css'>body { background-color: white!important; } .hideBottomPrintViewButton {display:none !important;} .dontShowOnSurveyReport {display:none;} </style>";
  var heading = "<div style ='margin:20px 40px 40px 40px; background-color:white; width:660px;'>";
      heading += "<div style='width: 100%; text-align: right; padding-bottom:10px;'><a class='bottomPrintButton' href='javascript:window.print();'>Print</a></div>";
      heading += "<table style='border-collapse: collapse; width:100%;'>";
      heading += "<tr><td><div><img src='Images/logoNotablePage.gif'/></div></td><td class='leftPad10'>";
      heading += "<div style='font-size: 18px; color: #c20000; font-weight: bold; padding-bottom: 0px;'>";
      heading += "The User's Guide to Prescription Medications and Side Effects</div>";
      heading += "<div style='font-size: 12px; padding-top: 0px;'>";
      heading += "&nbsp;User ratings and self-evaluation tools for over 8000 prescription drugs and alternative medications";
      heading += "</div></td></tr></table>";
  
  
  printWindow.document.write(heading + printContent.innerHTML + printButton + styles );
  printWindow.document.close();
  printWindow.focus();
  
}
//To prevent multiple data entry, if the user press submit button more than once
function ToggleButton(buttonContainer, waitContainer, validationGroup){ 
// If client validators not active  
  if (typeof(Page_Validators) == "undefined"){
    DisableButton(buttonContainer, waitContainer);
  } 
  if (typeof(Page_ClientValidate) == 'function'){ 
  // Force Page validation  
    Page_ClientValidate(validationGroup);   
// If validation passed   
    if(Page_IsValid){  
      DisableButton(buttonContainer, waitContainer);
    }
  } 
  else{ 
    DisableButton(buttonContainer, waitContainer);
  }
}
function DisableButton(buttonContainer, waitContainer){ 
  var bContainer = window.document.getElementById(buttonContainer);
  var wContainer = window.document.getElementById(waitContainer); 
  bContainer.style.display = "none";  
  wContainer.style.display = "block";
}
function addItemRow(containerCtrl, hdnCtrol, identifier){
  var tbl = document.getElementById(containerCtrl);
  var lastRow = tbl.rows.length;
  var iteration = lastRow;
  var row = tbl.insertRow(lastRow);
  var cellTextRow = row.insertCell(0);
  var ua = navigator.userAgent;
  if (ua.toLowerCase().indexOf('msie') != -1) {
    var txtBox = document.createElement("<input id='txtBox" + iteration + identifier + "' type='text' size ='99' onblur=collectItems(" + containerCtrl + "," + hdnCtrol + "); />");
  }
  else {
    var txtBox = document.createElement('input');
    txtBox.type = 'text';
    txtBox.id = 'txtBox' + iteration + identifier;
    txtBox.name = 'txtBox' + iteration + identifier;
    txtBox.size = '99';
    txtBox.setAttribute('onblur', "collectItems(" + containerCtrl + "," + hdnCtrol + ");");
  }
  cellTextRow.appendChild(txtBox);
}
function collectItems(ctrl, hdnCt){
  var hdf = document.getElementById(hdnCt);
  hdf.value = '';
  var elem = document.getElementById(ctrl);
  for (i = 0; i < elem.rows.length; i++) {
    var t = elem.rows[i].cells[0];
    var tx = t.childNodes.item(0).value;
    hdf.value += '|' + tx;
  }
}
