function WinOpen(url,name,features) {
	window.open(url,name,features);
}
		if (parent.frames.length > 0) {
			parent.location.href = self.document.location
		}
function getElementsByClass(searchClass,node,tag) {
	var classElements = new Array();
	if ( node == null )
		node = document;
	if ( tag == null )
		tag = '*';
	var els = node.getElementsByTagName(tag);
	var elsLen = els.length;
	var pattern = new RegExp("(^|\s)"+searchClass+"(\s|$)");
	for (i = 0, j = 0; i < elsLen; i++) {
		if ( pattern.test(els[i].className) ) {
			classElements[j] = els[i];
			j++;
		}
	}
	return classElements;
}//ajax
function ajaxRequest(params){


	var url = params.url
	err  = new String
	if(params.start !=null){
		params.start()
	}
	if (window.XMLHttpRequest) {
		xmlhttp = new XMLHttpRequest();
                if(!document.all){
		    xmlhttp.overrideMimeType("text/xml");
                }
	}else {
		xmlhttp = new ActiveXObject("Microsoft.XMLDOM");
	}
	xmlhttp.onreadystatechange = function(){ 
		//alert(xmlhttp.readyState)
		if (xmlhttp.readyState == 4) {
			if (xmlhttp.status == 200) {
			if(params.finish !=null){
				params.finish(xmlhttp)
			}
				
			}else if (xmlhttp.status == 500){
				err = "There was a problem retrieving the XML data:\n" + xmlhttp.statusText
				if(params.error !=null){
					params.error(err)
				}else{
					alert(err)
				}
			}else{
				err = "There has been an error: \n" + xmlhttp.statusText + ' - ' + xmlhttp.status
				if(params.error !=null){
					params.error(err)
				}else{
					alert(err)
				}
			}
		}
	}
	xmlhttp.open("GET",url,true);
	xmlhttp.setRequestHeader('content-type', 'text/xml'); 		
	xmlhttp.send(null);	
}
//ajax
function getSel(tag,id)
{
	if(document.all){
		var str = document.selection.createRange().text;
		document.getElementById(id).focus();
		var sel = document.selection.createRange();
		sel.text = "<" + tag + ">" + str + "</" + tag + ">";
	}else{
		alert("Only works in IE!!!")
	}
}


//----email form stuff

function rnd(n) {
	return Math.floor(Math.random()*n)+1;
}
var xmlhttp
var address
var err
var loadingImg = new Image
loadingImg.src = 'http://www.martialartsallstyles.co.uk/images/loading.gif'
function makeEmail(addy){
	if (parent.frames.length > 0) {
	parent.location.href = self.document.location
}
window.scroll(0,0);
	address = addy
	ajaxRequest(
		params = {
			'url' : 'http://www.martialartsallstyles.co.uk/emailForm.htm?rnd='+rnd(1000),
			'start'  : emailFormLoading,
			'finish'  : emailFormLoaded
		}
	);
}
function emailFormLoading(){

//make overlay
	var opacity=70
	var frmEle = document.createElement('div');
	frmEle.setAttribute('id','overlay');
	frmEle.style.width=Page.Width()+ 'px';
	frmEle.style.height=Page.Height()+ 'px';
	frmEle.style.backgroundColor = "#F7F7F7";
	frmEle.style.position="absolute";
	frmEle.style.MozOpacity=opacity/100;
	frmEle.style.opacity = (opacity / 100);
	frmEle.style.filter = "alpha(opacity=" + opacity + ")"; 
	frmEle.style.top="0px";
	frmEle.style.left="0px";
	frmEle.style.zIndex=50;
	document.body.appendChild(frmEle);	
//make form
	var frmEle = document.createElement('div')
	frmEle.setAttribute('id','mailForm');
	document.body.appendChild(frmEle);
	frmEle.style.height='340px';
	frmEle.style.overflow = 'auto';
	frmEle.style.padding = '10px';
	frmEle.style.position = 'absolute';
	frmEle.style.left = ((Page.Width() / 2) - 270) + 'px';
	frmEle.style.top = (190) + 'px';
	frmEle.style.backgroundColor = 'white';
	frmEle.style.border = '1px solid black';
	frmEle.style.zIndex = '201';
	frmEle.appendChild(loadingImg)

	var frmEle = document.createElement('div');
	document.getElementById('mailForm').innerHTML+= "Loading...";
	
//Make Drop Shadow


}


