﻿/********* Funzione che viene utilizzata dai controlli che hanno abilitato il drag and drop dei prodotti
Prende in input l'url dell'immagine e ne crea una nuova per simulare il trascinamento.
Inoltre archivia nei dati di trasferimento l'id del prodotto necessario al controllo target che esegue la funzione di drop. ************/




/***********************Funzione relative alla gestione del dragAndDrop***********************************/
function InitiateDrag(urlImage)
{
	event.dataTransfer.setData("Text",event.srcElement.name);
	var img;
	if ( typeof(document.DragImage) == 'undefined' ){
		img = document.DragImage = document.createElement("IMG");
		document.body.appendChild(img);
		img.border = 1;
		img.style.position = "absolute";
		img.style.zIndex = 1000;
		img.style.display = 'none';
		img.style.filter = "progid:DXImageTransform.Microsoft.Alpha(opacity=80)"
		
	}else{
		img = document.DragImage;
	}
	/*Se il parametro urlImage è avvalorato lo assegno alla proprietà src dell'immagine
	altrimenti prendo l'immagine contenuta nell'oggetto anckor.*/
	var source = event.srcElement;
	var children = source.children(1);
	if (urlImage!=null && urlImage!='')
	{
		img.src = urlImage;
	}
	else if (children != null && children.tagName == 'IMG')
	{
		img.src = children.src;
	}
	
	if (img.src!=null && img.src!='')
	{
		with(img.style){
			display = 'block';
			posLeft = event.clientX;
			posTop = event.clientY + document.body.scrollTop - 50;
		}
	}
}

//Esegue il trascinamento utillando le coordinate del mouse.
function OnDrag(){
	with(document.DragImage.style){
		posLeft = event.clientX;
		posTop = event.clientY + document.body.scrollTop - 50;
	}
}

function cancelEvent() 
{
	window.event.returnValue = false;
}

function inizializeDrag(objectTarget)
{
   /*if ( document.getElementById(objectTarget)!=null)
   {
        alert('pippo');
   }*/
}

//Elimina l'immagine droppata
function CancelDropImage()
{
	document.DragImage.style.display = 'none';
}


function doClick(buttonName,e)
{
    //the purpose of this function is to allow the enter key to 
    //point to the correct button to click.
    var key;
    
     if(window.event)
          key = window.event.keyCode;     //IE
     else
          key = e.which;     //firefox
    if (key == 13)
    {
        //Get the button the user wants to have clicked
        var btn = $get(buttonName);
        if (btn != null)
        { //If we find the button click it
            btn.focus();
            btn.click();
            event.keyCode = 0
            return true;
        }
    }
    return false;
}

// JScript File
function SetPosition(elementId)
{
    var element = $get(elementId);
   
    if (element!=null)
    {
        x = document.documentElement.scrollLeft;
        y = document.documentElement.scrollTop;
        
        var clientBounds = $common.getClientBounds();
        var width = clientBounds.width;
        var height = clientBounds.height;
        
         x = Math.max(0, Math.floor(x + width / 2.0 - element.offsetWidth / 2.0 ));
         y = Math.max(0, Math.floor(y + height / 2.0 - element.offsetHeight / 2.0 ));
         
         element.style.left = x + 'px';
         element.style.top = y + 'px';
     }
  }
  
  function SetShadow(elementId)
  {
    var border = RUZEE.ShadedBorder.create({ corner:8, shadow:20,  border:2 });
    border.render(elementId);
  }




