
//Author: Shashank.
//Function to clear value of all controls on a form
//Please extend this function as required for your control's type
function ClearAllControls(form) 
{
    //Get all elements on the form
    var e = form.elements;
    for (var i=0; i<e.length; i++)
    {
        //Clear each element based on its type
        switch (e[i].type)
        {
            
             //TextBox
             case "text" :
                e[i].value = "";
                break;
             //Multi-line Text Box
             case "textarea" :
                e[i].value = "";
                break;
             //Password
             case "password":
              e[i].value = "";
                break;
             //Check Box
             case "checkbox" :
                e[i].checked = false;
                break; 
             case "select-one":
                e[i].selectedIndex = 0;
                break;
        }
    }
}

function SetDefaultFocus(nameOfControl)
{
    var ctrl = document.getElementById(nameOfControl);
    if (ctrl != null) {
        //Shashank - Cannot set focus to a hidden control.
        if (ctrl.style.visibility == "visible") {
            ctrl.focus();
        }
    }
}

 //Ameen
 //This function is used to move the focus to the next text box
 //after it reached maxLength value of the text box.
function autoTab(ctr,nextCtl) 
{ 
    if (ctr.value.length == ctr.maxLength) { ctr.form[nextCtl].focus(); } 
} 

function autoTabImproved(ctr,nextCtl,varevent) 
{ 
    if (varevent.keyCode != '9' && varevent.keyCode != '16')
        if (ctr.value.length == ctr.maxLength) { ctr.form[nextCtl].focus(); } 
} 

function DisputeChange()
{
    var dispCtrl = document.getElementById('chkDispute');
    var authCtrl = document.getElementById('chkAuthorized');
    
    if(dispCtrl)
    {
        if(authCtrl && authCtrl.checked == true)
        {
           dispCtrl.checked = false;
        }
    }
}

function AuthorizeChange()
{
    var dispCtrl = document.getElementById('chkDispute');
    var authCtrl = document.getElementById('chkAuthorized');
    
    if( authCtrl )
    {
        if(dispCtrl && dispCtrl.checked == true)
        {
           authCtrl.checked = false;
        }
    }
}

function EnableDisableValidator(ctr,cellcount)
{
        var spans = [];
        var i;
        
        var grid = document.getElementById(ctr); //get the grid control
        var gridCount = grid.rows.length; //get its count to looping through all the rows
        var rowIndex = 1; //we dont want the header row and hence start with 1
        var rowError = false;
        
        for(rowIndex ; rowIndex<=gridCount-1;rowIndex++)
        {
            var rowElement = grid.rows[rowIndex]; // get the row
            var chekBox = rowElement.cells[cellcount].firstChild; //get the checkbox
            var img = rowElement.cells[0].firstChild; //get the image column
            rowError = false;
            
            spans = rowElement.getElementsByTagName('span'); //validators emit as spans. get all the spans
             
            //if the delete checkbox is checked disable all the validators 
            if(chekBox.checked)
            {
               for(i in spans)
               {
                spans[i].enabled = false;
               }
               
                img.src = "../Images/error_blank.GIF";
            }
            else
            {
               //if the checkbox is unchecked enable back the validators
               for(i in spans)
               {
                spans[i].enabled = true;
               }
               
               
               
               for(i in spans)
               {
                   if(typeof(spans[i].id) == 'undefined') 
                   {
                     continue;
                   }
                    
                    ValidatorValidate(spans[i]);
                        
                    if(!spans[i].isvalid)
                    {
                        rowError = true;
                        break;
                    }
               }
               
               
               if(rowError)
               {
                  img.src = "../Images/grid_error_icon.png";
               }
               else
               {
                 img.src = "../Images/error_blank.GIF";
               }
               
            }  
            
        }
        

}

function popUp(evt,currElem) {
   			popUpWin = eval(docObj + currElem + styleObj)
			if (document.all) {
				popUpWin.top = parseInt(evt.y)+2
				popUpWin.left = Math.max(2,parseInt(evt.x)-125)
			}
			else {
				popUpWin.top = parseInt(evt.pageY)+2
				popUpWin.left = Math.max(2,parseInt(evt.pageX)-125)
			}
			popUpWin.visibility = "visible"
			window.status = ""
		}
		
function popDown(currElem) {
			popUpWin = eval(docObj + currElem + styleObj)
			popUpWin.visibility = "hidden"
		}
		
