//
//  VasqueViewController.m
//  Vasque
//
//  Created by Victor Johnson on 8/2/10.
//  Copyright __MyCompanyName__ 2010. All rights reserved.
//

#import "VasqueViewController.h"
#import "RadioBtn.h"
#import "AdminView.h"
#import "State.h"
#import "MapScroller.h"

@implementation VasqueViewController
@synthesize admin,formView,formData,thankyouView,buttonsArray,submit,firstName, 
lastName,phone,phoneNum,toolbar,email,gender,age,answersTextArray,
questionsTextArray,r1,r2,r3,r4,rt1,rt2,rt3,rt4,rX,rY,btn0,btn1,btn2,btn3,btn4,btn5,
btn6,btn7,btn8,btn9,btn10,btn11;



// Implement viewDidLoad to do additional setup after loading the view, typically from a nib.
- (void)viewDidLoad {
    
	//if (UI_USER_INTERFACE_IDIOM() == UIUserInterfaceIdiomPad)  {
	
	//}
	
	
	buttonsArray = [[NSMutableArray alloc] init];
	
	questionsTextArray = [[NSMutableArray alloc] init];
	[questionsTextArray addObject:@"First Name,Last Name,Phone,Email,Gender,Age,"];
	[questionsTextArray addObject:@"1)In which outdoor activities do you participate?,"];
	[questionsTextArray addObject:@"2)Do you currently own Vasque shoes or boots?,"];
	[questionsTextArray addObject:@"3)Do you plan on buying new Hiking Boots in the next 6 months?,"];
	[questionsTextArray addObject:@"4)Do you plan on buying new trail running shoes in the next 6 months?,"];
	
	answersTextArray = [[NSMutableArray alloc] init];
	[answersTextArray addObject:@"Trail Running"];
	[answersTextArray addObject:@"Hiking"];
	[answersTextArray addObject:@"Backpacking"];
	[answersTextArray addObject:@"Mountain Biking"];
	[answersTextArray addObject:@"Road Running"];
	[answersTextArray addObject:@"Camping"];
	[answersTextArray addObject:@"Yes"];
	[answersTextArray addObject:@"No"];
	[answersTextArray addObject:@"Yes"];
	[answersTextArray addObject:@"No"];
	[answersTextArray addObject:@"Yes"];
	[answersTextArray addObject:@"No"];
	
	self.view.backgroundColor = [UIColor blackColor];
	
	thankyouView = [[UIView alloc] initWithFrame:CGRectMake(0,0,768,1024)];
	thankyouView.center = CGPointMake(384, 492);
	thankyouView.backgroundColor = [UIColor blackColor];
	thankyouView.tag = 110;
	thankyouView.hidden = YES;
	thankyouView.userInteractionEnabled = YES;
	[self.view addSubview:thankyouView];
	
	UIImageView *bg_thankyouView = [[UIImageView alloc] initWithFrame:CGRectMake(0,0,768,1024)];
	bg_thankyouView.center = CGPointMake(384, 492);
	bg_thankyouView.image = [UIImage imageNamed:@"bg_thankyou.png"];
	bg_thankyouView.hidden = NO;
	bg_thankyouView.userInteractionEnabled = NO;
	bg_thankyouView.alpha = 1;
	//bg_formView.backgroundColor = [UIColor redColor];
	[thankyouView addSubview:bg_thankyouView];
	
	formView = [[UIView alloc] initWithFrame:CGRectMake(0,0,768,1024)];	
	formView.center = CGPointMake(384, 492);
	formView.hidden = NO;
	formView.tag = 10;
	formView.userInteractionEnabled = YES;
	formView.backgroundColor = [UIColor blackColor];
	[self.view addSubview:formView];
	
	UIImageView *bg_formView = [[UIImageView alloc] initWithFrame:CGRectMake(0,0,768,1024)];
	bg_formView.image = [UIImage imageNamed:@"bg_form.png"];
	bg_formView.hidden = NO;
	bg_formView.alpha = 1;
	bg_formView.userInteractionEnabled = NO;
	bg_formView.backgroundColor = [UIColor blackColor];
	[formView addSubview:bg_formView];
	
	submit = [[UIButton alloc] initWithFrame:CGRectMake(0,0,81,34)];
	submit.backgroundColor = [UIColor clearColor];
	submit.tag = 200;
	submit.center = CGPointMake(655,960);
	submit.userInteractionEnabled = YES;
	[submit setBackgroundImage:[UIImage imageNamed:@"btn_submit.png"] forState:UIControlStateNormal];
	//[btn setCenter:CGPointMake(230, 272)];
	submit.hidden = NO;
	[submit addTarget:self action:@selector(submitForm) forControlEvents:UIControlEventTouchUpInside];
	[formView addSubview:submit];
	
	currTextField = 400;
	
	float startX = 224;
	float startY = 242;
	
	firstName = [[UITextField alloc] initWithFrame:CGRectMake(0,0,280,30)];
	//firstName.autocapitalizationType = UITextAutocapitalizationTypeWords;
	firstName.autocorrectionType = UITextAutocorrectionTypeNo;
	firstName.alpha = 1;
	firstName.tag = 400;
	//firstName.textColor = [[UIColor alloc] initWithRed:.55 green:.55 blue:.55 alpha:1];
	firstName.textColor = [UIColor blackColor];
	firstName.font = [UIFont fontWithName:@"Helvetica" size:15];	
	firstName.backgroundColor = [UIColor clearColor];
	firstName.borderStyle = UITextBorderStyleRoundedRect;
	firstName.center = CGPointMake(startX, startY);
	firstName.placeholder = @"First Name";
	firstName.textAlignment = UITextAlignmentLeft;
	firstName.delegate = self;
	[formView addSubview:firstName];
	
	lastName = [[UITextField alloc] initWithFrame:CGRectMake(0,0,278,30)];
	lastName.alpha = 1;
	lastName.tag = 401;
	lastName.autocorrectionType = UITextAutocorrectionTypeNo;
	//lastName.textColor = [[UIColor alloc] initWithRed:.55 green:.55 blue:.55 alpha:1];
	lastName.textColor = [UIColor blackColor];
	lastName.font = [UIFont fontWithName:@"Helvetica" size:15];	
	lastName.backgroundColor = [UIColor clearColor];
	lastName.borderStyle = UITextBorderStyleRoundedRect;
	lastName.center = CGPointMake(startX + 320, startY);
	lastName.placeholder = @"Last Name";
	lastName.textAlignment = UITextAlignmentLeft;
	lastName.delegate = self;
	[formView addSubview:lastName];
	
	phone = [[UITextField alloc] initWithFrame:CGRectMake(0,0,278,30)];
	phone.alpha = 1;
	phone.tag = 402;
	phone.autocorrectionType = UITextAutocorrectionTypeNo;
	//phone.textColor = [[UIColor alloc] initWithRed:.55 green:.55 blue:.55 alpha:1];
	phone.textColor = [UIColor blackColor];
	phone.font = [UIFont fontWithName:@"Helvetica" size:15];	
	phone.backgroundColor = [UIColor clearColor];
	phone.borderStyle = UITextBorderStyleRoundedRect;
	phone.center = CGPointMake(startX, startY + 35);
	phone.placeholder = @"Phone";
	phone.textAlignment = UITextAlignmentLeft;
	phone.delegate = self;
	[phone setKeyboardType:UIKeyboardTypeNumberPad];
	[phone addTarget:self action:@selector(clearFormatPhone) forControlEvents:UIControlEventEditingDidBegin];
	[phone addTarget:self action:@selector(formatPhone) forControlEvents:UIControlEventEditingDidEnd];
	[formView addSubview:phone];
	
	phoneNum = [[NSMutableString alloc] init];
	
	email = [[UITextField alloc] initWithFrame:CGRectMake(0,0,280,30)];
	email.alpha = 1;
	email.tag = 403;
	//email.textColor = [[UIColor alloc] initWithRed:.55 green:.55 blue:.55 alpha:1];
	email.textColor = [UIColor blackColor];
	email.font = [UIFont fontWithName:@"Helvetica" size:15];	
	email.backgroundColor = [UIColor clearColor];
	email.borderStyle = UITextBorderStyleRoundedRect;
	email.center = CGPointMake(startX + 320, startY + 35);
	email.placeholder = @"Email";
	email.textAlignment = UITextAlignmentLeft;
	email.autocorrectionType = UITextAutocorrectionTypeNo;
	email.autocapitalizationType = UITextAutocapitalizationTypeNone;
	email.delegate = self;
	//[email addTarget:self action:@selector(formatEmail) forControlEvents:UIControlEventEditingChanged];
	[email setKeyboardType:UIKeyboardTypeEmailAddress];
	[formView addSubview:email];
	
	gender = [[UITextField alloc] initWithFrame:CGRectMake(0,0,140,30)];
	gender.alpha = 1;
	gender.tag = 404;
	gender.autocorrectionType = UITextAutocorrectionTypeNo;
	gender.autocapitalizationType = UITextAutocapitalizationTypeNone;
	//apt.textColor = [[UIColor alloc] initWithRed:.55 green:.55 blue:.55 alpha:1];
	gender.textColor = [UIColor blackColor];
	gender.font = [UIFont fontWithName:@"Helvetica" size:15];	
	gender.backgroundColor = [UIColor clearColor];
	gender.borderStyle = UITextBorderStyleRoundedRect;
	gender.center = CGPointMake(startX - 70, startY + 70);
	gender.placeholder = @"Gender (M or F)";
	gender.textAlignment = UITextAlignmentLeft;
	gender.delegate = self;
	[gender addTarget:self action:@selector(formatGender) forControlEvents:UIControlEventEditingDidEnd];
	
	[formView addSubview:gender];
	
	age = [[UITextField alloc] initWithFrame:CGRectMake(0,0,100,30)];
	age.alpha = 1;
	age.tag = 405;
	age.autocorrectionType = UITextAutocorrectionTypeNo;
	age.autocapitalizationType = UITextAutocapitalizationTypeNone;
	age.textColor = [UIColor blackColor];
	age.font = [UIFont fontWithName:@"Helvetica" size:15];	
	age.backgroundColor = [UIColor clearColor];
	age.borderStyle = UITextBorderStyleRoundedRect;
	age.center = CGPointMake(startX + 90, startY + 70);
	age.placeholder = @"Age";
	age.textAlignment = UITextAlignmentLeft;
	age.delegate = self;
	[formView addSubview:age];
	
	btn0 = [[RadioBtn alloc] initWithFrame:CGRectMake(0,0,50,50)];
	[btn0 initBtn];
	btn0.tag = 501;
	btn0.center = CGPointMake(103,479);
	[buttonsArray addObject:btn0];
	[formView addSubview:btn0];
	
	btn1 = [[RadioBtn alloc] initWithFrame:CGRectMake(0,0,50,50)];
	[btn1 initBtn];
	btn1.tag = 501;
	btn1.center = CGPointMake(300,479);
	[buttonsArray addObject:btn1];
	[formView addSubview:btn1];
	
	btn2 = [[RadioBtn alloc] initWithFrame:CGRectMake(0,0,50,50)];
	[btn2 initBtn];
	btn2.tag = 501;
	btn2.center = CGPointMake(103,517);
	[buttonsArray addObject:btn2];
	[formView addSubview:btn2];
	
	btn3 = [[RadioBtn alloc] initWithFrame:CGRectMake(0,0,50,50)];
	[btn3 initBtn];
	btn3.tag = 501;
	btn3.center = CGPointMake(300,517);
	[buttonsArray addObject:btn3];
	[formView addSubview:btn3];	
	
	btn4 = [[RadioBtn alloc] initWithFrame:CGRectMake(0,0,50,50)];
	[btn4 initBtn];
	btn4.tag = 501;
	btn4.center = CGPointMake(103,555);
	[buttonsArray addObject:btn4];
	[formView addSubview:btn4];
	
	btn5 = [[RadioBtn alloc] initWithFrame:CGRectMake(0,0,50,50)];
	[btn5 initBtn];
	btn5.tag = 501;
	btn5.center = CGPointMake(300,555);
	[buttonsArray addObject:btn5];
	[formView addSubview:btn5];
	
	btn6 = [[RadioBtn alloc] initWithFrame:CGRectMake(0,0,50,50)];
	[btn6 initBtn];
	btn6.tag = 502;
	btn6.center = CGPointMake(82,644);
	[buttonsArray addObject:btn6];
	[formView addSubview:btn6];
	
	btn7 = [[RadioBtn alloc] initWithFrame:CGRectMake(0,0,50,50)];
	[btn7 initBtn];
	btn7.tag = 502;
	btn7.center = CGPointMake(154,644);
	[buttonsArray addObject:btn7];
	[formView addSubview:btn7];
	
	btn8 = [[RadioBtn alloc] initWithFrame:CGRectMake(0,0,50,50)];
	[btn8 initBtn];
	btn8.tag = 503;
	btn8.center = CGPointMake(82,732);
	[buttonsArray addObject:btn8];
	[formView addSubview:btn8];
	
	btn9 = [[RadioBtn alloc] initWithFrame:CGRectMake(0,0,50,50)];
	[btn9 initBtn];
	btn9.tag = 503;
	btn9.center = CGPointMake(154,732);
	[buttonsArray addObject:btn9];
	[formView addSubview:btn9];
	
	btn10 = [[RadioBtn alloc] initWithFrame:CGRectMake(0,0,50,50)];
	[btn10 initBtn];
	btn10.tag = 504;
	btn10.center = CGPointMake(82,820);
	[buttonsArray addObject:btn10];
	[formView addSubview:btn10];
	
	btn11 = [[RadioBtn alloc] initWithFrame:CGRectMake(0,0,50,50)];
	[btn11 initBtn];
	btn11.tag = 504;
	btn11.center = CGPointMake(154,820);
	[buttonsArray addObject:btn11];
	[formView addSubview:btn11];
	
	for (int c = 0; c < [buttonsArray count]; c++){
		UIImageView *temp = [buttonsArray objectAtIndex:c];
		temp.hidden = NO;
		temp.alpha = 1;
		temp.userInteractionEnabled = YES;
	}
	[self.view bringSubviewToFront:formView];
	
	float _x = 120;
	
	r1 = [[UIImageView alloc] initWithFrame:CGRectMake(0,0,134,67)];
	r1.image = [UIImage imageNamed:@"required.png"];
	r1.hidden = NO;
	r1.alpha = 0;
	r1.tag = 0;
	r1.center = CGPointMake(_x, 375);
	//r1.center = CGPointMake(384, 375);
	[formView addSubview:r1];
	
	r2 = [[UIImageView alloc] initWithFrame:CGRectMake(0,0,134,67)];
	r2.image = [UIImage imageNamed:@"required.png"];
	r2.hidden = NO;
	r2.alpha = 0;
	r2.tag = 1;
	r2.center = CGPointMake(_x, 455);
	//r2.center = CGPointMake(284, 455);
	[formView addSubview:r2];
	
	r3 = [[UIImageView alloc] initWithFrame:CGRectMake(0,0,134,67)];
	r3.image = [UIImage imageNamed:@"required.png"];
	r3.hidden = NO;
	r3.alpha = 0;
	r3.tag = 2;
	r3.center = CGPointMake(_x, 522);
	//r3.center = CGPointMake(384, 522);
	[formView addSubview:r3];
	
	r4 = [[UIImageView alloc] initWithFrame:CGRectMake(0,0,134,67)];
	r4.image = [UIImage imageNamed:@"required.png"];
	r4.hidden = NO;
	r4.alpha = 0;
	r4.tag = 3;
	r4.center = CGPointMake(_x, 660);
	//r4.center = CGPointMake(384, 660);
	[formView addSubview:r4];
	
	//q7_txt = [[NSString alloc] init];
	
	rX = [[NSMutableArray alloc] init];
	[rX addObject:@"384"];
	[rX addObject:@"384"];
	[rX addObject:@"384"];
	[rX addObject:@"384"];
	
	rY = [[NSMutableArray alloc] init];
	[rY addObject:@"388"];
	[rY addObject:@"555"];
	[rY addObject:@"642"];
	[rY addObject:@"730"];
	
	rt1 = [[UILabel alloc] initWithFrame:CGRectMake(0,0,134,30)];
	rt1.alpha = 0;
	rt1.textColor = [UIColor redColor];
	rt1.font = [UIFont fontWithName:@"Helvetica" size:15];	
	rt1.backgroundColor = [UIColor clearColor];
	rt1.center = CGPointMake(startX+58, startY-2);
	rt1.text = @"*required";
	rt1.textAlignment = UITextAlignmentRight;
	[formView addSubview:rt1];
	
	rt2 = [[UILabel alloc] initWithFrame:CGRectMake(0,0,134,30)];
	rt2.alpha = 0;
	rt2.textColor = [UIColor redColor];
	rt2.font = [UIFont fontWithName:@"Helvetica" size:15];	
	rt2.backgroundColor = [UIColor clearColor];
	rt2.center = CGPointMake(startX+378, startY-2);
	rt2.text = @"*required";
	rt2.textAlignment = UITextAlignmentRight;
	[formView addSubview:rt2];
	
	rt3 = [[UILabel alloc] initWithFrame:CGRectMake(0,0,134,30)];
	rt3.alpha = 0;
	rt3.textColor = [UIColor redColor];
	rt3.font = [UIFont fontWithName:@"Helvetica" size:15];	
	rt3.backgroundColor = [UIColor clearColor];
	rt3.center = CGPointMake(startX+58, startY+33);
	rt3.text = @"*required";
	rt3.textAlignment = UITextAlignmentRight;
	[formView addSubview:rt3];	
	
	rt4 = [[UILabel alloc] initWithFrame:CGRectMake(0,0,134,30)];
	rt4.alpha = 0;
	rt4.textColor = [UIColor redColor];
	rt4.font = [UIFont fontWithName:@"Helvetica" size:15];	
	rt4.backgroundColor = [UIColor clearColor];
	rt4.center = CGPointMake(startX + 378, startY+33);
	rt4.text = @"*required";
	rt4.textAlignment = UITextAlignmentRight;
	[formView addSubview:rt4];	
	
	/*
	// question 7
	
	q7 = [[MapScroller alloc] initWithFrame:CGRectMake(0,0,314,247)];
	q7.center = CGPointMake (219, 824);
	q7.hidden = NO;
	q7.alpha = 0;
	q7.tag = 699;
	q7.userInteractionEnabled=YES;
	q7.showsVerticalScrollIndicator = YES;
	q7.showsHorizontalScrollIndicator = NO;
	[q7 setBackgroundColor:[UIColor clearColor]];
	q7.clipsToBounds = YES;		// default is NO, we want to restrict drawing within our scrollview
	q7.scrollEnabled = YES;
	q7.pagingEnabled = NO;
	q7.maximumZoomScale = 1;
	q7.minimumZoomScale = 1;
	q7.contentSize = CGSizeMake(298,176);
	[formView addSubview:q7];
	
	NSArray *q7Array = [NSArray arrayWithObjects:@"Less than 1 month",
						@"2-3 months",@"4-6 months",@"More than 6 months",nil];
	qArray = [[NSMutableArray alloc] init];
	for (int d = 0; d < 4; d++){
		State *_q = [[State alloc] initWithFrame:CGRectMake(0,0,298,44)];
		[_q initText:[q7Array objectAtIndex:d]];
		float _y = d*44+30;
		_q.tag = 700 + d;
		_q.center = CGPointMake (157, _y);
		_q.hidden = NO;
		_q.userInteractionEnabled = YES;
		[qArray addObject:_q];
		[q7 addSubview:_q];
	}		
	
	UIImageView *bg_q7 = [[UIImageView alloc] initWithFrame:CGRectMake(0,0,314,247)];
	bg_q7.image = [UIImage imageNamed:@"bg_q7.png"];
	bg_q7.hidden = NO;
	bg_q7.alpha = 1;
	bg_q7.tag = -102;
	bg_q7.center = CGPointMake (157,123.5);
	bg_q7.userInteractionEnabled = NO;
	[q7 addSubview:bg_q7];
	*/
	admin = [[AdminView alloc] initWithFrame:CGRectMake(0,0,768,1024)];
	admin.center = CGPointMake(384,512);
	admin.hidden = YES;
	admin.userInteractionEnabled  = YES;
	admin.backgroundColor = [UIColor blackColor];
	[admin initAdminView];
	[self.view addSubview:admin];
	
	UIView *adminHotSpot = [[UIView alloc] initWithFrame:CGRectMake(0,0,150,150)];
	adminHotSpot.backgroundColor = [UIColor clearColor];
	adminHotSpot.hidden = NO;
	adminHotSpot.tag = 300;
	adminHotSpot.center = CGPointMake(693, 75);
	adminHotSpot.userInteractionEnabled = YES;
	[formView addSubview:adminHotSpot];
	
	
	[[NSNotificationCenter defaultCenter] addObserver:self selector:@selector(showEmailModalView) name:@"EmailData" object:admin];
	[[NSNotificationCenter defaultCenter] addObserver:self selector:@selector(showForm) name:@"ReturnToForm" object:admin];
	
	formData = [[NSString alloc] initWithString:@""];
	
	NSFileManager *filemgr;
	filemgr = [NSFileManager defaultManager];
	NSData *dataBuffer = [[NSData alloc] init];
	
	NSArray *paths = NSSearchPathForDirectoriesInDomains(NSDocumentDirectory, NSUserDomainMask, YES); NSString *documentsDirectory = [paths objectAtIndex:0]; 
	NSString *path = [NSString stringWithFormat:@"%@/VasqueData.txt",documentsDirectory];
	NSLog(@"%@",path);
	if ([filemgr fileExistsAtPath:path] == YES) {
        dataBuffer = [filemgr contentsAtPath: path];
		formData = [NSString stringWithUTF8String:[dataBuffer bytes]];
		NSLog (@"File exists");
		NSLog(@"formData to start file:\r\n%@",formData);
	}
	else {
        NSLog (@"File not found");
		NSError *error = noErr;
		NSString *introText = [NSString stringWithFormat:@"%@%@%@%@%@",[questionsTextArray objectAtIndex:0],
							   [questionsTextArray objectAtIndex:1],[questionsTextArray objectAtIndex:2],
							   [questionsTextArray objectAtIndex:3],[questionsTextArray objectAtIndex:4]];
		
		
		
        BOOL success = [introText writeToFile:path atomically:YES encoding:NSUTF8StringEncoding error:&error];
        if (!success) {
            // handle the error
            NSLog(@"%@", error);
        }
		else {
			NSLog(@"new file created. header text: %@",introText);
		}
	}
	
	toolbar = [[UIToolbar alloc] initWithFrame:CGRectMake(0, 0, 768, 50)];
	toolbar.center = CGPointMake(384, 1050);
	toolbar.barStyle = UIBarStyleDefault;
	//toolbar.barStyle = UIBarStyleBlackTranslucent;
	toolbar.tintColor = [UIColor lightGrayColor];
	//toolbar.tintColor = [[UIColor alloc] initWithRed:.07 green:.11 blue:.17 alpha:1];
	UIBarButtonItem *previous = [[UIBarButtonItem alloc] initWithTitle:@"prev" style:UIBarButtonItemStyleBordered target:self action:@selector(prevClicked)];
	previous.tag = 0;
	UIBarButtonItem *next = [[UIBarButtonItem alloc] initWithTitle:@"next" style:UIBarButtonItemStyleBordered target:self action:@selector(nextClicked)];
	next.tag = 1;
	UIBarButtonItem *done = [[UIBarButtonItem alloc] initWithTitle:@"done" style:UIBarButtonItemStyleDone target:self action:@selector(doneClicked)];
	done.tag = 2;
	UIBarButtonItem *BtnSpace = [[UIBarButtonItem alloc]initWithBarButtonSystemItem:UIBarButtonSystemItemFlexibleSpace target:self action:nil];
	NSArray *items = [[NSArray alloc] initWithObjects: previous, next, BtnSpace, done, nil];
	[toolbar setItems:items];
	[items release];
	[formView addSubview:toolbar];
	
	[[NSNotificationCenter defaultCenter] addObserver:self selector:@selector(keyboardWillShow:) name:UIKeyboardWillShowNotification object:nil]; 
    [[NSNotificationCenter defaultCenter] addObserver:self selector:@selector(keyboardWillHide:) name:UIKeyboardWillHideNotification object:nil]; 
	
	//currQ7 = 0;
	//currState = 0;
	//[formView bringSubviewToFront:statesView];
	
	[super viewDidLoad];
}

