﻿
function showRelatedProductsLoad(obj, isLarge) {

  var grid = null;
  if (isLarge)
    grid = Element.extend(obj).up('.divLargeWindowCenter').down('.divProductGrid');
  else
    grid = Element.extend(obj).up('.divCenterWindowCenter').down('.divProductGrid');
    
  //var gridRow =
  $('relatedProductsLoad').setStyle({ height: grid.getHeight() + 'px' });
  grid.select('.divProductGridRow').invoke('hide');
  //gridRow.hide();
  $('relatedProductsLoad').show();
}


function showRelatedIdeasLoad(obj, isLarge) {

  var grid = null;
  if (isLarge)
    grid = Element.extend(obj).up('.divLargeWindowCenter').down('.divProductGrid');
  else
    grid = Element.extend(obj).up('.divCenterWindowCenter').down('.divProductGrid');
    
  var gridRow = grid.down('.divProductGridRow');

  $('relatedIdeasLoad').setStyle({ height: grid.getHeight() + 'px' });
  gridRow.hide();
  $('relatedIdeasLoad').show();
}

function addChecklistClick(obj) {
  obj = Element.extend(obj);
  var divChecklistResult = obj.up('.icons').down('.divChecklistResult');
  if (divChecklistResult != null)
    divChecklistResult.hide();
  $('divChecklistLoad').show();
}

function toggleImageSize(obj, originalCssClass, originalSizePath) {
    obj = Element.extend(obj);
    var tableObj = obj.up('table');
    if (tableObj.hasClassName('large')) {
        tableObj.removeClassName('large');
        tableObj.addClassName(originalCssClass);
        tableObj.next(0).removeClassName('large');
        tableObj.next(0).addClassName(originalCssClass);
        obj.src = obj.src.replace('/mega/', originalSizePath);
    }
    else {
        tableObj.removeClassName(originalCssClass);
        tableObj.addClassName('large');
        tableObj.next(0).removeClassName(originalCssClass);
        tableObj.next(0).addClassName('large');
        obj.src = obj.src.replace(originalSizePath, '/mega/');
    }
}

function toggleProductImageSize(obj) {
    obj = Element.extend(obj);
    var tableObj = obj.up('table');
    if (tableObj.hasClassName('tableProductMega')) {
        tableObj.removeClassName('tableProductMega');
        tableObj.addClassName('tableProductLarge');

        tableObj.next(0).removeClassName('textLarge');
        tableObj.next(0).addClassName('textSMall');
        obj.src = obj.src.replace('/mega/', '/large/');
    }
    else {
        tableObj.removeClassName('tableProductLarge');
        tableObj.addClassName('tableProductMega');
        tableObj.next(0).removeClassName('textSMall');
        tableObj.next(0).addClassName('textLarge');
        obj.src = obj.src.replace('/large/', '/mega/');
    }
}

function changePaymentOption(input) {

    $('paymentDiv').select("div.creditpopup").each(Element.hide);
    $('paymentDiv').select("div.creditsecure").each(Element.hide);
    $('paymentDiv').select("div.creditquickpay").each(Element.hide);
    $('paymentDiv').select("div.bank").each(Element.hide);
    $('paymentDiv').select("div.cod").each(Element.hide);
    $('paymentDiv').select("div.account").each(Element.hide);
    $('submitButtons').select('input').each(Element.hide);


    var paymentOption = input.value;

    switch (paymentOption) {
        case "1":
            $('paymentDiv').select("div.creditpopup").each(Element.show);
            $('paymentDiv').select("div.creditsecure").each(Element.show);
            $('paymentDiv').select("div.creditquickpay").each(Element.show);
            $('submitButtons').select('input.creditSubmit').each(Element.show);
            $('submitButtons').select('input.quickpaySubmit').each(Element.show);
            break;
        case "2":
            $('paymentDiv').select("div.bank").each(Element.show);
            $('submitButtons').select('input.bankSubmit').each(Element.show);
            break;
        case "3":
            $('paymentDiv').select("div.cod").each(Element.show);
            $('submitButtons').select('input.codSubmit').each(Element.show);
            break;
        case "4":
            $('paymentDiv').select("div.account").each(Element.show);
            $('submitButtons').select('input.accountSubmit').each(Element.show);
            break;
    }
}

function updateDeliveryCountry(obj) {
    obj = Element.extend(obj);
    $('deliveryCountry').innerHTML = obj.options[obj.selectedIndex].text;
}

/* Method used for password fields */
function changeInputType(
	  oldElm,
	  iType,
	  iValue,
	  blankValue,
	  noFocus) {
    if (!oldElm || !oldElm.parentNode || (iType.length < 4) ||
		!document.getElementById || !document.createElement) return;
    var isMSIE = /*@cc_on!@*/false;
    if (!isMSIE) {
        var newElm = document.createElement('input');
        newElm.type = iType;
    } else {
        var newElm = document.createElement('span');
        newElm.innerHTML = '<input type="' + iType + '" name="' + oldElm.name + '">';
        newElm = newElm.firstChild;
    }
    var props = ['name', 'id', 'className', 'size', 'tabIndex', 'accessKey'];
    for (var i = 0, l = props.length; i < l; i++) {
        if (oldElm[props[i]]) newElm[props[i]] = oldElm[props[i]];
    }
    newElm.onfocus = function () {
        return function () {
            if (this.hasFocus) return;
            var newElm = changeInputType(this, 'password', iValue,
		  (this.value.toLowerCase() == iValue.toLowerCase()) ? true : false);
            if (newElm) newElm.hasFocus = true;
        }
    } ();
    newElm.onblur = function () {
        return function () {
            if (this.hasFocus)
                if (this.value == '' || (this.value.toLowerCase() == iValue.toLowerCase())) {
                    changeInputType(this, 'text', iValue, false, true);
                }
        }
    } ();
    newElm.hasFocus = false;
    if (!blankValue) newElm.value = iValue;
    oldElm.parentNode.replaceChild(newElm, oldElm);
    if (!isMSIE && !blankValue) newElm.value = iValue;
    if (!noFocus || typeof (noFocus) == 'undefined') {
        window.tempElm = newElm;
        setTimeout("tempElm.hasFocus=true;tempElm.focus();", 1);
    }
    return newElm;
}
