// Copyright 2012-2013 Adobe Systems Incorporated.  All rights reserved.

//--------------------------------------------------------------------
// CLASS:
//   JQuery.DesignTime.Widget.Datepicker
//
// DESCRIPTION:
//   This class is used by the Datepicker property inspector to manage
//   and manipulate the design-time state of the widget's markup in the
//   design view.
//--------------------------------------------------------------------

//--------------------------------------------------------------------
// FUNCTION:
//   Datepicker
//
// DESCRIPTION:
//	 This is the constructor method for this design time Datepicker object.
//	 It calls the base widget constructor which helps us inherit all base methods
//	 like addClass, removeClass, ensureValidElements etc
//	 
//   It also manages the Datepicker's widget markup in the design view. This constructor
//   is registered in the JQuery Widget translator found at:
//
//       Configuration/Translators/jQueryWidget.htm
//	 
//
// ARGUMENTS:
//   dom - object - The DOM used by the document in design view.
//   element - object - The top-level DOM element for our widget markup.
// RETURNS:
//   N/A
//--------------------------------------------------------------------

JQuery.DesignTime.Widget.Datepicker = function(dom, element, consArgs)
{
  JQuery.DesignTime.Widget.Base.call(this, dom, element);

	this.opts = {};
	this.opts = consArgs;
  this.init(element);
};

// JQuery.DesignTime.Widget.Datepicker derives from our JQuery.DesignTime.Widget.Base
// class, so create a Base object and use it as our prototype so we inherit all of its
// methods.
JQuery.DesignTime.Widget.Datepicker.prototype = new JQuery.DesignTime.Widget.Base();

// Reset the constructor property back to Datepicker for our newly created prototype
// object so callers know that our object was created with the Datepicker constructor.
JQuery.DesignTime.Widget.Datepicker.prototype.constructor = JQuery.DesignTime.Widget.Datepicker;

//--------------------------------------------------------------------
// FUNCTION:
//   init
//
// DESCRIPTION:
//   Initializes the design-time object's properties. This  method is
//   called from the constructor and refresh() methods.
//
// ARGUMENTS:
//   element - object - The widget's top-level DOM element.
//
// RETURNS:
//   N/A
//--------------------------------------------------------------------
var LOCALEOPTION = "";
JQuery.DesignTime.Widget.Datepicker.prototype.init = function(element)
{
	this.element = this.getElement(element);
	this.localeArray = [];
	this.localeValueArray = [];
	this.dateFormatArray = [];
	this.initLocaleArray();
	this.initLocaleValueArray();
	this.initDateFormatArray();
	
	if (!this.opts)
		this.opts = {};
		
	var consArgs = this.getConstructorArgs('datepicker');
	this.opts = consArgs; 
	
	this.canRefresh = true;
};

JQuery.DesignTime.Widget.Datepicker.prototype.getLocaleIndex = function()
{
	if( LOCALEOPTION == "" )
		return 0;
	
	var localeValueArray = this.getLocaleValueArray();
	for ( var i = 0; i < localeValueArray.length; i++)
	{
		if( localeValueArray[i] == LOCALEOPTION )
			return i;
	}
	
	return 0;
}

JQuery.DesignTime.Widget.Datepicker.prototype.recalculateOpts = function()
{
	this.opts = {};
	var consArgs = this.getConstructorArgs(this.widgetType);
	this.opts = consArgs;
}

JQuery.DesignTime.Widget.Datepicker.prototype.setLocaleValue = function(localeIndex)
{
	var oldLocale = ""
	if( localeIndex == 0 )
	{
		oldLocale = LOCALEOPTION;
		LOCALEOPTION = "";
	}
	else	
	{
		oldLocale = LOCALEOPTION;
		LOCALEOPTION = this.getLocaleValueArray()[localeIndex];
	}
	
	if( oldLocale != "" )
	{
		this.deleteLocaleFile(oldLocale);
	}
	if( LOCALEOPTION != "" )
	{
		this.addLocaleFile(LOCALEOPTION);
	}
	
	this.updateOptions(this.widgetType, this.opts);
}
JQuery.DesignTime.Widget.Datepicker.prototype.deleteLocaleFile = function(localeString)
{
	var tags = new Array();
	tags = tags.concat(this.dom.getElementsByTagName("script"));
	
	for (var j=0; j<tags.length; j++)
	{
		var tag = tags[j];
		if (tag && tag.getAttribute)
		{
			var valueToSearch = tag.getAttribute("src");
			if( valueToSearch && valueToSearch.match(/i18n/) )
			{
				if( valueToSearch.match(new RegExp(localeString)) )
				{
					tag.outerHTML = "";
					break;
				}
			}
		}
	}
}
JQuery.DesignTime.Widget.Datepicker.prototype.addLocaleFile = function(localeString)
{
	var localeAssetObject = new Object();
	localeAssetObject.fullPath = "Shared/jQueryWidgets/Widgets/Datepicker/i18n/jquery.ui.datepicker-" + localeString + ".js";
	localeAssetObject.file = "i18n/jquery.ui.datepicker-" + localeString + ".js";
	localeAssetObject.type = "javascript";
	
	var assetsArray = new Array ();
	var assetInfo = new AssetInfo(localeAssetObject.fullPath, localeAssetObject.file, localeAssetObject.type);
	assetsArray.push (assetInfo);
	this.dom.copyAssets(assetsArray);
}

