window.onload = function() {
	document.getElementById('tednoten').onmouseover = function() {
		document.getElementById('contact').className = 'breadcrumb';
		document.getElementById('links').className = 'breadcrumb';
	}
	document.getElementById('contact').onmouseover = function() {
		document.getElementById('tednoten').className = 'breadcrumb';
		document.getElementById('links').className = 'breadcrumb';
	}
	document.getElementById('links').onmouseover = function() {
		document.getElementById('tednoten').className = 'breadcrumb';
		document.getElementById('contact').className = 'breadcrumb';
	}
	document.getElementById('tednoten').onmouseout = function() {
		document.getElementById('contact').className = '';
		document.getElementById('links').className = '';
	}
	document.getElementById('contact').onmouseout = function() {
		document.getElementById('tednoten').className = '';
		document.getElementById('links').className = '';
	}
	document.getElementById('links').onmouseout = function() {
		document.getElementById('tednoten').className = '';
		document.getElementById('contact').className = '';
	}
	// targets don't validate, use rel="external" instead
	var anchors = document.getElementsByTagName('A');
	for (var i = 0; i < anchors.length; i++) {
		if (anchors[i].getAttribute('rel') == 'popup') {
			anchors[i].onclick = function() { window.open(this.getAttribute('href'), '', 'scrollbars=yes, width=500, height=500'); return false; }
		}
	}
}

function setInnerHTML(element, toValue) {
	if (typeof(element.innerHTML) != 'undefined') {
		element.innerHTML = toValue;
	}
	else {
		var range = document.createRange();
		range.selectNodeContents(element);
		range.deleteContents();
		element.appendChild(range.createContextualFragment(toValue));
	}
}

function setOuterHTML(element, toValue) {
	if (typeof(element.outerHTML) != 'undefined') {
		element.outerHTML = toValue;
	}
	else {
		var range = document.createRange();
		range.setStartBefore(element);
		element.parentNode.replaceChild(range.createContextualFragment(toValue), element);
	}
}

function toggleCollapseHTML(id1, id2) {
	var span = document.getElementById(id2);
	var element = document.getElementById(id1);
	
	element.style.display == 'none' ? element.style.display = '' : element.style.display = 'none';
	element.style.display == 'none' ? setInnerHTML(span, 'add more details...') : setInnerHTML(span, 'less details...');
}

function addPhoto() {
	setOuterHTML(document.getElementById('extraPhoto'), '<span id="extraPhoto"><br /><input type="file" size="27" name="image[]" id="p2" /> <a href="javascript:removePhoto();">remove this photo...</a></span>');
}

function removePhoto() {
	setOuterHTML(document.getElementById('extraPhoto'), '<span id="extraPhoto"><a href="javascript:addPhoto();">add another photo...</a></span>');
}

function checkEntry(form) {
	
	var spans = Array('spanContinent', 'spanPhoto');
	for (var i = 0; i < spans.length; i++) {
		document.getElementById(spans[i]).style.color = '#000000';
	}
	
	if (document.getElementById('name').value == '') {
		document.getElementById('name').value = 'Anonymous';
	}
	
	if (document.getElementById('continent').options[document.getElementById('continent').selectedIndex].value == '0') {
		document.getElementById('spanContinent').style.color = 'red';
		alert('It is required to select a continent!');
		document.getElementById('continent').focus();
		return false;
	}
	
	if (document.getElementById('p1').value == '') {
		document.getElementById('spanPhoto').style.color = 'red';
		alert('It is required to select a photo to upload!');
		document.getElementById('p1').focus();
		return false;
	}
	
	var p1_array = document.getElementById('p1').value.split('.');
	if (p1_array[p1_array.length-1].toLowerCase() != 'gif' && p1_array[p1_array.length-1].toLowerCase() != 'jpg') {
		document.getElementById('spanPhoto').style.color = 'red';
		alert('Photos are allowed in either \'gif\' or \'jpg\' format!' + "\n" + 'The photo you\'re trying to upload is of the \'' + p1_array[p1_array.length-1] + '\' format!');
		document.getElementById('p1').focus();
		return false;
	}

	
	if (document.getElementById('p2')) {
		
		if (document.getElementById('p2').value == '') {
			document.getElementById('spanPhoto').style.color = 'red';
			alert('You clicked \'add another photo\' but did not select another photo to upload!');
			document.getElementById('p2').focus();
			return false;
		}
		
		else {
		
			var p2_array = document.getElementById('p2').value.split('.');
			if (p2_array[p1_array.length-1].toLowerCase() != 'gif' && p2_array[p1_array.length-1].toLowerCase() != 'jpg') {
				document.getElementById('spanPhoto').style.color = 'red';
				alert('Photos are allowed in either \'gif\' or \'jpg\' format!' + "\n" + 'The second photo you\'re trying to upload is of the \'' + p1_array[p1_array.length-1] + '\' format!');
				document.getElementById('p2').focus();
				return false;
			}
			
		}
		
	}
	
}