function showFontsData()
{
	var theForm = document.forms['product_form'];
	var num_fonts = 0;
	var elms ='';
	for (var j=0; j<theForm.length; j++){
			if ((theForm[j].name.indexOf('font_')>=0)&&(theForm[j].name.indexOf(':')>0)&&(theForm[j].checked))
			{
				num_fonts ++;
				elms += theForm[j].name+'='+theForm[j].value+'&';
			}
			if ((theForm[j].name.indexOf('product')>=0)&&(theForm[j].name.indexOf(':')>0) && theForm[j].value >0)
			{
				elms += theForm[j].name+'='+theForm[j].value+'&';
			}
		}
	if (num_fonts == 0)
	{
		document.getElementById('fonts_data').style.display = 'none';
	}
	else
	{
		if (document.getElementById('num_computers').value == 0) document.getElementById('num_computers').value = 1;
		if (document.getElementById('discount_code') != null) 
		{
			discount_code = document.getElementById('discount_code').value;
		}
		do_ajax_request("/ajax/ajax_get_price.php",elms+'num_computers='+document.getElementById('num_computers').value+'&c='+discount_code,fillPriceDiv);
		document.getElementById('fonts_data').style.display = 'block';
	}
}

function fillPriceDiv(res)
{
	if (res.responseText.indexOf('Moved Permanently') == -1)
		document.getElementById('fonts_price').innerHTML = res.responseText;
}

function showHolidayMessage()
{
	var theForm = document.forms['product_form'];
	var state = false;
	
	if (document.getElementById('holiday_notice') != null)
	{
		for (var j=0;j<theForm.length;j++)
		{
			var i = theForm[j].name;
				if (i.indexOf("product")>-1)
				{
				 	if (parseInt(theForm[i].value)>0) 
				 	{
				 		state = true;
				 	}
				}
		}
		if (state)
		{
			document.getElementById('holiday_notice').style.display = 'block';
		}
		else
		{
			document.getElementById('holiday_notice').style.display = 'none';
		}
	}
}

function checkOrderForm(theForm, required)
{
	document.getElementById('error_number').style.display = "none";
	document.getElementById('error_license').style.display = "none";
	document.getElementById('error_selection').style.display = "none";
	document.getElementById('error_more_fonts').style.display = "none";
	document.getElementById('error_different_formats').style.display = "none";
	
	if (theForm['login'] != null && theForm['email'] != null)
	{
		document.getElementById('error_customer').style.display = "none";
		document.getElementById('error_email').style.display = "none";
		document.getElementById('error_email_wrong').style.display = "none";
	}
	
	if (theForm['l_email'] != null)
	{
		document.getElementById('error_first_name').style.display = "none";
		document.getElementById('error_last_name').style.display = "none";
		document.getElementById('error_street').style.display = "none";
		document.getElementById('error_city').style.display = "none";
		document.getElementById('error_zip').style.display = "none";
		document.getElementById('error_country').style.display = "none";
	
		if (theForm.first_name == ''){
			document.getElementById('error_first_name').style.display = "block";
			return false;
		}
	
		if (theForm.surname.value == ''){
			document.getElementById('error_last_name').style.display = "block";
			return false;
		}
	
		if (theForm.street.value == ''){
			document.getElementById('error_street').style.display = "block";
			return false;
		}
	
		if (theForm.city.value == ''){
			document.getElementById('error_city').style.display = "block";
			return false;
		}
	
		if (theForm.post_code.value == '' && theForm.country.value != 'ie'){
			document.getElementById('error_zip').style.display = "block";
			return false;
		}
	
		if (theForm.country.options[theForm.country.selectedIndex].value==''){
			document.getElementById('error_country').style.display = "block";
			return false;
		}
		
		if (theForm.country.options[theForm.country.selectedIndex].value=='us' || theForm.country.options[theForm.country.selectedIndex].value=='ca'){
			if (theForm.state.options[theForm.state.selectedIndex].value==''){
				document.getElementById('error_state').style.display = "block";
				theForm.state.focus();
				return false;
			}
		}
	}
	
	var last = 0;
	var arrFonts = new Array();
	for (j=0; j<theForm.length; j++)
	{
		if ((theForm[j].name.indexOf('font_')>=0)&&(theForm[j].name.indexOf(':')>0)&&(theForm[j].checked))
		{
			last = theForm[j].name.substring(theForm[j].name.indexOf(':')+1,theForm[j].name.length);
			if (arrFonts[last]==null) arrFonts[last]=1; else arrFonts[last]+=1;
		}
	}
	
	if (arrFonts.length>0 && (theForm['num_computers'].value=='' || theForm['num_computers'].value==0))
	{
		document.getElementById('error_number').style.display = "block";
		return false;
	}
	if (arrFonts.length>0 && theForm['num_computers'].value>200)
	{
		document.getElementById('error_more_fonts').style.display = "block";
		return false;
	}
	
	arrFonts = arrFonts.compact();
	for (var i=0; i<arrFonts.length; i++)
	{
		if (arrFonts[i]>theForm['num_computers'].value && arrFonts[i] != null && arrFonts[i] != undefined) {
			document.getElementById('error_different_formats').style.display = "block";
			return false;
		}
	}
	
	if (arrFonts.length>0 && !theForm['licence'].checked)
	{
		document.getElementById('error_license').style.display = "block";
		return false;
	}
	
	var state;
	var no_br = true;
	
	state = false;
	
	for (var j=0;j<theForm.length;j++)
	{
		var i = theForm[j].name;
			if (i.indexOf("product")>-1)
			{
			 	var id = i.substr(i.indexOf("product")+8,i.length-8);
			 	id = 'stock:' + id;
			 	if (parseInt(theForm[id].value) < parseInt(theForm[i].value))
			 	{
			 		no_br = false;
			 		alert('We only have '  + theForm[id].value + ' items on stock; please chose less than '  + theForm[id].value + '.');
			 		theForm[i].focus();
			 		break;
			 	}
			 	if (parseInt(theForm[i].value)>0) 
			 	{
			 		state = true;
			 	}
			}
	}
	
	//less 
	if (!no_br)
		return false;
		
	if (arrFonts.length == 0 && !state)
	{
		document.getElementById('error_selection').style.display = 'block';
		return false;
	}
	if (theForm['login'] != null && theForm['email'] != null)
	{
		if (theForm['login'].value=='' && theForm['email'].value == '')
		{
			document.getElementById('error_email').style.display = "block";
			return false;
		}
		
		if ((!isEmail(theForm['login'].value) && theForm['login']!='') || (!isEmail(theForm['email'].value) && theForm['email']!=''))
		{
			document.getElementById('error_email_wrong').style.display = "block";
			return false;
		}
		
		if (!theForm['customer'][0].checked && !theForm['customer'][1].checked)
		{
			document.getElementById('error_customer').style.display = "block";
			return false;
		}
	}
	return true;
}