﻿var timerCounter = 1000;
var counter = 0;
function SetSize(obj, btName, lbError, qty, ojbQantity, droplist, cardId, proOjb, lblselectSize, lblQuantity, buttonLocation) {
    if (obj != null) {
        obj.style.backgroundColor = "#c64340";
        obj.style.color = "white";
        obj.style.fontWeight = "bold";
       // var lbErrorObj = document.getElementById(lbError);

        var indexCurrentSize = document.getElementById("currentSizeIndex");
        indexCurrentSize.value = btName;
        var droplistAlertText = document.getElementById("droplistAlertText");
        if (droplistAlertText != null) {
            droplistAlertText.value = droplist;
        }
        var hidden = document.getElementById(btName);
        //var hiddenOrderSize = document.getElementById("orderSize");
        if (hidden != null ) {
            if (hidden.value != null && hidden.value != "") {
                var oldChoice = document.getElementById(hidden.value);
                if (oldChoice != null) {
                    oldChoice.style.fontWeight = "normal";
                    oldChoice.style.backgroundColor = "white";
                    oldChoice.style.color = "black";
                }
            }

            if (obj.id == hidden.value) {
                hidden.value = "";
                //lbErrorObj.style.display = "inline";
            }
            else {
                hidden.value = obj.id;
//                if (lbErrorObj.style.display == "inline") {
//                    lbErrorObj.style.display = "none";
//                }
            }
        }
       // document.getElementById(ojbQantity).onclick = Function("createQuantity('" + qty + "','" + "','" + ojbQuantity + "')");
        createQuantity(qty, droplist, ojbQantity, lblselectSize, lblQuantity, buttonLocation);

        var orderCardID = document.getElementById(cardId);
        document.getElementById("orderCardID").value = orderCardID.value;
        var orderSize = document.getElementById(btName);
        document.getElementById("orderSize").value = orderSize.value;
        var orderQuantity = document.getElementById(ojbQantity);
        document.getElementById("orderDropListSelectChange").value = orderQuantity.value;
        var prodID = document.getElementById(proOjb);
        document.getElementById("orderProductID").value = prodID.value;

        var lbErrorObj = document.getElementById("lbsucces");
        if (lbErrorObj!=null)
            lbErrorObj.innerHTML = "";
        var contentDisplay = document.getElementById("divAlertSize");

       
        
        contentDisplay.style.display = "none";
        //hidden.value = "";
    }


}

function Validate(sender, args){     
       args.IsValid = false;     
       if(args.Value != "")     
       {         
         args.IsValid = true;
       }
}

function changeToWhiteBrg(obj) {
    var text = document.getElementById(obj).value;
    if (text != "") {
        $('#' + obj).css("background-color", "White");
    }
    else {
        $('#' + obj).css("background-color", "#FFCCCC");
    }
}

function TextChangeEventArg(textOjb) {
    $('#' + textOjb).keyup(function (event) {
        var text = document.getElementById(textOjb).value;
       if (text != "") {
            $('#' + textOjb).css("background-color", "White");
        }
        else {
            $('#' + textOjb).css("background-color", "#FFCCCC");
        }       
    });


}

function TextChangeEventArgPhone(currentPhone, otherPhone) {
    $('#' + currentPhone).keyup(function (event) {
        var text1 = document.getElementById(currentPhone).value;
        var text2 = document.getElementById(otherPhone).value;
        if (text1 != "" || text2 != "") {
            $('#' + currentPhone).css("background-color", "White");
            $('#' + otherPhone).css("background-color", "White");

        }
        else if (text1 == "" && text2 == "") {
            $('#' + currentPhone).css("background-color", "#FFCCCC");
            $('#' + otherPhone).css("background-color", "#FFCCCC");
        }
    });


}




function createQuantity(qty, droplistContaint, ojbQuantity, lblselectSize, lblQuantity, buttonLocation) {

    if (qty != null  && qty != 0) {
        var quantityObj = document.getElementById(ojbQuantity);
        quantityObj.value = 1;
        var dropContaint = document.getElementById(droplistContaint);
        dropContaint.innerHTML = "";
        var dropList = document.createElement("Select"); // document.getElementById("ctl00_contentPlaceHolder_ctl00_slQuantity");
        
        dropList.onchange = function () {SetQuantityValue(ojbQuantity )};
        //dropList.setAttribute("onchange", "SetQuantityValue('" + ojbQuantity + "')");
        dropList.setAttribute("class", "selectdetail");
//        dropList.setAttribute("onfocus", "javascript: this.style.width='auto'");
//        dropList.setAttribute("onblur", "javascript: this.style.width=160;");
        dropList.setAttribute("style", "width:160px");
        dropList.setAttribute("id", "quantityList");
        
        if (qty > 5) {
            qty = 5;
        }

       // dropList.innerHTML = "";
        //var strOption = '<select> id ="quantityList" class="selectdetail" onchange=SetQuantityValue("' + ojbQuantity + '")';

        for (var i = 1; i <= qty; i++) {
            var option = document.createElement('option');            
            //strOption = strOption + "<option value=" + i + ">" + i + "</option>";
            option.value = i;
            option.innerHTML = i;
            dropList.appendChild(option);
        }

         //strOption = strOption + "</select>";
        // dropContaint.innerHTML = strOption;
        dropContaint.appendChild(dropList);
       // alert(dropContaint.innerHTML.toString());
        var btnbt = document.getElementById(buttonLocation);
        if (btnbt != null) {
            btnbt.style.display = 'inline';
        }
        var addButton = document.getElementById("AddToCard");
        if (addButton != null) {
            addButton.style.display = 'inline';
        }
        var seQuantity = document.getElementById(lblQuantity);
        if (seQuantity != null)
            seQuantity.style.display = 'inline';
        var lblQuantityHidden = document.getElementById('lblQuantityHidden');
        if (lblQuantityHidden != null) {
            lblQuantityHidden.value = lblQuantity;
        }
    }
    else if (qty == 0) {
        var dropContaint = document.getElementById(droplistContaint);
        dropContaint.innerHTML = "";

        var span2 = document.createElement('span');
        span2.innerHTML = "Please select size";
        span2.style.color = "Red";
        span2.style.fontSize = "12px";
        dropContaint.appendChild(span2);

        var seSize = document.getElementById(lblselectSize);
        if (seSize != null)
            seSize.style.display = 'inline';

        var seQuantity = document.getElementById(lblQuantity);
        if (seQuantity != null)
            seQuantity.style.display = 'none';

        var addButton = document.getElementById("AddToCard");
        if (addButton != null) {
            addButton.style.display = 'inline';
        }

       

    }   
    else {
        var dropContaint = document.getElementById(droplistContaint);
        dropContaint.innerHTML = "";
        var span2 = document.createElement('span');
        span2.innerHTML = "This product is currently out of stock";
        
        span2.style.color = "Red";
        span2.style.fontSize = "14px";
        dropContaint.appendChild(span2);

        var seSize = document.getElementById(lblselectSize);
        if (seSize != null)
            seSize.style.display = 'none';

        var seQuantity = document.getElementById(lblQuantity);
        if (seQuantity != null)
            seQuantity.style.display = 'none';

        var addButton = document.getElementById("AddToCard");
        if (addButton != null) {
            addButton.style.display = 'none';
        }
    }
       
}


