
// Modified by sunil on 16/07/2009, in order to fix the issue related to Product type image extension as we were previously considering    
// thumb image extension as productimage extension
//Freezes by sunil on 16/07/2009

function applyCascadingDropdown(sourceId, targetId) {
    var source = document.getElementById(sourceId);
    var target = document.getElementById(targetId);
    if (source && target) {
        source.onchange = function () {
            //sai
            //displayOptionItemsByClass(target, source.text);
            //color.goto_slide_by_id(source.text);
            displayOptionItemsByClass(target, source.options[source.selectedIndex].text);
            color.goto_slide_by_id(source.options[source.selectedIndex].text);
            setprice();
        }
        //sai
        //displayOptionItemsByClass(target, source.text);
        displayOptionItemsByClass(target, source.options[source.selectedIndex].text);
    }
}

function displayOptionItemsByClass(selectElement, className) {
    if (!selectElement.backup) {
        selectElement.backup = selectElement.cloneNode(true);
    }
    var options = selectElement.getElementsByTagName("option");
    for (var i = 0, length = options.length; i < length; i++) {
        selectElement.removeChild(options[0]);
    }
    var options = selectElement.backup.getElementsByTagName("option");
    for (var i = 0, length = options.length; i < length; i++) {
        if (options[i].className == className)
            selectElement.appendChild(options[i].cloneNode(true));
    }
    
    size.goto_slide_by_id(selectElement.value);
    
}

function applyCascadingDropdowns() {
  try
  {
    applyCascadingDropdown("ctl00_CP_ddlColor", "sizes");
    setprice();
   }
 catch(e)
    {
    }
}

//window.onload = applyCascadingDropdowns();


function quantityvalidation(MinimumQty, maxqty) {

    if (isNaN(MinimumQty)) {
        MinimumQty = 1;
    }

    var mmid = 0;

    //if (typeof (document.getElementById('sizes')) == "undefined" || document.getElementById('sizes') == null) {
    if (typeof (document.getElementById('ctl00_CP_ddlColor')) != "undefined" && document.getElementById('ctl00_CP_ddlColor') != null)
        mmid = document.getElementById("ctl00_CP_ddlColor").options[document.getElementById("ctl00_CP_ddlColor").selectedIndex].id;
    else
        mmid = location.href.substring(location.href.indexOf('MID') + 3, location.href.indexOf('.aspx'));
    //}

    if (String(maxqty) != "null") {
        if (typeof (document.getElementById('sizes')) != "undefined" && document.getElementById('sizes') != null) {
            if (maxqty > size.get_qty_by_id(document.getElementById('sizes').value)) {
                maxqty = size.get_qty_by_id(document.getElementById('sizes').value);
            }
        }
        else {
            //Following if condition was added by team1c in order to validate the user to specify the quantity between 
            //max and min values specified per order in product card for the selected product ---- 31/03/2009
            if (maxqty > size.get_qty_by_id(mmid))
                maxqty = size.get_qty_by_id(mmid);
        }
    }
    else {
        if (typeof (document.getElementById('sizes')) != "undefined" && document.getElementById('sizes') != null) {

            maxqty = size.get_qty_by_id(document.getElementById('sizes').value);
        }
        else {
            maxqty = size.get_qty_by_id(mmid);
        }
    }  //included by lava kumar to resolve the problem when minqty greater than qty available
    if (MinimumQty > maxqty) {
        MinimumQty = maxqty;
    }

    if (isNaN(document.getElementById('ctl00_CP_txtQuantity').value) || document.getElementById('ctl00_CP_txtQuantity').value == '' || Number(document.getElementById('ctl00_CP_txtQuantity').value) <= 0) {
        alert('Please enter a valid Quantity');
        return false;
    }
    else if (isNaN(maxqty)) {
        alert('Please enter quantity larger than ' + MinimumQty + ' for this item');
        return false;
    }
    else if ((Number(document.getElementById('ctl00_CP_txtQuantity').value) < Number(MinimumQty))
				         || (Number(document.getElementById('ctl00_CP_txtQuantity').value) > Number(maxqty))) {
        if (MinimumQty == maxqty)
            alert('Please enter a quantity of ' + MinimumQty + ' for this item');
        else
            alert('Please enter a quantity between ' + MinimumQty + ' and ' + maxqty + ' for this item');
        //alert('Please enter a Minimum of ' + MinimumQty + ' Products'); 
        return false;
    }
    else if (document.getElementById('sizes') != null && typeof (document.getElementById('sizes')) != "undefined") {

        if ((Number(document.getElementById('ctl00_CP_txtQuantity').value)) > (Number(size.get_qty_by_id(document.getElementById('sizes').value)))) {

            //alert('Please enter a quantity less than ' + size.get_qty_by_id(document.getElementById('sizes').value)); 
            alert('Please enter a quantity of ' + size.get_qty_by_id(document.getElementById('sizes').value) + ' for this item');
            //alert('Quantity available is ' + size.get_qty_by_id(document.getElementById('sizes').value)); 
            return false;
        }
        else {
            return true;
        }
    }
    else if (document.getElementById('sizes') != null && typeof (document.getElementById('sizes')) != "undefined") {
        if ((Number(document.getElementById('ctl00_CP_txtQuantity').value))
					        > (Number(size.get_qty_by_id(mmid)))) {
            //alert('Please enter a quantity less than ' + size.get_qty_by_id(document.getElementById('sizes').value)); 
            alert('Please enter a quantity of ' + size.get_qty_by_id(mmid) + ' for this item');
            //alert('Quantity available is ' + size.get_qty_by_id(document.getElementById('sizes').value)); 
            return false;
        }
        else {

            return true;
        }
    }
    else {

        return true;
    }

}



