﻿//Purpose: Open BrowseByCompany or MastrFormat popup window
function ShowBrowsePopup() {

    if (document.getElementById('ctl00_ContentPlaceHolder1_SearchByCompany').checked == true) {
        window.open('/MHCPNWWebApp/WebPages/BrowseByCompanyPopup.aspx', '',
                    'left=200,top=75, width=700, height=630,menubar=no,resizable=yes,scrollbars=yes');
                    
    }
    if (document.getElementById('ctl00_ContentPlaceHolder1_SearchByMasterFormat').checked == true) {
        window.open('/MHCPNWWebApp/WebPages/BrowseDivisionsPopup.aspx', '', 'left=0,top=0, width=800, height=600,menubar=no, resizable=yes,scrollbars=yes');
    }
}
//Purpose: GetResult Based on Alphabet
function GetResultByAlphabet(SelectedAlphabet,AlphabetId) {
    document.getElementById('hdnCurrentPagePaging').value = "0";
    document.getElementById('HdnSelectedAlphabet').value = SelectedAlphabet;
    document.getElementById('hdnAlphabetId').value = AlphabetId;
    
    document.frmBrowsePopup.submit();
}
//Purpose:get the selected company id and name from Browse by company popup
function GetSelectedCompany(companyId, companyName) {

    var selectedText = document.getElementById(companyName).value;
    window.opener.document.getElementById('ctl00_ContentPlaceHolder1_txtSearchTerm').value = selectedText;
    //window.opener.document.getElementById('ctl00_ContentPlaceHolder1_hdnCompanyId').value = companyId;
    window.close();
}
//Purpose: cleare the previous value and validate company  selection
function RepCompanyResultOnClick()
 {
    document.getElementById("ctl00_ContentPlaceHolder1_hdnRepPagNumber").value = "0";
    document.getElementById('ctl00_ContentPlaceHolder1_hdnEventTarget').value = "0";
    //Validation for company check 
    var selectedComany = 'false';
    lclForm = document.forms["aspnetForm"]		
    elm=lclForm.elements;
    	for (i = 0; i < elm.length; i++)
    	{
    	    if (elm[i].type == "radio" && elm[i].name != 'ctl00$ContentPlaceHolder1$SearchBy')
    	     {
    	          if (elm[i].checked == true) {
    	              selectedComany = 'true'
    	          }
    		 }
   }
   if (selectedComany == 'false') {
       alert("Please select a company")
       return false;
   }    
    	
  }
 function ClearValue() {

     var theform = document.forms["aspnetForm"];
     theform.__EVENTTARGET.value = " ";
          
    document.getElementById("ctl00_ContentPlaceHolder1_hdnCompanyPageNumber").value = "0";
    document.getElementById("ctl00_ContentPlaceHolder1_hdnRepPagNumber").value = "0";
    document.getElementById("ctl00_ContentPlaceHolder1_hdnSelectedCompanyId").value = "0";
    document.getElementById('ctl00_ContentPlaceHolder1_hdnEventTarget').value = "0";
    document.getElementById("ctl00_ContentPlaceHolder1_hdnCheckBoxId").value = "0";
    document.getElementById('ctl00_ContentPlaceHolder1_hdnEventTarget').value = "0";
    //search tearm
    var searchText = trimAll(document.getElementById('ctl00_ContentPlaceHolder1_txtSearchTerm').value);
    if (searchText.length == 0) {
        document.getElementById('ctl00_ContentPlaceHolder1_txtSearchTerm').focus()
        alert("Please enter search term")
        return false;
    }
    //Zip code
    var zipCode = document.getElementById('ctl00_ContentPlaceHolder1_txtPostalCode').value
    if (zipCode.length != 5) {
        document.getElementById('ctl00_ContentPlaceHolder1_txtPostalCode').focus()
        alert("Please enter valid postal code");
        return false;
    }
    if (isInteger(zipCode) == false) {
        document.getElementById('ctl00_ContentPlaceHolder1_txtPostalCode').focus()
        alert("Please enter valid numeric postal code");
        return false;
    }
    
}

