var NOT_NULL = 0;
var EMAIL = 1;
var defaultInputBorderStyle = null;

var formTypes = {	yourName:NOT_NULL,
									yourEmail:EMAIL,
									yourSubject:NOT_NULL,
									yourMessage:NOT_NULL
								};	

function verifyForm(form){
	if(defaultInputBorderStyle == null)
		defaultInputBorderStyle = form.elements[0].style.border;
	var invalidFields = new Array();
	var pattern;
	for(field in formTypes){
		switch (formTypes[field]){
		case NOT_NULL:
			pattern = /.+/;
			break;
		case EMAIL:
			pattern = /[\w-]+@[\w-]+\.[a-z]{2,}/;
			break;
		}
		if(form[field].value.match(pattern) == null){
			invalidFields.push(form[field]);
			form[field].style.border = "1px solid #ff3300";
		}
		else
			form[field].style.border = defaultInputBorderStyle;
	}
	if(invalidFields.length > 0){
		var msg = ""
		if(invalidFields.length > 1)
			msg += formValidationErrorMessage.many + ":\n";
		else
			msg += formValidationErrorMessage.one + ":\n";
		for(var i=0; i<invalidFields.length; i++)
			msg += '\n'+invalidFields[i].previousSibling.firstChild.nodeValue;
		alert(msg);
		invalidFields[0].focus();
		invalidFields[0].select();
		return false;
	}else{
		jsSwitch = document.getElementById('jsSwitch');
		return true;
	}
}

var pane;
function showLargeType(caller){
	var data = caller.nextSibling.firstChild.nodeValue;
	var clientWidth = isIE()? document.body.clientWidth : window.innerWidth;
	var body = document.getElementsByTagName('body')[0];
	pane = document.createElement('div');
	pane.setAttribute('id','LargeType');
	var text = document.createTextNode(data);
	pane.appendChild(text);
	body.appendChild(pane);
	var fontSizes = new Array(48,64,72,96,144,288);
	for(var i=0; i<fontSizes.length; i++){
		pane.style.fontSize = fontSizes[i]+'px';
		if(pane.offsetWidth > clientWidth){
			pane.style.fontSize = fontSizes[i-1]+'px';
			break;
		}
	}
	pane.style.marginLeft = '-' + pane.offsetWidth/2 + 'px';
	pane.style.marginTop = '-' + pane.offsetHeight/2 + 'px';
	pane.style.visibility = 'visible';
	body.addEventListener('click', hideLargeType, true);
}

function hideLargeType(){
	document.body.removeChild(pane);
	document.body.removeEventListener('click', hideLargeType, true);
}

function sentWithSuccess(){
	alert("Thank you for contacting us!\n\nYour message has been sent successfully.");
}

function sentWithError(){
	alert("Thank you for wanting to contact us!\n\nUnfortunately, there seems to be a technical failure.\nYour message could not be sent.");
}
