function dowjsGrid(
	$gridId,
	$pagerId,
	$request_url
	)
{
	$("#"+$gridId)
		.jqGrid({
			width: 889,
			height: 400,
			url: $request_url,
			datatype: 'xml',
			mtype: 'GET',
			colNames:['TITLE', 'PRICE', 'STD. PRICE', 'MAX ORD. ALLOWED', 'EXP. DATE', 'ZIP', 'Status'],
			colModel :[
				{name:'deal_title', index:'deal_title', sortable:false, align:"center", editable: false},
				{name:'deal_price', index:'deal_price', sortable:false, align:"left", editable: false},
				{name:'deal_standard_price', index:'deal_standard_price', sortable:false, align:"left", editable: false},
				{name:'deal_max_cansell', index:'deal_max_cansell', sortable:false, align:"center", editable: false},
				{name:'deal_expiration_date', index:'deal_expiration_date', sortable:false, align:"center", editable: false},
				{name:'deal_primary_zip', index:'deal_primary_zip', width:50, sortable:false, align:"center", editable: false},
				{name:'live', index:'live', width:60, sortable:false, align:"center", editable: false},
			],
			pager: '#'+$pagerId,
			rowNum:25,
			rowList:[25,50,100],
			sortname: 'deal_expiration_date',
			sortorder: 'asc',
			viewrecords: true,
			caption: 'Deal Of the Week for Provider',
			subGrid : true,
			subGridRowExpanded: function(subgrid_id, row_id)
			{
				var subgrid_table_id, pager_id, $sub_request_url, style;
				subgrid_table_id = subgrid_id+"_t";
				pager_id         = "p_"+subgrid_table_id;
				$sub_request_url = 'getdow.ajax.php?did='+row_id;
				style            = 'line-height:20px; height:20px; display:block; float:left;margin:0px; margin-right:5px;';
				$("#"+subgrid_id)
					.html(
						"<div style='height:30px;'>"+
							"<span style='"+style+"border-bottom: solid 5px transparent;'>Legend:</span>"+
							"<span style='"+style+"border-bottom: solid 5px red;'>Cancelled</span>"+
							"<br style='clear:left;' />"+
						"</div>"+
						"<table id='"+subgrid_table_id+"'></table>"+
						"<div id='"+pager_id+"'></div>"
					);

				$('#'+subgrid_table_id)
					.jqGrid({
						width: 810,
						height: '100%',
						url: $sub_request_url,
						datatype: 'xml',
						mtype: 'GET',
						colNames:['User Id','First','Last','Email','Phone','Total','Qnty','Buy Date','Refund Date','Refund'],
						colModel :[
							{name:'user_id', index:'user_id', width:60, sortable:false, align:"center", editable: false},
							{name:'firstName', index:'firstName', width:60, sortable:false, align:"center", editable: false},
							{name:'lastName', index:'lastName', width:60, sortable:false, align:"center", editable: false},
							{name:'email', index:'email', width:140, sortable:false, align:"center", editable: false},
							{name:'ContactPhone', index:'ContactPhone', width:100, sortable:false, align:"center", editable: false},
							{name:'total', index:'total', width:70, sortable:false, align:"center", editable: false},
							{name:'quantity', index:'quantity', width:50, sortable:false, align:"center", editable: false, hidden:true},
							{name:'transaction_date', index:'transaction_date', width:80, sortable:false, align:"center", editable: false},
							{name:'cancelDate', index:'cancelDate', sortable:false, align:"center", editable: false, hidden:true},
							{name:'cancelled', index:'cancelled', width:50, sortable:false, align:"center", editable: false, hidden:true},
						],
						pager: '#'+pager_id,
						rowNum:25,
						rowList:[25,50,100],
						sortname: 'transaction_date',
						sortorder: 'asc',
						viewrecords: true,
						caption: 'Purchasers of Deal of the Week',
						afterInsertRow: function(rowid, aData, rowelem)
						{
							if(aData.cancelled =='1')
							{
								$('#'+rowid)
									.css('background-color','red')
									.css('color','white')
									.css('background-image','none')
									.click(function(){
										$(this).removeClass('ui-state-highlight');
										return false;
									});
							}
						} // ends function afterInsertRow
					})
					.navGrid('#'+pager_id, {edit:false,add:false,del:false,search:false,refresh:true})
					.navButtonAdd('#'+pager_id,{
						caption:"Export MS Excel",
						buttonicon:"ui-icon-circle-arrow-s",
						onClickButton: function(){
							location.href=$sub_request_url+'&exportit=true';
						},
						position:"last"
					}).navButtonAdd('#'+pager_id,{
						caption:"Export CSV",
						buttonicon:"ui-icon-circle-arrow-s",
						onClickButton: function()
						{
							location.href=$sub_request_url+'&exportit=true&export_type=csv';
						},
						position:"last"
					})
			} // ends function subGridRowExpanded
		})
		.navGrid('#'+$pagerId, {edit:false,add:false,del:false,search:false,refresh:true})
		.navButtonAdd('#'+$pagerId,{
			caption:"Export MS Excel",
			buttonicon:"ui-icon-circle-arrow-s",
			onClickButton: function()
			{
				location.href=$request_url+'&exportit=true';
			},
			position:"last"
		}).navButtonAdd('#'+$pagerId,{
			caption:"Export CSV",
			buttonicon:"ui-icon-circle-arrow-s",
			onClickButton: function()
			{
				location.href=$request_url+'&exportit=true&export_type=csv';
			},
			position:"last"
		});
}

