<!--

//TOP PRODUCER JAVASCRIPT

function validateBuyersData()
{
	var txtFirstName		= getElementById( "FIRST_NAME"			);
	var txtLastName			= getElementById( "LAST_NAME"			);
	var txtEmail			= getElementById( "EMAIL"				);
	var txtPhoneAreaCode	= getElementById( "PHONE_AREA_CODE"	);
	var txtPhoneLocalCode	= getElementById( "PHONE_LOCAL_CODE"	);
	var txtPhoneNumber		= getElementById( "PHONE_NUMBER"		);
	var txtComments			= getElementById( "COMMENTS"			);
	var sPhoneValue			= txtPhoneAreaCode.value + txtPhoneLocalCode.value + txtPhoneNumber.value;
	var bRequirementsMet	= true;
	
	
	if( txtFirstName.value.length == 0 && txtLastName.value.length == 0 ) {
		bRequirementsMet = false;
	}
	if( bRequirementsMet && ( txtEmail.value.length == 0 && sPhoneValue.length == 0 ) ) {
		bRequirementsMet = false;
	}
	
	if( !bRequirementsMet ) {
		window.alert( "\nPlease enter your FIRST NAME or LAST NAME\nand\nPHONE NUMBER or EMAIL ADDRESS.\n" );
	} else {
		if( sPhoneValue.length > 0 && ( txtPhoneAreaCode.value.length != 3 || txtPhoneLocalCode.value.length != 3 || txtPhoneNumber.value.length != 4 ) ) {
			bRequirementsMet = false;
			window.alert( "\nYou have entered an invalid phone number. Please enter a correct phone number.\n" );
		}
		if( bRequirementsMet && txtEmail.value.length > 0 ) {
			var nAtSymbolIndex = txtEmail.value.indexOf( "@" );
			var sUserName      = "";
			var sServerName    = "";
			
			if( nAtSymbolIndex > 0 && nAtSymbolIndex < txtEmail.value.length - 1 ) {
				sUserName = txtEmail.value.substring( 0, nAtSymbolIndex );
				sServerName = txtEmail.value.substring( nAtSymbolIndex + 1 );
				nAtSymbolIndex = sServerName.indexOf( "." );
			}
			if( nAtSymbolIndex == -1 || sUserName.length == 0 || sServerName.length == 0 ) {
				window.alert( "You have entered an invalid email address. Please enter a correct email address." );
				bRequirementsMet = false;
			}
		}
		var txtZip = getElementById( "ZIP" );
		txtZip.value = txtZip.value.toUpperCase();

		if( typeof( txtComments ) != "undefined" && txtComments != null && txtComments.value.length > 2900 ) {
			bRequirementsMet = false;
			window.alert( "\nYour comments are too long.  Please try to limit the length of your comments to 2900 characters.\n" );
		}
	}
	
	// The BUYER minimum price must be less than or equal to the maximum price.
	if( bRequirementsMet ) {
		var txtMinPrice = getElementById( "BUYER_MIN_PRICE" );
		var txtMaxPrice = getElementById( "BUYER_MAX_PRICE" );
		if( typeof( txtMinPrice ) != "undefined" && txtMinPrice != null && typeof( txtMaxPrice ) != "undefined" && txtMaxPrice != null ) {
			var sMinPrice = txtMinPrice.value;
			var sMaxPrice = txtMaxPrice.value;
			// Pre-parse the string to remove any non digit characters
			sMinPrice = sMinPrice.replace( /\$|\+|,/g,			"" );
			sMaxPrice = sMaxPrice.replace( /\$|\+|,/g,			"" );
		
			// Convert from a string to a number.
			var nMinPrice = new Number( sMinPrice );
			var nMaxPrice = new Number( sMaxPrice );
		
			if( nMinPrice != Number.NaN && nMaxPrice != Number.NaN && nMinPrice > nMaxPrice ) {
				window.alert( "\nYou have specified an invalid minimum or maximum price.  Please\nensure that the minimum price is not greater than the maximum price\nin the price range section.\n" )
				bRequirementsMet = false;
			}
		}
	}
	
	return bRequirementsMet;
}

