
function Quote()
{
	this.oFullForm = this.oAutoFillMsg = this.oNELink = this.oFDCont = this.oEmailCon = this.oMsg = this.oEmailCont = null;;
	this.quickinit = function()
	{
		this.oNELink = _GL.getUIElem('noEmailCon');
		this.oEmailCont = _GL.getUIElem('sEmilCont');
		this.oFullForm = new HTMLLayer('fullForm');
		this.oAutoFillMsg = new HTMLLayer('autoFillMsg');
		this.oMsg = new HTMLLayer('pageMsg');
		this.oEmailCon = new HTMLLayer('emailCon');
		if (this.oNELink)
		{
			this.oNELink.onclick = function()
			{
				_qt.oFullForm.show(true);
				_qt.oEmailCon.show(false);
				_qt.oAutoFillMsg.show(false);
				return false;
			}
		}

		if (this.oEmailCont)
		{
			this.oEmailCont.onclick = function()
			{
				var email = _GL.getUIElem('email');
				if(email && email.value.length > 0)
				{
					var sUrl = baseUrl + '?c=ajax&email='+email.value;
					var oAjax = new Ajax('getFirmData', sUrl, true,  ['_qt.processFirmData']);
					oAjax.iResponseType = oAjax.RESPONSE_JSON;
					oAjax.send();
					return false;
				}
			}
		}
		
		if (typeof aCBMapping != 'undefined')
			_GL.setCBMapping(aCBMapping);
	
		this.initYNDesc();
	}

	this.detailsinit = function()
	{
		this.oAttToggleLink = _GL.getUIElem('attToggle');
		this.oMoreThanFiveAtts = _GL.getUIElem('moreFiveAtt');
		this.oLessThanFivAttLyr = new HTMLLayer('lessThanFiveAtts');
		this.oMoreThanFivAttLyr = new HTMLLayer('moreThanFiveAtts');
		
		if (this.oAttToggleLink)
		{
			this.oAttToggleLink.onclick = function()
			{
				var v = _qd.oMoreThanFiveAtts.value, bIsLess = v.is('N');
				_qd.oLessThanFivAttLyr.show(!bIsLess);
				_qd.oMoreThanFivAttLyr.show(bIsLess);
				_qd.oMoreThanFiveAtts.value = bIsLess ? 'Y' : 'N';
				return false;
			}
		}
		this.initYNDesc();
	}

	this.processFirmData = function(pResp)
	{
		var oD = pResp.oJSON;
		if (oD && oD.email)
		{
			_GL.getUIElem('phone').value = oD.phone;
			_GL.getUIElem('appName').value = oD.contact_name;
			_GL.getUIElem('firmName').value = oD.firm_name;
			_GL.getUIElem('address').value = oD.address;
			_GL.getUIElem('city').value = oD.city;
			_GL.getUIElem('zip').value = oD.zip;
			_GL.getUIElem('fax').value = oD.fax;
			_GL.getUIElem('website').value = oD.website;
			_GL.getUIElem('yearEst').value = oD.year_est;
		}

		this.oNELink.onclick();
	}

	this.initYNDesc = function()
	{
		if (typeof aYNDesc == 'undefined')
			return;

		var a = aYNDesc;
		if (a)
		{
			for (var i in a)
			{
				var oE = _GL.getUIElem(i),len = oE.length;
				for (var j=0;j<len;j++)
				{
					var o = oE[j];
					o.data = a[i];
					o.onclick = function()
					{
						var b = this.value == this.data['ov'],
							de = this.data['de'], oDesc = _GL.getUIElem(de),
							oDescDiv = _GL.getUIElem(de+'Div');
						
						if(oDesc)
						{
							if (!b)
								oDesc.value = " ";
							
							oDescDiv.style.display = b ? 'block' : 'none';
						}

					}
				}
			}
		}
	}

	this.qfinit = function()
	{
		var oQL = _GL.getUIElem('quickAppLink'), 
			oFL = _GL.getUIElem('fullAppLink'),
			oEL = _GL.getUIElem('editAppLink'),
			oFrm = document.forms['form1'];
		
        if (oQL)
        {
		    oQL.onclick = function()
		    {
			    oFrm.elements['appFormat'].value = 'Q';
			    oFrm.submit();
		    }
        }
        
        if (oFL)
        {
		    oFL.onclick = function()
		    {
			    oFrm.elements['appFormat'].value = 'D';
			    oFrm.submit();
		    }
        }

        if (oEL)
        {
		    oEL.onclick = function()
		    {
			    oFrm.elements['appFormat'].value = 'E';
			    _GL.getUIElem('editApp').style.display = 'block';
			    _GL.getUIElem('editAppMsg').style.display = 'none';
			    this.removeAttribute('href');
			    return false;
		    }
        }
	}

	this.init = function()
	{
		if (typeof sPage == 'undefined')
			return;

		switch(sPage)
		{
			case 'quickapp':
				this.quickinit();
				break;
			case 'quotedetails':
				this.detailsinit()
				break;
			case 'quoteformat':
				this.qfinit()
				break;
		}
	}
}
var _qt = new Quote();
_GL.addOnLoadListener(function(){_qt.init()});
