/*
 * author: 
 * 
 * 
 * tabsInitialize
 *
 * Description:
 * This constructor function creates objects that associates themselves
 * with DOM elements whose IDs are passed to the constructor as a
 * string. The object instances want to arrange than when the
 * corresponding element triggers onclick.
 *
 * Functional Overview:
 *	1) creates the tab structure for provided container and associates onclick event on them
 *
 * Parameters:
 * 	1) container
 *  2) selectedTab	
 *
 * Examples:
 *  to initialize the tab structure
 *	var overviewTabsInit = new tabsInitialize('overviewTabContainer','overview');
 *  to select other than default tab
 *  overviewTabsInit.doOnClick('restaurant'); 
 * 
 */
function tabsInitialize(container, selectedTab){
	this.containerId = container;
	this.selectedTabId = selectedTab;
	
	var tabsObj = this.getTabs(this.containerId);
	var selectedTabRef = getElementWithId(this.selectedTabId);
	var lastSelectedTabContRef = getElementWithId(this.selectedTabId+"Container");

	for(var i = 0; i <= tabsObj.length; i++){
		var tabElement = tabsObj[i];
		if(tabElement){
			tabElement.onclick = associateObjWithEvent(this, "doOnClick");				        
		};
	};
};


/*
 * author: 
 * 
 * 
 * getTabs
 *
 * Description:
 * returns the tabs from supplid container 
 * 
 * Functional Overview:
 *	1) returns tabs
 *
 * Parameters:
 * 	1) container
 *
 * Examples:
 * this.getTabs('containerId');
 * 
 * 
 */
tabsInitialize.prototype.getTabs = function(containerId){
	var container = getElementWithId(containerId);
	var tabsObj = container.getElementsByTagName('li');
	
	return tabsObj;
};


/*
 * author: 
 * 
 * 
 * getTabs
 *
 * Description:
 * onclick method for each tab. shows the clicked tab container 
 * and hides the lastselected tab container
 * 
 * Functional Overview:
 *	1) onclick method for tabs
 *
 * Parameters:
 * 	1) event
 * 	2) element ref
 *
 * Examples:
 * this.doOnClick(event, elementRef);
 * 
 * 
 */
tabsInitialize.prototype.doOnClick = function(event, elementRef){
	var tabContainerRef = getElementWithId(elementRef.id+"Container");
	var tabRef = elementRef;
	var selectedTabRef = getElementWithId(this.selectedTabId);
	var lastSelectedTabContRef = getElementWithId(this.selectedTabId+"Container");	

	if(elementRef.id != this.selectedTabId){
		tabRef.className = "active";
		tabContainerRef.style.display = "block";
	
		selectedTabRef.className = "";
		lastSelectedTabContRef.style.display = "none";
		
		this.selectedTabId = elementRef.id;
	};
	
	return false;
};

/*
 * author: 
 * 
 * 
 * getElementWithId
 *
 * Description:
 * A general function that retrives the element DOM referance 
 * using the element id. Internally uses the DOM method getElementById.
 *
 * Functional Overview:
 *	1) returns the DOM refrence of the supplied elementId
 *
 * Parameters:
 * 	1) elementId	
 *
 * Examples:
 *	getElementWithId('elementId');
 * 
 */

function getElementWithId(elementId){
	return document.getElementById(elementId);
};


/*
 * author: 
 * 
 * 
 * associateObjWithEvent
 *
 * Description:
 * A general function that associates an object instance with an event
 * handler. The returned inner function is used as the event handler.
 * The object instance is passed as the - obj - parameter and the name
 * of the method that is to be called on that object is passed as the -
 * methodName - (string) parameter.
 *
 * Functional Overview:
 *	1) A general function that associates an object instance with an event handler.
 *
 * Parameters:
 * 	1) Event	
 *	2) function name
 *
 * Examples:
 *	associateObjWithEvent(this, "doOnClick");
 * 
 */

function associateObjWithEvent(obj, methodName){
    return (function(e){
		e = e||window.event;
		return obj[methodName](e, this);
    });
};


/*
 * author: 
 * 
 * 
 * starRatingInitialize
 *
 * Description:
 * This constructor function creates objects that associates themselves
 * with DOM elements whose IDs are passed to the constructor as a
 * string. The object instances want to arrange than when the
 * corresponding element triggers onclick.
 *
 * Functional Overview:
 *	1) creates star rating 
 *
 * Parameters:
 * 	1) container
 *  2) currentRating
 *  3) inputElem	
 *
 * Examples:
 *    
 */
