var ModalDialogWindow;
var ModalDialogInterval;
var ModalDialog = new Object;

ModalDialog.value = '';
ModalDialog.eventhandler = '';

function refresh_page()
{
	document.location.replace(document.location.href);
}

function ModalDialogMaintainFocus()
{
	try
	{
		if (ModalDialogWindow.closed)
		{
			window.clearInterval(ModalDialogInterval);
			eval(ModalDialog.eventhandler);
			return;
		}

//			ModalDialogWindow.focus();
	}
	catch (everything)
	{

	}
}

function ModalDialogRemoveWatch()
{
	ModalDialog.value = '';
	ModalDialog.eventhandler = '';
}

function ModalDialogShow(page_to_show, do_refresh)
{
	var do_refresh = (do_refresh == null) ? true : do_refresh;

	ModalDialogRemoveWatch();

	if(do_refresh === true)
	{
		ModalDialog.eventhandler = "refresh_page()";
	}

	var args='width=800,height=610,left=325,top=300,toolbar=0,';
	args += 'location=0,status=0,menubar=0,scrollbars=1,resizable=0'; 

	ModalDialogWindow=window.open("","",args);
	ModalDialogWindow.document.open('');
	ModalDialogWindow.document.location = page_to_show;
	ModalDialogWindow.document.close();
	ModalDialogWindow.focus();
	ModalDialogInterval = window.setInterval("ModalDialogMaintainFocus()", 5);
}

var fwIsNetscape = navigator.appName == 'Netscape';

fwLoad = new Object;

function FWLoad(image)
{
	if (!document.images)
	{
		return null;
	}

	if (!fwLoad[image])
	{
		fwLoad[image]=new Image;
		fwLoad[image].src=image;
	}

	return fwLoad[image].src;
}

fwRestore = new Object;

function FWRestore(msg,chain) 
{
	if (document.images) 
	{
		for (var i in fwRestore)
		{
			var r = fwRestore[i];
			if (r && (!chain || r.chain==chain) && r.msg==msg)
			{
				r.src = FWLoad(r.old);
				fwRestore[i]=null;
			}
		}
	}
}

function FWLSwap(name,msg,newImg,layer,chain,trigger) 
{
	var r = fwRestore[name];

	if (document.images && (!r || r.msg < msg)) 
	{
		var uselayers = fwIsNetscape && document.layers && layer != '';
		var hld = (uselayers) ? document.layers[layer].document : document;
		var im = hld[name];
		if (!im.old) im.old = im.src;
		im.msg = msg;
		im.chain = chain;
		im.trigger = trigger;
		if (newImg) im.src = FWLoad(newImg);
		fwRestore[name] = im;
	}
}

function FWCallHit(func,targNum,msg)
{
	if(func)
	{
		for (var i in func)
		{
			func[i](targNum,msg);
		}
	}
}

function FW_Hit(frameset,chain,targNum,msg)
{
	if (frameset && frameset.length)
	{
		for (var i=0 ; i <frameset.length ; i++)
		{
			FW_Hit(frameset[i].frames,chain,targNum,msg);
			FWCallHit(top["FT_"+chain],targNum,msg);
			FWCallHit(frameset[i].window["FT_"+chain],targNum,msg);
		}
	}
	else
	{
		FWCallHit(window["FT_"+chain],targNum,msg);
	}
}

fwHit = new Object;

function FWSlave(frameset,chain,targNum,msg)
{
	if (msg==1) fwHit[chain]=targNum;
	FW_Hit(frameset,chain,targNum,1);
}

function FWSRestore(frameset,chain)
{
	var hit=fwHit[chain];
	if (hit)
		FW_Hit(frameset,chain,hit,0);
	fwHit[chain]=null;
}

