﻿/*  TagBlankScript.js 
    Nathan A Burn (PureNet - 29th Feb 2008)
*/

var sSelectedColour = 'white';
var sCurrentColour = 'white';

function SetColour(sNewColour, SideOneAttID, SideTwoAttID, TagColourAttID)
{   
    var urlBackground = $get('divBlankTag').style.background;
    var newUrlBackground = urlBackground.replace(sSelectedColour, sNewColour);
    $get('divBlankTag').style.background = newUrlBackground;
    
    var ImgSelectedColour = $get(sSelectedColour).src;
    ImgSelectedColour = ImgSelectedColour.replace("b.gif", ".gif");
    $get(sSelectedColour).src = ImgSelectedColour;
    
    var ImgNewColour = $get(sNewColour).src;
    ImgNewColour = ImgNewColour.replace(".gif", "b.gif");
    $get(sNewColour).src = ImgNewColour;
    
    sSelectedColour = sNewColour;
    sCurrentColour = sNewColour;
    
    TagGeneratorService.SetBlankTag(SideOneAttID, SideTwoAttID, TagColourAttID, SetColour_Response);
}

// CABLE TIE 'SET DIMENSION AND COLOUR'
function SetDimensionColour(sNewColour, TagColourAttID)
{   
    var urlBackground = $get('divBlankTag').style.background;
    var newUrlBackground = urlBackground.replace(sSelectedColour, sNewColour);
    $get('divBlankTag').style.background = newUrlBackground;
    
    var ImgSelectedColour = $get(sSelectedColour).src;
    ImgSelectedColour = ImgSelectedColour.replace("b.gif", ".gif");
    $get(sSelectedColour).src = ImgSelectedColour;
    
    var ImgNewColour = $get(sNewColour).src;
    ImgNewColour = ImgNewColour.replace(".gif", "b.gif");
    $get(sNewColour).src = ImgNewColour;
    
    sSelectedColour = sNewColour;
    sCurrentColour = sNewColour;
    
    var sStockCode = $get('divStockCode').innerHTML;
    
    TagGeneratorService.SetBlankTagDimensionColour(sStockCode, TagColourAttID, SetColour_Response);
}

// CABLE TIE 'SET DIMENSION'
function SetDimension()
{
    var sStockCode = $get('divStockCode').innerHTML;
    var iSideOneID = $get('selDimensions').value;
    
    TagGeneratorService.SetBlankTagDimensions(sStockCode, iSideOneID, SetDimension_Response);
}

function SetDimension_Response(Results)
{
    $get('spanItemName').innerHTML = Results[0];
    $get('divStockCode').innerHTML = Results[1];
    $get('divPriceBands').innerHTML = Results[2];
}


function SetColour_Response(Results)
{
    $get('spanItemName').innerHTML = Results[0];
    $get('divStockCode').innerHTML = Results[1];
}

function ResetColour()
{
    var urlBackground = $get('divBlankTag').style.backgroundImage;
    var newUrlBackground = urlBackground.replace(sCurrentColour, sSelectedColour);
    $get('divBlankTag').style.backgroundImage = newUrlBackground;
    
    sCurrentColour = sSelectedColour;
}

function ShowColour(sNewColour)
{  
    var urlBackground = $get('divBlankTag').style.backgroundImage;
    var newUrlBackground = urlBackground.replace(sCurrentColour, sNewColour);
    $get('divBlankTag').style.backgroundImage = newUrlBackground;
    
    sCurrentColour = sNewColour;
}

function GetBlankTags()
{
    var sQty = $get('txtTagQty').value;
    
    if(sQty == "") { alert('Please enter a Quantity of Tags!'); }
    
    else 
    {
        var checkInt = new RegExp("[0-9]+");
        var result = checkInt.test(sQty);
    
        if(!result) { alert('Please enter a Quantity of Tags that is a Number value!'); }
        
        else
        {   
            var iQty = parseInt(sQty);
            var bCableTie = false;
            // CABLE TIES (ROUND QTY. TO NEAREST 100)
            if($get('divCableTie') != null) { iQty = (Math.ceil(iQty/100) * 100); bCableTie = true; }
            
            var sAddInfo = $get('txtAddInfo').value;
            var TagCode = $get('divStockCode').innerHTML;
            var TagPreview = $get('divTagHolder').innerHTML;
            
            TagGeneratorService.AddBlankTags(TagCode, iQty, TagPreview, sAddInfo, bCableTie, GetBlankTags_Response);
        }
     }
}

function GetMarkerPen()
{
    var sQty = $get('txtTagQty').value;
    
    if(sQty == "") { alert('Please enter a Quantity!'); }
    
    else 
    {
        var checkInt = new RegExp("[0-9]+");
        var result = checkInt.test(sQty);
    
        if(!result) { alert('Please enter a Quantity that is a Number value!'); }
        
        else
        {   
            var iQty = parseInt(sQty);
            var TagCode = $get('divStockCode').innerHTML;
            var TagPreview = $get('divTagHolder').innerHTML;
            
            TagGeneratorService.AddBlankTags(TagCode, iQty, TagPreview, "", false, GetBlankTags_Response);
        }
     }
}

function GetBlankTags_Response()
{
    window.location = "../basket/default.aspx"
}

function BuyRelatedProd(ProdCode, ProdQty)
{
    var PicPreview = $get('divTagHolder').innerHTML;
    TagGeneratorService.AddBlankTags(ProdCode, ProdQty, PicPreview, "", false, GetBlankTags_Response);
}