// JavaScript Document
// Verify The Choose Package Form
// File: validateChoice.js
// Version: V1.0
// Last Updated: 10 February 2003
// Author: Bozidar Jovanovic - boz@neolateral.com.au
// Company: Neolateral
// ABN: 31 554 615 680
	
	function updateCount( form )
	{
		var text = null;
		text = form.textDescription.value;
		
		var length = text.length;
		
		for ( i = 0; i < text.length; i++) // loop throught the text the user typed and compensate for 'carraige return + linefeed = newline' being 2 chars...
		{
			if ( text.charAt(i) == '\n' )
			{
				length--; // subtract 1 from the 
						  // length the user sees to compensate for {enter} being 
						  // 2 chars (carraige return + linefeed)
			}
		}
		
		//form.charCount.value = "Character Count: Used " + length + " of " + form.maxChars.value + " allowed.";
		if ( length >= form.maxChars.value ) // i.e. reached Max Chars...
		{
			//var testvar = text.charAt(10);
			var resizedText = "";
			var maxCharsCalculated = form.maxChars.value;
			for ( i = 0; i < maxCharsCalculated; i++)
			{
				if ( text.charAt(i) == '\n' )
				{
					maxCharsCalculated++;
				}
				resizedText = resizedText + text.charAt(i);
			}
			form.textDescription.value = resizedText;
	//		form.charCount.value = "Character Count: Used " + length + " of " + form.maxChars.value + " allowed.";
			form.textDescription.focus();
			//alert("You have reached the maximum allowed number of characters for this advertising package.\nIf you require adding more information to your text description, consider revising your description, or choosing\na package that offers more text storage space. Thank you.");
		}
		//alert( form.textDescription.value + " has length " + text.length );
	}
	
	function validateAdDetails( form )
	{
		//alert("About to Submit...");
	
		if (form.headline.value == "") // Check 'headline' field
		{ 
			alert ("Please enter headline for your advertisement.")
			form.headline.focus();
        	return false ;
		}
		
/*		if (!validEmail( form.emailAddress ) )
		{
			alert("Please enter a valid email address for your advertisement") ;
			form.emailAddress.focus();
			return false ;
		}*/
		
/*		if (form.phoneNumber.value == "") 
		{ 
			alert ("Please enter a contact phone number for your advertisement.")
			form.phoneNumber.focus();
        	return false ;
		}*/
		
/*		if (form.price.value == "Your Selling Price (eg 38.00)") 
		{ 
			alert ("Please enter your selling price.")
			form.price.focus();
        	return false ;
		}*/
		
		var descriptionText = null;
		var text = null;
		text = form.textDescription.value;
		descriptionText = "Type your text description for your advertisement here. You may submit as much text as you can fit into this box.";

		if (text == descriptionText) // Check 'textDescription' field
		{ 
			alert ("Please enter your text description for your advertisement.")
			form.textDescription.focus();
        	return false ;
		}

		function validEmail( emailAddress )
		{
			var valid = false ;

			if (emailAddress.value.length < 7) //a@bc.de check for minimum length
			{
				return false ;
			}

			var hasAt = -1;
			for (i = 0; i < emailAddress.value.length ; i++)
			{
				
				if (emailAddress.value.charAt(i) == "@")
				{
					//valid = true ;
					hasAt = i;
					//return true ;
				}
				
				//Check to see if we have at least 'a@bc.de'
				if ( ( i >= hasAt + 2) && ( emailAddress.value.length >= (hasAt + (i-hasAt) + 3) ) && (emailAddress.value.charAt(i) == ".") )
				{
					valid = true ;
					//return true ;
				}
			}
			if ( !valid )
			{
				return false ;
			}else
			{
				return true ;
			}
		}
	}
	
	
	
	function validateChoice( choice )
	{

		if(choiceMade() == -1)
		{
			alert("Please choose a package that best suits your needs before proceeding. Thank you.");
			return false;
		}else
		{
			return true;
		}

		function choiceMade()
		{
			var i;

			for( i=0; i<choice.selection.length; ++i)
				if( choice.selection[i].checked)
					return 1;

			// default (none selected)
			return -1;
		}
	}