var currentPage="";
var currentPage1=""; // for favorite map
var ipad="";          // for ipad map view
var process = ({
	
	initialize: function()
	{
	},

	ajaxRequest: function(url,queryString,callbackfn,requestType,classNm)
	{
		if(classNm==null)
			classNm = false;
			
		if(requestType==null)
		{
			requestType=true;
		}
		
		if(typeof(callbackfn) == 'undefined')
		{
			var objAjaxReq = new Ajax.Request(url, {method: 'post',asynchronous:requestType, parameters: queryString, onlyLatestOfClass:classNm, onFailure: process.showError, evalScripts: true});
		}
		else
		{
			var objAjaxReq = new Ajax.Request(url, {method: 'post',asynchronous:requestType, parameters: queryString, onlyLatestOfClass:classNm, onFailure: process.showError, onSuccess: callbackfn, evalScripts: true});
		}
	},

	showError: function(originalRequest)
	{
		if (originalRequest.status == 999)
		{
			window.location.href = "../auth/sessionExpire.php";
		}
		else
		{
			var response = originalRequest.responseText;
			$(maindivid).innerHTML = response;
			//alert(response);
		}
	},

	MinChange: function()
	{
		var MinIndex = $('minprice').selectedIndex;
		var MaxIndex = $('maxprice').selectedIndex;
		var MinValue = parseInt($('minprice').value);
		var MaxValue = parseInt($('maxprice').value);
		
		if(MinValue > MaxValue)
		{
			//alert("min="+MinValue+" max="+MaxValue);
			$('maxprice').selectedIndex = MinIndex;
		}
		else if(MinValue==MaxValue)
		{
			$('maxprice').selectedIndex = MaxIndex+1;
		}
				
		/*//alert(MinIndex);
		if(MinIndex==(MaxIndex-1))
		{
		//	alert("1===="+MinIndex);
			if(MaxIndex+1<=16)
			{
				$('maxprice').selectedIndex =MaxIndex+1;
			}

		}
		else if(MinIndex>(MaxIndex-1))
		{
		//	alert("2===="+MinIndex);
			$('maxprice').selectedIndex =MinIndex;
		}*/
		
	},

	MaxChange: function()
	{
		var MinIndex = $('minprice').selectedIndex;
		var MaxIndex = $('maxprice').selectedIndex;
		var MinValue = parseInt($('minprice').value);
		var MaxValue = parseInt($('maxprice').value);
		
		if(MaxValue < MinValue)
		{
			//alert("min="+MinValue+" max="+MaxValue);
			$('minprice').selectedIndex = MaxIndex;
		}
		
		else if(MaxValue==MinValue)
		{
			$('minprice').selectedIndex = MinIndex-1;
		}
		
		//alert("max= "+MaxValue+" min="+MinValue);

		/*if((MinIndex+1)==MaxIndex)
		{
			alert("3===="+MinIndex+ "maxindex="+MaxIndex);

			if((MinIndex-1)>=0)	
			{
				$('minprice').selectedIndex =MinIndex-1;
			}
		}
		if((MinIndex+1)>MaxIndex)
		{
			alert("4===="+MinIndex);
			$('minprice').selectedIndex =MaxIndex;
		}*/
		
	},

	FooterClick: function(id)
	{
		
		$(id).addClassName('selected');
		
		if(id=="achSearch")
		{
			$('Favorites').removeClassName('selected');
			$('Result').removeClassName('selected');
		}
		else if(id=="Favorites")
		{
			$('Result').removeClassName('selected');
			$('achSearch').removeClassName('selected');	
		}
		else if(id=="Result")
		{
			$('achSearch').removeClassName('selected');
			$('Favorites').removeClassName('selected');
		}
		
	},
	
	DetailPush: function(val,city,state)
	{
		//alert("hello"+val);
		if(currentPage=="FavPage")
		{
			$('indexFav').value = parseInt(val);
			document.forms['FavDetailProp'].city.value = city;
			document.forms['FavDetailProp'].state.value = state;
			$('FavDetailProp').submit();
			return;
		}
		else
		{
			$('index').value = parseInt(val);
			document.forms['DetailProp'].city.value = city;
			document.forms['DetailProp'].state.value = state;
			$('DetailProp').submit();
		}
	},

	picPagination: function(action,page,totalcnt)
	{
		
		//alert("hello="+page);
	},

	DetailExplore: function(srno)
	{
		if(currentPage=="FavPage" || currentPage1=="FavPage")
		{
			$('FavExpIndex').value = parseInt(srno);
			$('FavExploreDetail').submit();
			return;
		}
		else
		{
			$('ExpIndex').value = parseInt(srno);
			$('ExploreDetail').submit();
		}
	},
	
	updateOrientation: function()
	{
		var contentType="";
		switch(window.orientation){
			case 0:
			contentType += "normal";
			break;

			case -90:
			contentType += "right";
			break;

			case 90:
			contentType += "left";
			break;

			case 180:
			contentType += "flipped";
			break;
		}

		if(currentPage=="map")
		{
			if(contentType=="right" || contentType=="left")
			{
				if(ipad=="1")
				{
					$('map').className = "Gmap_Flip_ipad";
				}
				else
				{
					$('map').className = "Gmap_Flip";
				}
			}
			else if(contentType=="normal" || contentType=="flipped")
			{
				if(ipad=="1")
				{
					$('map').className = "Gmap_ipad";
				}
				else
				{
					$('map').className = "Gmap";
				}
			}
		}
		//alert("change123="+contentType+" page="+currentPage);
		else if(currentPage=="mapD")
		{
			if(contentType=="right" || contentType=="left")
			{
				$('map_bg').style.width = "450px";
				$('map_bg').style.height = "290px";
				$('mapD').className = "mapD_flip";
			}
			else if(contentType=="normal" || contentType=="flipped")
			{
				$('map_bg').style.width = "290px";
				$('map_bg').style.height = "295px";
				$('mapD').className = "mapD";
			}
		}
		else if(currentPage=="PicDetail")
		{
			if(contentType=="right" || contentType=="left")
			{
				//for map
				$('map_bg').style.width = "450px";
				$('map_bg').style.height = "290px";
				$('mapD').className = "mapD_flip";
				
				// for slide show
				$('picId').style.width = "425px";
				$('picId').style.height = "225px";
				$('pictures').style.margin = "0px";
				$('pict_nav').style.margin = "0px";
				$('pict_nav').style.width = "100%";
				$('next').style.marginRight = "30px";
				$('previous').style.marginLeft = "30px";
			}
			else if(contentType=="normal" || contentType=="flipped")
			{
				//for map
				$('map_bg').style.width = "290px";
				$('map_bg').style.height = "295px";
				$('mapD').className = "mapD";

				// for slide show
				$('picId').style.width = "250px";
				$('picId').style.height = "195px";
				$('pictures').style.margin = "0 auto";
				$('pict_nav').style.margin = "0 auto";
				$('pict_nav').style.width = "260px";
				$('next').style.marginRight = "0px";
				$('previous').style.marginLeft = "0px";
			}
		}
	},	

	signInClick: function()
	{
		document.forms['signin'].submit();
	},
	ExploreSearch: function()
	{
		$('BackToProp').submit();
	},
	FavFooterClick: function()
	{
		$('favForm').submit();
	},
	
	indexFocus: function ()
	{
		$('bodyId').style.height = "700px";  // used for autocomplete to increase the page height onfocus in index page
	},
	
	DownSearchFocus: function ()
	{
		$('bodyId').style.height = "1600px";  // used for autocomplete to increase the page height onfocus in all pages except index page
	},
	
	SearchBlur: function ()
	{
		$('bodyId').style.height = "";  // used for autocomplete to again keep the original page height onblur in all pages
	},

	logoClick: function()
	{
		$('logoLink').submit();
	}
})
