/* 
 * To change this template, choose Tools | Templates
 * and open the template in the editor.
 */

function submit_form_report_search()
{
  document.searchForm.submit();
}
function reset_form_report_search()
{
  //var actionValue= document.forms['searchForm'].action.value;
  //alert('reset');
  //if (confirm("Are you sure you want to clear form?")) {
     //document.searchForm.reset();
  // }
  reset_form();
  
}

function reset_form()
{
     var searchForms = document.getElementsByName("searchForm");
     var searchForm = searchForms[0];
     
     searchForm.productFamilyIdArray.selectedIndex=-1;
    
     searchForm.productId.value="";     
     searchForm.productIdType.selectedIndex=0;

     
     
     searchForm.productDesc.value="";
     searchForm.productDescType.selectedIndex=0;
     
     searchForm.eccn.value="";
     searchForm.eccnType.selectedIndex=0;
     
     searchForm.ccat.value="";
     searchForm.ccatType.selectedIndex=0;
     
     searchForm.encStatus.selectedIndex="";
     //searchForm.encStatusType.selectedIndex=0;
     
     //searchForm.encStrength.value="";
     //searchForm.encStrengthType.selectedIndex=0;
     searchForm.encryptionLevelDesc.selectedIndex=0;
     
     searchForm.dcssiNumber.value="";
     searchForm.dcssiNumberType.selectedIndex=0;     
     
     searchForm.hsCountry.selectedIndex=0;
     searchForm.hsNumber.value="";
     searchForm.hsNumberType.selectedIndex=0;


}



function updateProductIdSearchType(){

   var searchForms = document.getElementsByName("searchForm");
   var searchForm = searchForms[0];
   var productId = searchForm.productId.value;
   ///alert (productId.lastIndexOf(','))
   //alert (productId.length);
   //if ((productId.lastIndexOf(',')+1) ==productId.length ){
   //   productId = productId.substring(0,productId.length-1);      
   //}
   
   productId=replace_xls_str(productId,'\n',',');
   searchForm.productId.value=productId;
   
   var psize = productId.split(",").length;
   if (productId.length>0){
      document.getElementById('prodIdCount').innerHTML='Count = '+psize;
   }else{
      document.getElementById('prodIdCount').innerHTML=''; 
   }
   if (productId.indexOf(',')>-1){
       searchForm.productIdType.selectedIndex=3;
       searchForm.productIdType.disabled=true;
   }else{
      searchForm.productIdType.disabled=false;
   }
   searchForm.productId.focus();

}


function getPage(pageElement){   
    var pageIdx = pageElement.selectedIndex;
    var page = pageElement.options[pageIdx].value;
    //alert('PageRequested='+page);
    document.forms['searchForm'].newPage.value=page;
    //DWR code
    //var formObj = dwr.util.getFormValues("searchForm");    
    //formObj.newPage = page;    
    //callDwr(formObj);
    document.forms['searchForm'].submit();
}

function getNextPage(page) {
    
    document.forms['searchForm'].newPage.value=page;
    //DWR code
    //var formObj = dwr.util.getFormValues("searchForm");    
    //formObj.newPage = page;    
    //callDwr(formObj);
   document.forms['searchForm'].submit();
}

function getPreviousPage(page) {
    
    document.forms['searchForm'].newPage.value=page;
    //DWR code
    //var formObj = dwr.util.getFormValues("searchForm");    
    //formObj.newPage = page;    
    //callDwr(formObj);  
    document.forms['searchForm'].submit();
}

function modifySearch() {     
     document.forms['searchForm'].action.value='search';
     document.searchForm.submit();
}
function submitDownloadForm(){    
    document.forms['downloadForm'].action.value='download';
    document.downloadForm.submit();
}

var now = new Date();
var shortWidth = 5;
var multiple = 2.5;
function displayProgressBar() {

    with (document.all) {
        progressBarBlock.style.setExpression("width","now.getSeconds() * shortWidth","jscript");
        progressBarLabel.setExpression("innerHTML","now.getSeconds()","jscript");
    }
    updateProgressBarClock();
}
function updateProgressBarClock() {
    now = new Date();
    document.recalc();
    setTimeout("updateProgressBarClock()",1000);
}

//DWR code
/*
function callDwr(formObj) {
    
    dwr.util.setValue("resulttablediv", "", { escapeHtml:false });
    SearchDWRManager.getNextPageQ(formObj,callbackJSPInclude);            
}

callbackJSPInclude=function(data) {             
    dwr.util.setValue("resulttablediv", data, { escapeHtml:false });
};

*/

function replace_xls_str(string,text,by) {
    // Replaces text with by in string
    var strLength = string.length, txtLength = text.length;
    
    if ((strLength == 0) || (txtLength == 0)) return string;

    var i = string.indexOf(text);
    if ((!i) && (text != string.substring(0,txtLength))) return string;
    if (i == -1) return string;
    
    
    var strBefore= string.substring(i-2,i-1);
    var strAfter= string.substring(i+2,i+1);
    var newstr="";
    
    if ((strBefore!=by) &&(strAfter!=by)){                                        
       newstr = string.substring(0,i) + by;
    }else{
       newstr = string.substring(0,i);
    }

    if (i+txtLength < strLength){
        newstr += replace_xls_str(string.substring(i+txtLength,strLength),text,by);
    }

    return newstr;
    
}

function pepd_open_ext_window(url){

popupWin = window.open(url,
  'pepdextwindow',
  'menubar=yes, toolbar=yes, location=yes, directories=yes, status=yes, scrollbars, resizable, dependent, width=640, height=480, left=0, top=0');

}




