function JScript()
{
	this._ajaxurl = 'giftcert.php';
	this._timeOut = null;
	
	this._dg = null;
	this._numRecords = 10;
	this._isDynamic = true;
	
	this.loadGrid();
}
JScript.prototype.loadGrid = function()
{/*
	
	var obj = this;
	
	Ext.QuickTips.init();
	Ext.form.Field.prototype.msgTarget = 'side';
	Ext.menu.RangeMenu.prototype.icons = {
		gt: '../extjs/grid-filters/img/greater_then.png', 
		lt: '../extjs/grid-filters/img/less_then.png',
		eq: '../extjs/grid-filters/img/equals.png'
	};
	Ext.grid.filter.StringFilter.prototype.icon = '../extjs/grid-filters/img/find.png';
	
	var fields = [
		{ name: 'id', mapping: 'id', type: 'int' },
		{ name: 'pid',mapping:'pid',type: 'string' },
		{ name: 'model_id',mapping:'model_id',type: 'string' },
		{ name: 'color_name',mapping:'color_name',type: 'string' },
		{ name: 'current_price',mapping:'current_price',type: 'string' },
		{ name: 'product_name',mapping:'product_name',type: 'string' }
		
	];
	
	var filters = new Ext.grid.GridFilters({
		filters:[
			{type: 'string', dataIndex: 'colour_name'},
			{type: 'string', dataIndex: 'id'},
			{type: 'list', dataIndex: 'is_active', options: [['y', 'Yes'], ['n', 'No']], phpMode: true}
			
		]
	});
	var expander = new Ext.grid.RowExpander({
        tpl : new Ext.Template(
            '<div style="padding:10px;">{product_name}</div><div style="padding:10px;">{id}</div>'
			
        )
    });
	obj._ds = new Ext.data.JsonStore({
		url: obj._ajaxurl,
		baseParams: {
			mode: 'loadGrid',
			productid:obj._productiD
		},
        fields: fields,
		totalProperty: 'total',
		root: 'records',
		sortInfo: {
			field: 'id',
			direction: 'ASC'
		},
		remoteSort: true
    });
		var cols = [ expander,
		{ id:id, header: "Model Code", width: 100,sortable: true, dataIndex: 'model_id' },
		{ header: "Model Colour", width: 100, sortable: false, dataIndex: 'color_name', align: 'center', hideable: false},
		{ header: "Model Price", width: 100, sortable: false, dataIndex: 'current_price', align: 'center', hideable: false},
		{ header: "Edit", width: 100, sortable: false, dataIndex: 'id', align: 'center', hideable: false,
			renderer:  function (id, metadata, record, rowIndex, colIndex, store){
				return '<a href="#" onclick="JavaScript:  js.editModel(' + id + ', ' + rowIndex + '); return false;"><img src="images/edit.gif" width="16" height="16" alt="Edit" title="Edit" border="0" /></a>';
			}
		},
		{ header: "Delete", width: 100, sortable: false, dataIndex: 'id', align: 'center', hideable: false,
			renderer:  function (id, metadata, record, rowIndex, colIndex, store){
				
					return '<a href="#" onclick="JavaScript: js.deleteModel(' + id + ', ' + rowIndex + '); return false;"><img src="images/delete.gif" width="16" height="16" alt="Delete" title="Delete" border="0" /></a>';
				
				
			}
		}
	];
	
	obj._dg = new Ext.grid.GridPanel({
		autoExpandColumn : id,
        store            : obj._ds,
        columns          : cols,
		enableDragDrop   : false,
        stripeRows       : true,
        width            : 900,
		height			 : 350,
        title            : obj._productName,
		el				 : 'cms-grid',
		enableColLock: false,
		loadMask: true,
		plugins: [filters, expander],
        collapsible: true,
        animCollapse: true,
		viewConfig: {
            forceFit: false
        },
		iconCls: 'icon-grid',
		tbar: [{
            text:'Go back',
			tooltip:'Go back',
            iconCls:'add',
			handler: function(){
				history.back()
				
			}
        },'-', {
			 text:'Add Model',

            tooltip:'Add Model',
            iconCls:'add',
			handler: function(){
				obj.clear();
				obj._isDynamic = true;
				$('#mode').val('AddModel');
				$('#add-model-grid').fadeIn(500);
				$.scrollTo('#add-model-grid', 500);
			}
			
			
			
        },'-',{
            text:'Clear Filters',
            tooltip:'Clears Grid Search Filters',
            iconCls:'reload',
			handler: function(){
				obj._dg.plugins[0].clearFilters();
			}
			
        }],
		bbar: new Ext.PagingToolbar({
			store: obj._ds,
			pageSize: obj._numRecords,
			plugins: filters,
			displayInfo: true,
			displayMsg: 'Displaying {0} - {1} of {2}',
			emptyMsg: 'No Category to display'
		})
    });
	obj._ds.load({params:{start: 0, limit: obj._numRecords}});
	obj._dg.render();*/
}
JScript.prototype.ChangeState = function(idval)
{}

