function showShare2(aObj,aID,aGID){
	document.getElementById("id").value=aID;
	showShare(aObj,aID);
}

function showShare(aObj,aID){
	var pX=findPosX(aObj);
	var pY=findPosY(aObj);
	document.getElementById("id").value=aID;
	document.getElementById('sharebox').style.top=(pY-290)+"px";
	document.getElementById('sharebox').style.left=(pX-450)+"px";

	document.getElementById('sharebox').style.display="";
}

function closeShare(){
	document.getElementById('sharebox').style.display="none";
}

function openShowBox(obj, organiser, email){
	var pX=findPosX(obj);
	var pY=findPosY(obj);
	document.getElementById("race_organiser").innerHTML = organiser;
	document.getElementById("race_organiser_email").innerHTML = '<a href="mailto:' + email + '">' + email + '</a>';
	document.getElementById('showbox').style.top=(pY-23-document.getElementById('container').scrollTop)+"px";
	document.getElementById('showbox').style.left=(pX-510)+"px";

	document.getElementById('showbox').style.display="";
}

function closeShowBox(){
	document.getElementById('showbox').style.display="none";
}

function findPosX(obj)
  {
    var curleft = 0;
    if(obj.offsetParent)
        while(1) 
        {
          curleft += obj.offsetLeft;
          if(!obj.offsetParent)
            break;
          obj = obj.offsetParent;
        }
    else if(obj.x)
        curleft += obj.x;
    return curleft;
  }

  function findPosY(obj)
  {
    var curtop = 0;
    if(obj.offsetParent)
        while(1)
        {
          curtop += obj.offsetTop;
          if(!obj.offsetParent)
            break;
          obj = obj.offsetParent;
        }
    else if(obj.y)
        curtop += obj.y;
    return curtop;
  }

  function sendFriend(){
	var pID=document.getElementById("id").value;
	var gID=document.getElementById("gid").value;
	var pEmail=document.getElementById("email").value;
	var pEmail2=document.getElementById("email2").value;
	var pName=document.getElementById("name").value;
	var pYourName=document.getElementById("your_name").value;
	var pMess=document.getElementById("message").value;
	var pError=0;
	var pMessage="";

	if(pEmail==""){
		pMessage+="Please type email to send link to\n";
		pError=1;
	}
	if(pYourName==""){
		pMessage+="Please type your name\n";
		pError=1;
	}
	if(pError==1){
		alert(pMessage);
	}else{

		var pAjaxObj = null;
		if(window.XMLHttpRequest){
			pAjaxObj = new XMLHttpRequest();
		
		}else if(window.ActiveXObject){
			pAjaxObj = new ActiveXObject("Microsoft.XMLHTTP");
		}//if
		var pFile="/assets/libs/sendfriend.php?email="+pEmail+"&email2="+pEmail2+"&id="+pID+"&name="+pName+"&yourname="+pYourName+"&gid="+gID+"&message="+pMess.replace("\n", "<br />");

		pAjaxObj.open("GET",pFile);
		
		pAjaxObj.onreadystatechange = function(){

			if(pAjaxObj.readyState == 4 && pAjaxObj.status == 200){		
				document.getElementById("sfcontent").innerHTML="An email has been sent to your friend.";
				
			}//if
		}//function
		
		pAjaxObj.send(null);
		
	}//if
  }//sendFriend

var validation = new Array();
	
function checkForm(form, fields){
	var pError=0;
	var errorCount = 0;

	if(fields.length > 0){
		for(var i = 0; i < fields.length; i++){
			if(typeof(form.elements[validation[i][0]]) != 'undefined' && (form.elements[validation[i][0]].value=="") ){
				pError=1;
				if(errorCount == 0){
					form.elements[validation[i][0]].focus();
				}
				document.getElementById(validation[i][1]).className=validation[i][2] + ' error';
				errorCount++;
			}else if(validation[i][5] != '' && validation[i][5] != null && (form.elements[validation[i][0]].value==validation[i][5])){
				pError=1;
				if(errorCount == 0){
					form.elements[validation[i][0]].focus();
				}
				document.getElementById(validation[i][1]).className=validation[i][2] + ' error';
				errorCount++;
			}else if(typeof(validation[i][3]) != 'undefined' && typeof(validation[i][3]) != 'string' && validation[i][3] != null && typeof(form.elements[validation[i][0]]) != 'undefined' && !validation[i][3].test(form.elements[validation[i][0]].value)){
				pError=1;
				if(errorCount == 0){
					form.elements[validation[i][0]].focus();
				}
				document.getElementById(validation[i][1]).className=validation[i][2] + ' error';
				errorCount++;
			}else if(typeof(validation[i][3]) != 'undefined' && validation[i][3] != null && typeof(form.elements[validation[i][0]]) != 'undefined' && validation[i][3] == '/on/' && form.elements[validation[i][0]].checked != true){
				pError=1;
				if(errorCount == 0){
					form.elements[validation[i][0]].focus();
				}
				document.getElementById(validation[i][1]).className=validation[i][2] + ' error';
				errorCount++;
			}else if(typeof(validation[i][4]) != 'undefined' && validation[i][4] != null && typeof(form.elements[validation[i][0]]) != 'undefined' && form.elements[validation[i][0]].value != form.elements[validation[i][4]].value){
				pError=1;
				if(errorCount == 0){
					form.elements[validation[i][0]].focus();
				}
				document.getElementById(validation[i][1]).className=validation[i][2] + ' error';
				errorCount++;
			}			
			else{
				document.getElementById(validation[i][1]).className=validation[i][2];
			}		
			if(typeof(validation[i][3]) == 'string' && validation[i][3].substring(0,4) == 'date'){
				var from = new Date(validation[i][3].substring(5,15));
				var to = new Date(validation[i][3].substring(16,26));
				var fd = form.elements[validation[i][0]].value.split('/');
				fd = fd[2] + '-' + fd[1] + '-' + fd[0];
				var fieldDate = new Date(fd);
				if(fieldDate > to || fieldDate < from){
					pError=1;
					if(errorCount == 0){
						form.elements[validation[i][0]].focus();
					}
					document.getElementById(validation[i][1]).className=validation[i][2] + ' error';
					errorCount++;
				}
			}
		}
	}

	if(pError>0){
		document.getElementById('instructions').style.display="";
	}
	
	if(pError==0){
		document.getElementById('instructions').style.display="none";
		form.submit();
	}

}

