/**
 * Returns the browser viewpoint to the top of the page.
 * @return
 */
function backToTop() {
	window.scrollTo(0,0); 
	return false;
}

/**
 * Prints text to the page.
 * @param text the text to print
 * @return
 */

function __echo(text) {
	document.write(text);
}

/**
 * Prints an obfuscated email address.
 * @param anchor the anchor to use for the mailto link
 * @return void
 */
function printEmail(anchor) {
	__echo("<a href='mai");
	__echo("lto");
	__echo(":info");
	__echo("@s");
	__echo("outheastweb");
	__echo("development.com' title='Email Me'>");
	__echo(anchor);
	__echo("</a>");
}


/**
 * Validates an email address.
 * @param strng
 * @return string
 */
function checkEmail (strng) {
	
	var error="";
	if (strng == "") {
	   error = "You didn't enter an email address.\n";
	}

	    var emailFilter=/^.+@.+\..{2,3}$/;
	    if (!(emailFilter.test(strng))) { 
	       error = "Please enter a valid email address.\n";
	    }
	    else {
	//test email for illegal characters
	       var illegalChars= /[\(\)\<\>\,\;\:\\\"\[\]]/;
	         if (strng.match(illegalChars)) {
	          error = "The email address contains illegal characters.\n";
	       }
	    }
	return error;    
	}


/**
 * Validates a phone number.
 * @param strng
 * @return string
 */
function checkPhone (strng) {
	var error = "";
	if (strng == "") {
	   error = "Please enter a valid phone number.\n";
	}

	var stripped = strng.replace(/[\(\)\.\-\ ]/g, ''); //strip out acceptable non-numeric characters
	    if (isNaN(parseInt(stripped))) {
	       error = "Please enter a valid phone number.\n";
	  
	    }
	    //if (!(stripped.length == 10)) {
		//error = "The phone number is the wrong length. Make sure you included an area code.\n";
	    //} 
	return error;
	}

/**
 * Validates the existence of a contact name.
 * @param strng
 * @return string
 */
function checkName(strng) {
	var error = "";
	if (strng == "") {
	   error = "Please enter a contact name.\n";
	}
	return error;
}

/**
 * Validates the existence of a message.
 * @param strng
 * @return string
 */
function checkMessage(strng) {
	var error = "";
	if (strng == "") {
	   error = "Please enter a message.\n";
	}
	return error;
}

/**
 * Validates the non-existence of a field.
 * @param strng
 * @return string
 */
function isEmpty(strng) {
	var error = "";
	if (strng != "") {
	   error = "This field should be empty.\n";
	}
	return error;
}

/**
 * Validates a form.
 * @param theForm
 * @return boolean
 */
function validateForm(theForm) {
    var why = "";
    why += checkName(theForm.contact_name.value);
    why += checkEmail(theForm.contact_email.value);
    why += checkPhone(theForm.contact_phone.value);
    why += checkMessage(theForm.contact_enquiry.value);
    why += isEmpty(theForm.email.value);
    why += isEmpty(theForm.comment.value);
    //why += isDifferent(theForm.different.value);
    if (why != "") {
       alert(why);
       return false;
    }
return true;
}


/**
 * Function to load preview-sized image in preview panel from thumbnail.
 * Copyright Felicity Properties.
 * @return boolean
 */
function changePreviewTo(img) {
	var img_href = 'images/alice-court-4/alice-court-4-' + img + '_preview.jpg';
	document.getElementById('alice_preview').src = img_href;
	//window.location = '#previewtop'; 
	return false;
}

/**
 * Function to redirect browser to a full-sized version of a preview image.
 * Copyright Felicity Properties.
 * @return void
 */
function viewFullImage() {
	var img_href = document.getElementById('alice_preview').src;
	img_href = img_href.replace('_preview', '');
	window.location = img_href; 
}



/**
 * Highlights form fields on focus.
 */
var highlightcolor="#99CCFF";
var highlightcolor = '#333';
var ns6=document.getElementById&&!document.all;
var previous='';
var eventobj;
var intended=/INPUT|TEXTAREA|SELECT|OPTION/;

/**
 * Just focuses cursor on the first form field for the contact form page.
 * @return
 */
function init() {
	if (document.getElementById('contact_form')) {
		document.getElementById('contact_form').contact_name.focus();
		//document.getElementById('contact_form').contact_name.style.backgroundColor = highlightcolor;
	}
}

/**
 * Checks an element to highlight.
 * @param which the element
 * @return boolean
 */
function checkel(which){
	if (which.style&&intended.test(which.tagName)){
	if (ns6&&eventobj.nodeType==3)
		eventobj=eventobj.parentNode.parentNode;
	return true;
}
	else
		return false;
}

/**
 * Highlights an element.
 * @param e the element to highlight
 * @return
 */
function highlight(e){
	eventobj=ns6? e.target : event.srcElement
	if (previous!='') {
		if (checkel(previous)) 
			previous.style.backgroundColor='';
			previous=eventobj;
		if (checkel(eventobj))
			eventobj.style.backgroundColor=highlightcolor;
	}
	else{
		if (checkel(eventobj))
			eventobj.style.backgroundColor=highlightcolor;
			previous=eventobj;
		}
}






