//                  .  .. . . .        ..    ..          .   .  ..  .   .          
//                  ...   ... .      ......... ..        . ... ..  .... .         
//                     ..  . .       ..8O..8O~...      . .88O.O8~....$8~...  ..   
//..... .   .....,~. .+$Z$Z$   .   ....MM,,MM=.. ...... ..MMM,MM=,...8M=,..   .   
//. ...  ..,:?7ZOZZ,. 7?+?$? ... ......MM,,,,,.............,,,MM+,,.,8M+,..       
//    . ,?O8OOZZ$$Z..,OOO8$:.. ...I7777MM:,77:...=777+....777,MMZ77?,8M+,...      
//.... ?DNDDDDDDDD$  ~MMMN+....~NMMMMMMMM:,MM+.=MMMMMMM?,,MMM,MMMMM8,8M+,...  ....
// ....NNNDNNDD8O$~.,7MMMZ,....MMM=::::MM::MM+IMMZ~::7MM7,MMM:MM+::,,8M+,.........
//. ..?NDDI=,.......=DMMM?.....MMZ:,.,,MM::MM+8MM:,,,,?MM:MMM:MM+::,,8M+,.........
//...+87,.:?$ZOOO+.:ZMMMM......MMI,...,MM::MM+NMM,,...,MM:MMM:MM+,,.,8M+,.........
//...$D,.~88888OZ:.?NMMMZ......MMN,,,,$MD::MM+ZMM:,,.,,MM:MMM:DMZ:,,,8MO:,........
//...Z8.,788888O?..OMMM8~......DMMMD8MMM=:,MM+:NMMMD888MM:MMM:IMMMM$,+MMMN$,......
//...?O.:$888888,.,MMMO~.......,=DMMMMNI,,,MM+,,=MMMMMMMM:MMM,,,MMM8,,7DMM8,......
//...,+,.:O8OZ7~,?DMDZ..........,,,,,,,,,..,,,,,,,,:::?MM:,,,,,,,,,,,,,,,,,,......
//........,,,:=7MNO:...............,...........=77778NMMZ:,...............,.......
//.............................................7MMMMMMM+,,,.......................
//..............................................,,:::::,,,........................
//..............................................,,,,,,,...........................
// because file sizes aren't an issue?..........,,,,,,,...........................


var ajaxObjects = new Array();

function EmailMe(propertyID,divID,sEmail) {
	var fieldname = 'fcemail'+propertyID;	
	
	document.getElementById(divID).innerHTML='<br/>Please enter your email address to be sent details of this farm:<br/><br/><form><input type="text" name="'+fieldname+'" id="'+fieldname+'" onKeyPress="return checkEnter(event)" /><input type="button" name="bSend" id="bSend" value="Email Me" onClick="EmailMeProcess(\''+propertyID+'\',\''+divID+'\',\''+fieldname+'\')\;"/></form><br/><br/><a href="#" onClick="CloseMe(\''+divID+'\',\''+propertyID+'\')\; return false;">Close</a>';	
}

function EmailMeProcess(propertyID,divID,fieldName) {
	var ajaxIndex = ajaxObjects.length;
	var sEmail = document.getElementById(fieldName).value;
	
	document.getElementById(divID).innerHTML='<img src="/images/loading.gif" align="absmiddle" />&nbsp;&nbsp;Please Wait...';
	
	ajaxObjects[ajaxIndex] = new sack();
	var url = '/includes/ajax_mymatches_email.asp?Action=PropertyEmail&PropertyID=' + propertyID + '&Email=' + sEmail;
	ajaxObjects[ajaxIndex].requestFile = url;	// Specifying which file to get
	ajaxObjects[ajaxIndex].onCompletion = function() { EmailMeComplete(ajaxIndex,divID,propertyID,sEmail); } ;	// Specify function that will be executed after file has been found
	ajaxObjects[ajaxIndex].runAJAX();		
}

function CloseMe(divID,propertyID) {
	document.getElementById(divID).innerHTML='<a href="#" onClick="EmailMe(\''+propertyID+'\',\'prop_'+propertyID+'\',\'\')\; return false\;"">Email complete details to me &raquo\;</a>';
}

function EmailMeComplete(index,divID,propertyID,sEmail) {
	var xmlString = ajaxObjects[index].response;
	// code for IE
	if (window.ActiveXObject)
	  {
	  var doc=new ActiveXObject("Microsoft.XMLDOM");
	  doc.async="false";
	  doc.loadXML(xmlString);
	  }
	// code for Mozilla, Firefox, Opera, etc.
	else
	  {
	  var parser=new DOMParser();
	  var doc=parser.parseFromString(xmlString,"text/xml");
	  }
	
	var x=doc.documentElement;
	
	var sEmailResult  = x.childNodes[0].childNodes[0].nodeValue;
	var sResult = x.childNodes[1].childNodes[0].nodeValue;
	
	if (sResult =='ok') {
		var sMessage = '<a href="#" onClick="EmailMe(\''+propertyID+'\',\'prop_'+propertyID+'\',\'\')\; return false\;"">Email complete details to me &raquo;</a><br /><br /><strong>Email was sent to your email address.'; //' + sEmailResult + '.</strong>';		
	} else {
		var sMessage = '<a href="#" onClick="EmailMe(\''+propertyID+'\',\'prop_'+propertyID+'\',\'\')\; return false\;"">Email complete details to me &raquo\;</a><br /><br /><strong>An error occured - the email was not sent - please try again.</strong><br/><br/><small>Error details:<br/>'+sResult+'</small>';
	}
	
	document.getElementById(divID).innerHTML=sMessage;
}

function ReportError(sError) {
		
}

function checkEnter(e){ //e is event object passed from function invocation
var characterCode //literal character code will be stored in this variable

if(e && e.which){ //if which property of event object is supported (NN4)
e = e
characterCode = e.which //character code is contained in NN4's which property
}
else{
e = event
characterCode = e.keyCode //character code is contained in IE's keyCode property
}

if(characterCode == 13){ //if generated character code is equal to ascii 13 (if enter key)
//document.forms[0].submit() //submit the form
alert("Please press the Email Me button...");
return false
}
else{
return true
}

}
