
/*
 * Added scripts to help with region selection
 */
    // if Cookie is set automagically redirect to regional site    
    var cultureCode = get_cookie ("DPSSGDCultureCode");
    if(cultureCode != null && getQueryVariable("ChangeRegion") != "true") 
    {
        window.location = cultureCode + "/";
    }
    
    // sets cookie and redirect to appropiate region
    function goToSelectedCountry(CultureCode)
    {
        var cookie_date = new Date();
        set_cookie("DPSSGDCultureCode",CultureCode,cookie_date.getFullYear()+1,cookie_date.getMonth(),cookie_date.getDate(),"/");
        window.location=CultureCode + "/";
    }

    // set the cookie used by MCMS
    function set_cookie ( name, value, exp_y, exp_m, exp_d, path, domain, secure )
    {
      var cookie_string = name + "=" + escape ( value );
      if ( exp_y )
      {
        var expires = new Date ( exp_y, exp_m, exp_d );
        cookie_string += "; expires=" + expires.toGMTString();
      }
      if ( path ) cookie_string += "; path=" + escape ( path );
      if ( domain ) cookie_string += "; domain=" + escape ( domain );
      if ( secure ) cookie_string += "; secure";
      document.cookie = cookie_string;
    }
    
    // gets cookie by name
    function get_cookie (cookie_name)
    {
      var results = document.cookie.match ( cookie_name + '=(.*?)(;|$)' );

      if ( results )
        return ( unescape ( results[1] ) );
      else
        return null;
    }
    
    // gets query string variable
    function getQueryVariable(variable) {
        var query = window.location.search.substring(1);
        var vars = query.split("&");
        for (var i=0;i<vars.length;i++) {
            var pair = vars[i].split("=");
            if (pair[0] == variable) {
                return pair[1];
            }
        } 
    }