﻿var isDrag = false;
	var objectDrag;
	var columns;
	var columnsPositions = new Array();
	
    
    function SubmitLoginInput()
    {
        new Ajax.Request('Login.ashx', {
              method: 'get',
              parameters: { login: $F('login_login2'), password: $F('login_password2') },
              onSuccess: function(transport) {
                var result = transport.responseText.evalJSON();
                if (result.status == 'OK')
                    window.location.reload(true);
                else
                    new Effect.Appear('span_errormessage2');
              }
            }); 
    }
    
    
    function Signout()
    {
        new Ajax.Request('Signout.ashx', {
              method: 'get',
              onSuccess: function(transport) {
                var result = transport.responseText.evalJSON();
                if (result.status == 'OK')
                    window.location.reload(true);
              }
            }); 
    }
    
    function ClearTextBox(elm)
    {
    
        if ($F(elm) != 'Mon mot de passe' && $F(elm) != 'Mon email' && $F(elm) != 'Rechercher')
            return;
        
        elm.value = '';
    }
    
    function SetTextBox(elm, text)
    {
        if (elm.value == ''){
            elm.value = text;
            }
    }
    
    function LoadConnectAccount()
    {
        
        new Ajax.Updater($('global_perso'), '/ConnectAccount.ashx', {
            insertion: Insertion.Top
            });
                
    }
        
    
    // open product detail popup
    function openPopup(merchantProductId,productsList,action)
    {

        if (merchantProductId == '')
        {
            return;
        }

        var drag = new Draggable('popup_products_detail');
        
        $('popup_overlay').show();
        $('loading').show();

        new Ajax.Updater('popup_products_detail','/ProductDetailInfo.ashx',{method:'get',parameters: { merchantProdId: merchantProductId,productsList: productsList,action: action},onComplete: function() { $('loading').hide(); Effect.Appear('popup_products_detail');}}); 
        
    }


    //close product detail
    function closePopup()
    {
        //document.getElementById('popup').style.display='none';
        Effect.Fade('popup_products_detail');
        $('popup_overlay').hide();
    }	
	
	function SetLoginInputFocus(elm)
	{
        $(elm).setStyle({
            background: '#fcec9f',
            border: '1px solid #ebac1f'
        });
	}
	
	function SetLoginInputBlur(elm)
	{
        $(elm).setStyle({
	        background: '#ffffff',
	        border: '1px solid #89939D'
	    });
	}
	
	
	
	// TO REMOVE
	function showHideHistory(element)
	{
	    element.toggle();
	    //initCarousel();
	    
	}
	
	
	
	/*** delete ***/
	function reportAbuse(source_id,sourceType,data)
	{
	    if(source_id == '')
	        return;
	        
	    if (sourceType =='')
	        return;
	        
	    new Ajax.Updater('popup_abuse_container','/signalAbuse.ashx', {
              method: 'post',
              parameters: { sourceId: source_id, data:data, sourceType:sourceType },
                        onSuccess: function(transport) {
                        $('popup_abuse_container').show();
          }
        });
	}
		
	function closePopupConfirm()
	{
	    $('popup_abuse_container').hide();
	    $('popup_overlay').hide();
	}
	
	
	/**** delete ****/
	function SaveSpaceRating(el,spaceId)
	{
	    
	    if($F('note_value') == '')
	        return;
	    
	    if(spaceId =='')
	        return;
	        
	      var rating = $F('note_value');
	      
	      
	         new Ajax.Updater('space_rating_container','/AddRatingToSpace.ashx', {
              method: 'get',
              parameters: { rating:rating,spaceId:spaceId },
                        onSuccess: function(transport) {
                        
          }
        });

    	    
	}
	
	
	
	

	
    // add product to cart
    function addToCart(merchantProductId,src)
    {
        
        if(merchantProductId == '')
            return;
            
        var optionId = $('merchant_products_option')[$('merchant_products_option').selectedIndex].value;
       
        new Ajax.Updater('addCart','/AddToCart.ashx', 
                {   
                    method:'get',   
                    parameters: { merchantProdId: merchantProductId,optionId:optionId,quantity:1},   
                    onSuccess: function(transport)
                        {
                        LoadMiniCart();
                       closePopup();
                        }
                });  
                    
    }

	
    function GetProductsWidgetsInSpace(products_id)
    {

        new Ajax.Updater('products_widgets_in_space', 'PopupAddProductToSpaceSimple.ashx?index=' + products_id);
    }
    
    function viewUserComments(pseudo,product_id,comment_id)
    {
        if(pseudo == '')
            return;
            
        if(product_id == '')
            return;
            
        if(comment_id =='')
            return;
        
        var container = "comments-container-"+comment_id;
        var dest = "comments-" + comment_id;
        
       new Ajax.Updater(dest,'/getCommentsByUserName.ashx', 
           {   
                    method:'get',   
                    parameters: { pseudo: pseudo,prodId:product_id},
                    onSuccess: function(transport)
                        {
                            $(container).show();
                        }
       });  
       
       
    }

    function closeCommentsUser(comment_id)
    {
            if(comment_id =='')
            return;
            
            var container = "comments-container-"+comment_id;
            $(container).hide();
    }

    function AddProductToSpace(products_id)
    {

        var widgets_id = $('popup_add_to_space_widget')[$('popup_add_to_space_widget').selectedIndex].value;

        new Ajax.Updater('products_widgets_in_space', 'AddToMySpaceSimple.ashx?widgets_id='+widgets_id+'&products_id='+products_id);

    }
	
	
    function ConfirmationEspacePublic(elm)
    {
        if (elm.checked){
            if (confirm ('Tous les onglets de votre espace seront visibles par les internautes. Voulez-vous continuer?'))
                elm.checked = true;
            else
                elm.checked = false;
        }
        else{
            if (confirm ('Votre espace ne sera plus visible par les internautes. Voulez-vous continuer?'))
                elm.checked = false;
            else
                elm.checked = true;
        }
            
    }    
    
var CardMessage = {
    print:function(message)
    {        
        window.open('CardPrint.ashx?id='+message);
    }
};