function AddCardPreClick(sizeMsg, size) {
    var sMsg = document.getElementById(sizeMsg);
    var span2 = document.createElement('span');
    span2.innerHTML = "Please select size";
    span2.style.color = "Red";
    span2.style.fontSize = "12px";
    //dropContaint.appendChild(span2);

    var getSize = document.getElementById(size);
    if (getSize == null) {
        sMsg.appendChild(span2);
        alert("hh");
    }
    else {
        if (sMsg.value == "") {
            sMsg.appendChild(span2);
            alert("hh33");
        }

    }
}


function SetQuantityValue(objID){
    var quantity = document.getElementById('quantityList');
    var quantityObj = document.getElementById(objID);
    quantityObj.value = quantity.value;
    document.getElementById("orderDropListSelectChange").value = quantity.value;
}


function SetColorArea(obj, color) {
    if (obj != null) {
        obj.style.backgroundColor = color;
    }
}

function SetColorArea1(obj, btName, lbError, color) {
    if (obj != null) {
        obj.style.backgroundColor = "Red";
        obj.style.color = color ;
        obj.style.fontWeight = "bold";
        var lbErrorObj = document.getElementById(lbError);

        var hidden = document.getElementById(btName);
        if (hidden != null) {
            if (hidden.value != null && hidden.value != "") {
                var oldChoice = document.getElementById(hidden.value);
                if (oldChoice != null) {
                    oldChoice.style.fontWeight = "normal";
                    oldChoice.style.backgroundColor = "Red";
                    //oldChoice.style.color = "black";
                }
            }

            if (obj.id == hidden.value) {
                hidden.value = "";
                lbErrorObj.style.display = "inline";
            }
            else {
                hidden.value = obj.id;
                if (lbErrorObj.style.display == "inline") {
                    lbErrorObj.style.display = "none";
                }
            }
        }
    }
}

function detect() {
    framesetpage = "guideclothing.co.uk";
    thispage = window.location.href;
    if (thispage.indexOf('://') < 0) { thispage = "://" + thispage; };
    prefix = thispage.substring(0, thispage.lastIndexOf('://'));
    suffix = thispage.substring(thispage.lastIndexOf('://') + 3, thispage.length);
    // alert('the subpage is:['+prefix+']['+suffix+']');
    if (parent.location.href == window.location.href) { parent.location.href = framesetpage + "?" + prefix + "&&&" + suffix };
}


function createPopUpForm(datasource) {

    div = document.createElement('div');
    div.className = "ShowProductAdded";
    table = document.createElement('table');
    tr1= document.createElement('tr');
    td11 = document.createElement('td');
    img = document.createElement('img');
    img.src = "http://images.guideclothing.com/images/40_60/LS.71847%20Black.jpg";
    td11.appendChild(img);
    td12 = document.createElement('td');
    span1 = document.createElement('span');
    span1.innerHTML = "Test";
    td12.appendChild(span1);
    tr1.appendChild(td11);
    tr1.appendChild(td12);
    table.appendChild(tr1);
    div.appendChild(table);
    var content = document.getElementById("buttonAddCard");
    content.appendChild(div);
//    tr2 = document.createElement('tr');
//    td21 = document.createElement('td');
//    td22 = document.createElement('td');

}

function showpopup() {
    var testpopup3 = new popup('popUpDiv');
    testpopup3.visible = true;
//    testpopup3.height = 200;
//    testpopup3.width = 200;
    testpopup3.offsetY = 20;
}

function showpopupMouseOver() {
    var testpopup3 = new popupMouseOver('mouseOverContentID');
    testpopup3.visible = true;    
    testpopup3.offsetY = 20;
}

function buttonMouseOver() {
    var contentDisplay = document.getElementById("divAlertSize");
    if (contentDisplay != null)
        contentDisplay.style.display = "none"
}

function onload() {
    alert("AAA");
}
function addCardID(cId) {
    if (cId != null || cId != "") {
        if (document.getElementById("orderCardID") != null) {
            document.getElementById("orderCardID").value = cId;
        }
    }
}

function UpdateBasKet(cardId, orderProductId, size, quantity)
{ }


