

//==========================================================================================
//	SETTINGS OPTIONS OBJECT AVAILABLE FOR EACH BROWSER CONFIGURATION
//==========================================================================================

var G6_SettingsOptions = function(profilesArray)
{
	if(typeof(profilesArray)!='undefined' && profilesArray.length > 0)
	{
		this._profiles = profilesArray;
	}
	else
	{
		this._profiles = [];
	}
	// default index is the first item in the array
	this._defaultIndex = 0;
}

G6_SettingsOptions.prototype.addProfile = function(profileObject)
{
	this._profiles.push(profileObject);
}

G6_SettingsOptions.prototype.getDefaultFormat = function()
{
	var f = null;
	try{
		f = this._profiles[this._defaultIndex].format;
	}catch(e){}
	return f;
}

G6_SettingsOptions.prototype.isValidSetting = function(format,bitrate)
{
	for(var i = 0; i < this._profiles.length; i++)
	{
		var f = this._profiles[i].format;
		var b = this._profiles[i].bitrate;
		if(f == format && b == bitrate)
		{
			return true;
		}
	}
	return false;
}


G6_SettingsOptions.prototype.getDefaultBitrate = function()
{
	var b = null;
	try{
		b = this._profiles[this._defaultIndex].bitrate;
	}catch(e){}
	return b;	
}	

G6_SettingsOptions.prototype.setDefaultIndex = function(number)
{
	this._defaultIndex = number;
}	

//==========================================================================================
//	SETTINGS POLICY OBJECT
//==========================================================================================

var G6_SettingsPolicy = function(platform,browserType,browserSubtype)
{
	//	Store platform and browsertype as member variables
	this._platform = platform;
	
	//	Default is enabled
	this._isEnabled = true;
	
	//  Create an extra type for conytainered browser
	if(browserType=="IE" && browserSubtype=="NS"){
	    this._browserType = "NSIE";
	}else{
	    this._browserType = browserType;
	};

	//	DEFINE PROFILES
	//NN Bug fix 3367 -start -added bitrate 128 for all 3 formats, viz., wmp, real and flash
	var FLA_056 = {format:"flash" , bitrate:"56"};
	var FLA_128 = {format:"flash" , bitrate:"128"};
	var FLA_300 = {format:"flash" , bitrate:"300"};
	var FLA_700 = {format:"flash" , bitrate:"700"};
	var WMP_056 = {format:"wmp" , bitrate:"56"};
	var WMP_128	= {format:"wmp" , bitrate:"128"};		
	var WMP_300	= {format:"wmp" , bitrate:"300"};		
	var WMP_700	= {format:"wmp" , bitrate:"700"};
	var RPL_056 = {format:"real" , bitrate:"56"};
	var RPL_128	= {format:"real" , bitrate:"128"};		
	var RPL_300	= {format:"real" , bitrate:"300"};		
	var RPL_700	= {format:"real" , bitrate:"700"};		
	
	this._defaultSettingsOptions = new G6_SettingsOptions([WMP_300, WMP_056, WMP_700, WMP_128, FLA_056, FLA_300, FLA_700, FLA_128, RPL_056, RPL_300, RPL_700, RPL_128]);
	
	//	DEFAULT PROFILE IS THE FIRST ONE		
	var allFormats_WMP_Default = new G6_SettingsOptions([WMP_300, WMP_056, WMP_700, WMP_128, FLA_056, FLA_300, FLA_700, FLA_128, RPL_056, RPL_300, RPL_700, RPL_128]);
	var allFormats_FLA_Default = new G6_SettingsOptions([FLA_300, WMP_056, WMP_300, WMP_700, WMP_128, FLA_056, FLA_700, FLA_128, RPL_056, RPL_300, RPL_700, RPL_128]);
	var flashOnly = new G6_SettingsOptions([FLA_300,FLA_056,FLA_700,FLA_128]);
	//NN Bug fix 3367 -end
	
	//	ASSIGN SETTINGS PROFILES TO BROWSER PLATFORM COMBINATIONS
	this._m = {};
	this._m["WIN"] = {};
	this._m["WIN"]["IE"] 	= allFormats_WMP_Default;
	this._m["WIN"]["FF"] 	= allFormats_FLA_Default;
	this._m["WIN"]["NSIE"] 	= allFormats_FLA_Default;
	this._m["WIN"]["OP"] 	= allFormats_FLA_Default;
	this._m["WIN"]["NS"] 	= allFormats_FLA_Default;
	
	this._m["MAC"] = {};
	this._m["MAC"]["IE"] 	= flashOnly;
	this._m["MAC"]["FF"] 	= flashOnly;
	this._m["MAC"]["OP"] 	= flashOnly;
	this._m["MAC"]["SF"] 	= flashOnly;
	this._m["MAC"]["NS"] 	= flashOnly;
	this._m["MAC"]["NSIE"] 	= flashOnly;
	
	this._m["LINUX"] = {};
	this._m["LINUX"]["IE"] 	= flashOnly;
	this._m["LINUX"]["FF"] 	= flashOnly;
	this._m["LINUX"]["OP"] 	= flashOnly;
	this._m["LINUX"]["SF"] 	= flashOnly;
	this._m["LINUX"]["NS"] 	= flashOnly;
	
	this._m["UNIX"] = {};
	this._m["UNIX"]["IE"] 	= flashOnly;
	this._m["UNIX"]["FF"] 	= flashOnly;
	this._m["UNIX"]["OP"] 	= flashOnly;
	this._m["UNIX"]["SF"] 	= flashOnly;
	this._m["UNIX"]["NS"] 	= flashOnly;	
	
	this._m["SUN"] = {};
	this._m["SUN"]["IE"] 	= flashOnly;
	this._m["SUN"]["FF"] 	= flashOnly;
	this._m["SUN"]["OP"] 	= flashOnly;
	this._m["SUN"]["SF"] 	= flashOnly;
	this._m["SUN"]["NS"] 	= flashOnly;
}


//	get the array in the relavent matrix slot
G6_SettingsPolicy.prototype.getSettingsOptions = function()
{
	return this._m[this._platform][this._browserType];
}	

//	
G6_SettingsPolicy.prototype.isValidSetting = function(format, bitrate)
{
	if(this._isEnabled)
	{
		if(format==""){
			format = this.getDefaultFormat();
		}
		if(bitrate==""){
			bitrate = this.getDefaultBitrate();
		}
		
		return this.getSettingsOptions().isValidSetting(format, bitrate);
	}
	else
	{
		if(format==""){
			//format = this.getDefaultFormat();         
			format="wmp";
		}
		if(bitrate==""){
		    bitrate="300";
			//bitrate = this.getDefaultBitrate();
		}
			
		return this._defaultSettingsOptions.isValidSetting(format, bitrate);
	}
};

G6_SettingsPolicy.prototype.disable = function(isDisabled)
{
	if(typeof(isDisabled)=="undefined"||isDisabled==true)
	{
		this._isEnabled = false;
	}
	else
	{
		this._isEnabled = true;
	}
}

G6_SettingsPolicy.prototype.isEnabled = function()
{
	return this._isEnabled;
}

G6_SettingsPolicy.prototype.getDefaultFormat = function()
{
    r = "";
    if(this._isEnabled)
    {
        r = this.getSettingsOptions().getDefaultFormat();
    }
	return r;
};

G6_SettingsPolicy.prototype.getDefaultBitrate = function()
{
    r = "";
    if(this._isEnabled)
    {
	    r =  this.getSettingsOptions().getDefaultBitrate();
	}
	return r;
};	
