function clickButton(e, buttonid){ 

  var evt = e ? e : window.event;
  var bt = document.getElementById(buttonid);

  if (bt){ 
      if (evt.keyCode == 13){ 
         bt.click(); 
        return false; 
      } 
  } 
}


function ShowAlternativeImage(imageName, clientID)    {
    
    document.getElementById(clientID).src = '/images/ecommerce/standard/' + imageName;
    //document['mainImage'].src = '/images/ecommerce/mini/' + imageName;
}

function ShowCaseImage(imageName, clientID)    {
    
    document.getElementById(clientID).src = '/images/brand/case_standard/' + imageName;
    //document['mainImage'].src = '/images/ecommerce/mini/' + imageName;
}


function zoomProductImage(productImage) {
	if (productImage) {
		window.open('/Ecommerce/zoom.aspx?image=' + productImage,'ZOOM','width=500,height=500,scrollbars=no,resize=no');
    }
    
    //[RK] 21/12/06 - triggered from ImageButton so MUST return false
    return false;
}

function fitPic() {
	if (window.innerWidth){
		iWidth = window.innerWidth;
		iHeight = window.innerHeight;
	}else{
		iWidth = document.body.clientWidth;
		iHeight =document.body.clientHeight;
	}
	
	iWidth = document.images[0].width - iWidth;
	iHeight = document.images[0].height - iHeight;
	window.resizeBy(iWidth, iHeight);
}

function copyAddress()  {
    //[RK] 27/03/2007.
    //Uses hidden fields to allow us to access ASP.NET controls from Javascript.
    
    var prefix = document.forms['aspnetForm'].elements['jsPrefix'].value;
    var oForm = document.forms['aspnetForm']

    oForm.elements[prefix + '_DeliveryLine1TextBox'].value = oForm.elements[prefix + '_Line1TextBox'].value
    oForm.elements[prefix + '_DeliveryLine2TextBox'].value = oForm.elements[prefix + '_Line2TextBox'].value
    oForm.elements[prefix + '_DeliveryLine3TextBox'].value = oForm.elements[prefix + '_Line3TextBox'].value
    oForm.elements[prefix + '_DeliveryTownTextBox'].value = oForm.elements[prefix + '_TownTextBox'].value
    oForm.elements[prefix + '_DeliveryCountyTextBox'].value = oForm.elements[prefix + '_CountyTextBox'].value
    oForm.elements[prefix + '_DeliveryPostcodeTextBox'].value = oForm.elements[prefix + '_PostcodeTextBox'].value
    oForm.elements[prefix + '_DeliveryPhoneNumberTextBox'].value = oForm.elements[prefix + '_PhoneNumberTextBox'].value
    oForm.elements[prefix + '_DeliveryCountryDropDownList'].selectedIndex = oForm.elements[prefix + '_CountryDropDownList'].selectedIndex

}

function DisableAddToBasketButton() {
    var prefix = document.forms['aspnetForm'].elements['jsPrefix'].value;
    var oForm = document.forms['aspnetForm']
    
    var button = document.getElementById(prefix + '_AddToBasketImageButton');
    button.disabled = true;
    button.src = '/images/ecommerce/addtobasket_off.gif'
    
}

function GenerateVariantArray() {
    var prefix = document.forms['aspnetForm'].elements['jsPrefix'].value;
    var oForm = document.forms['aspnetForm']

    alert(oForm.elements[prefix + '_variantsArrayHiddenField'].value);

}

function SelectVariant(variantCode) {
    //makes a selection of a variant into a hidden field which is then available on post back to
    //add to basket function
    
    //[RK] 14/04/2007.
    //Uses hidden fields to allow us to access ASP.NET controls from Javascript.
    var prefix = document.forms['aspnetForm'].elements['jsPrefix'].value;
    var oForm = document.forms['aspnetForm']

    //First unselect any selected variants by looping through the list of variants created in code behind
    var variantsList = oForm.elements[prefix + '_variantsArrayHiddenField'].value
    //alert(variantsList);
    var variantsArray = variantsList.split(',');
    
    for (var i=0; i <= variantsArray.length; i++)
    {
        //alert(variantsArray[i]);
        if (document.getElementById('variantimage_' + variantsArray[i]))   {
            document.getElementById('variantimage_' + variantsArray[i]).className = 'variantSelectionOFF';
        }
    }
    
    //populate a hidden field to store the selected variant
    oForm.elements[prefix + '_selectedVariantCodeTextBox'].value = variantCode;
    
    
    //highlight the selected variant
    document.getElementById('variantimage_' + variantCode).className = 'variantSelectionON';


    //enable add to basket button
    var button = document.getElementById(prefix + '_AddToBasketImageButton');
    button.disabled = false;
    button.src = '/images/ecommerce/addtobasket.gif'
}

function ConfirmOrder() {
    
    var prefix = document.forms['aspnetForm'].elements['jsPrefix'].value;
    var oForm = document.forms['aspnetForm']
    //alert('prefix=' + prefix)
    
    
    var confirmButton =  document.getElementById(prefix + '_OrderOptionsPanelNextButton');
    var cvnNumber = document.getElementById(prefix + '_CVNTextBox').value;
    
    
    //If the issue number is valid too, then disable the button so we dont get multiple submissions
    if (cvnNumber.length == 3)  {
        confirmButton.src = '/images/buttons/pleasewait.gif';
        confirmButton.style.cursor = 'wait';
        //confirmButton.onclick.value = '';
        return true;
        
        //oForm.submit();

        //confirmButton.disabled = true;
    }
}



function demoZoom(productCode)	{

    window.open('/zoom.asp?product=' + productCode,'ZOOM','width=580,height=400,scrollbars=no,resize=yes');
}

function OpenPopup(pageName)	{
    window.open('/eyesize.aspx','ZOOM','width=400,height=300,scrollbars=no,resize=yes');
	//window.open('/Ecommerce/zoom.aspx?image=' + productImage,'ZOOM','width=500,height=500,scrollbars=no,resize=no');
}


function SendToFriendPopup(URL)	{
    window.open('/sendToFriend.aspx?' + URL,'ZOOM','width=500,height=300,scrollbars=yes,resize=yes');
	//window.open('/Ecommerce/zoom.aspx?image=' + productImage,'ZOOM','width=500,height=500,scrollbars=no,resize=no');
}

function showProuductCount(labelID, productCount)    {
    
    var countLabel = document.getElementById(labelID).style.visibility = 'visible';
}

function hideProuductCount(labelID, productCount)    {
    
    var countLabel = document.getElementById(labelID).style.visibility = 'hidden';
}