
function doActivateJSOnly() {
	document.getElementById('cart_widget_cart').style.cursor = 'pointer';
	document.getElementById('cart_widget_wishlist').style.cursor = 'pointer';
	document.getElementById('cart_widget_compare').style.cursor = 'pointer';
}

standardTagOverlayWidth = 500; //Pixels
wideTagOverlayWidth = 700;

function doHeaderWidthStaging() { 	var thisWidth = document.body.clientWidth;
	//alert(thisWidth);
	if (thisWidth >= 950) {
		var domIDHeadOptFirstStyleDisplay = 'block';
	} else {
		var domIDHeadOptFirstStyleDisplay = 'none';
	}
	//document.getElementById('head_opt_first').style.display = domIDHeadOptFirstStyleDisplay;
	return false;
}

arrImageReplace = new Array();
function imageReplace(domID, newImage) {
	arrImageReplace[domID] = document.getElementById(domID).src;
	document.getElementById(domID).src = newImage;
	return true;
}
function imageRestore(domID) {
	document.getElementById(domID).src = arrImageReplace[domID];
	return true;
}
function getCurrentTime() {
	var currentTimestamp = new Date();
	var currentTime = currentTimestamp.getTime();
	return currentTime;
}
function falseReturn() {
     return false;
}
function doLoadUploadImageApplet(description) {
  if (typeof description !== 'undefined') {
    var descriptionHTMLThrow = 'description='+escape(description);
  } else {
    var descriptionHTMLThrow = '';
  }
	window.open ('http://www.helmetheadcycle.com/public_image_uploader?'+descriptionHTMLThrow, 'Uploader', 'height=380, width=450, resizable=1, scrollbars=1');
	return true;
}
//candidPhotoKey = 1;
function doRenderSmallCandidPhotos(returnNumber, returnStart) {
	$('#small_candid_photos_content').load('http://www.helmetheadcycle.com/js_resources/ajax_small_candid_photos.php?return_number='+returnNumber+'&return_start='+returnStart);
	return true;
}