- (void)keyboardWillShow:(NSNotification *)notification {
	[UIView beginAnimations:nil context:nil];
	[UIView setAnimationDuration:.4];
	toolbar.center = CGPointMake(384, 736);
	[UIView commitAnimations];
}
- (void)keyboardWillHide:(NSNotification *)notification {
	[UIView beginAnimations:nil context:nil];
	[UIView setAnimationDuration:.4];
	toolbar.center = CGPointMake(384, 1050);
	[UIView commitAnimations];
}
-(void)nextClicked {
	NSLog(@"textFieldShouldReturn");
	currTextField++;
	if (currTextField == 406){
		currTextField = 400;
		NSInteger nextTag = currTextField;
		UIResponder* nextResponder = [self.view viewWithTag:nextTag];
		[nextResponder becomeFirstResponder];
	}
	else {
		NSInteger nextTag = currTextField;
		// Try to find next responder
		UIResponder* nextResponder = [self.view viewWithTag:nextTag];
		if (nextResponder) {
			// Found next responder, so set it.
			[nextResponder becomeFirstResponder];
		} else {
			// Not found, so remove keyboard.
			[self hideKeyboard];
		}
	}
}
-(void)prevClicked {
	NSLog(@"textFieldShouldReturn");
	currTextField--;
	if (currTextField == 399){
		currTextField = 405;
		NSInteger nextTag = currTextField;
		UIResponder* nextResponder = [self.view viewWithTag:nextTag];
		[nextResponder becomeFirstResponder];
	}
	else {
		NSInteger nextTag = currTextField;
		// Try to find next responder
		UIResponder* nextResponder = [self.view viewWithTag:nextTag];
		if (nextResponder) {
			// Found next responder, so set it.
			[nextResponder becomeFirstResponder];
		} else {
			// Not found, so remove keyboard.
			[self hideKeyboard];
		}
	}
}

