//if(window.width<1280||window.height<1024){
//alert("This web page is best viewed with a screen resolution of 1280 by 1024 or higher.  Your current resolution is "+screen.width+" by "+screen.height+".  If possible please change your resolution.")
//document.write("<style>.productList{border:1px solid blue;}</style>")
//}
//else{
//alert("Whoa, you have a high resolution.  Nice Job!" + window.width)

//document.write("<style>.productList{border:1px solid red;}</style>")

//}



function addLoadListener(fn)
{
	if (typeof window.addEventListener != 'undefined')
	{
		window.addEventListener('load', fn, false);
	}
	else if (typeof document.addEventListener != 'undefined')
	{
		document.addEventListener('load', fn, false);
	}
	else if (typeof window.attachEvent != 'undefined')
	{
		window.attachEvent('onload', fn);
	}
	else
	{
		return false;
	}
	
	return true;
};




function attachEventListener(target, eventType, functionRef, capture)
{
    if (typeof target.addEventListener != "undefined")
    {
        target.addEventListener(eventType, functionRef, capture);
    }
    else if (typeof target.attachEvent != "undefined")
    {
        target.attachEvent("on" + eventType, functionRef);
    }
    else
    {
        return false;
    }

    return true;
};



checkBrowserWidth();

attachEventListener(window, "resize", checkBrowserWidth, false);


function checkBrowserWidth()
{
	var theWidth = getBrowserWidth();
	
	if (theWidth == 0)
	{
		var resolutionCookie = document.cookie.match(/(^|;)tmib_res_layout[^;]*(;|$)/);

		if (resolutionCookie != null)
		{
			setStylesheet(unescape(resolutionCookie[0].split("=")[1]));
		}
		
		addLoadListener(checkBrowserWidth);
		
		return false;
	}

	if (theWidth > 1000)
	{
	    //alert('test');
		setStylesheet("general");
		//document.cookie = "tmib_res_layout=" + escape("1024 x 768");
	}
	else
	{
	    //alert('test2');
		setStylesheet("general2");
		//document.cookie = "tmib_res_layout=";
	}
	
	return true;
};




function getBrowserWidth()
{
	if (window.innerWidth)
	{
		return window.innerWidth;
	}
	else if (document.documentElement && document.documentElement.clientWidth != 0)
	{
		return document.documentElement.clientWidth;
	}
	else if (document.body)
	{
		return document.body.clientWidth;
	}
	
	return 0;
};



function setStylesheet(styleTitle)
{
	var currTag;

	if (document.getElementsByTagName)
	{
		for (var i = 0; (currTag = document.getElementsByTagName("link")[i]); i++)
		{
			if (currTag.getAttribute("rel").indexOf("style") != -1 && currTag.getAttribute("title"))
			{
				currTag.disabled = true;

				if(currTag.getAttribute("title") == styleTitle)
				{
					currTag.disabled = false;
				}
			}
		}
	}
	
	return true;
};



//Submit search form without a button
function SearchSubmit(e, searchTextboxID)
{
    var evt = e ? e : window.event;
    var searchBox = document.getElementById(searchTextboxID);

    if (evt.keyCode == 13) {
        window.location = '/Search.aspx?search=' + searchBox.value;
        return false;   //stops any .net validation in other controls on the page being fired!
    } 
}



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 zoomProductImage(productImage) {
    
	if (productImage) {
		window.open('/Ecommerce/zoom.aspx?image=' + productImage,'ZOOM','width=700,height=700,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 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 showSubCategoryFeed(categoryID)  {

    //alert('test' + categoryID);
}


function ViewProductSpecSheet(variantID, productID)    {
   // alert(productID);

	if (productID) {
		window.open('/Ecommerce/ProductSpecSheet.aspx?ID=' + variantID + '&productID=' + productID, 'SPECSHEET','width=450,height=700,scrollbars=yes,resize=no');
    }
}

function GlossaryTerm(term) {

	if (term) {
		window.open('/Glossary/Term.aspx?term=' + term, 'Glossary','width=450,height=350,scrollbars=yes,resize=no');
    }
}


function SubmitSecureIFrame() {
    document.forms['secureForm'].submit()
}

//Populates a hidden field with all the selected orders from the admin salessummary page.
function populateHiddenField(orderID, clientID, checkboxClientID) {

    document.getElementById(clientID).value += '|' + orderID;

    //alert(document.getElementById(clientID).value)
}

//home grid mouseover function. Uses JQuery on default.aspx
function SetHomePromo(areaID, price, brandID, textLinkID, URLLink) {
    document.getElementById('boxImageLink_' + areaID).href = URLLink;

    document.getElementById('boxPrice_' + areaID).innerHTML = price.toFixed(2);

    document.getElementById('brandImage_' + areaID).src = '/images/brand/smalllogo/' + brandID + '.gif';

    document.getElementById(textLinkID).href = URLLink;
}

//sets up the first selected item for the given box grid area
function SetHomeFirstItem(areaID, price, brandID, textLinkID, URLLink, imageURL) {
    document.getElementById('boxImageLink_' + areaID).href = URLLink;

    document.getElementById('boxPrice_' + areaID).innerHTML = price.toFixed(2);

   // document.getElementById('boxPricePackMessage_' + areaID).innerHTML = 'for ' + packSize;

    document.getElementById(textLinkID).href = URLLink;

   // alert(document.getElementById('boxImage_' + areaID));

    document.getElementById('brandImage_' + areaID).src = '/images/brand/smalllogo/' + brandID + '.gif';
    
    document.getElementById('boxImage_' + areaID).src = imageURL;
}


/***********************************************
* Bookmark site script- © Dynamic Drive DHTML code library (www.dynamicdrive.com)
* This notice MUST stay intact for legal use
* Visit Dynamic Drive at http://www.dynamicdrive.com/ for full source code
***********************************************/

/* Modified to support Opera */
function bookmarksite(title, url) {
    if (window.sidebar) // firefox
        window.sidebar.addPanel(title, url, "");
    else if (window.opera && window.print) { // opera
        var elem = document.createElement('a');
        elem.setAttribute('href', url);
        elem.setAttribute('title', title);
        elem.setAttribute('rel', 'sidebar');
        elem.click();
    }
    else if (document.all)// ie
        window.external.AddFavorite(url, title);
}