﻿function checkUserAgent() {
    var ua = navigator.userAgent;
    var checker = {
        iphone: ua.match(/(iPhone|iPod|iPad)/),
        //blackberry: ua.match(/BlackBerry/),
        android: ua.match(/Android/)
    };

    /*
    if (checker.android) {
        var answer = confirm("There is an Android app available for this website. Do you wish to download it now?");
        if (answer) {
            window.location = "market://search?q=pname:smartsalary";
        }
    }
    else 
    */
    if (checker.iphone) {
        var answer = confirm("There is an iphone app available for this website. Do you wish to download it now?");
        if (answer) {
            window.location = "http://itunes.com/apps/smartsalary";
        }
    }
}

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 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 checkCookie() {
    var URL = window.location.pathname;
    var PageName = URL.substring(URL.lastIndexOf('/') + 1);

    if (PageName == "" || PageName.toLowerCase() == "default.aspx") {
        //var mycookie = getCookie("useragent_detector");
        //if (mycookie == null) {
        checkUserAgent();
        //    setCookie("useragent_detector", "1", 30);
        //}  
    }  
}