function validateSellersData()
{
	var txtFirstName		= getElementById( "FIRST_NAME"			);
	var txtLastName			= getElementById( "LAST_NAME"			);
	var txtEmail			= getElementById( "EMAIL"				);
	var txtPhoneAreaCode	= getElementById( "PHONE_AREA_CODE"	);
	var txtPhoneLocalCode	= getElementById( "PHONE_LOCAL_CODE"	);
	var txtPhoneNumber		= getElementById( "PHONE_NUMBER"		);
	var txtComments			= getElementById( "COMMENTS"			);
	var sPhoneValue			= txtPhoneAreaCode.value + txtPhoneLocalCode.value + txtPhoneNumber.value;
	var bRequirementsMet	= true;
	
	
	if( txtFirstName.value.length == 0 && txtLastName.value.length == 0 ) {
		bRequirementsMet = false;
	}
	if( bRequirementsMet && ( txtEmail.value.length == 0 && sPhoneValue.length == 0 ) ) {
		bRequirementsMet = false;
	}
	
	if( !bRequirementsMet ) {
		window.alert( "\nPlease enter your FIRST NAME or LAST NAME\nand\nPHONE NUMBER or EMAIL ADDRESS.\n" );
	} else {
		if( sPhoneValue.length > 0 && ( txtPhoneAreaCode.value.length != 3 || txtPhoneLocalCode.value.length != 3 || txtPhoneNumber.value.length != 4 ) ) {
			bRequirementsMet = false;
			window.alert( "\nYou have entered an invalid phone number. Please enter a correct phone number.\n" );
		}
		if( bRequirementsMet && txtEmail.value.length > 0 ) {
			var nAtSymbolIndex = txtEmail.value.indexOf( "@" );
			var sUserName      = "";
			var sServerName    = "";
			
			if( nAtSymbolIndex > 0 && nAtSymbolIndex < txtEmail.value.length - 1 ) {
				sUserName = txtEmail.value.substring( 0, nAtSymbolIndex );
				sServerName = txtEmail.value.substring( nAtSymbolIndex + 1 );
				nAtSymbolIndex = sServerName.indexOf( "." );
			}
			if( nAtSymbolIndex == -1 || sUserName.length == 0 || sServerName.length == 0 ) {
				window.alert( "You have entered an invalid email address. Please enter a correct email address." );
				bRequirementsMet = false;
			}
		}
		var txtZip = getElementById( "ZIP" );
		txtZip.value = txtZip.value.toUpperCase();

		txtZip = getElementById( "SELLER_ZIP" );
		txtZip.value = txtZip.value.toUpperCase();
		if( typeof( txtComments ) != "undefined" && txtComments != null && txtComments.value.length > 2900 ) {
			bRequirementsMet = false;
			window.alert( "\nYour comments are too long.  Please try to limit the length of your comments to 2900 characters.\n" );
		}
	}
	
	// The SELLER minimum price must be less than or equal to the maximum price.
	if( bRequirementsMet ) {
		var txtMinPrice = getElementById( "SELLER_MIN_PRICE" );
		var txtMaxPrice = getElementById( "SELLER_MAX_PRICE" );
		if( typeof( txtMinPrice ) != "undefined" && txtMinPrice != null && typeof( txtMaxPrice ) != "undefined" && txtMaxPrice != null ) {
			var sMinPrice = txtMinPrice.value;
			var sMaxPrice = txtMaxPrice.value;
			// Pre-parse the string to remove any non digit characters
			sMinPrice = sMinPrice.replace( /\$|\+|,/g,			"" );
			sMaxPrice = sMaxPrice.replace( /\$|\+|,/g,			"" );
		
			// Convert from a string to a number.
			var nMinPrice = new Number( sMinPrice );
			var nMaxPrice = new Number( sMaxPrice );
		
			if( sMinPrice.length != 0 && sMaxPrice.length != 0 ) {
				if( nMinPrice != Number.NaN && nMaxPrice != Number.NaN && nMinPrice > nMaxPrice ) {
					window.alert( "\nYou have specified an invalid minimum or maximum price.  Please\nensure that the minimum price is not greater than the maximum price\nin the price range section.\n" )
					bRequirementsMet = false;
				}
			}
		}
	}
	
	return bRequirementsMet;
}

