function setCookie( name, value, expires, path, domain, secure )
{
	if(typeof(expires)=="undefined"){
		expires=0;
	}
	
	domain = ".voltageconverters.com";
	var today = new Date();
	today.setTime( today.getTime() );
	
	if ( expires )
	{
		expires = expires * 1000 * 60 * 60 * 24;
	}
	var expires_date = new Date( today.getTime() + (expires) );
	
	document.cookie = name + "=" +escape( value ) +
	( ( expires ) ? ";expires=" + expires_date.toGMTString() : "" ) +
	( ( path ) ? ";path=" + path : "" ) +
	( ( domain ) ? ";domain=" + domain : "" ) +
	( ( secure ) ? ";secure" : "" );
}
	
	
	
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);
		}
	  }
	return "";
}
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 showShipCanadaButton(){
	$(".d_checkout").hide();
	$("#d_checkout_canada").show();
}
function showShipNormalButtons(){
	$(".d_checkout").show();
	$("#d_checkout_canada").hide();
}
function setShipCountry(c){
	setCookie('ckc',c);
	return true;
}
try{
	var env = gup("env");
	var userLang = gup("nav.lang");
	

	if(env=="dev"){
		setCookie("env",env);
	}else{
		env=getCookie("env");
	}
	env="prod";
	
	if(userLang!=""){
		setCookie("nav.lang",userLang);
	}else{
		userLang=getCookie("nav.lang");
	}
	if(env=="prod"){	
		var ckc=getCookie("ckc");		

		if(ckc=="ca"){
			location.href="http://www.voltageconverters.ca";
		}
		if(location.pathname.indexOf("splash_vc")==-1){
			if(userLang==""){
				userLang = (navigator.language) ? navigator.language : navigator.userLanguage;
			}
			if(ckc!="us" && userLang.indexOf("-ca")!=-1){
				location.href="http://www.voltageconverters.com/splash_vc.html";
			}
		}
		
		if(typeof($) != "undefined" && location.pathname.indexOf("viewcart")!=-1){
			$(function() {
				var country=$("#selshipdest").val();
				if(country==2){
					showShipCanadaButton();
				}
				$("#selshipdest").change(function(){
					var country=$("#selshipdest").val();
					if(country==2){
						showShipCanadaButton();
					}else{
						showShipNormalButtons();
					}
				});
			});
		}
	}
}catch(err){
	
}