function starRatingInitialize(container, currentRating, inputElem){
	this.containerId = container;
	this.currentRatingObjRef = getElementWithId(currentRating);
	this.inputElemRef = inputElem;
	
	var starRatingsObj = this.getStarRatingObj(this.containerId);

	for(var i = 0; i <= starRatingsObj.length; i++){
		var starRatingElem = starRatingsObj[i];

		if(starRatingElem){
			starRatingElem.onclick = associateObjWithEvent(this, "doOnClick");				        
		};
	};
};

/*
 * author: 
 * 
 * 
 * getStarRatingObj
 *
 * Description:
 * return star rating objects with in containerId
 * 
 * Functional Overview:
 *	1) returns star rating object ref 
 *
 * Parameters:
 * 	1) containerId
 *
 * Examples:
 *    
 */
starRatingInitialize.prototype.getStarRatingObj = function(containerId){
	var container = getElementWithId(containerId);
	var starRatingObj = container.getElementsByTagName('a');
	
	return starRatingObj;
};

/*
 * author: 
 * 
 * 
 * doOnClick
 *
 * Description:
 * handles onClick event of individual stars 
 * and updates the form values
 * 
 * Functional Overview:
 *	1) handles onClick event and updates the form values
 *
 * Parameters:
 * 	1) event
 *  2) elemRef
 *
 * Examples:
 *    
 */
starRatingInitialize.prototype.doOnClick = function(event, elementRef){
	this.inputElemRef.value = elementRef.innerHTML;	
	this.currentRatingObjRef.className = "current-rating " + elementRef.className;

	return false;
};


/*
 * author: 
 * 
 * 
 * clearRating
 *
 * Description:
 * clears the rating
 * 
 * Functional Overview:
 *	1) clears the rating
 *
 * Parameters:
 *
 * Examples:
 *    
 */
starRatingInitialize.prototype.clearRating = function(){
	this.inputElemRef.value = "";	
	this.currentRatingObjRef.className = "current-rating";

	return false;
};


/*
 * author: 
 * 
 * 
 * bodyEvent
 *
 * Description:
 * handles onClick event of body 
 * and hides the container
 * 
 * Functional Overview:
 *	1) handles onClick event of body
 *
 * Parameters:
 * 	1) container
 *
 * Examples:
 *    
 */
function bodyEvent(container){
	/*
	 * TODO: fix IE bug for dropdownbox
	 */
	this.bodyObj = getElementWithId('blockLayer');
	this.bodyObj.style.display = 'block';
	this.container = container;
	
	if(this.bodyObj){
		this.bodyObj.onclick = associateObjWithEvent(this, "doOnClick");
	};
};

/*
 * author: 
 * 
 * 
 * doOnClick 
 *
 * Description:
 * onClick method for body
 * 
 * Functional Overview:
 *	1) handles onClick event of body
 *
 * Parameters:
 * 	1) event
 * 	2) elementRef
 *
 * Examples:
 *    
 */
bodyEvent.prototype.doOnClick = function(event, elementRef){
	var containerRef = getElementWithId(this.container);
	containerRef.style.display = "none";
	this.bodyObj.style.display = "none";
};



/*
 * author: 
 * 
 * 
 * getScreenDimensions
 *
 * Description:
 * returns the screen width and height
 * 
 * Functional Overview:
 *	1) returns the screen width and height
 *
 * Parameters:
 *
 * Examples:
 *    getScreenDimensions()
 */
function getScreenDimensions()
{
	var frameHeight;
	var frameWidth;
	
	if (self.innerWidth)
	{
		frameWidth = self.innerWidth;
		frameHeight = self.innerHeight;
	}
	else if (document.documentElement && document.documentElement.clientWidth)
	{
		frameWidth = document.documentElement.clientWidth;
		frameHeight = document.documentElement.clientHeight;
	}
	else if (document.body)
	{
		frameWidth = document.body.clientWidth;
		frameHeight = document.body.clientHeight;
	}
	else return;
	
	return [frameWidth, frameHeight];
};


