function mouseOver(target,name_of_class) {
PreviousClass = target.className;
target.className = name_of_class;
}
function mouseOut(target) {
target.className = PreviousClass;
}

function show_hide_div(mode, divid, ahref){
 if(mode=="show"){
 document.getElementById(divid).style.display = "block"
 }else{
 document.getElementById(divid).style.display = "none"
 }
 }

function show_hide(the_layer)
{
  if(document.getElementById(the_layer))
  {
    if(document.getElementById(the_layer).style.display == 'none')
    {
      document.getElementById(the_layer).style.display = 'inline';
    }
    else
    {
      document.getElementById(the_layer).style.display = 'none';
    }
  }
}

function showDiv(the_layer)
{
  if(document.getElementById(the_layer))
  {
      document.getElementById(the_layer).style.display = 'inline';
  }
}

function hideDiv(the_layer)
{
  if(document.getElementById(the_layer))
  {
      document.getElementById(the_layer).style.display = 'none';
  }
}

function showTR(id){
      if (document.getElementById && document.createTextNode)
    {
         var tr=document.getElementById(id);
			if (tr) {
						try {
						  tr.style.display='table-row';
						} catch(e) {
						  tr.style.display = 'block';
						}
				}     
    }
}

function hideTR(id){
      if (document.getElementById && document.createTextNode)
    {
         var tr=document.getElementById(id);
			if (tr) {
				tr.style.display = 'none';
				}     
    }
}


function showTD(id){
      if (document.getElementById && document.createTextNode)
    {
         var td=document.getElementById(id);
			if (td) {
						try {
						  td.style.visibility='visible';
						} catch(e) {
						  td.style.display = 'block';
						}
				}     
    }
}

function hideTD(id){
      if (document.getElementById && document.createTextNode)
    {
         var td=document.getElementById(id);
			if (td) {
				td.style.visibility='hidden';
				}     
    }
}


function showTRs(tableprefix,numTRs,lastTR)
{
  if(numTRs==0) {
     for (var x = 0; x <= lastTR; x++)
       hideTR(tableprefix+'R'+x);
	}
  else	{
    for (var x = 0; x <= numTRs; x++)
	showTR(tableprefix+'R'+x);
    for (x = numTRs+1; x <= lastTR; x++)
	hideTR(tableprefix+'R'+x);
   }
}

function showTDs(tableprefix,row,numTDs,lastTD)
 {
  if(numTDs==0)
   {
     hideTR(tableprefix+'R'+row);
     var totalChildren = 0;
     for(var x = 1; x <= (document.getElementById("numRooms").selectedIndex+1); x++)
	     {
	     totalChildren += document.getElementById("r"+x+"Children").selectedIndex;
	     }
     if(totalChildren == 0)
	hideTR('agesOfChildrenSection');
	else showTR('agesOfChildrenSection');
   }
  else
   {
     showTR('agesOfChildrenSection');
     showTR(tableprefix+'R'+row);
     for (var col = 0; col <= numTDs; col++)
	showTD(tableprefix+'R'+row+'C'+col);
     for (var col = numTDs+1; col <= lastTD; col++)
	hideTD(tableprefix+'R'+row+'C'+col);
   }
 }

function setRoomCount(numRooms)
{
refreshFields();
}

function setChildCount(room,numChildren)
{
refreshFields();
}

function changeAddressFields(country)
{
	if(country.value=="US")
	{
	hideTR("stateprovAU");
	hideTR("stateprovCA");
	showTR("stateprovUS");
	}
	else if(country.value=="CA")
	{
	hideTR("stateprovAU");
	hideTR("stateprovUS");
	showTR("stateprovCA");
	}
	else if(country.value=="AU")
	{
	hideTR("stateprovUS");
	hideTR("stateprovCA");
	showTR("stateprovAU");
	}
	else
	{
	hideTR("stateprovUS");
	hideTR("stateprovCA");
	hideTR("stateprovAU");
	}
}

function changeCardSecurityCodeField(type) 
{
	if (type == null || type.value == null)
	{
	hideTR("cardSecurityCode");
	}
	else if(type.value=="AX" || type.value=="CA" || type.value=="VI")
	{
	showTR("cardSecurityCode");
	showTR("whatisCSV");
	}
	else
	{
	hideTR("cardSecurityCode");
	hideTR("whatisCSV");
	//clear value in case of card type change so this value is not sent
	bookingInformationForm.cardSecurityCode.value = "";
	}

	if (type.value=="O" || type.value=="S" || type.value=="TO") {
		showTR("cardIssue1");
		showTR("cardIssue2");
		showTR("cardIssue3");
	} else {
		hideTR("cardIssue1");
		hideTR("cardIssue2");
		hideTR("cardIssue3");
		bookingInformationForm.creditCardIssueNumber.value = "";
	}
}

function showChildLabels(numLabels)
{
	for (var col = 1; col <= numLabels; col++)
		showTD("child"+col+"Label");
	for (var col = numLabels+1; col <= 3; col++)
		hideTD("child"+col+"Label");
}

function refreshFields()
{
	var numRooms = document.getElementById("numRooms").selectedIndex+1;
	showTRs('roomPeople',numRooms,8);
	var showChildAgesDiv=false;
	var maxChildCol=0;
	for(var row=1;row<=numRooms;row++)
	{
		childrenInRow=document.getElementById("r"+row+"Children").selectedIndex;
		for (var col = 1; col <= childrenInRow; col++)
			showTD("childAgeR"+row+'C'+col);
		for (var col = childrenInRow+1; col <= 3; col++)
			hideTD("childAgeR"+row+'C'+col);
		if (childrenInRow > 0)
		{
		showChildAgesDiv=true;
		showTR("childAgeR"+row);
		}
		else hideTR("childAgeR"+row);
		if (childrenInRow > maxChildCol)
			maxChildCol=childrenInRow;
	}

	for(var ir=numRooms+1;ir<=8;ir++)
		hideTR("childAgeR"+ir);

	showChildLabels(maxChildCol);
	if (showChildAgesDiv==true)
	     showTR('agesOfChildrenSection');
	 else hideTR('agesOfChildrenSection');		
}

function showMoreOptions()
{
	if(document.getElementById("starSelect").selectedIndex > 0)
	{
	show_hide_div('show','searchOptions');
	show_hide_div('hide','showOptionsLink');
	return;
	}
	for(var amenity=1;amenity<=9;amenity++)
	{
		if(document.getElementById("am"+amenity).checked == true)
		{
		show_hide_div('show','searchOptions');
		show_hide_div('hide','showOptionsLink');
		return;
		}
	}
}