-(void) doneClicked {
	//UIBarButtonItem *b = sender;
	//NSLog(@"button tag: %i",b.tag);
	//if (b.tag == 2){
	[self hideKeyboard];
	//}
}
-(void) formatGender {
	gender.text = [gender.text uppercaseString];
}
- (BOOL)textField:(UITextField *)textField shouldChangeCharactersInRange:(NSRange)range replacementString:(NSString *)string {
	//NSLog(@"textField function");
	BOOL results = FALSE;
	
	//NSLog(@"tf(): %i",textField.tag);
	/*
	 403 address 1
	 405 state
	 406 zip
	 409 phone
	 410 email
	 */
	
	currTextField = textField.tag;
	if (textField.tag == 404){ // gender 
		
		 //NSArray* alphaArray = [NSArray arrayWithObjects: @"A", @"B", @"C", @"D",@"E",@"F",
		 //@"G",@"H",@"I",@"J",@"K",@"L",@"M",@"N",@"O",@"P",@"Q",@"R",
		 //@"S",@"T",@"U",@"V",@"W",@"X",@"Y",@"Z",nil];
		NSArray* alphaArray = [NSArray arrayWithObjects: @"M",@"F",nil];
							   
		if ([alphaArray containsObject:[string uppercaseString]]) {
			 if ([gender.text length] < 1){
				 results = TRUE;
			 }
		 }
		 else if ([string isEqualToString:@""]) {
			 results = TRUE;
		 }
		 
	}
	else if (textField.tag == 402){ // phone
		//NSLog(@"phone textfield!");
		NSArray* numericArray = [NSArray arrayWithObjects: @"0", @"1", @"2", @"3",@"4",@"5",@"6",@"7",@"8",@"9",nil];
		
		if ([numericArray containsObject:string]){
			if ([phoneNum length] < 10){
				results = TRUE;
				[phoneNum appendFormat:string];
				//		NSLog(@"phoneNum: %@",phoneNum);
			}	
		}
		else if ([string isEqualToString:@""]) {
			results = TRUE;
			[phoneNum replaceCharactersInRange:NSMakeRange([phoneNum length]-1, 1) withString:@""];
		}
	}
	else if (textField.tag == 405){ // age code 
		NSLog(@"zip textfield!");
		NSArray* numericArray = [NSArray arrayWithObjects: @"0", @"1", @"2", @"3",@"4",@"5",@"6",@"7",@"8",@"9",nil];
		
		if ([numericArray containsObject:string]){
			if ([age.text length] < 3){
				results = TRUE;
			}
		}
		else if ([string isEqualToString:@""]) {
			results = TRUE;
		}
	}
	else {
		results = TRUE;
	}
	
	return results;
}

