// --------------------------------------------------------------------------------
// purchase.js
// --------------------------------------------------------------------------------
// description - Validate form and write policy to the browser
// --------------------------------------------------------------------------------


// --------------------------------------------------------------------------------
// function :: validateForm( targetForm)
// --------------------------------------------------------------------------------
// targetForm - Form used to submit the product purchase
// --------------------------------------------------------------------------------

function validateForm( targetForm )
{
	// Declarations
	var output = "";
	var item = "";
	var validColour = false;
	var colourName = "";
	var alertText = "";
	
	// Get product selected on the order grid
	item = targetForm.elements[3].value;
	
	try
	{
		// Validate Colour from a multi select
		for( counter = 0; counter < document.userInput.colour.length; counter++ )
		{
			if( document.userInput.colour[ counter ].checked )
			{	
				validColour = true;
				colourName = document.userInput.colour[counter].value;	 
			}
		}	
	}
	catch( err )
	{
		validColour = false;
	}	
	
	// Build alert text
	if( validColour == false )                      { alertText += "- Colour\r"; }
	if( document.userInput.breed.value == "" )      { alertText += "- Breed\r"; }
	if( document.userInput.sex.value == "" )        { alertText += "- Sex\r"; }
	if( document.userInput.weight.value == "" )     { alertText += "- Weight\r"; }
	if( document.userInput.age.value == "" )        { alertText += "- Age\r"; }
	if( document.userInput.backLength.value == "" ) { alertText += "- Back Length\r"; }
	if( document.userInput.chestGirth.value == "" ) { alertText += "- Chest Girth\r"; }

	// Display alert text if the validation failed
	if( alertText != "" )
	{
		alert( "Please ensure the following fields are filled:\r\r" + alertText );
		return false;
	}
		
	// Build output
	output += item;
	output += "Colour:" + colourName + ", ";
	output += "Breed:" + document.userInput.breed.value + ", ";
	output += "Sex:" + document.userInput.sex.value + ", ";
	output += "Weight:" + document.userInput.weight.value + ", ";
	output += "Age:" + document.userInput.age.value + ", ";
	output += "A:" + document.userInput.backLength.value + ", ";
	output += "B:" + document.userInput.chestGirth.value + ", ";
	output += "C:" + document.userInput.chestWidth.value + ", ";
	output += "D:" + document.userInput.neckGirth.value;

	// Assign output back to the hidden field on the target form.
	targetForm.elements[3].value = output;
	
	return true;
}


// --------------------------------------------------------------------------------
// function :: validateFormCollars( targetForm)
// --------------------------------------------------------------------------------
// targetForm - Form used to submit the product purchase
// --------------------------------------------------------------------------------
function validateFormSingleColour( targetForm )
{
	// Declarations
	var output = "";
	var item = "";
	var validColour = false;
	var colourName = "";
	var alertText = "";
	
	// Get product selected on the order grid
	item = targetForm.elements[3].value;
	
	try
	{
		colourName = document.userInput.colour.value;
		validColour = true;
	}
	catch( err )
	{
		validColour = false;
	}		
	
	// Build alert text
	if( validColour == false )                      { alertText += "- Colour\r"; }
	if( document.userInput.breed.value == "" )      { alertText += "- Breed\r"; }
	if( document.userInput.sex.value == "" )        { alertText += "- Sex\r"; }
	if( document.userInput.weight.value == "" )     { alertText += "- Weight\r"; }
	if( document.userInput.age.value == "" )        { alertText += "- Age\r"; }
	if( document.userInput.backLength.value == "" ) { alertText += "- Back Length\r"; }
	if( document.userInput.chestGirth.value == "" ) { alertText += "- Chest Girth\r"; }

	// Display alert text if the validation failed
	if( alertText != "" )
	{
		alert( "Please ensure the following fields are filled:\r\r" + alertText );
		return false;
	}
		
	// Build output
	output += item;
	output += "Colour:" + colourName + ", ";
	output += "Breed:" + document.userInput.breed.value + ", ";
	output += "Sex:" + document.userInput.sex.value + ", ";
	output += "Weight:" + document.userInput.weight.value + ", ";
	output += "Age:" + document.userInput.age.value + ", ";
	output += "A:" + document.userInput.backLength.value + ", ";
	output += "B:" + document.userInput.chestGirth.value + ", ";
	output += "C:" + document.userInput.chestWidth.value + ", ";
	output += "D:" + document.userInput.neckGirth.value;

	// Assign output back to the hidden field on the target form.
	targetForm.elements[3].value = output;
	
	return true;
}


