﻿// t-shirt designer functions

var PreviousPanel = null;
var intCurrentViewIndex = 0;

function ToggleView() {
    intCurrentViewIndex = intCurrentViewIndex + 1;
    if (intCurrentViewIndex > 1) {
      intCurrentViewIndex = 0;
    }
    UpdateGraphic();
    UpdateTextTab();
}

function ShowPanel(NewPanel) {
  if (PreviousPanel) {
    PreviousPanel.style.display = "none";
  }
  PreviousPanel = document.getElementById(NewPanel);
  PreviousPanel.style.display = "";
}

function UpdatePanel(txtFieldName, txtNewText) {
    var fieldNameElement = document.getElementById(txtFieldName);
    fieldNameElement.innerHTML = txtNewText;
}

// update the graphic
function UpdateGraphic() {
    var intProductIndex = parseInt(document.aspnetForm.ProductIndex.value);
    var strProductImage = GetImage(intProductIndex, intCurrentViewIndex);
    var varStr = 'designer.aspx?I=' + strProductImage

    var strDesignImage;
    var intDesignImageIndex;

    if (intCurrentViewIndex == 0) {
        intDesignImageIndex = parseInt(document.aspnetForm.DesignFrontIndex.value)
    } 

    if (intCurrentViewIndex == 1) {
      intDesignImageIndex = parseInt(document.aspnetForm.DesignRearIndex.value)
    }

    strDesignImage = GetDesign(intDesignImageIndex);
    if (strDesignImage != "") {
        varStr = varStr + '&D=' + strDesignImage + '&DL=' + intImageLeft[intCurrentViewIndex] + '&DT=' + intImageTop[intCurrentViewIndex] + '&DS=' + dblImageScale[intCurrentViewIndex] + '&DR=' + intImageRotation[intCurrentViewIndex];
    }

    if (strText[intCurrentViewIndex] != '') {
        varStr = varStr + '&T=' + strText[intCurrentViewIndex].replace(/\r/g, 'vbCrLf') + '&TL='+ intTextLeft[intCurrentViewIndex] + '&TT=' + intTextTop[intCurrentViewIndex] + '&TS=' + intTextSize[intCurrentViewIndex] + '&TA=' + strTextAlign[intCurrentViewIndex] + '&TC=' + strTextColour[intCurrentViewIndex] + '&TF=' + strFontName[intCurrentViewIndex];
    }
    
    document.images["Graphic"].src = varStr;
    //alert(document.images["Graphic"].src);
}

// Get the product image view graphic from the Product ID and the current View
function GetImage(intProductIndex, intCurrentViewIndex) {
    var strRetval;

    if (intCurrentViewIndex == 0) {
        strRetval = ProductFront[intProductIndex];
    }

    if (intCurrentViewIndex == 1) {
        strRetval = ProductBack[intProductIndex];
    }

    return (strRetval);
}

function EscapeCRs(strText) {
    var strRetval;
    var intLength;




    return(strRetval);
}

// Get the Design image view graphic from the Design ID
function GetDesign(intDesignIndex) {
    var strRetval;

    if (intDesignIndex > -1) {
        strRetval = Designs[intDesignIndex];
    } else {
        strRetval = '';
    }

    return (strRetval);
}


function SetProduct(intProductIndex) {
    if (document.aspnetForm.ProductIndex.value != '' + intProductIndex) {
        document.aspnetForm.ProductIndex.value = '' + intProductIndex;
        UpdateGraphic();
    }
}

// Image functions and variables

var intImageTop = new Array(210, 210);
var intImageLeft = new Array(210, 210);
var dblImageScale = new Array(1.0, 1, 0);
var intImageRotation = new Array(0, 0);


function SetDesign(intDesignIndex) {
    if (intCurrentViewIndex == 0) {
        if (document.aspnetForm.DesignFrontIndex.value != '' + intDesignIndex) {
            document.aspnetForm.DesignFrontIndex.value = '' + intDesignIndex;
            UpdateGraphic();
        }
    } else {
        if (document.aspnetForm.DesignRearIndex.value != '' + intDesignIndex) {
            document.aspnetForm.DesignRearIndex.value = '' + intDesignIndex;
            UpdateGraphic();
        }
    }
}

function ImageMoveLeft() {
    if (intImageLeft[intCurrentViewIndex] > 0) {
        intImageLeft[intCurrentViewIndex] = intImageLeft[intCurrentViewIndex] - 5;
        UpdateGraphic();
    }
}

function ImageMoveRight() {
    intImageLeft[intCurrentViewIndex] = intImageLeft[intCurrentViewIndex] + 5;
    UpdateGraphic();
}