-(void) clearFormatPhone {
	phone.text = phoneNum;
}

-(void) formatPhone {
	
	if ([phoneNum length] > 3){
		NSString *tempStr = [[NSString alloc] initWithString:@""];
		NSString *areaCode = [phoneNum substringToIndex:3];
		NSString *phone1;
		NSString *phone2;
		NSRange range;
		
		if ([phoneNum length] < 7) {
			range.length = [phoneNum length] - 3;
			range.location = 3;
			
			phone1 = [phoneNum substringWithRange:range];
			tempStr	= [NSString stringWithFormat:@"(%@) %@", areaCode, phone1];	
		}
		else if ([phoneNum length] >= 7) {
			range.length = 3;
			range.location = 3;
			
			phone1 = [phoneNum substringWithRange:range];
			phone2 = [phoneNum substringFromIndex:6];
			tempStr	= [NSString stringWithFormat:@"(%@) %@-%@", areaCode, phone1,phone2];	
		}
		phone.text = tempStr;
	}
}

-(BOOL) emailIsValid {
	BOOL isAtSymbol = FALSE;
	BOOL isPeriod = FALSE;
	NSRange range;
	
	for (int i = 0; i < [email.text length]; i++){
		range.length = 1;
		range.location = i;
		
		NSString *temp = [email.text substringWithRange:range];
		if ([temp isEqualToString:@"@"]){
			isAtSymbol = TRUE;
		}
		else if ([temp isEqualToString:@"."]) {
			isPeriod = TRUE;
		}
	}
	if (isAtSymbol && isPeriod){
		return TRUE;
	}
	else {
		return FALSE;
	}
}