function AddToShoppingCard() {

   
   
   
    var dataInput = "";
    var cardID = document.getElementById("orderCardID").value;
    var orderProductID = document.getElementById("orderProductID").value;
    var orderSize = document.getElementById("orderSize").value;
    
   
    var orderDropListSelectChange = document.getElementById("orderDropListSelectChange").value;

    if (orderSize == "" || orderSize == "null") {

        var alertDiv = document.createElement('div');
        alertDiv.className = "alertSelectSize";

        var alertSpan = document.createElement('span');
        alertSpan.innerHTML = "Please select size first";
        alertSpan.style.fontSize = "12px";
        alertSpan.style.color = "#FFFFFF";
        
        alertDiv.appendChild(alertSpan);

        var contentDisplay = document.getElementById("divAlertSize");
        contentDisplay.style.display = "inline";
        contentDisplay.appendChild(alertDiv);
        return;
    }

    dataInput = cardID + "," + orderProductID + "," + orderSize + "," + orderDropListSelectChange;

    

    var buttonAdd = document.getElementById("AddToCard");
    buttonAdd.style.visibility = "hidden";



    var content = document.getElementById("buttonAddCard");
    content.innerHTML = "";
    var div = document.createElement('div');
   // div.setAttribute("id", "processingId");
    var span = document.createElement('span');
    span.innerHTML = "Processing...";
    div.appendChild(span);
    var img = document.createElement('img');
    img.src = "images/ProcessingPics.gif";
    // div.className = "Processing";
    div.appendChild(img);
    div.appendChild(span);
    content.appendChild(div);

    $(document).ready(function () {
        //            var msgbox = $("#status");
        // $("#AddToCard").click(function() {
        $.ajax({
            type: "POST",

            url: "Default.aspx/AddToCart",
            data: "{'dataInput':'" + dataInput + "'}",
            contentType: "application/json; charset=utf-8",

            dataType: "json",

            success: function (result) {

                if (result.d == "") {

                    var lbErrorObj = document.getElementById("lbsucces");
                    document.getElementById(orderSize).style.fontWeight = "normal";
                    document.getElementById(orderSize).style.backgroundColor = "white";
                    document.getElementById(orderSize).style.color = "black";
                    lbErrorObj.innerHTML = "Product was NOT added to shopping bag";


                    buttonAdd.style.visibility = "visible";
                    //div.style.visibility = "hidden";
                    div.innerHTML = "";
                    return;
                }

                //                $(document).ready(function () {
                //                    $('#Button1').click(function () {
                //$.blockUI({ message: '<h1> Processing...</h1>' });
                var ControlName = "UserControls/ViewBag.ascx&" + cardID;
                $.ajax({
                    type: "POST",
                    url: "Default.aspx/Result",
                    data: "{controlName:'" + ControlName + "'}",
                    contentType: "application/json; charset=utf-8",
                    dataType: "json",
                    success: function (response) {
                        //  $.unblockUI();
                        showpopup();




                        $('#popUpDiv').html(response.d);

                        document.getElementById(orderSize).style.fontWeight = "normal";
                        document.getElementById(orderSize).style.backgroundColor = "white";
                        document.getElementById(orderSize).style.color = "black";


                        var lbErrorObj = document.getElementById("lbsucces");
                        lbErrorObj.style.display = "inline";
                        var itemOjb = result["d"].split(":")[1] + " ";
                        var priceOjb = result["d"].split(":")[0];


                        var span1 = document.createElement('span');
                        span1.innerHTML = itemOjb;

                        var span2 = document.createElement('span');
                        span2.innerHTML = priceOjb;

                        var test1 = document.getElementById("shoppingBagItems");
                        test1.title = "";
                        test1.innerHTML = "";
                        test1.appendChild(span1);

                        var test2 = document.getElementById("shoppingBagPrices");
                        test2.title = "";
                        test2.innerHTML = "";
                        test2.appendChild(span2);
                        lbErrorObj.innerHTML = "Product was add to shopping bag";

                        var checkoutlink = document.getElementById("checkoutLinkID");
                        checkoutlink.innerHTML = "CheckOut";
                        checkoutlink.title = "CheckOut";


                        buttonAdd.style.visibility = "visible";
                        //div.style.visibility = "hidden";


                        //                var quantitylist = document.getElementById("quantityList");
                        //                if (quantitylist != null) {
                        //                    quantitylist.style.visibility = "hidden";
                        //                }
                        //                document.getElementById("orderSize").value = "";

                        var droplistAlertText = document.getElementById("droplistAlertText");
                        if (droplistAlertText != null) {
                            var dropContaint = document.getElementById(droplistAlertText.value);
                            dropContaint.innerHTML = "";
                            var span2 = document.createElement('span');
                            span2.innerHTML = "Please select size";
                            span2.style.color = "Red";
                            span2.style.fontSize = "12px";
                            dropContaint.appendChild(span2);
                        }

                        //                        var getProcessingDiv = document.getElementById("processingId");
                        //                        if (getProcessingDiv != null) {
                        //                            getProcessingDiv.innerHTML = "";
                        //                        }
                        div.innerHTML = "";
                        document.getElementById("orderSize").value = "";
                        var indexCurrentSize = document.getElementById("currentSizeIndex");
                        document.getElementById(indexCurrentSize.value).value = "";


                        var lblQuantityHidden = document.getElementById('lblQuantityHidden');
                        if (lblQuantityHidden != null) {
                            document.getElementById(lblQuantityHidden.value).style.display = "none";
                            
                        }
                    },
                    failure: function (msg) {
                        //  $.unblockUI();
                        $('#popUpDiv').html(msg);
                    }
                });

            }
        });
    });

}


function UpdateAddress(Street1, Street2, Town, County, Country, PostCode, CompanyName, id,userName) {

    var inputData = document.getElementById(Street1).value + "|" +
                    document.getElementById(Street2).value + "|" +
                    document.getElementById(Town).value + "|" +
                    document.getElementById(County).value + "|" +
                    document.getElementById(Country).value + "|" +
                    document.getElementById(PostCode).value + "|" +
                    document.getElementById(CompanyName).value + "|" +
                    id + "|" + userName;
    
    $(document).ready(function () {
        var ControlName = "UserControls/ViewBag.ascx&" + cardID + "&mouse=OK";
        $.ajax({
            type: "POST",
            url: "Default.aspx/UpdateAddress",
            data: "{controlName:'" + inputData + "'}",
            contentType: "application/json; charset=utf-8",
            dataType: "json",
            success: function (response) {

                if (response.d == "") {
                    return;
                }
               
            },
            failure: function (msg) {
                //  $.unblockUI();
                container.innerHTML = msg;
            }
        });

    });
}

