//
//  ViewController.m
//  Momsens
//
//  Created by Fredrik Åkerström on 22/05/2015.
//  Copyright (c) 2015 Fredrik Åkerström. All rights reserved.
//

#import "ViewController.h"

@interface ViewController ()

@end

@implementation ViewController
@synthesize SearchPhrase, MomsensSearchField;

-(IBAction)OpenWebKnappen:(id)sender{
    [[UIApplication sharedApplication] openURL:[NSURL URLWithString:@"http://www.momsens.se"]];
}

-(IBAction)OpenBlogg:(id)sender{
    [[UIApplication sharedApplication] openURL:[NSURL URLWithString:@"http://www.momsens.se/moms-blogg"]];
}

-(IBAction)OpenEUmoms:(id)sender{
    [[UIApplication sharedApplication] openURL:[NSURL URLWithString:@"http://www.momsens.se/eu-moms"]];
} 

-(IBAction)OpenLathundBokforing:(id)sender{
    [[UIApplication sharedApplication] openURL:[NSURL URLWithString:@"http://www.momsens.se/lathund-for-bokforing"]];
}

-(IBAction)SearchButtonClick:(id)sender{
    [MomsensSearchField resignFirstResponder];
    
    NSString *Inmatning = NSLocalizedString(MomsensSearchField.text, nil);
    
    
    NSString *StringMedPlus = [Inmatning stringByReplacingOccurrencesOfString:@" " withString:@"+"];
    
    SearchPhrase.text = StringMedPlus;
   
    /*
    [[UIApplication sharedApplication] openURL:[NSURL URLWithString: [NSString stringWithFormat:@"http://www.google.se/cse?cx=partner-pub-9135043205349318:2159573588&ie=UTF-8&q=%@", StringMedPlus]] ];
    */
    
    NSString *UTF8FormateradURL = [NSString stringWithFormat:
                           @"http://www.google.se/cse?cx=partner-pub-9135043205349318:2159573588&ie=UTF-8&q=%@",
                           [StringMedPlus stringByAddingPercentEscapesUsingEncoding:NSUTF8StringEncoding]];
    NSURL *FullstandigURL = [NSURL URLWithString:UTF8FormateradURL];
    [[UIApplication sharedApplication] openURL:FullstandigURL];
    
    /*
    NSString *finalString = [NSString stringWithFormat:@"http://www.google.com/search?q=%@",StringMedPlus];
    
    [[UIApplication sharedApplication] openURL:[NSURL URLWithString:finalString]];
    */

}




- (void)viewDidLoad {
    [super viewDidLoad];
    // Do any additional setup after loading the view, typically from a nib.
}

- (void)didReceiveMemoryWarning {
    [super didReceiveMemoryWarning];
    // Dispose of any resources that can be recreated.
}

@end
