/****************************************
Dynamic vCard for No Header Profile Layout
****************************************/

// AJAX function
function ajaxFunction() { var xmlHttp; try { xmlHttp=new XMLHttpRequest(); } catch (e) { try { xmlHttp=new ActiveXObject("Msxml2.XMLHTTP"); } catch (e) { try { xmlHttp=new ActiveXObject("Microsoft.XMLHTTP"); } catch (e) { alert("Your browser does not support AJAX!"); return false; } } } return xmlHttp; }

// vCard Javascript
function vCard(vcf){ if (window.confirm("A VCard is a way of saving this person's information to your local email address book. \n\n If you have Outlook 2000, Groupwise 5.5, or Outlook Express 5, click OK, then select Download File from Current Location. \n\nThen follow your email program instructions to add the data to your address book.")) window.location = vcf; }

// Get vCard
function getVCard() {
	// Global vars
	var d = document, tbl, row, cell1, cell2, vCard = ajaxFunction(), name = window.location.href.split('../index.html'), get = function(i) { return d.getElementById(i); }, create = function(e) { return d.createElement(e); };
	
	// Get supposed file name (based on file name)
	name = name[name.length - 1].split('.')[0];
	
	// AJAX check to see if file exists
	vCard.onreadystatechange = function() {
		if(vCard.readyState==4) {
			// vCard Creation
			if(vCard.status != 404) {
				tbl = get('content'); tbl = tbl.getElementsByTagName('table')[0].className == 'InternetExplorerFix' ? tbl.getElementsByTagName('table')[0] : tbl; tbl = tbl.getElementsByTagName('table')[0].childNodes[0];
				row = create('tr'); cell1 = create('td'); cell2 = create('td');
				cell1.innerHTML = '<span class="profilecommtexthdr">vCard</span>';
				cell2.innerHTML = '<a id="VCardURL" href="javascript:vCard(\'/CM/Docs/Vcard/' + name + '.vcf\')"><img alt="Add contact information to your vCard compatible address book." src="/Includes/Templates/Active/images/vcard.gif" border="0"></a>';
				row.appendChild(cell1); row.appendChild(cell2); tbl.appendChild(row);
			}
		}
	}
	
	// Fetch vCard
	vCard.open('http://admin.tashpad1.lawoffice.com/Bio/GET','/CM/Docs/Vcard/' + name + '.vcf',true);
	vCard.send(null);
}

getVCard();
