startList = function() {

	if (document.all&&document.getElementById) {

		navRoot = document.getElementById("nav");

		for (i=0; i<navRoot.childNodes.length; i++) {

			node = navRoot.childNodes[i];

			if (node.nodeName=="LI") {

				node.onmouseover=function() {

					this.className+=" over";

				}

				node.onmouseout=function() {

					this.className=this.className.replace(" over", "");

				}

			}

		}

	}

}

skyscraperCheck = function() {

	var bodyWidth;
	var containerWidth;

	bodyWidth      = document.body.offsetWidth;
	containerWidth = 717;

	if ((bodyWidth - containerWidth) / 2 > 120) {

		document.getElementById('skyscraper').style.display = 'block';
		document.getElementById('skyscraper').style.top     = '10px';
		document.getElementById('skyscraper').style.left    = ((bodyWidth - containerWidth) / 2 - 120) / 2 + 'px';

		document.getElementById('skyscraper2').style.display  = 'block';
		document.getElementById('skyscraper2').style.top      = '10px';
		document.getElementById('skyscraper2').style.right    = ((bodyWidth - containerWidth) / 2 - 120) / 2 + 'px';

	} else {

		document.getElementById('skyscraper').style.display  = 'none';
		document.getElementById('skyscraper2').style.display = 'none';

	}

}

function prepFormFields() {

	var htmlElements = Array('select', 'input', 'textarea');
	var htmlTempArray;
	var strTemp;
	
	for (var i = 0; i < htmlElements.length; i++) {

		htmlTempArray = document.getElementsByTagName(htmlElements[i]);

		for (var j = 0; j < htmlTempArray.length; j++) {

			if (navigator.userAgent.indexOf('MSIE 6') > 0) {

				if (htmlTempArray[j].getAttribute('type') == 'submit') {

					htmlTempArray[j].style.marginLeft = '82px';

				}

			}

			htmlTempArray[j].onfocus = function() {

				strTemp = this.className;
	
				if (strTemp != "radio" && this.getAttribute("name") != "id") {

					this.className = "activeElement";

				} else if (strTemp == "radio") {

					name  = this.getAttribute("name");
					label = getLabelForId(name);

					label.className = "success";

				}

			}

			htmlTempArray[j].onblur = function() {

				this.className = strTemp;

			}

			htmlTempArray[j].onkeyup = function() {

				if (strTemp == "required") {

					if (isNotEmpty(this)) {

						name  = this.getAttribute("name");
						label = getLabelForId(name);

						label.className = "success";

					} else {

						name  = this.getAttribute("name");
						label = getLabelForId(name);

						label.className = "failure";

					}

				}
				
				if (strTemp == "email") {

					if (mailCheck(this.value)) {

						name  = this.getAttribute("name");
						label = getLabelForId(name);

						label.className = "success";

					} else {

						name  = this.getAttribute("name");
						label = getLabelForId(name);

						label.className = "failure";

					}

				}

			}

		}

	}

}

function getLabelForId(id) {

	var label, labels = document.getElementsByTagName('label');
	
	for (var i = 0; (label = labels[i]); i++) {
	
		if (label.htmlFor == id) {

			return label;

		}
	
	}

	return false;

}


function isNotEmpty(elem) {

	var str = elem.value;
	
	if (str.length == 0) {

		return false;

	} else {
		
		return true;

	}

}

function mailCheck(elem) {

	var email = elem;

	var emailRegxp = /^[\w-]+(\.[\w-]+)*@[\w-]+(\.[\w-]+)*\.\w{2,8}$/;

	if (emailRegxp.test(email) != true) {

		return false;

	} else {

		return true;

	}

}
 
function validate(form) {

	var attrVal, attrReg, attrEq, attrFail, strTemp, formfield, name, label, radio_checked, invalid;

	for (var i = 0; i < form.length; i++) {

		attrVal   = form[i].className;
		
		switch (attrVal) {

			case 'required' :

			if (!isNotEmpty(form[i])) {

				formfield = document.getElementById('input_' + i);

				name      = formfield.getAttribute('name');
				label     = getLabelForId(name);

				label.className = "failure";

				if (!invalid) {

					document.getElementById('form_message').style.display  = 'none';
					document.getElementById('form_error').style.display    = 'block';
					document.getElementById('form_error').style.color      = '#FF0000';
					document.getElementById('form_error').style.fontWeight = 'bold';

					invalid = true;

				}

			} else {

				formfield = document.getElementById('input_' + i);
				name      = formfield.getAttribute('name');
				label     = getLabelForId(name);

				label.className = "success";

				if (!invalid) {

					invalid = false;

				}

			}

			break;
			
			case 'email' :

			if (!mailCheck(form[i].value)) {

				formfield = document.getElementById('input_' + i);
				name      = formfield.getAttribute('name');
				label     = getLabelForId(name);

				label.className = "failure";

				if (!invalid) {

					document.getElementById('form_message').style.display = 'none';
					document.getElementById('form_error').style.display   = 'block';
					document.getElementById('form_error').style.color     = '#FF0000';
					document.getElementById('form_error').style.fontWeight = 'bold';

					invalid = true;

				}

			} else {

				formfield = document.getElementById('input_' + i);
				name      = formfield.getAttribute('name');
				label     = getLabelForId(name);

				label.className = "success";

				if (!invalid) {

					invalid = false;

				}

			}

			break;

			case 'radio' :

			formfield = document.getElementById('input_' + i);
			name      = formfield.getAttribute('name');
			label     = getLabelForId(name);

			for (k = 0; k < document.forms[0].elements[name].length; k++) {

				if (document.forms[0].elements[name][k].checked) {

					radio_checked = true;

				}

			}

			if (!radio_checked) {

				label.className = "failure";

				document.getElementById('form_message').style.display = 'none';
				document.getElementById('form_error').style.display   = 'block';
				document.getElementById('form_error').style.color     = '#FF0000';
				document.getElementById('form_error').style.fontWeight = 'bold';

				invalid = true;
	
			} else {

				label.className = "success";

				if (!invalid) {

					invalid = false;

				}

			}

			radio_checked = null;
			
			break;

		}
   
	}

	if (!invalid) {

		return true;		

	} else {

		return false;
		
	}

}

function bookmark(title, url) {

	if (window.sidebar) {

		window.sidebar.addPanel(title, url, '');

	}

	else if (window.external) {

		window.external.AddFavorite(url, title);

	}

	else if (window.opera && window.print) {

		var bookmark_element = document.createElement('a');
		bookmark_element.setAttribute('rel', 'sidebar');
		bookmark_element.setAttribute('href', url);
		bookmark_element.setAttribute('title', title);
		bookmark_element.click();

	}

}

window.onload = function() {

	startList()
	prepFormFields();

}
