function validateOptInDialogForm(form)
{
    var Contact0FirstName = form.elements["Contact0FirstName"].value;
    if (Contact0FirstName == '' || Contact0FirstName == 'First Name Here...') {
        alert('Please type you name');
        return false;
    }
    var reg = /^([A-Za-z0-9_\-\.])+\@([A-Za-z0-9_\-\.])+\.([A-Za-z]{2,4})$/;
    var Contact0Email = form.elements["Contact0Email"].value;
    if (Contact0Email == '' || Contact0Email == 'First Email Here...') {
        alert('Please type you email');
        return false;
    } else if (reg.test(Contact0Email) == false) {
        alert('Invalid email address');
        return false;
    }

    return true;
}

function closeOptInDialogForm()
{
    $(".block-dialog-opt-in-lightbox").remove();
}

function openOptInDialog() {
	if ($.cookie('Secure2')) {
		var count = $.cookie('Secure2');
	} else {
	    var count = 0;
	}
	
	if (count > 0 || count=='NaN' || $(document).width() <= 1000) {
	} else {
    	// dialog content
        var dialogContent = ''+
        '<div style="display: none;" class="block-dialog-opt-in-lightbox">'+
            '<div class="opt-in-lightbox-form">'+
                '<form action="https://iman.infusionsoft.com/app/form/process/29b8a40cae13fa58b9c81495394e821e" method="POST" id="form-secure" onsubmit="return validateOptInDialogForm(this);">'+
                '<input name="infusion_xid" type="hidden" id="inf_form_xid" value="29b8a40cae13fa58b9c81495394e821e" />'+
                '<input name="infusionsoft_version" type="hidden" value="1.23.12.31" />'+
                '<input name="infusion_name" type="hidden" id="inf_form_name" value="lightbox optin v2" />'+
		'<input id="LeadSourceId" name="inf_field_LeadSourceId" type="hidden" value="14" />'+
		'<div id="headline-holder" style="height:130px; display:block;">'+
		'<div class="opt-in-headline">'+
			'<h1>YOUR DAILY DOSE OF FREEDOM</h1>'+
			'<p>Sign up to recieve exclusive email updates from Simon Black through his <i>Notes from the Field</i>. You\'ll also get free instant access to the <strong>Sovereign Man Freedom Kit</strong>.</p>'+
		'</div>'+
		'<div class="opt-in-submit-form">'+
                    '<table>'+
		    '<tr>'+
                        '<td valign="top">'+
                            '<img src="/wp-content/themes/thesis_16/custom/images/arrow.jpg" alt="SovereignMan" style="margin: 10px 10px 0;" />'+
                        '</td>'+
                        '<td style="padding: 20px 10px 10px 0;">'+
                            '<input name="inf_field_Email" class="opt-in-lightbox-form-input" type="text" id="inf_field_Email" value="Email Here..." onclick="if(this.value==\'Email Here...\'){this.value=\'\'}" onfocus="if(this.value==\'Email Here...\'){this.value=\'\'}"  onblur="if(this.value==\'\'){this.value=\'Email Here...\'}" />'+
			    '<p style="font-family: sans-serif; font-size: 10px; color: #525252; text-align:center;">We will never share your email with third parties.<br />Blacksmith PTE., LTD. Publisher of SovereignMan.com</p>'+
                        '</td>'+
                        '<td valign="top">'+
                            '<input type="submit" name="submit" value="" class="opt-in-lightbox-form-button" />'+
                        '</td>'+
                    '</tr></table>'+
		'</div>'+
		'</div>'+
		'</form>'+
		'<div id="text-holder" style="height:370px; display:block; clear:both;">'+
		'<script type="text/javascript">'+
		'function show_alert() {'+
		'var msg = "Just one more step... Enter your first name and email address in the boxes to right and click the button, and You will be directed straight to the download page.";'+
		'alert(msg);'+
		'}'+
		'</script>'+
		'<div class="opt-in-report">'+
		'<img src="/wp-content/themes/thesis_182/custom/images/downloadmindmap.jpg" alt="Reports" onclick="show_alert()" style="cursor:pointer;" />'+
		'<iframe src="//www.facebook.com/plugins/like.php?href=http%3A%2F%2Fwww.facebook.com%2FSovereignMan&amp;send=false&amp;layout=standard&amp;width=270&amp;show_faces=false&amp;action=like&amp;colorscheme=light&amp;font&amp;height=35" scrolling="no" frameborder="0" style="border:none; overflow:hidden; width:270px; height:35px;" allowTransparency="true"></iframe></div>'+
		'<div class="opt-in-access">'+
			'<h1>Sign Up Above To Get Instant Access</h1>'+
			'<p>Included in the Sovereign Man Freedom Kit is the mind map to the left as well as three exclusive reports. You will learn how to:<p>'+
			'<ul>'+
				'<li>grow and protect your capital, hedge the financial, food, energy, water and social systems, declare your economic independence, infiltrate and build strong networks, and more.</li>'+
				'<li>how to divorce the U.S. Government for good</li>'+
			'</ul>'+
		'</div>'+
		'</div>'+
		'<div id="footer-holder" style="display:block; clear:both; background-color: white; height: 60px;">'+
			'<div class="opt-in-links">'+
				'<p>www.SovereignMan.com</p>'+
				'<p><a href="http://www.sovereignman.com/about-us/privacy-policy/">Privacy Policy</a> | <a href="http://www.sovereignman.com/about-us/terms-of-use/">Terms of Use</a> | <a href="http://www.sovereignman.com/contact-us/">Contact</a></p>'+
			'</div>'+
			'<div class="opt-in-footer"><a class="opt-in-no-thanks" href="javascript:closeOptInDialogForm();">No&nbsp;Thanks.&nbsp;Go&nbsp;To&nbsp;Website.</a></div>'+
		'</div>'+
            '</div>'+
	'</div>'+
        '';

        // destroy block if exists
        if ($(".block-dialog-opt-in-lightbox").html()) $("#block-dialog-opt-in-lightbox").remove();
        // create new block
        $('body').append(dialogContent);
        //create new dialog object
        $(".block-dialog-opt-in-lightbox").dialog("destroy");
    	$('.block-dialog-opt-in-lightbox').dialog({
            autoOpen: false,
            width: $(document).width(),
            height: $(document).height(),
            modal: true,
            resizable: false,
            closeOnEscape: true,
            draggable: false,
            buttons: {},
            close: function() {$('.block-dialog-opt-in-lightbox').html('');}
        });

        // open dialog object
        $(".block-dialog-opt-in-lightbox").dialog("open");
	}

    count = count + 1;
    $.cookie('Secure2', '', { expires: 360, path: '/', domain: 'www.sovereignman.com' });
    $.cookie('Secure2', count, { expires: 360, path: '/', domain: 'www.sovereignman.com' });
}
$(document).ready(function() {
    setTimeout('openOptInDialog()', 100);
});
