  
  function newWindow(theurl,thewidth,theheight) {
  
    var photoPageUrl;
    photoPageUrl = "viewimage.asp?File=[" + theurl + "]";
    
    newWin = window.open(photoPageUrl,'newWindow','width=' + thewidth + ',height=' + theheight + ',toolbar=no,location=no,scrollbars=yes,resizable=yes');
      
  }
  
  
  function act(imgName) {
    if (document.images)
      document.images[imgName].src = eval(imgName + "up.src");
  }


  function inact(imgName) {
    if (document.images)
      document.images[imgName].src = eval(imgName + "down.src");
  }


  function actMenuItem(imgName,defImg) {
    if(defImg != imgName)
    {
	  act(imgName);

    }
  }


  function inactMenuItem(imgName,defImg) {
    if(defImg != imgName)
    {
	  inact(imgName);
    }
  }

  
function toggleLayer(whichLayer)
{

	if (document.getElementById(whichLayer))
	{
		// this is the way the standards work

		var style2 = document.getElementById(whichLayer).style;
		
		style2.display = style2.display? "":"block";

	}
	else if (document.all)
	{
		// this is the way old msie versions work

		var style2 = document.all[whichLayer].style;
		style2.display = style2.display? "":"block";

	}
	else if (document.layers)
	{
		// this is the way nn4 works
	
		var style2 = document.layers[whichLayer].style;
		style2.display = style2.display? "":"block";
	}
	else
	{
	
		//alert("NO LAYER: " + whichLayer);
		
	}

	
	//alert('LAYER TOGGLED: ' + whichLayer);

}

function toggleLayerNew(whichLayer)
{

	if (document.getElementById(whichLayer))
	{
		// this is the way the standards work

		var style2 = document.getElementById(whichLayer).style;
		
		if(style2.display != "none") {
		
			style2.display = style2.display? "":"none";
		
		}
		else {
		
			style2.display = style2.display? "":"block";
		}
				
	}
	else if (document.all)
	{
		// this is the way old msie versions work

		var style2 = document.all[whichLayer].style;
		style2.display = style2.display? "":"block";

	}
	else if (document.layers)
	{
		// this is the way nn4 works
	
		var style2 = document.layers[whichLayer].style;
		style2.display = style2.display? "":"block";
	}
	else
	{
	
		//alert("NO LAYER: " + whichLayer);
		
	}

	
	//alert('LAYER TOGGLED: ' + whichLayer);

}

function hideLayer(whichLayer)
{
	
	if (document.getElementById(whichLayer))
	{
		// this is the way the standards work

		var style2 = document.getElementById(whichLayer).style;
		
		if(style2.display != "none") {
		
			style2.display = style2.display? "":"";
		
		}

	}
	else if (document.all)
	{
		// this is the way old msie versions work

		var style2 = document.all[whichLayer].style;
		style2.display = style2.display? "":"";

	}
	else if (document.layers)
	{
		// this is the way nn4 works
	
		var style2 = document.layers[whichLayer].style;
		style2.display = style2.display? "":"";
	}
	else
	{
	
		//alert("NO LAYER: " + whichLayer);
		
	}

	
	//alert('LAYER TOGGLED: ' + whichLayer);

}

function hideAllButtons(whichLayer,whichLayer2)
{
	
	if (document.getElementById(whichLayer))
	{
		// this is the way the standards work

		var style2 = document.getElementById(whichLayer).style;
		var style3 = document.getElementById(whichLayer2).style;
		
		if(style2 != null) {
		
			if(style2.display != "none") {
			
				style2.display = style2.display? "":"none";
			}			
			else
			{
				//alert("1: " + style2.display);
			}
		
		}
		else {
			//alert(whichLayer + " HAS NO STYLE...");
		}
		
		
		
		if(style3 != null) {
		
			if(style3.display != "none") {
			
				style3.display = style3.display? "":"none";
			}	
			else
			{				
				if(style2.display == "") {
				
					style2.display = style2.display? "":"none";
				}
				else
				{
					//alert("2: " + style3.display);				
				}
			}
		
		}
		
		// show our original message
		
		var style4 = document.getElementById('original-message').style;
		style4.display = style4.display? "":"block"; 

	}
	else if (document.all)
	{
		// this is the way old msie versions work

		var style2 = document.all[whichLayer].style;
		style2.display = style2.display? "":"";

	}
	else if (document.layers)
	{
		// this is the way nn4 works
	
		var style2 = document.layers[whichLayer].style;
		style2.display = style2.display? "":"";
	}
	else
	{
	
		//alert("NO LAYER: " + whichLayer);
		
	}

	
	//alert('LAYER TOGGLED: ' + whichLayer);

}
  
