﻿// JScript File


    var xmlHttp = null;
    var display = null;
    var char_count = null;
    var start_alp = 'a';
    var timeoutSet = false;
    var downloadOK = false;
    var wardXmlDoc = null;
    var timer;
    var count=0;   
    var className="col3";  
    
    var wCount = 30;


    //var loading=document.getElementById("loading");
    
    window.onload = function() { 
        var curr = window.location.pathname;
        curr=curr.toLowerCase();
        if(curr.indexOf("companylist")>0)   
            {jsCategory(start_alp,'col1',200,100);}
        else if(curr.indexOf("categorylist")>0)
            {jsCategory(start_alp,'col3',200,100);}//alert("Category list");
        else 
            {jsCategory(start_alp,'col3',15,35);}
       //if (document.getElementById("span_category")){alert("0k"); jsCategory('a','col3',35);}       
    }
      
    //====================================================function for category
    function jsCategory(alp,disp,l_count,w_count){
          
        var t=setTimeout("ShowAlert('Category')",120000); //2 minutes time out        
        document.getElementById("catLoading").style.display="block";
        className = disp;
        wCount = w_count;
        start_alp = alp;     
        try
        {         
            loadService('getCategory', alp,l_count,'onCategory()'); 
        }   
        catch(e){                
                alert("Error Occurred! \n\n" + e.message);
                document.getElementById("curLoading").style.display="none";
            }            
        
    }
   
    ///=====================================================function for load service
        function loadService(func,parm,listcount,call) { 

                if(call== 'onCategory()')
                    {
                        Mdg.AspNet.WebService.getCategory(parm,listcount,onCategory,FailedCallback);
                    }
                else
                    {   
                        Mdg.AspNet.WebService.currency_convert(parm,onCurrency,FailedCallback);
                    }
        }
//===============================function for category ====================
function onCategory(result) {
        
      
        //var span = document.getElementById("span_category");  
       // span.innerHTML = result;
        var xmlDoc = result;
                   
                   xmlDoc = xmlDoc.substring(xmlDoc.indexOf("~")+1,xmlDoc.indexOf("^"));
                   
                   xmlDoc = xmlDoc.split("|");
                   
                    var str="<ul id="+ className +">";
                    var i=0;
                    for (i=0;i<xmlDoc.length;i++){
                       if (xmlDoc[i].length> wCount) {
                            temp = xmlDoc[i].substring(0,wCount)+"...";
                       }else{
                            temp = xmlDoc[i];
                       }
                        str +="<li title='"+ xmlDoc[i] +"'><a href='CompanyList.aspx?sub_cat=" +xmlDoc[i]+ "'>"+ temp.substring(temp.indexOf("~")+1,temp.length) + "</a></li>";
                    }
                    str +="</ul>";
                    var span = document.getElementById("span_category");  
                    span.innerHTML = str;//xmlDoc;  
        document.getElementById("catLoading").style.display="none";                         
}


///==============================================

//===============================================


function TimerTick()
{
    var catTimer= document.getElementById("catTimer");
    //alert("Test");
    if(catTimer.Interval>0)
        {
            document.getElementById("catLoading").style.display="block";
            alert("Service call timed out.");
        }
}
function setInterval()
{
    
}
function OnTimeOut() {
    alert("Timed Out.");
    document.getElementById("catLoading").style.display="block";
    
}

function OnError(args) {
        var RsltElem = document.getElementById("span_category");
    RsltElem.innerHTML = "Service Error: " + error.get_message();
}
function FailedCallback(error)
{
    // Display the error.    
    var RsltElem = 
        document.getElementById("ResultId");
    RsltElem.innerHTML = 
    "Service Error: " + error.get_message();
}
function ShowAlert(parm)
{
    if (parm=="Category")
    {
        if (document.getElementById("catLoading").style.display=="block")
            alert("Connection Time Out");
    }
    else if (parm=="Currency")
    {
        if(document.getElementById("curLoading").style.display=="block")
            alert("Connection Time Out");
    }
    
}