function destinationReview(container){
	 
	if (loginStatus()) {
		var cityReviewFormCont = getElementWithId(container);
		
		if (cityReviewFormCont) {
			var cityReviewContWidth = 500;
			var cityReviewContHeight = 500;
			var screenDimensions = getScreenDimensions();
			var contLeft = (screenDimensions[0] - cityReviewContWidth) / 2;
			var contTop = (screenDimensions[1] - cityReviewContHeight) / 2;
			
			if (!overallRating) 
				overallRating = new starRatingInitialize('overallRatingStar', 'overallCurRating', document.cityReviewForm.overAllRating);
			if (!restaurantRating) 
				restaurantRating = new starRatingInitialize('restaurantRating', 'restCurRating', document.cityReviewForm.restaurants);
			if (!shoppingRating) 
				shoppingRating = new starRatingInitialize('shoppingRating', 'shoppingCurRating', document.cityReviewForm.shopping);
			if (!attractionRating) 
				attractionRating = new starRatingInitialize('attractionRating', 'attractionCurRating', document.cityReviewForm.nearByAttraction);
			if (!sightsRating) 
				sightsRating = new starRatingInitialize('sightsRating', 'sightsCurRating', document.cityReviewForm.sightSeeing);
			if (!theatersRating) 
				theatersRating = new starRatingInitialize('theatersRating', 'theatersCurRating', document.cityReviewForm.theaters);
			
			cityReviewFormCont.style.top = contTop + "px";
			cityReviewFormCont.style.left = contLeft + "px";
			cityReviewFormCont.style.display = "block";
			attachBodyEvent = new bodyEvent(container);
		};
	}else{
		createCookie("destinatonReview");
		document.loginForm.redirectUrl.value = window.location;
		document.loginForm.submit();	
	};
	
};

function hotelAssetWriteReview(assetId, assetName, cityName){
	document.hotelReviewForm.hotelId.value=assetId;
	document.getElementById("reviewTitleWrapper").innerHTML = "<h2>" + assetName + ", " + cityName + "</h2>";
	
	hotelReview('hotelReviewHolder');
};

function hotelReview(container){
	if(loginStatus()){	
		var hotelReviewFormCont = getElementWithId(container);
			
		if(hotelReviewFormCont){
			var hotelReviewContWidth = 500;
			var hotelReviewContHeight = 500;
			var screenDimensions = getScreenDimensions();
			var contLeft = (screenDimensions[0] - hotelReviewContWidth) / 2;
			var contTop = (screenDimensions[1] - hotelReviewContHeight) / 2;
			
			if(!hotelOverallRating) hotelOverallRating = new starRatingInitialize('hotelOverallRatingStar','hotelOverallCurRating',document.hotelReviewForm.overAllRating);
			if(!roomsRating) roomsRating = new starRatingInitialize('roomsRating','roomsCurRating',document.hotelReviewForm.roomCondition);	
			if(!serviceRating) serviceRating = new starRatingInitialize('serviceRating','serviceCurRating',document.hotelReviewForm.staffFriendliness);		
			if(!valueRating) valueRating = new starRatingInitialize('valueRating','valueCurRating',document.hotelReviewForm.worthMoney);
			if(!cleanlinessRating) cleanlinessRating = new starRatingInitialize('cleanlinessRating','cleanlinessCurRating',document.hotelReviewForm.cleanliness);							
			if(!diningRating) diningRating = new starRatingInitialize('diningRating','diningCurRating',document.hotelReviewForm.restaurant);							
			
			hotelReviewFormCont.style.top = contTop +"px";
			hotelReviewFormCont.style.left = contLeft +"px";
			hotelReviewFormCont.style.display = "block";
			attachBodyEvent = new bodyEvent(container);
		};
	}else{
		createCookie("hotelReview", document.hotelReviewForm.hotelId.value, "");
		document.loginForm.redirectUrl.value = window.location;
		document.loginForm.submit();	
	};
};


function restaurantAssetWriteReview(assetId, assetName, cityName){
	document.restaurantReviewForm.restaurantId.value=assetId;
	document.getElementById("reviewTitleWrapper").innerHTML = "<h2>" + assetName + ", " + cityName + "</h2>";
	
	restaurantReview('restaurantReviewHolder');
};

