//<!--
//
// Specify a default submit button
//
/*
document.onkeydown = function() {
	var name = ($('pnlContact').style.visibility == 'hidden' ? 'leftForms_imgSideLogin' : 'btnSend');
	var subButton = $(name);
		if ( event.keyCode ==  13 ) { 
			subButton.click(); 
		event.returnValue=false; 
	} 
}*/

var urlPages = '';

/*******************************************************************
 *	DDi Solutions AJAX Methods for asynchronous data retrieval.
 *******************************************************************/
//
// Use AJAX to retrieve the Therapists information
//
function getMembersInfo(memberId){
	ASP.SearchResults.GetMembersInfo(memberId, getMembersInfo_callback);  // asynchronous call
	getMeasurements();
	collapseElement('divResults');
	// find the buttons at the bottom of the control panel 
	// so we know how far we need to grow the element 
	//var h = findPos($('Hyperlink_BackPage'))[1];
	//displayElement('ControlPanel', h+100);//551);
}
//
// Use AJAX to send an email to the therapist
//	
function sendEmail(){
	var name, userEmail, therapistEmail, phone, msg;
	
	name 					= $('txtName').value;
	userEmail 		= $('txtEmail').value;
	therapistEmail= $('hiddenEmailAddress').value;
	phone 				= $('txtPhone').value;
	msg 					= $('txtMessage').value;
	//alert('Sending Email...');
	if ( typeof(Page_ClientValidate) == 'function' ) 
	{
		if ( Page_ClientValidate() && name && userEmail && therapistEmail )// && msg )
		{
			//alert("Emailing using AJAX...\n\n\t"+name+"\n\t"+userEmail+"\n\t"+therapistEmail+"\n\t"+phone+"\n\t"+(msg ? msg : 'No message was added...'));
			ASP.SearchResults.SendContact(name, userEmail, therapistEmail, phone, msg, sendEmail_callback)
		}
		//else
		//	alert('Please enter your Name, Email Address and Message before contacting the therapist...');
	}
	else if ( !MS.Browser.IE && name && userEmail && therapistEmail )
	{
		//alert("Emailing using AJAX with Non MS Browser...\n\n\t"+name+"\n\t"+userEmail+"\n\t"+therapistEmail+"\n\t"+phone+"\n\t"+(msg ? msg : 'No message was added...'));
		ASP.SearchResults.SendContact(name, userEmail, therapistEmail, phone, msg, sendEmail_callback)
	}
	else
		alert('Please enter your Name, Email Address and Message before contacting the therapist...');
	
}
//
// Asynchronous callback result emailing the therapist
//	
function sendEmail_callback(res){
	if (res.error != null){ alert(res.error); return; }
	var s = res.value;
	alert(s);
	//alert(s.substr(0, 6));
	if ( s.substr(0, 6) != "ERROR:" ) $('pnlContact').style.visibility = 'hidden';
}
//
// Asynchronous callback results of the Therapist selected
//
function getMembersInfo_callback(res){
	//alert("Is Error "+res.error);
	if (res.error != null){
		alert(res.error);
		return;
	}	
	if (MS.Browser.IE) $('ControlPanelText').filters[0].apply();
	//MS.Debug.enabled = true;
	//MS.Debug.trace(res.value);
	//alert(res.value);
	var o = res.value;
	if (o.IsError) alert(o.ErrorMessage);
	//alert("Return Object "+o.Testing);
	var email = "<a href='mailto:" + o.EmailAddress + "'>" + o.EmailAddress + "</a>";
	//alert($('Hyperlink_Contact').href);
	$('lblBigName').innerHTML = o.BusinessName;
	$('lblBusinessName').innerHTML = o.BusinessName;
	
	var line = '<hr style="height:1px; color:#D1D1D1; padding:0px;" />'
	
	//Manipulate Qualifications area
	var pnl_quals = $('pnlQuals');
	var qual_line = $('QualLine');
	var qual_hdr = $('QualHeader');
	var qual_txt = $('QualText');
	if (pnl_quals)
	{
		qual_line.innerHTML = qual_hdr.innerHTML = qual_txt.innerHTML = "";
		pnl_quals.style.display = 'none';
		
		if (o.Qualifications.length > 0) {	
			qual_txt.innerHTML = o.Qualifications;
			qual_hdr.innerHTML = 'Qualifications &nbsp;';
			qual_line.innerHTML = line;
			pnl_quals.style.display = 'block';
		}
	}
	
	$('lblClinics').innerHTML = o.BusinessName;
	//$('lblEmail').insertAdjacentHTML('afterBegin', email);  //"<a href='mailto:" & o.EmailAddress & "'>" & o.EmailAddress & "</a>"
	//$('lblEmail').innerHTML = email;
	var winOptions = ''; //<a href="javascript:void(0)" onclick="javascript:openLookup('/index.php?m=search&a=ask_question&h_b=true&id=750','appt',600,500)">Make an Enquiry</a>
	//$('Hyperlink_Contact').href = "javascript: openWin(\""+urlPages+"/email.aspx?bn="+o.BusinessName.replace(/[\&]+/, '|')+"&em="+o.EmailAddress+"\",600,500,true);"; //"javascript: $('txtMessage').value=''; showPanel('pnlContact'); $('txtName').focus();"//"mailto:" + o.EmailAddress;
	$('Hyperlink_Contact').href = "javascript: openWin(\"email.aspx?bn="+o.BusinessName.replace(/[\&]+/, '|')+"&em="+o.EmailAddress+"\",600,500,true);";
	//$('Hyperlink_Contact_Top').href = "javascript: openWin(\""+urlPages+"/email.aspx?bn="+o.BusinessName.replace(/[\&]+/, '|')+"&em="+o.EmailAddress+"\",600,500,true);"; //"javascript: $('txtMessage').value=''; showPanel('pnlContact'); $('txtName').focus();"// "mailto:" + o.EmailAddress;
	$('Hyperlink_Contact_Top').href = "javascript: openWin(\"email.aspx?bn="+o.BusinessName.replace(/[\&]+/, '|')+"&em="+o.EmailAddress+"\",600,500,true);";
	$('txtMessage').value = "";
	$('hiddenEmailAddress').value = o.EmailAddress;  
	$('lblStates').innerHTML = o.States//.split(",").join("<br>");
	//$('lblRegions').innerHTML = o.Regions.split(",").join("<br>");
	//alert(o.MemberDocId);
	$('showClinics').style.visibility = 'hidden';
	$('divLogo').innerHTML = "";
	
	//$('divLogo').style.background = "";
	if ( o.IsLogoExists==true )
	{
	  try
		{
			//do not allow the image to go over 150pixels
			//var scale = 150.0f / Math.Max(o.ImageHeight, o.ImageWidth);
			//var imgHeight = parseInt(o.ImageHeight) > 150 ? 150 : parseInt(o.ImageHeight);
			//var imgWidth = parseInt(o.ImageWidth) > 150 ? 150 : parseInt(o.ImageWidth);
			//$('divLogo').innerHTML = "<img src='../uploads/MEMBERSDOCID_" + o.MemberDocId + ".jpg' height='" + imgHeight + "' width='" + imgWidth + "'>";
			//$('divLogo').innerHTML = "<img src='../uploads/MEMBERSDOCID_THUMB_" + o.MemberDocId + ".jpg'>";
			$('divLogo').innerHTML = "<img src='" + o.ImagePath + "'>";
			
		}catch(ex){alert(ex);}
	}
	
	var ds = o.Addresses; //alert(ds.Tables[0].Rows.length);
	if(ds != null && typeof(ds) == "object" && ds.Tables != null && ds.Tables[0].Rows.length > 0 ){
		$('lblAddress1').innerHTML = ds.Tables[0].Rows[0].ADDRESS1;//.split(",").join("<br>");
		$('lblAddress2').style.display = 'inline';
		$('lblAddress3').style.display = 'inline';
		if ( ds.Tables[0].Rows[0].ADDRESS2.length > 0 )
		  $('lblAddress2').innerHTML = "<br>" + ds.Tables[0].Rows[0].ADDRESS2;//.split(",").join("<br>");
		else
		  $('lblAddress2').style.display = 'none';
		if (ds.Tables[0].Rows[0].ADDRESS3.length > 0)
		  $('lblAddress3').innerHTML = "<br>" + ds.Tables[0].Rows[0].ADDRESS3;//.split(",").join("<br>");
		else
		  $('lblAddress3').style.display = 'none';  
		$('lblSuburb').innerHTML = ds.Tables[0].Rows[0].SUBURB;		  	  
		$('lblPostCode').innerHTML = ds.Tables[0].Rows[0].POSTCODE;
		$('lblTelephone').innerHTML = ds.Tables[0].Rows[0].TELEPHONE;
		$('lblFax').innerHTML = ds.Tables[0].Rows[0].FAX;	
		$('lblMobile').innerHTML = ds.Tables[0].Rows[0].MOBILE;
		
		//build and format the therapists clinic information
		$('clinics').innerHTML = '';
		$('showClinics').style.display = 'none';
		if ( ds.Tables[0].Rows.length > 1 ){
		  $('showClinics').style.visibility = 'visible';
		  $('showClinics').style.display = 'inline';
		  var htm = '';
		  for (i = 0; i < ds.Tables[0].Rows.length; i++)
		  {
				if ( i > 0 ) htm += "<br>";
				htm += "<table width='100%' cellpadding='2' cellspacing='0' border='0' style='border: 1px solid #CCCCCC;'>";
				htm += "<tr><td colspan='2' class='app_heading' style='padding:3px 3px 3px 3px;'>Clinic " + (i+1) + "</td></tr>";
				htm += "<tr valign='top' align='left' class='bodycopy_bold'>";
				htm += "<td class='app_heading_ddi' width='55'>Address</td>";
				var add = ds.Tables[0].Rows[i].ADDRESS1;//.split(",").join("<br>");
				var add2 = ds.Tables[0].Rows[i].ADDRESS2.length > 0 ? "<br>" + ds.Tables[0].Rows[i].ADDRESS2 : "";
				var add3 = ds.Tables[0].Rows[i].ADDRESS3.length > 0 ? "<br>" + ds.Tables[0].Rows[i].ADDRESS3 : "";
				//alert(add.substring(add.length - 4))
				htm += "<td width='100%'>" + add //+ (add.substring(add.length - 4)=="<br>" ? "" : "<br>")
					+ add2
					+ add3
					+ "<br>" + ds.Tables[0].Rows[i].SUBURB
					+ "<br>" + ds.Tables[0].Rows[i].POSTCODE							
					+ "</td>"
					+ "</tr>";
				//htm += "<tr><td colspan='2'><hr style='height:1px; color:#D1D1D1; padding:0px;' /></td></tr>";
				htm += "<tr valign='top' class='bodycopy_bold'>"
					+ "	<td class='app_heading_ddi'>Phone</td>"
					+ "	<td>" + ds.Tables[0].Rows[i].TELEPHONE + "</td>"
					+ "</tr>";
				//htm += "<tr><td colspan='2'><hr style='height:1px; color:#D1D1D1; padding:0px;' /></td></tr>";
				htm += "<tr valign='top' class='bodycopy_bold'>"
					+ "	<td class='app_heading_ddi'>Fax</td>"
					+ "	<td>" + ds.Tables[0].Rows[i].FAX + "</td>"
					+ "</tr>";	
				//htm += "<tr><td colspan='2'><hr style='height:1px; color:#D1D1D1; padding:0px;' /></td></tr>";
				htm += "<tr valign='top' class='bodycopy_bold'>"
					+ "	<td class='app_heading_ddi'>Mobile</td>"
					+ "	<td>" + ds.Tables[0].Rows[i].MOBILE + "</td>"
					+ "</tr>";	
				htm += "</table><br>";
													
				//$('lblAddress1').innerHTML += "<br>" + ds.Tables[0].Rows[i].ADDRESS1.split(",").join("<br>");
		  }
		  if ( !MS.Browser.IE ) htm += "<br>";
		  $('clinics').innerHTML = htm;
		//alert(htm);
		}
	}
	else 
	{ 
		alert("Error. [3001] No Address table was returned."); 
	}
	/*ds = null;*/
	ds = o.OtherData; //alert(ds.Tables[0].Rows.length);
	if(ds != null && typeof(ds) == "object" && ds.Tables != null && ds.Tables[0].Rows.length > 0 ){
		$('hiddenMemberId').value =  ds.Tables[0].Rows[0].MEMBERID;
		if (ds.Tables[0].Rows[0].IMAGE2 == 1) {
			htm = "<table width='100%' border='0' cellpadding='0' cellspacing='0'>"
				+ "<tr><td><img src='../uploads/WEB_MEMBERSDOCID_" 
				+ ds.Tables[0].Rows[0].MEMBERDOCID + ".jpg' " 
				+ "style='float:left; padding: 0px 15px 15px 0px;' />" 
				+ ds.Tables[0].Rows[0].DESCRIPTION
				/*+ "</td><td>" + ds.Tables[0].Rows[0].DESCRIPTION */
				+ "</td></tr></table>";
				//alert(htm);
			}
		else {
			htm = ds.Tables[0].Rows[0].DESCRIPTION;
			}
		//$('divDescription').innerHTML = ds.Tables[0].Rows[0].DESCRIPTION;
		$('divDescription').innerHTML = htm;
		
		// allow long descriptions to be scrollable
		$('divDescription').style.overflow = 'auto';
		//$('divDescription').style.height = (o.IsLogoExists==true ? '450px' : '350px');//'400px';
		$('divDescription').style.padding = '3px 3px 3px 3px';
		//
		// manipulate the navigation buttons...
		//
		var url = ds.Tables[0].Rows[0].URL;
		var btn = $('WebText');//$('btnUrl');
		var hyp_top = $('Hyperlink_URL_Top');
		//var hyp = $('Hyperlink_URL');
		var hyp_web = $('pnlWeb'); 
		var hyp_hdr = $('WebHeader');
		var hyp_txt = $('WebText');
		var hyp_lne = $('WebLine');
		
		if (url.length > 0) url = url.substring(url.indexOf('URL=')+4, url.length);
		
		/**
		 *	determine if the member has a web url and display it.
		 */
		if ( hyp_web && hyp_hdr && hyp_txt && hyp_lne )
		{
			hyp_hdr.innerHTML = hyp_txt.innerHTML = hyp_lne.innerHTML = "";  
			hyp_web.style.display = 'none';
			
			if ( ds.Tables[0].Rows[0].URL.length > 0 )
			{ 
			  hyp_hdr.innerHTML = 'Web &nbsp;';
				hyp_txt.innerHTML = '<a href="'+ds.Tables[0].Rows[0].URL+'" target="_blank" class="bodycopy">'+unescape(url).replace(/http:\/\//, '')+'</a>';
				hyp_lne.innerHTML = line;//'<hr style='height:1px; color:#D1D1D1; padding:0px;' />'
				hyp_web.style.display = 'block';
			}
		}		
		/*
		//build and show a link to the therapists website
		if ( btn!=null )
		{
		  //btn.href = ds.Tables[0].Rows[0].URL;
			btn.innerHTML = '';
				
			hyp_web.style.display = 'none';
			alert(hyp_web.style.display);
			
		  if ( ds.Tables[0].Rows[0].URL.length > 0 ) {
				btn.innerHTML = '<a href="' +
						ds.Tables[0].Rows[0].URL +
						'" target="_blank" class="bodycopy">' +
						unescape(url).replace(/http:\/\//, '') +
						'</a>';
				//btn.innerHTML = unescape(url).replace(/http:\/\//, '');//o.BusinessName;//"<img src='../images/wi_logo.gif' border='0'>";// unescape(url);
				hyp_web.style.display = 'block';
				alert(hyp_web.style.display);				
			}
		//else btn.innerHTML = "&laquo; None &raquo;";
		}
		*/
		/**
		 *	build and show a link button to the therapists website		
		 */
		if ( hyp_top ) //!=null )//&& hyp!=null ) 
		{
		  	//hyp.style.display = 'none';
			hyp_top.style.display = 'none';//alert(hyp_web.style.display);
			//hyp_web.style.display = 'none';
			
			if ( ds.Tables[0].Rows[0].URL!="undefined" && ds.Tables[0].Rows[0].URL!="" )
			{
				//hyp.href = ds.Tables[0].Rows[0].URL;
				hyp_top.style.display = 'inline';
				//hyp_web.style.display = 'inline';
				hyp_top.href = ds.Tables[0].Rows[0].URL;
			}
		}	
		
		// display the Registered details
		var pnl = $('pnlRegistered');
		var hdr = $('MemberHeader');
		var txt = $('MemberText');
		var lne = $('MemberLine');
		if ( pnl && hdr && txt && lne )
		{
			hdr.innerHTML = txt.innerHTML = lne.innerHTML = "";  
			pnl.style.display = 'none';
			
			if ( Boolean(ds.Tables[0].Rows[0].Registered) == true )
			{ 
			  hdr.innerHTML = 'Memberships &nbsp;';
				txt.innerHTML = ds.Tables[0].Rows[0].RegisterDetails;
				lne.innerHTML = line;//'<hr style='height:1px; color:#D1D1D1; padding:0px;' />'
				pnl.style.display = 'block';
			}
		}
		
		// call the displayElement after a tiny wait to allow page to be
		// fully loaded, passing it the result of the findPos to get
		// the top of one of the buttons on the bottom of the page 
		// so we know how far we need to grow the element 
		window.setTimeout("displayElement('ControlPanel', findPos($('Hyperlink_BackPage'))[1])", 5);
	}
	else 
	{ 
		alert("Error. [3001] No OtherData table was returned."); 
	}		

	if (MS.Browser.IE) $('ControlPanelText').filters[0].play();
}
//-->
