function isValidEmail( fieldValue ) {
	if ( /^\w+([\.-]?\w+)*@\w+([\.-]?\w+)*(\.\w{2,7})+$/.test(fieldValue) )
		return true;
	
	return false;
}

if ( use_popups == undefined ) {
	var use_popups = true;
}
var popUpWin=0;

function popUpWindow(URLStr, left, top, width, height)
{
	if ( use_popups == false ) {
		window.location.href = URLStr;
		return;
	}

	if(popUpWin)
	{
		if(!popUpWin.closed) {popUpWin.close();}
	}
	popUpWin = open(URLStr, 'popUpWin', 'toolbar=no,location=no,directories=no,status=no, scrollbars=yes, menubar=no, resizable=yes, addressbar=no, copyhistory=no, width='+width+',height='+height+',left='+left+', top='+top+',screenX='+left+',screenY='+top+'');
}

function ShowDesc(f)
{
document.getElementById("tooltip").innerHTML=str_replace('++s1++','"',str_replace('++s2++','"',f));
document.getElementById("tooltip").style.display='block';
document.onmousemove=follow;
}

function mouseX(evt)
{
if (!evt) evt = window.event; if (evt.pageX) return evt.pageX; else if (evt.clientX)return evt.clientX + (document.documentElement.scrollLeft ?  document.documentElement.scrollLeft : document.body.scrollLeft); else return 0;}
function mouseY(evt) {if (!evt) evt = window.event; if (evt.pageY) return evt.pageY; else if (evt.clientY)return evt.clientY + (document.documentElement.scrollTop ? document.documentElement.scrollTop : document.body.scrollTop); else return 0;}

function follow(evt)
{
if(evt=='stop') { document.onmousemove=null; document.getElementById("tooltip").style.display='none'; return false; }
if (document.getElementById) {var obj = document.getElementById("tooltip").style; obj.display = 'block';
obj.left = (parseInt(mouseX(evt)))+10+'px';
obj.top = (parseInt(mouseY(evt)))-60+'px';}
}

function str_replace (search, replace, subject, count) {
    var i = 0, j = 0, temp = '', repl = '', sl = 0, fl = 0,
            f = [].concat(search),
            r = [].concat(replace),
            s = subject,
            ra = r instanceof Array, sa = s instanceof Array;
    s = [].concat(s);
    if (count) {
        this.window[count] = 0;
    }
    for (i=0, sl=s.length; i < sl; i++) {
        if (s[i] === '') {
            continue;
        }
        for (j=0, fl=f.length; j < fl; j++) {
            temp = s[i]+'';
            repl = ra ? (r[j] !== undefined ? r[j] : '') : r[0];
            s[i] = (temp).split(f[j]).join(repl);
            if (count && s[i] !== temp) {
                this.window[count] += (temp.length-s[i].length)/f[j].length;}
        }
    }
    return sa ? s : s[0];
}

function BookNow(evid,dat)
{
document.getElementById('booknow').style.top='140px';
if (document.getElementById) ww=window.screen.width;
if(!ww) ww=document.body.parentNode.clientwidth;
ww=parseInt(ww/2)-200;
document.getElementById('booknow').style.left=ww+'px';
document.getElementById('booknow').style.display='block';
document.getElementById('booknow').innerHTML="<center><img src='images/load.gif'></center>";

xmlH=GetXmlHttpObject();
var url="ajax.php?loc=booknow&event="+evid+"&date="+dat;
xmlH.onreadystatechange=function()
{
if (xmlH.readyState==4)
{
document.getElementById('booknow').innerHTML='';
document.getElementById('booknow').innerHTML=xmlH.responseText;
}
};
xmlH.open("GET",url,true);
xmlH.send(null);
}

function ReservIt(evid,dat,uid)
{
var mf=document.getElementById('bookform');
// if(!mf.name.value || !mf.email.value || !mf.phone.value) { alert('Name, email and phone number are required fields'); return; }
xmlH=GetXmlHttpObject();
var url="ajax.php?loc=reservit&message="+str_replace('"','++1++',str_replace("'","++2++",mf.message.value))+"&event="+evid+"&date="+dat;
xmlH.onreadystatechange=function()
{
if (xmlH.readyState==4)
{
document.getElementById('booknow').innerHTML=xmlH.responseText;
}
};
xmlH.open("GET",url,true);
xmlH.send(null);
}

function str_replace (search, replace, subject, count) {
    var i = 0, j = 0, temp = '', repl = '', sl = 0, fl = 0,
            f = [].concat(search),
            r = [].concat(replace),
            s = subject,
            ra = r instanceof Array, sa = s instanceof Array;
    s = [].concat(s);
    if (count) {
        this.window[count] = 0;
    }
    for (i=0, sl=s.length; i < sl; i++) {
        if (s[i] === '') {
            continue;
        }
        for (j=0, fl=f.length; j < fl; j++) {
            temp = s[i]+'';
            repl = ra ? (r[j] !== undefined ? r[j] : '') : r[0];
            s[i] = (temp).split(f[j]).join(repl);
            if (count && s[i] !== temp) {
                this.window[count] += (temp.length-s[i].length)/f[j].length;}
        }
    }
    return sa ? s : s[0];
}

function GetXmlHttpObject()
{
var xmlHttp=null;
try
  {
  xmlHttp=new XMLHttpRequest();
  }
catch (e)
  {
  try
    {
    xmlHttp=new ActiveXObject("Msxml2.XMLHTTP");
    }
  catch (e)
    {
    xmlHttp=new ActiveXObject("Microsoft.XMLHTTP");
    }
  }
return xmlHttp;
}

function TrainerCalendar(trid,dat) {
document.getElementById('calendar').innerHTML="<center><img style='padding:30px' src='images/load.gif'></center>";
xmlH=GetXmlHttpObject();
var url="ajax.php?loc=TrainerCalendar&trid="+trid+"&date="+dat;
xmlH.onreadystatechange=function()
{
if (xmlH.readyState==4)
{
document.getElementById('calendar').innerHTML=xmlH.responseText;
}
};
xmlH.open("GET",url,true);
xmlH.send(null);
}