function emailFormLoaded(){
	var xmlDoc = xmlhttp.responseText;
	address = address.replace("##","@");
	var mailForm = document.getElementById('mailForm')
	mailForm.innerHTML =  '<strong>Send an email to ' + address + '</strong>' + xmlDoc;
	mailForm.style.left = ((Page.Width() / 2) - (Element.Width('mailForm')/2)) + 'px';
	mailForm.style.top = (190)+ 'px';
	
	DropShadow.add('mailForm')

	
}

var DropShadow = {
	n : null,
	dsLeft : null,
	dsTop : null,
	dsContainer : null,
	dsWidth : null,
	dsHeight : null,
	Start : function(){
		var el = getElementsByClass('dropShadow',document);
		for(var i=0;i<el.length;i++){
			DropShadow.n = null;DropShadow.dsContainer = null;
			DropShadow.dsLeft = null;DropShadow.dsTop = null;
			DropShadow.dsWidth = null;DropShadow.dsHeight = null;
			DropShadow.add(el[i].id);
		}
	},
	add : function(id,colour,offsetX,offsetY,opacity){
		if(DropShadow.n==null){
			offsetX = ((offsetX==null) ? 3 : (offsetX/2));
			offsetY = ((offsetY==null) ? 3 : (offsetY/2));
			opacity = ((opacity==null) ? 90 : opacity);
			colour = ((colour==null) ? "black" : colour);
			DropShadow.dsWidth = ((DropShadow.dsWidth==null) ? Element.Width(id)-12 : DropShadow.dsWidth);
			DropShadow.dsHeight = ((DropShadow.dsHeight==null) ? Element.Height(id)-12 : DropShadow.dsHeight);
			
			document.getElementById(id).style.zIndex = 120;
			DropShadow.dsContainer =  id +"_dropshadow"
			var frmEle = document.createElement('div');
			frmEle.setAttribute('id',DropShadow.dsContainer);
			frmEle.style.position = 'absolute';
			frmEle.style.top=0;
			frmEle.style.left=0;
			frmEle.innerHTML+= "&nbsp;"
			frmEle.style.zIndex = 119;
			document.body.appendChild(frmEle);
		
			DropShadow.dsLeft = Element.Left(id);
			DropShadow.dsTop = Element.Top(id);
	
			DropShadow.n=0;
		}
		dsID = DropShadow.dsContainer + DropShadow.n
		var parentDiv = document.getElementById(id);
		//parentDiv.style.zIndex = 50
		var frmEle = document.createElement('div');
		frmEle.setAttribute('id',dsID);

		frmEle.style.position = 'absolute';
		frmEle.style.backgroundColor=colour;
		frmEle.style.MozOpacity=(opacity/100);
		frmEle.style.opacity = (opacity / 100);
		frmEle.style.filter = "alpha(opacity=" + opacity + ")"; 
		frmEle.style.zIndex = parentDiv.style.zIndex - 1;

		frmEle.style.width = DropShadow.dsWidth + (DropShadow.n*2) + 'px';
		frmEle.style.height = DropShadow.dsHeight + (DropShadow.n*2) + 'px';

		frmEle.style.top = DropShadow.dsTop+ (offsetY) +(6-DropShadow.n)+'px';
		frmEle.style.left = DropShadow.dsLeft + (offsetX) +(6-DropShadow.n) +'px';
		document.getElementById(DropShadow.dsContainer).appendChild(frmEle);
	
		document.getElementById(dsID).innerHTML+= "&nbsp;";
		var modifier =9;
		if(DropShadow.n==0){
			for(DropShadow.n=1;DropShadow.n<12;DropShadow.n++){
				DropShadow.add(dsID,colour,offsetX,offsetY,opacity-(modifier*DropShadow.n));
			}
		}
	},
	remove : function(id){
		if(document.getElementById(id +"_dropshadow")!=null)document.body.removeChild(document.getElementById(id +"_dropshadow"));
	}
}
function sendMail(){
	alert('sendmail.asp?'+'from='+from+'&subject='+subject+'&name='+name+'&message='+message);
}
function validateEmail(){
	if (fuzzyValidation('email_from,email_subject,email_name,email_message','true,true,true,true','email,null,null,null','null,null,null,null')){
		var from = document.getElementById('email_from').value;
		var subject = document.getElementById('email_subject').value;
		var name = document.getElementById('email_name').value;
		var message = document.getElementById('email_message').value.replace(/\n/g, "<br />");
		ajaxRequest(

		params = {
			'url' : 'http://www.martialartsallstyles.co.uk/sendmail.asp?'+rnd(1000)+'&from='+from+'&to='+address+'&subject='+subject+'&name='+name+'&message='+message,
			'start'  : emailSending,
			'finish'  : emailSent,
			'error' : cleanupSend
		}
	);	
	}
}
function cleanupSend(){
	alert(err);
	window.location.reload();
}
function emailSending(){
		document.getElementById('mailForm').style.zIndex=1

		var frmEle = document.createElement('div')
		frmEle.setAttribute('id','sending');
		frmEle.style.padding = '10px'
		frmEle.style.position = 'absolute'
		frmEle.appendChild(loadingImg)
		frmEle.innerHTML+= "<strong>Sending...</strong>"
		frmEle.style.zIndex=60
		frmEle.style.backgroundColor = 'white'
		frmEle.style.border = '1px solid black'
		DropShadow.remove('mailForm')
		frmEle.style.left = ((Page.Width() / 2) - 30) + 'px'
		frmEle.style.top = ((Page.Height() / 2) - 20) + 'px'	
		document.body.appendChild(frmEle);	

}
function emailSent(){
	var xmlDoc = xmlhttp.responseXML;
	if(xmlDoc.getElementsByTagName('sent')[0].firstChild.nodeValue=='true'){
		document.getElementById('sending').innerHTML = "<strong>Sent!!</strong>"
		pausecomp(2000)
		setTimeout(cleanUp,2000)
	}else{
		document.getElementById('mailForm').innerHTML += "<span class='required'>There has been an error.<br> Try copying the email address <br><a href='mailto:"+address+"'>"+address+"</a> into your email program eg outlook.</span>"
		document.body.removeChild(document.getElementById('sending'))
		document.getElementById('mailForm').style.zIndex=99
		alert(xmlDoc.getElementsByTagName('sent')[0].firstChild.nodeValue)
	}
}
function cleanUp(){
	if(document.getElementById('sending')!=null)document.body.removeChild(document.getElementById('sending'))
	DropShadow.remove('mailForm')
	DropShadow.remove('sending')
	document.body.removeChild(document.getElementById('mailForm'))
	document.body.removeChild(document.getElementById('overlay'))
}
function cancel(){
	cleanUp()
}


