_factories = [
           function(){return new XMLHttpRequest();},
           function(){return new ActiveXObject("Msxml2.XMLHTTP");},
           function(){return new ActiveXObject("Microsoft.XMLHTTP");}
       ];
       
       _factory = null;
       
       newRequest = function(){
           if(_factory != null) return _factory();
               
           for(var i = 0; i < _factories.length; i++)
           {
               try
               {
                   var factory = _factories[i];
                   var request = factory();
                   if(request != null)
                   {
                       _factory = factory;
                       return request;
                   }
               }
               catch(e)
               {
                   continue;       
               }       
           
           }
           
           _factory = function()
           {
               throw new Error("XMLHttpRequest not supported");
           }
           _factory();
       }
       
       
       function showPhoneDetails()
       {
           var phoneDetails = document.getElementById("phone");
           var requestPhoneDetails = document.getElementById("requestPhone");
           requestPhoneDetails.style.display = "none";
           phoneDetails.style.display = "inline";
       }
     
     function doClickAway(restaurantId)
     {
       _bsn.Crossfader.prototype.pause();
       var request = newRequest();
       request.open("POST",'/restaurant/ShowRestaurant!clickAway.action?id=' + restaurantId, true);
       request.send();
     }
     
    var divArray;
    function setDivArray(restArray)
    {
    	divArray = restArray;
    }
    
	function showPicture(imageName)
	{
	document.largeImage.src = "/gallery/" + imageName;
	}
	
	var commentDefaultString = "Type your comment here.";
	function textareaFocus()
	{
	      var comment = document.getElementById("comment");
	      if(comment.value.length == 0 || comment.value==commentDefaultString)
	      {
	             comment.value="";
	             comment.style.color="black";
	      }
	  return true;    
	}
	
	function popUp(URL, id) {
		day = new Date();
		eval("page" + id + " = window.open(URL, '" + id + "', 'toolbar=0,scrollbars=0,location=0,statusbar=0,menubar=0,resizable=0,width=520,height=495,left = 470,top = 200');");
		}
	function popSize(URL, id, width, height) {
		day = new Date();
		eval("page" + id + " = window.open(URL, '" + id + "', 'toolbar=0,scrollbars=0,location=0,statusbar=0,menubar=0,resizable=0,width="+width+",height="+height+",left = 470,top = 200');");
	}
		function galleryPopUp(URL, id) {
		day = new Date();
		eval("page" + id + " = window.open(URL, '" + id + "', 'toolbar=0,scrollbars=0,location=0,statusbar=0,menubar=0,resizable=0,width=620,height=645,left = 370,top = 100');");
		}
	
	function textareaBlur()
	{
	      var comment = document.getElementById("comment");
	      if(comment.value.length == 0 || comment.value==commentDefaultString)
	      {
	          comment.value="Type your comment here.";
	          comment.style.color="#888";
	      }
	      return true;
	}

	function validLength(field)
	{
		  return ((field.value != null && !(field.value == "" || field.value.replace(/^\s+|\s+$/g,"").length == 0)));
	}
	
	function validEmailAddress(field)
	{
		var filter = /\b(^[_A-Za-z0-9-]+(\.[_A-Za-z0-9-]+)*@([A-Za-z0-9-])+(\.[A-Za-z0-9-]+)*((\.[A-Za-z0-9]{2,})|(\.[A-Za-z0-9]{2,}\.[A-Za-z0-9]{2,}))$)\b/gi;
		return filter.test(field.value);
	}

	function validateWriteReview()
	{
		var error = false;

		//name
		var name = document.getElementById('userName');
		var nameLabel = document.getElementById('nameLabel');
		if(!validLength(name))
		{
			nameLabel.style.color = "red";
			error = true;
		}
		else
			nameLabel.style.color = "black";

		//comment
		var comment = document.getElementById('comment');
	    if(!validLength(comment) || comment.value == 'Type your comment here.')
	        {
	    	  comment.style.color = "red";
	          error = true;
	        }
	    else
	        comment.style.color = "black";

	    //email
		var email = document.getElementById('email');
		var emailLabel = document.getElementById('emailLabel');
		if(!validLength(email) || !validEmailAddress(email))
		   {
			emailLabel.style.color = "red";
            error = true;
		   }
		else
			emailLabel.style.color = "black";

		//title
		var title = document.getElementById('title');
		var titleLabel = document.getElementById('titleLabel');
        if(!validLength(title))
        {
        	titleLabel.style.color = "red";
            error = true;
        }
        else
        	titleLabel.style.color = "black";

		var submitError = document.getElementById('submitError');
		
		if(error)
			submitError.style.display = "block";
		else
			submitError.style.display = "none";
		
		return !error;
	}
	
	function Restaurant(name, description,cuisines, avgPrice, town, suburb, rating, specialOffer, review)
	{
	  this.name=name;
	  this.description=description;
	  this.cuisines=cuisines;
	  this.avgPrice=avgPrice;
	  this.town=town;
	  this.suburb=suburb;
	  this.rating=rating;
	  this.specialOffer=specialOffer;
	  this.review=review;

	}
	
	function togglePlay()
	{
	  var altPlayPause = document.getElementById("altPlayPause");
	  if(playState)
	  {  _bsn.Crossfader.prototype.pause();
	  altPlayPause.src = "images/playBlack.gif";}
	  else
	  { _bsn.Crossfader.prototype.play();
	  altPlayPause.src = "images/pauseBlack.gif";}
	    
	    
	}
	
	function altSlides()
	{
	if(divArray.length > 1)
	  var cf = new Crossfader( divArray, 500, 5000 );
	}

