/** John Armit Javascript - JDG **/
//=================================================================================

function MM_preloadImages() { //v3.0
  var d=document; if(d.images){ if(!d.MM_p) d.MM_p=new Array();
    var i,j=d.MM_p.length,a=MM_preloadImages.arguments; for(i=0; i<a.length; i++)
    if (a[i].indexOf("#")!=0){ d.MM_p[j]=new Image; d.MM_p[j++].src=a[i];}}
}

//=================================================================================

function MM_swapImgRestore() { //v3.0
  var i,x,a=document.MM_sr; for(i=0;a&&i<a.length&&(x=a[i])&&x.oSrc;i++) x.src=x.oSrc;
}

//=================================================================================

function MM_findObj(n, d) { //v4.0
  var p,i,x;  if(!d) d=document; if((p=n.indexOf("?"))>0&&parent.frames.length) {
    d=parent.frames[n.substring(p+1)].document; n=n.substring(0,p);}
  if(!(x=d[n])&&d.all) x=d.all[n]; for (i=0;!x&&i<d.forms.length;i++) x=d.forms[i][n];
  for(i=0;!x&&d.layers&&i<d.layers.length;i++) x=MM_findObj(n,d.layers[i].document);
  if(!x && document.getElementById) x=document.getElementById(n); return x;
}

//=================================================================================

function MM_swapImage() { //v3.0
  var i,j=0,x,a=MM_swapImage.arguments; document.MM_sr=new Array; for(i=0;i<(a.length-2);i+=3)
   if ((x=MM_findObj(a[i]))!=null){document.MM_sr[j++]=x; if(!x.oSrc) x.oSrc=x.src; x.src=a[i+2];}
}

//=================================================================================

function fnOpenDocWin(filePath){
	var sScreenX = screen.width
	var sScreenY = screen.height
	var x = sScreenX - 650
	var y = sScreenY - 450
	var winLeft = x/2
	var winTop =  y/2 
	window.open(filePath,"doc_window","width=650,height=450,toolbar=no,location=no,status=yes,menubar=yes,scrollbars=no,resizable=yes,left=" + winLeft + ",top=" + winTop)
}

//=================================================================================

function fnOpenFlashWin(filePath){
	var sScreenX = screen.width
	var sScreenY = screen.height
	var x = sScreenX - 650
	var y = sScreenY - 450
	var winLeft = x/2
	var winTop =  y/2 
	window.open(filePath,"doc_window","width=650,height=450,toolbar=no,location=no,status=yes,menubar=yes,scrollbars=no,resizable=yes,left=" + winLeft + ",top=" + winTop)
}

//=================================================================================

function fnOpenVideoWin(filePath){
	var sScreenX = screen.width
	var sScreenY = screen.height
	var x = sScreenX - 650
	var y = sScreenY - 450
	var winLeft = x/2
	var winTop =  y/2 
	window.open(filePath,"doc_window","width=650,height=450,toolbar=no,location=no,status=yes,menubar=yes,scrollbars=no,resizable=yes,left=" + winLeft + ",top=" + winTop)
}

//=================================================================================

function fnCMSnoPopup(filePath){
	alert ('You cannot follow links from a preview page.');
}

function fnOpenWin(sFileName,sWinName,sWidth,sHeight){
	var sScreenX = screen.width
	var sScreenY = screen.height
	var x = sScreenX - sWidth
	var y = sScreenY - sHeight
	var winLeft = x/2	
	var winTop =  y/2 
	window.open(sFileName,"win_" + sWinName + "","width=" + sWidth + ",height=" + sHeight + ",toolbar=no,location=no,status=no,menubar=no,scrollbars=yes,resizable=no,left=" + winLeft + ",top=" + winTop)
}

function fnOpenVoucherWin(sFileName,sWinName,sWidth,sHeight){
	var sScreenX = screen.width
	var sScreenY = screen.height
	var x = sScreenX - sWidth
	var y = sScreenY - sHeight
	var winLeft = x/2	
	var winTop =  y/2 
	window.open(sFileName,"win_" + sWinName + "","width=" + sWidth + ",height=" + sHeight + ",toolbar=yes,location=no,status=no,menubar=yes,scrollbars=yes,resizable=no,left=" + winLeft + ",top=" + winTop)
}

function fnOpenChartWin(filePath){
	var sScreenX = screen.width
	var sScreenY = screen.height
	var x = sScreenX - 700
	var y = sScreenY - 260
	var winLeft = x/2
	var winTop =  y/2 
	window.open(filePath,"chart_window","width=700,height=260,toolbar=yes,location=no,status=no,menubar=no,scrollbars=yes,resizable=yes,left=" + winLeft + ",top=" + winTop)
}

function fnOpenTrailWin(filePath){
	var sScreenX = screen.width
	var sScreenY = screen.height
	var x = sScreenX - 600
	var y = sScreenY - 327
	var winLeft = x/2
	var winTop =  y/2 
	window.open(filePath,"trail_window","width=600,height=327,toolbar=yes,location=no,status=no,menubar=no,scrollbars=yes,resizable=yes,left=" + winLeft + ",top=" + winTop)
}

