/* Function: renderProductDetails; */
function renderProductDetails(productID, categoryID, prevLocation){
	intWidth = 830;
	intHeight = 470;
	
	if(arguments.length > 4) {
		showPrice = arguments[4];
		showCartControls = arguments[3];
	} else if(arguments.length > 3) {
		showPrice = 1;
		showCartControls = arguments[3];
	} else {
		showPrice = 1;
		showCartControls = 1;
	}
	
	if( document.getElementById('box') == null ){
		return false;
	}
	else{
		Lightbox.showBoxByAJAX('/resource/chocolates/ajax/aj_productDetail.cfm?productID=' + productID + '&categoryID=' + categoryID + '&prevLocation=' + prevLocation + '&showCartControls=' + showCartControls + '&showPrice=' + showPrice, intWidth, intHeight);
	}
}

/* Function: updateLightBoxContent */
function updateLightBoxContent( productID, categoryID, prevLocation, showCartControls, showPrice ){
	/* get our variables to revinvoke our content */
	if( $('checkoutForm') ){
		/* Pull in our data from the current form object */
		href = '/resource/chocolates/ajax/aj_productDetail.cfm?productID='+ productID + '&categoryID=' + categoryID + '&prevLocation=' + prevLocation + '&showCartControls=' + showCartControls + '&showPrice=' + showPrice;
		var myAjax = new Ajax.Updater($('boxContents'), href, {method: 'get', evalScripts:true});
	}
	else{
		/* No dice */
		return true;
	}
	return false;
}

/* Function: renderGiftWrapChoice; */
function renderGiftWrapChoice(productID, giftWrapID){
	intWidth = 830;
	intHeight = 470;
	
	if( document.getElementById('box') == null ){
		return false;
	}
	else{
		Lightbox.showBoxByAJAX('/ajax/giftWrap.cfm?itemID=' + productID + '&giftWrapID=' + giftWrapID, intWidth, intHeight);
	}
}

/* Function: renderGiftWrapChoice; */
function renderChangeEmailForm(){
	intWidth = 570;
	intHeight = 250;
	
	if( document.getElementById('box') == null ){
		return false;
	}
	else{
		Lightbox.showBoxByAJAX('/resource/chocolates/ajax/aj_changeEmail.cfm', intWidth, intHeight);
	}
}

function changePrice(value){
	/* this function depends on the existance of a javascript array */
	try{
		/* we expect coldfusion to have formatted the string, rather than storing a numeric value its a string */
		$('priceArea').innerHTML = arrPrices[value];
	}
	catch (err){
		/* suppress error */
		alert(err);
	}
}

function hideShowShipping (object) {
	if( object.value == 'new' ){
		/* always hide help container */
		$('helpContent').hide();
		$('newShipToContainer').show();
		$('newShipTo').focus();
	}
	else{
		$('newShipToContainer').hide();
	}
}

function hideShowProductHelp(){
	$('helpContent').toggle();
}

function renderGiftCertificate(code, url){
	intWidth = 492;
	intHeight = 382;
	if( document.getElementById('box') == null ){
		return false;
	}
	else{
		/* determine if we should show a real or an "in-process" */
		url = '/resource/chocolates/ajax/aj_giftCertificate.cfm'+(( url.length == 0 || url == null ) ? '?gct_id='+code : url);
		Lightbox.showBoxByAJAX(url, intWidth, intHeight);
	}
}

/*******************	MAO 07.17.08; Created function for image transitions and other useful product logic	***********/
function switchImage(imageID,imageName,rowID,inStock) {
	/* divID = ID of element to have new image content, colorCode = guid of new image id */
	var srcImageID	= 'image_'+rowID;
	var imageID		= 'mainImage';
	var divID		= 'imagediv';
	var largeLocation	=	'/resource/images/products/large/';
	imageName	=	escape(imageName);	/* Encode the string using url syntax */
	/* first check to make sure we aren't already showing the current image */
	var currentImage	=	$(imageID).src;
	if( currentImage.substr(currentImage.length-imageName.length,imageName.length) == imageName ){
		return false;
	}
	
	/* update our primary image */
	$(imageID).src	=	largeLocation+imageName;
	$(imageID).alt	=	$(srcImageID).alt;
	$(imageID).title=	$(srcImageID).title;
	
	if( inStock == false ){
		/* if we are on quickview we will use our stored image information to update our description */
		try{
			$('imageDescription').innerHTML	=	arrImageD[rowID];
		}
		catch(err){
			/* supress error if we are on womens/mens instead of instock */
		}
	}
	/* after image switch drop our class to create the red border */
	for( i=1; i <= 5; i++ ){
		try{
			if( i == rowID ){
				$('image_'+i).addClassName('activeImage');
			}
			else{
				$('image_'+i).removeClassName('activeImage');
			}
		}
		catch(err){
			/* supress error */	
		}
	}
	return false;
}