// Check for Mac IE browser
checkForMacIE();

function checkForMacIE() {
	if ((navigator.userAgent.indexOf('MSIE') != -1)
  		&& (navigator.userAgent.indexOf('Mac') != -1)
  		&& (location.href.indexOf('MacIE') == -1))
  	{
  		window.location.replace('/MacIE');
  	}
}

function goToJumpPage(country) {
  location.href=country.value;
}

function findKeyValue(key, list) {
	var tranArr = list.split(',');
	var i=0;
	for (i=0; i<tranArr.length; i++)
	{
		var tempArr = tranArr[i].split('=');
		if (tempArr[0] == key)
		{
			return tempArr[1];
		}
	}
	return '';
}

function externalSite(site, path) {
  var host = "";
  if (site == 'shure.com' && window.location.hostname.indexOf('vmldev') > -1) {
    host = 'http://shure.com.vmldev.com';
  } else if (site == 'shure.cn' && window.location.hostname.indexOf('vmldev') > -1) {
    host = 'http://shure.cn.vmldev.com';
  } else if (site == 'shure.co.uk' && window.location.hostname.indexOf('vmldev') > -1) {
    host = 'http://shure.co.uk.vmldev.com';
  } else if (site == 'shure.de' && window.location.hostname.indexOf('vmldev') > -1) {
    host = 'http://shure.de.vmldev.com';
  } else if (site == 'shure.com.hk' && window.location.hostname.indexOf('vmldev') > -1) {
    host = 'http://shure.com.hk.vmldev.com';
  } else if (site == 'es.shure.com' && window.location.hostname.indexOf('vmldev') > -1) {
    host = 'http://es.shure.com.vmldev.com';
  } else if (site == 'needlz.com' && window.location.hostname.indexOf('vmldev') > -1) {
    host = 'http://needlz.com.vmldev.com';
  } else if (site == 'shure.com' && window.location.hostname.indexOf('vmlstage') > -1) {
    host = 'http://shure.com.vmlstage.com';
  } else if (site == 'shure.cn' && window.location.hostname.indexOf('vmlstage') > -1) {
    host = 'http://shure.cn.vmlstage.com';
  } else if (site == 'shure.co.uk' && window.location.hostname.indexOf('vmlstage') > -1) {
    host = 'http://shure.co.uk.vmlstage.com';
  } else if (site == 'shure.de' && window.location.hostname.indexOf('vmlstage') > -1) {
    host = 'http://shure.de.vmlstage.com';
  } else if (site == 'shure.com.hk' && window.location.hostname.indexOf('vmlstage') > -1) {
    host = 'http://shure.com.hk.vmlstage.com';
  } else if (site == 'es.shure.com' && window.location.hostname.indexOf('vmlstage') > -1) {
    host = 'http://es.shure.com.vmlstage.com';
  } else if (site == 'needlz.com' && window.location.hostname.indexOf('vmlstage') > -1) {
    host = 'http://needlz.com.vmlstage.com';
  } else if (site == 'shure.com' && window.location.hostname.indexOf('dev.shure.com') > -1) {
    host = 'http://us-dev.shure.com';
  } else if (site == 'shure.cn' && window.location.hostname.indexOf('dev.shure.com') > -1) {
    host = 'http://cn-dev.shure.com';
  } else if (site == 'shure.co.uk' && window.location.hostname.indexOf('dev.shure.com') > -1) {
    host = 'http://uk-dev.shure.com';
  } else if (site == 'shure.de' && window.location.hostname.indexOf('dev.shure.com') > -1) {
    host = 'http://de-dev.shure.com';
  } else if (site == 'shure.com.hk' && window.location.hostname.indexOf('dev.shure.com') > -1) {
    host = 'http://hk-dev.shure.com';
  } else if (site == 'es.shure.com' && window.location.hostname.indexOf('dev.shure.com') > -1) {
    host = 'http://esus-dev.shure.com';
  } else if (site == 'needlz.com' && window.location.hostname.indexOf('dev.shure.com') > -1) {
    host = 'http://needlz-dev.shure.com';
  } else if (site == 'shure.com' && window.location.hostname.indexOf('stg.shure.com') > -1) {
    host = 'http://us-stg.shure.com';
  } else if (site == 'shure.cn' && window.location.hostname.indexOf('stg.shure.com') > -1) {
    host = 'http://cn-stg.shure.com';
  } else if (site == 'shure.co.uk' && window.location.hostname.indexOf('stg.shure.com') > -1) {
    host = 'http://uk-stg.shure.com';
  } else if (site == 'shure.de' && window.location.hostname.indexOf('stg.shure.com') > -1) {
    host = 'http://de-stg.shure.com';
  } else if (site == 'shure.com.hk' && window.location.hostname.indexOf('stg.shure.com') > -1) {
    host = 'http://hk-stg.shure.com';
  } else if (site == 'es.shure.com' && window.location.hostname.indexOf('stg.shure.com') > -1) {
    host = 'http://esus-stg.shure.com';
  } else if (site == 'needlz.com' && window.location.hostname.indexOf('stg.shure.com') > -1) {
    host = 'http://needlz-stg.shure.com';
  } else if (site == 'shure.com' && window.location.hostname.indexOf('prd.shure.com') > -1) {
    host = 'http://us-prd.shure.com';
  } else if (site == 'shure.com' && window.location.hostname.indexOf('prd.shure.com') > -1) {
    host = 'http://us-prd2.shure.com';  
  } else if (site == 'shure.cn' && window.location.hostname.indexOf('prd2.shure.com') > -1) {
    host = 'http://cn-prd.shure.com';
  } else if (site == 'shure.co.uk' && window.location.hostname.indexOf('prd.shure.com') > -1) {
    host = 'http://uk-prd.shure.com';
  } else if (site == 'shure.de' && window.location.hostname.indexOf('prd.shure.com') > -1) {
    host = 'http://de-prd.shure.com';
  } else if (site == 'shure.com.hk' && window.location.hostname.indexOf('prd.shure.com') > -1) {
    host = 'http://hk-prd.shure.com';
  } else if (site == 'es.shure.com' && window.location.hostname.indexOf('prd.shure.com') > -1) {
    host = 'http://esus-prd.shure.com';
  } else if (site == 'needlz.com' && window.location.hostname.indexOf('prd.shure.com') > -1) {
    host = 'http://needlz-prd.shure.com';
  } else if (site == 'shure.com') {
    host = 'http://www.shure.com';
  } else if (site == 'shure.cn') {
    host = 'http://www.shure.com.cn';
  } else if (site == 'shure.co.uk') {
    host = 'http://www.shure.co.uk';
  } else if (site == 'shure.de') {
    host = 'http://www.shure.de';
  } else if (site == 'shure.com.hk') {
    host = 'http://www.shure.com.hk';
  } else if (site == 'es.shure.com') {
    host = 'http://es.shure.com';
  } else if (site == 'needlz.com') {
    host = 'http://www.needlz.com';
  }

  window.location.href = host + path;
}

