/*
$Id: index.js.php  2011-08-08 vndevweb@gmail.com $

  osCmax e-Commerce
  http://www.oscmax.com

  Copyright 2000 - 2011 osCmax

  Released under the GNU General Public License
*/
var errCSS = {
	'border-color': 'red',
	'border-style': 'solid'
};

var indexAjax = {
	charset: 'UTF-8',
	pageLinks: {},
	fieldSuccessHTML: '<div style="margin-left:1px;margin-top:1px;float:left;" class="success_icon ui-icon-green ui-icon-circle-check"></div>',
	fieldErrorHTML: '<div style="margin-left:1px;margin-top:1px;float:left;" class="error_icon ui-icon-red ui-icon-circle-close"></div>',
	fieldRequiredHTML: '<div style="margin-left:1px;margin-top:1px;float:left;" class="required_icon ui-icon-red ui-icon-gear"></div>',
	showAjaxLoader: function (){
        if(this.showMessagesPopUp == true)
		{
			$('#ajaxMessages').dialog({
                shadow: true,
                modal: true,
                width: 400,
                height: 100,
                open: function (event, ui){
                    $(this).parent().children().children('.ui-dialog-title').hide();
                    $(this).parent().children().children('.ui-dialog-titlebar').hide();
                    $(this).parent().children().children('.ui-dialog-titlebar-close').hide();
                }
            });
            
            $('#ajaxMessages').dialog('open');
		}
		$('#ajaxLoader').show();
	},
	hideAjaxLoader: function (){
        //$('#ajaxLoader').hide();
		setTimeout("$('#ajaxLoader').hide()", 3000);
		if(this.showMessagesPopUp == true)
		{
            setTimeout("$('#ajaxMessages').dialog('close')", 1000);  
			//$('#ajaxMessages').dialog('close');
		}
	},
	showAjaxMessage: function (message){
		$('#ajaxMessages').show().html('<center>Loading...<br><img src="ext/jQuery/themes/smoothness/images/ajax_load.gif"><br>' + message + '</center>');
	},
	hideAjaxMessage: function (){
        setTimeout("$('#ajaxMessages').hide()", 3000); 
	},
	queueAjaxRequest: function (options){
		var indexClass = this;
		var o = {
			url: options.url,
			cache: options.cache || false,
			dataType: options.dataType || 'html',
			type: options.type || 'GET',
			contentType: options.contentType || 'application/x-www-form-urlencoded; charset=' + this.ajaxCharset,
			data: options.data || false,
			beforeSend: options.beforeSend || function (){
                indexClass.showAjaxMessage(options.beforeSendMsg || 'Ajax Operation, Please Wait...');
				indexClass.showAjaxLoader();
			},
			complete: function (){
                indexClass.showAjaxMessage('Item Added to Cart');
				indexClass.hideAjaxMessage();
				indexClass.hideAjaxLoader();
			},
			success: options.success,
            error: function (XMLHttpRequest, textStatus, errorThrown){
                if (XMLHttpRequest.responseText == 'session_expired') document.location = this.pageLinks.shoppingCart;
                alert(options.errorMsg || 'There was an ajax error, please contact ' + checkoutClass.storeName + ' for support.');
            }
		};
        
        $.ajax(o);  
	},
    
    ajaxAddtoCart : function(pro_id)
    {
       var options = {
        url: addAjax.pageLinks.urlCart+pro_id,
        beforeSendMsg: 'Adding Item to Cart',
        dataType: 'json',
        data: null,
        type: 'get',
        errorMsg: 'There was an error adding this item.'
      }
       addAjax.queueAjaxRequest(options );
    },
    ajaxDelay : function(){
        
    },
	initindexAjax: function (){
        var indexClass = this;
        this.initializing = false;  
    }  
}