function restaurantReview(container){
	if(loginStatus()){
		var restaurantReviewFormCont = getElementWithId(container);
			
		if(restaurantReviewFormCont){
			var restaurantReviewContWidth = 500;
			var restaurantReviewContHeight = 500;
			var screenDimensions = getScreenDimensions();
			var contLeft = (screenDimensions[0] - restaurantReviewContWidth) / 2;
			var contTop = (screenDimensions[1] - restaurantReviewContHeight) / 2;
			
			if(!restaurantOverallRating) restaurantOverallRating = new starRatingInitialize('restaurantOverallRatingStar','restaurantOverallCurRating',document.restaurantReviewForm.overAllRating);
			if(!foodRating) foodRating = new starRatingInitialize('foodRating','foodCurRating',document.restaurantReviewForm.foodQuality);	
			if(!serviceRating) serviceRating = new starRatingInitialize('serviceRating','serviceCurRating',document.restaurantReviewForm.staffFriendliness);		
			if(!valueRating) valueRating = new starRatingInitialize('valueRating','valueCurRating',document.restaurantReviewForm.worthMoney);
			if(!cleanlinessRating) cleanlinessRating = new starRatingInitialize('cleanlinessRating','cleanlinessCurRating',document.restaurantReviewForm.cleanliness);							
			if(!ambianceRating) ambianceRating = new starRatingInitialize('ambianceRating','ambianceCurRating',document.restaurantReviewForm.ambiance);							
			
			restaurantReviewFormCont.style.top = contTop +"px";
			restaurantReviewFormCont.style.left = contLeft +"px";
			restaurantReviewFormCont.style.display = "block";
			attachBodyEvent = new bodyEvent(container);
		};
	}else{
		createCookie("restaurantReview", document.restaurantReviewForm.restaurantId.value, "");
		document.loginForm.redirectUrl.value = window.location;
		document.loginForm.submit();	
	};
	
};

function barAssetWriteReview(assetId, assetName, cityName){
	document.barReviewForm.barId.value=assetId;
	document.getElementById("reviewTitleWrapper").innerHTML = "<h2>" + assetName + ", " + cityName + "</h2>";

	barReview('barReviewHolder');
};

function barReview(container){
	if(loginStatus()){
		var barReviewFormCont = getElementWithId(container);
			
		if(barReviewFormCont){
			var barReviewContWidth = 500;
			var barReviewContHeight = 500;
			var screenDimensions = getScreenDimensions();
			var contLeft = (screenDimensions[0] - barReviewContWidth) / 2;
			var contTop = (screenDimensions[1] - barReviewContHeight) / 2;
			
			if(!barOverallRating) barOverallRating = new starRatingInitialize('barOverallRatingStar','barOverallCurRating',document.barReviewForm.overAllRating);
			if(!diningRating) diningRating = new starRatingInitialize('diningRating','diningCurRating',document.barReviewForm.foodQuality);	
			if(!serviceRating) serviceRating = new starRatingInitialize('serviceRating','serviceCurRating',document.barReviewForm.staffFriendliness);		
			if(!valueRating) valueRating = new starRatingInitialize('valueRating','valueCurRating',document.barReviewForm.worthMoney);
			if(!musicRating) musicRating = new starRatingInitialize('musicRating','musicCurRating',document.barReviewForm.music);							
			if(!ambianceRating) ambianceRating = new starRatingInitialize('ambianceRating','ambianceCurRating',document.barReviewForm.ambiance);							
			
			barReviewFormCont.style.top = contTop +"px";
			barReviewFormCont.style.left = contLeft +"px";
			barReviewFormCont.style.display = "block";
			attachBodyEvent = new bodyEvent(container);
		};
	}else{
		createCookie("barReview", document.barReviewForm.barId.value, "");
		document.loginForm.redirectUrl.value = window.location;
		document.loginForm.submit();	
	};	
};

function nearByAssetWriteReview(assetId, assetName, cityName){
	document.nearByReviewForm.assetId.value=assetId;
	document.getElementById("reviewTitleWrapper").innerHTML = "<h2>" + assetName + ", " + cityName + "</h2>";

	nearByReview('nearByReviewHolder');
};

