var s_front = true;

if (window.location.href.indexOf("/ac2/") >0){
	s_front = false;
}

function initFields(){
	if(s_front){
		document.getElementById("keyword").setAttribute("value",mainSearchKeywordSuggest);
		document.getElementById("area").setAttribute("value",mainSearchLocationSuggest);
	}else{
		var keyValue = document.getElementById("keyword").getAttribute("value");
		var locValue = document.getElementById("area").getAttribute("value");
		var keyExisted = true;
		var locExisted = true;
		if(locValue == mainSearchLocationSuggest || locValue =="")
		{
			locExisted = false;
		}
		if((keyValue == mainSearchKeywordSuggest || keyValue =="") && !locExisted)
		{
			document.getElementById("keyword").setAttribute("value",mainSearchKeywordSuggest);
			keyExisted = false;
		}
		if((locValue == mainSearchLocationSuggest || locValue =="") && !keyExisted)
		{
			document.getElementById("area").setAttribute("value",mainSearchLocationSuggest);
		}
	}
}

function searchNew(){	
  if (document.forms.searchForm.displaySearchTerm.value == mainSearchKeywordSuggest  
	|| document.forms.searchForm.displaySearchTerm.value == "")
  {
    document.forms.searchForm.displaySearchTerm.value ="";
    document.forms.searchForm.st.value = "";
  } else {
    document.forms.searchForm.st.value = document.forms.searchForm.displaySearchTerm.value;
  }

  if (document.forms.searchForm.displaySearchLocation.value == mainSearchLocationSuggest 
	|| document.forms.searchForm.displaySearchLocation.value == "")
  {
    document.forms.searchForm.sl.value = '';
    document.forms.searchForm.displaySearchLocation.value = '';
  } else {  	
    document.forms.searchForm.sd.value = document.forms.searchForm.displayDistance.value;    
    document.forms.searchForm.sl.value = document.forms.searchForm.displaySearchLocation.value;
  }
  if (document.forms.searchForm.displaySearchTerm.value.length < 1 
	&& document.forms.searchForm.displaySearchLocation.value.length < 1)
  {
    document.forms.searchForm.displaySearchTerm.className = 'main_search_box';
    document.forms.searchForm.displaySearchLocation.className = 'main_search_box';
    alert("Please enter a keyword and/or location.");
    return false;			
  }

  document.forms.searchForm.fc.value = "fcsearch";
  document.forms.searchForm.map.value = '';
  document.forms.searchForm.currentPage.value = 1;
  document.forms.searchForm.sortBy.value = 7;
  document.forms.searchForm.sa.value = "ns";
  removeEmptyParameters();
  document.forms.searchForm.submit();
}


function clearDisplayTermField() {
if (document.forms.searchForm.displaySearchTerm.value == mainSearchKeywordSuggest)
{
  	document.forms.searchForm.displaySearchTerm.value = "";
}
	document.forms.searchForm.displaySearchTerm.className = 'main_search_box';
}

function clearDisplayLocationField() {
  	if (document.forms.searchForm.displaySearchLocation.value == mainSearchLocationSuggest)
{
  	document.forms.searchForm.displaySearchLocation.value = "";
}
	document.forms.searchForm.displaySearchLocation.className = 'main_search_box';
}

function initNatlMovieFields() {
	var keyValue = document.forms.getElementById("keyword").getAttribute("value");
	var locValue = document.forms.getElementById("area").getAttribute("value");
	var keyExisted = true;
	var locExisted = true;
	if(locValue == natlMovieLocationSuggest || locValue =="")
	{
		locExisted = false;
	}
	if((keyValue == natlMovieNameSuggest || keyValue =="") && !locExisted)
	{
		document.forms.getElementById("keyword").setAttribute("value",natlMovieNameSuggest);
		keyExisted = false;
	}
	if((locValue == natlMovieLocationSuggest || locValue =="") && !keyExisted)
	{
		document.forms.getElementById("area").setAttribute("value",natlMovieLocationSuggest);
	}
}

