// JavaScript Document

// Show and Hide Sub-Navigation
function showMe(subnavi){
	document.getElementById("subnav-general").style.display="block";
	document.getElementById("subnav-countries").style.display="block";
	document.getElementById("subnav-camping").style.display="block";
	document.getElementById("subnav-accommodated").style.display="block";
	document.getElementById("subnav-prepost").style.display="block";
	
	document.getElementById("subnav-general").style.display="none";
	document.getElementById("subnav-countries").style.display="none";
	document.getElementById("subnav-camping").style.display="none";
	document.getElementById("subnav-accommodated").style.display="none";
	document.getElementById("subnav-prepost").style.display="none";
	
	document.getElementById(subnavi).style.display="block";
	
}

function hideMe(subnavi){
	document.getElementById(subnavi).style.display="none";
	
}


// Show and Hide Images n the content
function showmenow(element){ document.getElementById(element).style.display="inline"; }
function hidemenow(element){ document.getElementById(element).style.display="none"; }

/*///////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
// JS-LIVE-CHECK 1.0 (if every field of an InputForm is valid) / Flatspin Web Solutions / 2006 / by Daniel Benkenstein //
>>>>>>>>> Fill in the CSS-Classes, which you want to use <<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<*/ 
class_normal= 'inp_normal'; 
class_selected= 'inp_normal inp_selected';
class_valid= 'inp_normal inp_valid';
class_invalid= 'inp_normal inp_invalid';
/////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
minChars=3; /* minimum number of characters in an input field <<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<
///////////////////////////////////////////////////////////////////////////////////////////////////////////////////////*/



///////// this function selects an input field //////////////////////////////////////////////////////////////////////////
function select_me(selected){
	document.getElementById(selected).className = class_selected;
}

///////// this function unselects an input field ////////////////////////////////////////////////////////////////////////
function unselect_me(selected){
	document.getElementById(selected).className = class_normal;
	CheckInput();
}

///////// this function checks a text if it is longer than the minimum character lenght /////////////////////////////////
function checkText(selected){
	count = document.getElementById(selected).value.length;
	if (count<minChars)
		document.getElementById(selected).className = class_invalid;
	else
		document.getElementById(selected).className = class_valid;
	CheckInput();
}

///////// this function checks a text if it is a valid E-Mail address ///////////////////////////////////////////////////
function checkMail(selected){
	var x = document.getElementById(selected).value
	var filter  = /^([a-zA-Z0-9_\.\-])+\@(([a-zA-Z0-9\-])+\.)+([a-zA-Z0-9]{2,4})+$/;
	if (filter.test(x))
		 document.getElementById(selected).className = class_valid;
	else
		document.getElementById(selected).className = class_invalid;
	CheckInput();
}

///////// this function checks selection if one element is selected /////////////////////////////////
function checkSelection(selected){
	mytour="";
	if(document.getElementById("tours").value == "bc")mytour = "Botswana Adventure";
	if(document.getElementById("tours").value == "wgt")mytour = "Windhoek to Victoria Falls Adventure";
	if(document.getElementById("tours").value == "gt")mytour = "Great Trek Tour";
	if(document.getElementById("tours").value == "tc")mytour = "Capricorn Adventure";
	if(document.getElementById("tours").value == "sa")mytour = "South African Adventure";
	if(document.getElementById("tours").value == "tk")mytour = "Transkalahari Adventure";
	if(document.getElementById("tours").value == "ok")mytour = "Okavango Adventure";
	if(mytour!=""){
		document.getElementById("txtComment").value = "I am interested in the " + mytour + ". Please contact me and send me more information.";}
	else document.getElementById("txtComment").value = "";
	checkText('txtComment');
}

///////// this function is the final check of the form and enables or disables the submit button ///////////////////////
function CheckInput(){
	validForm=1;
	for(k=0; k<checkFields.length; k++){
		if(document.getElementById(checkFields[k]).className != class_valid){
			validForm=0;}
	}
	if(validForm==1){
		document.getElementById("submit").disabled = "";
		//document.getElementById("submit").className = 'submit';
	}
	else{
		document.getElementById("submit").disabled = true;
		//document.getElementById("submit").className = 'submit_d';
	}
}

///////// this function clears the forms, when the site is refreshed ///////////////////////////////////////////////////
function clearFields(){
	for(f=0; f<checkFields.length; f++){
		document.getElementById(checkFields[f]).className = class_normal;
		document.getElementById(checkFields[f]).value = "";
	}
	CheckInput();
}

///////// use this function if only numbers are allowed ////////////////////////////////////////////////////////////////
function onlyNumbers(sText){
	var ValidChars = "0123456789 -/";
	var Char;
	var numb = new String;
	Text = document.getElementById(sText).value;
	for (i = 0; i < Text.length; i++){ 
		Char = Text.charAt(i); 
		if (ValidChars.indexOf(Char) != -1){
			numb=numb+Char;
		}
	}
	document.getElementById(sText).value = numb;
}