//Written by Ran Zafrir,
//2010-05
//
var DOW =
{
	//Private Properties:
	_isContactFormInitialized : false,
	_isWaitListFormInitialized : false,
	_waitListPopupDiv : null,
	_waitListMessageObj : null,
	_dealID : null,
	_contactFormErrorClass: 'dowError',
	_waitListFormErrorClass: 'error',


	initContactForm: function(
		url,
		slideTriggers
		)
	{
		if (this._isContactFormInitialized)
		{
			return;
		}

		var self = this;

		//Run toggleContactForm() when elements matching specified selectors are clicked
		$(slideTriggers).click(
			function()
			{
				self.toggleContactForm();
				return false;
			}
		);

		$('#backgroundPopup').click(
			function()
			{
				self.hideContactForm();
			}
		);

		//animation for same page links #
		$('a[href*=#]').each(
			function()
			{
				if (
					location.pathname.replace(/^\//,'') == this.pathname.replace(/^\//,'') &&
					location.hostname == this.hostname &&
					this.hash.replace(/#/,'')
					)
				{
					var $targetId = $(this.hash), $targetAnchor = $('[name=' + this.hash.slice(1) +']');
					var $target = $targetId.length ? $targetId : $targetAnchor.length ? $targetAnchor : false;
					if ($(this.hash).length)
					{
						$(this).click(
							function(event)
							{
								var targetOffset = $(this.hash).offset().top;
								var target = this.hash;
								event.preventDefault();
								$('html, body').animate({scrollTop: targetOffset}, 500);
								return false;
							}
						);
					}
				}
			}
		);

		$('#contactForm form :submit').click(
			function()
			{
				if ($('#contactForm .loader:visible').length == 1)
				//If request already made - wait till that has been processed
				{
					return false;
				}

				//First make sure all input fields are valid:
				//Validation.validateInput({
				//	input: document.getElementById('dowName'),
				//	validationFunction: Generics.validation.validateNonEmpty
				//	//errorClass: 'error'
				//	//beforeSetError: function(input, validationFunction) { }
				//	//beforeRemoveError: function(input, validationFunction) { }
				//});
				Validation.validateInput({
					input: document.getElementById('dowEmail'),
					validationFunction: Generics.validation.validateEmail,
					errorClass: DOW._contactFormErrorClass,
					beforeSetError: function(input, validationFunction)
					{
						$(input).parent().append('<span class="errorDescription">You\'ve specified an invalid e-mail</span>');
					},
					beforeRemoveError: function(input, validationFunction)
					{
						$(input).next('.errorDescription').remove();
					}
				});
				Validation.validateInput({
					input: document.getElementById('dowEmailConf'),
					validationFunction: function(email)
					{
						if (document.getElementById('dowEmail').value == email)
						{
							return true;
						}

						return false;
					},
					errorClass: DOW._contactFormErrorClass,
					beforeSetError: function(input, validationFunction)
					{
						$(input).parent().append('<span class="errorDescription">The e-mail and the e-mail confirmation fields must match !</span>');
					},
					beforeRemoveError: function(input, validationFunction)
					{
						$(input).next('.errorDescription').remove();
					}
				});
				Validation.validateInput({
					input: document.getElementById('dowZip'),
					validationFunction: Generics.validation.validateZipCode,
					errorClass: DOW._contactFormErrorClass,
					beforeSetError: function(input, validationFunction)
					{
						$(input).parent().append('<span class="errorDescription">You\'ve specified an invalid zip-code</span>');
					},
					beforeRemoveError: function(input, validationFunction)
					{
						$(input).next('.errorDescription').remove();
					}
				});
				if (
					$('#dowName').hasClass(DOW._contactFormErrorClass) ||
					$('#dowEmail').hasClass(DOW._contactFormErrorClass) ||
					$('#dowEmailConf').hasClass(DOW._contactFormErrorClass) ||
					$('#dowZip').hasClass(DOW._contactFormErrorClass)
					)
				{
					//Invalid Input !

					return false;
				}

				//All inputs are valid - submit data to server
				//var userName = document.getElementById('dowName').value;
				var userEmail = document.getElementById('dowEmail').value;
				var userZip = document.getElementById('dowZip').value;

				$('#contactForm .loader').show();
				AjaxHelpers.sendRequest({
					data:
						'data=' +
						Generics.serialize({
							data: [
								userZip,
								userEmail
								//userName
							],
							separator: 'A',
							encodeFunction: function(param){ return Base64.encode(param); }
							//ascendingOrder: false,
							//method: 0
						})
						,
					url: url,
					//type: null,
					//serverFunction: null,
					onValid: function(data, textStatus)
					{
						$('#contactForm form :input').not(':submit').val('');
						self.hideContactForm();
						DialogFactory.openDialog({
							message: data,
							title: 'Request Submitted',
							modal: true
							//buttons
							//beforeclose
							//close
							//width
							//height
							//dialogClass
							});
					},
					onExplicitlyInvalid: function(data, textStatus)
					{
						DialogFactory.openDialog({
							message: data,
							title: 'Request Failed',
							modal: true
							//buttons
							//beforeclose
							//close
							//width
							//height
							//dialogClass
							});
					},
					onImplicitlyInvalid: function(data, textStatus)
					{
						DialogFactory.openDialog({
							message: 'An unexpected error has occured. Please contact the site\'s management.',
							title: 'Request Failed',
							modal: true
							//buttons
							//beforeclose
							//close
							//width
							//height
							//dialogClass
							});
					},
					onError: function(xhr, textStatus, errorThrown)
					{
						DialogFactory.openDialog({
							message: 'A server error has occured. Please contact the site\'s management.',
							title: 'Request Failed',
							modal: true
							//buttons
							//beforeclose
							//close
							//width
							//height
							//dialogClass
							});
					},
					//onEmpty: null,
					//onNonEmpty: null,
					//onComplete: null,
					onNonErrorNonEmpty: function(data, textStatus)
					{
						$('#contactForm .loader').hide();
					},
					decodeFunction: function(data)
					{
						return Base64.decode(data);
					},
					validResponseIndicator: 'OK',
					invalidResponseIndicator: 'BAD'
				});//End of AjaxHelpers.sendRequest

				return false;
			}
		);

		//Validation.startInputValidation({
		//	input: document.getElementById('dowName'),
		//	validationFunction: Generics.validation.validateNonEmpty,
		//	errorClass: DOW._contactFormErrorClass,
		//	//beforeSetError: null,
		//	//beforeRemoveError: null,
		//	validateOnBlur: true,
		//	validateOnChange: false,
		//	validateOnKeyup: false
		//});
		Validation.startInputValidation({
			input: document.getElementById('dowEmail'),
			validationFunction: Generics.validation.validateEmail,
			errorClass: DOW._contactFormErrorClass,
			beforeSetError: function(input, validationFunction)
			{
				$(input).parent().append('<span class="errorDescription">You\'ve specified an invalid e-mail</span>');
			},
			beforeRemoveError: function(input, validationFunction)
			{
				$(input).next('.errorDescription').remove();
			},
			validateOnBlur: true,
			validateOnChange: false,
			validateOnKeyup: false
		});
		Validation.startInputValidation({
			input: document.getElementById('dowEmailConf'),
			validationFunction: function(email)
			{
				if (document.getElementById('dowEmail').value == email)
				{
					return true;
				}

				return false;
			},
			errorClass: DOW._contactFormErrorClass,
			beforeSetError: function(input, validationFunction)
			{
				$(input).parent().append('<span class="errorDescription">The e-mail and the e-mail confirmation fields must match !</span>');
			},
			beforeRemoveError: function(input, validationFunction)
			{
				$(input).next('.errorDescription').remove();
			},
			validateOnBlur: true,
			validateOnChange: false,
			validateOnKeyup: false
		});
		Validation.startInputValidation({
			input: document.getElementById('dowZip'),
			validationFunction: Generics.validation.validateZipCode,
			errorClass: DOW._contactFormErrorClass,
			beforeSetError: function(input, validationFunction)
			{
				$(input).parent().append('<span class="errorDescription">You\'ve specified an invalid zip-code</span>');
			},
			beforeRemoveError: function(input, validationFunction)
			{
				$(input).next('.errorDescription').remove();
			},
			validateOnBlur: true,
			validateOnChange: false,
			validateOnKeyup: false
		});


		this._isContactFormInitialized = true;
	},

	showContactForm: function()
	{
		if (!this._isContactFormInitialized)
		{
			throw 'Not initialized !';
		}

		$('#contactForm').slideDown('slow');
		$('#backgroundPopup').css({'opacity': '0.7'});
		$('#backgroundPopup').fadeIn('slow');

		$('#contactFormContainer .contactShow').addClass('contactHide').removeClass('contactShow');
	},

	hideContactForm: function()
	{
		if (!this._isContactFormInitialized)
		{
			throw 'Not initialized !';
		}

		$('#contactForm').slideUp('slow');
		$('#backgroundPopup').fadeOut('slow');

		$('#contactFormContainer .contactHide').addClass('contactShow').removeClass('contactHide');
	},

	toggleContactForm: function()
	{
		if (!this._isContactFormInitialized)
		{
			throw 'Not initialized !';
		}

		if ($('#contactForm').is(':hidden'))
		{
			this.showContactForm();
		}
		else
		{
			this.hideContactForm();
		}
	},


	initWaitListForm: function(url, dealID)
	{
		if (this._isWaitListFormInitialized)
		{
			return;
		}
		this._dealID = dealID;

		//Create a div and then have JQuery make it into a popup
		this._waitListPopupDiv = document.createElement('div');
		this._waitListPopupDiv.style.display = 'none';
		this._waitListPopupContentObj = document.createElement('div');
		$(this._waitListPopupContentObj).addClass('form');

		this._waitListPopupContentObj.innerHTML =
			'<div class="dowWaitListForm">' +
				'<p>' +
					'<label for="dowWaitListName">Name:</label>' +
					'<input id="dowWaitListName" type="text" value="" name="name" />' +
					'<br style="clear: both;" />' +
				'</p>' +
				'<p>' +
					'<label for="dowWaitListEmail">E-mail:</label>' +
					'<input id="dowWaitListEmail" type="text" value="" name="email" />' +
					'<br style="clear: both;" />' +
				'</p>' +
				'<p>' +
					'<label for="dowWaitListEmailConf">E-mail Confirmation:</label>' +
					'<input id="dowWaitListEmailConf" type="text" value="" name="emailConf" />' +
					'<br style="clear: both;" />' +
				'</p>' +
				'<div class="loader" style="display: none;">Please Wait...</div>' +
			'</div>'
			;
		this._waitListPopupDiv.appendChild(this._waitListPopupContentObj);
		document.body.appendChild(this._waitListPopupDiv);

		$(this._waitListPopupDiv).dialog({
			autoOpen: false,
			closeOnEscape: true,
			dialogClass: 'jqueryui',
			modal: true,
			stack: true,
			resizable: false,
			title: 'Join Wait-List',
			width: 500,
			buttons:
			{
				'Join Wait-List': function()
				{
					if ($('.loader:visible', this._waitListPopupDiv).length == 1)
					//If request already made - wait till that has been processed
					{
						return false;
					}

					//First make sure all input fields are valid:
					Validation.validateInput({
						input: document.getElementById('dowWaitListName'),
						validationFunction: Generics.validation.validateNonEmpty,
						errorClass: DOW._waitListFormErrorClass,
						beforeSetError: function(input, validationFunction)
						{
							$(input).parent().append('<div class="errorDescription">You must specify a name</div>');
						},
						beforeRemoveError: function(input, validationFunction)
						{
							$('.errorDescription', $(input).parent().get(0)).remove();
						}
					});
					Validation.validateInput({
						input: document.getElementById('dowWaitListEmail'),
						validationFunction: Generics.validation.validateEmail,
						errorClass: DOW._waitListFormErrorClass,
						beforeSetError: function(input, validationFunction)
						{
							$(input).parent().append('<div class="errorDescription">You\'ve specified an invalid e-mail</div>');
						},
						beforeRemoveError: function(input, validationFunction)
						{
							$('.errorDescription', $(input).parent().get(0)).remove();
						}
					});
					Validation.validateInput({
						input: document.getElementById('dowWaitListEmailConf'),
						validationFunction: function(email)
						{
							if (document.getElementById('dowWaitListEmail').value == email)
							{
								return true;
							}

							return false;
						},
						errorClass: DOW._waitListFormErrorClass,
						beforeSetError: function(input, validationFunction)
						{
							$(input).parent().append('<div class="errorDescription">The e-mail and the e-mail confirmation fields must match !</div>');
						},
						beforeRemoveError: function(input, validationFunction)
						{
							$('.errorDescription', $(input).parent().get(0)).remove();
						}
					});
					if (
						$('#dowWaitListName').hasClass(DOW._waitListFormErrorClass) ||
						$('#dowWaitListEmail').hasClass(DOW._waitListFormErrorClass) ||
						$('#dowWaitListEmailConf').hasClass(DOW._waitListFormErrorClass)
						)
					{
						//Invalid Input !

						return false;
					}

					//All inputs are valid - submit data to server
					var userName = document.getElementById('dowWaitListName').value;
					var userEmail = document.getElementById('dowWaitListEmail').value;

					$('.loader', this._waitListPopupDiv).show();
					AjaxHelpers.sendRequest({
						data:
							'data=' +
							Generics.serialize({
								data: [
									DOW._dealID + '',
									userEmail,
									userName
								],
								separator: 'A',
								encodeFunction: function(param){ return Base64.encode(param); }
								//ascendingOrder: false,
								//method: 0
							})
							,
						url: url,
						//type: null,
						//serverFunction: null,
						onValid: function(data, textStatus)
						{
							$(':input', this._waitListPopupContentObj).not(':submit').val('');
							DialogFactory.openDialog({
								message: data,
								title: 'Request Submitted',
								modal: true
								//buttons
								//beforeclose
								//close
								//width
								//height
								//dialogClass
								});
						},
						onExplicitlyInvalid: function(data, textStatus)
						{
							DialogFactory.openDialog({
								message: data,
								title: 'Request Failed',
								modal: true
								//buttons
								//beforeclose
								//close
								//width
								//height
								//dialogClass
								});
						},
						onImplicitlyInvalid: function(data, textStatus)
						{
							DialogFactory.openDialog({
								message: 'An unexpected error has occured. Please contact the site\'s management.',
								title: 'Request Failed',
								modal: true
								//buttons
								//beforeclose
								//close
								//width
								//height
								//dialogClass
								});
						},
						onError: function(xhr, textStatus, errorThrown)
						{
							DialogFactory.openDialog({
								message: 'A server error has occured. Please contact the site\'s management.',
								title: 'Request Failed',
								modal: true
								//buttons
								//beforeclose
								//close
								//width
								//height
								//dialogClass
								});
						},
						//onEmpty: null,
						//onNonEmpty: null,
						//onComplete: null,
						onNonErrorNonEmpty: function(data, textStatus)
						{
							$('.loader', this._waitListPopupContentObj).hide();
						},
						decodeFunction: function(data)
						{
							return Base64.decode(data);
						},
						validResponseIndicator: 'OK',
						invalidResponseIndicator: 'BAD'
					});//End of AjaxHelpers.sendRequest

					$(this).dialog('close');
				},
				'Cancel' : function()
				{
					$(this).dialog('close');
				}
			},
			beforeClose: function(event, ui)
			{
			},
			close: function(event, ui)
			{
			}
		});

		Validation.startInputValidation({
			input: document.getElementById('dowWaitListName'),
			validationFunction: Generics.validation.validateNonEmpty,
			errorClass: DOW._waitListFormErrorClass,
			beforeSetError: function(input, validationFunction)
			{
				$(input).parent().append('<div class="errorDescription">You must specify a name</div>');
			},
			beforeRemoveError: function(input, validationFunction)
			{
				$('.errorDescription', $(input).parent().get(0)).remove();
			},
			validateOnBlur: true,
			validateOnChange: false,
			validateOnKeyup: false
		});
		Validation.startInputValidation({
			input: document.getElementById('dowWaitListEmail'),
			validationFunction: Generics.validation.validateEmail,
			errorClass: DOW._waitListFormErrorClass,
			beforeSetError: function(input, validationFunction)
			{
				$(input).parent().append('<div class="errorDescription">You\'ve specified an invalid e-mail</div>');
			},
			beforeRemoveError: function(input, validationFunction)
			{
				$('.errorDescription', $(input).parent().get(0)).remove();
			},
			validateOnBlur: true,
			validateOnChange: false,
			validateOnKeyup: false
		});
		Validation.startInputValidation({
			input: document.getElementById('dowWaitListEmailConf'),
			validationFunction: function(email)
			{
				if (document.getElementById('dowWaitListEmail').value == email)
				{
					return true;
				}

				return false;
			},
			errorClass: DOW._waitListFormErrorClass,
			beforeSetError: function(input, validationFunction)
			{
				$(input).parent().append('<div class="errorDescription">The e-mail and the e-mail confirmation fields must match !</div>');
			},
			beforeRemoveError: function(input, validationFunction)
			{
				$('.errorDescription', $(input).parent().get(0)).remove();
			},
			validateOnBlur: true,
			validateOnChange: false,
			validateOnKeyup: false
		});

		this._isWaitListFormInitialized = true;
	},
	openWaitListForm: function()
	{
		if (!this._isWaitListFormInitialized)
		{
			throw 'Not initialized !';
		}

		$(this._waitListPopupDiv).dialog('open');
	}
};