//Purpose:Get the company addrese when select company name from multiple company result
function show_CompanyAddress(CompanyAddres,CheckBoxId,SelectedCompanyId,rowCount,divEmailId) {
    var address = "";
    var address_arry = new Array();
    address_arry = CompanyAddres.split('~');
    document.getElementById("ctl00_ContentPlaceHolder1_hdnSelectedCompanyName").value = address_arry[0];  // set the selected company name.
    address_arry[0] = "<B>" + address_arry[0] + "</B>";

    if (address_arry[4].length > 1) {
        //address_arry[4] = "<a class='ArialGreyL11px' href=javascript:EmailtoRFI('" + address_arry[4] + "','" + divEmailId + "')>email </a>";
        address_arry[4] = "<a class='ArialGrey11px' title=" + address_arry[4] + " href=javascript:GotoRFI('RC','" + rowCount + "')>email </a>";
        
    }
    if (address_arry[5].length > 1) {
        address_arry[5] = "&nbsp;|&nbsp;<a class='ArialGrey11px' title=" + address_arry[5] + " href=javascript:RepCompanyWebSiteLink('" + address_arry[5] + "','" + SelectedCompanyId + "')> website </a>";
    }
    address_arry[4] = address_arry[4] + address_arry[5];
    
    for (i = 0; i < address_arry.length-1; i++) {   
    address += "<div>" + address_arry[i] + "</div>";
    }
   

    document.getElementById("ctl00_ContentPlaceHolder1_ctl03_divSelectedCompany").innerHTML = address;   // add the selected company address in div.
    document.getElementById("ctl00_ContentPlaceHolder1_hdnSelectedCompanyId").value = SelectedCompanyId; // set the selected company radio button id.
    document.getElementById("ctl00_ContentPlaceHolder1_hdnCheckBoxId").value = CheckBoxId;               // set the check box value/
    document.getElementById("ctl00_ContentPlaceHolder1_ctl03_tblRepResult").style.display = "none";      // hide the represult table. */
}

