// found online
function gup(name)
{
    name = name.replace(/[\[]/,"\\\[").replace(/[\]]/,"\\\]");
    var regexS = "[\\?&]"+name+"=([^&#]*)";
    var regex = new RegExp( regexS );
    var results = regex.exec( window.location.href );
    if( results == null )
        return "";
    else
        return results[1];
}

function setCookie(c_name,value,exdays)
{
    var exdate=new Date();
    exdate.setDate(exdate.getDate() + exdays);
    var c_value=escape(value) + ((exdays==null) ? "" : "; expires="+exdate.toUTCString());
    document.cookie=c_name + "=" + c_value;
}

function getCookie(c_name)
{
    var i,x,y,ARRcookies=document.cookie.split(";");
    for (i=0;i<ARRcookies.length;i++)
    {
        x=ARRcookies[i].substr(0,ARRcookies[i].indexOf("="));
        y=ARRcookies[i].substr(ARRcookies[i].indexOf("=")+1);
        x=x.replace(/^\s+|\s+$/g,"");
        if (x==c_name)
        {
            return unescape(y);
        }
    }
}


function shukr_redirect(country) 
{
    if ( (document.location == 'http://shukronline.com') ||
         (document.location == 'http://shukronline.com/') ||
         (document.location == 'http://shukronline.com/index.html') ||
         (document.location == 'http://www.shukronline.com') ||
         (document.location == 'http://www.shukronline.com/') ||
         (document.location == 'http://www.shukronline.com/index.html') ) {
        // international page, so do nothing
    } else if (getCookie('sh_nrdr') == '1') {
        // do nothing
    } else if (gup('sh_nrdr') == '1') {
        setCookie('sh_nrdr', '1', null);
    } else {
        var cc = geoip_country_code();
        if ( (cc == country) || (cc == 'JO') || (cc == 'SY') ) {
            // stay put
        } else if (cc == 'US') {
            window.location = "http://www.shukronline.com/home.html";
        } else if (cc == 'CA') {
            window.location = "http://www.shukr.ca";
        } else if (cc == 'GB') {
            window.location = "http://www.shukr.co.uk";
        } else {
            window.location = "http://www.shukronline.com";
        }
    }
}


