var submitcount=0;
            
function resetSubmitCount()
{
    submitcount = 0;
}

function isFirstSubmit(increment)
{
    if (submitcount == 0)
    {
        if(increment)
        {
            submitcount++;
        }
    }
    else 
    {
        alert("Your message has already been sent.  Thanks!");
        return false;
    }

    return true;
}
 
function getElements(val,container)
{
	container = container||document;
	var all = container.all||container.getElementsByTagName('*');
	
	var arr = [];
	for(var k=0;k<all.length;k++)
	{
		if(all[k]&&(all[k].getAttribute('className') == val || all[k].getAttribute('class') == val))
		{
			arr[arr.length] = all[k];
		}
	}
	return arr;
}

function selectNav(page)
{
    var navElements = getElements('deselected');
    for(i=0;i<navElements.length;i++)
    {
        var text = navElements[i].innerHTML;
        
        if(text!=null&&text.indexOf(page)>0)
        {
        	var alist = navElements[i].getElementsByTagName('a');
        	Rounded(alist[0],'#cccc9a','#f6f6ee', 'small');
        	
        	var agt=navigator.userAgent.toLowerCase();
        	var is_ie     = ((agt.indexOf("msie") != -1) && (agt.indexOf("opera") == -1));
        	if(is_ie)
        	{
        		alist[0].className='current';
        	}
        	else
        	{
        		navElements[i].className='current';
        	}
        }
    }
}


function checkMaxLength(Object, MaxLen)
{
  if(Object.value.length > MaxLen)
  {
    Object.value = Object.value.substring(0, MaxLen);
    alert("Limit of "+MaxLen+" characters reached.");
  }
}

Date.parseDate = function(str, fmt) {
	var today = new Date();
	var y = 0;
	var m = -1;
	var d = 0;
	var a = str.split(/\W+/);
	var b = fmt.match(/%./g);
	var i = 0, j = 0;
	var hr = 0;
	var min = 0;
	for (i = 0; i < a.length; ++i) {
		if (!a[i])
			continue;
		switch (b[i]) {
		    case "%d":
		    case "%e":
			d = parseInt(a[i], 10);
			break;

		    case "%m":
			m = parseInt(a[i], 10) - 1;
			break;

		    case "%Y":
		    case "%y":
			y = parseInt(a[i], 10);
			(y < 100) && (y += (y > 29) ? 1900 : 2000);
			break;

		    case "%b":
		    case "%B":
			for (j = 0; j < 12; ++j) {
				if (Calendar._MN[j].substr(0, a[i].length).toLowerCase() == a[i].toLowerCase()) { m = j; break; }
			}
			break;

		    case "%H":
		    case "%I":
		    case "%k":
		    case "%l":
			hr = parseInt(a[i], 10);
			break;

		    case "%P":
		    case "%p":
			if (/pm/i.test(a[i]) && hr < 12)
				hr += 12;
			else if (/am/i.test(a[i]) && hr >= 12)
				hr -= 12;
			break;

		    case "%M":
			min = parseInt(a[i], 10);
			break;
		}
	}
	if (isNaN(y)) y = today.getFullYear();
	if (isNaN(m)) m = today.getMonth();
	if (isNaN(d)) d = today.getDate();
	if (isNaN(hr)) hr = today.getHours();
	if (isNaN(min)) min = today.getMinutes();
	if (y != 0 && m != -1 && d != 0)
		return new Date(y, m, d, hr, min, 0);
	y = 0; m = -1; d = 0;
	for (i = 0; i < a.length; ++i) {
		if (a[i].search(/[a-zA-Z]+/) != -1) {
			var t = -1;
			for (j = 0; j < 12; ++j) {
				if (Calendar._MN[j].substr(0, a[i].length).toLowerCase() == a[i].toLowerCase()) { t = j; break; }
			}
			if (t != -1) {
				if (m != -1) {
					d = m+1;
				}
				m = t;
			}
		} else if (parseInt(a[i], 10) <= 12 && m == -1) {
			m = a[i]-1;
		} else if (parseInt(a[i], 10) > 31 && y == 0) {
			y = parseInt(a[i], 10);
			(y < 100) && (y += (y > 29) ? 1900 : 2000);
		} else if (d == 0) {
			d = a[i];
		}
	}
	if (y == 0)
		y = today.getFullYear();
	if (m != -1 && d != 0)
		return new Date(y, m, d, hr, min, 0);
	return today;
};

var oldSubtract = 1000*60*60*24*14; // 14 days

function setNewNews()
{
	var newDate = new Date();
	newDate.setTime(newDate.getTime()-oldSubtract);
	var newsElements = getElements('date');
	for(i=0;i<newsElements.length;i++)
    {
    	var text = newsElements[i].innerHTML;
    	var newsDate = Date.parseDate(text, '%m/%d/%Y');
		if(newsDate.getTime()>newDate)
		{
			newsElements[i].className='newNews';
		}
    }
	
}
