<?php

vcita_add_stylesheet();
$vcita_widget = (array) get_option(VCITA_WIDGET_KEY);
$key = $vcita_widget["implementation_key"];
?>
<div class="vcita-wrap wide">
	<div id="vcita-head">
		Edit vCita Proactive Contact Form
		<div class="small-text">Gain More Clients from Your Website!</div>
	</div>
	<a class="left faq" href="http://support.vcita.com/forums/21650943-wordpress" target="_blank">Add Active Engage on specific pages</a>
	<a class="right done-editing" href="<?php 
echo $url = get_admin_url('', '', 'admin') . 'admin.php?page=' . VCITA_WIDGET_UNIQUE_ID . '/vcita-settings-functions.php';
?>
">Done</a>
	<a class="right back-to-main" href="<?php 
echo $url = get_admin_url('', '', 'admin') . 'admin.php?page=' . VCITA_WIDGET_UNIQUE_ID . '/vcita-settings-functions.php';
?>
">Back to main page</a>
	<div class="clear"></div>
	<?php 
if (!empty($key)) {
    ?>
	<script type="text/javascript">	
		jQuery(function ($) {	
			$('#iframe-holder').html($('#iframe-template').html());
		});
	</script>
	<div id="iframe-holder"></div>
	<script type="text/html" id="iframe-template">
/**
 * Create the vCita floatting widget Settings form content.
 *
 * This is based on Wordpress guidelines for creating a single widget.
 */
function vcita_widget_admin()
{
    vcita_add_stylesheet();
    ?>
    <script type="text/javascript">
		jQuery(function ($) {	
		     $('.start-login')
		    	.on('click', function(){
		        	var callbackURL = "<?php 
    echo $url = get_admin_url('', '', 'admin') . 'admin.php?page=' . VCITA_WIDGET_UNIQUE_ID . '/vcita-callback.php';
    ?>
";
					var email = "";
					$('.vcita-email').each(function(){
						var tempMail = $(this).val();
						if (tempMail)
					 	email = tempMail;
						if (email == $(this).data('watermark')) {
							email = "";
						}
					});
		        	
		        	var new_location = "http://" + "<?php 
    echo VCITA_LOGIN_PATH . '?callback=';
    ?>
" + encodeURIComponent(callbackURL) + "&invite="+"<?php 
    echo VCITA_WIDGET_INVITE_CODE;
    ?>
"+"&lang="+"<?php 
    echo get_locale();
    ?>
"+"&email=" + email; 
		        	window.location = new_location;
		    	});
		    	
		    $('.switch-account')
		    	.on('click', function(){
		        	var callbackURL = "<?php 
    echo $url = get_admin_url('', '', 'admin') . 'admin.php?page=' . VCITA_WIDGET_UNIQUE_ID . '/vcita-callback.php';
    ?>
";
		        	var new_location = "http://" + "<?php 
    echo VCITA_LOGIN_PATH . '?callback=';
    ?>
" + encodeURIComponent(callbackURL) + "&invite="+"<?php 
    echo VCITA_WIDGET_INVITE_CODE;
    ?>
"+"&lang="+"<?php 
    echo get_locale();
    ?>
"+"&login=true"; 
		        	window.location = new_location;
	 	        });					
	 	        	
        	$('.vcita-email')
				.on('keypress', function(e){
					if (e.keyCode == 13) {
						$('.start-login').click();
					}
				});
				
			$('a.preview')
				.bind('click', function(e){
			       var link = $(e.currentTarget);
			       var height = link.data().height ? link.data().height : 600;
			       var width = link.data().width ? link.data().width : 600;
			       var specs = 'directories=0, height=' + height + ', width=' + width + ', location=0, menubar=0, scrollbars=0, status=0, titlebar=0, toolbar=0';
			       window.open(link.attr('href'), '_blank', specs);
			       e.preventDefault();
			     });
			     
    	});
    </script>
    <div id="vcita_config" dir="ltr">
		<?php 
    if (vcita_is_demo_user()) {
        ?>
    		<h3>Contact requests will be sent to this email:</h3>
    		<input class="vcita-email" type="text" value=""/>
    		<a href="javascript:void(0)" class="gray-button-style account start-login"><span></span>OK</a>	    	    			
    	<?php 
    } else {
        $vcita_widget = (array) get_option(VCITA_WIDGET_KEY);
        ?>
    		<h3>Contact requests will be sent to this email:</h3>
    		<label class="checked" for="user-email"></label>
    		<input class="vcita-email" type="text" disabled="disabled" value="<?php 
        echo $vcita_widget["email"];
        ?>
"/>
    		<br><br>
    		<a href="javascript:void(0)" class="gray-button-style account switch-account" ><span></span>Change Email</a>
    		<br><br>    		
    		<a class="gray-button-style edit" href="<?php 
        echo $url = get_admin_url('', '', 'admin') . 'admin.php?page=' . VCITA_WIDGET_UNIQUE_ID . '/vcita-sidebar-edit.php';
        ?>
"><span></span>Edit</a>
    		<br><br>
			<a class="gray-button-style preview" href="http://<?php 
        echo VCITA_SERVER_BASE;
        ?>
/contact_widget?v=<?php 
        echo vcita_get_uid();
        ?>
&ver=2" data-width="200" data-height="500"><span></span>Preview</a>
    	<?php 
    }
    ?>
			
    </div>

    <?php 
}