 
/*---------------------------------------------------------------------------------------------------------
 Suchithsoft Common JavaScript Library

Find - Find an element in a List

IsError - Displays an Error

IsEmpty - checks if string is Empty
ExitForm - this routine will prompt if user has changed data without saving
OpenNewWindow - Open New Window using url & other Parameters

AutoSizeWindow - will size a window to the right size based upon it's content.
-----------------------------------------------------------------------------------------------------------*/



//IsEmpty - checks if string is Empty
function IsEmpty(text) {
  if (text == "") return true;
  text = text.toString();		
  for (var i = 0; (i < text.length); i++) {
  	if (text.charAt(i) == " ") continue;
  	else return false; 
  }
  return true;	  
}

// Find an element in the list
// Arguments: 1) the select list, 2) the textbox
function Find(list, text)
{

  // find the first matching
  if( text.value.length > 0){
    for( var i = 0; i < list.length; i++){
      if( list.item(i).text.substr(0,text.value.length).toUpperCase() == text.value.toUpperCase()){
        list.options[i].selected = true;
        return true;
      }
    }
  }
  return false;
}


//IsError - Displays an Error
function IsError(elem, text, bSelect) {
// display the first error
   var ss;

   if (typeof(text)  == "undefined") { window.alert("Undefined error."); this.select()}
   window.alert(text);
   if (typeof(elem)  == "undefined") {return}
   if (elem == "n"){return}
   if (elem.disabled == true) {return}
   if (bSelect != "false") {
      if (bSelect != "combo") {          
        try {
      	  document.forms[0].elements[elem.name].focus();        
      	  document.forms[0].elements[elem.name].select();        
      	}
      	catch (any) { }
      }
   };
   errorfound = true;
}

function IsDataChanged(obj)
{
    if (!(obj.defaultValue == obj.value))
    {	
	    document.getElementById("hdnDataChanged").value="1";
    }
}

function ErrorDisplay(isValid)
{
	if (!isValid)
	{
	    sumAlert = strMandatory + sumAlert; 
	    document.getElementById("ctl00_ErrorArea_lblErrorMessage").innerHTML="";
	    document.getElementById("ctl00_ErrorArea_lblErrorMessage").innerHTML=sumAlert;
	    document.getElementById("ctl00_ErrorArea_lblErrorMessage").className="ErrorMsg";
	    document.getElementById("ErrorAreaTD").className="ErrorMsgTD";
	    windowResize();	    
	    return false;
	}
    else
    {
       document.getElementById("ctl00_ErrorArea_lblErrorMessage").innerHTML="";
       document.getElementById("ctl00_ErrorArea_lblErrorMessage").className="ErrorMsgDefault";
	   document.getElementById("ErrorAreaTD").className="ErrorMsgTDDefault";
	    windowResize();	 
        return true;			   	  
	}
}


function ErrorDisplay(isValid)
{

	if (!isValid)
	{
	    sumAlert = strMandatory + sumAlert; 
	    document.getElementById("ctl00_ErrorArea_lblErrorMessage").innerHTML="";
	    document.getElementById("ctl00_ErrorArea_lblErrorMessage").innerHTML=sumAlert;
	    document.getElementById("ctl00_ErrorArea_lblErrorMessage").className="ErrorMsg";
	    document.getElementById("ErrorAreaTD").className="ErrorMsgTD";
	    windowResize();	    
	    return false;
	}
    else
    {
       document.getElementById("ctl00_ErrorArea_lblErrorMessage").innerHTML="";
       document.getElementById("ctl00_ErrorArea_lblErrorMessage").className="ErrorMsgDefault";
	   document.getElementById("ErrorAreaTD").className="ErrorMsgTDDefault";
	    windowResize();	 
        return true;			   	  
	}
}

function SearchErrorDisplay(isValid)
{

	if (!isValid)
	{
	    sumAlert = strMandatory + sumAlert; 
	    document.getElementById("ctl00_ErrorArea_lblErrorMessage").innerHTML="";
	    document.getElementById("ctl00_ErrorArea_lblErrorMessage").innerHTML=sumAlert;
	    document.getElementById("ctl00_ErrorArea_lblErrorMessage").className="ErrorMsg";
	    document.getElementById("ErrorAreaTD").className="SearchErrorMsgTD";
	    windowResize();	    
	    return false;
	}
    else
    {
       document.getElementById("ctl00_ErrorArea_lblErrorMessage").innerHTML="";
       document.getElementById("ctl00_ErrorArea_lblErrorMessage").className="ErrorMsgDefault";
	   document.getElementById("ErrorAreaTD").className="SearchErrorMsgTDDefault";
	    windowResize();	 
        return true;			   	  
	}
}

//SaveForm
function SaveForm()
{
    if (document.getElementById("hdnSave")==null) {return}	
    document.getElementById("hdnSave").value="1";
}


