// Main Function

function pageSetup(){

	var fullNavOptions = 'width=800, height=600,menubar=1,location=yes,menubar=yes,resizable=yes,scrollbars=yes,status=yes,titlebar=no,toolbar=yes,directories=no';
				$(".externalLink").click(function(){ window.open(this.href, '', fullNavOptions); return false });

     var largerPopUp = 'width=1024, height=600,menubar=1,location=yes,menubar=yes,resizable=yes,scrollbars=yes,status=yes,titlebar=no,toolbar=yes,directories=no';
				$(".externalLinkLarge").click(function(){ window.open(this.href, '', largerPopUp); return false });
				
	var whybuyPopUp = 'width=900, height=665,menubar=1,location=yes,menubar=yes,resizable=yes,scrollbars=yes,status=yes,titlebar=no,toolbar=yes,directories=no';
				$(".whybuyLink").click(function(){ window.open(this.href, '', whybuyPopUp); return false });
				
	var whyIPPopUp = 'width=900, height=600,menubar=1,location=yes,menubar=yes,resizable=yes,scrollbars=yes,status=yes,titlebar=no,toolbar=yes,directories=no';
				$(".whyIPLink").click(function(){ window.open(this.href, '', whyIPPopUp); return false });	
	
	var lensComparisonPopUp = 'width=800, height=650,menubar=1,location=yes,menubar=yes,resizable=yes,scrollbars=yes,status=yes,titlebar=no,toolbar=yes,directories=no';
	$(".lensComparisonLink").click(function() { window.open(this.href, '', lensComparisonPopUp); return false });

	var dvrComparisonPopUp = 'width=800, height=650,menubar=1,location=yes,menubar=yes,resizable=yes,scrollbars=yes,status=yes,titlebar=no,toolbar=yes,directories=no';
	$(".externalComparison").click(function() { window.open(this.href, '', dvrComparisonPopUp); return false });
	
	var perfectSystemPopUp = 'width=900, height=665,menubar=1,location=yes,menubar=yes,resizable=yes,scrollbars=yes,status=yes,titlebar=no,toolbar=yes,directories=no';
				$(".perfectSystemLink").click(function(){ window.open(this.href, '', perfectSystemPopUp); return false });
				
//Thank You PopUp
						$('.slideshowClients').cycle({
							fx: 'fade'
						});
						
						var _thankYouDisplay = gup("ThankYou");

						$('#ThankYouMessage').dialog({ autoOpen: false, modal: true, width: 665, height: 370 });
						
						if(_thankYouDisplay == 1)
						{
							// Display logic goes here
							$('#ThankYouMessage').dialog('open');

						}
						
						
						if($('#QuoteRequestOverlay') != null)
							$('#QuoteRequestOverlay').dialog({ autoOpen: false, modal: true, width: 820, height: 400 });
						
						
								
				
}
//Thank You PopUp Function for HTTP Parameter              
function gup(name) {
					name = name.replace(/[\[]/, "\\\[").replace(/[\]]/, "\\\]");
					var regexS = "[\\?&]" + name + "=([^&#]*)";
					var regex = new RegExp(regexS);
					var results = regex.exec(window.location.href);
					if (results == null)
						return "";
					else
						return results[1];
				}
				
//Replace stringA with stringB
function replaceAll(text, strA, strB) {
        while (text.indexOf(strA) != -1) {
            text = text.replace(strA, strB);
        }
        return text;
    }
	
//Validating name and e-mail				
    function  _CF_checkCFForm_1(_CF_this)
    {
        //reset on submit
        _CF_error_exists = false;
        _CF_error_messages = new Array();
        _CF_error_fields = new Object();
        _CF_FirstErrorField = null;

        //form element acctContact required check
        if( !_CF_hasValue(_CF_this['acctContact'], "TEXT", false ) )
        {
            _CF_onError(_CF_this, "acctContact", _CF_this['acctContact'].value, "Please provide a contact name.");
            _CF_error_exists = true;
        }
		
		if (!validateEmail((_CF_this['companyEmail']).value)) {
			_CF_onError(_CF_this, "companyEmail", _CF_this['companyEmail'].value, "Please provide a valid contact email address");
			_CF_error_exists = true;
		}

        //display error messages and return success
        if( _CF_error_exists )
        {
            if( _CF_error_messages.length > 0 )
            {
                // show alert() message
                _CF_onErrorAlert(_CF_error_messages);
                // set focus to first form error, if the field supports js focus().
                if( _CF_this[_CF_FirstErrorField].type == "text" )
                { _CF_this[_CF_FirstErrorField].focus(); }

            }
            return false;
        }else {
            return true;
        }
    }
	
	function validateEmail(element) {
		var pattern = /^[a-zA-Z_0-9-'\+~]+(\.[a-zA-Z_0-9-'\+~]+)*@([a-zA-Z_0-9-]+\.)+[a-zA-Z]{2,7}$/;
		return pattern.test(element);
	}
	



				
									   



