// iconF is Feature1 on the form. This is the number of the icon from the database.
// "00" is no icon, a blank value is also no icon selected.

/*
	woIcon == without Icon
	wIcon == with Icon
*/
var lblCharLen_2x15_woIcon = new Array( 20, 20, 20 )
var lblCharLen_2x15_wIcon = new Array( 17, 20, 20 )

var lblCharLen_15d_woIcon = new Array( 17, 17 )
var lblCharLen_15d_wIcon = new Array( 17, 17 )

var lblCharLen_2x5_woIcon = new Array( 26, 26 )
var lblCharLen_2x5_wIcon = new Array( 24, 24 )


var lblCharLen_275x625_woIcon = new Array()
	lblCharLen_275x625_woIcon = 24
var lblCharLen_275x625_wIcon = new Array()
	lblCharLen_275x625_wIcon = 17
	
var lblCharLen_2x3125_woIcon = new Array()
	lblCharLen_2x3125_woIcon[0] = 17;
var lblCharLen_2x3125_wIcon = new Array()
	lblCharLen_2x3125_wIcon[0] = 14;

var lblCharLen_1d_woIcon = new Array( 8, 8 )
//	lblCharLen_1d_woIcon[0] = 8
var lblCharLen_1d_wIcon = new Array( 8, 8 )
//	lblCharLen_1d_wIcon[0] = 8;

var lblCharLen_allergy_woIcon = new Array()
	lblCharLen_allergy_woIcon[0] = 32

var lblCharLen_allergy_wIcon = new Array()
	lblCharLen_allergy_wIcon[0] = 0;
	



function validateValuePackForm( f, useColor, useIcon, iconF, iconFV )
	{
	if( !validateShoeTagLabelForm( f, useColor, useIcon, iconF, iconFV ) )
		return false
	
	if( !validateIronOnLabelForm( f, useColor, useIcon, iconF, iconFV ) )
		return false
	if( !validateStickonComboSheetForm( f, useColor, useIcon, iconF, iconFV ) )
		return false

	if( useIcon )		
		{
		f.elements[iconFV].value =  "0";
		}
		

	return true
	}



function validateIronOnLabelForm( f, useColor, useIcon, iconF, iconFV )
	{
	var name = "2\" wide x .5\" high"
	var formName = "label_ironon_" 
	var wIconLen = lblCharLen_2x5_wIcon
	var woIconLen = lblCharLen_2x5_woIcon
	// set minLen to -1 if there is no requirement for this field, no min char.
	var minLen = new Array( 0, -1 )
	var iconSelected = false;

	if( useColor )
		if( !validateColorSelector( f )	)
			return false

	if( useIcon )
		iconSelected = calcIconPrice( f, iconF, iconFV, useColor )

	for( var i = 0; i < wIconLen.length; i++ )
		{
		if( iconSelected )
			len = wIconLen[i]
				else
					len = woIconLen[i]		
	
		if( !validateLen( f, name, i+1, formName+(i+1), len, minLen[i], iconSelected )  )
			return false;
	
		}	
	
	return true;
	}

	
	
function validateAllergyAlertLabelForm( f, useColor )
	{
	if( useColor )
		if( !validateColorSelector( f )	)
			return false


	if( !validateLen( f, "Allergy Alert", 1, "allergy_alert_1", lblCharLen_allergy_woIcon[0], 0, false ) )
		return false;

	return true;
	}





function validateStickonLabelForm( f, useColor, useIcon, iconF, iconFV )
	{
	if( useColor )
		if( !validateColorSelector( f )	)
			return false

	var iconSelected = false;
	if( useIcon )
		iconSelected = calcIconPriceSelectedIndex( f, iconF, iconFV )
		
	if( !validateForm_label_15d( f, iconSelected ) )
		return false;


	
	return true;
	}