-(void)showAdmin{
	[admin showKeyboard];
	[UIView beginAnimations:nil context:nil];
	[UIView setAnimationDuration:1];
	//[UIView setAnimationTransition:UIViewAnimationTransitionFlipFromRight forView:self.view cache:YES];
	[UIView setAnimationTransition:UIViewAnimationTransitionCurlUp forView:[self.view superview] cache:YES];
	admin.hidden = NO;
	formView.hidden = YES;
	
	[UIView commitAnimations];	
}
-(void)showForm{
	[self resetForm];
	[UIView beginAnimations:nil context:nil];
	[UIView setAnimationDuration:1];
	[UIView setAnimationTransition:UIViewAnimationTransitionFlipFromRight forView:[self.view superview] cache:YES];
	admin.hidden = YES;
	formView.hidden = NO;
	[UIView setAnimationDelegate:self];
	[UIView setAnimationDidStopSelector:@selector(hideAdminKeyboard)];
	[UIView commitAnimations];	
}
/*-(void)showQ7 {
	q7.alpha = 1;
}
-(void)hideQ7 {
	q7.alpha = 0;
}
 */
-(void)hideAdminKeyboard{
	[admin hideKeyboard];	
}

-(void) showReqText:(UILabel *)_l {
	[UIView beginAnimations:nil context:_l];
	//[UIView setAnimationDelay:_delay];
	[UIView setAnimationDuration:.25];		
	_l.alpha = 1;
	[UIView setAnimationDelegate:self];
	[UIView setAnimationDidStopSelector:@selector(hideReqText:finished:context:)];
	[UIView commitAnimations];		
}
-(void) hideReqText:(NSString *)animationID finished:(NSNumber *)finished context:(void *)_l {
	UILabel *tempLabel = (UILabel *)_l;
	[UIView beginAnimations:nil context:tempLabel];
	[UIView setAnimationDelay:2.25];
	[UIView setAnimationDuration:.25];		
	tempLabel.alpha = 0;
	[UIView commitAnimations];			
}