function BasketMouseOver() {
//    if (($.browser.msie) && ($.browser.version == "6.0")){
//        alert('IE6 Detected');
//    }

    // alert("In");

//    var myViewState = document.getElementById("__VIEWSTATE");
//    var viewStateValue;
//    if (myViewState != null)
    //        viewStateValue = myViewState.value;
    
    var getPopUp = document.getElementById("popUpDiv");

    
    if (getPopUp == null || (getPopUp != null && getPopUp.offsetTop == 0)) {



        if (document.getElementById("orderCardID") != null) {
            var cardID = document.getElementById("orderCardID").value;
            $(document).ready(function () {
                var ControlName = "UserControls/ViewBag.ascx&" + cardID + "&mouse=OK";
                $.ajax({
                    type: "POST",
                    url: "Default.aspx/Result",
                    data: "{controlName:'" + ControlName + "'}",
                    contentType: "application/json; charset=utf-8",
                    dataType: "json",
                    success: function (response) {

                        if (response.d == "") {
                            return;
                        }

                        showpopupMouseOver();
                        $('#mouseOverContentID').html(response.d);

                    },
                    failure: function (msg) {
                        //  $.unblockUI();
                        container.innerHTML = msg;
                    }
                });

            });
        }
    }
}

function BasketMouseLeave() {
    // document.getElementById(oriPic).src = newPictureSrc;   
//    $('#containercontent').css("z-index", "1").css("position", "relative");
//    $('#quantityList').css("display","inline");
//    var container = document.getElementById('mouseOvershoppingID');
//   
//        if (container != null) {
//            container.className = "nonedisplay";
//           
    //        }


    var getPopUp = document.getElementById("popUpDiv");


    if (document.getElementById('checkoutLinkID').innerHTML != "") {
        if (getPopUp == null || (getPopUp != null && getPopUp.offsetTop == 0)) {
            showpopupMouseOver();
        }
    }
}

function CheckSize(lbError, lbErrorTxt, btsize, lbsucces, dataInput) {
          
    var hidden = document.getElementById(btsize);

    if (hidden.value == null || hidden.value == "") {
        var objError = document.getElementById(lbError);
        var objErrorTxt = document.getElementById(lbErrorTxt);
        if (objError != null && objErrorTxt != null) {
            objError.style.display = "inline";
           // objErrorTxt.style.display = "block";
        }

        var objsucces = document.getElementById(lbsucces);
        if (objsucces != null && objsucces.style.display == "block") {
            objsucces.style.display = "none";
        }
        return false;
    }
    return true;
}

function GetBiggerPicture(obj, bigImg) {
    if (bigImg != null) {
        bigImg.style.display = "block";
    }
}

function CancleBiggerPicture(bigImg, obj) {
    if (bigImg != null) {
        bigImg.style.display = "none";
    }
}

function ChangePicture(obj, path) {
    if (obj != null) {
        obj.src = path;
    }
}

function ValidateNumeric() {
    var keyCode = window.event.keyCode;
    if (keyCode > 57 || keyCode < 4)
        window.event.returnValue = false;
}

function SetDeliveryAddress(obj, arrayAddress) {

    if (obj != null && arrayAddress != null) {
        for (var i = 0; i < arrayAddress.length; i++) {
            var obj1 = document.getElementById(arrayAddress[i]);
            i++;
            var obj2 = document.getElementById(arrayAddress[i]);
            if (obj.checked == false) {
                if (obj2 != null) {
                    obj2.value = "";
                    obj2.readOnly = false;
                    obj2.color = "black";
                    if (i == 1 || i == 5 || i == 9 || i == 11) {
                        $('#' + arrayAddress[i]).css("background-color", "#FFCCCC");
                    }
                    
                }
            }
            else {
                if (obj1 != null && obj2 != null) {
                    obj2.value = obj1.value;
                    obj2.readOnly = true;
                    obj2.color = "grey";
                    if (obj2.value != "") {
                        $('#' + arrayAddress[i]).css("background-color", "White");
                    }
                }
            }
        }
    }
}

function ChangeAddress(obj, myArray, arrayNameObj, btChange) {
    Address = myArray.split('|||');
    if (Address != null && obj != null) {
        var chooseAddress = obj.selectedIndex - 1;
        if (chooseAddress != null) {
            if (Address.length >= chooseAddress) {
                for (var i = 0; i < arrayNameObj.length; i++) {
                    var obj1 = document.getElementById(arrayNameObj[i]);
                    if (obj1 != null) {
                        if (chooseAddress < 0) {
                            obj1.value = "";
                            obj1.readOnly = false;
                            obj1.color = "black";
                            if (i == 1 || i == 3 || i == 5 || i == 6) {
                                $('#' + arrayNameObj[i]).css("background-color", "#FFCCCC");
                            }
                            
                        }
                        else {
                            obj1.value = Address[chooseAddress].split(',')[i];
                            obj1.readOnly = true;
                            obj1.color = "grey";
                            if (obj1.value != "") {
                                $('#' + arrayNameObj[i]).css("background-color", "White");
                            }

                        }
                    }
                }

                if (chooseAddress < 0) {
                    btChange.disabled = false;
                    btChange.className = "btfilter";
                }
                else {
                    btChange.disabled = true;
                    btChange.className = "btfilterdisabled";
                }
            }
        }
    }
}

function ChangeDeliveryAddress(obj, delivery, checkbox) {
    var objdelivery = document.getElementById(delivery);
    var objCheckbox = document.getElementById(checkbox);

    if (delivery != null && obj != null) {
        if (objCheckbox.checked == true) {
           // objdelivery.value = obj.value;
         //   changeToWhiteBrg(delivery);
        }
    }
}