JScript.prototype.checkOther = function(idval11)
{}

JScript.prototype.getalladd = function()
{}

JScript.prototype.saveModel = function()
{/*
	var obj = this;
	var errors = new Array();
	var fileExpr = /^[A-Za-z0-9]+$/;
	$('#mode').val('saveModel');
	obj.clearErrors();
	
	if ($('#model_name').isEmpty())
	{
		errors.push('Please enter Model name .');
		$('#model_name').addClass('wrongBox');
	}
	if ($('#model_price').isEmpty())
	{
		errors.push('Please enter Model price .');
		$('#model_price').addClass('wrongBox');
	}
	
	
	if (errors.length > 0)
	{
		$('.errors:eq(1)').html(obj.formatErrors(errors)).slideDown(500);
		$.scrollTo('.errors:eq(1)', 500);
		return false;
	}
	else
	{
		return true;
	}


*/
}



JScript.prototype.deleteModel = function(id, rowIndex)
{/*
	
	var obj = this;
	obj.clear();
	Ext.MessageBox.confirm('Delete Page?', 'Are you sure to delete this Model?<br /><br /><font style="color:#F00; font-weight:bold;">The Model will no longer be available.</font>', function(btn){
		if (btn == 'yes')
		{
			obj.loading('Deleting Model.<br />Please wait...');
			var data = {
				mode:	'deleteModel',
				id:		id
			};
			$.ajax({
				url:		obj._ajaxurl,
				data:		data,
				type:		'POST',
				timeout:	12000,
				dataType:	'json',
				success:	function(jData, textStatus){
					$.unblockUI();
					$('.errors:eq(0)').html(obj.formatErrors(jData.message)).slideDown(500);
					if (jData.isDeleted)
					{
						obj._ds.reload();
						obj._timeOut = setTimeout(obj.clearErrors, 5000);
					}
				},
				error:		function(XMLHttpRequest, textStatus, errorThrown){
					$.unblockUI();
					var errors = new Array();
					if (textStatus == 'timeout')
					{
						errors.push('Sorry! Request Timeout.<br />Please check you internet connection.');
					}
					else if (textStatus == 'parsererror')
					{
						errors.push('Invalid Response returned by Server.');
					}
					else
					{
						errors.push('Unknown Error.');
					}
					$('.errors:eq(0)').html(obj.formatErrors(errors)).slideDown(500);
				}
			});
		}
	});*/
}
JScript.prototype.setStatus = function(id, status)
{/*
	
	var obj = this;
	obj.clear();
	obj.loading('Updating Status.<br />Please wait...');
	var data = {
		mode:		'setStatus',
		id:			id,
		nstatus:	status					
	};
	
	$.ajax({
		url: 		obj._ajaxurl,
		data:		data,
		type:		'POST',
		timeout: 	12000,
		dataType:	'json',
		success:	function(jData, textStatus){
			$.unblockUI();
			obj._ds.reload();
			$('.errors:eq(0)').html(obj.formatErrors(jData.message)).slideDown(500);
			obj._timeOut = setTimeout(obj.clearErrors, 5000);
		},
		error:		function(XMLHttpRequest, textStatus, errorThrown){
			$.unblockUI();
			var errors = new Array();
			if (textStatus == 'timeout')
			{
				errors.push('Sorry! Request Timeout.<br />Please check you internet connection.');
			}
			else if (textStatus == 'parsererror')
			{
				errors.push('Invalid Response returned by Server.');
			}
			else
			{
				errors.push('Unknown Error.');
			}
			$('.errors:eq(0)').html(obj.formatErrors(errors)).slideDown(500);
		}		
	});*/
}