// --------------------------------------------------------------------------------
// function :: validateFormCollars( targetForm)
// --------------------------------------------------------------------------------
// targetForm - Form used to submit the product purchase
// --------------------------------------------------------------------------------
function validateFormCollars( targetForm )
{
	// Declarations
	var output = "";
	var item = "";
	var validColour = false;
	var colourName = "";
	var alertText = "";
	
	// Get product selected on the order grid
	item = targetForm.elements[3].value;
	
	try
	{
		// Validate Colour from a multi select
		for( counter = 0; counter < document.userInput.colour.length; counter++ )
		{
			if( document.userInput.colour[ counter ].checked )
			{	
				validColour = true;
				colourName = document.userInput.colour[counter].value;	 
			}
		}	
	}
	catch( err )
	{
		validColour = false;
	}			
	
	// Build alert text
	if( validColour == false )                      { alertText += "- Colour\r"; }
	if( document.userInput.breed.value == "" )      { alertText += "- Breed\r"; }
	if( document.userInput.sex.value == "" )        { alertText += "- Sex\r"; }
	if( document.userInput.weight.value == "" )     { alertText += "- Weight\r"; }
	if( document.userInput.age.value == "" )        { alertText += "- Age\r"; }
	
	// Display alert text if the validation failed
	if( alertText != "" )
	{
		alert( "Please ensure the following fields are filled:\r\r" + alertText );
		return false;
	}
	
	// Build output
	output += item;
	output += "Colour:" + colourName + ", ";
	output += "Breed:" + document.userInput.breed.value + ", ";
	output += "Sex:" + document.userInput.sex.value + ", ";
	output += "Weight:" + document.userInput.weight.value + ", ";
	output += "Age:" + document.userInput.age.value + ", ";

	// Assign output back to the hidden field on the target form.
	targetForm.elements[3].value = output;
	
	return true;
}


// --------------------------------------------------------------------------------
// function :: validateFormCollars( targetForm)
// --------------------------------------------------------------------------------
// targetForm - Form used to submit the product purchase
// --------------------------------------------------------------------------------
function validateFormGiftCertificates( targetForm )
{
	// Declarations
	var output = "";
	var item = "";
	var alertText = "";
	
	// Get product selected on the order grid
	item = targetForm.elements[3].value;
	
	// Build alert text
	if( document.userInput.purchaserName.value == "" )      { alertText += "- Purchaser Name\r"; }
	if( document.userInput.purchaserTelephone.value == "" ) { alertText += "- Purchaser Telephone\r"; }
	if( document.userInput.recipientName.value == "" )      { alertText += "- Recipient Name\r"; }
	
	// Display alert text if the validation failed
	if( alertText != "" )
	{
		alert( "Please ensure the following fields are filled:\r\r" + alertText );
		return false;
	}
	
	// Build output
	output += item;
	output += "PurchName:" 		+ document.userInput.purchaserName.value + ", ";
	output += "PurchTel:" 		+ document.userInput.purchaserTelephone.value + ", ";
	output += "PurchEmail:" 	+ document.userInput.purchaserEmail.value + ", ";
	output += "PurchAddr:" 		+ document.userInput.purchaserAddress.value + ", ";
	output += "RecipName:" 		+ document.userInput.recipientName.value + ", ";
	output += "RecipTel:" 		+ document.userInput.recipientTelephone.value + ", ";
	output += "RecipAddr:" 		+ document.userInput.recipientAddress.value + ", ";
	output += "From:"	 		+ document.userInput.from.value + ", ";
	output += "To:"	 			+ document.userInput.to.value + ", ";
	output += "Ship To:" 		+ document.userInput.shipTo.value;
	
	// Assign output back to the hidden field on the target form.
	targetForm.elements[3].value = output;
	
	return true;
}