function FWPreload()
{
	FWLoad("/resources/images/home1.gif");
	FWLoad("/resources/images/home2.gif");
	FWLoad("/resources/images/hearing1.gif");
	FWLoad("/resources/images/hearing2.gif");
	FWLoad("/resources/images/more1.gif");
	FWLoad("/resources/images/more2.gif");
	FWLoad("/resources/images/faqs1.gif");
	FWLoad("/resources/images/faqs2.gif");
	FWLoad("/resources/images/contact1.gif");
	FWLoad("/resources/images/contact2.gif");
	FWLoad("/resources/images/products1.gif");
	FWLoad("/resources/images/products2.gif");
	FWLoad("/resources/images/accessories1.gif");
	FWLoad("/resources/images/accessories2.gif");
	FWLoad("/resources/images/committment1.gif");
	FWLoad("/resources/images/committment2.gif");
	FWLoad("/resources/images/news1.gif");
	FWLoad("/resources/images/news2.gif");
	FWLoad("/resources/images/r0.jpg");
	FWLoad("/resources/images/r1a.jpg");
	FWLoad("/resources/images/r2a.jpg");
	FWLoad("/resources/images/r3a.jpg");
	FWLoad("/resources/images/r4a.jpg");
}

function FWLHitSwap(layer,name,num)
{
	var image = arguments[num+3];
	if (document.images && image)
	{
		var uselayers = fwIsNetscape && document.layers && layer != '';
		var hld = (uselayers) ? document.layers[layer].document : document;
		hld[name].src = FWLoad(image);
	}
}

function FWImage_Indigo(chain,msg)
{
	if (chain==1)
		FWLHitSwap('','img1',msg,'/resources/images/r0.jpg','/resources/images/r1a.jpg');
	if (chain==2)
		FWLHitSwap('','img1',msg,'/resources/images/r0.jpg','/resources/images/r2a.jpg');
	if (chain==3)
		FWLHitSwap('','img1',msg,'/resources/images/r0.jpg','/resources/images/r3a.jpg');
	if (chain==4)
		FWLHitSwap('','img1',msg,'/resources/images/r0.jpg','/resources/images/r4a.jpg');
	if (chain==5)
		FWLHitSwap('','img1',msg,'/resources/images/r0.jpg','/resources/images/r1a.jpg');
	if (chain==6)
		FWLHitSwap('','img1',msg,'/resources/images/r0.jpg','/resources/images/r2a.jpg');
	if (chain==7)
		FWLHitSwap('','img1',msg,'/resources/images/r0.jpg','/resources/images/r3a.jpg');
	if (chain==8)
		FWLHitSwap('','img1',msg,'/resources/images/r0.jpg','/resources/images/r4a.jpg');
	if (chain==9)
		FWLHitSwap('','img1',msg,'/resources/images/r0.jpg','/resources/images/r1a.jpg');
}
window.FT_Indigo=new Object;
window.FT_Indigo['0']=FWImage_Indigo;


function toggle_expand_item(button, element_id)
{
	if (document.getElementById(element_id)) 
	{
		var element = document.getElementById(element_id);

		if (element.style.display == "block") 
		{

       setTimeout(element.style.display = "none", 5000);


		}
		else 
		{
			element.style.display = "block";
		}
	}
}

function jsrsArrayFromString(s, delim){
  // rebuild an array returned from server as string
  // optional delimiter defaults to ~
  var d = (delim == null)? '~' : delim;
  return s.split(d);
} 