function gethref() {
    var img = document.getElementsByName("colorIMG")[0];
    newpath = img.src;
    var Url = newpath.substring(0, newpath.indexOf("UploadedFiles/"));
    newpath = newpath.substring(newpath.indexOf("ProductImage/"));
    var str = newpath.split("/");
    str[0] = Url + "ViewImage.aspx?pid=" + str[1] + "&color=" + str[2] + "&fn=" + str[4].toString().split(".")[0];
    str[0] = str[0] + "&fe=." + str[4].toString().split(".")[1];

}

//changed by lava kumar to open the shadow box for each view - 13/June/2009
function li(path, imgnumber) {

    var newpath = path.replace("Thumb", "Product");

    var extension = newpath.substring(0, newpath.lastIndexOf(".")); // Multi image
    newpath = newpath.substring(newpath.lastIndexOf(".") - 1, newpath.lastIndexOf("."));
    /* Following switch case was added by team1c 18/07/2009 *** It basically sets the product image to the product type image by fetching the thumb image src and replacing the thumb with product and replacing the thumb image name attribute value which basically holds the product type image's extesntion*/

    if (!isNaN(newpath)) {
        switch (newpath) {
            case "1":
                document.images.colorIMG.src = extension + document.images.i0.name;
                break;
            case "2":
                document.images.colorIMG.src = extension + document.images.i1.name;
                break;
            case "3":
                document.images.colorIMG.src = extension + document.images.i2.name;
                break;
            case "4":
                document.images.colorIMG.src = extension + document.images.i3.name;
                break;
            case "5":
                document.images.colorIMG.src = extension + document.images.i4.name;
                break;
            case "6":
                document.images.colorIMG.src = extension + document.images.i5.name;
                break;
            default:
                break;
        }
    }
    if (!isNaN(newpath)) {

        for (i = 0; i < $d('largeview').childNodes.length; i++) {

            if ($d('largeview').childNodes[i].href.lastIndexOf("/" + newpath + ".") > 0) {
                $d('largeview').childNodes[i].innerHTML = "Large View";
                $d('lnkX').href = $d('largeview').childNodes[i].href;
                $d('lnkX').rel = $d('largeview').childNodes[i].rel;
                var rel = $d('lnkX').rel;
                rel = rel.replace(rel.substring(rel.indexOf('['), rel.indexOf(']')), rel.substring(rel.indexOf('['), rel.indexOf(']')) + "999");
                $d('lnkX').rel = rel;
            }
            else {
                $d('largeview').childNodes[i].innerHTML = "";
            }
        }
    }
    else {
        if ($d("lnkX").childNodes[1] != undefined) {
            $d('lnkX').href = $d("lnkX").childNodes[1].src;
        }
        else {
            if ($d("lnkX").childNodes[0] != undefined)
                $d('lnkX').href = $d("lnkX").childNodes[0].src;
        }

        $d('lnkX').rel = "shadowbox[p~~rn~~];options={counterType:'skip',continuous:true,animSequence:'sync'}";

    }

    if ($d('divvideo').style.display != "none")
        setlargeviewtonull()
    Shadowbox.setup();
}
function setlargeviewtonull() {
    var i = 0;
    for (i = 0; i < $d('largeview').childNodes.length; i++) {
        $d('largeview').childNodes[i].innerHTML = "";

    }

}





