var x = 1;

function otherRegion() {

	var  otherRegion = document.getElementById ("hutRegion");
	var  otherRegion_index;
	var  otherRegion_value;
	
	otherRegion_index = otherRegion.selectedIndex;

	if ( otherRegion_index < 0) {
	
	} else  {

	otherRegion_value = otherRegion.options[ otherRegion_index].value;

		if (otherRegion_value == "Other") 
		
			{	toggle_element ("otherRegionHidden"); 
		
		}
	}
}

function show_hide(id, show) {         
		
	if (show==1){document.getElementById(id).style.display="";}
	
	else{document.getElementById(id).style.display="none";}
	
	}
	
function toggle_element (id) {

	var current_state;
	current_state = document.getElementById(id).style.display;
	
	
	if ((current_state == "none" ) || (current_state == "" ) ){  	
	document.getElementById(id).style.display="block"; 
	} else { document.getElementById(id).style.display="none"; }


}

function makePounds(amount)	{
 
  	var _v=parseInt(amount*100);
  	var _pounds=parseInt(_v/100);
  	var _pence=_v-(_pounds*100);
  	while(_pence.toString().length<2)_pence="0"+_pence;
  	var _dA=_pounds.toString().split("");
  	var _d="";
  	for(var i=_dA.length-1;i>=0;i--)
  	{
    var _comma="";
	if((_dA.length-i)%3==0 && i!=0)_comma=",";
    _d=_comma+_dA[i]+_d;
  	}
  	var _result="£"+_d;
  	_result+="."+_pence;
  	return(_result)

}
	
function changeCost() {

  var rrpPerItem = MM_findObj('rrpPerItem'); // the unit cost contained in a hidden field
  var quantity = MM_findObj('quantity'); // the quantity required, editable text box
  var cost = MM_findObj('cost'); // div to display the total cost
  var curcost = rrpPerItem.value * quantity.value;
  var itemTotal = MM_findObj('itemTotal'); // the hidden field used to pass the total cost
  
  cost.innerText =  makePounds(curcost);
  itemTotal.value = makePounds(curcost);

}

function chooseValue(listName,fieldName) {

	list = document.getElementById(listName);
	field = document.getElementById(fieldName);

	field.value = list.value;

}

function MM_goToURL() { //v3.0
  var i, args=MM_goToURL.arguments; document.MM_returnValue = false;
  for (i=0; i<(args.length-1); i+=2) eval(args[i]+".location='"+args[i+1]+"'");
}

function MM_openBrWindow(theURL,winName,features) { //v2.0
  window.open(theURL,winName,features);
  }
  
function openCalendar(dataField)
{
var newWindow;
var urlstring = 'calendar/calendar.asp?retCtrl=' + dataField
newWindow = window.open(urlstring,'','height=250,width=280,toolbar=no,minimize=no,status=no,memubar=no,location=no,scrollbars=no')
}

function rotate(){
	
	imgCt = adImages.length
	
	if (document.images){
		if (document.adBanner.complete){		
			thisAd++ 
			if(thisAd == imgCt){
				thisAd = 0
			} 

		document.adBanner.src = adImages[thisAd]
		
		}
		setTimeout("rotate()",7*1000)
	}
	
}

function newLocation() {

//if (adURLs[thisAd] = "#"){
//ht = ""}
//else{
//ht = "http://"
//}

document.location.href = adURLs[thisAd]

}


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.01
  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 && d.getElementById) x=d.getElementById(n); return x;
}

function MM_validateForm() { //v4.0
  var i,p,q,nm,test,num,min,max,errors='',args=MM_validateForm.arguments;
  for (i=0; i<(args.length-2); i+=3) { test=args[i+2]; val=MM_findObj(args[i]);
    if (val) { nm=val.name; if ((val=val.value)!="") {
      if (test.indexOf('isEmail')!=-1) { p=val.indexOf('@');
        if (p<1 || p==(val.length-1)) errors+='- '+nm+' must contain an e-mail address.\n';
      } else if (test!='R') { num = parseFloat(val);
        if (isNaN(val)) errors+='- '+nm+' must contain a number.\n';
        if (test.indexOf('inRange') != -1) { p=test.indexOf(':');
          min=test.substring(8,p); max=test.substring(p+1);
          if (num<min || max<num) errors+='- '+nm+' must contain a number between '+min+' and '+max+'.\n';
    } } } else if (test.charAt(0) == 'R') errors += '- '+nm+' is required.\n'; }
  } if (errors) alert('The following error(s) occurred:\n'+errors);
  document.MM_returnValue = (errors == '');
}

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 searchDB(which) {

	if (which == "cat" )
	{
	document.frmSearchCategory.submit();
	}
	else
	{
	document.frmSearchManufacturer.submit();
	}

}


function MM_changeProp(objName,x,theProp,theValue) { //v6.0
  var obj = MM_findObj(objName);
  if (obj && (theProp.indexOf("style.")==-1 || obj.style)){
    if (theValue == true || theValue == false)
      eval("obj."+theProp+"="+theValue);
    else eval("obj."+theProp+"='"+theValue+"'");
  }
}

function navOver(div,strColour)
{
div.style.backgroundColor=strColour;
div.style.backgroundImage="url(../furniture/huts.gif)";
}

function navOff(div,strColour)
{
div.style.backgroundColor=strColour;
}

function navDown(div,strColour)
{
div.style.backgroundColor=strColour;
}

function checkDelete(strPage,strQuerystring) {

	if( confirm('Are you sure you want to delete this?') == true ) 

	window.location=strPage + '?' + strQuerystring 
	
}

function testURL(varWhere) { 

	if (varWhere == "web") {

	theURL=window.document.form1.resourceaddress.value;
	
	window.open(theURL);
	//window.open("http://" + theURL);
	
	}
	
	else
	
	{
	
	theURL=window.document.frmAddEvent.bookingForm.value;

	window.open("../assets/downloads/" + theURL);	
	}
}