function highlight(x) {
	x.parentNode.parentNode.parentNode.style.backgroundColor = "transparent";
	x.parentNode.parentNode.parentNode.parentNode.style.backgroundColor = "#C0FFC0";
}

function unhighlight(x) {
	if( x.parentNode.parentNode.parentNode.className == "parent" ) { x.parentNode.parentNode.parentNode.style.backgroundColor = "#EFEFEF"; }
	x.parentNode.parentNode.parentNode.parentNode.style.backgroundColor = "";
}

function addRow(x) {
	if( MSIE == 1 ) { a =  x.parentNode.previousSibling.children[0]; }
	else { a = x.parentNode.previousElementSibling.children[0]; }
	// Identify number of rows with items in the table above
	i = 0;
	for( j = 0; i == 0; j = j + 1 ) {
		if( a.children[j] == null ) {
			i = j - 1;
			break;
		}
	}
	tr = a.children[i].cloneNode(true);
	j = 0;
	// Format the new row
	while( tr.children[j] != null ) {
		c = parseInt( tr.children[j].children[0].id.match( /[0-9]/ ) );
		if ( tr.children[j].children[0].style.visibility == "hidden" ) { tr.children[j].children[0].style.visibility = "visible" }
		else if( tr.children[j].children[0].type == "checkbox" ) { tr.children[j].children[0].checked = false; }
		else if ( /mult/.test( tr.children[j].children[0].id ) ) { tr.children[j].children[0].value = "1"; }
		else { tr.children[j].children[0].value = ""; }
		tr.children[j].children[0].name = tr.children[j].children[0].name.replace( /[0-9]+/, i );
		tr.children[j].children[0].id = tr.children[j].children[0].id.replace( /[0-9]+/, i );
		j = j + 1;
	}
	tr.id = tr.id.replace( /[0-9]+/, i );
	a.appendChild(tr);
}

function removeRow(x) {
	a = x.parentNode.parentNode.id.replace( /[0-9]/g, "" );
	b = parseInt( x.parentNode.parentNode.id.replace( /[^0-9]/g, "" ) );
	// Now: a = row name without number; b = row number
	x.parentNode.parentNode.parentNode.removeChild(x.parentNode.parentNode);
	i = b + 1;
	// Change name/id of following form elements
	while( document.getElementById(a + i) ) {
		c = parseInt( document.getElementById(a + i).children[0].children[0].id.match( /[0-9]/ ) );
		document.getElementById(a + i).children[0].children[0].name = document.getElementById(a + i).children[0].children[0].name.replace( /[0-9]/, c - 1 );
		document.getElementById(a + i).children[0].children[0].id = document.getElementById(a + i).children[0].children[0].id.replace( /[0-9]/, c - 1 );
		document.getElementById(a + i).id = a + (i - 1);
		i = i + 1;
	}
}

function validateForm() {
	j = 0;
	while( document.forms[0].elements[j] ) {
		x = document.forms[0].elements[j];
		if ( x.type == "checkbox" ) {
			j = j + 1;
			continue;
		}
		if ( x.value == "" ) {
			document.getElementById("completeform").style.visibility = "visible";
			x.focus();
			return false;
		}
		if( x.id == "email" && !/^[A-Za-z0-9]+(\.?[A-Za-z0-9-_]+)*@[A-Za-z0-9]+(-?[A-Za-z0-9]+)*\.[A-Za-z]{1}(\.?[A-Za-z]{1}){1,4}$/.test(x.value) ) {
			document.getElementById("completeform").style.visibility = "visible";
			x.focus();
			return false;
		}
		if( x.id == "phone" && x.value.replace( /[^0-9]/g , "" ).length != 10 ) {
			document.getElementById("completeform").style.visibility = "visible";
			x.focus();
			return false;
		}
		if ( /price/.test( x.id ) && !/^([0-9]*\.*[0-9]*)+$/.test ( x.value ) ) {
			document.getElementById("completeform").style.visibility = "visible";
			x.focus();
			return false;
		}
		j = j + 1;
	}
}