function SoundLab(page, name, w, h, scroll)
{
    var wl = (screen.width - w) / 2;
    var wt = (screen.height - h) / 2;
    props = 'height='+h+',width='+w+',top='+wt+',left='+wl+',scrollbars='+scroll+',resizable';
    win = window.open(page, name, props);
    if (parseInt(navigator.appVersion) >= 4)
    {
        win.window.focus();
    }
}

function setActiveStyleSheet(title) {
    var i, a, main;
    for(i=0; (a = document.getElementsByTagName("link")[i]); i++) {
        if(a.getAttribute("rel").indexOf("style") != -1
            && a.getAttribute("title")) {
        a.disabled = true;
        if(a.getAttribute("title") == title) a.disabled = false;
        }
    }
}

function printPage(originalStyle)
{   
    // Swap stylesheets
    setActiveStyleSheet('print');
    
    // Print the window
    window.print();
    
    // Swap stylesheets
    setActiveStyleSheet(originalStyle);
}

// This is to disable the print style since it's on every page.  It only
// needs to be used when the user clicks the print button.
if (document.getElementById('print_style')) {
	document.getElementById('print_style').disabled=true;
}

// These functions are to be used for links to the ISA applications.
// Form submits to ISA are handled withing the layout pages and fragments
// that add items to the cart.
// The idea is that templates or fragments that need a URL for ISA will call
// the appropriate isaXXX() functions below to go to the appropriate ISA page.
// The exception to the rule is for the OCI form submit where the template or
// fragment should call the isaAddToCart() function to get the url then call
// createCookie() when the form is actually submitted.

function createCookie(name,value,days) {
    if (days) {
        var date = new Date();
        date.setTime(date.getTime()+(days*24*60*60*1000));
        var expires = "; expires="+date.toGMTString();
    } else {
        var expires = "";
    }
    document.cookie = name+"="+value+expires+"; path=/";
}

function removeCookie(name) {
	createCookie(name, 'false', -5);
}
	
function readCookie(name) {
    var nameEQ = name + "=";
    var ca = document.cookie.split(';');
    for(var i=0;i < ca.length;i++) {
        var c = ca[i];
        while (c.charAt(0)==' ') c = c.substring(1,c.length);
        if (c.indexOf(nameEQ) == 0) return c.substring(nameEQ.length,c.length);
    }
    return null;
}

function getIsaPrefix() {
  var prefix = "";
  if (window.location.hostname.indexOf('vmldev') > -1) {
    prefix = 'http://us-stg.shure.com/PersonalAudio/Products/ScheduledMaintenance/index.htm';
  } else if (window.location.hostname.indexOf('vmlstage') > -1) {
    prefix = 'http://us-stg.shure.com/PersonalAudio/Products/ScheduledMaintenance/index.htm';
  } else if (window.location.hostname.indexOf('dev.shure.com') > -1) {
    prefix = 'http://us-dev.shure.com/PersonalAudio/Products/ScheduledMaintenance/index.htm';
  } else if (window.location.hostname.indexOf('stg.shure.com') > -1) {
    prefix = 'http://us-stg.shure.com/PersonalAudio/Products/ScheduledMaintenance/index.htm';
  } else if (window.location.hostname.indexOf('prd.shure.com') > -1) {
    prefix = 'http://www.shure.com/PersonalAudio/Products/ScheduledMaintenance/index.htm';
  } else if (window.location.hostname == 'www.shure.com' || window.location.hostname == 'shure.com') {
    prefix = 'http://www.shure.com/PersonalAudio/Products/ScheduledMaintenance/index.htm';
  }
  return prefix;
}

function isaMyAccount() {
    if (readCookie('session')=='true') {
        window.location = getIsaPrefix() + "#";
    } else {
        createCookie('session', 'true');
        window.location = getIsaPrefix() + "#";
    }
}

function isaShoppingCart() {
    if (readCookie('session')=='true') {
        window.location = getIsaPrefix() + "#";
    } else {
        createCookie('session', 'true');
        window.location = getIsaPrefix() + "#";
    }
}

function isaMyOrders() {
    if (readCookie('session')=='true') {
        window.location = getIsaPrefix() + "#";
    } else {
        createCookie('session', 'true');
        window.location = getIsaPrefix() + "#";
    }
}

function isaAddToCart() {
    if (readCookie('session')=='true') {
        return getIsaPrefix() + "#";
    } else {
        return getIsaPrefix() + "#";
    }
}

