// BC_Attraction.js

var xmlHttp;
function txtFocus(param1)
{
	var a = "document.AttractionTicketSearchForm."+param1;
	var obj = new Object(eval(a));
	obj.click();
}

//THIS FUNCTION IS USED WHEN STATE IS CHANGED.IT TAKES STATE NAME AND COUNTRY NAME RESPECTIVELY AS ARGUMENT
function Submit(str, ctr)
{   
	document.getElementById('searchimage').style.display = "";
	document.getElementById('attractionlabel').style.display = "none";
    document.getElementById("slowScreenSplash").style.display = '';
	document.getElementById("slowScreenSplash").style.visibility = 'visible';
	document.getElementById("NoAttr").style.visibility = 'hidden';
	document.getElementById("AttrLabel").style.visibility = 'hidden';
	document.getElementById("AttrList").style.visibility = 'hidden';

	if(str.length == 0)
	{
		document.getElementById("slowScreenSplash").style.visibility = 'hidden';
		return;
	}
	xmlHttp = GetXmlHttpObject();

	if(xmlHttp == null)
	{
		alert("Browser does not support HTTP Request");
		return;
	}

	var url ="/attraction/searchAttraction.do";
	
	url = url +"?state=" + str + "&ctr=" + ctr;
	
	url=url+"&sid="+Math.random()
	//alert(url);
	xmlHttp.onreadystatechange = stateChanged
	xmlHttp.open("GET",url,true);
	xmlHttp.send(null);

}	

//GET ATTRACTION FOR SELECTED STATE
function stateChanged() 
{ 
	if (xmlHttp.readyState==4 || xmlHttp.readyState=="complete")
	{ 
		document.AttractionTicketSearchForm.attractionId.length = null;
		var myAtt = xmlHttp.responseText.split("^");
		//alert(xmlHttp.responseText);
		//alert(myAtt);
        
        //document.getElementById("AllAttraction").value=xmlHttp.responseText;
        
		if(myAtt.length > 1)
		{	
			for(var i=0; i< myAtt.length; i+=2)
			{					
				document.AttractionTicketSearchForm.attractionId.options[i/2] = new Option(myAtt[i+1],myAtt[i]);
			}
			
			//show attraction label after state change
			document.getElementById('attractionlabel').style.display = "";
			document.getElementById("AttrLabel").style.visibility = 'visible';
			document.getElementById("AttrList").style.visibility = 'visible';
			document.getElementById("NoAttr").style.visibility = 'hidden';
			
			}
			else
			{
				document.getElementById("AttrLabel").style.visibility = 'hidden';
				document.getElementById("AttrList").style.visibility = 'hidden';
	            document.getElementById("NoAttr").style.display = '';	
				document.getElementById("NoAttr").style.visibility = 'visible';	
			}	
			
		document.getElementById('slowScreenSplash').style.visibility = 'hidden';
		
		return;
	} 
}

//GET XMLHTTPREQUEST OBJECT
function GetXmlHttpObject()
{
	var objXMLHttp = null;
	if(window.XMLHttpRequest)
	{
		objXMLHttp = new XMLHttpRequest();
	}
	else if(window.ActiveXObject)
	{
		objXMLHttp = new ActiveXObject("Microsoft.XMLHTTP");
	}
	
	return objXMLHttp;
}
	

function Show1()
{
    var st = document.getElementById("state");
    
    document.AttractionTicketSearchForm.ScreenName.value = "GetAttraction";
    document.AttractionTicketSearchForm.submit();
}

//SHOW STATE NAME IN COUNTRY IS US OTHERWISE HIDE STATE NAME
function Show1(str)
{
	if(str != "US")
	{
		document.getElementById("showStateList").style.visibility = 'hidden';
		document.getElementById("showStateLabel").style.visibility = 'hidden';
		Submit(str,str);		
	}
	else
	{
        document.getElementById("AttrLabel").style.visibility = 'hidden';
        document.getElementById('attractionlabel').style.display = "none";
		document.getElementById("AttrList").style.visibility = 'hidden';
		document.getElementById("showStateList").style.visibility = 'visible';
		document.getElementById("showStateLabel").style.visibility = 'visible';
		document.getElementById("NoAttr").style.visibility = 'hidden';
		document.AttractionTicketSearchForm.stateCode.value ="";
	}	    
}

//VALIDATION FOR BLANK(WITHOUT SELECTED)STATE NAME AND ATTRACTION FIELD
function Validate()
{
  if(document.AttractionTicketSearchForm.country.value == "US")
  {
      if(document.AttractionTicketSearchForm.stateCode.value.length == "0" && 
      		document.AttractionTicketSearchForm.stateCode.disabled == false)
      {
        alert("Please choose the state");
        return false;
      }
    }
    if(document.AttractionTicketSearchForm.attractionId.value == "Select")
	{
	  	alert("Choose the attraction");
	  	
	  	return false;
	} 
   	else if(document.AttractionTicketSearchForm.attractionId.value == "NoAttraction")
    {
		alert("No attraction");
		
		return false;
    }
  	else
  	{
    	document.AttractionTicketSearchForm.ScreenName.value = "DoSearch";

    	return true;
  	}
}

function hideWaitImage()
{			
	document.getElementById('searchimage').style.display = "none";
	document.getElementById('attractionlabel').style.display = "none";
	document.getElementById('slowScreenSplash').style.visibility = 'hidden';
	document.getElementById("AttrLabel").style.visibility = 'hidden';
	document.getElementById("AttrList").style.visibility = 'hidden';
	document.getElementById("NoAttr").style.visibility = 'hidden';
	if(document.AttractionTicketSearchForm.country.value == "US")
  	{
		document.getElementById("showStateList").style.visibility = 'visible';
		document.getElementById("showStateLabel").style.visibility = 'visible';
		document.AttractionTicketSearchForm.stateCode.value ="";
	}
	else
	{
		document.getElementById("showStateList").style.visibility = 'hidden';
		document.getElementById("showStateLabel").style.visibility = 'hidden';
	}		
}

function showDetails()
{
	var atrCode = document.AttractionTicketSearchForm.attractionId.value;
	if(document.AttractionTicketSearchForm.country.value == "US")
	{
		if(document.AttractionTicketSearchForm.stateCode.value.length == "0" && 
  		document.AttractionTicketSearchForm.stateCode.disabled == false)
	  	{
	    	alert("Please choose the state");
	    	return false;
	  	}
	}
	if(atrCode.length > 0)
	{
		return true;
	}
	else
	{
		alert('No Attraction found for selected country and/or state.\n Please change your search Criteria.');
		return false;
	}
	//alert(atrCode);
	return true;
}