function FillHiddenBt(obj, price, address, cartId, hash) {
    if (counter == 0) {
        var objTransId = document.getElementById("trans_id");
        if (objTransId != null) {

            objTransId.value = cartId;
        }
        var objAmount = document.getElementById("amount");
        if (objAmount != null) {
            objAmount.value = price;
        }


        var objDigest = document.getElementById("digest");
        if (objDigest != null) {
            objDigest.value = hash;
        }

        var arr = address.split(",");
        var bill_name = document.getElementById("bill_name");
        if (bill_name != null) {
            bill_name.value = arr[0].split("=")[1];
        }
        var bill_company = document.getElementById("bill_company");
        if (bill_company != null) {
            bill_company.value = arr[1].split("=")[1];
        }
        var bill_addr_1 = document.getElementById("bill_addr_1");
        if (bill_addr_1 != null) {
            bill_addr_1.value = arr[2].split("=")[1];
        }
        var bill_addr_2 = document.getElementById("bill_addr_2");
        if (bill_addr_2 != null) {
            bill_addr_2.value = arr[3].split("=")[1];
        }
        var bill_city = document.getElementById("bill_city");
        if (bill_city != null) {
            bill_city.value = arr[4].split("=")[1];
        }
        var bill_country = document.getElementById("bill_country");
        if (bill_country != null) {
            bill_country.value = arr[6].split("=")[1];
        }
        var bill_post_code = document.getElementById("bill_post_code");
        if (bill_post_code != null) {
            bill_post_code.value = arr[7].split("=")[1];
        }
        var bill_email = document.getElementById("bill_email");
        if (bill_email != null) {
            bill_email.value = arr[8].split("=")[1];
        }

        

        return true;
    }
}


function CreateInformationDiv(obj, colors, description, refNo, colourID) {
    document.cookie = "colourID=" + colourID;    
//     $(document).ready(function () {        
//        $.ajax({
//            type: "POST",

//            url: "Default.aspx/SetEnCode",
//            data: "{'dataInput':'" + colourID + "'}",
//            contentType: "application/json; charset=utf-8",
//            dataType: "json",
//            success: function (result) {


//                document.cookie = "colourID=" + result.d;                                        
//             },
//            failure: function () {            
//            }
//          });
//        })
}


function ChangePicture(obj, mainPic, newPicsrc, sizeArr, refID, refNo, price, sizeID, btnSize, msgError, idOfProduct, productID, ojbQuantity, droplist, cardID, lblselectSize, lblQuantity, btnButtonLocation, itemNo,colouID,additionThumb) {

    var product = document.getElementById(idOfProduct);
    //product.innerHTML = "";
    product.value = productID;

    document.getElementById("orderProductID").value = productID;

    var sizeContaint = document.getElementById(sizeID);
    document.getElementById(refID).innerHTML = refNo;
    sizeContaint.innerHTML = "";

  //  var mouseOverOjb = colouID + itemNo;
  //  CreateMouseHoverChangePicsAtDetailPage(mouseOverOjb, mainPic, newPicsrc, sizeArr, description, refNo, colouID) 

    var lbErrorObj = document.getElementById("lbsucces");
    if (lbErrorObj != null) {
        lbErrorObj.innerHTML = "";
    }

    var arr = sizeArr.split(",");
    var count =0;
    for (i = 0; i < arr.length; i++) {
        
        var str = "";
        str = arr[i].toString();
        var quantity = str.split(":");
        
        if (quantity[1] != 0) {
            count++;
            var container = document.createElement('div');
            
            container.setAttribute('id', quantity[0]);
            container.className = "sizeblock";
            //container.setAttribute("onclick", "SetSize(this,'" + btnSize + "','" + msgError +  "'");
            
            span1 = document.createElement('span');
            span1.innerHTML = quantity[0];
            span1.style.fontSize = "12px";
            container.appendChild(span1);
            if (sizeContaint != null) {
                sizeContaint.appendChild(container);

            }
            var quantityDisplay;
            if (quantity[1] > 5) {
                quantityDisplay = 5;
            }
            else {
                quantityDisplay = quantity[1];
            }

            var hidden = document.getElementById(btnSize);
            hidden.value = "";
            document.getElementById(quantity[0]).onclick = Function("SetSize(this,'" + btnSize + "','" + msgError + "','" + quantityDisplay + "','" + ojbQuantity + "', '" +droplist + "','" + cardID + "','" + idOfProduct + "','" + lblselectSize + "','" + lblQuantity + "','" + btnButtonLocation + "')");
            

        }

    }
   
    if (count == 0) {

        createQuantity(null, droplist, ojbQuantity, lblselectSize, lblQuantity, btnButtonLocation);
        document.getElementById("orderSize").value = "";
        //createQuantity('0', droplist)
    }
    else {

        createQuantity(0, droplist, ojbQuantity, lblselectSize, lblQuantity, btnButtonLocation)
        document.getElementById("orderSize").value = null ;
    }

    var contentDisplay = document.getElementById("divAlertSize");
    if (contentDisplay != null)
        contentDisplay.style.display = "none";

    var dataInput = itemNo + ":" + colouID;

    $(document).ready(function () {
        $.ajax({
            type: "POST",

            url: "Default.aspx/LoadAdditionImages",
            data: "{'dataInput':'" + dataInput + "'}",
            contentType: "application/json; charset=utf-8",
            dataType: "json",
            success: function (result) {
                if (result.d != "") {
                    $("#" + additionThumb).html(result.d);
                }

            },
            failure: function () {
            }
        });
    })
    

}

function removeChildrenFromNode(node)
{
   if(node == null)
   {
      return;
   }

   var len = node.childNodes.length;

   for(var i = 0; i < len; i++) {
       if (node.childNodes[i] != undefined) {
           node.removeChild(node.childNodes[i]);
       }
   }
}


function ChangeZoomImg(zoomOjb, picOjb) {
    //var newPictureSrc = document.getElementById(picOjb).src;
    $(document).ready(function () {
        
       // var count = newPictureSrc.split("/").length;
        //var newZoomPics = newPictureSrc.split("/")[count - 1];
        $('#zoomlink110421').attr('href', 'http://images.guideclothing.com/images/800_1200/LS.71847%20Black.jpg');

    });
}

