/* Product object */
function Product(
    ID,
    Name,
    Quantity,
    Size,
    Price,
    RasterValueID,
    Picture
){
    this.id = ID;
    this.name = Name;
    this.quantity = Quantity;
    this.size = Size;
    this.price= Price;
    this.rasterValueID = RasterValueID;
    this.picture = Picture;
}

/* PO object */
function PO(
    LeadID,
    RasterDDL,
    SizeLabel,
    SelectedSizeLabel,
    SelectedSizeTxt,
    SelectedSizeValidator
){
    this.leadID = LeadID,
    this.rasterDDL = RasterDDL;
    this.sizeLabel = SizeLabel;
    this.selectedSizeLabel = SelectedSizeLabel;
    this.selectedSizeTxt = SelectedSizeTxt;
    this.selectedSizeValidator = SelectedSizeValidator;

    this.activeSizeDimension = -1;
    this.selectedSizeDimension = -1;
    this.arrayAllSizeDimension = new Array();
}

PO.prototype.getRaster = function() {
    return this.rasterDDL;
}

PO.prototype.ShowPanel = function(order) {
    if (objInlineBag.isOpen)
        objInlineBag.closeInlineBag(true, true);
    
    objInlineBag.initializeInlineBag();
    var total = Djak.Common.getOrderAttribute(order, 'order_total');
    var price = objProduct.price;
    if (objProduct)
        objInlineBag.setInlineShoppingBagData(objProduct.picture, objProduct.name, objProduct.quantity, objProduct.size, price + " din", total + " din", Djak.Common.getOrderAttribute(order, 'order_items_count'));
    objInlineBag.positionInlineBag();
    objInlineBag.openInlineBag();
}

PO.prototype.setSizeDimension = function(RasterValueID, RasterValueName) {
    if (objImg.className != "soldOut" && objImg.className != "selectedSoldOut") {
	    if (RasterValueID != this.selectedSizeDimension) {
            if (objProduct)
            {
                objProduct.rasterValueID = RasterValueID;    
                objProduct.size = RasterValueName;    
            }
		    this.selectedSizeDimension = RasterValueID;
		    this.activeSizeDimension = RasterValueID;
            this.setDropDownValue(RasterValueID);
            this.setSelectedSizeLabelValue(RasterValueID);
		    this.setSizeDimensionSwatches();
	    }
	}
}

PO.prototype.swatchOver = function(index) {
	doMouseOver = false;
	if (index != this.selectedSizeDimension) {
		this.activeSizeDimension = index;
		doMouseOver = true;
	}
	if (doMouseOver) {
		objImg = returnObjById("swatch_"+index);
		if (objImg.className != "soldOut" && objImg.className != "selectedSoldOut") {
			objImg.className = "hover";
		}
        var CurrentSwatch = this.getSwatch(index);
        if (CurrentSwatch != null)
        {
	        var objLabel = returnObjById(this.sizeLabel);
            objLabel.innerHTML = CurrentSwatch.TranslatedName;    
        }
	}
}
PO.prototype.swatchOut = function(index) {
    if (objImg.className != "soldOut" && objImg.className != "selectedSoldOut") {
	    doMouseOut = false;
	    if (index != this.selectedSizeDimension) 
	    {
		    doMouseOut = true;
	    }
	    if (doMouseOut) 
	    {
    		this.setSizeDimensionSwatches();
	    }
	}
    var objLabel = returnObjById(this.sizeLabel);
	if (this.selectedSizeDimension != -1)
	{
        var CurrentSwatch = this.getSwatch(this.selectedSizeDimension);
        if (CurrentSwatch != null)
            objLabel.innerHTML = CurrentSwatch.TranslatedName;    
    }
    else
        objLabel.innerHTML = '';    
}

PO.prototype.setSizeDimensionSwatches = function() {
    for (i=0; i < this.arrayAllSizeDimension.length; i = i + 1) 
    {
        var CurrentSwatch = this.arrayAllSizeDimension[i];
		if (CurrentSwatch.Enabled) {
			var classState = (CurrentSwatch.ID == this.selectedSizeDimension ? "selected" : "normal");
		} 
		else 
		{
			var classState = (CurrentSwatch.ID == this.selectedSizeDimension ? "selectedSoldOut" : "soldOut");
		}    
	    var objSwatch = returnObjById("swatch_" + CurrentSwatch.ID);
	    objSwatch.className = classState;
    }
}
PO.prototype.setDropDownValue = function(index) {
    var objSwatch = returnObjById(this.rasterDDL);
    for (var i=0; i < objSwatch.options.length; i++) {
          if (objSwatch.options[i].value == index) {
            objSwatch.options[i].selected = true;
            objSwatch.options.selectedIndex = i;
          }
        }
}
PO.prototype.setQuantity = function(index){
    if (objProduct)
        objProduct.quantity = index;
}
PO.prototype.setSelectedSizeLabelValue = function(index) {
    var CurrentSwatch = this.getSwatch(this.selectedSizeDimension);
    if (CurrentSwatch != null)
    {
        objLabel = returnObjById(this.selectedSizeLabel);
        objLabel.innerHTML = CurrentSwatch.TranslatedName;    
        objTxt = returnObjById(this.selectedSizeTxt);
        objTxt.value = CurrentSwatch.TranslatedName;    
        objValidator = returnObjById(this.selectedSizeValidator);
        objValidator.style.display = "none";
    }
}
PO.prototype.getSwatch = function(index) {
    for (var i=0; i < this.arrayAllSizeDimension.length; i++) 
    {
        var CurrentSwatch = this.arrayAllSizeDimension[i];
    	if (CurrentSwatch.ID == index)
		    return CurrentSwatch;
    }
    return null;
}

function View(
    LeadID,
    ListControlID,
    ListControlGridClass,
    ListControlListClass,
    ListButtonControlID,
    GridButtonControlID,
    ListButtonImageOn,
    ListButtonImageOff,
    GridButtonImageOn,
    GridButtonImageOff
){
    this.leadID = LeadID;
    this.listControlID = ListControlID;
    this.listControlGridClass = ListControlGridClass;
    this.listControlListClass = ListControlListClass;
    
    this.listButtonControlID = ListButtonControlID;
    this.gridButtonControlID = GridButtonControlID;
    
    this.listButtonImageOn = ListButtonImageOn;
    this.listButtonImageOff = ListButtonImageOff;
    this.gridButtonImageOn = GridButtonImageOn;
    this.gridButtonImageOff = GridButtonImageOff;


    this.SetView = function(view)
    {
        var object = this;
        var callback = function(result){
            object.SetView_SucceededCallback(view);
        }
        
        AIKON.CommerceLive.WebService.Lead.SetView(this.leadID, view, callback);
    }

    this.SetView_SucceededCallback = function(view)
    {
        var list = $("#" + this.listControlID);
        var objListButton = $("#" + this.listButtonControlID);
        var objGridButton = $("#" + this.gridButtonControlID);
        
        if (view == 'list')
        {
            list[0].className = this.listControlListClass;
            objListButton[0].src = this.listButtonImageOn;
            objGridButton[0].src = this.gridButtonImageOff;
        }
        else if (view == 'grid')
        {
            list[0].className = this.listControlGridClass;
            objListButton[0].src = this.listButtonImageOff;
            objGridButton[0].src = this.gridButtonImageOn;
        }
    }

}


