/*
 * SimpleModal Basic Modal Dialog
 * http://www.ericmmartin.com/projects/simplemodal/
 * http://code.google.com/p/simplemodal/
 *
 * Copyright (c) 2010 Eric Martin - http://ericmmartin.com
 *
 * Licensed under the MIT license:
 *   http://www.opensource.org/licenses/mit-license.php
 *
 * Revision: $Id: basic.js 254 2010-07-23 05:14:44Z emartin24 $
 */
jQuery(function ($) {
//email admin

$("input.email, a.email").click(function (e) {
	     var y = e.pageY;
	     y=y-100;
				$("#osx-modal-content").modal({
					overlayId: 'osx-overlay',
					containerId: 'osx-container',
					//closeHTML: null,
					minHeight: 80,
					opacity: 65, 
					position: [y,"30%"],
					overlayClose: true
					//onOpen: OSX.open,
					//onClose: OSX.close
				});
				    return false;
			});	

	// Load dialog on click
	$('#basic-modal .basic').click(function (e) {	
    var cContent = $("#careers-content").html();
    $("#basic-modal-content").html(cContent);	
    
		$("#basic-modal-content").modal({overlayClose:true});
		$('#simplemodal-container').css('height','610px');	
    return false;
	});
	$('#basic-modal .sales').click(function (e) {
    //set login html
    var login =
    '<div id="login">'+
    '<img alt="logo image" src="/wp-content/themes/xzeres/images/header-logo.jpg" width="235" height="110" style="float:left;">'+
    
    ' <fieldset>                                         '+
    '   <legend><b>You must login to access this area</b></legend>'+
    '   <label for="admin_name" class="loginLabel"><b>Username:</b></label>'+
    '   <input type="text" value="" name="admin_username" id="Uname">'+
    '  <br class="clearBoth">'+
    '  <label for="admin_pass" class="loginLabel"><b>Password:</b></label>'+
    '  <input type="password" value="" name="admin_pass" id="Upass">'+
    '  <br class="clearBoth">'+           
    ' <input type="submit" value="Login" class="button" name="submit" onclick="login();">'+
    ' </fieldset></div>';
			
    $('#basic-modal-content').html(login);
//setting css for login 
$('#basic-modal-content').css('width','500px');
$('#basic-modal-content').css('height','200px');
$('#basic-modal-content').css('position','absolute');
$('#basic-modal-content').css('top','50%');
$('#basic-modal-content').css('left','50%');
$('#basic-modal-content').css('margin-left','-250px');
$('#basic-modal-content').css('margin-top','-100px');
    
    $("#basic-modal-content").modal({
    position: ["5%","10%"],
              containerCss:{
            		backgroundCoor:"#666666"            		
            		
            	},
      
            	overlayClose:true
            });

		return false;
	});	
	
});

function login(){
  var Uname = jQuery('#Uname').val();
  var Upass = jQuery('#Upass').val();
  
   
  //first - require user to login
		jQuery.ajax({
			type : 'POST',
			url  : '/loginAJAX.php',
			dataType : 'json',
			data: {
				Uname : jQuery('#Uname').val(),
				Upass : jQuery('#Upass').val()
			},
			success : function(data){

				if (data.error === true){
					alert(data.msg);
				} else {
          //after succesful login then display flash 
           /*  set css for modal container
              (this is done here as this container is used multiple times 
              for various things thru out the site) */
            jQuery('#simplemodal-container').css('padding','8px');
            jQuery('#simplemodal-container').css('left','54px');
            jQuery('#simplemodal-container').css('top','10px');
    		    jQuery('#simplemodal-container').css('height','710px');		
    		    jQuery('#simplemodal-container').css('width','1090px');		    
            jQuery('#basic-modal-content').css('position','');
            jQuery('#basic-modal-content').css('margin-left','');
            jQuery('#basic-modal-content').css('margin-top','');
    		    
            //retrieve sales support data
            var src = "http://www.xzeres.com/enews/sales-support/XZERES-Sales-elearning-International/player.html";
                       
         /*   jQuery.ajax({
            			type : 'POST',
            			url  : '/salesSupport.php',
            			dataType : 'json',
            			data: {
            				src : src
            			},
            			success : function(salesData){
            			 jQuery('#basic-modal-content').html(salesData.html);
                  },
            			error : function(XMLHttpRequest, textStatus, errorThrown) {
            				alert('error in retrieving sales support info');
            			}
            		});*/
            
            jQuery('#basic-modal-content').html('<iframe src="' + src + '" height="700px" width="1080px">');
        }
			},
			error : function(XMLHttpRequest, textStatus, errorThrown) {
				alert('error occured in AJAX call to loginAJAX.php');
			}
		});

	
}