function validateFreeInfoData()
{
	var txtFirstName		= getElementById( "FIRST_NAME"			);
	var txtLastName			= getElementById( "LAST_NAME"			);
	var txtEmail			= getElementById( "EMAIL"				);
	var txtPhoneAreaCode	= getElementById( "PHONE_AREA_CODE"	);
	var txtPhoneLocalCode	= getElementById( "PHONE_LOCAL_CODE"	);
	var txtPhoneNumber		= getElementById( "PHONE_NUMBER"		);
	var txtComments			= getElementById( "COMMENTS"			);
	var sPhoneValue			= txtPhoneAreaCode.value + txtPhoneLocalCode.value + txtPhoneNumber.value;
	var bRequirementsMet	= true;
	
	
	if( txtFirstName.value.length == 0 && txtLastName.value.length == 0 ) {
		bRequirementsMet = false;
	}
	if( bRequirementsMet && ( txtEmail.value.length == 0 && sPhoneValue.length == 0 ) ) {
		bRequirementsMet = false;
	}
	
	if( !bRequirementsMet ) {
		window.alert( "\nPlease enter your FIRST NAME or LAST NAME\nand\nPHONE NUMBER or EMAIL ADDRESS.\n" );
	} else {
		if( sPhoneValue.length > 0 && ( txtPhoneAreaCode.value.length != 3 || txtPhoneLocalCode.value.length != 3 || txtPhoneNumber.value.length != 4 ) ) {
			bRequirementsMet = false;
			window.alert( "\nYou have entered an invalid phone number. Please enter a correct phone number.\n" );
		}
		if( bRequirementsMet && txtEmail.value.length > 0 ) {
			var nAtSymbolIndex = txtEmail.value.indexOf( "@" );
			var sUserName      = "";
			var sServerName    = "";
			
			if( nAtSymbolIndex > 0 && nAtSymbolIndex < txtEmail.value.length - 1 ) {
				sUserName = txtEmail.value.substring( 0, nAtSymbolIndex );
				sServerName = txtEmail.value.substring( nAtSymbolIndex + 1 );
				nAtSymbolIndex = sServerName.indexOf( "." );
			}
			if( nAtSymbolIndex == -1 || sUserName.length == 0 || sServerName.length == 0 ) {
				window.alert( "You have entered an invalid email address. Please enter a correct email address." );
				bRequirementsMet = false;
			}
		}
		
		if( typeof( txtComments ) != "undefined" && txtComments != null && txtComments.value.length > 2900 ) {
			bRequirementsMet = false;
			window.alert( "\nYour comments are too long.  Please try to limit the length of your comments to 2900 characters.\n" );
		}
	}
	
	// They must select atleast one packet
	if( bRequirementsMet ) {
		var i;
		var bChecked = false;
		// Check if user selected atleast one packet
		for (i=0;i<document.frmMain.elements["WWYL"].length; i++)
		{
			if (document.frmMain.elements["WWYL"][i].checked == true)
			{
				bChecked = true;
			}
		}
		
		if(bChecked)
		{
		}
		else
		{
			window.alert( "\nYou must select atleast one packet.\n" );
			bRequirementsMet = false;
		}
	}
	if (bRequirementsMet == true)
	{
		joinFields();
	}
	return bRequirementsMet;
}

// Move items from the Free Info packet checkboxes to
// the Comments field
function joinFields()
{
	// Add heading so we know where the packet information starts
	document.frmMain.elements["COMMENTS"].value += " [SELECTED PACKAGES: "
	for (var i=0;i<document.frmMain.elements["WWYL"].length; i++)
	{
		if (document.frmMain.elements["WWYL"][i].checked == true)
		{
			document.frmMain.elements["COMMENTS"].value += document.frmMain.elements["WWYL"][i].value + ",";
		}
	}
	document.frmMain.elements["COMMENTS"].value += "]"	
	return true;
}

function enableAddressFields( clearValues ) {
	var objCheckbox = getElementById( "SELLER_LOCATION_SAME_ADDRESS" );
	var objRadio = getElementById( "STATUS_BUYER" );
	
	var disable = objCheckbox.checked
	var ctrlHouseNo		= getElementById( "SELLER_HOUSE_NO"    );
	var ctrlStreetName	= getElementById( "SELLER_STREET_NAME" );
	var ctrlSuiteNo		= getElementById( "SELLER_SUITE_NO"    );
	var ctrlCity		= getElementById( "SELLER_CITY"        );
	var ctrlState		= getElementById( "SELLER_STATE"       );
	var ctrlZip			= getElementById( "SELLER_ZIP"         );

	setControl( ctrlHouseNo,	disable );
	setControl( ctrlStreetName,	disable );
	setControl( ctrlSuiteNo,	disable );
	setControl( ctrlCity,		disable );
	setControl( ctrlState,		disable );
	setControl( ctrlZip,		disable );

	setControl( getElementById( "TXT_SELLER_HOUSE_NO"		), disable );
	setControl( getElementById( "TXT_SELLER_STREET_NAME"	), disable );
	setControl( getElementById( "TXT_SELLER_SUITE_NO"		), disable );
	setControl( getElementById( "TXT_SELLER_CITY"			), disable );
	setControl( getElementById( "TXT_SELLER_STATE"			), disable );
	setControl( getElementById( "TXT_SELLER_ZIP"			), disable );

	if( disable ) {
		setValue( ctrlHouseNo,		"HOUSE_NO"		);
		setValue( ctrlStreetName,	"STREET_NAME"	);
		setValue( ctrlSuiteNo,		"SUITE_NO"		);
		setValue( ctrlCity,			"CITY"			);
		setValue( ctrlState,		"STATE"			);
		setValue( ctrlZip,			"ZIP"			);
	}
	else if( typeof( clearValues ) == "undefined" ) {
		clearValue( ctrlHouseNo		);
		clearValue( ctrlStreetName	);
		clearValue( ctrlSuiteNo		);
		clearValue( ctrlCity		);
		clearValue( ctrlState		);
		clearValue( ctrlZip			);
	}
}