//--------------------------------------------------------------------
// FUNCTION:
//  	getButtonImagePathValue
//
// DESCRIPTION:
//  	This method returns the value of the ButtonImage attribute in the widget constructor.
//		If user changes the ButtonImage value in the code. This is where we 'read' that updated 
//		value from the object
//
// ARGUMENTS:
//  	None
//
// RETURNS:
//  	String: The value of the ButtonImage attribute as string
//--------------------------------------------------------------------

JQuery.DesignTime.Widget.Datepicker.prototype.getButtonImagePathValue = function()
{
	if( this.opts && this.opts.buttonImage != null && typeof this.opts.buttonImage != 'undefined' )
	{
		return this.opts.buttonImage;
	}
	return "";
}

//--------------------------------------------------------------------
// FUNCTION:
//  	setButtonImagePathValue
//
// DESCRIPTION:
//  	When a new value for buttonImageValue is attained for the buttonImageValue attribute from the PI
//		we have to update our opts object with this new buttonImageValue value and initiate an update cycle
//		for this change to be reflected in code.
//
// ARGUMENTS:
//  	None
//
// RETURNS:
//  	None
//--------------------------------------------------------------------

JQuery.DesignTime.Widget.Datepicker.prototype.setButtonImagePathValue = function(buttonImageValue)
{
	if( buttonImageValue == null || typeof buttonImageValue == "undefined" )
		return;
	
	if (!this.opts)
		this.opts = {};
	
	var oldButtonValue = this.opts.buttonImage;
	this.opts.buttonImage = buttonImageValue;
	
	if( oldButtonValue != this.opts.buttonImage)
		this.updateOptions(this.widgetType, this.opts);
}

//--------------------------------------------------------------------
// FUNCTION:
//  	getDateFormatIndex
//
// DESCRIPTION:
//  	This method will return the index of the dateformat List element
//
// ARGUMENTS:
//  	None
//
// RETURNS:
//  	Number: The value of the index of dateformat list
//--------------------------------------------------------------------

JQuery.DesignTime.Widget.Datepicker.prototype.getDateFormatIndex = function()
{
	if( this.opts && this.opts.dateFormat != null && typeof this.opts.dateFormat != 'undefined' )
	{
		var dateFormatArray = this.getDateFormatArray();
		for( var i = 0; i < dateFormatArray.length; i++ )
		{
			if( this.opts.dateFormat.toString() == dateFormatArray[i] )
				return i;
		}
	}
	return 0;
}

//--------------------------------------------------------------------
// FUNCTION:
//  	setDateFormatIndex
//
// DESCRIPTION:
//  	Here we set the opts object from the new index set in the dateformat
//		list.
//
// ARGUMENTS:
//  	None
//
// RETURNS:
//  	None
//--------------------------------------------------------------------

JQuery.DesignTime.Widget.Datepicker.prototype.setDateFormatIndex = function(dateFormatIndex)
{
	if( dateFormatIndex == null || typeof dateFormatIndex == "undefined" )
		return;
		
	if (!this.opts)
		this.opts = {};
	
	var oldDateValue = this.opts.dateFormat;
	
	if( dateFormatIndex == 0 )
		this.opts.dateFormat = null;
	else
		this.opts.dateFormat = this.getDateFormatArray()[dateFormatIndex];
	
	if( oldDateValue != this.opts.dateFormat )
		this.updateOptions(this.widgetType, this.opts);	
}

//--------------------------------------------------------------------
// FUNCTION:
//  	getChangeMonthValue
//
// DESCRIPTION:
//  	This method returns the value of the changemonth attribute in the widget constructor.
//		If user changes the changemonth value in the code. This is where we 'read' that updated 
//		value from the object
//
// ARGUMENTS:
//  	None
//
// RETURNS:
//  	Boolean: The value of the changemonth attribute as boolean
//--------------------------------------------------------------------

