
/*  DECLARE GLOBAL VARIABLES ********************* */
    var _activeForm         = null;
    var _dvMsg           	= null;
    var _tblGeneral         = null;
    var _tblCompany         = null;
    var _tblAddl            = null;

    var _txCompany          = null;
    var _txAddress1         = null;
    var _txAddress2         = null;
    var _txCity             = null;
    var _ddlStateList       = null;
    var _txZipCode          = null;

    var _txName             = null;
    var _txPhone            = null;
    var _txFax              = null;
    var _txEMail            = null;

    var _txCompanyURL       = null;
    var _txCompanyProfile   = null;
    var _ddlListingType     = null;
    var _txDescription      = null;
    
    var _btnNext            = null;
    var _btnBack            = null;
    var _btnFinish          = null;
    
    

/*  page_onload() ******************************** */
// function page_onload(){  function is generated by the code behind  }

	
/*  InitPage()  ********************************** */
	function page_onInit()
	{
        _dvMsg       	 = document.getElementById("dvMsg");
        _activeForm     = document.getElementById("tblGeneral");
        _tblGeneral     = document.getElementById("tblGeneral");
        _tblCompany     = document.getElementById("tblCompany");
        _tblAddl        = document.getElementById("tblAddl");
    
        _txCompany      = document.getElementById("txCompany");
        _txAddress1     = document.getElementById("txAddress1");
        _txAddress2     = document.getElementById("txAddress2");
        _txCity         = document.getElementById("txCity");
        _ddlStateList   = document.getElementById("ddlStateList");
        _txZipCode      = document.getElementById("txZipCode");
        
        _txName         = document.getElementById("txName");
        _txPhone        = document.getElementById("txPhone");
        _txFax          = document.getElementById("txFax");
        _txEMail        = document.getElementById("txEMail");
        
        _txCompanyURL       = document.getElementById("txCompanyURL");
        _txCompanyProfile   = document.getElementById("txCompanyProfile");
        _ddlListingType     = document.getElementById("ddlListingType");
        _txDescription      = document.getElementById("txDescription");
        
        _btnNext            = document.getElementById("btnNext");
        _btnBack            = document.getElementById("btnBack");
        _btnFinish          = document.getElementById("btnSubmit");
		
		menubar_setPageHeight();
	}



// *********************************************** //
// ** TAB ONE EVENTS 
// ********************************************** //
    function txCompany_onKeyUp()
    {
		btnFinish_Enable( true );
		ActivateTabOne();
		_txCompany.focus();
    }

    function txAddress_onKeyUp()
    {
		btnFinish_Enable( true );
		ActivateTabOne();
		_txAddress1.focus();
    }

    function txCity_onKeyUp()
    {
		btnFinish_Enable( true );
		ActivateTabOne();
		_txCity.focus();
    }

    function txZipCode_onKeyUp()
    {
		btnFinish_Enable( true );
		ActivateTabOne();
		_txZipCode.focus();
    }

    function txName_onKeyUp()
    {
		btnFinish_Enable( true );
		ActivateTabOne();
		_txName.focus();
    }

    function txEMail_onKeyUp()
    {
		btnFinish_Enable( true );
		ActivateTabOne();
		_txEMail.focus();
    }
    
    function txPhone_onKeyUp()
    {
		btnFinish_Enable( true );
		ActivateTabOne();
		_txPhone.focus();
    }

    function txFax_onKeyUp()
    {
		btnFinish_Enable( true );
		ActivateTabOne();
		_txFax.focus();
    }

// *********************************************** //
// ** TAB TWO EVENTS 
// ********************************************** //
    function txCompanyURL_onKeyUp()
    {
		btnFinish_Enable( true );
		ActivateTabTwo();
		_txCompanyURL.focus();
	}
    
    function txDescription_onKeyUp()
    {		
		btnFinish_Enable( true );
		ActivateTabTwo();
		_txDescription.focus();
    }


/* FUNCTION NAME: ActivateTabOne()
*/
	function ActivateTabOne()
	{
	//	alert("activating 1");
		_btnBack.disabled = true;
		
		if(null != _activeForm && _tblGeneral != _activeForm){
			_activeForm.style.display 	= "none";
		}
		
		if(TabOne_IsValid( true )){
			_btnNext.disabled = false;
		}
		else{
			_btnNext.disabled = true;
			_dvMsg.className  = "errMsg";
		}	
		
		_activeForm 				= _tblGeneral;
		_activeForm.style.display 	= "block";
	}

/* FUNCTION NAME: ActivateTabTwo()
*/
	function ActivateTabTwo()
	{
	//	alert("activating 2");
		_btnBack.disabled = false;
		var oTabTwo	= document.getElementById("tblCompany");
		if(null != _activeForm && oTabTwo != _activeForm){
			_activeForm.style.display 	= "none";
		}
		
		if(TabTwo_IsValid( true )){
			_btnNext.disabled = false;
		}
		else{
			_btnNext.disabled = true;
		}
			
		_activeForm 				= _tblCompany;
		_activeForm.style.display 	= "block";
		
	}

