﻿// JScript File
  
//following function is used on the My-Search-Page.aspx
    function resetalldemo()
        {   
            //uncheck all the checkboxes start here
            UncheckAll();
                    
            window.document.getElementById("ctl00_BodyContents_rdbExport").checked = true;    
            window.document.getElementById("ctl00_BodyContents_rdbImport").checked = false;
            window.document.getElementById("ctl00_BodyContents_txtproduct").value = "";
            window.document.getElementById("ctl00_BodyContents_rdb_use_wild_card").checked = false;    
            window.document.getElementById("ctl00_BodyContents_rbd_dont_use_wild_card").checked = true;
            window.document.getElementById("ctl00_BodyContents_txthscode").value = "";
            window.document.getElementById("ctl00_BodyContents_txtexpimp").value = "";
            window.document.getElementById("ctl00_BodyContents_Chk_Month_List_0").checked = true;       
            window.document.getElementById("ctl00_BodyContents_Chk_Month_List_1").checked = false;           
            window.document.getElementById("ctl00_BodyContents_chkindianport_0").checked = true;
            window.document.getElementById("ctl00_BodyContents_txtforeigncontry").value = "";
            window.document.getElementById("ctl00_BodyContents_txtforeignport").value = "";     
            return false;         
        }           
    
    
//Uncheck all the checkboxes of the current page
    function UncheckAll()
    {
        for (var n = 0; n < document.forms[0].length; n++)
            if (document.forms[0].elements[n].type === 'checkbox')
                    document.forms[0].elements[n].checked = false;
                    
            return false;   
    }    
    
    
   
//only numbers,backspace,comma can enter using the following function
function hscode_validation(e)
{  
    var code;   
    e = e || window.event;
    if (e.keyCode) 
        {
            code = e.keyCode;
        } 
    else if (e.which) 
        {
            code = e.which;
        }

    if ((code === 32) || (code === 37)) 
        {
        e.cancelBubble = true;
        e.returnValue = false;

        if (e.stopPropagation) 
            {
                e.stopPropagation();
                e.preventDefault();
            }
        return false;
        }
   
    if((code < 48 || code >57) && (code !== 8) && (code !== 44))
    {
        e.cancelBubble = true;
        e.returnValue = false;
        
         if (e.stopPropagation) 
            {
                e.stopPropagation();
                e.preventDefault();
            }
            
        return false;   
    }      
}  
    
//only alpha and comma can enter for country
function forcountry_validation(e)
{  
    var code;   
    e = e || window.event;
    if (e.keyCode) 
        {
            code = e.keyCode;
        } 
    else if (e.which) 
        {
            code = e.which;
        }

   
if((code < 65 || code > 90) && (code < 97 || code > 122) && (code !== 32) && (code !== 8) && (code !== 44))
    {
        e.cancelBubble = true;
        e.returnValue = false;
        
         if (e.stopPropagation) 
            {
                e.stopPropagation();
                e.preventDefault();
            }
            
        return false;   
    } 
   
if ((code > 106 && code < 111) && (code > 186 && code < 191) && (code >  219 && code < 222) && (code !== 188) && (code !== 108)) 
   {    
        e.cancelBubble = true;
        e.returnValue = false;

        if (e.stopPropagation) 
            {
                e.stopPropagation();
                e.preventDefault();
            }
        return false;
   }     
}        
    
//only alpha and comma can enter for country
function forport_validation(e)
{  
    var code;   
    e = e || window.event;
    if (e.keyCode) 
        {
            code = e.keyCode;
        } 
    else if (e.which) 
        {
            code = e.which;
        }

   
if((code < 65 || code > 90) && (code < 97 || code > 122) && (code !== 32) && (code !== 8) && (code !== 44))
    {
        e.cancelBubble = true;
        e.returnValue = false;
        
         if (e.stopPropagation) 
            {
                e.stopPropagation();
                e.preventDefault();
            }
            
        return false;   
    } 
   
if ((code > 106 && code < 111) && (code > 186 && code < 191) && (code >  219 && code < 222) && (code !== 188) && (code !== 108)) 
   {    
        e.cancelBubble = true;
        e.returnValue = false;

        if (e.stopPropagation) 
            {
                e.stopPropagation();
                e.preventDefault();
            }
        return false;
   }     
} 