var Element = {
	Height : function(id){
		var oHeight;
		if(document.getElementById){
			oHeight = document.getElementById(id).offsetHeight;
		}else if (document.layers){
			oHeight = document.layers[id].clip.height;
		}
		return oHeight;
	},
	Width : function(id){
		var oWidth;
		if(document.getElementById){
			oWidth = document.getElementById(id).offsetWidth;
		}else if (document.layers){
			oWidth = document.layers[id].clip.width;
		}
		return oWidth;
	},
	Top : function(id){
		var oTop;
		if(document.getElementById){
			oTop = document.getElementById(id).offsetTop;
		}else if (document.layers){
			oTop = document.layers[id].clip.top;
		}
		return oTop;
	},
	Left : function(id){
		var oLeft;
		if(document.getElementById){
			oLeft = document.getElementById(id).offsetLeft;
		}else if (document.layers){
			oLeft = document.layers[id].clip.left;
		}
		return oLeft;
	}
}

var Page = {
	Height : function(){
		var  browseHeight;
		if(document.layers||(document.getElementById&&!document.all)){
		   browseHeight=window.innerHeight;
		}else if(document.all){
		   browseHeight=document.body.clientHeight;
		}
		return browseHeight;
	},
	Width : function(){
		var browseWidth;
		if(document.layers||(document.getElementById&&!document.all)){
		   browseWidth=window.outerWidth;
		}else if(document.all){
		   browseWidth=document.body.clientWidth;
		}
		return browseWidth;
	}
}

function pausecomp(millis) 
{
date = new Date();
var curDate = null;

do { var curDate = new Date(); } 
while(curDate-date < millis);
} 
function getElementHeight(id) {
	if(document.getElementById){
		oHeight = document.getElementById(id).offsetHeight;
	}
	else if (document.layers){
		oHeight = document.layers[id].clip.height;
	}
	return oHeight
}

