<!--

function getCooky(name) {

  var i, x, y, c = document.cookie.split(";");
  for (i = 0; i < c.length; i++) {
    x = c[i].substr(0, c[i].indexOf("="));
    y = c[i].substr(c[i].indexOf("=")+1);
    x = x.replace(/^\s+|\s+$/g,"");
//alert('cooky=' + c + ' ....cooky file')
    if (x == name) { return unescape(y); }
  }
}

function viewMobi() {

  var c = getCooky('device');
//alert('device=' + c + ' ....view mobi')
  if (c) { 
    document.cookie = "device=; path=/; expires=Thu, 01-Jan-70 00:00:01 GMT; domain=.headsetfactory.com";
  }  
  window.location.href = "http://www.headsetfactory.mobi";
}

function deviceTest() {

  var c = getCooky('device');
//alert('device=' + c + ' ....cookie test')
  if (c == 'mobi') { viewMobi(); }
  if (c == 'pc') { return; }
  
  var param = checkURL()
  if ( param == 'pc') { 
    //set cookie named device w/ value 'pc' duration 1 month
    var expires = new Date();
    expires.setTime(expires.getTime() + 1000 * 60 * 60 * 24 * 35); 
    document.cookie = "device=pc; expires=" + expires + "; path=/; domain=.headsetfactory.com";
//var c = getCooky('device');
//alert('cookie=' + c + ' ...cookie set')
	return;
  }
  
  var x = notDeviceDetect();
  if (x != 'pc') { 
    window.location.href = "http://www.headsetfactory.mobi/detect.html"; 
  }
}

function checkURL() {

  var paraName = 'item';
  paraName = paraName.replace(/[\[]/,"\\\[").replace(/[\]]/,"\\\]");
  var regexS = "[\\?&]" + paraName + "=([^&#]*)";
  var regex = new RegExp(regexS);
  var paraValue = regex.exec(window.location.href);
  if (paraValue == null) { return; }
  return paraValue[1];
}

function notDeviceDetect() {
    var ua = navigator.userAgent;
    var qs = window.location.search.substring(1);
    var agent = "error";
    var re = {
        "pcswitch" : /pc/i,
        "pomswitch" : /pom/i,
        "iphoneswitch" : /iphone/i,
        "iphone" : /iP(hone|od)(;|\s)/i,
//        "iphone" : /iP(hone|od|ad)(;|\s)/i,
        "android" : /Android/i,
        "opera1" : /Opera\s+Mobi/i,
        "winmo" : /Windows\s+CE/i,
        "winmo2" : /IEMobile/i,
        "linux" : /Linux/i,
        "windows" : /Windows/i,
        "mac" : /OS\s+(X|9)/i,
        "solaris" : /Solaris/i,
        "bsd" : /BSD/i
    };
    if (qs.match(re.pcswitch)) {
        /* This assumes you have a single query string value of "pc" */
        agent = "pc";
    } else if (qs.match(re.pomswitch)) {
        /* This assumes you have a single query string value of "pom" */
        agent = "pom";
    } else if (qs.match(re.iphoneswitch)) {
        /* This assumes you have a single query string value of "iphone" */
        agent = "iphone";
    } else if (ua.match(re.iphone)) {
        /* This user agent should be an iPhone/iPod */
        agent = "iphone";
    } else if (ua.match(re.android)) {
        /* This assumes you have a single query string value of "android" */
        agent = "android";
    } else if (ua.match(re.opera1)) {
        /* This user agent should be a Opera mini browser */
        agent = "opera";
    } else if (ua.match(re.winmo)) {
        /* This user agent should be a Windows Mobile device */
        agent = "pom";
    } else if (ua.match(re.winmo2)) {
        /* This user agent should be a Windows Mobile device */
        agent = "pom";
    } else if (
        (!ua.match(re.linux)) &&
        (!ua.match(re.windows)) &&
        (!ua.match(re.mac)) &&
        (!ua.match(re.solaris)) &&
        (!ua.match(re.bsd))
    ) {
        /* This user agent is not Linux, Windows, a Mac, Solaris or BSD */
        agent = "mobi";
    } else {
        /* Otherwise assume it's a PC */
        agent = "pc";
    }
//	alert(ua)
    return agent;
}

-->
