var CurHost = "http://www.hdb.gov.sg";
var TrendsDBName = "fi10/fi10298p.nsf";//"fi10/fi10298p.nsf";
var host = window.location.hostname.toString();

var validateROI = function() {
	var ROptions = $(":radio").filter("#RateOptions:checked").val();
	var RSuggestion = $('#Suggestion').val();
	
	if(ROptions != undefined){
		if(ROptions == "Average" || ROptions == "Below Average"){
			if(RSuggestion != ''){
				return true;
			} else {
				alert("Please help provide your feedback.");
			}
		} else {
			return true;
		}
	} else {
		alert("Please select a rating.");
	}
	
	return false;
}

function submitROS(){
        if (validateROI()){
        	var PName = '';
        	var PURL = String(window.location);
        	var splitURL = PURL.split("/");

        	switch(splitURL[6]){
        		case 'properties':
        			PName = 'HBiz : Our Industrial Premises';
        			break;
        		case 'maintenance':
        			PName = 'HBiz : Maintenance of Premises';
        			break;
        		case 'movingin':
        			PName = 'HBiz : Moving In';
        			break;
        		case 'policies':
        			PName = 'HBiz : Policies and Procedures';
        			break;
        		case 'renewal':
        			PName = 'HBiz : Renewing your Lease';
        			break;
        		case 'renovating':
        			PName = 'HBiz : Renovating your Premises';
        			break;
        		case 'rentfees':
        			PName = 'HBiz : Rent and Fees';
        			break;
        		case 'renting':
        			PName = 'HBiz : Renting from IPD';
        			break;
        		case 'aboutus':
        			PName = 'HBiz : About Us';
        			break;
        	}
           
            var PTitle = title;
            var ROptions = $(":radio").filter("#RateOptions:checked").val();
            
            // Here we must take care to give "Form" the correct value since back-end
            // processing depends on it. Assign "wROS_Mail" if rating is Average or
            // Below Average. Otherwise, assign "ROS".
            var theForm = ( ROptions == "Average" || ROptions == "Below Average" )? "wROS_Mail" : "ROS";

            //use the below code for ajax rate our info
            $.ajax({
                    url: CurHost + "/" + TrendsDBName + "/(PostRatingJsonP)?OpenAgent", //(TrendsDBName: fi10/fi10298x.nsf)
            		data: {
                            PackageName: PName,
                            PageTitle: PTitle,
                            ParentURL: PURL,
                            RateOptions: ROptions,
                            Form: theForm,
                            Suggestion: escape($('#Suggestion').val())
                    },
                    type: "GET",
                    dataType: "jsonp",
                    jsonpCallback: 'jsonp_callback',
                    error: function(){
                            alert("Error occured. Please try to submit again");
                    },
                    success: function(content){
                            $("#RateOurInfoCont").fadeOut( "fast", function() { alert('Thank you for your feedback.'); } );
                    }
            });
        }
}