function setimageforonlycolor() {
    if (typeof (document.getElementById('sizes')) == "undefined" || document.getElementById('sizes') == null) {
        //if condition added by lava kumar,if there is no color and no size it is giving java script problem
        if (document.getElementById('ctl00_CP_ddlColor') != null) {
            var mmid = document.getElementById("ctl00_CP_ddlColor").options[document.getElementById("ctl00_CP_ddlColor").selectedIndex].id;
         }
        else {
            var mmid = location.href.substring(location.href.indexOf('MID') + 3, location.href.indexOf('.aspx'));
        }
    }

    if (document.getElementById('ctl00_CP_ddlColor') != null) {
        //sai

        //color.goto_slide_by_id(document.getElementById('ctl00_CP_ddlColor').innerHTML);
        var oDDL = document.getElementById('ctl00_CP_ddlColor');
        var curText = oDDL.options[oDDL.selectedIndex].text;
        color.goto_slide_by_id(curText);
        hidequantityforsoldout();

        if (typeof (document.getElementById('sizes')) != "undefined" && document.getElementById('sizes') != null) {
            document.getElementById('PriceText').innerHTML = size.get_price_by_id(document.getElementById('sizes').value);
            //alert('undefined');
        }
        else {
            //alert('defined');
            document.getElementById('PriceText').innerHTML = size.get_price_by_id(mmid);
        }
    }
    setprice();

}

//included by lavakumar,it hides the thumb image if it has only one view
function hideimages() {
    if (document.getElementById('ctl00_CP_hdnimage') != null) {
        if (document.getElementById('ctl00_CP_hdnimage').value == 'nocolor') {
            document.getElementById('CP_dlImage').style.cssText = "display:none;";
        }
        else if (document.getElementById('ctl00_CP_hdnimage').value != '') {
            if ((document.getElementById('ctl00_CP_hdnimage').value.indexOf(',' + document.getElementById("ctl00_CP_ddlColor").options[document.getElementById("ctl00_CP_ddlColor").selectedIndex].text + ',')) >= 0) {
                document.getElementById('CP_dlImage').style.cssText = "display:none;";
            }
            else {
                document.getElementById('CP_dlImage').style.cssText = "display:;";
            }
        }
        else {
            document.getElementById('CP_dlImage').style.cssText = "display:;";
        }
    }
}
function setprice() {

try
{

    Shadowbox.init({ skipSetup: false }); Shadowbox.setup();
    //included by lavakumar,it hides the thumb image if it has only one view
    hideimages();
    if (typeof (document.getElementById('sizes')) == "undefined" || document.getElementById('sizes') == null) {
        if (typeof (document.getElementById('ctl00_CP_ddlColor')) != "undefined" && document.getElementById('ctl00_CP_ddlColor') != null)
            mmid = document.getElementById("ctl00_CP_ddlColor").options[document.getElementById("ctl00_CP_ddlColor").selectedIndex].id;
        else
            mmid = location.href.substring(location.href.indexOf('MID') + 3, location.href.indexOf('.aspx'));
    }

    if (typeof (document.getElementById('sizes')) != "undefined" && document.getElementById('sizes') != null) {
        if (document.getElementById('sizes') != null) {
            size.goto_slide_by_id(document.getElementById('sizes').value);
            hidequantityforsoldout();
        }
    }
    else {
        size.goto_slide_by_id(mmid);
        hidequantityforsoldout(); ;
    }

    //added by lava kumar to open the shadow box on clicking the product image - 13/June/2009
   	
    
    if ($d("lnkX").childNodes[1] != undefined) {
        li($d("lnkX").childNodes[1].src, 0);
    }
    else {
        if ($d("lnkX").childNodes[0] != "undefined")
            li($d("lnkX").childNodes[0].src, 0);
    }
}
catch(e)
{
}
   
}


