/* Custom login page javascript
 * Written by Michael Behringer (michaelb@criticalmass.com)
 * Requires: jQuery 1.2.3
 */
function submitForm(e){
	if(e.which == 13)
		$(this).parent().submit();
} 

var Buttons = {
	init: function(){
		$(".submit").replaceWith('<a class="submit" onclick="$(this).parent().submit();">Submit</a>');
	}
}
$(document).ready(function(){
	$("head").append("<link type='text/css' href='/include/styles/basic-modal.css' rel='stylesheet' media='screen' />")
	$("head").append("<link type='text/css' href='/include/styles/passwordassistant.css' rel='stylesheet' media='screen' />")
	$("#errormsg").css("display", "none")
	if($('#errormsg').length > 0)
		$('#errormsg').modal({onOpen: modalShow, onClose: modalHide});
	
	if($("#return-user-group3-channel").val() == 3){
			$("#return-user-group3-vehicles-label").show();
			$("#return-user-group3-vehicles").show();
	}  
	 $("#return-user-group3-channel").change( function () { 
		  if($("#return-user-group3-channel").val() == 3){
			$("#return-user-group3-vehicles-label").show();
			$("#return-user-group3-vehicles").show();
		}
		  else{
			$("#return-user-group3-vehicles-label").hide();
			$("#return-user-group3-vehicles").hide();
		}
	 });
	
	$("#return-user-model-password").keypress(function(e){
		if(e.which == 13)
			$(this).parent().submit();}
	);
	$("#new-user-group-secret_answer").keypress(function(e){
		if(e.which == 13)
			$(this).parent().submit();}
	);
	Buttons.init();
	
	
	$('input#return-user-group-username').cluetip({
					  arrows: true, 
					  dropShadow: false,
					  hoverIntent: false,
					  sticky: true,
					  activation: 'focus',
					  closePosition: 'title',
					  closeText: '',
					  splitTitle: '|',
					  leftOffset: 0,
					  cluezIndex: 3200,
					  local: true,
					  hideLocal: false
					});
	
	$('input#new-user-model-password').cluetip({
					  arrows: true, 
					  dropShadow: false,
					  hoverIntent: false,
					  sticky: true,
					  activation: 'focus',
					  closePosition: 'title',
					  closeText: '',
					  splitTitle: '|',
					  leftOffset: 0,
					  cluezIndex: 3200,
					  local: true,
					  hideLocal: false
					});	
	$('input#return-user-group-username').blur(function(){$("#cluetip").hide();});
	$('input#new-user-model-password').blur(function(){$("#cluetip").hide();});
	

	$('a.popup').click(function(){
		var href=$(this).attr('href')
		var message = (href.split("?"))[1]

		$.ajax({
		type: "GET",
		url: "/include/message.asp",
		data: "message="+message,
		success: function(html){
			$("#errormsg").replaceWith('');
			$("#message").modal({onOpen: modalShow, onClose: modalHide, persist:true});	
			$("#message").replaceWith(html);
			$(".message").show();
			
			$('a#tryagain').click(function(){
				$("#modalContainer").slideUp('fast', function () {
					$("#modalOverlay").fadeOut('slow', function () {
						$.modal.close(); 
					});
			});
		});

		}
		
		});
		return false;
	});
	
	
});
