// Trieste Javascript Functions
// Copyright 2010 - 2011, Castellian Web Designs

// Write messages to specified area
function writetext(tag, txt)
{
        document.getElementById(tag).innerHTML=txt;
}

var now = new Date();
var year = now.getFullYear();

// Validate Form Fields
function check_form(mode)
{
	if (mode == 1)
	{
		var elem = ['email','fname','lname'];
		var fnames = ['Email Address','First Name','Last Name'];
	}

	if (mode == 2)
    {
        var elem = ['email','fname','lname','address','city',
                'state','zip','country'];
        var fnames = ['Email Address','First Name','Last Name',
				'Street Address','City','State','Zip Code',
				'Country'];
    }

	for (var i=0; i<elem.length; i++)
	{
		var x=document.forms["myform"][elem[i]];
		if (x.value==null || x.value=="")
		{
			alert("Please enter your "+fnames[i]);
			x.focus();
			return false;
		}
	}

	var valid = /^[\w\-\.\+]+\@[a-zA-Z0-9\.\-]+\.[a-zA-Z0-9]{2,4}$/;
	var x = document.forms["myform"]["email"];

	if (!x.value.match(valid))
	{
		alert("Please enter a valid email address");
		x.focus();
		return false;
	}
}

// Print Coupon Function
function print_coupon(printThis) {
  var win = window.open();
  self.focus();
  win.document.open();
  win.document.write('<'+'html'+'><'+'body'+'>');
  win.document.write(printThis);
  win.document.write('<'+'/body'+'><'+'/html'+'>');
  win.document.close();
  win.print();
  win.close();
}
