function trackGaEvent(category,action,label,value)
{
	// Google Analytics Event Tracker
	if (typeof _gaq != 'undefined' && typeof _gaq.push != 'undefined')
	{
		_gaq.push(['_trackEvent', category, action, label, value]);
	}
}

/**
 * Sets a Cookie with the given name and value.
 *
 * name       Name of the cookie
 * value      Value of the cookie
 * [expires]  Expiration date of the cookie (default: end of current session)
 * [path]     Path where the cookie is valid (default: path of calling document)
 * [domain]   Domain where the cookie is valid
 *              (default: domain of calling document)
 * [secure]   Boolean value indicating if the cookie transmission requires a
 *              secure transmission
 */
function setCookie(name, value, expires, path, domain, secure) 
{
    document.cookie= name + "=" + escape(value) +
        ((expires) ? "; expires=" + expires.toGMTString() : "") +
        ((path) ? "; path=" + path : "") +
        ((domain) ? "; domain=" + domain : "") +
        ((secure) ? "; secure" : "");

}

/**
 * Gets the value of the specified cookie.
 *
 * name  Name of the desired cookie.
 *
 * Returns a string containing value of specified cookie,
 *   or null if cookie does not exist.
 */
function getCookie(name) 
{
    var dc = document.cookie;
    var prefix = name + "=";
    var begin = dc.indexOf("; " + prefix);
    if (begin == -1) 
    {
        begin = dc.indexOf(prefix);
        if (begin != 0) return null;
    } 
    else 
    {
        begin += 2;
    }
    var end = document.cookie.indexOf(";", begin);
    if (end == -1) 
    {
        end = dc.length;
    }
    return unescape(dc.substring(begin + prefix.length, end));
}

/**
 * Deletes the specified cookie.
 *
 * name      name of the cookie
 * [path]    path of the cookie (must be same as path used to create cookie)
 * [domain]  domain of the cookie (must be same as domain used to create cookie)
 */
function deleteCookie(name, path, domain) 
{
    if (getCookie(name)) 
    {
        document.cookie = name + "=" +
            ((path) ? "; path=" + path : "") +
            ((domain) ? "; domain=" + domain : "") +
            "; expires=Thu, 01-Jan-70 00:00:01 GMT";
    }
}

/**
 * Loads contact page in a new window or tab
 * Used on the shipping rates error message
 */
function contactusPopup()
{
	window.open(STORE_URL + 'contacts');
	return false;
}

/**
 * Pops open a live chat window
 * Used on the shipping rates error message
 */
function livechatPopup()
{
	//lpButtonCTTUrl = 'https://server.iad.liveperson.net/hc/36810496/?cmd=file&amp;file=visitorWantsToChat&amp;site=36810496&amp;referrer='+escape(document.location); 
	//lpButtonCTTUrl = (typeof(lpAppendVisitorCookies) != 'undefined' ? lpAppendVisitorCookies(lpButtonCTTUrl) : lpButtonCTTUrl); 
	//window.open(lpButtonCTTUrl,'chat36810496','width=475,height=400,resizable=yes');
	window.open('https://chat.livechatinc.net/licence/1053233/open_chat.cgi?lang=en&amp;groups=0&amp;dc='+escape(document.cookie+';l='+document.location+';r='+document.referer+';s='+typeof lc_session),'Chat_1053233','width=530,height=520,resizable=yes,scrollbars=no');
        return false;
}

/**
 * Reloads shipping methods step on checkout page or the shipping estimator on the cart page
 * Used on the shipping rates error message
 */
function reloadShippingRates()
{
	if (window.location.href.indexOf('checkout/cart') != -1)
	{
		window.location.reload();
		return false;
	}
	else if (window.location.href.indexOf('checkout/onepage') != -1)
	{
		shipping.save();
		var oldStr = document.getElementById('shipping-method-please-wait').innerHTML;
		document.getElementById('shipping-method-please-wait').innerHTML = oldStr.replace('Loading next step', 'Loading');
		checkout.setLoadWaiting('shipping-method');
		return false;
	}
}


/**
 * URL Changer for POV, POVCA, POVUK
 * @param from can be an array or string
 *
 * If "to" is an array, then "from" must also be an array with the same number of parmeters as from
 * Sample Usage:
 * switchPovStore('pointofviewcameras.ca/','pointofviewcameras.co.uk/');
 * switchPovStore(new Array('pointofviewcameras.ca/','pointofviewcameras.com/'),'pointofviewcameras.co.uk/');
 * switchPovStore(new Array('pointofviewcameras.ca/','/blog/povca/'),new Array('pointofviewcameras.co.uk/','/blog/povuk/'));
 */
function switchPovStore(from, to)
{
	// Check Data
	if (to instanceof Array)
	{
		// to is an array
		// check if from is also and array with same length
		if (!(from instanceof Array))
		{
			return false;
		}
		
		if (from.length != to.length)
		{
			return false;
		}
	}
	
	var redirLocation = window.location.href;
	
	if (from instanceof Array)
	{
		if (to instanceof Array)
		{
			for (var i=0; i < from.length; ++i)
			{
				redirLocation = redirLocation.replace(from[i], to[i]);
			}
		}
		else
		{
			for (var i=0; i < from.length; ++i)
			{
				redirLocation = redirLocation.replace(from[i], to);
			}
		}
	}
	else
	{
		redirLocation = redirLocation.replace(from, to);
	}
	
	window.location.href = redirLocation;
}


/**
 * URL Changer for SAD, SADCA
 * @param from can be an array or string
 * If "to" is an array, then "from" must also be an array with the same number of parmeters as from
 */
function switchSadStore(from, to)
{
	switchPovStore(from, to);
}


/**
 * Show UK store switcher popup as a lightbox
 * This is shown to EU visitors on POV and POVCA
 */
function showUKSwitcher()
{
	try
	{
		if (typeof continent_code == 'undefined')
		{
			return;
		}

		if (continent_code != 'EU')
		{
			return;
		}

		if (!getCookie('has_seen_uk_switcher'))
		{
			var element = document.createElement('a');
			element.setAttribute('href', '/povuk-popup.html');
			element.setAttribute('modal', 'height=150;width=460');
			element.setAttribute('title', '');
			element.setAttribute('rel', 'lightbox');
			myLightbox.start(element);
			setCookie('has_seen_uk_switcher',1,null,'/');
		}
	}
	catch (e)
	{
	}
}







