// Popup Window (Centred)
function popup(url,winname,w,h,feat)
{
	if (!(isNaN(w) || isNaN(h)))
	{
		var x=parseInt((screen.width-w)/2);
		var y=parseInt((screen.height-h)/2);
		if (x<0)	x=0;
		if (y<0)	y=0;
		
		if (feat!=null && feat!="")
		{
			feat=","+feat;
		}
		else
		{
			feat="";
		}
		feat="left="+x+",top="+y+",width="+w+",height="+h+feat;
	}
	window.open(url,winname,feat);
}

function prodimgswp(dotdotpath, targetProd, oldID) {
	var imageClicked;
	var big_image;
	
	// GET CLICKED IMAGE DATA
	imageClicked = document.getElementById(oldID).src;
	var med_i = "";
	if (String(imageClicked).length < 5)
		med_i = imageClicked;
	else {
		var iLen = String(imageClicked).length;
		med_i = String(imageClicked).substring(iLen-5, iLen-4);
	}
	
	// GET LARGE IMAGE DATA
	big_image = document.getElementById("product_big").src;
	var big_i = "";
	if (String(big_image).length < 5)
		big_i = big_image;
	else {
		var iLen = String(big_image).length;
		big_i = String(big_image).substring(iLen-5, iLen-4);
	}
	
	// SHOW NEW IMAGE
	if (med_i == 3) {
		document.getElementById("product_big").src = dotdotpath + "_images/products/" + targetProd + "_" + document.cart_cTxt + "_big_0" + med_i + ".jpg";
	} else {
		document.getElementById("product_big").src = dotdotpath + "_images/products/" + targetProd + "_big_0" + med_i + ".jpg";
	}
	
	// MOVE OLD IMAGE
	if (big_i == 3) {
		document.getElementById(oldID).src = dotdotpath + "_images/products/" + targetProd + "_" + document.cart_cTxt + "_med_0" + big_i + ".jpg";
	} else {
		document.getElementById(oldID).src = dotdotpath + "_images/products/" + targetProd + "_med_0" + big_i + ".jpg";
	}
}

function imageSwap(dotdotpath, overOut, targetID, image) {
	var imageSuffix = "";
	if (overOut == "over") {
		imageSuffix = "_over";
	}
		
	document.getElementById(targetID).src = dotdotpath + "images/" + image + imageSuffix + ".jpg";
}

// CART FUNCTIONS
function cart_init(initColourInt) {
	document.cart_c = 1;
	document.cart_cTxt = 1;
	document.cart_s = 1;
	document.cart_q = 1;
}
function set_cart_colour(d, v, vTxt, pu, swatchOnly) {
	// UNHIGHLIGHT CURRENT COLOR
	document.getElementById("colorswatch_" + document.cart_c).className = "colorswatch";
	
	// HIGHLIGHT SELECTED COLOR
	document.getElementById("colorswatch_" + v).className = "colorswatchselected";
	
	// UPDATE FORM VALUE
	document.cart_c = v;
	document.cart_cTxt = vTxt;
	
	// UPDATE IMAGES IF REQUIRED
	if (swatchOnly == false) {
		// SWAP MAIN IMAGE
		document.getElementById("product_big").src = d + "_images/products/" + pu + "_" + vTxt + "_big_03.jpg";
		
		// RESET SMALLER 2 IMAGES
		document.getElementById("product_med_left").src = d + "_images/products/" + pu + "_med_02.jpg";
		document.getElementById("product_med_right").src = d + "_images/products/" + pu + "_med_01.jpg";
	}
}
function addtocart(d, p) {
	c = document.cart_c;
	s = document.getElementById("ProductSize").value;
	q = document.getElementById("ProductQuantity").value;
	l = document.getElementById("ProductLength").value;
	
	document.location = d + "store/basket/add/?p=" + p + "&c=" + c + "&s=" + s + "&l=" + l + "&q=" + q;
}
function updatecart(d, cp) {
	q = document.getElementById("ProductQuantity_" + cp).value;
	
	document.location = d + "store/basket/update/?cp=" + cp + "&q=" + q;
}
function removefromcart(d, cp) {
	document.location = d + "store/basket/remove/?cp=" + cp;
}
function relative_time(time_value) { var values = time_value.split(" "); time_value = values[1] + " " + values[2] + ", " + values[5] + " " + values[3]; var parsed_date = Date.parse(time_value); var relative_to = (arguments.length > 1) ? arguments[1] : new Date(); var delta = parseInt((relative_to.getTime() - parsed_date) / 1000); delta = delta + (relative_to.getTimezoneOffset() * 60);
if (delta < 60) { return 'less than a minute ago'; } else if(delta < 120) { return 'about a minute ago'; } else if(delta < (45*60)) { return (parseInt(delta / 60)).toString() + ' minutes ago'; } else if(delta < (90*60)) { return 'about an hour ago'; } else if(delta < (24*60*60)) { return 'about ' + (parseInt(delta / 3600)).toString() + ' hours ago'; } else if(delta < (48*60*60)) { return '1 day ago'; } else { return (parseInt(delta / 86400)).toString() + ' days ago'; } }