﻿function SetValue(objform, ActionID)
{
    objform.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 = objform.QtyField.length;
    var flg = false;
    
    if(count==undefined)
    {                                  
        if(HasInvalids(objform.QtyField.value))
        {
            alert("Quantity can not contain:\n\n - Special characters\n - Negative values\n - Alphabets");
            return false;
        }

        if(objform.QtyField.value!='') 
         flg = true;
    }
    else
    {
        for(var i=0;i<count;i++)
        {
            if(HasInvalids(objform.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(objform.QtyField[i].value!='')
                flg = true;
        }
    }

    if(flg==false)
    {
        alert("Please provide quantity for atleast one size");
        return false;
    }
    else
    {
        var ProductID = objform.ProductID.value;
        var VariantID = objform.VID.value;
        
        SetValue(objform, 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);
        }
    }
}
  
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;
}