//ExitForm
function ExitForm() 
{
  //this routine will prompt if user has changed data without saving
  //hdnDataChanged is required form variable.  Caller should set it = 1 if he wants to bypass this routine	
    if (document.getElementById("hdnDataChanged")==null) {return}
    if (document.getElementById("hdnSave")==null) {return}	
    if (typeof(document.forms[0].elements["hdnSave"]) == "undefined") {return}	
	if (typeof(document.getElementById("hdnDataChanged")) == "undefined") {return}	
	if (typeof(document.forms[0].elements["hdnSave"]) != "undefined" && document.getElementById("hdnSave").value=="1") {document.getElementById("hdnSave").value="0"; return}	
	
	try
	{
        if (typeof(document.activeElement.href) != "undefined") {
	      if (document.activeElement.href.indexOf("CableNetServices") > 0) {return}
            
	    }
	 }
	 catch(any)
	 {
	    return;
	 }
	//trigger a onBlur, which will trigger the hdnDataChanged, in case they made a change without leaving the control	
//	if (typeof(document.activeElement) != "undefined" && typeof(document.activeElement.name) != "undefined") 
//	{
//	   IsDataChanged(document.activeElement);
//	}	  
	if (document.getElementById("hdnDataChanged").value == "1") { 
	  event.returnValue="Do you want to loose changes?"; 
	  __doPostBack("ctl00_AppendArea_imgBtnSaveExit");   
	  //alert('WARNING: Do you want to save changes?');	
	}	
}



//Open New Window
function OpenNewWindow(url, windowName, windowSize)
{
    
    window.open(url, windowName, windowSize + ',width=480,left=400,toolbar=no,resizable=Yes,fullscreen=no,status=Yes,location=no,scrollbars=no, menubar=no');
    return false;
//    while (self.userWin == null) {}  
//	userWin.location = url + '?' + Parameters;
}

//Open New Window
function OpenNewWindowPAA(url, windowName, windowSize)
{
    
    window.open(url, windowName, windowSize + ',width=480,left=400,toolbar=no,resizable=Yes,fullscreen=no,status=Yes,location=no,scrollbars=yes, menubar=no');
    return false;
//    while (self.userWin == null) {}  
//	userWin.location = url + '?' + Parameters;
}

 function StatusBarMsgClear()
{
    document.getElementById('StatusBar').innerText='';
}  

function OpenNewMemberWindow()
{
    if(document.getElementById('ctl00_txtQuickLinksSearch') != null)
    {
        document.getElementById('ctl00_txtQuickLinksSearch').focus();
    }
    window.open('Members.aspx', 'CableNetServicesMain', 'toolbar=no,resizable=yes,fullscreen=no, status=Yes, location=No,scrollbars=yes, menubar=no');
}

function StatusBarMsg(item)
{

    if (item.id == "ctl00_AppendArea_imgBtnSave")
    {
        document.getElementById('StatusBar').innerText = 'Save';
    }
    else if(item.id == "ctl00_AppendArea_imgBtnSaveExit")
    {
        document.getElementById('StatusBar').innerText = 'Save & Exit';
    }
    else if(item.id == "ctl00_AppendArea_imgBtnDelete")
    {
        document.getElementById('StatusBar').innerText = 'Delete';
    }
    else if(item.id == "ctl00_AppendArea_imgBtnRefresh")
    {
        document.getElementById('StatusBar').innerText = 'Refresh';
    }
     else if(item.id == "ctl00_SearchInput_imgBtnSearch")
    {
        document.getElementById('StatusBar').innerText = 'Search';
    }
     else if(item.id == "ctl00_SearchResult_imgBtnAdd")
    {
        document.getElementById('StatusBar').innerText = 'Add';
    }
     else if(item.id == "ctl00_SearchResult_imgBtnExcel")
    {
        document.getElementById('StatusBar').innerText = 'Export to Excel';
    }
     else if(item.id == "ctl00_SearchResult_imgBtnPrint")
    {
        document.getElementById('StatusBar').innerText = 'Print to PDF';
    }    
    else if(item.id == "btnLogin")
    {
        document.getElementById('StatusBar').innerText = 'Login';
    }    
    else if(item.id == "btnContinue")
    {
        document.getElementById('StatusBar').innerText = 'Continue';
    }  
    else if(item.id == "ctl00_SearchResult_wpmWorkSheet_gwppanelWH_imgBtnSearch")
    {
        document.getElementById('StatusBar').innerText = 'Search';
    }  
    else if(item.id == "ctl00_SearchResult_wpmWorkSheet_gwppanelWH_btnSave")
    {
        document.getElementById('StatusBar').innerText = 'Save the Status';
    } 
    else if(item.id == "ctl00_SearchResult_wpmWorkSheet_gwppanelWD_btnSaveDetails")
    {
        document.getElementById('StatusBar').innerText = 'Save the Details';
    }  
    else
    {		
        document.getElementById('StatusBar').innerText = 'Enter ' + item.getAttribute("DisplayName");
    }
    
}

