function hideInput(id) {
	var d = document.getElementById(id);
	d.style.display = 'none';
}

function showInput(id) {
	var d = document.getElementById(id);
	d.style.display = 'block';
}

var isLongForm = false;
function shortForm() {
/* :-) */
	isLongForm = false;
	prev = null;
	hideInput("checkinString");
	hideInput("checkinString2");
	hideInput("checkoutString");
	hideInput("checkoutString2");
	hideInput("adultsString");
	hideInput("adultsString2");
	hideInput("childU2String");
	hideInput("childU2String2");
	hideInput("child211String");
	hideInput("child211String2");
	hideInput("child1215String");
	hideInput("firstnameString");
	hideInput("firstnameString2");
	hideInput("postcodeString");
	hideInput("postcodeString2");
	hideInput("addressString");
	hideInput("addressString2");
	hideInput("homephoneString");
	hideInput("workphoneString");
	hideInput("homephoneString2");
	hideInput("workphoneString2");
}
function longForm() {
	prev = null;
	isLongForm = true;
	showInput("checkinString");
	showInput("checkinString2");
	showInput("checkoutString");
	showInput("checkoutString2");
	showInput("adultsString");
	showInput("adultsString2");
	showInput("childU2String");
	showInput("childU2String2");
	showInput("child211String");
	showInput("child211String2");
	showInput("child1215String");
	showInput("firstnameString");
	showInput("firstnameString2");
	showInput("postcodeString");
	showInput("postcodeString2");
	showInput("addressString");
	showInput("addressString2");
	showInput("homephoneString");
	showInput("workphoneString");
	showInput("homephoneString2");
	showInput("workphoneString2");

}

var alerts = new Array ('Mr. or Mrs.', 'name', 'country', 'state/province', 'phone', 'e-mail', 'address');
var prev = null;

function ChangeCountry(index)
{
var state = document.getElementById ('stateField');
var combo_state = document.getElementById ('combo_stateField');
if (index == 0 || index == 67)
{
state.value = '';
state.style.width = '0px';
state.style.height = '0px';
combo_state.style.width = '220px';
combo_state.style.height = '20px';
}else{
state.style.width = '220px';
state.style.height = '20px';
combo_state.selectedIndex = -1;
combo_state.style.width = '0px';
combo_state.style.height = '0px';
}
}

function selectByName(name)
{
if (name == 'sex_field')
return 0;
if (name == 'name_field')
return 1;
if (name == 'country_field')
return 2;
if (name == 'state_field' || name == 'combo_state_field')
return 3;
if (name == 'phone_field')
return 4;
if (name == 'email_field')
return 5;
if (name == 'address_field')
return 6;
}

function CheckBlur(obj)
{
if ((obj.name == 'sex_field' || 
obj.name == 'adult_field' || 
obj.name == 'childU2_field' || 
obj.name == 'child211_field' || 
obj.name == 'child1215_field' || 
obj.name == 'firstname_field' || 
obj.name == 'postcode_field' || 
obj.name == 'address_field' || 
obj.name == 'homephone_field' || 
obj.name == 'workphone_field' || 
obj.name == 'state_field' || 
obj.name == 'combo_state_field' || 
obj.name == 'country_field' || 
obj.name == 'name_field' || 
obj.name == 'phone_field' || 
obj.name == 'email_field'))
prev = obj;
}
function validatePhone(str) {
var q = " ()-+.0123456789";
var f;
if (str.length < 7)
return false;
for (var c=0; c < str.length; c++) {
f = 0;
for (var v=0; v < q.length; v++) 
if (str.charAt(c) == q.charAt(v))
f++;
if (f==0) return false;
}
if (str.indexOf('+') > 0) return false;
/*
if (str.indexOf('(') != str.lastIndexOf('(')) return false;
if (str.indexOf(')') != str.lastIndexOf(')')) return false;
if (str.indexOf('(') >= 0 && str.indexOf(')') <= 0) return false;
if (str.indexOf(')') >= 0 && str.indexOf('(') <= 0) return false;
if (str.indexOf('(') > str.indexOf(')')-2) return false;
*/

return true;
}
function validateEmail(str) {
if (str.indexOf('@')<2) return false;
if (str.indexOf('.')<4) return false;
if (str.indexOf('@')>str.indexOf('.')) return false;
if (str.length < 8) return false;
if (str.indexOf('@') != str.lastIndexOf('@')) return false;
return true;
}

/*
function CheckFocus(obj) {
var index;

if ((prev != null && prev.value == '') && prev != obj) {
index = selectByName(prev.name);
alert ('You must input your ' + alerts[index] + '!!!');
prev = null;
}

if (prev != null && prev != obj) {
if (prev.id == 'emailField' && !validateEmail(prev.value))
alert('Wrong E-mail address !!!');
if (prev.id == 'nameField' && prev.value.length < 3)
alert('Too short name !');
if (prev.id == 'stateField' && prev.value.length < 3)
alert('Too short state/province !');

if (prev.id == 'countryField' && prev.selectedIndex == 4)
alert('You must input your country !');


if (prev.id == 'addressField' && prev.value.length < 10)
alert('Too short address !');
if (prev.id == 'phoneField' && (!validatePhone(prev.value) || prev.value.length < 7))
alert('Wrong phone !');
prev = null;
}

}
*/

function totalValidate() {
var msg="";

var f = document.getElementById('sexField1');
var f2 = document.getElementById('sexField2');
if (f.checked == false && f2.checked == false)
msg += "Mr. or Mrs.\n";

f = document.getElementById('nameField');
if ((f.value == '') || (f.value.length < 3))
msg += "Name\n";

f = document.getElementById('cityField');
if ((f.value == '') || (f.value.length < 3))
msg += "City\n";

f = document.getElementById('countryField');
if (f.selectedIndex == 4)
msg += "Country\n";

var cfsi = document.getElementById('countryField').selectedIndex;
f = document.getElementById('stateField');
f2 = document.getElementById('combo_stateField');
if ((cfsi != 0 && cfsi != 67 && f.value.length < 3) || ((cfsi == 0 && cfsi == 67) && f.value == ''))
msg += "State/Province\n";

/*
f = document.getElementById('stateField');
f2 = document.getElementById('combo_stateField');
if ((f.value == '')  || (f.value.length < 3) || (f2.selectedIndex != 0))
msg += "State/Province\n\n";
*/

f = document.getElementById('addressField');
if ((isLongForm && f.value == '') || (isLongForm && f.value.length < 10))
msg += "Address\n";

f = document.getElementById('phoneField');
if ((f.value == '') || (f.value.length < 7) || !validatePhone(f.value))
msg += "Cell Phone\n";

f = document.getElementById('emailField');
if ((f.value == '') || !validateEmail(f.value))
msg += "E-mail\n";

f = document.getElementById('commentField');
if (f.value == '')
msg += "Comments\n";	

if (msg == '')
return true;
alert("Please verify these fields:\n\n"+msg);
return false;
}