﻿var fvid;
function changeddl(fieldid, ddl, lblfield, lblfieldvalue) {
    var field = document.getElementById(lblfield);
    var fieldvalue = document.getElementById(lblfieldvalue);
    var ddlvalue = document.getElementById(ddl);



    var fvsplit = new Array();
    if (fvid != undefined) {
        fvsplit = fvid.split(',');
    }

    if (!isNaN(parseInt(ddlvalue.value))) {

        for (var i = 0; i < ddlvalue.length; i++) {
            if (ddlvalue.options[i].value != "---Select---") {

                if (fvsplit != undefined) {
                    if (fvsplit.length > 0) {

                        for (var j = 0; j <= fvsplit.length; j++) {

                            if (fvsplit[j] == ddlvalue.options[i].value) {

                                fvid = fvid.replace(ddlvalue.options[i].value, " ");
                                var intIndexOfMatch = fvid.indexOf(" ,");

                                while (intIndexOfMatch != -1) {
                                    fvid = fvid.replace(" ,", "")
                                    intIndexOfMatch = fvid.indexOf(" ,");
                                }

                            }
                        }
                    }
                }

            }
        }


        fvid = fvid + "," + ddlvalue.value;

    }
    fieldvalue.value = fvid;
    alert(fvid);
}

function showmsg(prdname, prdqty) {

    //    var msg1 = "Product Name                   Available Stock";

    //    var msg2 = "--------------------------------------------";

    //    var msg3 = "Limited Stock Only";

    //    alert(msg1 + "\n" + msg2 + "\n" + prdname + "                                   " + prdqty + " \n\r \n\r" + msg3);


    var msg3 = "Product stock of " + prdname + " is limited...";

    alert(msg3 + "\n" + "Only " + prdqty + " Quantity Is Available");
}
function changeimage(imageid, path, imgname, atagid) {
    var img = document.getElementById(imageid);


    img.src = path + "createimage.aspx?path=uploadimage\\ProductImg\\" + imgname + "&height=271&width=271";

}
function changeprice() {
    var checkboxvalue = document.getElementById('ctl00_ContentPlaceHolder1_chkcheses').checked;
    if (checkboxvalue) {
        document.getElementById('ctl00_ContentPlaceHolder1_lblprice').style.display = 'none';
        document.getElementById('ctl00_ContentPlaceHolder1_lblpricewithcheses').style.display = '';
    }
    else {
        document.getElementById('ctl00_ContentPlaceHolder1_lblprice').style.display = '';
        document.getElementById('ctl00_ContentPlaceHolder1_lblpricewithcheses').style.display = 'none';
    }
}
function checkQuantity() {

    var qty = document.getElementById('txtqty').value;
    var availqty = document.getElementById('txtavailqty').innerHTML;
    if (parseInt(availqty) < parseInt(qty)) 
    {
        var prdname = document.getElementById('lblproducttitle').innerHTML
        var msg3 = "Product stock of " + prdname + " is limited to " + availqty;
        alert(msg3);        
        return false;
    }
    else 
    {
        return true;
    }
}

function checkQuantity1() {

    var qty = document.getElementById('ctl00_MasterContent_txtqty').value;
    var availqty = document.getElementById('ctl00_MasterContent_txtavailqty').innerHTML;
    if (parseInt(availqty) < parseInt(qty)) {
        var prdname = document.getElementById('ctl00_MasterContent_lblproducttitle').innerHTML
        var msg3 = "Product stock of " + prdname + " is limited to " + availqty;
        alert(msg3);
        return false;
    }
    else {
        return true;
    }
}   



//moved from master page 
 function replaceSubstring(inputString, fromString, toString) {
                // Goes through the inputString and replaces every occurrence of fromString with toString
                var temp = inputString;
                if (fromString == "") {
                    return inputString;
                }
                if (toString.indexOf(fromString) == -1) { // If the string being replaced is not a part of the replacement string (normal situation)
                    while (temp.indexOf(fromString) != -1) {
                        var toTheLeft = temp.substring(0, temp.indexOf(fromString));
                        var toTheRight = temp.substring(temp.indexOf(fromString) + fromString.length, temp.length);
                        temp = toTheLeft + toString + toTheRight;
                    }
                } else { // String being replaced is part of replacement string (like "+" being replaced with "++") - prevent an infinite loop
                    var midStrings = new Array("~", "`", "_", "^", "#");
                    var midStringLen = 1;
                    var midString = "";
                    // Find a string that doesn't exist in the inputString to be used
                    // as an "inbetween" string
                    while (midString == "") {
                        for (var i = 0; i < midStrings.length; i++) {
                            var tempMidString = "";
                            for (var j = 0; j < midStringLen; j++) { tempMidString += midStrings[i]; }
                            if (fromString.indexOf(tempMidString) == -1) {
                                midString = tempMidString;
                                i = midStrings.length + 1;
                            }
                        }
                    } // Keep on going until we build an "inbetween" string that doesn't exist
                    // Now go through and do two replaces - first, replace the "fromString" with the "inbetween" string
                    while (temp.indexOf(fromString) != -1) {
                        var toTheLeft = temp.substring(0, temp.indexOf(fromString));
                        var toTheRight = temp.substring(temp.indexOf(fromString) + fromString.length, temp.length);
                        temp = toTheLeft + midString + toTheRight;
                    }
                    // Next, replace the "inbetween" string with the "toString"
                    while (temp.indexOf(midString) != -1) {
                        var toTheLeft = temp.substring(0, temp.indexOf(midString));
                        var toTheRight = temp.substring(temp.indexOf(midString) + midString.length, temp.length);
                        temp = toTheLeft + toString + toTheRight;
                    }
                } // Ends the check to see if the string being replaced is part of the replacement string or not
                return temp; // Send the updated string back to the user
            } // Ends the "repl


            function ProductString(productstr) {

                if (productstr.length > 10) {
                    var myNewString = replaceSubstring(productstr, "_", "&nbsp;");
                    document.getElementById('ProductstrVal').innerHTML = myNewString;
                }
            }
            
            
        function checkurl(str, str1) {

            document.getElementById(str1).href = str1;
            return false;
        }
        function ShoWproductInfo(url, width1, height1) {


            //alert(url);
            wintest = new Window({ className: "spread", title: "Product Details",
                recenterAuto: false, minimizable: false, maximizable: false, width: width1, height: height1, url: url, showEffectOptions: { duration: 1.5 }
            })

            wintest.showCenter(true);
            wintest.maximizable = false;
            wintest.minimizable = false;
            wintest.show();
            //wintest.setLocation(25,16);
            return false;
        }
        
        
        
        function closeWin(strqty, strprice, strproduct, strurl) // call after clicking cancel in register popup
        {

            wintest.close(wintest.getId());
            document.getElementById('ctl00_SpValue').innerHTML = strqty;
            document.getElementById('ctl00_SpPrice').innerHTML = strprice;
            var myNewString = replaceSubstring(strproduct, "_", "&nbsp;");
            if (myNewString.length > 10) {
                document.getElementById('ProductstrVal').innerHTML = myNewString;
            }
            if (strurl.length > 10)
                window.location = strurl;
        }                   
