$(document).ready(function() {
  $("#add_announcement").click( function() {
		$("#newitem").animate({height: 'toggle'}, { duration: "slow" });
	});
	
	$("#can_announcement").click( function() {
		if (confirm('Are you sure you want to discard?  This can not be undone.')) {
		  $("#newitem").animate({height: 'toggle'}, {duration: "slow"});
		  reset_announcment_add_form();
		}
  });
	
	$(".postitem_content .news_headline h1").hover( function() {
    $imageObject = $(this).
                     parents(".postitem").
										 children(".postitem_left").
                     children(".postitem_left_top");
		$imageObject.attr('src', 'images/ctrl_edit_indicator_on.gif' );
	}, function() {
		$imageObject.attr('src', 'images/ctrl_edit_indicator_blank.gif' );
	});
	
  $(".further_details").hover( function() {
    $imageObject = $(this).
                     parents(".postitem").
                     children(".postitem_left").
                     children(".postitem_left_bottom");
    $imageObject.attr('src', 'images/ctrl_edit_indicator_on.gif' );
  }, function() {
    $imageObject.attr('src', 'images/ctrl_edit_indicator_blank.gif' );
  });	

	
	$("#add_email").click( function() {
		$("#email_form_elements").append( '<img src="images/widget_delete.gif" class="delete_email" style="margin-left: 2px;" /> <br class="clearall"/> <div class="subscribe_label">Email:</div> <div class="subscribe_input"><input name="email[]" type="text" size="58" maxlength="254" /></div>' );
		
		$(".delete_email").unbind( 'click' );
		$(".delete_email").click( function() {
      $(this).prev( 'div' ).remove();
			$(this).prev( 'div' ).remove();
			$(this).prev( 'br' ).remove();
			$(this).remove();
    });
	});
	
	$("#rig_alert_selector_view").change( function() {
    rig_id = $(this).attr("value");
    rig_name = $(this).find(':selected').text();
    
    $.ajax({
      type: "POST",
      url: "employee.php?location=alerts",
      data: "alert_rig_id=" + rig_id + "&" + "alert_rig_name=" + rig_name,
      success: function(del) {
        window.location="employee.php?location=alerts";
      }
    });
  });
	
	$("#SubmitCreds").click( function() {
		$("#emp_login_form").attr("action", "https://mail.blakeinternationalrigs.com/exchweb/bin/auth/owaauth.dll" );
		$("#emp_login_form").attr("name", "logonForm" );
		
		$("#auth_username").attr("name", "username" );
		$("#auth_username").attr("id", "username" );
		
		$("#auth_password").attr("name", "password");
		$("#auth_password").attr("id", "password");
		
		$("#emp_login_form").submit();
	});
});


function reset_announcment_add_form() {
	$("#new_headline").html("Click to add a headline");
	$("#new_alert").html("Click to add further detail (will be sent in an email to subscribers).");
}

function getParameterByName( 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];
}