function hidequantityforsoldout() {

    if (document.getElementById('sizes') != null && typeof (document.getElementById('sizes')) != "undefined") {
        if (size.get_qty_by_id(document.getElementById('sizes').value) <= 0) {
            showORhide(false);
        }
        else {
            //document.getElementById("ctl00_CP_txtQuantity").value = size.get_qty_by_id(document.getElementById('sizes').value); 
            showORhide(true);
            }

    }
    else {
        if (document.getElementById('ctl00_CP_ddlColor') != null) {
            if (color.get_qty_by_id(document.getElementById('ctl00_CP_ddlColor').title) <= 0) {
                showORhide(false);
            }
            else {
                if (typeof (document.getElementById('ctl00_CP_ddlColor')) != "undefined" && document.getElementById('ctl00_CP_ddlColor') != null)
                    var mmid = document.getElementById("ctl00_CP_ddlColor").options[document.getElementById("ctl00_CP_ddlColor").selectedIndex].id;
                else
                    mmid = location.href.substring(location.href.indexOf('MID') + 3, location.href.indexOf('.aspx'));


                if (!isNaN(mmid)) {
                    if (size.get_qty_by_id(mmid) > 0) {
                        //document.getElementById("ctl00_CP_txtQuantity").value = size.get_qty_by_id(document.getElementById('sizes').value); 
                        showORhide(true);
                    }
                    else {
                        showORhide(false);
                    }
                }
                else {
                    //document.getElementById("ctl00_CP_txtQuantity").value = size.get_qty_by_id(document.getElementById('sizes').value); 
                    showORhide(true);
                }
            }
        }
        else {
            //var mmid1 = location.href.substring(location.href.indexOf('MID') + 3, location.href.indexOf('.aspx'));
            if (isNaN(location.href.substring(location.href.indexOf('MID') + 3, location.href.indexOf('.aspx'))))
                
		//sai-commented as right now the url has been changed and there is no more MID or aspx in URL-24Apr
		//showORhide(false);
		   showORhide(true);
            else {
                if (size.get_qty_by_id(location.href.substring(location.href.indexOf('MID') + 3, location.href.indexOf('.aspx'))) > 0) {
                    showORhide(true);
                }
                else {
                    showORhide(false);
                }
            }

        }
    }
}
function showORhide(IsShown) {
    if (IsShown) {
        if ($d("ctl00_CP_trQuantity") != null) {
            document.getElementById("ctl00_CP_trQuantity").style.cssText = "display:;";
        }
        if (document.getElementById("trsold") != null) {
             //document.getElementById("trsold").style.cssText = "display:none;";
            if(document.getElementById("ctl00_CP_hdnsoldout").value != "1")
                document.getElementById("trsold").style.cssText = "display:none;";
            else
                document.getElementById("trsold").style.cssText = "display:;";
        }
        if ($d("ctl00_CP_ibtnShoppingCart") != null && typeof ($d("ctl00_CP_ibtnShoppingCart")) != undefined)
            document.getElementById("ctl00_CP_ibtnShoppingCart").style.cssText = "display:;";
        if (typeof (document.getElementById("ctl00_CP_lbtnWish")) != "undefined" && document.getElementById("ctl00_CP_lbtnWish") != null)
            document.getElementById("ctl00_CP_lbtnWish").style.cssText = "display:;";
        if (typeof (document.getElementById("ctl00_CP_lbtnGift")) != "undefined" && document.getElementById("ctl00_CP_lbtnGift") != null)
            document.getElementById("ctl00_CP_lbtnGift").style.cssText = "display:;";
        //Following condition was added by team1c on 06/04/2009 in order to hide the tr which holds the notes textfield
        if (typeof (document.getElementById("ctl00_CP_trDonationnotes")) != "undefined" && document.getElementById("ctl00_CP_trDonationnotes") != null)
            document.getElementById("ctl00_CP_trDonationnotes").style.cssText = "display:;";
    }
    else {
        if ($d("ctl00_CP_trQuantity") != null) {
            document.getElementById("ctl00_CP_trQuantity").style.cssText = "display:none;";
        }
        if (document.getElementById("trsold") != null) {
            //document.getElementById("trsold").style.cssText = "display:;";

            if(document.getElementById("ctl00_CP_hdnsoldout").value != "1")
                document.getElementById("trsold").style.cssText = "display:none;";
            else
                document.getElementById("trsold").style.cssText = "display:;";
        }
        if ($d("ctl00_CP_ibtnShoppingCart") != null && typeof ($d("ctl00_CP_ibtnShoppingCart")) != undefined)
            document.getElementById("ctl00_CP_ibtnShoppingCart").style.cssText = "display:none;";
        if (typeof (document.getElementById("ctl00_CP_lbtnWish")) != "undefined" && document.getElementById("ctl00_CP_lbtnWish") != null)
            document.getElementById("ctl00_CP_lbtnWish").style.cssText = "display:none;";
        if (typeof (document.getElementById("ctl00_CP_lbtnGift")) != "undefined" && document.getElementById("ctl00_CP_lbtnGift") != null)
            document.getElementById("ctl00_CP_lbtnGift").style.cssText = "display:none;";
        //Following condition was added by team1c on 06/04/2009 in order to hide the tr which holds the notes textfield
        if (typeof (document.getElementById("ctl00_CP_trDonationnotes")) != "undefined" && document.getElementById("ctl00_CP_trDonationnotes") != null)
            document.getElementById("ctl00_CP_trDonationnotes").style.cssText = "display:none;";
    }
}
function setsize() {
    var s = document.getElementById('sizes');

    if (document.getElementById('ctl00_CP_hdnGid') != "0" && s != null) {
        //document.getElementById('sizes').selectedvalue = document.getElementById('ctl00_CP_hdnGid');
        var v = document.getElementById('ctl00_CP_hdnGid').value;
        for (var i = 0; i < s.options.length; i++) {
            if (s.options[i].value == v) {
                s.options[i].selected = true;
                return;
            }
        }
    }

}