-(void) showReq:(UIImageView *)_v {
	//float _x = [[rX objectAtIndex:_v.tag] floatValue];
	float _y = [[rY objectAtIndex:_v.tag] floatValue] + 30;
	float _delay = _v.tag *.1;
	float _x = 120;
	[UIView beginAnimations:nil context:_v];
	[UIView setAnimationDelay:_delay];
	[UIView setAnimationDuration:.25];		
	_v.center = CGPointMake(_x,_y);
	_v.alpha = 1;
	[UIView setAnimationDelegate:self];
	[UIView setAnimationDidStopSelector:@selector(showReq2:finished:context:)];
	[UIView commitAnimations];	
}
-(void) showReq2:(NSString *)animationID finished:(NSNumber *)finished context:(void *)_c {
	UIImageView *_v = (UIImageView *)_c;
	//float _x = [[rX objectAtIndex:_v.tag] floatValue];
	float _y = [[rY objectAtIndex:_v.tag] floatValue]+15;
	float _x = 120;
	[UIView beginAnimations:nil context:_v];
	[UIView setAnimationDuration:.1];		
	_v.center = CGPointMake(_x,_y);
	[UIView setAnimationDelegate:self];
	[UIView setAnimationDidStopSelector:@selector(showReq3:finished:context:)];
	[UIView commitAnimations];	
}
-(void) showReq3:(NSString *)animationID finished:(NSNumber *)finished context:(void *)_c {
	UIImageView *_v = (UIImageView *)_c;
	//float _x = [[rX objectAtIndex:_v.tag] floatValue];
	float _y = [[rY objectAtIndex:_v.tag] floatValue]+30;
	//NSLog(@"ShowReq3 y: %f",_y);
	
	float _x = 120;
	[UIView beginAnimations:nil context:_v];
	[UIView setAnimationDuration:.1];		
	_v.center = CGPointMake(_x,_y);
	[UIView setAnimationDelegate:self];
	[UIView setAnimationDidStopSelector:@selector(hideReq:finished:context:)];
	[UIView commitAnimations];	
}

-(void) hideReq:(NSString *)animationID finished:(NSNumber *)finished context:(void *)_c {
	//NSLog(@"context: %@",_c);
	UIImageView *_v = (UIImageView *)_c;
	//float _x = [[rX objectAtIndex:_v.tag] floatValue];
	float _y = [[rY objectAtIndex:_v.tag] floatValue];
	
	float _x = 120;
	[UIView beginAnimations:nil context:nil];
	[UIView setAnimationDelay:1.5];
	[UIView setAnimationDuration:.25];
	_v.center = CGPointMake(_x, _y);
	_v.alpha = 0;
	[UIView commitAnimations];		
}
/*
-(void)clearQ7:(int)i {
	NSLog(@"clearQ7: %@",[qArray objectAtIndex:i]);
	State *temp = [qArray objectAtIndex:i];
	[temp upState];	
}
-(void)clearState:(int)i {
	NSLog(@"clearState: %@",[sArray objectAtIndex:i]);
	State *temp = [sArray objectAtIndex:i];
	[temp upState];
}
 */
-(BOOL) contentIsGood {
	BOOL results = TRUE;
	if ([firstName.text isEqualToString: @""] || (firstName.text == NULL)) {
		results = FALSE;
		[self showReqText:rt1];
	}
	if ([lastName.text isEqualToString: @""] || (lastName.text == NULL)) {
		results = FALSE;
		[self showReqText:rt2];		
	}
	if ([phone.text isEqualToString: @""] || (phone.text == NULL)) {
		results = FALSE;
		[self showReqText:rt3];
		
	}
	if ([email.text isEqualToString: @""] || (email.text == NULL)) {
		results = FALSE;
		[self showReqText:rt4];
	}	
	if (([phoneNum length] > 0) && ([phoneNum length] < 10)){
		results = FALSE;
		rt3.text = @"*10 digits required";
		[self showReqText:rt3];		
	}
	if ([email.text length] > 0) {
		if (![self emailIsValid]){
			rt4.text = @"*invalid address";
			[self showReqText:rt4];
			results = FALSE;
		}
	}
	if (![btn0 btnTouched] && ![btn1 btnTouched]) {
		[self showReq:r1];	
		results = FALSE;
	}
	if (![btn2 btnTouched] && ![btn3 btnTouched]) {
		[self showReq:r2];	
		results = FALSE;
	}
	if (![btn4 btnTouched] && ![btn5 btnTouched] && ![btn6 btnTouched] && ![btn7 btnTouched]) {
		[self showReq:r3];		
		results = FALSE;
	}
	if (![btn8 btnTouched] && ![btn9 btnTouched] && ![btn10 btnTouched]) {
		[self showReq:r4];
		results = FALSE;
	}
	if (![btn11 btnTouched]){}
	return results;
}

-(NSString *) appendFormData {
	//NSString *results = [NSString stringWithFormat:@"%@ %@ %@\n%@, %@ %@ %@\n%@ %@\n%@\n%@\n\nAnswers: \n",
	NSString *results = [NSString stringWithFormat:@"\r\n%@,%@,%@,%@,%@,%@,",
						 firstName.text,lastName.text,phone.text,email.text,gender.text,age.text];
	
	NSString *tempResults = [NSString stringWithFormat:@""];
	
	for (int c = 0; c < 6; c++){
		RadioBtn *b = [buttonsArray objectAtIndex:c];
		if ([b btnTouched]){
			tempResults = [tempResults stringByAppendingFormat:@"%@,",[answersTextArray objectAtIndex:c]];
		}
	}
	if (![tempResults isEqualToString:@""] && (tempResults != NULL)){
		results = [results stringByAppendingFormat:@"\"%@\",",tempResults];
	}
	NSLog(@"results before last buttons: %@",results);
	for (int d = 6; d < [buttonsArray count]; d++){
		RadioBtn *b2 = [buttonsArray objectAtIndex:d];
		if ([b2 btnTouched]){
			NSString *tempString = [answersTextArray objectAtIndex:d];
			results = [results stringByAppendingFormat:@"%@,",tempString];
		}
	}
	return results;
}

