//
//  AdminView.m
//  StuntPuppy
//
//  Created by Victor Johnson on 7/15/10.
//  Copyright 2010 __MyCompanyName__. All rights reserved.
//

#import "AdminView.h"


@implementation AdminView

@synthesize loginView,loggedInView, bg_login, bg_loggedIn, user, pass;

- (id)initWithFrame:(CGRect)frame {
    if ((self = [super initWithFrame:frame])) {
        // Initialization code
    }
    return self;
}

/*
// Only override drawRect: if you perform custom drawing.
// An empty implementation adversely affects performance during animation.
- (void)drawRect:(CGRect)rect {
    // Drawing code
}
*/
-(void) initAdminView {
	self.backgroundColor = [UIColor blackColor];
	
	loginView = [[UIView alloc] initWithFrame:CGRectMake(0,0,768,1024)];
	loginView.center = CGPointMake(384, 492);
	loginView.hidden = NO;
	loginView.alpha = 1;
	loginView.userInteractionEnabled = YES;
	loginView.backgroundColor = [UIColor blackColor];
	[self addSubview:loginView];
	
	loggedInView = [[UIView alloc] initWithFrame:CGRectMake(0,0,768,1024)];
	loggedInView.center = CGPointMake(384, 492);
	loggedInView.hidden = NO;
	loggedInView.alpha = 0;
	loggedInView.userInteractionEnabled = YES;
	loggedInView.backgroundColor = [UIColor blackColor];
	[self addSubview:loggedInView];
	
	
	bg_login = [[UIImageView alloc] initWithFrame:CGRectMake(0,0,768,1024)];
	bg_login.image = [UIImage imageNamed:@"bg_admin.png"];
	bg_login.hidden = NO;
	bg_login.alpha = 1;
	bg_login.userInteractionEnabled = NO;
	//bg_login.backgroundColor = [UIColor redColor];
	[loginView addSubview:bg_login];
	
	UIButton *signin = [[UIButton alloc] initWithFrame:CGRectMake(0,0,71,34)];
	signin.backgroundColor = [UIColor clearColor];
	signin.center = CGPointMake(500,360);
	signin.userInteractionEnabled = YES;
	[signin setBackgroundImage:[UIImage imageNamed:@"btn_signin.png"] forState:UIControlStateNormal];
	//[btn setCenter:CGPointMake(230, 272)];
	signin.hidden = NO;
	[signin addTarget:self action:@selector(checkPass) forControlEvents:UIControlEventTouchUpInside];
	[loginView addSubview:signin];
	
	user = [[UITextField alloc] initWithFrame:CGRectMake(0,0,170,30)];
	user.alpha = 1;
	user.autocorrectionType = UITextAutocorrectionTypeNo;
	user.textColor = [[UIColor alloc] initWithRed:.55 green:.55 blue:.55 alpha:1];
	user.font = [UIFont fontWithName:@"Helvetica" size:18];
	user.autocorrectionType = UITextAutocorrectionTypeNo;
	user.autocapitalizationType = UITextAutocapitalizationTypeNone;
	//user.backgroundColor = [UIColor redColor];
	//user.borderStyle = UITextBorderStyleRoundedRect;
	user.center = CGPointMake(445,268);
	//user.placeholder = @"IBUM";
	user.textAlignment = UITextAlignmentLeft;
	[loginView addSubview:user];
	
	pass = [[UITextField alloc] initWithFrame:CGRectMake(0,0,170,30)];
	pass.alpha = 1;
	pass.autocorrectionType = UITextAutocorrectionTypeNo;
	pass.autocapitalizationType = UITextAutocapitalizationTypeNone;
	pass.textColor = [[UIColor alloc] initWithRed:.55 green:.55 blue:.55 alpha:1];
	pass.font = [UIFont fontWithName:@"Helvetica" size:18];	
	//pass.backgroundColor = [UIColor redColor];
	pass.center = CGPointMake(445,310);
	//pass.placeholder = @"";
	pass.textAlignment = UITextAlignmentLeft;
	[loginView addSubview:pass];
	
	UIButton *btn_return = [[UIButton alloc] initWithFrame:CGRectMake(0,0,136,34)];
	btn_return.backgroundColor = [UIColor clearColor];
	btn_return.center = CGPointMake(308,360);
	btn_return.userInteractionEnabled = YES;
	[btn_return setBackgroundImage:[UIImage imageNamed:@"btn_return.png"] forState:UIControlStateNormal];
	btn_return.hidden = NO;
	[btn_return addTarget:self action:@selector(returnToMain) forControlEvents:UIControlEventTouchUpInside];
	[loginView addSubview:btn_return];	
	
	bg_loggedIn = [[UIImageView alloc] initWithFrame:CGRectMake(0,0,768,1024)];
	bg_loggedIn.image = [UIImage imageNamed:@"bg_admin_loggedin.png"];
	bg_loggedIn.hidden = NO;
	bg_loggedIn.alpha = 1;
	bg_loggedIn.userInteractionEnabled = NO;
	//bg_login.backgroundColor = [UIColor redColor];
	[loggedInView addSubview:bg_loggedIn];
	
	UIButton *btn_return2 = [[UIButton alloc] initWithFrame:CGRectMake(0,0,136,34)];
	btn_return2.backgroundColor = [UIColor clearColor];
	btn_return2.center = CGPointMake(314,260);
	btn_return2.userInteractionEnabled = YES;
	[btn_return2 setBackgroundImage:[UIImage imageNamed:@"btn_return.png"] forState:UIControlStateNormal];
	btn_return2.hidden = NO;
	[btn_return2 addTarget:self action:@selector(returnToMain) forControlEvents:UIControlEventTouchUpInside];
	[loggedInView addSubview:btn_return2];
	
	UIButton *btn_submit = [[UIButton alloc] initWithFrame:CGRectMake(0,0,136,34)];
	btn_submit.backgroundColor = [UIColor clearColor];
	btn_submit.center = CGPointMake(460,260);
	btn_submit.userInteractionEnabled = YES;
	[btn_submit setBackgroundImage:[UIImage imageNamed:@"btn_submitsurveydata.png"] forState:UIControlStateNormal];
	btn_submit.hidden = NO;
	[btn_submit addTarget:self action:@selector(emailInfo) forControlEvents:UIControlEventTouchUpInside];
	[loggedInView addSubview:btn_submit];
	
	//[user becomeFirstResponder];

}
-(void) showKeyboard{
	[user becomeFirstResponder];	
}
-(void) hideKeyboard{
	[user resignFirstResponder];
}

-(void) checkPass {
	if ([user.text isEqualToString:@"admin"] && [pass.text isEqualToString:@"ideapark"]){
		NSLog(@"log in successful");
		
		
		[UIView beginAnimations:nil context:nil];
		[UIView setAnimationDuration:1];
		loginView.alpha = 0;
		loggedInView.alpha = 1;
		[UIView commitAnimations];	
	}
}

-(void) returnToMain {
	loginView.alpha = 1;
	loggedInView.alpha = 0;
	user.text = @"";
	pass.text = @"";
	[user becomeFirstResponder];
	[[NSNotificationCenter defaultCenter] postNotificationName:@"ReturnToForm" object:self];
}

-(void) emailInfo {

	[[NSNotificationCenter defaultCenter] postNotificationName:@"EmailData" object:self];
}

- (void)dealloc {
	[loginView release];
	[loggedInView release];
	[bg_login release];
	[bg_loggedIn release];
    [user release];
	[pass release];
	[super dealloc];
}

@end
