﻿// this file for common methods 

//confirms an action  
function ConfirmAction(message)
{
    return confirm(message) ;    
}

// Desplays a notification message
function DisplayStatus(message)
{
    return alert(message);
}

// loades the previos page
function GoBack()
{
    window.history.back();
}

// sets the focus on the passed button to submit the current from 
function SubmitOnEnter(btnSubmit) 
{

  if (window.event && window.event.keyCode == 13)
  {
     //var btnSubmit= document.getElementById('<%=btnSubmit.ClientID %>');
     btnSubmit.focus();
   } 
  
}

///Resets the controls on the current page 
//Params: withPostBack - indecates either the page will posted back or not 
function ResetFields(parentControlName, withPostBack)
{
    
    if(withPostBack)
    {
        window.location.pathname=window.location.pathname;  
        return;
    }
    var InputFields = document.forms[0].getElementsByTagName("input");
    var textAreas   = document.forms[0].getElementsByTagName("textarea");
    var Lists       = document.forms[0].getElementsByTagName("select");
    // reset the input fields
    for(var i=0;i<InputFields.length;i++)
    {
        var inputFieldType=InputFields[i].getAttribute("type");
        
        
        // reset the field if it is a child for the current user control and if it is from the types (text, radio,checkbox)
        if(( inputFieldType == "text" | inputFieldType=="password") & InputFields[i].id.indexOf(parentControlName) != -1)
        {
            InputFields[i].value="";
        }
        else if( (inputFieldType== "radio" | inputFieldType== "checkbox") & InputFields[i].id.indexOf(parentControlName) != -1 )
            InputFields[i].checked=false;
            
    }
    //reset text areas
    for(var i=0;i<textAreas.length;i++)
    {
        textAreas[i].value="";
    }    
    // reset the list selection to the first item 
    for(var i=0;i<Lists.length;i++)
    {
        if (Lists[i].id.indexOf(parentControlName) != -1)
            Lists[i].selectedIndex=0;
    }
}