-(void) submitForm {
	if ([self contentIsGood]){
		NSArray *paths = NSSearchPathForDirectoriesInDomains(NSDocumentDirectory, NSUserDomainMask, YES); NSString *documentsDirectory = [paths objectAtIndex:0]; 
		NSString *path = [NSString stringWithFormat:@"%@/VasqueData.txt",documentsDirectory];
		NSString *results = [self appendFormData];
		//NSLog(@"submitForm results: %@",results);
		[self writeContents:results toFile:path];
		[UIView beginAnimations:nil context:nil];
		[UIView setAnimationDelay:.5];
		[UIView setAnimationDuration:1];
		[UIView setAnimationTransition:UIViewAnimationTransitionFlipFromRight forView:[self.view superview] cache:YES];
		formView.hidden = YES;
		thankyouView.hidden = NO;
		//the selector only works if you set the delegate here
		//[UIView setAnimationDidStopSelector:@selector(resetForm)];
		//[UIView setAnimationDelegate:self];
		[UIView commitAnimations];		
	}
}
-(void)hideKeyboard {
	[firstName resignFirstResponder];
	[lastName resignFirstResponder];
	[phone resignFirstResponder];
	[email resignFirstResponder];	
	[gender resignFirstResponder];	
	[age resignFirstResponder];	
	
}
-(void) resetForm {
	
	for (int c = 0; c < [buttonsArray count]; c++){
		RadioBtn *temp = [buttonsArray objectAtIndex:c];
		[temp btnOff];
	}
	firstName.text = @"";
	lastName.text = @"";
	phone.text = @"";
	email.text = @"";
	gender.text = @"";
	age.text = @"";
	[phoneNum setString:@""];
	
	[UIView beginAnimations:nil context:nil];
	//[UIView setAnimationDelay:1.5];
	[UIView setAnimationDuration:1];
	[UIView setAnimationTransition:UIViewAnimationTransitionFlipFromRight forView:[self.view superview] cache:YES];
	formView.hidden = NO;
	thankyouView.hidden = YES;
	[UIView commitAnimations];		
	
	//[self clearState:currState];
	//[self clearQ7:currQ7];
	//currState = 0;
	//currQ7 = 0;
}

-(void)updateButtons:(RadioBtn *)_btn {
	//NSLog(@"updateBUttons, received: %@",_btn);
	if (_btn.tag != 501){
		for (int c = 0; c < [buttonsArray count]; c++) {
			RadioBtn *temp = [buttonsArray objectAtIndex:c];
			if (temp.tag == _btn.tag){
				if (temp != _btn){
					[temp btnOff];
				}
			//		NSLog(@"tag match for: %i",c);
			}
		}
	}	
}
-(NSString *)getFullState:(int)_i {
	NSArray *statesFullArray = [NSArray arrayWithObjects:@"Alaska",@"Alabama",@"Arkansas",@"Arizona",
								@"California",@"Colorado",@"Connecticut",@"District of Columbia",
								@"Delaware",@"Florida",@"Georgia",@"Hawaii",@"Iowa",@"Idaho",
								@"Illinois",@"Indiana",@"Kansas",@"Kentucky",@"Louisiana",
								@"Massachusetts",@"Maryland",@"Maine",@"Michigan",@"Minnesota",
								@"Missouri",@"Mississippi",@"Montana",@"North Carolina",
								@"North Dakota",@"Nebraska",@"New Hampshire",@"New Jersey",
								@"New Mexico",@"Nevada",@"New York",@"Ohio",@"Oklahoma",
								@"Oregon",@"Pennsylvania",@"Rhode Island",@"South Carolina",
								@"South Dakota",@"Tennessee",@"Texas",@"Utah",@"Virginia",
								@"Vermont",@"Washington",@"Wisconsin", @"West Virginia",
								@"Wyoming",nil];
	
	return [statesFullArray objectAtIndex:_i];
}


-(NSString *)getState:(int)_i {
	NSArray *statesArray = [NSArray arrayWithObjects:@"AK",@"AL",@"AR",@"AZ",@"CA",@"CO",@"CT",
							@"DC",@"DE",@"FL",@"GA",@"HI",@"IA",@"ID",
							@"IL",@"IN",@"KS",@"KY",@"LA",@"MA",@"MD",
							@"ME",@"MI",@"MN",@"MO",@"MS",@"MT",@"NC",
							@"ND",@"NE",@"NH",@"NJ",@"NM",@"NV",@"NY",
							@"OH",@"OK",@"OR",@"PA",@"RI",@"SC",@"SD",
							@"TN",@"TX",@"UT",@"VA",@"VT",@"WA",@"WI",
							@"WV",@"WY",nil];	
	return [statesArray objectAtIndex:_i];
}

-(void)touchesBegan:(NSSet *)touches withEvent:(UIEvent *)event	{
	UITouch *touch = [touches anyObject];
	//NSLog(@"touch: %@",touch.view);
	//UIImageView *_v = (UIImageView *)touch.view;
	NSLog(@"button touch: %i",touch.view.tag);
	
	// radio buttons
	if ((touch.view.tag > 500) && (touch.view.tag < 600)){
		//RadioBtn *temp = (RadioBtn *) touch.view;
		[self hideKeyboard];
	}
	// quiz background
	else if (touch.view.tag == 10){
		[self hideKeyboard];
	}
	//thank you page
	else if ((touch.view.tag == 110) && ([touch tapCount] == 2)){
		[self resetForm];
	}
	// admin hotspot in top right corner
	else if ((touch.view.tag == 300) && ([touch tapCount] == 3) && (!formView.hidden)){
		[self showAdmin];
	}
	/*
	// question 7 responses
	else if ((touch.view.tag >= 700) && (touch.view.tag < 800)) {
		State *temp = (State *)touch.view;
		[temp downState];
		int _s = touch.view.tag - 700;
		if (currQ7 != _s){
			[self clearQ7:currQ7];
			currQ7 = _s;
		}
	} 
	// states 
	else if (touch.view.tag >= 1000) {
		State *temp = (State *)touch.view;
		[temp downState];
		// if current touched item is not the previous one, clear previous
		int _t = touch.view.tag - 1000;
		if (currState != _t){
			NSLog(@"touches ended 1000, tag: %i",_t);
			[self clearState:currState];
			currState = _t;
		}
	}
	*/
	
}