function validateShoeTagLabelForm( f, useColor, useIcon, iconF, iconFV )
	{
	if( useColor )
		if( !validateColorSelector( f )	)
			return false

	var iconSelected = false;
	if( useIcon )
		iconSelected = calcIconPriceSelectedIndex( f, iconF, iconFV )
		
	var name = "Shoe-tag 1.5 in diameter"
	var formName = "label_shoetag_" 
	var wIconLen = lblCharLen_15d_wIcon
	var woIconLen = lblCharLen_15d_woIcon
	// set minLen to -1 if there is no requirement for this field, no min char.
	var minLen = new Array( 0, -1 )
		
	for( var i = 0; i < wIconLen.length; i++ )
		{
		if( iconSelected )
			len = wIconLen[i]
				else
					len = woIconLen[i]		
	
		if( !validateLen( f, name, i+1, formName+(i+1), len, minLen[i], iconSelected )  )
			return false;
		}

	return true;
	}




function validateStickonComboSheetForm( f, useColor, useIcon, iconF, iconFV )
	{
	if( useColor )
		if( !validateColorSelector( f )	)
			return false


	var iconSelected = false;
	if( useIcon )
		iconSelected = calcIconPriceSelectedIndex( f, iconF, iconFV )

	if( !validateStickonComboSheetForm_label_2x15( f, iconSelected ) )
		return false;

	if( !validateForm_label_15d( f, iconSelected ) )
		return false;

	if( !validateStickonComboSheetForm_label_275x625( f, iconSelected ) )
		return false;

	if( !validateStickonComboSheetForm_label_2x3125( f, iconSelected ) )
		return false;

	if( !validateStickonComboSheetForm_label_1d( f, iconSelected ) )
		return false;

	
	return true;
	}

function validateStickonComboSheetForm_label_2x15( f, hasIcon )
	{
	
	var name = "2\" wide x 1.5\" high"
	var formName = "label_2x15_" 
	var wIconLen = lblCharLen_2x15_wIcon
	var woIconLen = lblCharLen_2x15_woIcon
	// set minLen to -1 if there is no requirement for this field, no min char.
	var minLen = new Array( 0, -1, -1 )
		
	if( !validateStickonComboSheetForm_label( f, hasIcon, name, formName, wIconLen, woIconLen, minLen ) )
		return false;

	return true;
	}



function validateForm_label_15d( f, hasIcon )
	{
	
	var name = "1.5\" in diameter"
	var formName = "label_15d_" 
	var wIconLen = lblCharLen_15d_wIcon
	var woIconLen = lblCharLen_15d_woIcon
	// set minLen to -1 if there is no requirement for this field, no min char.
	var minLen = new Array( 0, -1 )
		
	if( !validateStickonComboSheetForm_label( f, hasIcon, name, formName, wIconLen, woIconLen, minLen ) )
		return false;

	return true;
	}


function validateStickonComboSheetForm_label_275x625( f, hasIcon )
	{
	var name = "2.75\" wide x .625\" high"
	var formName = "label_275x625_" 
	var wIconLen = lblCharLen_275x625_wIcon
	var woIconLen = lblCharLen_275x625_woIcon
	// set minLen to -1 if there is no requirement for this field, no min char.
	var minLen = new Array()
		minLen[0] = 0
		
	if( !validateStickonComboSheetForm_label( f, hasIcon, name, formName, wIconLen, woIconLen, minLen ) )
		return false;

	return true;
	}
		


function validateStickonComboSheetForm_label_2x3125( f, hasIcon )
	{
	var name = "2\" wide x .3125\" high"
	var formName = "label_2x3125_" 
	var wIconLen = lblCharLen_2x3125_wIcon
	var woIconLen = lblCharLen_2x3125_woIcon
	// set minLen to -1 if there is no requirement for this field, no min char.
	var minLen = new Array()
		minLen[0] = 0
		
	if( !validateStickonComboSheetForm_label( f, hasIcon, name, formName, wIconLen, woIconLen, minLen ) )
		return false;

	return true;
	}



