//
//  ResultWebDetailView.m
//  Free Name
//
//  Created by Willem Laurentz Middelkoop on 14-03-11.
//  Copyright 2011 WMIT. All rights reserved.
//

#import "ResultWebDetailViewController.h"
#import "NameCheckResult.h"
#import "NameCheck.h"

@implementation ResultWebDetailViewController

@synthesize nameCheck,nameCheckResult;

// Implement viewDidLoad to do additional setup after loading the view, typically from a nib.
- (void)viewDidLoad {
    [super viewDidLoad];

	// do magic things here
	
	self.navigationItem.title = nameCheckResult.testValue;
	
	NSString *urlAddress =nil;// @"http://www.wmit.nl";
	
	if([nameCheckResult.nameCheckType isEqual:@"INTERNET_DOMAIN_NAME"]){
		urlAddress = [NSString stringWithFormat:@"http://www.%@",nameCheckResult.testValue];
	}else if([nameCheckResult.nameCheckType isEqual:@"TWITTER"]){
		urlAddress = [NSString stringWithFormat:@"http://www.twitter.com/%@",nameCheckResult.testValue];	
	}else if([nameCheckResult.nameCheckType isEqual:@"INTERNET_SEARCH"]){
		
		NSString *rawSearchValue = [NSString stringWithFormat:@"\"%@\"",nameCheckResult.testValue];
		NSString *encodedTestValue = (NSString *)CFURLCreateStringByAddingPercentEscapes(
																					  NULL,
																					  (CFStringRef)rawSearchValue,
																					  NULL,
																					  (CFStringRef)@"!*'();:@&=+$,/?%#[]",
																					  kCFStringEncodingUTF8 );
		
		urlAddress = [NSString stringWithFormat:@"http://www.google.com/search?q=%@&ie=UTF-8&oe=UTF-8&client=safari&nfpr=1",encodedTestValue];
        [encodedTestValue release];
	}else if([nameCheckResult.nameCheckType isEqual:@"APPLE_ITUNES"]){
		
		NSString *rawSearchValue = [NSString stringWithFormat:@"site:itunes.apple.com \"%@\"",nameCheckResult.testValue];
		NSString *encodedTestValue = (NSString *)CFURLCreateStringByAddingPercentEscapes(
																						 NULL,
																						 (CFStringRef)rawSearchValue,
																						 NULL,
																						 (CFStringRef)@"!*'();:@&=+$,/?%#[]",
																						 kCFStringEncodingUTF8 );
		
		urlAddress = [NSString stringWithFormat:@"http://www.google.com/search?q=%@&ie=UTF-8&oe=UTF-8&client=safari&nfpr=1",encodedTestValue];
        [encodedTestValue release];
	}
	
	NSURL *url = [NSURL URLWithString:urlAddress];
	NSURLRequest *requestObj = [NSURLRequest requestWithURL:url];
	webView.scalesPageToFit = YES;
	
	[webView loadRequest:requestObj];
}

- (void)viewWillAppear:(BOOL)animated {
	self.navigationController.navigationBar.tintColor = [UIColor colorWithRed:211/255.0 green:0/255.0 blue:0/255.0 alpha:1.0];
	
    [super viewWillAppear:animated];
}

/*
// Override to allow orientations other than the default portrait orientation.
- (BOOL)shouldAutorotateToInterfaceOrientation:(UIInterfaceOrientation)interfaceOrientation {
    // Return YES for supported orientations.
    return (interfaceOrientation == UIInterfaceOrientationPortrait);
}
*/

- (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 {
    [super viewDidUnload];
    // Release any retained subviews of the main view.
    // e.g. self.myOutlet = nil;
}


- (void)dealloc {
    [super dealloc];
}


@end