function nearByReview(container){
	if(loginStatus()){
		var nearByReviewFormCont = getElementWithId(container);
			
		if(nearByReviewFormCont){
			var nearByReviewContWidth = 500;
			var nearByReviewContHeight = 500;
			var screenDimensions = getScreenDimensions();
			var contLeft = (screenDimensions[0] - nearByReviewContWidth) / 2;
			var contTop = (screenDimensions[1] - nearByReviewContHeight) / 2;
			
			if(!nearByOverallRating) nearByOverallRating = new starRatingInitialize('nearByOverallRatingStar','nearByOverallCurRating',document.nearByReviewForm.overAllRating);
			if(!publicAmenities) publicAmenities = new starRatingInitialize('publicAmenitiesRating','publicAmenitiesCurRating',document.nearByReviewForm.publicAmenities);	
			if(!cleanlinessRating) cleanlinessRating = new starRatingInitialize('cleanlinessRating','cleanlinessCurRating',document.nearByReviewForm.cleanliness);							
			if(!parkingRating) parkingRating = new starRatingInitialize('parkingRating','parkingCurRating',document.nearByReviewForm.parking);							
			
			nearByReviewFormCont.style.top = contTop +"px";
			nearByReviewFormCont.style.left = contLeft +"px";
			nearByReviewFormCont.style.display = "block";
			attachBodyEvent = new bodyEvent(container);
		};
	}else{
		createCookie("nearByAttrReview", document.nearByReviewForm.assetId.value, "");

		document.loginForm.redirectUrl.value = window.location;
		document.loginForm.submit();	
	};
};

function sightAssetWriteReview(assetId, assetName, cityName){
	document.sightReviewForm.assetId.value=assetId;
	document.getElementById("reviewTitleWrapper").innerHTML = "<h2>" + assetName + ", " + cityName + "</h2>";

	sightReview('sightReviewHolder');
};

function sightReview(container){
	if(loginStatus()){
		var sightReviewFormCont = getElementWithId(container);
			
		if(sightReviewFormCont){
			var sightReviewContWidth = 500;
			var sightReviewContHeight = 500;
			var screenDimensions = getScreenDimensions();
			var contLeft = (screenDimensions[0] - sightReviewContWidth) / 2;
			var contTop = (screenDimensions[1] - sightReviewContHeight) / 2;
			
			if(!sightOverallRating) sightOverallRating = new starRatingInitialize('sightOverallRatingStar','sightOverallCurRating',document.sightReviewForm.overAllRating);
			if(!publicAmenities) publicAmenities = new starRatingInitialize('publicAmenitiesRating','publicAmenitiesCurRating',document.sightReviewForm.publicAmenities);	
			if(!cleanlinessRating) cleanlinessRating = new starRatingInitialize('cleanlinessRating','cleanlinessCurRating',document.sightReviewForm.cleanliness);							
			if(!parkingRating) parkingRating = new starRatingInitialize('parkingRating','parkingCurRating',document.sightReviewForm.parking);							
			
			sightReviewFormCont.style.top = contTop +"px";
			sightReviewFormCont.style.left = contLeft +"px";
			sightReviewFormCont.style.display = "block";
			attachBodyEvent = new bodyEvent(container);
		};
	}else{
		createCookie("sightReview", document.sightReviewForm.assetId.value, "");
		document.loginForm.redirectUrl.value = window.location;
		document.loginForm.submit();	
	};
	
};

function shoppingAssetWriteReview(assetId, assetName, cityName){
	document.shoppingReviewForm.assetId.value=assetId;
	document.getElementById("reviewTitleWrapper").innerHTML = "<h2>" + assetName + ", " + cityName + "</h2>";

	shoppingReview('shoppingReviewHolder');
};