function searchNewNatlMovie() {
  if (document.forms.searchForm.displaySearchTerm.value == natlMovieNameSuggest  
	|| document.forms.searchForm.displaySearchTerm.value == "")
  {
    document.forms.searchForm.displaySearchTerm.value ="";
  }

  if (document.forms.searchForm.displaySearchLocation.value == natlMovieLocationSuggest 
	|| document.forms.searchForm.displaySearchLocation.value == "")
  {
    document.forms.searchForm.displaySearchLocation.value = '';
  }

  if (document.forms.searchForm.displaySearchTerm.value.length < 1 
	&& document.forms.searchForm.displaySearchLocation.value.length < 1)
  {
    document.forms.searchForm.displaySearchTerm.className = 'main_search_box';
    document.forms.searchForm.displaySearchLocation.className = 'main_search_box';
    alert("Please enter a keyword and/or location.");
    return false;
  }
  document.forms.searchForm.searchTerm.value = document.forms.searchForm.displaySearchTerm.value;
  document.forms.searchForm.searchLocation.value = document.forms.searchForm.displaySearchLocation.value;
  removeEmptyNatlMovieParameters();
  document.forms.searchForm.submit();
}

function clearNatlMovieDisplayTermField() {
if (document.forms.searchForm.displaySearchTerm.value == natlMovieNameSuggest)
{
  	document.forms.searchForm.displaySearchTerm.value = "";
}
	document.forms.searchForm.displaySearchTerm.className = 'main_search_box';
}

function clearNatlMovieDisplayLocationField() {
  	if (document.forms.searchForm.displaySearchLocation.value == natlMovieLocationSuggest)
{
  	document.forms.searchForm.displaySearchLocation.value = "";
}
	document.forms.searchForm.displaySearchLocation.className = 'main_search_box';
}


function changeProximity(val) {  
	
	if(document.forms.searchForm.movieName.value != ""){
		document.forms.showSearchInclude.searchDistance.value=val;
		document.forms.showSearchInclude.searchLocation.value = document.searchForm.searchLocationDisplay.value;			
		document.forms.showSearchInclude.dateOffset.value=document.searchForm.dateOffset.value;
		document.forms.showSearchInclude.movieName.value=document.searchForm.movieName.value;
		document.forms.showSearchInclude.submit();
	}else{
		if (document.forms.searchForm.displaySearchTerm.value == mainSearchKeywordSuggest  
		|| document.forms.searchForm.displaySearchTerm.value == "")
	  	{
	    	document.forms.searchForm.displaySearchTerm.value ="";
	    	document.forms.searchForm.st.value = "";
	  	}   	
	  
	  	if (document.forms.searchForm.displaySearchLocation.value == mainSearchLocationSuggest 
		|| document.forms.searchForm.displaySearchLocation.value == "")
	  	{		    
		    document.forms.searchForm.displaySearchLocation.value ="";
		    document.forms.searchForm.sl.value = "";
	  	} else {
		    document.forms.searchForm.sl.value = document.searchForm.displaySearchLocation.value;
		    document.forms.searchForm.sd.value = val;
		    document.forms.searchForm.displayDistance.value = val;
		    document.forms.searchForm.searchDistance.value = val;
	  	}
	  
  		if (document.forms.searchForm.displaySearchTerm.value.length < 1 
		&& document.searchForm.displaySearchLocation.value.length < 1)
  		{
    		alert("Please enter a keyword and/or location.");
    		return false;
  		}
	  	document.forms.searchForm.fc.value = "navSearch";
	  	document.forms.searchForm.map.value = "";
	  	document.forms.searchForm.currentPage.value = 1;
	  	document.forms.searchForm.sortBy.value = 7;
	  	document.forms.searchForm.sa.value = "ns";
	  	removeEmptyParameters();
	  	document.forms.searchForm.submit();	
	}
}

function checkKey(evt) {
    var keyCode;
    if (!evt) {evt=window.event;}
    if (evt.keyCode)
        keyCode=evt.keyCode
    else
        keyCode=evt.which;
    if (keyCode == 13) searchNew();
}

//Clear showtime search location in profile page
//Clear Showtime search box
function clearShowTimeLocation() {
	if((document.forms.showSearch.searchLocation.value == "e.g., Reston, 20748") || 
	(document.forms.showSearch.searchLocation.className == 'profile_search_box_grey'))
	{
	  document.forms.showSearch.searchLocation.value = "";
	}
	document.forms.showSearch.searchLocation.className = 'profile_search_box';
}