function CreateMouseHoverChangePics(obj, oriPic, newPictureSrc, sizeArr, description, refNo, itemId,colourID, zoomLinkID, newZoomPic,imgLink, idRefNo) {

    var getOriPic = document.getElementById(oriPic);
    if (getOriPic != null) {
        getOriPic.src = newPictureSrc;
    }
    document.cookie = "ItemNo=" + itemId;
    document.cookie = "ColourID=" + colourID;

    var refchanging = document.getElementById(idRefNo);
    if (refchanging != null) {
        refchanging.innerHTML = refNo;
    }

    var linkTitle = document.getElementById(imgLink);
    if (linkTitle != null) {
        var title = linkTitle.title.split("|");
        var count_title = title.length;
        var str = refNo ;
        for (i = 1; i < count_title; i++) {
            str = str + "|" + title[i];
        }
        linkTitle.title = str;
    }     
    if (document.getElementById(obj + 'pic') == null) {
        var container = document.createElement('div');
        var arr = sizeArr.split(",");

        container.setAttribute('id', obj + 'pic');
        container.className = "infodivSize";
        if (sizeArr != null) {
            container.appendChild(createDivWithSpans("Ref.: ", refNo , "divRefNo", 'white', '10px'));
           // container.appendChild(createDivWithSpans(description,"", "", 'black', '10px'));
            container.appendChild(createDivWithSpans("Sizes avaiable in this colour: ", "", "SizeTitle", 'red', '10px'));
            var count = 0;
            var str = "";
           // var table = document.createElement('table');


            for (i = 0; i < arr.length; i++) {

                var container1 = document.createElement('div');
                container1.className = "sizeBlockShow";

                var remain = count % 3;
                
                if (remain == 0) {                    
                   
                    str = arr[i].toString();
                    var quantity = str.split(":");
                    if (quantity[1] == 0) {
                        container1.appendChild(createDivWithSpans(quantity[0], "", "infoSizeFontUnderline", 'red', '9px'));                     
                    }
                    else {
                        container1.appendChild(createDivWithSpans(quantity[0], "", "infoSizeFont", 'black', '9px'));
                    }                   

                }
                else {
                    str = arr[i].toString();
                    var quantity = str.split(":");
                    if (quantity[1] == 0) {
                        container1.appendChild(createDivWithSpans(quantity[0], "", "infoSizeFontUnderlinefar", 'red', '9px'));
                    }
                    else {
                        container1.appendChild(createDivWithSpans(quantity[0], "", "infoSizeFontfar", 'black', '9px'));
                    }
                    //td.setAttribute(quantity[0]);
                  
                }
                container.appendChild(container1);
                count++;
            }
           // container.appendChild(table);
            var objdiv = document.getElementById(obj);
            if (objdiv != null) {
                objdiv.appendChild(container);
                //alert(container.innerHTML);                    
            }
            else {
                var objdiv1 = document.getElementById(zoomLinkID);
                if (objdiv1 != null) {
                     //  alert(container.innerHTML);                    
                    objdiv1.appendChild(container);
                    
                }
            }
        }
      
        
    }
    else {

        document.getElementById(obj + 'pic').className = "infodivSize";
    }


}


function CreateMouseHoverChangePicsAtDetailPage(obj, oriPic, newPictureSrc, sizeArr, description, refNo, colourID) {

    
    if (document.getElementById(obj + 'pic') == null) {
        var container = document.createElement('div');
        var arr = sizeArr.split(",");

        container.setAttribute('id', obj + 'pic');
        container.className = "infodivSizeDetailPage";

//        var idDivColorContaint = document.getElementById("idDivColorContaint");
//        var lengOfidDivColorContaint;
//        if (idDivColorContaint != null) {
//        lengOfidDivColorContaint = idDivColorContaint.childElementCount;
//        if (lengOfidDivColorContaint < 7) {
//            var locationofDiv = lengOfidDivColorContaint * 86;
//            $(document).ready(function () {
//                $('#' + obj + 'pic').css("left", "172px");
//            });

//            }
//        }



        if (sizeArr != null) {
            container.appendChild(createDivWithSpans("Ref.: ", refNo, "divRefNo", 'white', '10px'));
            // container.appendChild(createDivWithSpans(description,"", "", 'black', '10px'));
            container.appendChild(createDivWithSpans("Sizes avaiable in this colour: ", "", "SizeTitle", 'red', '10px'));
            var count = 0;
            var str = "";
            // var table = document.createElement('table');


            for (i = 0; i < arr.length; i++) {

                var container1 = document.createElement('div');
                container1.className = "sizeBlockShow";

                var remain = count % 3;

                if (remain == 0) {

                    str = arr[i].toString();
                    var quantity = str.split(":");
                    if (quantity[1] == 0) {
                        container1.appendChild(createDivWithSpans(quantity[0], "", "infoSizeFontUnderline", 'red', '9px'));
                    }
                    else {
                        container1.appendChild(createDivWithSpans(quantity[0], "", "infoSizeFont", 'black', '9px'));
                    }

                }
                else {
                    str = arr[i].toString();
                    var quantity = str.split(":");
                    if (quantity[1] == 0) {
                        container1.appendChild(createDivWithSpans(quantity[0], "", "infoSizeFontUnderlinefar", 'red', '9px'));
                    }
                    else {
                        container1.appendChild(createDivWithSpans(quantity[0], "", "infoSizeFontfar", 'black', '9px'));
                    }
                    //td.setAttribute(quantity[0]);

                }
                container.appendChild(container1);
                count++;
            }
            // container.appendChild(table);
            var objdiv = document.getElementById(oriPic);
            if (objdiv != null) {
                objdiv.appendChild(container);
                //alert(container.innerHTML);                    
            }            
        }
    }
    else {

        document.getElementById(obj + 'pic').className = "infodivSizeDetailPage";
//        var idDivColorContaint = document.getElementById("idDivColorContaint");
//        var lengOfidDivColorContaint;
//        if (idDivColorContaint != null) {
//            lengOfidDivColorContaint = idDivColorContaint.childElementCount;
//            if (lengOfidDivColorContaint < 7) {
//                var locationofDiv = lengOfidDivColorContaint * 86;
//                $(document).ready(function () {
//                    $('#' + obj + 'pic').css("left", "172px");
//                });

//            }
//        }


    }


}