//Expanding the Grid Grouping data with nested Grouping Data
function grid_AfterXmlHttpResponseProcessed(gridName, rowId)
    {
        
        var oGrid =igtbl_getGridById(gridName);
        
        var oBands = oGrid.Bands;
        var oBand = oBands[0];

        var oRows = oGrid.Rows;
        oGrid.suspendUpdates(true);

        for(i=0; i<oRows.length; i++) 
       {
            
            oRow = oRows.getRow(i);
            oRow.setExpanded(true);
            
            if (oRow.ChildRowsCount>0)
            {
                IsChildRowsExpend(oRow)
            }
        }

    }
        
    function IsChildRowsExpend(oRow)
    {
        for (j = 0; j < oRow.ChildRowsCount; j++)
        {
        
            if (oRow.Rows.rows[j] != null)
            {
            oGroupRow = oRow.Rows.rows[j];
            if (oGroupRow != null)
            {
                oGroupRow.setExpanded(true);
                if (oGroupRow.ChildRowsCount>0)
                {
                    IsChildRowsExpend(oGroupRow)
                }
            }
            }
        }
    }
    
function dateChooser_OnBlur(oDateChooser, dummy, oEvent)
{
    if(oDateChooser.getValue() == null)
    {
        oDateChooser.setValue(null);
    }
}
//This Script is for Region WARP RefreshComplete and RefreshRequest in Search Screen
function warpSearchRegion_RefreshComplete(oPanel)
 {
   if  (igcmbo_getComboById("ctl00xSearchInputxwcCorporation").getSelectedIndex()==-1)
    {
       document.getElementById("ctl00xSearchInputxwcRegion_input").readOnly=true;
       igcmbo_getComboById("ctl00xSearchInputxwcRegion").Element.disabled=true;    
       document.getElementById("ctl00xSearchInputxwcServiceName_input").readOnly=true;
       igcmbo_getComboById("ctl00xSearchInputxwcServiceName").Element.disabled=true;    
    } 
    else
    {
       document.getElementById("ctl00xSearchInputxwcRegion_input").readOnly=false;
       igcmbo_getComboById("ctl00xSearchInputxwcRegion").Element.disabled=false;    
    }
    
 }
 
 function warpSearchRegion_RefreshRequest(oPanel)
 {
   document.getElementById("ctl00xSearchInputxwcRegion_input").readOnly=true;
   igcmbo_getComboById("ctl00xSearchInputxwcRegion").Element.disabled=true;     
 }
 
 //This Script is for Service WARP RefreshComplete and RefreshRequest in Search Screen
 function warpSearchServiceName_RefreshRequest(oPanel)
 {
   document.getElementById("ctl00xSearchInputxwcServiceName_input").readOnly=true;
   igcmbo_getComboById("ctl00xSearchInputxwcServiceName").Element.disabled=true;     
 }
 
 function warpSearchServiceName_RefreshComplete(oPanel)
 {
   if  (igcmbo_getComboById("ctl00xSearchInputxwcRegion").getSelectedIndex()==-1)
    {

       document.getElementById("ctl00xSearchInputxwcServiceName_input").readOnly=true;
       igcmbo_getComboById("ctl00xSearchInputxwcServiceName").Element.disabled=true;    
    } 
    else
    {
       document.getElementById("ctl00xSearchInputxwcServiceName_input").readOnly=false;
       igcmbo_getComboById("ctl00xSearchInputxwcServiceName_input").Element.disabled=false;    
    }
    
 }

//This Script is for Region WARP RefreshComplete and RefreshRequest in Append Screen
function warpAppendRegion_RefreshComplete(oPanel)
 {
   if  (igcmbo_getComboById("ctl00xContentxwcCorporation").getSelectedIndex()==-1)
    {
       document.getElementById("ctl00xContentxwcRegion_input").readOnly=true;
       igcmbo_getComboById("ctl00xContentxwcRegion").Element.disabled=true;    
       document.getElementById("ctl00xContentxwcServiceName_input").readOnly=true;
       igcmbo_getComboById("ctl00xContentxwcServiceName").Element.disabled=true;    
    } 
    else
    {
       document.getElementById("ctl00xContentxwcRegion_input").readOnly=false;
       igcmbo_getComboById("ctl00xContentxwcRegion").Element.disabled=false;    
    }
    
 }
 
 function warpAppendRegion_RefreshRequest(oPanel)
 {
   document.getElementById("ctl00xContentxwcRegion_input").readOnly=true;
   igcmbo_getComboById("ctl00xContentxwcRegion").Element.disabled=true;     
 }
 
 //This Script is for Service WARP RefreshComplete and RefreshRequest in Append Screen
 function warpAppendServiceName_RefreshRequest(oPanel)
 {
   document.getElementById("ctl00xContentxwcServiceName_input").readOnly=true;
   igcmbo_getComboById("ctl00xContentxwcServiceName").Element.disabled=true;     
 }
 
 function warpAppendServiceName_RefreshComplete(oPanel)
 {
   if  (igcmbo_getComboById("ctl00xContentxwcRegion").getSelectedIndex()==-1)
    {

       document.getElementById("ctl00xContentxwcServiceName_input").readOnly=true;
       igcmbo_getComboById("ctl00xContentxwcServiceName").Element.disabled=true;    
    } 
    else
    {
       document.getElementById("ctl00xContentxwcServiceName_input").readOnly=false;
       igcmbo_getComboById("ctl00xContentxwcServiceName_input").Element.disabled=false;    
    }
    
 }