JQuery.DesignTime.Widget.Datepicker.prototype.getChangeMonthValue = function()
{	
	if( this.opts && this.opts.changeMonth != null && typeof this.opts.changeMonth != 'undefined' )
	{
		return (this.opts.changeMonth == true);
	}
	return false;
}

//--------------------------------------------------------------------
// FUNCTION:
//  	setChangeMonthValue
//
// DESCRIPTION:
//  	When a new value for changeMonth is attained for the changeMonth attribute from the PI
//		we have to update our opts object with this new changeMonth value and initiate an update cycle
//		for this change to be reflected in code.
//
// ARGUMENTS:
//  	None
//
// RETURNS:
//  	None
//--------------------------------------------------------------------

JQuery.DesignTime.Widget.Datepicker.prototype.setChangeMonthValue = function(changeMonthValue)
{	
	if( changeMonthValue == null || typeof changeMonthValue == "undefined" )
		return;

	if (!this.opts)
		this.opts = {};
	
	var oldMonthValue = this.opts.changeMonth;
	
	if( changeMonthValue == true )
	{
		this.opts.changeMonth = true;
	}	
	else
	{
		this.opts.changeMonth = null;
	}
	
	if( oldMonthValue != this.opts.changeMonth )
		this.updateOptions(this.widgetType, this.opts);
}

//--------------------------------------------------------------------
// FUNCTION:
//  	getShowButtonImageValue
//
// DESCRIPTION:
//		Here we find the value of the show button Image check box using the showOn value	  	
//
// ARGUMENTS:
//  	None
//
// RETURNS:
//  	Boolean: Whether the showbuttonImage checkbox should be checked
//--------------------------------------------------------------------

JQuery.DesignTime.Widget.Datepicker.prototype.getShowButtonImageValue = function()
{
	if( this.opts && this.opts.showOn != null && typeof this.opts.showOn != 'undefined' )
	{
		if( this.opts.showOn.toString() == "button" || this.opts.showOn.toString() == "both" )
			return true;
	}
	return false;
}

//--------------------------------------------------------------------
// FUNCTION:
//  	setShowButtonImageValue
//
// DESCRIPTION:
//  	Argument is value of the showon checkbox. If it is true, we set the animate 
//		option to 'both'. On false we set it to null signifying that 
//		animate value should be removed from constructor
//
// ARGUMENTS:
//  	None
//
// RETURNS:
//  	N/A
//--------------------------------------------------------------------

JQuery.DesignTime.Widget.Datepicker.prototype.setShowButtonImageValue = function(showButtonImageValue)
{	
	if( showButtonImageValue == null || typeof showButtonImageValue == "undefined" )
		return;
		
	if (!this.opts)
		this.opts = {};
		
	var oldShowValue = this.opts.showOn;	
		
	if( showButtonImageValue == true )
	{
		this.opts.showOn = "both";
	}	
	else
	{
		this.opts.showOn = null;
		this.opts.buttonImage = null;
	}
	
	if( oldShowValue != this.opts.showOn )
		this.updateOptions(this.widgetType, this.opts);	
}

//--------------------------------------------------------------------
// FUNCTION:
//  	getMinDateValue
//
// DESCRIPTION:
//  	This method returns the value of the mindate attribute in the widget constructor.
//		If user changes the mindate value in the code. This is where we 'read' that updated 
//		value from the object
//
// ARGUMENTS:
//  	None
//
// RETURNS:
//  	String: The value of the mindate attribute as string
//--------------------------------------------------------------------

JQuery.DesignTime.Widget.Datepicker.prototype.getMinDateValue = function()
{
	if( this.opts && this.opts.minDate != null && typeof this.opts.minDate != 'undefined' )
	{
		return this.opts.minDate;
	}
	return "";
}

//--------------------------------------------------------------------
// FUNCTION:
//  	setMinDateValue
//
// DESCRIPTION:
//  	When a new value for minDate is attained for the minDate attribute from the PI
//		we have to update our opts object with this new minDate value and initiate an update cycle
//		for this change to be reflected in code.
//
// ARGUMENTS:
//  	None
//
// RETURNS:
//  	None
//--------------------------------------------------------------------

JQuery.DesignTime.Widget.Datepicker.prototype.setMinDateValue = function(minDateValue)
{
	if( minDateValue == null || typeof minDateValue == "undefined" )
		return;
	
	if (!this.opts)
		this.opts = {};
	
	var oldMinValue = this.opts.minDate;
	
	if( minDateValue == "" || parseInt(minDateValue).toString() == 'NaN' )
	{
		this.opts.minDate = null;
	}	
	else
	{
		this.opts.minDate = parseInt(minDateValue);
	}
	
	if( oldMinValue != this.opts.minDate )
		this.updateOptions(this.widgetType, this.opts);	
}

