﻿function SetValue(ActionID)
{
    window.document.TableOrderForm.Action.value=ActionID;
}

function popupimg(url, width, height)
{
    window.open('popup.aspx?src=' + url,'LargerImage','toolbar=no,location=no,directories=no,status=no,menubar=no,scrollbars=no,resizable=no,copyhistory=no,width=' + width + ',height=' + height + ',left=0,top=0');
    return (true);
}
  
function DoValid(objform, action)
{
    var count = document.TableOrderForm.QtyField.length;
    var flg = false;

    if(count==undefined)
    {                                  
        if(HasInvalids(document.TableOrderForm.QtyField.value))
        {
            alert("Quantity can not contain:\n\n - Special characters\n - Negative values\n - Alphabets");
            return false;
        }

        if(document.TableOrderForm.QtyField.value!='')
         flg = true;
    }
    else
    {
        for(var i=0;i<count;i++)
        {
            if(HasInvalids(document.TableOrderForm.QtyField[i].value))
            {
                alert("Quantity can not contain:\n\n - Special characters\n - Negative values\n - Decimal values\n - Alphabets\n - Value less than 1");
                return false;
            }

            if(document.TableOrderForm.QtyField[i].value!='')
                flg = true;
        }
    }

    if(flg==false)
    {
        alert("Please provide quantity for atleast one size");
        return false;
    }
    else
    {
        var ProductID = window.document.TableOrderForm.ProductID.value;
        var VariantID = window.document.TableOrderForm.VID.value;
        SetValue(action);
        
        PostOrder('Forward_Cart.aspx', objform, undefined);

        if ((ProductID!=0) && (VariantID!=0))
        {
            setTimeout("getPricingForColor(window.document.TableOrderForm.ProductID.value, window.document.TableOrderForm.VID.value, 1);", 1500);
            
            if (getPageName() != 'HS_ShowProduct.aspx')
            {
                setTimeout("CallSlideDown();", 3000);
                setTimeout("CallSlideUp();", 15000);
            }            
        }
    }

}
  
function HasInvalids(value)
{
    invalids = ' !-@#$%^&*()+=<>,?/\\\':.;{}[]ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz';
    for (var i = 0; i < value.length; i++) 
    {
        if (invalids.indexOf(value.substr(i,1)) != -1)
        {
            return true;
        }
    }

    if (parseInt(value) < 1)
    {
        return true;
    }
    else
    {
        return false;
    }
}
  
function swatchoverout(obj, action)
{
    if (action==1)
        obj.style.borderColor="#fff600";
    else
        obj.style.borderColor="#ffffff";
}

function HideShowLayers(action)
{
    var obj = document.getElementById("dvColorSwathcesInPage");
    
    if (action == "show")
        obj.style.visibility="visible";
    else if (action == "hide")
        obj.style.visibility="hidden";
}

function getPageName()
{
    var sPath = window.location.pathname;
    var sPage = sPath.substring(sPath.lastIndexOf('/') + 1);
    return sPage;
}