function shoppingReview(container){
	if(loginStatus()){
		var shoppingReviewFormCont = getElementWithId(container);
			
		if(shoppingReviewFormCont){
			var shoppingReviewContWidth = 500;
			var shoppingReviewContHeight = 500;
			var screenDimensions = getScreenDimensions();
			var contLeft = (screenDimensions[0] - shoppingReviewContWidth) / 2;
			var contTop = (screenDimensions[1] - shoppingReviewContHeight) / 2;
			
			if(!shoppingOverallRating) shoppingOverallRating = new starRatingInitialize('shoppingOverallRatingStar','shoppingOverallCurRating',document.shoppingReviewForm.overAllRating);
			if(!publicAmenities) publicAmenities = new starRatingInitialize('publicAmenitiesRating','publicAmenitiesCurRating',document.shoppingReviewForm.publicAmenities);	
			if(!cleanlinessRating) cleanlinessRating = new starRatingInitialize('cleanlinessRating','cleanlinessCurRating',document.shoppingReviewForm.cleanliness);							
			if(!ambianceRating) ambianceRating = new starRatingInitialize('ambianceRating','ambianceCurRating',document.shoppingReviewForm.ambiance);
			if(!parkingRating) parkingRating = new starRatingInitialize('parkingRating','parkingCurRating',document.shoppingReviewForm.parking);							
			
			shoppingReviewFormCont.style.top = contTop +"px";
			shoppingReviewFormCont.style.left = contLeft +"px";
			shoppingReviewFormCont.style.display = "block";
			attachBodyEvent = new bodyEvent(container);
		};
	}else{
		createCookie("shoppingReview", document.shoppingReviewForm.assetId.value, "");
		document.loginForm.redirectUrl.value = window.location;
		document.loginForm.submit();	
	};
};


function clearCityFormValues(){
	document.cityReviewForm.reset();
	overallRating.clearRating();
	restaurantRating.clearRating();
	shoppingRating.clearRating();
	sightsRating.clearRating();
	attractionRating.clearRating();
	theatersRating.clearRating();
};


function clearHotelFormValues(){
	document.hotelReviewForm.reset();
	overallRating.clearRating();
	roomsRating.clearRating();
	serviceRating.clearRating();
	valueRating.clearRating();
	cleanlinessRating.clearRating();
	diningRating.clearRating();
};


function clearRestaurantFormValues(){
	document.restaurantReviewForm.reset();
	overallRating.clearRating();
	foodRating.clearRating();
	serviceRating.clearRating();
	valueRating.clearRating();
	cleanlinessRating.clearRating();
	ambianceRating.clearRating();
};


function clearBarFormValues(){
	document.barReviewForm.reset();
	overallRating.clearRating();
	dinningRating.clearRating();
	serviceRating.clearRating();
	valueRating.clearRating();
	musicRating.clearRating();
	ambianceRating.clearRating();
};

function clearNearByFormValues(){
	document.nearByReviewForm.reset();
	overallRating.clearRating();
	publicAmenities.clearRating();
	ambianceRating.clearRating();
	cleanlinessRating.clearRating();
};

function clearSightFormValues(){
	document.sightReviewForm.reset();
	overallRating.clearRating();
	publicAmenities.clearRating();
	ambianceRating.clearRating();
	cleanlinessRating.clearRating();
};


function clearShoppingFormValues(){
	document.shoppingReviewForm.reset();
	overallRating.clearRating();
	publicAmenities.clearRating();
	ambianceRating.clearRating();
	cleanlinessRating.clearRating();
};


function destinationReviewForm(frmObj){
	
	var parameters = getFormValues(frmObj);
	
	reviewSubmit.open("POST", frmObj.action,true);
	reviewSubmit.onreadystatechange = reviewReadyStateChange;
	reviewSubmit.setRequestHeader("Content-Type", "application/x-www-form-urlencoded");
	reviewSubmit.setRequestHeader("Content-length", parameters.length);
	reviewSubmit.setRequestHeader("Connection", "close");
	reviewSubmit.send(parameters);
 };


function hotelReviewFormX(frmObj){
	
	var parameters = getFormValues(frmObj);
	
	reviewSubmit.open("POST", frmObj.action,true);
	reviewSubmit.onreadystatechange = reviewReadyStateChange;
	reviewSubmit.setRequestHeader("Content-Type", "application/x-www-form-urlencoded");
	reviewSubmit.setRequestHeader("Content-length", parameters.length);
	reviewSubmit.setRequestHeader("Connection", "close");
	reviewSubmit.send(parameters);
 };


function restaurantReviewFormX(frmObj){
	
	var parameters = getFormValues(frmObj);
	
	reviewSubmit.open("POST", frmObj.action,true);
	reviewSubmit.onreadystatechange = reviewReadyStateChange;
	reviewSubmit.setRequestHeader("Content-Type", "application/x-www-form-urlencoded");
	reviewSubmit.setRequestHeader("Content-length", parameters.length);
	reviewSubmit.setRequestHeader("Connection", "close");
	reviewSubmit.send(parameters);
 };