//product textbox validation for length

function product_validation()
{
     var sat_tempprod = window.document.getElementById('ctl00_BodyContents_txtproduct').value;  
    
    if(sat_tempprod.match(',') === null)
    {
        if ((window.document.getElementById('ctl00_BodyContents_txtproduct').value.length < 3) && (window.document.getElementById('ctl00_BodyContents_txtproduct').value.length !== 0))
            {
            alert('Please Provide Product Details At Least 3 Characters.\n\n  (Excluding Comma( i.e. ( , ))');            
            return false;
            }
    }
    else
    {
        if ((window.document.getElementById('ctl00_BodyContents_txtproduct').value.length < 4) && (window.document.getElementById('ctl00_BodyContents_txtproduct').value.length !== 0))
            {
            alert('Please Provide Product Details At Least 3 Characters.\n\n  (Excluding Comma( i.e. ( , ))');            
            return false;
            }
    }    
}


//hscode textbox validation for length

function hs_valid()
{  
     var sat_hsvalue = window.document.getElementById('ctl00_BodyContents_txthscode').value;
    //check if product is given or not
    if ((window.document.getElementById('ctl00_BodyContents_txtproduct').value.length === 0) && (sat_hsvalue.length !== 0))
    {   //check if comma is available in the hscode or not
        if(sat_hsvalue.match(',') === null)
        {
                if (sat_hsvalue.length < 4)
                    {
                    alert('Please Provide HsCode Details At Least 4 Digits.\n\n  (Excluding Comma( i.e. ( , ))');                              
                    return false;                          
                    }
        }
        else
        {
                if (sat_hsvalue.length < 5)
                    {
                    alert('Please Provide HsCode Details At Least 4 Digits.\n\n  (Excluding Comma( i.e. ( , ))');                              
                    return false;                          
                    }       
        }   
    }
    else
    {
        if((window.document.getElementById('ctl00_BodyContents_txtproduct').value.length > 2) && (sat_hsvalue.length !== 0))
            {
                //check if comma is available in the hscode or not
                if(sat_hsvalue.match(',') === null)
                    {                       
                         if ((sat_hsvalue.length === 1))
                            {               
                                window.document.getElementById('ctl00_BodyContents_txthscode').value = '';
                                window.document.getElementById('ctl00_BodyContents_txthscode').value = '0' + sat_hsvalue;
                                return false;       
                            }                     
                    }       
                else
                    {
                            if ((sat_hsvalue.length < 3))
                            {               
                                window.document.getElementById('ctl00_BodyContents_txthscode').value = '';
                                window.document.getElementById('ctl00_BodyContents_txthscode').value = '0' + sat_hsvalue;
                                return false;       
                            }                     
                    }                   
            }    
    }   
} 


 //the following function is used in Demo-Search/Default.aspx    
