var strTextClassName='vtText',strSelectClassName='vtSelect',strCheckClassName='vtCheck';var strAction='/quote/',strMethod='post',strTemplate='/quote/template.php',strContainerName='#quote-viewport';var strContactButton='submitForm';var arrFieldValues={'name':null,'company':null,'website':null,'email':null,'telephone':null,'budget':null};$(document).ready(function(){$(strContainerName+" > *").unbind('*');attatchEvents()});function attatchEvents(){$(strContainerName).css('display','none').load(strTemplate,null,function(){formatFormElements();$('form',strContainerName).hide()}).css('height','366px');$("#toggle").click(function(){if($(this).hasClass('on')){$('#quote-cover').fadeOut(100);$('form',strContainerName).fadeOut(50);$(strContainerName).slideUp(400).next('#controller').children('#toggle').removeClass("on")}else{$('#quote-cover').css('height',$(document).height()+'px').fadeTo(400,0.5);$(strContainerName).slideDown(600,function(){$('form',strContainerName).fadeIn(200)}).next('#controller').children('#toggle').addClass("on")}$('.subscribeHidden').next('span').addClass('isChecked');return false});$('#quote-cover').live('click',function(){$("#toggle").trigger('click')});$('.vtSelectFirst').live('click',function(){if($(this).hasClass('isOpen')){$(this).removeClass('isOpen').next('.vtDropdown').slideUp(200)}else{$('.vtDropdown').each(function(){$(this).hide().prev('.vtSelectFirst').removeClass('isOpen')});$(this).addClass('isOpen').next('.vtDropdown').slideDown(400)}});$('.vtDropdown span').live('click',function(){dropdownHook($(this));$(this).parent().prev('.vtSelectFirst').html($(this).html()).trigger('click');$(this).parent().next('input').val($(this).attr('id').substring(1))});$('.vtFormCheck span').live('click',function(){(!!$(this).prev('input').is(':checked'))?$(this).prev('input').attr('checked',false).next('span').removeClass('isChecked'):$(this).prev('input').attr('checked',true).next('span').addClass('isChecked')});$('.vtCheckLabel').live('click',function(){(!!$('.'+$(this).attr('id').substring(4)).is(':checked'))?$('.'+$(this).attr('id').substring(4)).attr('checked',false).next('span').removeClass('isChecked'):$('.'+$(this).attr('id').substring(4)).attr('checked',true).next('span').addClass('isChecked')});$('.hasTextError').live('click focus',function(){$(this).removeClass('hasTextError').children('input').val(arrFieldValues[$(this).children('input').attr('id')])});$('.hasSelectError').live('click focus',function(){$(this).removeClass('hasSelectError').html('Please Select')});$('#'+strContactButton).live('click',function(){var bolCanPost=true;if($('#name').val().length==0){bolCanPost=false;arrFieldValues['name']=$('#name').val();$('#name').val('Please enter your name').parent().addClass('hasTextError')}if($('#email').val().length==0){bolCanPost=false;arrFieldValues['email']=$('#email').val();$('#email').val('Please enter your e-mail address').parent().addClass('hasTextError')}if($('#telephone').val().length==0){bolCanPost=false;arrFieldValues['telephone']=$('#telephone').val();$('#telephone').val('Please enter your number').parent().addClass('hasTextError')}if($('#contact-time').val().length==0){bolCanPost=false;$('.contact-time').html('When are you available?').addClass('hasSelectError')}if($('#solution-required').val().length==0){bolCanPost=false;$('.solution-required').html('Please enter the project type').addClass('hasSelectError')}if($('#budget').val().length<=1){bolCanPost=false;arrFieldValues['budget']=$('#budget').val();$('#budget').val('Please enter your budget').parent().addClass('hasTextError')}if($('#referer').val().length==0){bolCanPost=false;$('.referer').html('Please tell us how you arrived').addClass('hasSelectError')}if($('.hasTextError').length>0){bolCanPost=false}if($('.hasSelectError').length>0){bolCanPost=false}if(!!bolCanPost==true){var arrFeaturesArray=Array();$(".featuresHidden").each(function(){if($(this).is(':checked')){arrFeaturesArray.push($(this).val())}});var isSubscribed=($('.subscribeHidden').is(':checked'))?'yes':'no';arrFormValues=Array({name:$('#name').val(),company:$('#company').val(),website:$('#website').val(),email:$('#email').val(),telephone:$('#telephone').val(),contacttime:$('#contact-time').val(),solutionrequired:$('#solution-required').val(),budget:$('#budget').val(),features:arrFeaturesArray,referer:$('#referer').val(),subscribe:isSubscribed});$.ajax({url:"/quote/",type:"POST",data:({request:'process',formValues:arrFormValues}),dataType:"json",success:function(response){(response=='success')?displaySuccess():processErrors(response)}})}return false})}function formatFormElements(){$(strContainerName+' .'+strTextClassName).each(function(){$(this).wrap('<div class="vtFormText" />')});$(strContainerName+' .'+strSelectClassName).each(function(){var objSelect=$(this).clone();$(this).wrap('<div class="vtFormSelect" />').parent().append('<span title="Please Select" class="'+objSelect.context.name+' vtSelectFirst">Please Select</span>').append('<div class="'+objSelect.context.name+'-menu vtDropdown"></div>');for(i=1;i<objSelect.context.options.length;i++){$(this).parent().children('.'+objSelect.context.name+'-menu').append('<span title="'+objSelect.context.options[i].text+'" id="b'+objSelect.context.options[i].value+'">'+objSelect.context.options[i].text+'</span>')}$(this).parent().append('<input type="hidden" name="'+objSelect.context.name+'" id="'+objSelect.context.name+'" value="" />');$(this).remove()});$(strContainerName+' .'+strCheckClassName).each(function(){var strInputName=$(this).attr('name').replace(/\[\]/,'');$(this).addClass(strInputName+'Hidden').hide().wrap('<div class="vtFormCheck" />').after('<span></span>')});return null}function displaySuccess(){$('#quoteForm').hide();$(strContainerName).css('overflow','hidden').animate({height:'70px'},1000).children('form').children('#info').children('h4').html('Thank You').next('span').html('We will be in touch soon!');setInterval(function(){$('#quote-cover').fadeOut(100);$(strContainerName).slideUp(400).next('#controller').children('#toggle').removeClass("on")},5000)}function processErrors(response){for(var key in response){if($('#'+key).parent().hasClass('vtFormText')){arrFieldValues[key]=$('#'+key).val();$('#'+key).val(response[key]).parent().addClass('hasTextError')}else if($('#'+key).parent().hasClass('vtFormSelect')){$('.'+key).html(response[key]).addClass('hasSelectError')}}}function dropdownHook(originalNode){if(originalNode.parent().hasClass('solution-required-menu')){populateFeatureCheckboxes(originalNode)}}function populateFeatureCheckboxes(subject){$('.featuresHidden').each(function(){$(this).attr('checked',false).next('span').removeClass('isChecked')});var strDivId=subject.attr('id').substring(1);if($('.vtCheckboxSet-'+strDivId).length>0&&$('.vtCheckboxSet-'+strDivId).is(':hidden')){$('.vtCheckboxPanel').each(function(){$(this).hide()});$('.vtCheckboxSet-'+strDivId).show()}}