function validateStickonComboSheetForm_label_1d( f, hasIcon )
	{
	var name = "1\" in diameter"
	var formName = "label_1d_" 
	var wIconLen = lblCharLen_1d_wIcon
	var woIconLen = lblCharLen_1d_woIcon
	// set minLen to -1 if there is no requirement for this field, no min char.
	var minLen = new Array( 0, -1 )
		
	if( !validateStickonComboSheetForm_label( f, hasIcon, name, formName, wIconLen, woIconLen, minLen ) )
		return false;

	return true;
	}
	
	
	
function validateStickonComboSheetForm_label( f, hasIcon, name, formName, wIconLen, woIconLen, minLen )
	{
	var len = 0;

	for( var i = 0; i < wIconLen.length; i++ )
		{
		if( hasIcon )
			len = wIconLen[i]
				else
					len = woIconLen[i]		
	
		if( !validateLen( f, name, i+1, formName+(i+1), len, minLen[i], hasIcon )  )
			return false;
	
		}	
	
	return true;
	}



	
function validateLen( f, name, line, label, len, minLen, hasIcon )
	{
	var errMsg

	if( !isPopulated( f.elements[label], name, line, minLen ) )
		return false
	
	if( f.elements[label].value.length > len )
		{
		num = f.elements[label].value.length - len

		errMsg = "You have to many characters in the label text  \"" + f.elements[label].value + "\""
		errMsg += "\n\nLabel Name: " + name + "\nLine: " + line 
		if( hasIcon )
			errMsg += "\n\nThe Maximum Length is " + len + " characters when SELECTING AN ICON."
				else
					errMsg += "\n\nThe Maximum Length is " + len + " characters."
		errMsg += "\nYou have " + num + " extra characters and\/or spaces."
		alert( errMsg ) 

		f.elements[label].select()
		f.elements[label].focus()		
		return false;
		}

	
	return true
	}	
	
// set minLen to -1 if there is no requirement for this field, no min char.
function isPopulated( field, name, line, minLen )
	{
	if( field.value.length <= minLen )
		{
		alert( "This field requires more than " + minLen + " characters, you must input a value in:\n\nLabel Name: " + name + "\nLine: " + line ) 
		field.focus();
		return false;
		}
	return true
	}
// -----------------------------------------------------------------






function validateColorSelector( f )	
	{
	if( f.Feature2.value == "" )
		{
		alert( "You must select a color" ) 
		return false;
		}
	return true;	
	}
	
	
function calcIconPrice( f, iconFeature, iconFeatureValue, useColor )
	{
	var num = 0	
	
/*
	for( var i = 0; i < f.productid.length; i++ )
		{
		if( f.productid[i].checked )
		
			if( useColor )
				{
				num = i + 1
				}
				else
					{
					// we increment because this because bw has a 50 quantity and that is valued at 1 
					// and a 100 value wich is also valued at 1 on black and white
					if( i == 0 )
						num = 1;
							else
								num = i;
					}			
		}			
	
*/	
	
	f.labelIcon.value = f.elements[iconFeature].value
	if( f.elements[iconFeature].value != "00" )
		{
//		f.elements[iconFeatureValue].value =  num;
		f.elements[iconFeatureValue].value = "1";	
		if( f.elements[iconFeature].value != "" )
			return true
		}
		else
			f.elements[iconFeatureValue].value =  "0";

	return false
	}

function calcIconPriceSelectedIndex( f, iconFeature, iconFeatureValue )
	{
	f.labelIcon.value = f.elements[iconFeature].value
	if( f.elements[iconFeature].value != "00" )
		{
//		f.elements[iconFeatureValue].value =  f.productid.options[f.productid.selectedIndex].text;
		f.elements[iconFeatureValue].value = "1";
		if( f.elements[iconFeature].value != "" )
			return true
		}
		else
			f.elements[iconFeatureValue].value =  "0";

	return false
	}

	
		