function promoCodeValidation (frm, type)
{
    document.getElementById('promo_code_error').innerHTML = "";
    var err = "";
	var startdate,expirationdate,lastusabledate,evaporationdate,duryear,durmonth,durday;
    var winner = document.getElementById('promotional_code[winner]').value;

    for (var i = 0; i < frm.elements.length; i++) {
		var txt = "";
		if (frm[i].name == "promotional_code[promo_code]") txt = "Promo code";
		if (frm[i].name == "promotional_code[date_of_inception]") {
			txt = "Start date";
			startdate = frm[i].value;
		}
		if (frm[i].name == "promotional_code[price]") txt = "Price";
		if (winner == "duration") {
		  if (frm[i].name == "promotional_code[duration(1i)]") {
			txt = "Duration - years";
			duryear = frm[i].value;
		  }
		  if (frm[i].name == "promotional_code[duration(2i)]") {
			txt = "Duration - months";
			durmonth = frm[i].value;
		  }
		  if (frm[i].name == "promotional_code[duration(3i)]") {
			txt = "Duration - days";
			durday = frm[i].value;
		  }
		}
		if (winner == "expiry") {
		  if (frm[i].name == "promotional_code[expiry_date]") {
			txt = "Expiration date";
			expirationdate = frm[i].value;
		  }
		}
		if (frm[i].name == "promotional_code[winner]") {
			txt = "Winner";
		}
		if (frm[i].name == "promotional_code[price_on_expiry]") txt = "Price on expiry";
		if (frm[i].name == "promotional_code[last_useable_date]") {
			txt = "Last usable date";
			lastusabledate = frm[i].value
		}
		if (frm[i].name == "promotional_code[evaporation_date]") {
			txt = "Evaporation date";
			evaporationdate = frm[i].value;
		}
		if (frm[i].name == "promotional_code[affiliation]") txt = "";
		if (frm[i].name == "promotional_code[promo_deal]") txt = "Promo deal";
		if (frm[i].name == "promotional_code[promo_blurb]") txt = "Promo blurb";
        if (txt != "") {
		  err += frm[i].value == "" ? "<br/>" + txt + " cannot be blank." : "";
		}
    }

    if (err != "") {
        document.getElementById('promo_code_error').innerHTML = "<b>Before you can continue you must clear up the following errors:</b><br/>" + err;
        return false;
    }

	if (winner == "expiry") {
	  if (type == "new") {
	    var todaydate = new Date();
	    var mon = todaydate.getMonth() + 1;
	    var day = todaydate.getDay();
	    var year = todaydate.getFullYear();
	    if (mon < 10) mon = "0" + mon;
	    if (day < 10) day = "0" + day;
	    var today = mon + "/" + day + "/" + year;
	    if (!compareDates(today, startdate)) {
		  err = "<br/>Start date cannot be before today.";
	    }
	  }
	  if (!compareDates(startdate, expirationdate)) {
		err = "<br/>Expiration date cannot be before start date.";
	  }
	  if (!compareDates(expirationdate, evaporationdate)) {
		err += "<br/>Evaporation date cannot be before expiration date.";
	  }
	  if (!compareDates(startdate, lastusabledate)) {
		err += "<br/>Last usable date cannot be before start date.";
	  }
	}

    if (err != "") {
        document.getElementById('promo_code_error').innerHTML = "<b>Before you can continue you must clear up the following errors:</b><br/>" + err;
        return false;
    }

    return true;
}