function barReviewFormX(frmObj){
	
	var parameters = getFormValues(frmObj);
	
	reviewSubmit.open("POST", frmObj.action,true);
	reviewSubmit.onreadystatechange = reviewReadyStateChange;
	reviewSubmit.setRequestHeader("Content-Type", "application/x-www-form-urlencoded");
	reviewSubmit.setRequestHeader("Content-length", parameters.length);
	reviewSubmit.setRequestHeader("Connection", "close");
	reviewSubmit.send(parameters);
 };


function nearByReviewFormX(frmObj){
	
	var parameters = getFormValues(frmObj);
	
	reviewSubmit.open("POST", frmObj.action,true);
	reviewSubmit.onreadystatechange = reviewReadyStateChange;
	reviewSubmit.setRequestHeader("Content-Type", "application/x-www-form-urlencoded");
	reviewSubmit.setRequestHeader("Content-length", parameters.length);
	reviewSubmit.setRequestHeader("Connection", "close");
	reviewSubmit.send(parameters);
 };

function sightReviewFormX(frmObj){
	
	var parameters = getFormValues(frmObj);
	
	reviewSubmit.open("POST", frmObj.action,true);
	reviewSubmit.onreadystatechange = reviewReadyStateChange;
	reviewSubmit.setRequestHeader("Content-Type", "application/x-www-form-urlencoded");
	reviewSubmit.setRequestHeader("Content-length", parameters.length);
	reviewSubmit.setRequestHeader("Connection", "close");
	reviewSubmit.send(parameters);
 };

function shoppingReviewFormX(frmObj){
	
	var parameters = getFormValues(frmObj);
	
	reviewSubmit.open("POST", frmObj.action,true);
	reviewSubmit.onreadystatechange = reviewReadyStateChange;
	reviewSubmit.setRequestHeader("Content-Type", "application/x-www-form-urlencoded");
	reviewSubmit.setRequestHeader("Content-length", parameters.length);
	reviewSubmit.setRequestHeader("Connection", "close");
	reviewSubmit.send(parameters);
 };



function reviewReadyStateChange(){
	
	var statusText;

	// Check the ready state.
	switch (reviewSubmit.readyState)
	{
		case XMLHTTPREQUEST_READY_STATE_UNINITIALIZED:
			statusText = "";
			break;

		case XMLHTTPREQUEST_READY_STATE_LOADING:
			statusText = "Initialzing form submition...";
			break;

		case XMLHTTPREQUEST_READY_STATE_LOADED:
			statusText = "Sending data...";
			break;

		case XMLHTTPREQUEST_READY_STATE_INTERACTIVE:
			statusText = "Downloading data...";
			break;

		case XMLHTTPREQUEST_READY_STATE_COMPLETED:
			var xmlDoc = reviewSubmit.responseXML;
			//alert(xmlDoc.getElementsByTagName("status").value);
			alert('Your review has been submitted successfully.');	
			attachBodyEvent.doOnClick(this);
			//clearCityFormValues();
			statusText = "";
			break;
		default:
			statusText = "Unknown error.";
			break;
	};
};


function getFormValues(frmObj){
	var frmValues = "";
	var els = frmObj.elements;
	
	/*
	 * TODO: add multiselect option values
	 */
	for(i=0; i < els.length; i++){ 
		switch(els[i].type){
			case "select-one":
				frmValues += els[i].name + '=' + escape(els[i].value) + "&";
				break;
			case "text":
			case "textarea":
			case "hidden":
				frmValues += els[i].name + '=' + escape(els[i].value) + "&";
				break;
			case "radio":
				if(els[i].checked == true)
					frmValues += els[i].name + '=' + escape(els[i].value) + "&";
				break;
			case "checkbox":
				if(els[i].checked == true)
					frmValues += els[i].name + '=' + escape(els[i].value) + "&";
				break;
			default:
				break;
		};	
	};
	
	return frmValues;
};



//-----------------------------------------------------------------------------
// Define some constants.
//-----------------------------------------------------------------------------