function doDisplayLargeRandomPhoto() {
	if (typeof(tRandLargeRandPhoto) != 'undefined') {
		clearInterval(tRandLargeRandPhoto);
	}
	$.getJSON('http://www.helmetheadcycle.com/js_resources/ajax_candid_photo_random_large.php?time='+getCurrentTime(), function(data) {
		if (data.result == 'success') {
			document.getElementById('large_rand_photo_container').style.width = data.width;
			document.getElementById('large_rand_photo_container').style.height = data.height;
			document.getElementById('large_rand_photo_container').innerHTML = '<img src="'+data.filepath+'" />';
			document.getElementById('large_rand_photo_container').style.left = ((document.body.clientWidth)-data.width)+'px';
			$('#large_rand_photo_container').fadeIn('slow');
			tRandLargeRandPhoto = setInterval('$(\'#large_rand_photo_container\').fadeOut(\'slow\', function(){doDisplayLargeRandomPhoto()})', 8000);
		}
	});
}
boolLargePhotoContainerDisplayed = false;
function doRenderTopLargeCandidPhotoContainer(largePhotoFilepath, largePhotoHeight) {
	doHideBrandsOverlay();
	document.getElementById('candid_photo_enlarge_container').style.height = (largePhotoHeight+25)+'px';
	$('#candid_photo_enlarge_container').slideDown('slow');
	var thisContainerFill = '<div style="text-align: center">';
	thisContainerFill = '    [<a href="#" onclick="doHideTopLargeCandidPhotoContainer(); return falseReturn();">Close Zoomed Image</a>]';
	thisContainerFill += '</div><br />';
	thisContainerFill += '<img src="'+largePhotoFilepath+'" /><br />';
	thisContainerFill += '<span id="candid_photo_cc" style="display: none"></span>';
	document.getElementById('candid_photo_enlarge_container').innerHTML = thisContainerFill;
	window.location = ('#candid_photo');
	$('#candid_photo_cc').load('http://www.helmetheadcycle.com/js_resources/ajax_candid_photo_counter.php?filepath='+largePhotoFilepath+'&time='+getCurrentTime());
	//$('#ajax_free_t-shirt_offer_container').load('http://www.helmetheadcycle.com/free-t-shirt-offer.php?ajax_include=1');
	boolLargePhotoContainerDisplayed = true;
	return true;
}
function doHideTopLargeCandidPhotoContainer() {
	if (boolLargePhotoContainerDisplayed === true) {
		$('#candid_photo_enlarge_container').slideUp('fast');
		boolLargePhotoContainerDisplayed = false;
		return true;
	} else {
		return false;
	}
}
boolBrandsOverlayDisplayed = false;
function doRenderBrandsOverlay() {
	if (doHideTopLargeCandidPhotoContainer()) {
		window.location = '#top';
	}
	document.getElementById('four_fifty_width_drawn_overlay_container').style.display = 'block';
	document.getElementById('four_fifty_width_draw_overlay_close_wrapper').innerHTML = '[<a href="#" onclick="doHideBrandsOverlay(); return falseReturn()">Close</a>]';
	document.getElementById('four_fifty_width_draw_overlay_title').innerHTML = 'HelmetHead Cycle&trade; Brands';
	document.getElementById('four_fifty_width_draw_overlay_content').innerHTML = '<span style="color: #ff0000">loading...</span>';
	$('#four_fifty_width_draw_overlay_content').load('http://www.helmetheadcycle.com/brands.php?ajax_mode=1&time='+getCurrentTime());
	boolBrandsOverlayDisplayed = true;
	return true;
}
function doHideBrandsOverlay() {
	if (boolBrandsOverlayDisplayed === true) {
		$('#four_fifty_width_drawn_overlay_container').fadeOut('slow');
		boolBrandsOverlayDisplayed = false;
		return true;
	} else {
		return false;
	}
}
function doChangeOpacity(domID, opacityPercentage) {
	document.getElementById(domID).style.opacity = opacityPercentage/100;
	document.getElementById(domID).style.filter = 'alpha(opacity='+opacityPercentage+')';
}
function doRenderProdMetaContainers(renderStart, renderEnd, explicitDivIDPre) {
	for (i = renderStart-1; i < renderEnd; i++) {
		if (typeof explicitDivIDPre == 'undefined') {
			document.getElementById('prod_meta_container_'+i).style.display = 'block';
		} else {
			document.getElementById(explicitDivIDPre+'_'+i).style.display = 'block';
		}
	}
	return true;
}
arrStarContainer = new Array();
function doStarControl(domID, mode, mainProdID, boolRedirectToProductPage) {
	if (typeof boolRedirectToProductPage == 'undefined') {
		var boolRedirectToProductPage = true;
	}
	var domIDSplit = domID.split('_', 5);
	var domStarContainerNumber = domIDSplit[2];
	var thisStarNumber = domIDSplit[4];
	if (mode == 'hover') {
		for (i = 1; i <= 5; i++) {
			arrStarContainer['prod_meta_'+domStarContainerNumber+'_star_'+i] = document.getElementById('prod_meta_'+domStarContainerNumber+'_star_'+i).src;
			if (thisStarNumber >= i) {
				document.getElementById('prod_meta_'+domStarContainerNumber+'_star_'+i).src = 'http://www.helmetheadcycle.com/image.php?img=theme/star_yellow.gif';
			} else {
				document.getElementById('prod_meta_'+domStarContainerNumber+'_star_'+i).src = 'http://www.helmetheadcycle.com/image.php?img=theme/star_red.gif';
			}
		}
		return true;
	} else if (mode == 'inactive') {
		for (i = 1; i <=5; i++) {
			document.getElementById('prod_meta_'+domStarContainerNumber+'_star_'+i).src = arrStarContainer['prod_meta_'+domStarContainerNumber+'_star_'+i];
		}
		return true;
	} else if (mode == 'click') {
		$.getJSON('http://www.helmetheadcycle.com/js_resources/ajax_star_modifier.php?star_number='+thisStarNumber+'&main_prod_id='+mainProdID, function(data) {
			if (data.result == 'success') {
				if (confirm('Thanks for rating! Would you like to add a review?'+(data.signed_in === false ? '\n\nYou will be prompted to first sign in or create an account.' : ''))) {
					if (data.signed_in === false) {
						window.location = 'https://www.helmetheadcycle.com/accounts.php?active_loc_ref_type=secure';
					} else if (boolRedirectToProductPage === true) {
						window.location = 'http://www.helmetheadcycle.com/product-id-'+mainProdID+'.html#comments';
					} else {
						window.location = '#comments';
					}
				}
				for (i = 1; i <= 5; i++) {
					arrStarContainer['prod_meta_'+domStarContainerNumber+'_star_'+i] = document.getElementById('prod_meta_'+domStarContainerNumber+'_star_'+i).src;
					if (data.averageLevel >= i) {
						document.getElementById('prod_meta_'+domStarContainerNumber+'_star_'+i).src = 'http://www.helmetheadcycle.com/image.php?img=theme/star_yellow.gif';
					} else {
						document.getElementById('prod_meta_'+domStarContainerNumber+'_star_'+i).src = 'http://www.helmetheadcycle.com/image.php?img=theme/star_red.gif';
					}
				}
				return true;
			} else {
				alert ('Could not rate this product at this time.');
				return false;
			}
		});
	}
}
function doModifyCart(mode, prodID, boolAdd, boolConvertToMainCart) {
	$.getJSON('http://www.helmetheadcycle.com/js_resources/ajax_cart.php?mode='+mode+'&prod_id='+prodID+'&add_or_remove_state='+(boolAdd === true ? 'add' : 'remove')+'&convert_to_main_cart='+(boolConvertToMainCart === true ? 'true' : 'false')+'&caller_uri='+window.location+'&time='+getCurrentTime(), function(data) {
		if (data.result == 'fail') {
			alert('Could not successfully store your '+mode+' modification at this time. Please try again later.');
			return false; 		} else {
			document.getElementById('header_'+mode+'_item_count').innerHTML = data.updatedItemCount;
			document.getElementById('cart_widget_'+mode+'_item_string').innerHTML = data.updatedItemCount+' item'+(data.updatedItemCount !== 1 ? 's' : '');
			if (mode == 'cart') {
				document.getElementById('header_'+mode+'_formatted_subtotal').innerHTML = data.updatedFormattedSubtotal;
				document.getElementById('cart_widget_'+mode+'_formatted_subtotal').innerHTML = data.updatedFormattedSubtotal;
			}
			if (mode == 'wishlist' && boolAdd === true && data.userIsLoggedIn === false && data.userSessionWishlistCountAdd == 1) {
				if (confirm('Your wishlist can only be saved if you have a user account.\n\nDo you wish to log in or create an account now?')) {
					window.location = 'https://www.helmetheadcycle.com/accounts.php?active_loc_ref_type='+(data.boolSecuredPage === true ? 'secured' : 'normal');
				}
				return true;
			}
			if (boolConvertToMainCart === true) {
				if (confirm('Do you wish to proceed to checkout?')) {
					window.location = 'https://www.helmetheadcycle.com/checkout.html';
				}
				return true;			
			}
		}
	});
	return true;
}

function doGetCart(mode) {
	return doModifyCart(mode, 1, false, false);
}
function doRenderProductZoom(prodID, posImage) {
	if (typeof posImage == 'undefined') {
		posImage = 0;
	}
	$('#product_image_zoom_container').load('http://www.helmetheadcycle.com/product.php?ajax_mode=image_zoom&product_id='+prodID+'&pos_image='+posImage+'&time='+getCurrentTime());
	window.location = '#product_zoom';
	doSlideDown('product_image_zoom_container');
	return true;
}
function doCloseProductZoom() {
	doSlideUp('product_image_zoom_container');
	return true;
}
function doSlideDown(divID) {
	$('#'+divID).slideDown('slow');
	return true;
}
function doSlideUp(divID) {
	$('#'+divID).slideUp('slow');
	return true;
}