// --------------------------------------------------------------------------------
// function :: validateFormHuman( targetForm)
// --------------------------------------------------------------------------------
// targetForm - Form used to submit the product purchase
// --------------------------------------------------------------------------------
function validateFormHuman( targetForm )
{
	// Declarations
	var output = "";
	var item = "";
	var validColour = false;
	var colourName = "";
	var alertText = "";
	
	// Get product selected on the order grid
	item = targetForm.elements[3].value;
	
	try
	{
		// Validate Colour from a multi select
		for( counter = 0; counter < document.userInput.colour.length; counter++ )
		{
			if( document.userInput.colour[ counter ].checked )
			{	
				validColour = true;
				colourName = document.userInput.colour[counter].value;	 
			}
		}	
	}
	catch( err )
	{
		validColour = false;
	}	
	
	// Build alert text
	if( validColour == false ){ alertText += "- Colour\r"; }
	
	// Display alert text if the validation failed
	if( alertText != "" )
	{
		alert( "Please ensure the following fields are filled:\r\r" + alertText );
		return false;
	}
	
	// Build output
	output += item;
	output += "Colour:" + colourName;

	// Assign output back to the hidden field on the target form.
	targetForm.elements[3].value = output;
	
	return true;
}


// --------------------------------------------------------------------------------
// function :: validateFormHuman( targetForm)
// --------------------------------------------------------------------------------
// targetForm - Form used to submit the product purchase
// --------------------------------------------------------------------------------
function validateFormHumanRainPoncho( targetForm )
{
	// Declarations
	var output = "";
	var item = "";
	var validColour = false;
	var colourName = "";
	var alertText = "";
	
	// Get product selected on the order grid
	item = targetForm.elements[3].value;
	
	try
	{
		colourName = document.userInput.colour.value;
		validColour = true;
	}
	catch( err )
	{
		validColour = false;
	}		

	// Build alert text
	if( validColour == false ){ alertText += "- Colour\r"; }
	
	// Display alert text if the validation failed
	if( alertText != "" )
	{
		alert( "Please ensure the following fields are filled:\r\r" + alertText );
		return false;
	}
	
	// Build output
	output += item;
	output += "Colour:" + colourName;

	// Assign output back to the hidden field on the target form.
	targetForm.elements[3].value = output;
	
	return true;
}


