
	
requereField       = new Array("cruised_seadream","cruised_other"  ,"otherline_name"      ,"hear_about_seadream_from","region_id","age","month_of_cruise","year_of_cruise","who_you_are","send_information","Comments");
recipientField     = new Array("Friend_FirstName","Friend_LastName","Friend_MiddleInitial","Friend_Title"         , "Friend_Company", "Friend_StreetAddress","Friend_Address2","Friend_City","Friend_Country", "Friend_ZipCode", "Friend_WorkPhone","Friend_FAX","Friend_Email", "Friend_State");

mandatoryrequereField   = new Array("cruised_seadream","cruised_other", "region_id");

mandatoryñustomerField  = new Array("Contact_FirstName","Contact_LastName","Contact_StreetAddress","Contact_City","Contact_ZipCode","Contact_Country","Contact_Email", "secret_code");
mandatoryñustomerName    = new Array("First Name", "Last Name", "Street Adress", "City", "Zip/Post Code", "Country", "Email", "Secret Code");
    
mandatoryrecipientField = new Array("Friend_FirstName","Friend_LastName", "Friend_StreetAddress", "Friend_City","Friend_ZipCode","Friend_Country","Friend_Email");
mandatoryrecipientName    = new Array("Friend First Name", "Friend Last Name", "Friend Street Adress", "Friend City", "Friend Zip/Post Code", "Friend Country", "Friend Email");   

var fieldOK=true;
var subOK=true;

//*********************************************************************************************************************
function checkForm(f) 
{
	f.elements["destinations_of_interest"].value=f.elements["region_id"].options[f.elements["region_id"].selectedIndex].text;	  	
	subOK=true;
	
	fieldOK=checkEmpty(f.elements["region_id"], 'Destinations interest', 'This is a required field. Please enter it now.');
	if (!fieldOK) subOK = false;
	errLayer(mandatoryrequereField[2],fieldOK);
	for(j=0; j<mandatoryñustomerField.length; j++) {
		fieldOK=checkEmpty(f.elements[mandatoryñustomerField[j]], mandatoryñustomerName[j], 'This is a required field. Please enter it now.'); 
		if (!fieldOK) subOK = false;
	    errLayer(mandatoryñustomerField[j], fieldOK);
		if (mandatoryñustomerField[j].indexOf("mail") > 0 && fieldOK) {
			fieldOK=checkEmail(f.elements[mandatoryñustomerField[j]], mandatoryñustomerName[j], 'This field should be a valid email such as yourname@server.name'); 
			if (!fieldOK) subOK = false;
			errLayer(mandatoryñustomerField[j], fieldOK);
		}
	}
	
	if(!f.elements["Friend_FirstName"].disabled) {
		var j;
		for(j=0; j<mandatoryrecipientField.length; j++) {
			fieldOK=checkEmpty(f.elements[mandatoryrecipientField[j]], mandatoryrecipientName[j], 'This is a required field. Please enter it now.'); 
			if (!fieldOK) subOK = false;
			errLayer(mandatoryrecipientField[j], fieldOK);
			if (mandatoryrecipientField[j].indexOf("mail") > 0 && fieldOK) {
				fieldOK=checkEmail(f.elements[mandatoryrecipientField[j]], mandatoryrecipientName[j], 'This field should be a valid email such as yourname@server.name'); 
				if (!fieldOK) subOK = false;
				errLayer(mandatoryrecipientField[j], fieldOK);
			}
		}
	}
	
	if (!subOK) { makeMess(message,"error"); }
   
	return subOK; 
}
//******************************************************************************************************
function selectState() {
	f=document.forms[0];

	if (document.getElementById("cont_state_select").value == 'US') { 
		document.getElementById("cont_state_input").disabled=true;
		document.getElementById("cont_state_select").disabled=false;	
		document.getElementById('cont_state_input').style.background = '#d3d3d3';
		document.getElementById("cont_state_select").style.background = '#ffffff';
	} 	else {
		document.getElementById("cont_state_input").disabled=false;	
		document.getElementById("cont_state_input").style.background = '#ffffff';	
		document.getElementById("cont_state_select").disabled=true;	
		document.getElementById("cont_state_select").style.background = '#d3d3d3';
	}	
}
function selectStateFriend() {
	f=document.forms[0];

	if (f.Friend_Country.value == 'US') { 
		document.getElementById("cont_state_inputFriend").disabled=true;
		document.getElementById("cont_state_selectFriend").disabled=false;	
		document.getElementById("cont_state_inputFriend").style.background = '#d3d3d3';
		document.getElementById("cont_state_selectFriend").style.background = '#ffffff';
	} 	else {
		document.getElementById("cont_state_inputFriend").disabled=false;	
		document.getElementById("cont_state_inputFriend").style.background = '#ffffff';	
		document.getElementById("cont_state_selectFriend").disabled=true;	
		document.getElementById("cont_state_selectFriend").style.background = '#d3d3d3';
	}	
}
//******************************************************************************************************
function reset() 
{
	f=document.forms[0];	
	selectState(); 
	disableSelect('otherline_name');
}
//******************************************************************************************************
function unableOptions(obj) {
	var dis = !obj.checked;
	var f = document.forms[0];
	for(j=0; j<recipientField.length -1; j++) {
		
		f.elements[recipientField[j]].disabled = dis;
		f.elements[recipientField[j]].style.background = dis ? '#d3d3d3' : '#ffffff';
	}
		document.getElementById("cont_state_inputFriend"). disabled = dis;
		document.getElementById("cont_state_inputFriend").style.background = dis ? '#d3d3d3' : '#ffffff';
	for(i=0; i<mandatoryrecipientField.length;i++)
	{
		//alert(mandatoryrecipientField[i]);
		errLayer(mandatoryrecipientField[i], true);
	
	}
//		deleteRecord(); 
//	if (message.length != 0)	{ makeMess(message,"error");}
		
}
//******************************************************************************************************
function deleteRecord() 
{
	var result=0;
	do {
		result=0;
		var lastIndex=message.length-1;
		var lastMessage=message[lastIndex];
		for(i=0; i<mandatoryrecipientField.length;i++)
		{
			var re=new RegExp(mandatoryrecipientName[i]);
			if (re.test(lastMessage) == true) { 
				message.pop(); 		
				result=1;
			}
		}
	} while (result==1);
}
//******************************************************************************************************

function setFieldValue(field, val) {       
	switch (field.type) {
		case "select-one" :  for(var i=0; i<field.length; i++) {
			                	if (field.options[i].value == val) {
		                			field.options[i].selected = true;
									break;
				            	}
							 }
							 break;
	}
}

