// www.happythreads.ie

// Take in the page number to display.
// Hides all other pages and shows this one.
function showpage(pagenumber)
{
	// Hide them all.
	// Work off the assumption that there are not going to be more than 20 pages of products!
	var x = 0;
	while(x < 20)
	{
		try
		{
			document.getElementById('productpage' + x).style.display = 'none';
		} catch (err) { }
		x = x + 1;
	}
	document.getElementById('productpage' + pagenumber).style.display = 'block';
}

// Justin, Used in the custom embroidry page...
function copyForm(formid)
{
	// We know the form id, so we simply reset EVERY element on the page to the attributes of this form!
	var myFields = new Array();
	myFields[0] = document.getElementById('custom_fontselect_' + formid);
	myFields[1] = document.getElementById('custom_threadcolourselect_' + formid);
	myFields[2] = document.getElementById('custom_location_' + formid);
	myFields[3] = document.getElementById('custom_text1_' + formid);
	myFields[4] = document.getElementById('custom_text2_' + formid);
	myFields[5] = document.getElementById('custom_logo_' + formid);
	myFields[6] = document.getElementById('custom_logolocation_' + formid);
	myFields[7] = document.getElementById('custom_logoandtext_' + formid);
	
	// We now have a list of values to default out form elements to.
	var elem = document.getElementById('custom_form').elements;
	var str = '';
	var myRegExp = new RegExp("custom_fontselect|custom_threadcolourselect|custom_location|custom_text1|custom_text2|custom_logo_|custom_logolocation_|custom_logoandtext_");
	var terminateRegExp = new RegExp("custom_logoandtext");
	var counter = 0;
	for(var i = 0; i < elem.length; i++)
	{
		// Do a string match on the name, if we find it set the value, thus copying the form fields!
		// This sets the font...
		var matchPos1 = elem[i].name.search(myRegExp);
		if(matchPos1 != -1)
		{
			var temp = myFields[counter];
			var matchPos2 = temp.name.search(terminateRegExp);
			elem[i].value = temp.value;
			if(matchPos2 != -1)
			{
				counter = 0;
			} else 
			{
				counter++;
			}
		}
	}
}

// Justin, Used in the custom embroidry page...
function copyForm_new(formid)
{
	// We know the form id, so we simply reset EVERY element on the page to the attributes of this form!
	var myFields = new Array();
	myFields[0] = document.getElementById('custom_fontselect_' + formid);
	myFields[1] = document.getElementById('custom_threadcolourselect_' + formid);
	myFields[2] = document.getElementById('custom_location_' + formid);
	myFields[3] = document.getElementById('custom_text1_' + formid);
	myFields[4] = document.getElementById('custom_text2_' + formid);
	// Justin - 19/08/2009, adding in a new field.
	myFields[5] = document.getElementById('custom_logo_' + formid);
	myFields[6] = document.getElementById('custom_ownlogo_des_' + formid);
	myFields[7] = document.getElementById('custom_logolocation_' + formid);
	myFields[8] = document.getElementById('custom_logoandtext_' + formid);
	
	// We now have a list of values to default out form elements to.
	var elem = document.getElementById('custom_form').elements;
	var str = '';
	var myRegExp = new RegExp("custom_fontselect|custom_threadcolourselect|custom_location|custom_text1|custom_text2|custom_logo_|custom_ownlogo_des|custom_logolocation_|custom_logoandtext_");
	var terminateRegExp = new RegExp("custom_logoandtext");
	var counter = 0;
	for(var i = 0; i < elem.length; i++)
	{
		// Do a string match on the name, if we find it set the value, thus copying the form fields!
		// This sets the font...
		var matchPos1 = elem[i].name.search(myRegExp);
		if(matchPos1 != -1)
		{
			var temp = myFields[counter];
			var matchPos2 = temp.name.search(terminateRegExp);
			elem[i].value = temp.value;
			if(matchPos2 != -1)
			{
				counter = 0;
			} else 
			{
				counter++;
			}
		}
	}
}