function CreateMouseHoverChangePicsOnZoomMagicScroll(obj, oriPic, newPictureSrc, sizeArr, description, refNo,itemId, colourID, zoomLinkID, newZoomPic, imgLink, idRefNo) {


    document.getElementById(oriPic).src = newPictureSrc;

    document.cookie = "ItemNo=" + itemId;
    document.cookie = "ColourID=" + colourID;

    var linkTitle = document.getElementById(imgLink);
    if (linkTitle != null) {
        var title = linkTitle.title.split("|");
        var count_title = title.length;
        var str = refNo;
        for (i = 1; i < count_title; i++) {
            str = str + "|" + title[i];
        }
        linkTitle.title = str;
    }


    var refchanging = document.getElementById(idRefNo);
    if (refchanging != null) {
        refchanging.innerHTML = refNo;
    }

    if (document.getElementById(obj + 'pic') == null) {
        var container = document.createElement('div');
        var arr = sizeArr.split(",");

        container.setAttribute('id', obj + 'pic');
        container.className = "infodivSizeOnMagicscroll";
        if (sizeArr != null) {
            container.appendChild(createDivWithSpans("Ref.: ", refNo, "divRefNo", 'white', '10px'));
            // container.appendChild(createDivWithSpans(description,"", "", 'black', '10px'));
            container.appendChild(createDivWithSpans("Sizes avaiable in this colour: ", "", "SizeTitle", 'red', '10px'));
            var count = 0;
            var str = "";
            // var table = document.createElement('table');


            for (i = 0; i < arr.length; i++) {

                var container1 = document.createElement('div');
                container1.className = "sizeBlockShow";

                var remain = count % 3;

                if (remain == 0) {

                    str = arr[i].toString();
                    var quantity = str.split(":");
                    if (quantity[1] == 0) {
                        container1.appendChild(createDivWithSpans(quantity[0], "", "infoSizeFontUnderline", 'red', '9px'));
                    }
                    else {
                        container1.appendChild(createDivWithSpans(quantity[0], "", "infoSizeFont", 'black', '9px'));
                    }

                }
                else {
                    str = arr[i].toString();
                    var quantity = str.split(":");
                    if (quantity[1] == 0) {
                        container1.appendChild(createDivWithSpans(quantity[0], "", "infoSizeFontUnderlinefar", 'red', '9px'));
                    }
                    else {
                        container1.appendChild(createDivWithSpans(quantity[0], "", "infoSizeFontfar", 'black', '9px'));
                    }
                    //td.setAttribute(quantity[0]);

                }
                container.appendChild(container1);
                count++;
            }
            // container.appendChild(table);
            var objdiv = document.getElementById(obj);
            if (objdiv != null) {
                objdiv.appendChild(container);
                //alert(container.innerHTML);                    
            }
            else {
                var objdiv1 = document.getElementById(zoomLinkID);
                if (objdiv1 != null) {
                    //  alert(container.innerHTML);                    
                    objdiv1.appendChild(container);

                }
            }
        }


    }
    else {

        document.getElementById(obj + 'pic').className = "infodivSizeOnMagicscroll";
    }


}
function CreateMouseHoverLeaveChangePics(obj) {
    // document.getElementById(oriPic).src = newPictureSrc;
    if (obj != null) {

        var container = document.getElementById(obj + 'pic');
        if (container != null) {
            container.className = "nonedisplay";
        }
    }
    else { 
    }
}

function findHighestZIndex(elem) {
    var elems = document.getElementsByTagName(elem);
    var highest = 0;   
    for (var i = 0; i < elems.length; i++) {
//        var zindex = document.defaultView.getComputedStyle(elems[i], null).getPropertyValue("z-index");
//        if ((zindex > highest) && (zindex != 'auto')) {
//            highest = zindex;
        //        }
        var zindex = elems[i].style.zIndex;
        if (zindex > highest) {
            highest = zindex;           
        } 

    }
    return highest;
} 



function GetProductIdImage() {
    
        alert(event.srcElement.id);
    
}

function createDivWithSpansTest(title, text, cssClass) {
    var div = document.createElement('div');
    if (cssClass != "") {
        div.className = cssClass;
    }
    
    var span1 = document.createElement('span');
    span1.innerHTML = title;
    span1.style.fontWeight = "bold";

    var span2 = document.createElement('span');
    span2.innerHTML = text;
    span2.style.color = fontcolor;
    span2.style.fontSize = fontsize;
    div.appendChild(span1);
    div.appendChild(span2);
    return div;
}

function createDivWithSpans(title, text, cssClass, fontcolor, fontsize) {
    var div = document.createElement('div');
    if (cssClass != "") {
        div.className = cssClass;
    }
    div.style.marginBottom = "3px";
    var span1 = document.createElement('span');
    span1.innerHTML = title;
    span1.style.fontWeight = "bold";

    var span2 = document.createElement('span');
    span2.innerHTML = text;
    span2.style.color = fontcolor;
    span2.style.fontSize = fontsize;
    div.appendChild(span1);
    div.appendChild(span2);
    return div;
}

function HiddenInformationDiv(obj) {
    if (obj != null) {

        var container = document.getElementById(obj + 'con');
        if (container != null) {
            container.className = "nonedisplay";
        }
    }
}

function ShowTextToControll(obj, textMsg) {
    if (obj != null) {
        if (obj.value == '') {
            obj.value = textMsg;
        }
    }
}

function EraseTextInControll(obj, textMsg) {
    if (obj != null) {
        if (obj.value == textMsg) {
            obj.value = '';
        }
    }
}

function ExpandText(id) {
    //contentDisplay.style.display = "none";
    
    
//    for (i = 0; i <= 5; i++) {
    var href = document.getElementById("ahref" + id);    
        var expand = document.getElementById(id);
        if (expand != null) {
            if (expand.style.display == "none") 
            {
                expand.style.display = "inline";
                if (href != null) {
                    href.innerHTML = "Click to collapse";
                }
            }
            else {
                expand.style.display = "none";
                if (href != null) {
                    href.innerHTML = "Click to expand";
                }
            }
        }

    }

    function GetFacebook() {
        window.open('http://www.facebook.com/pages/GUIDE-LONDON/150903688345766', '_blank');
    }