function toggle_expand_item2(button, element_id)
{

	//Hide the start div - this tells people how to use the map
	var start = document.getElementById('start');
	
	start.style.display = "none";
	
	var delim = "~";
	
	var arr = 'Ayrshire~Bedfordshire~Berkshire~Borders~Buckinghamshire~Cambridgeshire~Carlow~Cavan~Central~Channel_Islands~Cheshire~Clare~Cleveland~Clwyd~Cork~Cornwall~County_Durham~Cumbria~Derbyshire~Devon~Donegal~Dorset~Dublin~Dumfries_and_Galloway~Durham~Dyfed~East_Sussex~Edinburgh_Falkirk_and_Lothian~Essex~Fife~Galway~Glasgow_and_Renfrewshire~Gloucestershire~Grampian~Greater_London~Greater_Manchester~Guernsey~Gwent~Gwynedd~Hampshire~Hereford_and_Worcester~Herefordshire~Hertfordshire~Highland~Humberside~Isle_of_Man~Isle_of_Wight~Jersey~Kent~Kerry~Kildare~Kilkenny~Lanarkshire~Lancashire~Laois~Leicestershire~Leitrim~Limerick~Lincolnshire~Longford~Lothian~Louth~Mayo~Meath~Merseyside~Mid_Glamorgan~Middlesex~Monaghan~Norfolk~Northamptonshire~Northern_Ireland~Northumberland~Nottinghamshire~Offaly~Orkney_Islands~Oxfordshire~Powys~Republic_of_Ireland~Roscommon~Rutland~Scotland_North~Scottish_Borders~Shetland~Shropshire~Sligo~Somerset~South_Glamorgan~South_Yorkshire~Staffordshire~Strathclyde~Suffolk~Surrey~Swansea~Tayside~Tipperary~Tyne_and_Wear~Warwickshire~Waterford~West_Glamorgan~West_Midlands~West_Sussex~West_Yorkshire~Western_Isles~Westmeath~Wexford~Wicklow~Wiltshire~Worcestershire~Yorkshire';

	
	//convert into an array
	var array = jsrsArrayFromString(arr, delim);
	
	//Loop through that array turning the display of each of the divs to none
	for (i=0;i<array.length;i++)
	{
		var tmp = document.getElementById(array[i]);
		tmp.style.display = "none";
	} 
	
	//Then turn the div on for area you just hovered over 
	var element = document.getElementById(element_id);
	
	element.style.display = "block";


}

function resetAll()
{
	var delim = "~";
	
	var arr = 'Ayrshire~Bedfordshire~Berkshire~Borders~Buckinghamshire~Cambridgeshire~Carlow~Cavan~Central~Channel_Islands~Cheshire~Clare~Cleveland~Clwyd~Cork~Cornwall~County_Durham~Cumbria~Derbyshire~Devon~Donegal~Dorset~Dublin~Dumfries_and_Galloway~Durham~Dyfed~East_Sussex~Edinburgh_Falkirk_and_Lothian~Essex~Fife~Galway~Glasgow_and_Renfrewshire~Gloucestershire~Grampian~Greater_London~Greater_Manchester~Guernsey~Gwent~Gwynedd~Hampshire~Hereford_and_Worcester~Herefordshire~Hertfordshire~Highland~Humberside~Isle_of_Man~Isle_of_Wight~Jersey~Kent~Kerry~Kildare~Kilkenny~Lanarkshire~Lancashire~Laois~Leicestershire~Leitrim~Limerick~Lincolnshire~Longford~Lothian~Louth~Mayo~Meath~Merseyside~Mid_Glamorgan~Middlesex~Monaghan~Norfolk~Northamptonshire~Northern_Ireland~Northumberland~Nottinghamshire~Offaly~Orkney_Islands~Oxfordshire~Powys~Republic_of_Ireland~Roscommon~Rutland~Scotland_North~Scottish_Borders~Shetland~Shropshire~Sligo~Somerset~South_Glamorgan~South_Yorkshire~Staffordshire~Strathclyde~Suffolk~Surrey~Swansea~Tayside~Tipperary~Tyne_and_Wear~Warwickshire~Waterford~West_Glamorgan~West_Midlands~West_Sussex~West_Yorkshire~Western_Isles~Westmeath~Wexford~Wicklow~Wiltshire~Worcestershire~Yorkshire';
	
	//convert into an array
	var array = jsrsArrayFromString(arr, delim);
	
	//Loop through that array turning the display of each of the divs to none
	for (i=0;i<array.length;i++)
	{
		var tmp = document.getElementById(array[i]);
		tmp.style.display = "none";
	} 
	
	var start = document.getElementById('start');
	
	start.style.display = "block";
		
}


function toggle_hide_item(button, element_id)
{
	if (document.getElementById(element_id)) 
	{
		var element = document.getElementById(element_id);

		if (element.style.display == "block") 
		{
                        setTimeout = (element.style.display = "none", 5000);
		}
		else 
		{
			element.style.display = "block";
		}
	}
}