//--------------------------------------------------------------------
// FUNCTION:
//  	getChangeYearValue
//
// DESCRIPTION:
//  	This method returns the value of the changeYear attribute in the widget constructor.
//		If user changes the changeYear value in the code. This is where we 'read' that updated 
//		value from the object
//
// ARGUMENTS:
//  	None
//
// RETURNS:
//  	Boolean: The value of the source attribute as boolean
//--------------------------------------------------------------------

JQuery.DesignTime.Widget.Datepicker.prototype.getChangeYearValue = function()
{
	if( this.opts && this.opts.changeYear != null && typeof this.opts.changeYear != 'undefined' )
	{
		return this.opts.changeYear;
	}
	return false;
}

//--------------------------------------------------------------------
// FUNCTION:
//  	setChangeYearValue
//
// DESCRIPTION:
//  	When a new value for changeYear is attained for the changeYear attribute from the PI
//		we have to update our opts object with this new changeYear value and initiate an update cycle
//		for this change to be reflected in code.
//
// ARGUMENTS:
//  	None
//
// RETURNS:
//  	None
//--------------------------------------------------------------------

JQuery.DesignTime.Widget.Datepicker.prototype.setChangeYearValue = function(changeYearValue)
{
	if( changeYearValue == null || typeof changeYearValue == "undefined" )
		return;
		
	if (!this.opts)
		this.opts = {};
		
	var oldYearValue = this.opts.changeYear;	
		
	if( changeYearValue == true )
	{
		this.opts.changeYear = true;
	}	
	else
	{
		this.opts.changeYear = null;
	}
	
	if( oldYearValue != this.opts.changeYear )
		this.updateOptions(this.widgetType, this.opts);
}

//--------------------------------------------------------------------
// FUNCTION:
//  	getMaxDateValue
//
// DESCRIPTION:
//  	This method returns the value of the maxDate attribute in the widget constructor.
//		If user changes the maxDate value in the code. This is where we 'read' that updated 
//		value from the object
//
// ARGUMENTS:
//  	None
//
// RETURNS:
//  	String: The value of the maxDate attribute as string
//--------------------------------------------------------------------

JQuery.DesignTime.Widget.Datepicker.prototype.getMaxDateValue = function()
{
	if( this.opts && this.opts.maxDate != null && typeof this.opts.maxDate != 'undefined' )
	{
		return this.opts.maxDate;
	}
	return "";
}

//--------------------------------------------------------------------
// FUNCTION:
//  	setMaxDateValue
//
// DESCRIPTION:
//  	When a new value for maxDate is attained for the maxDate attribute from the PI
//		we have to update our opts object with this new maxDate value and initiate an update cycle
//		for this change to be reflected in code.
//
// ARGUMENTS:
//  	None
//
// RETURNS:
//  	None
//--------------------------------------------------------------------

JQuery.DesignTime.Widget.Datepicker.prototype.setMaxDateValue = function(maxDateValue)
{
	if( maxDateValue == null || typeof maxDateValue == "undefined" )
		return;
	
	if (!this.opts)
		this.opts = {};
		
	var oldDateValue = this.opts.maxDate;	
	
	if( maxDateValue == "" || parseInt(maxDateValue).toString() == 'NaN' )
	{
		this.opts.maxDate = null;
	}	
	else
	{
		this.opts.maxDate = parseInt(maxDateValue);
	}
		
	if( oldDateValue != this.opts.maxDate )	
		this.updateOptions(this.widgetType, this.opts);	
}

//--------------------------------------------------------------------
// FUNCTION:
//  	getShowButtonValue
//
// DESCRIPTION:
//  	This method returns the value of the showButtonpanel attribute in the widget constructor.
//		If user changes the showButtonpanel value in the code. This is where we 'read' that updated 
//		value from the object
//
// ARGUMENTS:
//  	None
//
// RETURNS:
//  	Boolean: The value of the showButtonpanel attribute as boolean
//--------------------------------------------------------------------

JQuery.DesignTime.Widget.Datepicker.prototype.getShowButtonPanelValue = function()
{
	if( this.opts && this.opts.showButtonPanel != null && typeof this.opts.showButtonPanel != 'undefined' )
	{
		return this.opts.showButtonPanel;
	}
	return false;
}

//--------------------------------------------------------------------
// FUNCTION:
//  	setShowButtonPanelValue
//
// DESCRIPTION:
//  	When a new value for showButtonPanel is attained for the showButtonPanel attribute from the PI
//		we have to update our opts object with this new showButtonPanel value and initiate an update cycle
//		for this change to be reflected in code.
//
// ARGUMENTS:
//  	None
//
// RETURNS:
//  	None
//--------------------------------------------------------------------