function setvalues(groupdetail1name) {

    if (document.getElementById('ctl00_CP_ddlColor') != null) {
        for (i = 0; i < document.getElementById('ctl00_CP_ddlColor').length; i++) {
            //sai
            if (document.getElementById('ctl00_CP_ddlColor').options[i].text == groupdetail1name) {
                //alert(document.getElementById('ctl00_CP_ddlColor').options[i].text);
                document.getElementById('ctl00_CP_ddlColor').selectedIndex = i
            }
        }
    }
    //included by lava kumar for swatch images
    setimageforonlycolor();
    applyCascadingDropdowns();
    //      color.goto_slide_by_id(groupdetail1name);
}


function productdetailsend() {
    color.set_image(document.images.colorIMG);
    color.set_image0(document.images.i0);
    color.set_image1(document.images.i1);
    color.set_image2(document.images.i2);
    color.set_image3(document.images.i3);
    color.set_image4(document.images.i4);
    color.set_image5(document.images.i5);
    //color.goto_slide(0);
    if (document.getElementById('ctl00_CP_ddlColor') != null) {
        //sai
        //color.goto_slide_by_id(document.getElementById('ctl00_CP_ddlColor').innerHTML);
        var oDDL = document.getElementById('ctl00_CP_ddlColor');
        var curText = oDDL.options[oDDL.selectedIndex].text;
        color.goto_slide_by_id(curText);

    }
    else {
        color.goto_slide(0);
    }
    size.set_textid('PriceText');
    //inlcuded by lava kumar to hide the price depening the show price column
    if (document.getElementById('ctl00_CP_hdnprice').value == "0") {
        document.getElementById('PriceText').style.cssText = "display:none;";
    }
    if (document.getElementById('sizes') != null) {
        size.goto_slide(document.getElementById('sizes').value);
    }
    hidequantityforsoldout();
 
}




