// CD Duplication Calculation script
// 
	function doCheck() {	
		var myQuantity = document.cd_quote.quantity.value;
		
		if (myQuantity < 50) {
			alert('The minimum order for CD Duplication is 50 CDs. Please correct the quantity!');
			document.cd_quote.quantity.value = 50;
			myQuantity = 50;
		} // end if
		
		var theQuote = .30;
		
		if (document.cd_quote.thermal.value == "yes") {
			theQuote += .25;
			document.images['cd_img1'].src = "images/cd_thermal.jpg";
		}// end if		

		if (document.cd_quote.thermal.value == "no") {
			document.images['cd_img1'].src = "images/cd_silver.jpg";
		}// end if		

		var thePackage = document.cd_quote.package.value;

		switch (thePackage)
		{
			case 'paper':
			  theQuote += .10; //04
			  document.images['cd_img2'].src = "images/cd_paper.jpg";
			  break;
			case 'plastic':
			  theQuote += .15; //07
			  document.images['cd_img2'].src = "images/cd_plastic.jpg";
			   break;
			case 'slim':
			  theQuote += .18; //
			  document.images['cd_img2'].src = "images/cd_slimblack.jpg";
			  break;
			case 'slimcolor':
			  theQuote += .20; //13
			  document.images['cd_img2'].src = "images/cd_slimcolor.jpg";
			  break;
			case 'regular':
			  theQuote += .27; //20  
			  document.images['cd_img2'].src = "images/cd_regular.jpg";
			  break;			  
			case 'cshell':
			  theQuote += .27; //12 
			  document.images['cd_img2'].src = "images/cd_cshell.jpg";
			  break;
			 case 'none':
			 theQuote += .01;
			  document.images['cd_img2'].src = "images/cd_white.jpg";
			  break;
			  
 		 }// end switch

							
		var myQuote = myQuantity * theQuote;
		
		if (document.cd_quote.insert_print.value == 'yes')
		{
			document.images['cd_img3'].src = "images/cd_insert.jpg";

			if (myQuantity <= 1005) {
				myQuote += 120; 
			} else {
				myQuote += 220; 
			}// end if else
		} else {
			document.images['cd_img3'].src = "images/cd_white.jpg";
		}// end if
		
		if (document.cd_quote.insert_design.value == 'yes')
		{
			myQuote += 50; 
			document.images['cd_img3'].src = "images/cd_designonly.jpg";
			//document.cd_quote.insert_print.value = 'yes';
						
		}// end if		
		

		if ( (document.cd_quote.insert_design.value == 'yes') && (document.cd_quote.insert_print.value == 'yes') ) {

			document.images['cd_img3'].src = "images/cd_design.jpg";
	
		} // end if both are true 

		myQuote = Math.round(myQuote, 4);
		
		document.cd_quote.quote.value = "$" + myQuote;

	} // end function
	
	


function isEmailAddr(email)
{
  var result = false;
  var theStr = new String(email);
  var index = theStr.indexOf("@");
  if (index > 0)
  {
    var pindex = theStr.indexOf(".",index);
    if ((pindex > index+1) && (theStr.length > pindex+1))
	result = true;
  }
  return result;
}

function validRequired(formField,fieldLabel)
{
	var result = true;
	
	if (formField.value == "")
	{
			if (fieldLabel == "E-mail")
				alert('Please enter a valid E-mail address.');

				
		formField.focus();
		result = false;
		
	}
	
	return result;
}


function validEmail(formField,fieldLabel,required)
{
	var result = true;
	
	if (required && !validRequired(formField,fieldLabel))
		result = false;

	if (result && ((formField.value.length < 3) || !isEmailAddr(formField.value) ) )
	{
		alert("Please enter a complete email address in the form: yourname@yourdomain.com");
		formField.focus();
		result = false;
	}
   
  return result;

}

function validPostal(formField,fieldLabel,required)
{
	var result = true;
	
	if (required && !validRequired(formField,fieldLabel))
		result = false;

	if (result && (formField.value.length < 3)  )
	{
		alert("Please enter a valid Postal code");
		formField.focus();
		result = false;
	}
   
  return result;

}



function validateForm(form)
{
	// Customize these calls for your form

	// Start ------->
	
		
	if (!validRequired(form.email,"E-mail"))
		return false;
			
	if (!validEmail(form.email,"E-mail",true))
		return false;
	
	// <--------- End
	
	return true;
}