function swapImage(imageDiv,linkId,imageUrl,imageFilename) {	
	
	// get main image obj
	var mainImage = document.getElementById(imageDiv);
	
	// get link obj
	var linkObj = document.getElementById(linkId);
	
	// set image
	mainImage.src = imageUrl;
		
	imageFilename = String(imageFilename);
	
	var tmpLink = "javascript:newWindow('" + imageFilename.replace("*","'") + ");";
	
	// set new link	
	linkObj.href= tmpLink;
}

function swapMainProductImage(filePath,photoWidth,photoHeight,photoId,photoTitle) {

	// get main image obj
	var mainImage = document.getElementById("main-product-img");
	
	// get link obj
	var linkObj = document.getElementById("main-product-link");	
	
	// set image
	mainImage.src = "resize.asp?File=" + filePath + "&Width=245&Height=245&C=false&RS=true";
		
	filePath = filePath.replace("\\","*-*");
	filePath = filePath.replace("\\","*-*");
	filePath = filePath.replace("\\","*-*");
	filePath = filePath.replace("*-*","//");
	filePath = filePath.replace("*-*","//");
	filePath = filePath.replace("*-*","//");
	
	// set other zoom div image as well - taken out as we cant add extra ones as the old ones stay there in ie
	
	//MojoZoom = null;
	
	//MojoZoom.makeZoomable(document.getElementById('main-product-img'),filePath,document.getElementById('myimage_zoom'),235,235,false);	
	
	var tmpLink = "javascript:newWindow('[" + filePath + "]','" + photoWidth + "','" + photoHeight + "'" + ")";
	linkObj.href= tmpLink;
	
	// set image title
	var titleObj = document.getElementById("main-product-title");
	titleObj.innerHTML = photoTitle;
}
      
function updateStockLevel(prodId,selectId) {

	// get the number of options
	
	var optionCount, thisOption, selectCount, selectedValues, headerList, stockDiv, thisURL;
	
	selectCount = 0;
	
	selectedValues = new Array();
	
	headerList = document.getElementById("headerlist").value.split("*");
	
	optionCount = document.getElementById("optionno").value;
	
	// check that all options have been selected
	
	for (i=0; i<optionCount; i++) {
	
		// do we have a value ?
		optNo = i + 1;
		thisOption = document.getElementById("option-" + optNo).selectedIndex;
		if(thisOption > 0 && document.getElementById("option-" + optNo).value.length > 0) {
		
			selectCount++;
			selectedValues[i] = optNo + "-" + document.getElementById("option-" + optNo).value;			
		}
		
		thisOption = 0;				
	}
	
	// see if the select count is the same as the option count
	
	if(selectCount == optionCount) {
	
		//alert("READY TO WORK OUT STOCK: " + selectedValues.length);
		
		// send a post to get the values for all of our fields
		//alert("SELECTED VALUES: " + selectedValues.join("*"));
		//alert("HEADER LIST: " + headerList.join());
		
		var HL = headerList.join();
		var SV = selectedValues.join("*");
		var currentUrl = window.location.href;
		var mode;
		
		if(currentUrl.indexOf('https') == 0) {
		
			mode = 'https://';
		}	
		else {
			mode = 'http://';
		}
		
		// work out if we are http or https
		
		//thisURL = "http://www.diem-angling.com/getstock.asp?Id=" + prodId + "&SV=" + SV + "&HL=" + HL;
		thisURL = mode + "www.diem-angling.com/getstock.asp?Id=" + prodId + "&SV=" + SV + "&HL=" + HL;
		
		//alert("LOADING: " + thisURL);
		
		loadXMLDoc(thisURL);
		
	}	
	else {
	
		//alert("NOT READY");		
		// send message to stock field
		stockDiv = "Select Options to view stock";	
		document.getElementById("stockdiv").innerHTML = stockDiv;
		
		if(document.getElementById("chosenOptionId") != null)
		{
			document.getElementById("chosenOptionId").value = '';
		}
		
		if(document.getElementById("calcStock") != null)
		{
			document.getElementById("calcStock").value = '';
		}
		
		hideAllButtons('buttondiv','outofstock');
	}
	
	
}

var xmlhttpObj;