JScript.prototype.savePrice = function()
{/*
	var obj = this;
	var errors = new Array();
	obj.clearErrors();
	var selected_text=new Array();
	selected_text=$('#product_color').val();
	
	$('#get_current_price').html(
								 
								 
								 );
	*/
}
JScript.prototype.saveContent = function()
{/*
	var obj = this;
	var errors = new Array();
	var fileExpr = /^[A-Za-z0-9]+$/;
	
	obj.clearErrors();
	
	if ($('#product_name').isEmpty())
	{
		errors.push('Please enter Product name .');
		$('#product_name').addClass('wrongBox');
	}
	
	
	
	if (errors.length > 0)
	{
		$('.errors:eq(1)').html(obj.formatErrors(errors)).slideDown(500);
		$.scrollTo('.errors:eq(1)', 500);
		return false;
	}
	else
	{
		return true;
	}*/
}
JScript.prototype.editModel = function(id, index)
{/*
	var obj = this;
	obj.clear();
	var row = obj._ds.getAt(index);
	
	//obj._isDynamic = (row.data.is_deletable == 'Y');
	$('#id').val(row.data.id);
	$('#mode').val('saveModel');
	$('#model_name').val(row.data.model_id);
	$('#model_price').val(row.data.current_price);
	$('#product_colour_name').val(row.data.color_name).selected;
	$('#add-model-grid').fadeIn(500);
	$.scrollTo('#add-model-grid', 500);*/
}
JScript.prototype.clear = function()
{
	var obj = this;
	
	obj._isDynamic = true;
	
	//FCKeditorAPI.GetInstance('content').SetHTML('');
	$('#cat_name').val('');
	$('#cat_type').val('');
	$('#page_title').val('');
	//$('#date').val('');
	$('input[name="is_active"]').filter('[value="y"]').attr('checked', true);
	$('#id').val('0');
	$('#mode').val('');	
	$('#edit-cms-grid').fadeOut(500);
	obj.clearErrors();
	$.scrollTo('#cms-grid', 500);
}
JScript.prototype.showError = function(errors)
{
	var obj = this;
	$('.errors:eq(1)').html(obj.formatErrors(errors.errors)).slideDown(500);
	if (errors.fields.length > 0)
	{
		$(errors.fields.join(',')).addClass('wrongBox');
	}
	$.scrollTo('#edit-cms-grid', 500);
}
JScript.prototype.clearErrors = function()
{
	var obj = this;
	clearTimeout(obj._timeOut);
	$('.errors').html('').slideUp(500);
	$('.wrongBox').removeClass('wrongBox');
}
JScript.prototype.formatErrors = function(errors)
{
	return '<ul><li>' + errors.join('</li>\n<li>') + '</li></ul>'
}
JScript.prototype.loading = function(text)
{
	$.unblockUI();
	$.blockUI({
		message: '<p style="margin:3px 0px 2px 0px;">' + text + '</p><br clear="all" /><p style="margin:2px 0px 3px 0px;"><img src="' + $('#loading').attr('src') + '" alt="Loading..." title="Loading..." /></p>',
		css: {
			color: '#000000',
			'font-size': '12px',
			border: '1px #CCCCCC dashed',
			padding: '10px 3px',
			opacity: 0.5
		}
	});
}