function FastSearchCurrentPage(objIdCurPage, curPage, hdnMove) {
    //alert(curPage);
    //alert(objIdCurPage);
    document.getElementById("ctl00_ContentPlaceHolder1_hdnCheckBoxId").value = "0";   //clear the checked company from multiple company result
    document.getElementById("ctl00_ContentPlaceHolder1_hdnSelectedCompanyId").value = "0";
    document.getElementById('ctl00_ContentPlaceHolder1_hdnEventTarget').value = "0";
    document.getElementById("ctl00_ContentPlaceHolder1_hdnCompanyPageNumber").value = curPage;
    objCurPage = document.getElementById(objIdCurPage)
    objCurPage.value = curPage 
    
}
function RepResultCurrentPage(objIdCurPage, curPage, hdnMove) {
    //document.getElementById("ctl00_ContentPlaceHolder1_hdnSelectedCompanyId").value = "0";
    document.getElementById('ctl00_ContentPlaceHolder1_hdnEventTarget').value = "0";
    document.getElementById("ctl00_ContentPlaceHolder1_hdnRepPagNumber").value = curPage;
    objCurPage = document.getElementById(objIdCurPage)
    objCurPage.value = curPage
}
function PrintRepSearchResult(eventId) {
    var companyId = document.getElementById('repCompanyId').innerText;
    window.open("/MHCPNWWebApp/WebPages/PrintRepResult.aspx?pageId=" + eventId + "&cid=" + companyId, "PrintRep", "status=1, toolbar=1, ,scrollbars=yes");
}
//Purpose :	To select all the checkboxes
function ValidateSelectedRep(requestPage)
{
    var selectedCheckBox="" ;  
    lclForm = document.forms["aspnetForm"]
    elm = lclForm.elements
    for (i = 0; i < elm.length; i++)
    {
        if (elm[i].type == "checkbox" && elm[i].id != 'allRepSelect' && elm[i].id != 'chkRememberLogin')
        {  //alert(elm[i].id);
            if (elm[i].checked == true) {
                selectedCheckBox = elm[i].id + '|' + selectedCheckBox;
                var IdName = selectedCheckBox.replace(/ctl00_ContentPlaceHolder1_ctl03_chkRow/g, " ");
                }
        }
    }
    document.getElementById('ctl00_ContentPlaceHolder1_hdnCommon').value = IdName;
    document.getElementById('ctl00_ContentPlaceHolder1_hdnEventTarget').value = requestPage;
    
    if (selectedCheckBox.length > 0) {
        return true
    } else {
        alert("Please select one or more Representatives!")
        return false;
    }
}
//selecte all rep check box
function SelectAllCheckBoxes(selectedCheckBox)
{
    state = selectedCheckBox.checked
    var count = 0;
    lclForm = document.forms["aspnetForm"]
    elm = lclForm.elements
    for (i = 0; i < elm.length; i++)
    {
         if (elm[i].type == "checkbox" && elm[i].id != selectedCheckBox.id)
         {
             if (elm[i].checked != state)
             {
                elm[i].checked = state;
             }
         }
     }
 }
 //redirect to RFI
 function GotoRFI(source,selectedId) {
        
        //alert(repData)
        //alert(document.getElementById(repData).innerText);
        //var theform = document.forms["aspnetForm"];  
        //theform.__EVENTTARGET.value    = "RFI";
        //theform.__EVENTARGUMENT.value  = document.getElementById(repData).innerText;
        //theform.submit();
         
         var theform = document.forms["aspnetForm"];  
         theform.__EVENTTARGET.value    = "RFI";
         theform.__EVENTARGUMENT.value  = source +  "|" + selectedId;
         theform.submit();
        
     
 }
 //redirect content presentation page
 function RepProductLines_OnClick(CpPageNavigateUrl,ProductId) {
     //alert(ProductId);
    // window.location = CpPageNavigateUrl;
     
     var theform = document.forms["aspnetForm"];
     theform.__EVENTTARGET.value = "CP";
     theform.__EVENTARGUMENT.value = CpPageNavigateUrl +"|"+ ProductId;
     theform.submit();
 }
 
 //Purpose:when click on rep company web site
 function RepCompanyWebSiteLink(url,mid) {
     
     window.open(url, '', 'left=0,top=0, width=800, height=600,menubar=no, resizable=yes, toolbar=yes, location=yes, menubar=yes, scrollbars=yes');
     //webmetric for manufacture website
     var webMetricsUrl   = document.getElementById('ctl00_ContentPlaceHolder1_Surf_Aid_Url').value; 
     var parameterNames  = 'refer~mid~act';
     var parameterValues = url + '~' + mid + '~' + 'xrefer';
     //alert(webMetricsUrl);
     InsertWebMetricsDataCommon(parameterNames, parameterValues,webMetricsUrl, '~');
 }
 
function sellectedRep(selectedCheckBox){
}
//Purpose:trim the string.
function trimAll(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;
}
//Purpose:Check that current character is number.
function isInteger(s) {
    var i
    for (i = 0; i < s.length; i++) {
        // Check that current character is number.
        var c = s.charAt(i);
        if (((c < "0") || (c > "9"))) return false
    }
    // All characters are numbers.
    return true;
}
//Purpose:On click on MasterFormat search radio button
function DisableTxtSearchBy(){
    document.getElementById('ctl00_ContentPlaceHolder1_txtSearchTerm').value = ''
    document.getElementById('ctl00_ContentPlaceHolder1_txtSearchTerm').readOnly = true
    if (document.getElementById('ctl00_ContentPlaceHolder1_divCompanyResult') != null) {
        ctl00_ContentPlaceHolder1_divCompanyResult.style.display = "none"
    }
}
//Purpose : To enable the search bt text box
function EnableTxtSearchBy() {

    document.getElementById('ctl00_ContentPlaceHolder1_txtSearchTerm').value = ''
    document.getElementById('ctl00_ContentPlaceHolder1_txtSearchTerm').readOnly = false;
    //document.getElementById('hdnMove').value = ""
    if (document.getElementById('ctl00_ContentPlaceHolder1_divCompanyResult') != null) {
        ctl00_ContentPlaceHolder1_divCompanyResult.style.display = "none"
    }
}
//company popup selection color change
function ChangeColor(id) {
    if(document.getElementById(id)!=null)
        document.getElementById(id).setAttribute("className", "ArialBlackAlphabet");

}