
function openWindow(address, width, height,features)
{
	/* Find out what features need to be enable
	 *
   */
	if(features)
		features = features.toLowerCase();
	else
		features = "";

	var toolbar = (features == "all" ? 1 : 0);
	var menubar = (features == "all" ? 1 : 0);
	var location = (features == "all" ? 1 : 0);
	var directories = (features == "all" ? 1 : 0);
	var status = (features == "all" ? 1 : 0);
	var scrollbars = (features == "all" ? 1 : 0);
	var resizable = (features == "all" ? 1 : 0);


	if(features != "all")
	{
		//split features
		var feature = features.split(",");
		for(i = 0; i < feature.length; i++)
		{
		 	if(feature[i] == "toolbar")
			   toolbar = 1;
			else if(feature[i] == "menubar")
			   menubar = 1;
			else if(feature[i] == "location")
			   location = 1;
			else if(feature[i] == "directories")
			   directories = 1;
			else if(feature[i] == "status")
			   status = 1;
			else if(feature[i] == "scrollbars")
			   scrollbars = 1;
			else if(feature[i] == "resizable")
			   resizable = 1;
		}

	}
	features = "toolbar=" + toolbar + ",";
	features += "menubar=" + menubar + ",";
	features += "location=" + location + ",";
	features += "directories=" + directories + ",";
	features += "status=" + status + ",";
	features += "scrollbars=" + scrollbars + ",";
	features += "resizable=" + resizable;

	var newWindow = window.open(address, 'Popup_Window', 'width=' + width + ',height=' + height + ',"' + features + '"');
	newWindow.focus();
}

// Function for print screen
$(function() {

	$(".print").click(function(){
		window.print()
	});

});


// Function for moving between fields for telephone number
$(function() {
			
	var fields = $(".phone-num");
	
	var totalFields = fields.length;
	
	for (i=0; i<totalFields; i++) {
		// add event to input boxes
		fields[i].onkeyup = checkLen;
	}
	function checkLen()
	{
		var inputVal = this.value.length;
		var x = 0;
		// compare max length to actual
		if (inputVal==this.maxLength)
		{
			// using input name to determine current location
			var inputName = this.name;
			
			// patterns
			var patternAreaCode = /phoneAreaCode/i;
			var patternPhoneExchange = /phoneExchange/i;
			var patternPhoneLocal = /phoneLocal/i;
			var patternEvening = /evening/i;
			
			// using reg expressions on the input name to move the focus to the next field
			var resultAreaCode = patternAreaCode.test(inputName);
			var resultPhoneExchange = patternPhoneExchange.test(inputName);
			var resultPhoneLocal = patternPhoneLocal.test(inputName);
			var resultEvening = patternEvening.test(inputName);
			
			
			// had to determine if the field was evening phone number of not in order to move to the correct location
			if(resultEvening) {

				if(resultAreaCode) {
						fields[5].focus();
				}
				else if (resultPhoneExchange) {
						fields[6].focus();
				}			
			}
			else {
				
				if(resultAreaCode) {
						fields[1].focus();
				}
				else if (resultPhoneExchange) {
						fields[2].focus();
				}
				else if(resultPhoneLocal) {
						fields[3].focus();
				}
			}
				
		}
	}		
});