// Define a list of Microsoft XML HTTP ProgIDs.
var XMLHTTPREQUEST_MS_PROGIDS = new Array(
	"Msxml2.XMLHTTP.7.0",
	"Msxml2.XMLHTTP.6.0",
	"Msxml2.XMLHTTP.5.0",
	"Msxml2.XMLHTTP.4.0",
	"MSXML2.XMLHTTP.3.0",
	"MSXML2.XMLHTTP",
	"Microsoft.XMLHTTP"
);

// Define ready state constants.
var XMLHTTPREQUEST_READY_STATE_UNINITIALIZED = 0;
var XMLHTTPREQUEST_READY_STATE_LOADING       = 1;
var XMLHTTPREQUEST_READY_STATE_LOADED        = 2;
var XMLHTTPREQUEST_READY_STATE_INTERACTIVE   = 3;
var XMLHTTPREQUEST_READY_STATE_COMPLETED     = 4;

//-----------------------------------------------------------------------------
// Returns an XMLHttpRequest object.
//-----------------------------------------------------------------------------
function getXMLHttpRequest()
{
	var httpRequest = null;

	// Create the appropriate HttpRequest object for the browser.
	if (window.XMLHttpRequest != null)
		httpRequest = new window.XMLHttpRequest();
	else if (window.ActiveXObject != null)
	{
		// Must be IE, find the right ActiveXObject.
		var success = false;
		for (var i = 0; i < XMLHTTPREQUEST_MS_PROGIDS.length && !success; i++)
		{
			try
			{
				httpRequest = new ActiveXObject(XMLHTTPREQUEST_MS_PROGIDS[i]);
				success = true;
			}
			catch (ex)
			{}
		};
	};

	// Display an error if we couldn't create one.
	if (httpRequest == null)
		alert("Error in HttpRequest():\n\nCannot create an XMLHttpRequest object.");

	// Return it.
	return httpRequest;
};


var reviewSubmit = getXMLHttpRequest();
var	overallRating = null;
var	restaurantRating = null;
var	shoppingRating = null;
var	sightsRating = null;
var	attractionRating = null;
var	theatersRating = null;
var	hotelOverallRating = null;
var	roomsRating = null;
var	serviceRating = null;
var	diningRating = null;
var	cleanlinessRating = null;
var	valueRating = null;
var	ambianceRating = null;
var 	parkingRating = null;
var	foodRating = null;
var	restaurantOverallRating = null;
var	barOverallRating = null;
var	musicRating = null;
var nearByOverallRating = null;
var publicAmenities = null;
var sightOverallRating = null;
var shoppingOverallRating = null;



/* Function to create cookie */
function createCookie(name,value,days)
{
        if (days)
        {
                var date = new Date();
                date.setTime(date.getTime()+(days*24*60*60*1000));
                var expires = "; expires="+date.toGMTString();
        }
        else var expires = "";
        var ck = name+"="+value+expires+"; path=/";
        document.cookie = ck;
}

/* Function to read the set cookie */
function readCookie(name)
{
        var nameEQ = name + "=";
        var ca = document.cookie.split(';');

        for(var i=0;i<ca.length;i++)
        {
                var c = ca[i];
                while (c.charAt(0)==' ') c = c.substring(1,c.length);
                if (c.indexOf(nameEQ) == 0) return c.substring(nameEQ.length,c.length);
        }
        return null;
}

/* Function to erase cookie */
function eraseCookie(name)
{
        createCookie(name,"",-1);
}

/*
 * loginStatus
 * checks whether user is loged in or not
 * 
 */
function loginStatus(){
	var status = false;
	
	if(readCookie("ide")){
		status = true;
	}else{
		status = false;
	}
	
	return status;
}

function loginUser(){
	document.loginForm.redirectUrl.value = window.location;
	document.loginForm.submit();	
}

function limitText(limitField, limitNum) {
    if (limitField.value.length > limitNum) {
        limitField.value = limitField.value.substring(0, limitNum);
    }
}

function isEmail(data) {
    //recommended expression: most complete
    return /^([\w]+)(\.[\w]+)*@([\w\-]+)(\.[\w]{2,4})(\.[a-z]{2})?$/i.test(data);
}//eof - isEmail

function isDate(data) {
    return /^\d{4}-\d{2}-\d{2}$/.test(data);
}//eof - isDate

function alltrim(str) {
    /* Trims leading and trailing spaces
     * Returns trimmed string
     */
    return str.replace(/^\s+|\s+$/g, '');
}//eof - alltrim
