
function validate_card_address_form(num_cards)
{
	var errors = new Array();


	var required = new Array("","giftcard_ship_first_name_","giftcard_ship_last_name_","giftcard_ship_address1_","giftcard_ship_city_","giftcard_ship_state_", "giftcard_ship_zip_","giftcard_ship_phone_");
	

	var required_message = new Array("","Please enter a first name for address # ",
									 "Please enter a last name for address # ",
									 "Please enter a shipping address for address # ",
									 "Please enter a city for address # ",
									 "Please enter a state for address # ",
									 "Please enter a zip code for address # ",
									 "Please enter a phone number for address # ");
						

	var k = 0; //index errors
	var req;
	for(i = 1; i<=num_cards; i++)
	{
		if(document.getElementById("address_"+i+"_check").checked == false) //if the checkbox for that address is clicked
		{
			for(j=1; j < required.length; j++)
			{
				var id = required[j] + i;
				
				req = document.getElementById(id);
				
				if(Trim(req.value) == "")
				{
					errors[k] = required_message[j] + i;
					k++;
				}
			}
			
			/*
			if(Trim(document.getElementById('giftcard_v_email_' + i).value) != Trim(document.getElementById('giftcard_email_' + i).value))
			{
				errors[k] = "Email addresses do not match for address #" + i;
				k++;
			}*/
		}
		
		
	}
	
	//alert(errors.length);

	if(errors.length != 0)
	{
		var err = "";	
		for(i=0; i<errors.length ; i++)
		{
			err += (errors[i] + "\n");

		}
		alert(err);
		return false;
	}

	return true;
	
	
}


function show_address_fields(num)
{
	var id = "card_address_" + num;
	document.getElementById(id).style.display = (document.getElementById(id).style.display == "block") ? "none": "block";
}


function textCounter(field,cntfield,maxlimit)
{
	if (field.value.length > maxlimit) // if too long...trim it!
	{
		field.value = field.value.substring(0, maxlimit);
	}
	// otherwise, update 'characters left' counter
	else
	{
		cntfield.value = maxlimit - field.value.length;
	}
}



function Trim(STRING)
{
	STRING = LTrim(STRING);
	return RTrim(STRING);
}

function RTrim(STRING)
{
	while(STRING.charAt((STRING.length -1))==" ")
	{
		STRING = STRING.substring(0,STRING.length-1);
	}
	return STRING;
}


function LTrim(STRING)
{
	while(STRING.charAt(0)==" ")
	{
		STRING = STRING.replace(STRING.charAt(0),"");
	}
	return STRING;
}

function OpenStorePop(section)
{
    window.open(section,'store_sub','height=600,width=950,scrollbars=yes,resizable');
}