function ImageMoveUp() {
    if (intImageTop[intCurrentViewIndex] > 0) {
        intImageTop[intCurrentViewIndex] = intImageTop[intCurrentViewIndex] - 5;
        UpdateGraphic();
    }
}

function ImageMoveDown() {
    intImageTop[intCurrentViewIndex] = intImageTop[intCurrentViewIndex] + 5;
    UpdateGraphic();
}

function ImageSmaller() {
    if (dblImageScale[intCurrentViewIndex] > 0) {
        dblImageScale[intCurrentViewIndex] = dblImageScale[intCurrentViewIndex] - 0.1;
        UpdateGraphic();
    }
}

function ImageLarger() {
    dblImageScale[intCurrentViewIndex] = dblImageScale[intCurrentViewIndex] + 0.1;
    UpdateGraphic();
}

function ImageRotateLeft() {
    intImageRotation[intCurrentViewIndex] = intImageRotation[intCurrentViewIndex] - 5;
    UpdateGraphic();
}

function ImageRotateRight() {
    intImageRotation[intCurrentViewIndex] = intImageRotation[intCurrentViewIndex] + 5;
    UpdateGraphic();
}

function ImageCentre() {
    intImageLeft[intCurrentViewIndex] = 260 - parseInt(50 * dblImageScale[intCurrentViewIndex]);
    intImageTop[intCurrentViewIndex] = 260 - parseInt(50 * dblImageScale[intCurrentViewIndex]);
    UpdateGraphic();
}

function ImageMiddle() {
    intImageLeft[intCurrentViewIndex] = 260 - parseInt(50 * dblImageScale[intCurrentViewIndex]);
    UpdateGraphic();
}

function ImageReset() {
    intImageTop[intCurrentViewIndex] = 210;
    intImageLeft[intCurrentViewIndex] = 210;
    dblImageScale[intCurrentViewIndex] = 1.0;
    intImageRotation[intCurrentViewIndex] = 0;
    UpdateGraphic();
}

function ImageDelete() {
    intImageTop[intCurrentViewIndex] = 210;
    intImageLeft[intCurrentViewIndex] = 210;
    dblImageScale[intCurrentViewIndex] = 1.0;
    intImageRotation[intCurrentViewIndex] = 0;
    if (intCurrentViewIndex == 0) {
        document.aspnetForm.DesignFrontIndex.value = '-1';
    } else {
        document.aspnetForm.DesignRearIndex.value = '-1';
    }
    UpdateGraphic();
}


// Text functions and variables
var strText = new Array('', '');
var intTextTop = new Array(210, 210);
var intTextLeft = new Array(210, 210);
var intTextSize = new Array(12, 12);
var strTextAlign = new Array('L', 'L');
var strFontName = new Array('Arial', 'Arial');
var strTextColour = new Array('000000', '000000');

function TextMoveLeft() {
    if (intTextLeft[intCurrentViewIndex] > 0) {
        intTextLeft[intCurrentViewIndex] = intTextLeft[intCurrentViewIndex] - 5;
        UpdateGraphic();
    }
}

function TextMoveRight() {
    intTextLeft[intCurrentViewIndex] = intTextLeft[intCurrentViewIndex] + 5;
    UpdateGraphic();
}

function TextMoveUp() {
    if (intTextTop[intCurrentViewIndex] > 0) {
        intTextTop[intCurrentViewIndex] = intTextTop[intCurrentViewIndex] - 5;
        UpdateGraphic();
    }
}

function TextMoveDown() {
    intTextTop[intCurrentViewIndex] = intTextTop[intCurrentViewIndex] + 5;
    UpdateGraphic();
}

function TextAlign(strStyle) {
    strTextAlign[intCurrentViewIndex] = strStyle;
    UpdateGraphic();
}

function TextFontNameChange() {
    strFontName[intCurrentViewIndex] = document.aspnetForm.FontName.value;
    UpdateGraphic();
}

function TextColourChange() {
    strTextColour[intCurrentViewIndex] = document.aspnetForm.FontColour.value;
    UpdateGraphic();
}

function TextSizeChange() {
    intTextSize[intCurrentViewIndex] = document.aspnetForm.FontSize.value;
    UpdateGraphic();
}

function TextUpdate() {
    strText[intCurrentViewIndex] = document.aspnetForm.BodyText.value;
    UpdateGraphic();
}

function UpdateTextTab() {
    document.aspnetForm.FontName.value = strFontName[intCurrentViewIndex];
    document.aspnetForm.FontColour.value = strTextColour[intCurrentViewIndex];
    document.aspnetForm.FontSize.value = intTextSize[intCurrentViewIndex];
    document.aspnetForm.BodyText.value = strText[intCurrentViewIndex];
}