function loadXMLDoc(url) {
 
    xmlhttpObj = false;
    // branch for native XMLHttpRequest object
    if(window.XMLHttpRequest && !(window.ActiveXObject)) {
    	try {
			xmlhttpObj = new XMLHttpRequest();
        } catch(e) {
			xmlhttpObj = false;
        }
    // branch for IE/Windows ActiveX version
    } 
    else if(window.ActiveXObject) {
       	try {
        	xmlhttpObj = new ActiveXObject("Msxml2.XMLHTTP");
      	} catch(e) {
        	try {
          		xmlhttpObj = new ActiveXObject("Microsoft.XMLHTTP");
        	} 
        	catch(e) {
          		xmlhttpObj = false;
        	}
	}
    }
    
    if(xmlhttpObj) {
	xmlhttpObj.onreadystatechange = handleResponse;
	xmlhttpObj.open("GET", url, true);
	xmlhttpObj.send("");
    }
   
}


function handleResponse() {

	var res;

	if(xmlhttpObj != null) {

	    if ( xmlhttpObj.readyState == 4 ) {

		res = xmlhttpObj.responseText;
		
		document.getElementById("stockdiv").innerHTML = res;
		
		if(res.indexOf("showButton") > 0) {			
			
			displayButton('buttondiv','outofstock');
			//hideLayer('button-spaceholder');
		}
		
		if(res.indexOf("hideButton") > 0) {
		
			displayButton('outofstock','buttondiv');
			//hideLayer('button-spaceholder');
			
		}
		
	    }

	 }
	 else
	 {
	  //alert("NO XML OBJECT");
	 }
  
}

function displayButton(showLayer,hideLayer) {

	
	if (document.getElementById(showLayer))
	{
		// this is the way the standards work

		var style2 = document.getElementById(showLayer).style;
		var style3 = document.getElementById(hideLayer).style;
		style2.display = style2.display? "":"block";
		
		// see if the other layer is displayed
		
		if(style3 != null) {
		
			if(style3.display != "none")
			{
				style3.display = style2.display? "":"none";
				//alert(hideLayer + " HAS DISPLAY");
				hideOriginalMessage();
			}
			else
			{
				//alert(hideLayer + " HAS NO DISPLAY");
				hideOriginalMessage();
			}
		
		}

	}
	else if (document.all)
	{
		// this is the way old msie versions work

		var style2 = document.all[showLayer].style;
		style2.display = style2.display? "":"block";

	}
	else if (document.layers)
	{
		// this is the way nn4 works
	
		var style2 = document.layers[showLayer].style;
		style2.display = style2.display? "":"block";
	}
	else
	{
	
		//alert("NO LAYER: " + whichLayer);
		
	}
	

}

function showOriginalMessage() {
	
	if (document.getElementById('original-message'))
	{
		// this is the way the standards work
		
		var om = document.getElementById('original-message');
		
		om.style.display='';
		
		alert("OM SHOWN");
		
		
	}	
	else if (document.all)
	{
		// this is the way old msie versions work

		var style2 = document.all['original-message'].style;
		style2.display = style2.display? "":"block";

	}
	else if (document.layers)
	{
		// this is the way nn4 works
	
		var style2 = document.layers['original-message'].style;
		style2.display = style2.display? "":"block";
	}
	else
	{
	
		//alert("NO LAYER: " + whichLayer);
		
	}	
}

function hideOriginalMessage() {
	
	if (document.getElementById('original-message'))
	{
		// this is the way the standards work
		
		var om = document.getElementById('original-message');
		
		om.style.display='none';
		
		//alert("OM HIDDEN");
		
		
	}	
	else if (document.all)
	{
		// this is the way old msie versions work

		var style2 = document.all['original-message'].style;
		style2.display = style2.display? "":"block";

	}
	else if (document.layers)
	{
		// this is the way nn4 works
	
		var style2 = document.layers['original-message'].style;
		style2.display = style2.display? "":"block";
	}
	else
	{
	
		//alert("NO LAYER: " + whichLayer);
		
	}	
}

function openCvcWindow(thewidth,theheight) {

    var cvcPageUrl;
    cvcPageUrl = "cvc.asp";    
    newWin = window.open(cvcPageUrl,'newWindow','width=' + thewidth + ',height=' + theheight + ',toolbar=no,location=no,scrollbars=yes,resizable=yes');
	
}

function openCouponWindow(thewidth,theheight) {

    var cvcPageUrl;
    cvcPageUrl = "coupons.asp";    
    newWin = window.open(cvcPageUrl,'newWindow','width=' + thewidth + ',height=' + theheight + ',toolbar=no,location=no,scrollbars=yes,resizable=yes');
	
}

