﻿// JScript File
//pages - isd-code,port code, country_code, currency_code, unit_quantitycode,indian_portlist
//also used in depb rates
//For search text box validation
function PRODUCT() 
{
    var len=window.document.getElementById('ctl00_BodyContents_txt_searchbox').value.length;    
    if (len===0)
    {
        alert("Please Enter a Search Value !");
        return false;        
    }
    else
    {
    // Remove white space from beggining
    var str=document.getElementById('ctl00_BodyContents_txt_searchbox').value;    
    document.getElementById('ctl00_BodyContents_txt_searchbox').value = str.replace(/^\s+|\s+$/g,"");    
    return true; 
    }      
}


function ACCEPTNUM() 
{
    var len=window.document.getElementById('ctl00_BodyContents_txt_searchbox').value.length;    
    if (len===0)
    {
        alert("Please Enter a Search Value !");
        return false;        
    }
    else
    {
    // Remove white space from beggining
    var str=document.getElementById('ctl00_BodyContents_txt_searchbox').value;        
    return true; 
    }      
}




// Prevent user to enter anything except Strings
  function validate()         
    {
        var s=String.fromCharCode(event.keyCode);
        if(s >=48 || s<=57 && s!=' ')
        {
            event.returnValue=false;
        }
    }    
    
   
    
//for HSCODE>DEFAULT PAGE VALIDATION
    
/************* ALLOW USER TO ENTER ONLY NUMERIC VALUE IN HS CODE TEXTBOX****/
  
   function ValidateTextHscode(i) 
    {
        if(i.value.length>0) 
        {    
            i.value = i.value.replace(/[^\d]+/g, ''); 
        }    
    } 
   
  /****************************************************************************/
       
    function validateHscode()         // Prevent user to enter anything except numerics
    {
        var s=String.fromCharCode(event.keyCode);
        if(s <"0" || s>"9")
        {
            event.returnValue=false;
        }
    }
/*===============================================================
    THIS FUNCTION IS CALLLED ON PAGELOAD IN ORDER TO MAINTIAN 
    THE STATES OF SEAERCH PANNEL   
=================================================================*/
   function everytime()
   {
        var selected_radio= window.document.getElementById('ctl00_BodyContents_Radio_Hscode').checked; 
        var u_text = window.document.getElementById('ctl00_BodyContents_txt_HsCode').value;
        if(selected_radio)
        {
            document.getElementById('MyRow').style.display = 'none';           
            document.getElementById('ctl00_BodyContents_Lb_required_descripion').innerHTML = 'Enter HS Code';
        }
        else
        {
            document.getElementById('MyRow').style.display = '';           
            document.getElementById('ctl00_BodyContents_Lb_required_descripion').innerHTML = 'Enter Products Description';
        }
   }

window.onload = everytime;
   

/****************** CHECK WETHER HS CODE IS EMPTY OR NOT ******************/
function HSCODE() 
{
var selected_radio= window.document.getElementById('ctl00_BodyContents_Radio_Hscode').checked; 
var u_text = window.document.getElementById('ctl00_BodyContents_txt_HsCode').value.replace(/^\s+|\s+$/g,"");
document.getElementById('ctl00_BodyContents_txt_HsCode').value = u_text;

    // if hs code is selected
    if(selected_radio)
    {
        if(u_text.length === 0)
        {
                var msg1=    "Please enter HS CODE to be searched.\n";
                alert(msg1);
                document.getElementById('ctl00_BodyContents_txt_HsCode').focus();                
                return false;  
        }
        else        
        {
            if (isNaN(u_text))            
            {
                var msg2=    "HS Code should be a Numeric Value, minimum of 1 digit and maximum upto 8 digit.";
                msg2+=       "\n\nFor Example :";
                msg2+=       "\n1. 01 or 1\t\t: Search Hs codes at Chapter Level.";
                msg2+=       "\n2. 0101\t\t: Search Hs codes at Heading Level.";
                msg2+=       "\n3. 01011010\t: Search Full Hs codes at Prodcut Level.";                                
                msg2+=       "\n\nPlease note that you can search only one hs code at a time.\n";
                msg2+=       "If you are searching HS Code for your Products, then Please select ";
                msg2+=       "\nProduct option above and enter the description of your products.";
                
                
                alert(msg2);
                document.getElementById('ctl00_BodyContents_txt_HsCode').select();                
                return false; 
            }
            else
            {
                if(u_text.length > 8 )
                {                    
                    alert("Please note that maximum length of hs code should be 8 digit.");
                    document.getElementById('ctl00_BodyContents_txt_HsCode').focus();
                    return false; 
                }     
                else
                {       
                    return true;
                }
            }  
        } 
        
             
    }
    else
    {
        if(u_text.length === 0)
        {
                var msg=    "Please enter the Products Description seperated with white space or comma.";
                msg+=       "Then, select one of the following sub-options to find results with.\n\n";              
                msg+=       "All of the words\t:\n";              
                msg+=       "Results will include all of the words irrespective of their order of appearance.\n\n";          
                msg+=       "Any of the words\t:\n";          
                msg+=       "Results may include any one of the words or all of the words irrespective of their order of appearance.\n\n";
                msg+=       "Exact Phrase\t:\n";          
                msg+=       "Results will include the exact phrase in the same order as specified in the search box.\n";          
                
                
                alert(msg);
                document.getElementById('ctl00_BodyContents_txt_HsCode').select();                
                return false;  
        }
        else
        {
            return true;
        }
    }


}


/****************** CHECK WETHER PRODUCT NAME IS EMPTY OR NOT ******************/
function PRODUCT_HSCODEPAGE() 
{
if (window.document.getElementById('ctl00_BodyContents_txt_ProductName').value.length===0)
{
   alert("This Text box is to be removed later along with this messgae!");
   document.getElementById('ctl00_BodyContents_txt_ProductName').focus();
    return false; 
}
else
{   
// Remove white space from beggining
    var str=document.getElementById('ctl00_BodyContents_txt_ProductName').value;    
    document.getElementById('ctl00_BodyContents_txt_ProductName').value = str.replace(/^\s+|\s+$/g,"");    
    return true; 
}
}