﻿function Evaluate (pSource, pArgs)
{
    var i;
    var count;
    var elems;
    var elem;
    
    pArgs.IsValid   = true;
    elems           = document.forms[0].elements;
    
    count = elems.length;
    
    for ( i = 0; i < count; i++ )
    {
        elem = document.forms[0].elements[i];
        
        if ( elem.getAttribute('Required') != null )
        {
            elem.parentNode.style.border = '';
            if ( elem.getAttribute('Required') == 'True' )
            {
                if ( Validate( elem ) )
                {
                    pArgs.IsValid = false;
                    elem.parentNode.style.border = 'solid 1px red';
                }
            }
        }
    }
                
    if ( !pArgs.IsValid )
    {
        Page_Validators[0].innerHTML = 'Fields indicated with red border are invalid';
    }
}

function Validate ( pElem )
{
    var res;
    var ReqType;
    
    res     = true;
    ReqType = pElem.getAttribute('ReqType');
    
    switch ( ReqType )
    {
        case 'Text' : res = pElem.value.length == 0;
                      break;

        case 'Combo': res = pElem.value == '-1';
                      break;
                      
        case 'Email': res = pElem.value.length == 0;
                      if ( !res )
                      {
                          res = pElem.value.indexOf('@') < 0;
                        
                          if ( !res )
                          {
                              res = pElem.value.indexOf('.') < 0;
                          }
                      }
                      break;
                      
    }
    
    return res;
}

function CheckType ( pObj, pTypeAttribute, pChkValAttribute )
{
    var i;
    var count;
    var txtObj;
    var data;
    var val;
            
    val    = pObj.parentNode.getAttribute(pTypeAttribute);    
    txtObj = pObj.parentNode.getAttribute(pChkValAttribute);
    txtObj = document.getElementById(txtObj);
        
    if ( pObj.checked )
    {
        txtObj.value +=  val + ';';
    }
    else
    {
        txtObj.value = txtObj.value.split(val + ';').join('');
    }        
}

function TabClick ( pObj, pExt )
{
    var i;
    var count;
    var Tabs;
    var cell;
    var Cont;
    var objDiv;
    
    Tabs  = document.getElementById('Tabs');
    Cont  = document.getElementById(pExt);
    count = Tabs.rows[0].cells.length;
            
    for ( i = 0; i < count; i++ )
    {
        cell = Tabs.rows[0].cells[i];
        
        if ( cell.firstChild != null )
        {
            cell.firstChild.className = 'TabItem';
        }        
    }
    
    count = Cont.parentNode.childNodes.length;
        
    for ( i = 0; i < count; i++ )
    {
        objDiv = Cont.parentNode.childNodes[i];
        
        if (objDiv.nodeName == 'DIV' )
        {
            
            if ( objDiv.getAttribute('id') != null )
            {
                if ( objDiv.getAttribute('id').length != 0 )
                {
                    objDiv.style.display = 'none';
                }
            }
            else
            {
                objDiv.style.display = 'none';
            }
        }
    }
    
    pObj.className     = 'TabItemSelect';
    Cont.style.display = '';
}

function checkAll ( pObjChkAll, pObjContainerId )
{
    var i;
    var count;
    var arrChks;
    var grdDownList;
            
    grdDownList = document.getElementById(pObjContainerId);
    arrChks     = grdDownList.getElementsByTagName('input');
    count       = arrChks.length;
        
    for ( i = 0; i < count; i++ )
    {
        if ( arrChks[i].getAttribute('type') == 'checkbox' )
        {
            arrChks[i].checked = pObjChkAll.checked;
        }
    }
}

function OpenWindow ( pURL, pTitle, pHeight, pWidth )
{
    GB_showCenter(pTitle, pURL,pHeight,pWidth,CallBack)
}

function CallBack ()
{
    document.location = document.location;
}