/* Function used to create a popup window used for printing purposes...*/
function printDesing(strID)
{
	intWidth = 800;
	intHeight = 500;
	intTop = (window.screen.height-intHeight)/2;
	intLeft = (window.screen.width-intWidth)/2;
	/*
	window.open('/resource/ajax/showSavedCustomImage.cfm?action=print&SCD_ID=' + strID,
				'_blank',
				'width=' + intWidth + 
				',height=' + intHeight +
				',top=' + intTop + 
				',left=' + intLeft + 
				',resizable=1');
	*/
	Lightbox.showBoxByAJAX('/resource/ajax/showSavedCustomImage.cfm?action=print&SCD_ID=' + strID, intWidth, intHeight);
}

// Function used to create a popup window used for emailing purposes...
function emailDesign(strID, strRedirect)
{
	intWidth = 900;
	intHeight = 500;
	intTop = (window.screen.height-intHeight)/2;
	intLeft = (window.screen.width-intWidth)/2;
	Lightbox.showBoxByAJAX('/resource/ajax/showSavedCustomImage.cfm?action=email&SCD_ID=' + strID + '&strRedirect=' + strRedirect, intWidth, intHeight);
}

// Function used to validate the Request Access form...
function validateAccessRequestForm()
{
	blnError = false;
	strErrorMsg = '';
	objForm = document.frmAccessRequest;
	objFirstFocus = '';
	
	// Require a gym mane..
	if(objForm.strGymName.value == '')
	{
		strErrorMsg += '\nPlease enter your Gym Name';
		blnError = true;
		objFirstFocus = objFirstFocus==''?objForm.strGymName:objFirstFocus;
	}
	// Require a first name...
	if(objForm.strFirstName.value == '')
	{
		strErrorMsg += '\nPlease enter your First Name';
		blnError = true;
		objFirstFocus = objFirstFocus==''?objForm.strFirstName:objFirstFocus;
	}
	// Require a last name...
	if(objForm.strLastName.value == '')
	{
		strErrorMsg += '\nPlease enter your Last Name';
		blnError = true;
		objFirstFocus = objFirstFocus==''?objForm.strLastName:objFirstFocus;
	}
	
	// Require an address...
	if(objForm.strAddress.value == '')
	{
		strErrorMsg += '\nPlease enter your Address';
		blnError = true;
		objFirstFocus = objFirstFocus==''?objForm.strAddress:objFirstFocus;
	}
	
	// Require an city...
	if(objForm.strCity.value == '')
	{
		strErrorMsg += '\nPlease enter your City';
		blnError = true;
		objFirstFocus = objFirstFocus==''?objForm.strCity:objFirstFocus;
	}
	
	// Require an city...
	if(objForm.strState.value == '')
	{
		strErrorMsg += '\nPlease enter your State';
		blnError = true;
		objFirstFocus = objFirstFocus==''?objForm.strState:objFirstFocus;
	}
	
	// Require an zipcode...
	if(objForm.strZip.value == '')
	{
		strErrorMsg += '\nPlease enter your Zipcode';
		blnError = true;
		objFirstFocus = objFirstFocus==''?objForm.strZip:objFirstFocus;
	}
	
	// Require an phone...
	if(objForm.strPhone.value == '')
	{
		strErrorMsg += '\nPlease enter your Phone Number';
		blnError = true;
		objFirstFocus = objFirstFocus==''?objForm.strPhone:objFirstFocus;
	}
	
	if(objForm.strEMail.value == '')
	{
		strErrorMsg += '\nPlease enter your Email address';
		blnError = true;
		objFirstFocus = objFirstFocus==''?objForm.strEMail:objFirstFocus;
	}
	else if(!_CF_checkEmail(objForm.strEMail.value, true))
	{
		strErrorMsg += '\nPlease enter a valid Email address';
		blnError = true;
		objFirstFocus = objFirstFocus==''?objForm.strEMail:objFirstFocus;
	}
	
	if(blnError)
	{
		alert(strErrorMsg);		
		if(typeof(objFirstFocus) == 'object')
		{
			objFirstFocus.focus();
		}
		return false;
	}
	else
	{
		/* Submit the form...*/
		objForm.submit();
	}
}

// Function used to validate an email address field under the Forgot Customer Number request form...
function validateForgotCustomerNumberForm()
{
	blnError = false;
	strErrorMsg = '';
	objForm = document.frmForgotCustomerNumber;
	if(objForm.email.value == '')
	{
		strErrorMsg += '\nPlease enter your email address';
		blnError = true;
	}
	else if(!_CF_checkEmail(objForm.email.value, true))
	{
		strErrorMsg += '\nPlease enter a valid email address';
		blnError = true;
	}
	
	if(blnError)
	{
		alert(strErrorMsg);
	}
	else
	{
		/* Submit the form...*/
		objForm.submit();
	}
}

// Function used under the 'Email to a Friend' section uder my Account...
function validateEmailToAFriendForm()
{
	objForm = document.frmEmail;
	blnError = false;
	strErrorMsg = '';
	if(objForm.strMyEmail.value == '')
	{
		strErrorMsg += '\nPlease enter your email address';
		blnError = true;
	}
	else if(!_CF_checkEmail(objForm.strMyEmail.value, true))
	{
		strErrorMsg += '\nPlease enter a valid email address';
		blnError = true;
	}
	
	if(objForm.txtMessage.value == '')
	{
		strErrorMsg += '\nPlease enter a message';
		blnError = true;
	}
	if(objForm.strFriendsEmail.value == '')
	{
		strErrorMsg += '\nPlease enter your friends email address';
		blnError = true;
	}
	/* - Removed email validation since it fails when multiple email addresses are entered - Victor - August 11, 2008
	else if(!_CF_checkEmail(objForm.strFriendsEmail.value, true))
	{
		strErrorMsg += '\nPlease enter a valid email address';
		blnError = true;
	}												
	*/
	if(blnError)
	{
		alert(strErrorMsg);
	}
	else
	{
		/* Submit the form...*/
		objForm.submit();
	}	
}

/* Helper functions stollen from the cfform.js file */											
function _CF_checkregex(object_value, regexPattern, required)
{
	if( required )
	{
		if( object_value.length == 0 )
		{
			return false;
		}
	}else{
		if( object_value.length == 0 )
		{
			return true;
		}
	}

	return regexPattern.test(object_value);
}

function _CF_checkEmail(object_value, required)
{
	//trim whitespace before we validate
	object_value = object_value.replace(/^\s+/,'').replace(/\s+$/,'');
	return _CF_checkregex(object_value, /^[a-zA-Z_0-9-'\+~]+(\.[a-zA-Z_0-9-'\+~]+)*@([a-zA-Z_0-9-]+\.)+[a-zA-Z]{2,7}$/, required);
}

/*******************	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;
}