function CallBusToFillCombo(BasePath,BusName,ParentID,Control_id,Lable)
{
    var sURL;
    sURL=BasePath+"/DataBus.aspx?ParentID="+ParentID+"&BusName="+BusName+"&Lable=" + Lable;
  //alert(sURL);
	makeAjaxRequest(sURL,"FillCombo('"+Control_id+"',XML_OBJECT)");
}
/////////////////////////////////////////////////////////////////////////////////////////
function FillCombo(Control_id,xmlObj)
{
	var oCombo = document.getElementById(Control_id);
	
	if (oCombo!=null)
	{
	    for (var i=oCombo.options.length;i>=0;i--)
		    oCombo.options[i] = null;
    		
	    var oCombo = document.getElementById(Control_id);
    	
	    var busData = xmlObj.selectNodes("//BusRows/BusRow");
    	if (busData!=null){//alert(busData.length);
            //alert("BusRows" + getSingleNode(getSingleNodeByPosition(busData,0),"Name"));
            for (var i=0;i<busData.length;i++)
            { //alert();
                var sText = getSingleNode(getSingleNodeByPosition(busData,i),"Name");
                var sValue = getSingleNode(getSingleNodeByPosition(busData,i),"ID");
           
                //alert("sText=" + sText + "  sText=" + sValue );
                if (sText!=null && sValue !=null && sText!='' && sValue !='')
                {
                 //alert(i + i);
	                oCombo.options[oCombo.options.length] = new Option(sText,sValue);
	            }
            }
	    }
	}
}

function CallBusToUpdate(BasePath,BusName,CtrlID,ID,CtrlForOtherIDs,sOtherIDs,CartCircleID)
{
    //alert(sOtherIDs);
    var sURL;
    //var sOtherIDs;

    /*if (sOtherIDs==null || sOtherIDs=="")
    {
        //alert('2');
        var oCtrlForOtherIDs =document.getElementById(CtrlForOtherIDs);
        //alert(oCtrlForOtherIDs.selectedIndex);
        if (oCtrlForOtherIDs!=null)
        { //for cart/favourite: it is size ids CSV. //Concept is changed now quantity is passing in it now
            if(oCtrlForOtherIDs.selectedIndex<=0)
            {
                alert("Please select quantity!");
                return;
            }
            else
            {
                sOtherIDs=oCtrlForOtherIDs.options[oCtrlForOtherIDs.selectedIndex].value;
                //alert(oCtrlForOtherIDs.options[oCtrlForOtherIDs.selectedIndex].value);
            }
        }
          else
          {
           alert("Please select quantity!");
           return;
          }
         
    } */
    
    if(ID!=null)
    {
        if(ID!="")
        {
            //alert(ID);
            //alert('3');
            if(sOtherIDs!="")
            {
                //alert('4.1');
                sURL=BasePath+"/UpdateBus.aspx?id="+ ID + "&BusName=" + BusName + "&Passengers=" + sOtherIDs;
            }
            else
            { 
                //alert('4.2');
                sURL=BasePath+"/UpdateBus.aspx?id=" + ID + "&BusName=" + BusName;
            }
            //alert(sURL);
          //alert(CartCircleID);
            if (CartCircleID!=null && CartCircleID!="")
            {
                //alert('5.1');
                makeAjaxRequest(sURL,"ShowMessage(XML_OBJECT,'" + CartCircleID + "')");
            }
            else
            {
                //alert('5.2');
                
                makeAjaxRequest(sURL,"ShowMessage(XML_OBJECT)");
            }
        }
     }
}

function CallBusToEmptyCartList(BasePath,BusName,Control_ID,EmptyTextID)
{
    var sURL;   
   
    sURL=BasePath+"/UpdateBus.aspx?BusName="+BusName;
    
    makeAjaxRequest(sURL,"ShowMessage(XML_OBJECT)");
    oCtrl = document.getElementById(Control_ID);
    if (oCtrl!=null)
    {
        oCtrl.style.display="none";
        divValue.style.display="none";
        document.getElementById(EmptyTextID).style.display = "block";
        document.getElementById(EmptyTextID).style.visibility = "visible";
    }
}

function CallBusToPayPal(BasePath)
{
    //alert('yes');
    var sURL;   
    sURL=BasePath+"/UpdateBus.aspx?BusName=PayPal";
    makeAjaxRequest(sURL,"ShowMessage(XML_OBJECT)");
    return true;
}

function CallBusToDelete(BasePath,BusName,Control_ID,ID,OtherID,CartCircleID,EmptyCtrlID,MainCtrlID )
{
    var sURL;
    if(ID!=null){
        if(ID!=""){
            if (OtherID==null || OtherID=="")
                sURL=BasePath+"/UpdateBus.aspx?id="+ID+"&BusName="+BusName;
            else
                sURL=BasePath+"/UpdateBus.aspx?id="+ID+"&BusName="+BusName+"&Passengers="+OtherID;
           //alert(sURL);
            makeAjaxRequest(sURL,"ShowMessage(XML_OBJECT,'"+ CartCircleID +"','"+EmptyCtrlID+"','"+MainCtrlID+"')");
            oCtrl = document.getElementById(Control_ID);
            if (oCtrl!=null){
                oCtrl.style.display="none";
                oCtrl.style.visibility="hidden";
            }
        }
	    else{
	        alert("Item not found!");
	    }    
	 }
	 else{
	    alert("Item not found!");
	 }
}

function ShowMessage(xmlObj, CartCircleID,EmptyCtrlID, MainCtrlID )
{
    //alert();
    //alert("CartCircleID=" + CartCircleID);
    var busUpdateMessage = xmlObj.selectNodes("//Messages/Message");
    if (busUpdateMessage!=null)    
    {
        var sText;
        var sValue;
        var oObj = getSingleNodeByPosition(busUpdateMessage,0);
        
        if (oObj!=null)
        {
            sText = getSingleNode(oObj,"TextMessage");
            //sValue = getSingleNode(getSingleNodeByPosition(busUpdateMessage,0),"Value");
            if (sText!=null)
            {
                if (sText!="" && sText!="na")
                {
                    alert(sText);
                }
            }
        }
    }
}