// Detect if the browser is IE or not.
// If it is not IE, we assume that the browser is NS.
var IE = document.all?true:false;

// If NS -- that is, !IE -- then set up for mouse capture
if (!IE) document.captureEvents(Event.MOUSEMOVE);

// Set-up to use getMouseXY function onMouseMove
//document.onmousemove = getMouseXY;

// Temporary variables to hold mouse x-y pos.s
var tempX = 0;
var tempY = 0;

// Main function to retrieve mouse x-y pos.s

function toggle_expand_item3(button, element_id)
{
	var left = getMouseX();
	var top = getMouseY();
	
	alert(left);
	
	var element = document.getElementById(element_id);
	element.style.position = "absolute";
	element.style.left = left;
	element.style.top = top;
	//3 different background color statements
	//so they work in all browsers
	element.style.bgColor = "#E9EDD1";
	element.style.background = "#E9EDD1";
	element.style.backgroundColor = "#E9EDD1";
	element.style.display = "block";

}

function getMouseX(e) {
  if (IE) { // grab the x-y pos.s if browser is IE
    tempX = event.clientX + document.body.scrollLeft
    //tempY = event.clientY + document.body.scrollTop
  } else {  // grab the x-y pos.s if browser is NS
    tempX = e.pageX
    //tempY = e.pageY
  }  
  // catch possible negative values in NS4
  if (tempX < 0){tempX = 0}
  //if (tempY < 0){tempY = 0}  
  // show the position values in the form named Show
  // in the text fields named MouseX and MouseY
  //document.Show.MouseX.value = tempX
  //document.Show.MouseY.value = tempY
  return tempX;
}

function getMouseY(e) {
  if (IE) { // grab the x-y pos.s if browser is IE
    //tempX = event.clientX + document.body.scrollLeft
    tempY = event.clientY + document.body.scrollTop
  } else {  // grab the x-y pos.s if browser is NS
   // tempX = e.pageX
    tempY = e.pageY
  }  
  // catch possible negative values in NS4
 //if (tempX < 0){tempX = 0}
  if (tempY < 0){tempY = 0}  
  // show the position values in the form named Show
  // in the text fields named MouseX and MouseY
  //document.Show.MouseX.value = tempX
  //document.Show.MouseY.value = tempY
  return tempY;
}

function process_form(form){
	var valid = true;
	if(form == "newsletter"){
		title = valid_string(document.getElementById('title').value, 1, 50,'title');
		if(title == false){
			valid = false;
		}else{
			firstname = valid_string(document.getElementById('forename').value, 1, 200,'firstname');
			if(firstname == false){
				valid = false;
			}else{
				surname = valid_string(document.getElementById('surname').value, 1, 200,'surname');
				if(surname == false){
					valid = false;
				}else{
					email = valid_email(document.getElementById('email').value, true, true);
					if(email == false){
						valid = false;
					}	
				}
			}
		}		
	}else if(form == "appointment"){
		title = valid_string(document.getElementById('title').value, 1, 500,'title');
		if(title == false){
			valid = false;
		}else{
			name = valid_string(document.getElementById('name').value, 1, 2000,'name');
			if(name == false){
				valid = false;
			}else{
				address = valid_string(document.getElementById('address').value, 1, 5000,'address');
				if(address == false){
					valid = false;
				}else{
					postcode = valid_string(document.getElementById('postcode').value, 1, 5000,'postcode');
					if(postcode == false){
						valid = false;
					}else{
						telephone = valid_string(document.getElementById('telephone').value, 1, 5000,'telephone');
						if(telephone == false){
							valid = false;
						}else{
							email = valid_email(document.getElementById('email').value, true, true);
							if(email == false){
								valid = false;
							}else{
								date = valid_date(document.getElementById('date').value,true,true);
								if(date == false){
									valid = false;
								}else{
									time = valid_string(document.getElementById('time').value, 1, 5000,'time');
									if(time == false){
										valid = false;	
									}
								}
							}
						}
					}
				}
			}
		}
	}
	
	return valid;	
}

