

function initPage() {
	
	initNewsHeadlines();
}

//=================================================================================

function initNewsHeadlines() {
	
	if (num_headlines > 0) {
		// get the <h2> node
		h2_news_headline_node = document.getElementById(h2_news_headline_id);
		// remove any nodes the h2 has
		while(h2_news_headline_node.childNodes[0]) {
			h2_news_headline_node.removeChild( h2_news_headline_node.childNodes[0] );
		}
		
		var text_node = document.createTextNode( news_headlines[0]['newsHeadline'] );	// create a text node
		var a_node = document.createElement('a');	// create a <a> node
		a_node.onmouseover = stopNewsHeadlines;	// set the <a> node mouse over
		a_node.onmouseout = restartNewsHeadlines;	// set the <a> node mouse out
		a_node.href = news_headlines[0]['newsID'];	// set the href of the <a> node
		a_node.id = news_headline_link_id;	// set the id of the <a> node. this allows the css definitions to apply to the <a>
		a_node.appendChild(text_node);		// add the text node to the <a>
		h2_news_headline_node.appendChild(a_node);	// add the <a> node to the <h2>
		news_headline_link_node = h2_news_headline_node.firstChild;	// get a reference to the <a> node
		
		
		
		startNewsHeadlines();	
	}
	
}

//=================================================================================

function updateHeadline() {
	if ( (current_index + 1) < num_headlines) {
		current_index++;
	} else {
		current_index = 0;
	}
	
	updateHeadlineText();
	updateHeadlineLink();	
}

//=================================================================================

function updateHeadlineText() {
	news_headline_link_node.firstChild.nodeValue = news_headlines[current_index]['newsHeadline'];
}

//=================================================================================

function updateHeadlineLink() {
	news_headline_link_node.href = news_headlines[current_index]['newsID'];
}

//=================================================================================

function restartNewsHeadlines() {
	updateHeadline();	// this causes an immediate change
	startNewsHeadlines();	// set the repeating changes
}

//=================================================================================

function startNewsHeadlines() {
	headline_interval = setInterval("updateHeadline()", delay);	// change the news headlines continuously
}

//=================================================================================

function stopNewsHeadlines() {
	clearInterval(headline_interval);	// stop changing the headlines
}

//=================================================================================

function setLanguage(element, lang) {
	var the_form = element.form;
	//alert(element + ' ' + the_form + ' ' + lang);
	the_form.elements['select_language'].value = lang;
	the_form.submit();
}

//=================================================================================

function uvCoatingCalc(the_form, factor) {
	var is_valid = true;
	
	// call our standard form validation
	is_valid = validateForm(the_form);
	
	if (is_valid) {
		
		var required_fields_arr = new Array();
		// get the required fields for the form
		required_fields_arr = the_form['required_fields'].value.split(',');
		// how many are there
		var limit = required_fields_arr.length;
		var sum = 1;
		// loop through the required fields
		for (var x=0; x<limit; x++) {	
			// get the field name		
			var element_name = required_fields_arr[x];
			// get the field value
			var val = the_form.elements[element_name].value;
			// multiply the value
			sum *= val;
		}
		// multiply the sum by the factor for this calculation
		sum *= factor;
		
		// place the value in the total text field for the calculation
		the_form.elements['total'].value = formatNumber(sum);
	}
	
	
}

//=================================================================================

function tspSearch_resetDateSubmitted() {
	
	var form_node = document.getElementById('tspSearchForm');
	
	var menu_name_arr = new Array(
		'minmonth',
		'minday',
		'minyear',
		'maxmonth',
		'maxday',
		'maxyear'
	);
	
	var limit = menu_name_arr.length;
	for (var x=0; x<limit; x++) {
		var element = form_node.elements[ menu_name_arr[x] ];
		switch (element.type) {
			case 'select-one':
				element.selectedIndex = 0;
				break;
			case 'text':
				element.value = '';
				break;
		}
		
	}
}

//=================================================================================





//==================================================
// BEGIN FORM VALIDATION FUNCTIONS
//==================================================
function validateForm_IntranetSignUp(the_form) {
	
	var is_valid = true;	// we assume it is a valid form
	// custom code can be added to this fucntion if form specific actions are required
	
	// call the standard form validation function
	is_valid = validateForm(the_form);
	
	return is_valid;

}


//==================================================
// END FORM VALIDATION FUNCTIONS
//==================================================