function reqiuredfield_ondemo()
    {  
        
        var hs_value = window.document.getElementById('ctl00_BodyContents_txthscode').value;
        var prod_value = window.document.getElementById('ctl00_BodyContents_txtproduct').value;
        var sat_month_var1 = window.document.getElementById("ctl00_BodyContents_Chk_Month_List_0").checked;     
        var sat_month_var2 = window.document.getElementById("ctl00_BodyContents_Chk_Month_List_1").checked;               
        
        
                    if((hs_value.length === 0) && (prod_value.length === 0))
                    {   
                            alert('Please Provide HsCode At-Least 4 Digits Or Product With 3 Characters.\n\n  (Excluding Comma( i.e. ( , ))');                            
                            return false;            
                    }
    
                    if(prod_value.match(',') === null)
                    {
                        if ((window.document.getElementById('ctl00_BodyContents_txtproduct').value.length < 3) && (window.document.getElementById('ctl00_BodyContents_txtproduct').value.length !== 0))
                            {
                                alert('Please Provide Product Details At Least 3 Characters.\n\n  (Excluding Comma( i.e. ( , ))');            
                                return false;
                            }
                    }   
                    else
                    {
                        if ((window.document.getElementById('ctl00_BodyContents_txtproduct').value.length < 4) && (window.document.getElementById('ctl00_BodyContents_txtproduct').value.length !== 0))
                            {
                                alert('Please Provide Product Details At Least 3 Characters.\n\n  (Excluding Comma( i.e. ( , ))');            
                                return false;
                            }
                    } 
                   
            //check if product is given or not
                    if ((window.document.getElementById('ctl00_BodyContents_txtproduct').value.length === 0) && (hs_value.length !== 0))
                    {   //check if comma is available in the hscode or not
                        if(hs_value.match(',') === null)
                            {
                                if (hs_value.length < 4)
                                    {
                                        alert('Please Provide HsCode Details At Least 4 Digits.\n\n  (Excluding Comma( i.e. ( , ))');                              
                                        return false;                          
                                    }
                            }
                            else
                            {
                                if (hs_value.length < 5)
                                {
                                    alert('Please Provide HsCode Details At Least 4 Digits.\n\n  (Excluding Comma( i.e. ( , ))');                              
                                    return false;                          
                                }       
                            }   
                    }
                    else
                    {
                    if((window.document.getElementById('ctl00_BodyContents_txtproduct').value.length > 2) && (hs_value.length !== 0))
                    {
                        //check if comma is available in the hscode or not
                        if(hs_value.match(',') === null)
                            {                       
                                if (hs_value.length === 1)
                                    {               
                                        window.document.getElementById('ctl00_BodyContents_txthscode').value = '';
                                        window.document.getElementById('ctl00_BodyContents_txthscode').value = '0' + hs_value;
                                        return false;       
                                    }                     
                            }       
                            else
                            {
                                if (hs_value.length < 3)
                                    {               
                                        window.document.getElementById('ctl00_BodyContents_txthscode').value = '';
                                        window.document.getElementById('ctl00_BodyContents_txthscode').value = '0' + hs_value;
                                        return false;       
                                    }                     
                            }                   
                      }    
                    } 
                    
                     if((sat_month_var1 === false) && (sat_month_var2 === false))
                    {   
                            alert("Please Provide At Least Single Month For Searching Data !");
                            return false;        
                    }
        
        
                    ProgressImage = document.getElementById('progress_image');                  
                    setTimeout("ProgressImage.src = ProgressImage.src",100);                                    
                    document.getElementById("divsearch").style.display = 'block';                        
                    document.getElementById('ctl00_BodyContents_lblsearch').innerHTML = "Data Mining is in Progress, It will Take Time So Please Wait........";                                                        
     
    }
  

//this function for select All indian port or another sepecific port name
function Select_Ind_Port(checkBoxListId, totalItem, selectedCheckBoxId)
{
    if(selectedCheckBoxId === (checkBoxListId + '_' + 0))
    {   
        for(var i = 0; i < parseInt(totalItem); i++)
        { 
            document.getElementById(checkBoxListId + '_' + i).checked = false;                            
        }
        document.getElementById(checkBoxListId + '_' + 0).checked = true;
    }
    else
    {
        document.getElementById(checkBoxListId + '_' + 0).checked = false;
        
    } 
    return false;    
}


//only single month selection checkbox facility

function SelectSingleCheckBox(checkBoxListId, totalItem, selectedCheckBoxId)
{
    var isSelected = document.getElementById(selectedCheckBoxId).checked;        
        for(var i = 0; i < parseInt(totalItem); i++)
        { 
            if ((document.getElementById(checkBoxListId + '_' + i).checked == true))
            {     
                document.getElementById(checkBoxListId + '_' + i).checked = false;                            
            }                           
        }       
         document.getElementById(selectedCheckBoxId).checked = true;            
}