// JavaScript Document

//here you place the ids of every element you want.
var ids=new Array('your-project','your-details');
function switchid(id)
{	
	hideallids();
	showdiv(id);
}

function hideallids()
{
	//loop through the array and hide each element by id
	for (var i=0;i<ids.length;i++)
	{
		hidediv(ids[i]);
	}		  
}

function hidediv(id) 
{
	//safe function to hide an element with a specified id
	if (document.getElementById) 
	{ // DOM3 = IE5, NS6
		document.getElementById(id).style.display = 'none';
	}
	else 
	{
		if (document.layers) 
		{ // Netscape 4
			document.id.display = 'none';
		}
		else
		{ // IE 4
			document.all.id.style.display = 'none';
		}
	}
}

function showdiv(id) 
{
	//safe function to show an element with a specified id
		  
	if (document.getElementById) 
	{ // DOM3 = IE5, NS6
		document.getElementById(id).style.display = 'block';
	}
	else 
	{
		if (document.layers) 
		{ // Netscape 4
			document.id.display = 'block';
		}
		else { // IE 4
			document.all.id.style.display = 'block';
		}
	}
}

function validateDeliveryDetails(contactForm) 
{
	/*
	if (contactForm.destination.checked==false) 
	{
		alert("Please select your destination");
		contactForm.destination.focus();
		return false;
	}
	*/
	
	if((contactForm.not_sure.checked==false) && (contactForm.botswana.checked==false) && (contactForm.south_africa.checked==false)&&(contactForm.zambia.checked==false) && (contactForm.zimbabwe.checked==false))
	{
		alert("Please select a destination");
		contactForm.not_sure.focus();
		return false;
	}	

	if (contactForm.campsafari.value == '') 
	{
		alert("Please select Camp or Safari");
		contactForm.campsafari.focus();
		return false;
	}

	if (contactForm.dateIII.value == '') 
	{
		alert("Select your arrival date");
		contactForm.dateIII.focus();
		return false;
	}
	
	if (contactForm.nights.value == '') 
	{
		alert("Please enter amount of nights");
		contactForm.nights.focus();
		return false;
	}

	if (contactForm.rooms.value == '') 
	{
		alert("Please enter amount of rooms");
		contactForm.rooms.focus();
		return false;
	}
	
	if (contactForm.adults.value == '') 
	{
		alert("Please indicate how many adults will be joining?");
		contactForm.adults.focus();
		return false;
	}
	
	if((contactForm.plan_safaris[0].checked==false) && (contactForm.plan_safaris[1].checked==false) && (contactForm.plan_safaris[2].checked==false))
	{
		alert("Please indicate if this an enquire, booking request or are you planning a Safari?");
		contactForm.plan_safaris[0].focus();
		return false;
	}
		
	return true;

}

function validateOrder(theForm)
{
	if(!validateDeliveryDetails(theForm))
	{
		return false;
	}
	
	if (theForm.frm_name.value == '') 
	{
		alert("Please enter your Name");
		theForm.frm_name.focus();
		return false;
	}

	if (theForm.frm_surname.value == '') 
	{
		alert("Please enter your Surname");
		theForm.frm_surname.focus();
		return false;
	}
	
	if (!validEmail(theForm.frm_email.value)) 
	{
		alert("Please enter a valid email");
		theForm.frm_email.focus();
		return false;
	}	
	
	if (theForm.frm_tel.value == '' || !validNum(theForm.frm_tel.value) ) {
		alert("Please enter a valid telephone number");
		theForm.frm_tel.focus();
		return false;
	}
	
	if (theForm.frm_country.value == '') 
	{
		alert("Please enter your Country");
		theForm.frm_country.focus();
		return false;
	}
	
	if (theForm.frm_cty.value == '') 
	{
		alert("Please enter your City or State");
		theForm.frm_cty.focus();
		return false;
	}
	
	return true;
}

function check_form()
{
	theForm = document.getElementById('sales_form');
	valid_form = validateDeliveryDetails(theForm);
	//alert(valid_form);
	if(valid_form)
	{
		switchid('your-details');
	}
}

// checks for valid telephone characters

function validNum(telno) 
{
	var pattern = "0123456789+-)(. ";
	var i = 0;

	do 
	{
		var pos = 0;
		for ( var j = 0 ; j < pattern.length ; j++ )
			if ( telno.charAt(i) == pattern.charAt(j) )
				pos = 1;
		i++;
	}

	while ( pos == 1 && i < telno.length )

	if ( pos == 0 ) return false;
	return true;
}



// check email address pattern
function validEmail(addr) 
{
	var regex = /^[a-zA-Z0-9._-]+@([a-zA-Z0-9.-]+\.)+[a-zA-Z0-9.-]{2,4}$/;
	if ( !regex.test(addr) ) 
	{
		return false;
	}
	return true;
}