// --------------------------------------------------------------------------------
// function :: writePolicy( type)
// --------------------------------------------------------------------------------
// Writes out the policy information on the right hand column of an order form.
// type: 
// 		DEFAULT
// 		COLLARS_AND_LEASHES
// 		PAWS_FOR_CHARITY
// --------------------------------------------------------------------------------
function writePolicy( type )
{
	document.write( "<table class='clear'>" );
	
	
	if( type != "NO_GUARANTEE" )
	{
		document.write( "	<tr>" );
		document.write( "		<td>" );
		document.write( "			<b>Guarantee:</b> " );
		document.write( "			<br><br>" );
		document.write( "			Chilly Dogs&#153; fully guarantees all of our products against defects in construction and materials " );
		document.write( "			for a period of 1 year. Damage due to normal wear and tear, or chewing is not guaranteed. All " );
		document.write( "			refunds must be made from the original point of purchase. For size refunds or exchanges, products " );
		document.write( "			must be returned in a clean, as new, resaleable condition." );
		document.write( "			<br><br>" );
		
		if( type == "COLLARS_AND_LEASHES" )
		{
			document.write( "			To ensure you have purchased an authentic Around the Hounds collar, look for the logo on all collars!" );
			document.write( "			<br><br>" );
			document.write( "			All Around the Hounds products are made in Canada." );
		}
		else
		{
			document.write( "			To ensure you have purchased an authentic Chilly Dogs&#153; coat, look for our reflective 3M&#153; logo affixed directly on all our coats!" );
			document.write( "			<br><br>" );
			document.write( "			All Chilly Dogs&#153; products made in Canada" );
		}
		
		document.write( "			<br><br><br>" );
		document.write( "		</td>" );
		document.write( "	</tr>" );
	}
	
	
	
	document.write( "	<tr>" );
	document.write( "		<td>" );
	document.write( "			<b>Price, Payment and Shipping Policy:</b> " );
	document.write( "			<br><br>" );
	document.write( "			<table class='clear'>" );



//	document.write( "				<tr>" );
//	document.write( "					<td width='7%' valign='top'>1.</td>" );
//	document.write( "					<td width='93%'>" );
//	document.write( "						$10.00 CDN fixed shipping rate for orders within Canada.  $15.00 CDN for US orders will be added.  $25.00 CDN for International orders will be added.<br>" );
//	document.write( "					</td>" );
//	document.write( "				</tr>" );





	document.write( "				<tr>" );
	document.write( "					<td width='7%' valign='top'>1.</td>" );
	document.write( "					<td width='93%'>" );
	document.write( "						We use Canada Post to ship all orders.<br>" );
	document.write( "					</td>" );
	document.write( "				</tr>" );

	document.write( "				<tr>" );
	document.write( "					<td width='7%' valign='top'>- </td>" );
	document.write( "					<td width='93%'>" );
	document.write( "						Canadian destinations: Canada Post-Expedited Parcel.  1 to 6 business days delivery time.<br>" );
	document.write( "					</td>" );
	document.write( "				</tr>" );

	document.write( "				<tr>" );
	document.write( "					<td width='7%' valign='top'>- </td>" );
	document.write( "					<td width='93%'>" );
	document.write( "						US destinations: Canada Post-Small Packet Air USA.  Approx. 8 business days delivery time.<br>" );
	document.write( "					</td>" );
	document.write( "				</tr>" );

	document.write( "				<tr>" );
	document.write( "					<td width='7%' valign='top'>- </td>" );
	document.write( "					<td width='93%'>" );
	document.write( "						International destinations: Canada Post - Small Packet Air International. Approx. 14 business days delivery time.<br>" );
	document.write( "					</td>" );
	document.write( "				</tr>" );




	document.write( "				<tr>" );
	document.write( "					<td width='7%' valign='top'>2.</td>" );
	document.write( "					<td width='93%'>" );
	document.write( "						All prices are in Canadian dollars." );
	document.write( "					</td>" );
	document.write( "				</tr>" );
	document.write( "				<tr>" );
	document.write( "					<td width='7%' valign='top'>3.</td>" );
	document.write( "					<td width='93%'>" );
	document.write( "						Payment methods include; Visa, Mastercard, Paypal, Cheque in Canadian funds drawn on a " );
	document.write( "						Canadian Bank or Postal Money Order in Canadian Funds." );
	document.write( "					</td>" );
	document.write( "				</tr>" );
	document.write( "				<tr>" );
	document.write( "					<td width='7%' valign='top'>4.</td>" );
	document.write( "					<td width='93%'>" );
	document.write( "						Payment via cheque or moneyorder payable to Chilly Dogs&#153;" );
	document.write( "					</td>" );
	document.write( "				</tr>" );
	document.write( "				<tr>" );
	document.write( "					<td width='7%' valign='top'>5.</td>" );
	document.write( "					<td width='93%'>" );
	document.write( "						All orders will be shipped upon receipt of payment." );
	document.write( "					</td>" );
	document.write( "				</tr>" );
	document.write( "				<tr>" );
	document.write( "					<td width='7%' valign='top'>6.</td>" );
	document.write( "					<td width='93%'>" );
	document.write( "						C.O.D. orders and other credit cards are not accepted." );
	document.write( "					</td>" );
	document.write( "				</tr>" );
	document.write( "				<tr>" );
	document.write( "					<td width='7%' valign='top'>7.</td>" );
	document.write( "					<td width='93%'>" );
	document.write( "						Orders shipped outside Canada may be charged duty and taxes at destination." );
	document.write( "					</td>" );
	document.write( "				</tr>" );
	document.write( "				<tr>" );
	document.write( "					<td width='7%' valign='top'>8.</td>" );
	document.write( "					<td width='93%'>" );
	document.write( "						Provincial Sales Tax (PST 8%) on orders shipped within Ontario will be added." );
	document.write( "					</td>" );
	document.write( "				</tr>" );
	document.write( "				<tr>" );
	document.write( "					<td width='7%' valign='top'>9.</td>" );
	document.write( "					<td width='93%'>" );
	document.write( "						Federal Sales Tax (GST 5%) on orders shipped within Canada will be added." );
	document.write( "					</td>" );
	document.write( "				</tr>" );
	document.write( "			</table>" );
	document.write( "		</td>" );
	document.write( "	</tr>" );
	document.write( "	<tr>" );
	document.write( "		<td align='center'>" );
	document.write( "			<br>" );
	
	if( type == "PAWS_FOR_CHARITY" )
	{
		document.write( "			<img src='images/icons/paymentLogosPawsForCharity.jpg' width='149' height='23' border='0' alt=''>" );
	}
	else
	{
		document.write( "			<img src='images/icons/paymentLogos.jpg' width='149' height='23' border='0' alt=''>" );
	}
	
	document.write( "		</td>" );
	document.write( "	</tr>" );
	document.write( "</table>" );
}