JQuery.DesignTime.Widget.Datepicker.prototype.setShowButtonPanelValue = function(showButtonPanel)
{
	if( showButtonPanel == null || typeof showButtonPanel == "undefined" )
		return;

	if (!this.opts)
		this.opts = {};
		
	var oldButtonValue = this.opts.showButtonPanel;	
	
	if( showButtonPanel == true )
	{
		this.opts.showButtonPanel = true;
	}	
	else
	{
		this.opts.showButtonPanel = null;
	}
	
	if( this.opts.showButtonPanel != oldButtonValue )
		this.updateOptions(this.widgetType, this.opts);
}

//--------------------------------------------------------------------
// FUNCTION:
//  	getMonthValue
//
// DESCRIPTION:
//  	This method returns the value of the numberOfMonths attribute in the widget constructor.
//		If user changes the numberOfMonths value in the code. This is where we 'read' that updated 
//		value from the object
//
// ARGUMENTS:
//  	None
//
// RETURNS:
//  	String: The value of the numberOfMonths attribute as string
//--------------------------------------------------------------------

JQuery.DesignTime.Widget.Datepicker.prototype.getMonthValue = function()
{
	if( this.opts && this.opts.numberOfMonths != null && typeof this.opts.numberOfMonths != 'undefined' )
	{
		return this.opts.numberOfMonths;
	}
	return "";
}

//--------------------------------------------------------------------
// FUNCTION:
//  	setMonthValue
//
// DESCRIPTION:
//  	When a new value for numberOfMonths is attained for the numberOfMonths attribute from the PI
//		we have to update our opts object with this new numberOfMonths value and initiate an update cycle
//		for this change to be reflected in code.
//
// ARGUMENTS:
//  	None
//
// RETURNS:
//  	None
//--------------------------------------------------------------------

JQuery.DesignTime.Widget.Datepicker.prototype.setMonthValue = function(monthValue)
{	
	if( monthValue == null || typeof monthValue == "undefined" )
		return;
		
	if (!this.opts)
		this.opts = {};
		
	var oldMonthValue = this.opts.numberOfMonths;	
		
	if( monthValue == "" || monthValue == "1" || parseInt(monthValue).toString() == 'NaN' )
	{
		this.opts.numberOfMonths = null;
	}	
	else
	{
		this.opts.numberOfMonths = parseInt(monthValue);
	}
	
	if( oldMonthValue != this.opts.numberOfMonths )
		this.updateOptions(this.widgetType, this.opts);	
}


//--------------------------------------------------------------------
// FUNCTION:
//   getAssets
//
// DESCRIPTION:
//   Static function that returns the assets to be applied to page
//
// ARGUMENTS:
//   None
//
// RETURNS:
//   (array of objects)
//--------------------------------------------------------------------

JQuery.DesignTime.Widget.Datepicker.getAssets = function()
{
	var assets = new Array();
	
	assetObject = new Object();
	assetObject.fullPath = jQDatepickerImagesPath;
	assetObject.file = jQDatepickerImagesFile;
	assetObject.type = "";
	assets.push(assetObject);
	
	assetObject = new Object();
	assetObject.fullPath = jQCoreCssPath;
	assetObject.file = jQCoreCssFile;
	assetObject.type = "link";
	assets.push(assetObject);

	assetObject = new Object();
	assetObject.fullPath = jQCssThemePath;
	assetObject.file = jQCssThemeFile;
	assetObject.type = "link";
	assets.push(assetObject);
	
	assetObject = new Object();
	assetObject.fullPath = jQDatepickerCssWidgetPath;
	assetObject.file = jQDatepickerCssWidgetFile;
	assetObject.type = "link";
	assets.push(assetObject);
	
	assetObject = new Object();
	assetObject.fullPath = jQMainPath;
	assetObject.file = jQMainFile;
	assetObject.type = "javascript";
	assets.push(assetObject);
	
	assetObject = new Object();
	assetObject.fullPath = jQDatepickerJsPath;
	assetObject.file = jQDatepickerJsFile;
	assetObject.type = "javascript";
	assets.push(assetObject);
	
	return (assets);
	
};

//--------------------------------------------------------------------
// FUNCTION:
//   refresh
//
// DESCRIPTION:
//   None
//
// ARGUMENTS:
//   Syncs up the internal state of the design-time widget object
//   with the markup that currently exists in the design view.
//
//   This method gets called from the translator if a design-time
//   object already exists for a specific widget ID, and from various
//   methods in the Datepicker property inspector.
//
// RETURNS:
//   N/A
//--------------------------------------------------------------------