/* FUNCTION NAME: ActivateTabThree()
*/
	function ActivateTabThree()
	{
	//	alert("activating 3");
		_btnBack.disabled = false;
		_btnNext.disabled = true;
		
		
		if(null != _activeForm && _tblAddl != _activeForm){
			_activeForm.style.display 	= "none";
		}
		
		_activeForm 				= _tblAddl;
		_activeForm.style.display 	= "block";
	}

	
	
/* FUNCTION NAME: btnFinish_Enable()
*/
    function btnFinish_Enable(bEnable)
    {
        if(bEnable)
        {
            if(TabOne_IsValid(false) && TabTwo_IsValid(false))
                _btnFinish.disabled = false;
            else
                _btnFinish.disabled = true;
        }
    }

/* FUNCTION NAME: btnNext_onclick()
*/
    function btnNext_onclick()
    {
        switch(_activeForm.id)
        {
            case "tblGeneral":
			ActivateTabTwo();
			break;
            case "tblCompany":
			ActivateTabThree();
			break;
        }        
    }

/* FUNCTION NAME: btnBack_onclick()
*/
	function btnBack_onclick()
	{
		// the current active form is the one we are coming FROM!
		switch(_activeForm.id)
		{
			case "tblCompany":
				ActivateTabOne();
				break;
			case "tblAddl":
				ActivateTabTwo();
				break;
		}        
	}



/* FUNCTION NAME: TabOne_IsValid()
*/
    function TabOne_IsValid( bShowMsg )
    {
        var isValid = true;
        var sErrMsg = "";
        
    // Company Name
        if( _txCompany.value.isEmpty() )
        {
            isValid  = false;
            sErrMsg += "<li>Company is Required</li>";
        }
        
    // Address1
        if( _txAddress1.value.isEmpty() )
        {
            isValid  = false;
            sErrMsg += "<li>Address is Required</li>";
        }
        
    // City
        if( _txCity.value.isEmpty() )
        {
            isValid  = false;
            sErrMsg += "<li>City is Required</li>";
        }
        
    // Zip Code
        if( _txZipCode.value.isEmpty() )
        {
            isValid  = false;
            sErrMsg += "<li>Zip Code is Required</li>";
        }
        else
        {
            if(!_txZipCode.value.isZipCode())
            {
                isValid  = false;
                sErrMsg += "<li>Zip Code is Invalid</li>";
            }
        }
        
    // Phone
        if( !_txPhone.value.isEmpty() )
        {
            if( !_txPhone.value.isPhone() )
            {
                isValid  = false;
                sErrMsg += "<li>Phone is invalid</li>";
            }
        }
        
    // Fax
        if( !_txFax.value.isEmpty() )
        {
            if( !_txFax.value.isPhone() )
            {
                isValid  = false;
                sErrMsg += "<li>Fax is invalid</li>";
            }
        }
        
    // Name
        if( _txName.value.isEmpty() )
        {
            isValid  = false;
            sErrMsg += "<li>Name is Required</li>";
        }
        
    // EMAIL
        if( _txEMail.value.isEmpty() )
        {
            isValid  = false;
            sErrMsg += "<li>EMail is Required</li>";
        }
        else
        {
            if( !_txEMail.value.isEmail() )
            {
                isValid  = false;
                sErrMsg += "<li>EMail is invalid</li>";
            }
        }
        
        
        if(!isValid && bShowMsg)
        {    
			_dvMsg.innerHTML 		= sErrMsg;
			_dvMsg.ClassName 		= "ErrMsg";
			_dvMsg.style.display 	= "block";
        }
        else
            _dvMsg.style.display = "none";
            
        return(isValid);
    }

/* FUNCTION NAME: TabTwo_IsValid()
*/
    function TabTwo_IsValid( bShowMsg )
    {
        var isValid = true;
        var sErrMsg = "";
        
        if(_txDescription.value.length <= 0)
        {
            isValid  = false;
            sErrMsg += "<li>Description is Required</li>";
        }
        
        if(!_txCompanyURL.value.isEmpty() )
        {
            if(!_txCompanyURL.value.isURL() )
            {
                isValid  = false;
                sErrMsg += "<li>URL is invalid</li>";
            }
        }
        
        if(!isValid && bShowMsg)
        {    
			_dvMsg.innerHTML 		= sErrMsg;
			_dvMsg.ClassName 		= "ErrMsg";
			_dvMsg.style.display 	= "block";
        }
        else
            _dvMsg.style.display = "none";
            
        return(isValid);
    }

    function TabThree_IsValid()
    {
    }





