<!--//BEGIN Script
function checkEmail(myForm,action)  {
  if (/^\w+([\.-]?\w+)*@\w+([\.-]?\w+)*(\.\w{2,3})+$/.test(myForm.requiredemail.value))	{
    if (myForm.requiredemail.value == myForm.requiredemail2.value)  {
      if (myForm.requiredcontact.value != "")	{
		if (myForm.requiredgroup_no.value > 0)	{
			saveForm(myForm);
			if (action=='submit')	{
				return checkTour(myForm);	
			}
			return (true);
		}
		 else  {
			alert("Group size is required.");
			return (false);
		}
      }
      else  {
        alert("Contact name is required.");
        return (false);
      }
    }
    else  {
      alert("E-mail fields don't match.");
      return (false);
    }
  }
  else  {
    alert("Invalid E-mail.");
    return (false);
  }
}

function checkTour(myForm)  {
	var i, j, currElem, currElem2, num, isTour, blankTour, daTour1, daTour2, daTour3;
	isTour = 0;
	daTour1=document.getElementById('tour1');
	daTour2=document.getElementById('tour2');
	daTour3=document.getElementById('tour3');
	//iterate form elements
	for (i=0; i < myForm.length; i++)	{
		currElem = myForm.elements[i];
		// find elements named tour that have data
		if (currElem.name.indexOf('tour') != -1 && currElem.options[currElem.selectedIndex].text)	{
			if (currElem.options[currElem.selectedIndex].text !='--select a tour--')	{
				isTour++;
				blankTour = false;
			}
			else
				blankTour = true;
			// once found grab the number at the end (1,2,3)
			num = currElem.name.substring(currElem.name.length - 1, currElem.name.length);
			// re-iterate the elements looking for elements named date ending with same number as the tour
			for (j=0; j < myForm.length; j++)	{
				currElem2 = myForm.elements[j];
				if (currElem2.name.indexOf(('date' + num)) != -1)	{
					if (blankTour && currElem2.value != 'click calendar box')	{
			
						alert("For at least one tour you have a date but no tour selection.");
						return (false);
					}
					if (!blankTour && currElem2.value == 'click calendar box')	{
						alert("You are missing one or more dates for your tours.");
						return (false);
					}
				}
			}
		}
	}
	// return true if at least one tour has been selected and has a date
	if (isTour > 0)	{
			if (daTour1.options[daTour1.selectedIndex].text == daTour2.options[daTour2.selectedIndex].text || daTour2.options[daTour2.selectedIndex].text == daTour3.options[daTour3.selectedIndex].text && daTour2.options[daTour2.selectedIndex].text != '--select a tour--')	{
		alert("You have selected two identical tours.");
		return (false);
		}
		else
			return (true);
	}
	else	{
		alert("You haven't selected any tours.");
		return (false);
	}
}

function saveForm (myForm)  {
  var i, len, currElem;
  i = 0;
  len = myForm.elements.length;
  while (i < len)  {
    currElem = myForm.elements[i];
    if (currElem.type.toLowerCase() != "hidden" && currElem.name)	{
		if (currElem.name.indexOf("tour") != -1)
		  	Set_Cookie(currElem.name, currElem.selectedIndex , 30, "/", "", "" );
		else	
	  		Set_Cookie(currElem.name, currElem.value , 30, "/", "", "" );
    }
	i++;
  }
}

function popForm (myForm)  {
  var i, len, currElem;
  i = 0;
  len = myForm.elements.length;
  while (i < len)  {
     currElem = myForm.elements[i];
     if (currElem.type.toLowerCase() != "hidden" && currElem.name)  {
	     var cVal = Get_Cookie(currElem.name);
	     if (cVal)	{
		 	if (currElem.name.indexOf("tour") == -1)
		     currElem.value = cVal;
			 else {
			 	currElem.selectedIndex = cVal;
				addTix(currElem.options[cVal].id,currElem.id);
			}
    	}
	}
    i++;
  }
}

function removeTour(tourNum)	{
		saveForm(document.getElementById('resForm'));
		Set_Cookie('tour' + tourNum, '0', 30, "/", "", "" );
		Set_Cookie('date' + tourNum, '', 30, "/", "", "" );
		location.reload(true);
}

function saveTour(tourCode)	{
		//iterate til you find the matching code. tours array is built in db.php using the tours_array.php values
		// counts every three as array has id,tix type and title
		for(var j = 0; j < tours.length; j+=3)	{
			if (tours[j] == tourCode)	{
				break; 
			}
		}
		//look for an empty or 0 tour cookie and write the index number to it
		// there are up to 3 tour possibilities so does 3 loops
		for(var i = 1; i < 4; i++)	{
			if (Get_Cookie('tour' + i)=='0' || !Get_Cookie('tour' + i))	{
				Set_Cookie('tour' + i, j/3, 30, "/", "", "" );
				break;
			}
		}
}

function addTix(selVal,tourId) {
// tix codes are 0=none, 1 = vatican, 2 = coliseum, 3 = borghese, 4 = uffizi or accademia, 5 = uffizi AND accademia, 6 = pompeii, 7 = pompeii and herculaneum, 8 = Vatican AND Ancient City.
	var innerVal = "";
	for(var j = 0; j < tours.length; j+=3)	{
		//match the selected id to the tours array id
		if (tours[j] == selVal.substring(4))	{
			j++;
			// check if tour tix type is > 0
			if (tours[j] > 0) {
				// match the selected tour to the tix type
				for(var k = 0; k < tix.length; k+=3)	{
					if (tix[k] == tours[j]) {
						innerVal = "<input name=\""+tix[k+1]+"_tix1\" type=\"checkbox\" checked=\"checked\"/>"+tix[k+2];
						break;
					}			
				}
			}
			break; 
		}
	}
	document.getElementById(tourId+'_tix').innerHTML = innerVal;	
}
//  End -->