function fnOpenPhotoWin(filePath){
	var sScreenX = screen.width
	var sScreenY = screen.height
	var x = sScreenX - 620
	var y = sScreenY - 400
	var winLeft = x/2
	var winTop =  y/2 
	window.open(filePath,"photo_window","width=620,height=400,toolbar=yes,location=no,status=no,menubar=no,scrollbars=yes,resizable=yes,left=" + winLeft + ",top=" + winTop)
}



/* General Functions */
function fnPrint () {
	window.print()
}

//--Submit Form--
function fnSubmit(formName) {	
	eval("document." + formName + ".submit();");
}	

//--Submit Form--
function fnSubmitCheckout(formName,actionName) {
	eval("document." + formName + ".action = 'checkout.aspx?section=" + actionName + "'");	
	eval("document." + formName + ".submit();");
}	

//--Submit Form to the parent window--
function fnSubmitParent(formName) {	
	eval("parent.opener.document." + formName + ".submit();");
}	

//--Link a page to the parent window--
function fnLinkParent(fileName) {	
	parent.opener.location = fileName;
	window.close();
}	


//--Submits two forms from the product popup--
function fnSubmitPopup(formName,parentFormName){
	eval("document." + formName + ".submit();");
	setTimeout("fnSubmitParent('" + parentFormName + "')",100);		
}


//--Reload the parent window--
function fnReloadParent() {
	parent.window.opener.location.reload()
}	

//--Submits the trader search form and updates the relevant search criteria--
function fnTraderProducerSubmit(formName,chr,colour){
		document.traderSearch.vintageStart.value = "0";
		document.traderSearch.vintageEnd.value = "0";
		document.traderSearch.colour.value = colour;
		document.traderSearch.producerInitial.value = chr;
		document.traderSearch.submit();
}

//--Submits the trader search form and updates the relevant search criteria--
function fnTraderVintageSubmit(formName,year,colour){
		document.traderSearch.producerInitial.value = "";
		document.traderSearch.colour.value = colour;
		document.traderSearch.vintageStart.value = year;
		document.traderSearch.vintageEnd.value = year;
		document.traderSearch.submit();
}

//--Open pop up window and centre in the middle of the screen--
function fnPopUp(filePath,height,width,attributes){
	var sScreenX = screen.width
	var sScreenY = screen.height
	var x = sScreenX - width
	var y = sScreenY - height
	var winLeft = x/2
	var winTop =  y/2 
	window.open(filePath,"","width=" + width + ",height=" + height + "," + attributes + ",left=" + winLeft + ",top=" + winTop)
}

//Add message to status bar
		window.defaultStatus='John Armit Wines';
		
//sort out arrow alignment inside the tools menu for the macs
if ((navigator.appVersion.indexOf("Mac") != -1)) 
{    //safari et al
	var mac='yes';
	document.write ("<style type=\"text/css\" media=\"all\"> #tools a img { position:relative; top: 5px;}</style>");

	if (navigator.userAgent && navigator.userAgent.indexOf("MSIE") >= 0) 
    {  //mac ie		
		document.write ("<style type=\"text/css\" media=\"all\"> #tools a img { position:relative; top: -2px;}</style>");
    } 
}


function getWindowHeight() {
			var windowHeight = 0;
			if (typeof(window.innerHeight) == 'number') {
				windowHeight = window.innerHeight;
			}
			else {
				if (document.documentElement && document.documentElement.clientHeight) {
					windowHeight = document.documentElement.clientHeight;
				}
				else {
					if (document.body && document.body.clientHeight) {
						windowHeight = document.body.clientHeight;
					}
				}
			}
	return windowHeight;
}
function fnFullScreen() {
	//Detect IE5.5+ as footer alignment script crashes older verisons of ie
	version=0
	if (navigator.appVersion.indexOf("MSIE")!=-1){
	temp=navigator.appVersion.split("MSIE")
	version=parseFloat(temp[1])
	}

	if (version>=5.5 && mac!="yes" || version==0) {

	
				//Height of header, footer etc.
					iNonContentHeight = 167;	
				//Calculate height that main content needs to be to push footer to bottom of page	
					var contentHeight = getWindowHeight() - iNonContentHeight;
					if (document.getElementById('bodyContent')) {
						var content = document.getElementById('bodyContent');	
				 		content.style.height = contentHeight+'px';					
					}	
					
	} else if (mac=="yes") {
				//Height of header, footer etc.
					iNonContentHeight = 167;	
				//Calculate height that main content needs to be to push footer to bottom of page	
					var contentHeight = getWindowHeight() - iNonContentHeight;
					if (document.getElementById('bodyContent')) {
						var content = document.getElementById('bodyContent');	
				 		content.style.height = contentHeight+'px';					
					}	
	
	}
}		


// New function to allow different sized popups to be incorporated from CMS
function fnPopUpStyle(filePath, popUpStyle, attributes){
	

	var width = 0;
	var height = 0;
	var sScreenX = screen.width
	var sScreenY = screen.height

	switch (popUpStyle){
		case "1" : 
			width = "600";
			height = "400";
			break;
		case "2":
			width = "400";
			height = "400";
			break;			
	}

	var x = sScreenX - width
	var y = sScreenY - height
	var winLeft = x/2
	var winTop =  y/2 
	
	
	window.open(filePath,"","width=" + width + ",height=" + height + "," + attributes + ",left=" + winLeft + ",top=" + winTop)
}

window.onload = fnFullScreen;
window.onresize = fnFullScreen;