function getVersionIE() {

    var version = 0;
    if (/MSIE (\d+\.\d+);/.test(navigator.userAgent)) { //test for MSIE x.x;
        var ieversion = new Number(RegExp.$1) // capture x.x portion and store as a number
        if (ieversion >= 9)
        //document.write("You're using IE9 or above")
            version = 9;
        else if (ieversion >= 8)
        //document.write("You're using IE8 or above")
            version = 8;
        else if (ieversion >= 7)
        //document.write("You're using IE7.x")
            version = 7;
        else if (ieversion >= 6)
        //document.write("You're using IE6.x")
            version = 6;
        else if (ieversion >= 5)
        //document.write("You're using IE5.x")
            version = 5;
    }
    return version;

}

function ResizeWindow() {
    var version = 0;
    if (/MSIE (\d+\.\d+);/.test(navigator.userAgent)) { //test for MSIE x.x;
        var ieversion = new Number(RegExp.$1) // capture x.x portion and store as a number
        if (ieversion >= 9)
        //document.write("You're using IE9 or above")
            version = 9;
        else if (ieversion >= 8)
        //document.write("You're using IE8 or above")
            version = 8;
        else if (ieversion >= 7)
        //document.write("You're using IE7.x")
            version = 7;
        else if (ieversion >= 6)
        //document.write("You're using IE6.x")
            version = 6;
        else if (ieversion >= 5)
        //document.write("You're using IE5.x")
            version = 5;
    }



    // alert(document.body.clientWidth);
    document.body.style.overflow = "hidden";
    //alert("length=" + length);
    if (document.body.clientHeight > 184) {
        if (document.getElementById('containercontent') != null) {
            document.getElementById('containercontent').style.height = document.body.clientHeight - 165 + 'px';
        }
        if (document.getElementById('incontent') != null) {
            document.getElementById('incontent').style.height = document.body.clientHeight - 184 + 'px';
        }
    }
    
    if (document.body.clientWidth < 850) {
        if (version == 5 || version == 6) {
            $(document).ready(function () {
                $('#divcontainerinfo').css("bottom", "20px");

            });            
            document.getElementById('lastViewFrame').style.display = "none";
            document.getElementById('topmenucontainer').style.width = 850 + 'px';
            document.getElementById('topmenu').style.width = 600 + 'px';
            document.getElementById('containercontent').style.width = 850 + 'px';
            document.getElementById('incontent').style.width = 850- 200 + 'px';
          
        }
        else {

            document.getElementById('lastViewFrame').style.display = "none";
            document.getElementById('topmenucontainer').style.width = 860 + 'px';
            document.getElementById('topmenu').style.width = 610 + 'px';
            document.getElementById('incontent').style.width = document.body.clientWidth - 130 + 'px';
            document.getElementById('shoppingBagContainer').style.width = 990 + 'px';
            document.getElementById('newsanduserinfo').style.width = 850 + 'px';
        }

    }
    else {


        if (version == 5 || version == 6) {
            $(document).ready(function () {
                $('#divcontainerinfo').css("bottom", "20px");             
            });           
            document.getElementById('incontent').style.width = document.body.clientWidth - 290 + 'px';
            document.getElementById('topmenucontainer').style.width = document.body.clientWidth - 440 + 'px';
            document.getElementById('topmenu').style.width = document.body.clientWidth - 440 + 'px';
            document.getElementById('shoppingBagContainer').style.width = document.body.clientWidth + 'px';
            document.getElementById('newsanduserinfo').style.width = document.body.clientWidth - 260 + 'px';
            document.getElementById('lastViewFrame').style.display = "inline";
        }
        else {
            document.getElementById('incontent').style.width = document.body.clientWidth - 230 + 'px';
            document.getElementById('topmenucontainer').style.width = document.body.clientWidth - 420 + 'px';
            document.getElementById('topmenu').style.width = document.body.clientWidth - 410 + 'px';
            document.getElementById('shoppingBagContainer').style.width = document.body.clientWidth   + 'px';
            document.getElementById('newsanduserinfo').style.width = document.body.clientWidth - 230 + 'px';
            document.getElementById('lastViewFrame').style.display = "inline";
        }
    }

}
window.onresize = ResizeWindow;
//function suppressBackspace(evt) {
//    evt = evt || window.event;
//    var target = evt.target || evt.srcElement;

//    if (evt.keyCode == 8 && !/input|textarea/i.test(target.nodeName)) {
//        return false;
//    }
//}

//document.onkeydown = suppressBackspace;
//document.onkeypress = suppressBackspace;
//var hash = location.hash;

//setInterval(function () {
//    if (location.hash != hash) {
//        alert("Changed from " + hash + " to " + location.hash);
//        hash = location.hash;
//    }
//}, 100);

setInterval(function () {
    var card = document.getElementById("orderCardID");
    if (card != null) {
        dataInput = card.value;
        $(document).ready(function () {

            $.ajax({
                type: "POST",

                url: "Default.aspx/GetCardExist",
                data: "{'dataInput':'" + dataInput + "'}",
                contentType: "application/json; charset=utf-8",

                dataType: "json",

                success: function (result) {

                    if (result.d != "") {
                        var itemOjb = result["d"].split(":")[1] + " ";
                        var priceOjb = result["d"].split(":")[0];

                        var span1 = document.createElement('span');
                        span1.innerHTML = itemOjb;

                        var span2 = document.createElement('span');
                        span2.innerHTML = priceOjb;

                        var test1 = document.getElementById("shoppingBagItems");
                        test1.title = "";
                        test1.innerHTML = "";
                        test1.appendChild(span1);

                        var test2 = document.getElementById("shoppingBagPrices");
                        test2.title = "";
                        test2.innerHTML = "";
                        test2.appendChild(span2);
                        // lbErrorObj.innerHTML = "Product was add to shopping bag";

                        var checkoutlink = document.getElementById("checkoutLinkID");
                        checkoutlink.innerHTML = "CheckOut";
                        checkoutlink.title = "CheckOut";
                    }
                }
            })
        })
    }

}, 100);