function clearValue( obj ) {
	if( typeof( obj ) != "undefined" && obj != null ) {
		obj.value = "";
	}
}

function setValue( obj, name ) {
	var obj2 = getElementById( name );
	if( typeof( obj ) != "undefined" && obj != null && typeof( obj2 ) != "undefined" && obj2 != null ) {
		var width = obj.offsetWidth;
		obj.value = obj2.value;
		obj.style.width = width;
	}
}


function setControl( control, disable, value ) {
	if( typeof( control ) != "undefined" && control != null ) {
		control.disabled = disable;
		if( disable ) {
			control.value = typeof( value ) == "undefined" ? "" : value;
			if( control.checked ) {
				control.checked = false;
			}
		}
	}
}
		
// Retrieve an element by it's ID attribute
// NOTE: This function is used in place of
//  'document.getElementById() to support
//  Internet Explorer 4.01.
function getElementById( id ) {
	if( typeof( document.getElementById ) == "undefined" ) {
		for( var i = 0; i < document.all.length; i++ ) {
			var el = document.all( i );
			if( el.id == id ) {
				return el;
			}
		}
	}
	else {
		return document.getElementById( id );
	}
}
function moveToNextField( id ) {
	if( window.event.keyCode != 9 ) {
		if( getElementById( id ).value.length == 3 ) {
			if( id == "PHONE_AREA_CODE" ) {
				getElementById( "PHONE_LOCAL_CODE" ).focus();
			}
			else if( id == "PHONE_LOCAL_CODE" ) {
				getElementById( "PHONE_NUMBER" ).focus();
			}
		}
	}
}
function allowKeys( obj, keys ) {
	var bAllowKey = false;
	for( var i = 0; i < keys.length; i++ ) {
		if( keys.charAt( i ) == String.fromCharCode( window.event.keyCode ) ) {
			bAllowKey = true;
			break;
		}
	}
	if( !bAllowKey ) {
		window.event.cancelBubble = true;
		window.event.keyCode = 0;
	}
}
function validateInput( obj, keys ) {
	if( typeof( window.clipboardData ) != "undefined" ) {
		var sData = window.clipboardData.getData( "Text" )
		var sTemp = "";
		if( typeof( sData ) != "undefined" ) {
			for( var i = sData.length; --i >= 0; ) {
				for( var j = keys.length; --j >= 0; ) {
					if( sData.charAt( i ) == keys.charAt( j ) ) {
						sTemp += sData.charAt( i );
					}
				}
			}
		}
	
		window.clipboardData.setData( "Text", sTemp );
	}
}
function enableBestTime() {
	var txtPhoneArea	= getElementById( "PHONE_AREA_CODE"		);
	var txtPhoneLocal	= getElementById( "PHONE_LOCAL_CODE"	);
	var txtPhoneNumber	= getElementById( "PHONE_NUMBER"		);
	var obgBestTime		= getElementById( "BEST_TIME"			);

	if( typeof( txtPhoneArea ) != "undefined" && txtPhoneArea != null && typeof( obgBestTime ) != "undefined" && obgBestTime != null ) {
		obgBestTime.disabled = !( txtPhoneArea.value.length != 0 || txtPhoneLocal.value.length != 0 || txtPhoneNumber.value.length != 0 );
	}
}
function Submit()
{
	if( checkform(document.frmMain) ) {
		getElementById( "Submit" ).disabled = true;
		var pForm = getElementById( "frmMain" );
		pForm.submit();
	}
	
}

// Thank you pop-up
function showConfirmation(msg)
{
	alert(msg);
}

//-->

