﻿/*
Geo redirector script v1.0
Author: James Wragg
Date: 06th October 2008
*/
var geoRedirector = function() {

    var debug = false;
    var countryCode = 'GB';
    var cookieName = 'geolocation';

    setGeoCookie = function(countryCode) {
        jQuery.cookie(cookieName, countryCode, { expires: 365, path: '/' });
    };
    
    getGeoCookie = function() {
        return jQuery.cookie(cookieName);
    };
    
    getGoogleAPILocation = function() {
        var tempCode = countryCode;
        if (google.loader.ClientLocation && google.loader.ClientLocation.address.country_code) 
            tempCode = google.loader.ClientLocation.address.country_code.toUpperCase();
 
        return tempCode;
    };
    
    
    return {
       init : function() {
       
            jQuery(document).ready(function() { 
                var dLocation = document.location.href;
                var cLocation = getGeoCookie();

                if(dLocation.toLowerCase().indexOf('sethome=') > -1 ){
                    countryCode = dLocation.toLowerCase().split('sethome=')[1].toUpperCase();
                    if( countryCode == 'GB' || countryCode == 'US')
                        setGeoCookie( countryCode );
                        
                }else if(cLocation != null){
                    countryCode = cLocation;        
                        
                }else{
                    countryCode = getGoogleAPILocation();
                    if( countryCode == 'GB' || countryCode == 'US')
                        setGeoCookie( countryCode );
                }
                
                if(countryCode == 'US'){
                    jQuery('a[href|=/cv-search-match/]').each(function() {
                        if(jQuery(this).text() == 'CV Search and Match'){
                            jQuery(this).text('Resume Search and match');
                            jQuery(this).attr('href', '/resume-search-match/')
                        }
                        
                        jQuery("#cv-product-block .link").attr('href', '../resume-search-match/')
                        jQuery("#cv-product-block .product-block-text").attr('src', '../images/txt-small-rvsm.gif')
                        jQuery("#cv-product-block .product-block-text").attr('alt', 'Resume Search and Match screenshot')
                        jQuery("#cv-product-block .product-block-text").attr('alt', 'Resume Search and Match screenshot')
                        jQuery("#cv-product-block p span").text('A next generation resume database with intelligent search technology matching recruiter needs with the most relevant candidates');
              
                    });
                }
            
      
            });
        }
    };
    
 } ();



geoRedirector.init();