JQuery.DesignTime.Widget.Datepicker.prototype.refresh = function()
{
  if (!this.canRefresh)
	return;
	
	if (!this.opts)
		this.opts = {};
	var consArgs = this.getConstructorArgs(this.widgetType);
	
	this.opts = consArgs; 
  this.init(this.element_id);  
};


//--------------------------------------------------------------------
// FUNCTION:
//   JQuery.DesignTime.Widget.Datepicker.getNewDatepickerSnippet
//
// DESCRIPTION:
//   Static utility function that returns a string containing the
//   markup for a complete Datepicker.
//
// ARGUMENTS:
//  id - string - The string to use as the widget's id attribute.
//
// RETURNS:
//   String that is the HTML markup fragment for the panel.
//--------------------------------------------------------------------

JQuery.DesignTime.Widget.Datepicker.getNewDatepickerSnippet = function(id)
{
  var dpSnippet = '<input type="text" id="' + id + '"></input>';
  return dpSnippet;
};

//--------------------------------------------------------------------
// FUNCTION:
//   JQuery.DesignTime.Widget.Datepicker.getNewDatepickerConstructorSnippet
//
// DESCRIPTION:
//   Static utility function that returns a string that contains the
//   constructor snippet for creating a JQuery widget with the specified id.
//
// ARGUMENTS:
//  id - string - The id of the widget markup to insert into the
//                constructor snippet.
//
// RETURNS:
//   String containing JS that is the constructor call to create the
//   widget.
//--------------------------------------------------------------------

JQuery.DesignTime.Widget.Datepicker.getNewDatepickerConstructorSnippet = function(id)
{
  return ' $(function() {\n\t$( "#' + id + '" ).datepicker(); \n});';
 /* $(function() {
		$( "#Datepicker1" ).Datepicker();
	});*/
};

//--------------------------------------------------------------------
// FUNCTION:
//  	initLocaleArray
//
// DESCRIPTION:
//  	Initializes the locale array with predefined values.
//
// ARGUMENTS:
//  	None
//
// RETURNS:
//  	None
//--------------------------------------------------------------------

JQuery.DesignTime.Widget.Datepicker.prototype.initLocaleArray = function()
{
	this.localeArray.push("English");
	this.localeArray.push("Deutsch");
	this.localeArray.push("Español");
	this.localeArray.push("Français");
	this.localeArray.push("Italiano");
	this.localeArray.push("Nederlands");
	this.localeArray.push("Português");
	this.localeArray.push("русский");
	this.localeArray.push("Svenska");
	this.localeArray.push("简体中文");
	this.localeArray.push("繁體中文");
	this.localeArray.push("日本語");
}
//--------------------------------------------------------------------
// FUNCTION:
//  	initLocaleArray
//
// DESCRIPTION:
//  	Initializes the locale value array with values that the $.datepicker.regional array accepts 
//		as attributes. This values must correspond to the localeArray options
//
// ARGUMENTS:
//  	None
//
// RETURNS:
//  	None
//--------------------------------------------------------------------

JQuery.DesignTime.Widget.Datepicker.prototype.initLocaleValueArray = function()
{
	this.localeValueArray.push("en-GB");
	this.localeValueArray.push("de");
	this.localeValueArray.push("es");
	this.localeValueArray.push("fr");
	this.localeValueArray.push("it");
	this.localeValueArray.push("nl");
	this.localeValueArray.push("pt");
	this.localeValueArray.push("ru");
	this.localeValueArray.push("sv");
	this.localeValueArray.push("zh-CN");
	this.localeValueArray.push("zh-TW");
	this.localeValueArray.push("ja");
}

//--------------------------------------------------------------------
// FUNCTION:
//  	initLocaleArray
//
// DESCRIPTION:
//  	Initializes the dateformat array with predefined values.
//
// ARGUMENTS:
//  	None
//
// RETURNS:
//  	None
//--------------------------------------------------------------------

JQuery.DesignTime.Widget.Datepicker.prototype.initDateFormatArray = function()
{
	this.dateFormatArray.push("mm/dd/yy");
	this.dateFormatArray.push("yy-mm-dd");
	this.dateFormatArray.push("d M, y");
	this.dateFormatArray.push("d MM, y");
	this.dateFormatArray.push("DD, d MM, yy");
}

//--------------------------------------------------------------------
// FUNCTION:
//  	getDateFormatArray
//
// DESCRIPTION:
//  	Return the dateformat Array containing all possible values for 'dateformat'
//		attribute of the constructor object
//
// ARGUMENTS:
//  	None
//
// RETURNS:
//  	N/A
//--------------------------------------------------------------------


