var domain = 'melandmaryscottages';

function setup() {
// Opens external links in a new window
	if (!document.getElementsByTagName) return;
	var anchors = document.getElementsByTagName("a");
	for (var i=0; i<anchors.length; i++) {
		var URLs = anchors[i].href;
		if (URLs.search(domain)===-1) anchors[i].target = "_blank";
	}
// If the visitor has JS enabled, the "Email this Page" link will be displayed
	if (document.getElementById('JSCheck1')) document.getElementById('JSCheck1').style.visibility = 'visible';

// Reconstructs Email a Friend link
	if (document.getElementById('URL')) {
		var temp = window.location + '';
		temp = temp.substring(temp.indexOf('page=')+5);
		document.getElementById('URL').value = 'www.melandmaryscottages.com/' + temp + '.php';
	}
}

// Compiles the Email a Friend email
function compile() {
	if (document.getElementById('From').value==='' || document.getElementById('To').value==='' || document.getElementById('Your_Email').value==='' || document.getElementById('Rec_Email').value==='') {
		alert('Please complete the entire form in order to continue');
	} else {
		var yourName = document.getElementById('From').value;
		var recName = document.getElementById('To').value;
		var preview = 'Dear ' + recName + ', \n\n';
		preview += yourName + ' would like to share the following page from the Mel and Mary\'s Cottages Web site with you: \n\n';
		preview += document.getElementById('URL').value + ' \n\n';
		preview += 'We hope you enjoy our site! \n\n';
		preview += 'Sincerely, Mel and Mary';
		document.getElementById('preview').value = preview;
		document.getElementById('config').value = 'yes2';
		document.getElementById('butPreview').value = 'Update Info';
		document.getElementById('showPreview').style.display = 'block';
		document.getElementById('subject').value = yourName + ' has a message for you';
	}
}

// Completes the circuit necessary to use contact forms on the site, spam-reducer
function connect(foo) {
	document.getElementById('config').innerHTML = '<input type="hidden" name="config" value="' + foo + '" />';
}
	
// Simple popup script that opens a no-frills window
function pop(file,wide,high) {
	window.open(file,'popup','toolbar=no,location=no,directories=no,status=no,menubar=no,scrollbars=auto,resizable=yes,copyhistory=no,width='+wide+',height='+high)
}

// Triggers the setup script
window.onload = setup;