-(void)touchesEnded:(NSSet *)touches withEvent:(UIEvent *)event	{
	UITouch *touch = [touches anyObject];
	//UIImageView *_v = (UIImageView *)touch.view;
	
	if ((touch.view.tag > 500) && (touch.view.tag < 600)){
		RadioBtn *temp = (RadioBtn *) touch.view;
		//[temp btnOff];
		if (touch.view.tag == 501){
			if ([temp btnTouched]){
				
				[temp btnOff];
			}
			else {
				[temp btnOn];
			}
		}
		else {
			[temp btnOn];
		}
		[self updateButtons:temp];
	}
	else if ((touch.view.tag >= 700) && (touch.view.tag < 800)) {
		//State *temp = (State *)touch.view;
		//[temp upState];
		//q7_txt = [temp getTxt];
		//[self hideQ7];
	}
	else if (touch.view.tag >= 1000) {
		//int _t = touch.view.tag - 1000;
		//state.text = [self getState:_t];
	}
}

// Dismisses the email composition interface when users tap Cancel or Send. Proceeds to update the message field with the result of the operation.

- (void)mailComposeController:(MFMailComposeViewController*)controller didFinishWithResult:(MFMailComposeResult)result error:(NSError*)error
{ 
	// Notifies users about errors associated with the interface
	switch (result)
	{
		case MFMailComposeResultCancelled:
			break;
		case MFMailComposeResultSaved:
			break;
		case MFMailComposeResultSent:
			break;
		case MFMailComposeResultFailed:
			break;
			
		default:
		{
			UIAlertView *alert = [[UIAlertView alloc] initWithTitle:@"Email" message:@"Sending Failed - Unknown Error :-("
														   delegate:self cancelButtonTitle:@"OK" otherButtonTitles: nil];
			[alert show];
			[alert release];
		}
			
			break;
	}
	[self dismissModalViewControllerAnimated:YES];
}

///
-(void) showEmailModalView {
	NSFileManager *filemgr;
	filemgr = [NSFileManager defaultManager];
	NSData *dataBuffer = [[NSData alloc] init];
	NSArray *paths = NSSearchPathForDirectoriesInDomains(NSDocumentDirectory, NSUserDomainMask, YES); NSString *documentsDirectory = [paths objectAtIndex:0]; 
	NSString *path = [NSString stringWithFormat:@"%@/VasqueData.txt",documentsDirectory];
	dataBuffer = [filemgr contentsAtPath:path];
	//NSString *formText = [NSString stringWithUTF8String:[dataBuffer bytes]];
	//NSLog(@"formText: %@",formText);
	
	
	
	MFMailComposeViewController *picker = [[MFMailComposeViewController alloc] init];
	picker.mailComposeDelegate = self; // &lt;- very important step if you want feedbacks on what the user did with your email sheet
	[picker addAttachmentData:dataBuffer mimeType:@"text/csv" fileName:@"VasqueData.csv"];
	
	[picker setSubject:@"Vasque Event - Form Submission Data"];
	
	// Fill out the email body text
	//NSString *emailBody = formText;
	NSString *emailBody = @"Vasque data file attached!";
	
	[picker setMessageBody:emailBody isHTML:YES]; // depends. Mostly YES, unless you want to send it as plain text (boring)
	
	picker.navigationBar.barStyle = UIBarStyleBlack; // choose your style, unfortunately, Translucent colors behave quirky.
	
	[self presentModalViewController:picker animated:YES];
	[picker release];
	
	NSLog(@"CSV sent: %@",[NSString stringWithUTF8String:[dataBuffer bytes]]);
	
}



- (void)writeContents:(NSString *)text toFile:(NSString *)filePath {
	// NSFileHandle won't create the file for us, so we need to check to make sure it exists
    NSFileManager *fileManager = [NSFileManager defaultManager];
    if (![fileManager fileExistsAtPath:filePath]) {
		NSLog(@"File doesn't exist, write out the text");
        // the file doesn't exist yet, so we can just write out the text using the 
        // NSString convenience method
		
        NSError *error = noErr;
		NSString *introText = [NSString stringWithFormat:@"%@%@%@%@%@%@",[questionsTextArray objectAtIndex:0],
							   [questionsTextArray objectAtIndex:1],[questionsTextArray objectAtIndex:2],
							   [questionsTextArray objectAtIndex:3],[questionsTextArray objectAtIndex:4],text];
		
        BOOL success = [introText writeToFile:filePath atomically:YES encoding:NSUTF8StringEncoding error:&error];
        if (!success) {
            // handle the error
            NSLog(@"%@", error);
        }
		
    } else {
		NSLog(@"File exists, appending new text to end");
		
        // the file already exists, so we should append the text to the end
		
        // get a handle to the file
        NSFileHandle *fileHandle = [NSFileHandle fileHandleForWritingAtPath:filePath];
		
        // move to the end of the file
        [fileHandle seekToEndOfFile];
		
        // convert the string to an NSData object
        NSData *textData = [text dataUsingEncoding:NSUTF8StringEncoding];
		
        // write the data to the end of the file
        [fileHandle writeData:textData];
		
        // clean up
        [fileHandle closeFile];
    }
}

- (BOOL)shouldAutorotateToInterfaceOrientation:(UIInterfaceOrientation)interfaceOrientation {
	// Return YES for supported orientations.
	return (interfaceOrientation == UIInterfaceOrientationPortrait || interfaceOrientation == UIInterfaceOrientationPortraitUpsideDown);
}

- (void)didReceiveMemoryWarning {
	// Releases the view if it doesn't have a superview.
    [super didReceiveMemoryWarning];
	
	// Release any cached data, images, etc that aren't in use.
}

- (void)viewDidUnload {
	// Release any retained subviews of the main view.
	// e.g. self.myOutlet = nil;
}


- (void)dealloc {
	[admin release];
	[formView release];
	[formData release];
	[thankyouView release];
	[buttonsArray release];
	[submit release];
	[firstName release];
	[lastName release];
	[phone release];
	[phoneNum release];
	[email release];
	[gender release];
	[age release];
	[answersTextArray release];
	[questionsTextArray release];
	[r1 release];
	[r2 release];
	[r3 release];
	[r4 release];
	[rt1 release];
	[rt2 release];
	[rt3 release];
	[rt4 release];
//	[q7 release];
//	[q7_txt release];
//	[qArray release];
	[rX release];
	[rY release];
	[btn0 release];
	[btn1 release];
	[btn2 release];
	[btn3 release];
	[btn4 release];
	[btn5 release];
	[btn6 release];
	[btn7 release];
	[btn8 release];
	[btn9 release];
	[btn10 release];
	[btn11 release];
	[toolbar release];
	[super dealloc];
}

@end