JQuery.DesignTime.Widget.Datepicker.prototype.getDateFormatArray = function()
{
	return this.dateFormatArray;
}

//--------------------------------------------------------------------
// FUNCTION:
//  	getLocaleArray
//
// DESCRIPTION:
//  	Return the locale Array containing all possible values for languages
//		the user can set for the datepicker
//
// ARGUMENTS:
//  	None
//
// RETURNS:
//  	N/A
//--------------------------------------------------------------------

JQuery.DesignTime.Widget.Datepicker.prototype.getLocaleArray = function()
{
	return this.localeArray;
}
//--------------------------------------------------------------------
// FUNCTION:
//  	getLocaleValueArray
//
// DESCRIPTION:
//  	Return the locale Value Array containing all possible values for the $.datepicker.regional
//		array of jQuery 
//
// ARGUMENTS:
//  	None
//
// RETURNS:
//  	N/A
//--------------------------------------------------------------------

JQuery.DesignTime.Widget.Datepicker.prototype.getLocaleValueArray = function()
{
	return this.localeValueArray;
}
JQuery.DesignTime.Widget.Datepicker.prototype.updateOptions = function(widgetType, opts)
{
	var consRegExp = this.getConstructorRegExp();
	var scriptTags = this.dom.getElementsByTagName("script");
	for( var i = 0; i < scriptTags.length; i++ )
	{
		var sTag = scriptTags[i];
		var src = sTag.innerHTML;
		if(!src)
			continue;

		var htmlSplitStrings = src.split(consRegExp);
		if( htmlSplitStrings.length == 2 )
		{
			var preHtml = htmlSplitStrings[0];
			var postHtml = htmlSplitStrings[1];
			var constructorString = consRegExp.exec(src)[0];
		
			if(  constructorString && constructorString.length )
			{
				var newObjectString 			= ""
				var newConstructorString 	= "";
				var preConstructorString 	= "";
				var postConstructorString 	= "";
				
				newObjectString = JQuery.DesignTime.Widget.Base.replaceWithUpdatedOption(opts);
				if( newObjectString == null )
					return;
				
				constructorParseArray = JQuery.DesignTime.Editing.Utils.getContainedString (constructorString, '(', ')', true);
				
				if(!constructorParseArray)
					return;
				
				preConstructorString = constructorString.slice(0, constructorParseArray[1]);
				postConstructorString = constructorString.slice(constructorParseArray[2], constructorString.length);
				
				if( LOCALEOPTION == "" )
				{
					if( newObjectString == "" )
						newConstructorString = preConstructorString + "()" + postConstructorString
					else
						newConstructorString = preConstructorString + "({\n" + newObjectString + "\t})" + postConstructorString
					
				}
				else
				{
					if( newObjectString == "" )
						newConstructorString = preConstructorString + "($.datepicker.regional['" + LOCALEOPTION + "'])" + postConstructorString
					else
						newConstructorString = preConstructorString + "(\n\t\t$.extend(\n\t\t$.datepicker.regional['" + LOCALEOPTION + "'],\n" + "\t\t{\n" + newObjectString + "\t\t}\n\t\t)\n\t\t)" + postConstructorString
				}
					
				this.canRefresh = false;
				sTag.innerHTML = preHtml + newConstructorString + postHtml;
				this.canRefresh = true;
			}
			else
			{
				if (dw.isDebugBuild())
				{
					alert("Regular expression fail!");
				}
			}

			return;
		}
	}
	
	return;
}
JQuery.DesignTime.Widget.Datepicker.prototype.getConstructorArgs = function (widgetType)
{
	var consRegExp = this.getConstructorRegExp();
	var scriptTags = this.dom.getElementsByTagName("script");
	for( var i = 0; i < scriptTags.length; i++ )
	{
		var sTag = scriptTags[i];
		var src = sTag.innerHTML;
		if(!src)
			continue;
			
		var matchStrings = src.match(consRegExp);
		if( matchStrings && matchStrings.length )
		{
			var args = JQuery.DesignTime.Editing.Utils.parseForJsOptions(matchStrings[0], widgetType);
			var localeRegExp = /\$\.datepicker\.regional\[\s*["'](.*)["']\s*\]/g;
			
			//We should not have to reset lastIndex of regExp to 0 right after creation. But for some reason it seems to retain the value of last call. Hence the need for this explicit set
			localeRegExp.lastIndex = 0;
			var localeMatchArray = localeRegExp.exec(matchStrings[0]);
			
			if( localeMatchArray && localeMatchArray.length > 0 )
			{
				LOCALEOPTION = localeMatchArray[1];
			}
			else
			{
				LOCALEOPTION = "";
			}
			
			return args;
		}
	}
	return null;
}

//Overriding translator's delete method with our own so that we can also separately remove datepicker localefiles in case widget gets deleted
JQuery.DesignTime.Widget.Datepicker.getDeleteWidgetCallback = function (removeString, widgetId)
{
	var deleteFunction = function(e)
	{
		var targetDom = e.target.ownerDocument;			
		var scriptTags = targetDom.getElementsByTagName("script");
		for( var i = 0; i < scriptTags.length; i++ )
		{
			var str = scriptTags[i].innerHTML;
			var index = str.indexOf(removeString);
			if( index >= 0 )
			{
				var strBefore = str.substr(0, index);
				var strAfter = str.substr(index+removeString.length);
				while( strBefore.length > 0 && ( strBefore.charAt(strBefore.length-1) == ' ' ||
												strBefore.charAt(strBefore.length-1) == '\t' ||
												strBefore.charAt(strBefore.length-1) == '\n' ||
												strBefore.charAt(strBefore.length-1) == '\r' ) )
				{
					strBefore = strBefore.substr(0, strBefore.length-1);
				}
				// We'll store the new InnerHTML to newInnerHTML and we'll decide later whether we'll replace the inner value with this
				// one or we'll simply remove the SCRIPT tag.
				var newInnerHTML = strBefore + strAfter;

				// Look if there is any valid JS code remining in the SCRIPT tag; of empty (or only comments were found) => go and remove it
				var tempInnerHTML = newInnerHTML;
				if (tempInnerHTML && tempInnerHTML.replace)
				{
					tempInnerHTML = tempInnerHTML.replace(/[\r\n]*(?:\<\!\-\-|\/\/\-\-\>)[\r\n]*/gi, "");
					tempInnerHTML = tempInnerHTML.replace(/[\r\n\s\t]*/gi, "")
				}
				
				// If the InnerHTML is empty, we'll remove the entire SCRIPT tag.
				if (tempInnerHTML === "")
				{
					scriptTags[i].outerHTML = "";
				}
				else
				{
					scriptTags[i].innerHTML = newInnerHTML;
				}
				
				// Get WidgetManager instance
				var widgetMgr = JQuery.DesignTime.Widget.Manager.getManagerForDocument(targetDom);
				
				if (!widgetMgr)
					return;
			
				// Search for widgets of the same type in the page, but different from the current one (compared by ID)
				var count = 0;
				var allWidgets = widgetMgr.getAllWidgets('datepicker');
				for (var widget in allWidgets) {
					if (widget != widgetId)
					{
						count++;
						break;
					}
				}
				
				if (count == 0)
				{
					// There are no more widgets remaining in the page of the current type, we'll remove the assets as well
					  
					var assets = JQuery.DesignTime.Widget.Datepicker.getAssets();
					
					//Add the locale object to the array of all assets to be removed
					var localeAsset = {};
					localeAsset.type = "locale";
					localeAsset.file = "jquery.ui.datepicker-" + LOCALEOPTION + ".js";
					assets.push(localeAsset);
					
					var tags = new Array();
					tags = tags.concat(targetDom.getElementsByTagName("script"));
					tags = tags.concat(targetDom.getElementsByTagName("link"));
					
					for (var j=0; j<tags.length; j++)
					{
					
						var tag = tags[j];
						if (tag && tag.getAttribute)
						{
							// Get the value to search; the attribute is different according to tag name: script or link
							var valueToSearch = tag.getAttribute("src");
							if (!valueToSearch)
							{
								valueToSearch = tag.getAttribute("href");
							}

							// Once we have a value, we test it against all assets
							if( valueToSearch && valueToSearch.match(/ui/) )
							{
								//Adding a special case for jquery.ui.theme.css and jquery.ui.core.css which should not be removed on removal of a widget as these files are commonly shared amongst widgets
								if (!valueToSearch.match(/jquery\.ui\.theme\.min\.css/) && !valueToSearch.match(/jquery\.ui\.core\.min\.css/))
								{	
									for (var k=0; k<assets.length; k++)
									{
										if (assets[k].type)
										{
											// If the current tag's value matches an asset we'll remove the tag from page
											if (valueToSearch.match && valueToSearch.match(new RegExp("(?:^|[\\/\\\\])" + dwscripts.escRegExpChars(assets[k].file) + "$", "gi")))
											{
												tag.outerHTML = "";
												break;
											}
										}
									}
								}
							}
						}
					}
				}
			}
		}
	};
	return deleteFunction;
}