// JavaScript Document
addthis_pub  = 'topmic';

function popup(src) {
win=window.open(src,"","top=20,left=20,height=300,width=450,toolbar=no,location=no,directories=no,status=no,menubar=no,scrollbars=yes,resizable=yes");
}

function winPrint(url){
newWin=window.open(url,'','height=800,width=800,toolbar=no,location=yes,directories=no,status=no,menubar=no,scrollbars=yes,copyhistory=no,resizable=yes');
newWin.focus();
newWin.print();
}

function hide_price_table()
{
	var url = window.location.href;
	var pos=url.lastIndexOf('?price=');
	
	var pricetable_array=new Array("0-2","2-4","4-8","8-10","10-20","20-50","50-100","100-200","200-400","400");
	for(i=0; i<pricetable_array.length; i++)
	{
		var table = document.getElementById(pricetable_array[i]);
		
		if(table!=null)
		{
			table.style.display='none';
		}
	}
	
	if(pos!=-1)
	{
		var name=url.substring(pos+7);
		var table=document.getElementById(name);
		table.style.display='';
	}
	
	var div_tag = document.getElementById('price-tables');
	div_tag.style.display='';
}

function formValidator(){
	// Make quick references to our fields
	var firstname = document.getElementById('firstname');
    var lastname = document.getElementById('lastname');
	var email = document.getElementById('email');
	var comments = document.getElementById('comments');

	// Check each input in the order that it appears in the form!
	if(isEmpty(firstname, "Please enter your name")){
					//	if(isEmpty(lastname, "Please enter your last name"))
						{
							if(emailValidator(email, "Please enter a valid email address"))
							{	
								if(isEmpty(comments, "Please enter your questions or comments"))
								{
									alert("Thank you! We have received your message and will reply promptly.");
								return true;
								}
							}
						}
	}
		
	return false;
	
}

function isEmpty(elem, helperMsg){
	if(elem.value.length == 0){
		alert(helperMsg);
		elem.focus(); // set the focus to this input
		return false;
	}
	return true;
}

function isNumeric(elem, helperMsg){
	var numericExpression = /^[0-9]+$/;
	if(elem.value.match(numericExpression)){
		return true;
	}else{
		alert(helperMsg);
		elem.focus();
		return false;
	}
}

function isAlphabet(elem, helperMsg){
	var alphaExp = /^[a-zA-Z]+$/;
	if(elem.value.match(alphaExp)){
		return true;
	}else{
		alert(helperMsg);
		elem.focus();
		return false;
	}
}

function isAlphanumeric(elem, helperMsg){
	var alphaExp = /^[0-9a-zA-Z]+$/;
	if(elem.value.match(alphaExp)){
		return true;
	}else{
		alert(helperMsg);
		elem.focus();
		return false;
	}
}

function lengthRestriction(elem, min, max){
	var uInput = elem.value;
	if(uInput.length >= min && uInput.length <= max){
		return true;
	}else{
		alert("Please enter between " +min+ " and " +max+ " characters");
		elem.focus();
		return false;
	}
}

function madeSelection(elem, helperMsg){
	if(elem.value == "Please Choose"){
		alert(helperMsg);
		elem.focus();
		return false;
	}else{
		return true;
	}
}

function emailValidator(elem, helperMsg){
	var emailExp = /^[\w\-\.\+]+\@[a-zA-Z0-9\.\-]+\.[a-zA-z0-9]{2,4}$/;
	if(elem.value.match(emailExp)){
		return true;
	}else{
		alert(helperMsg);
		elem.focus();
		return false;
	}
}

function printdate()
{
	var date = new Date();
var d  = date.getDate();
var day = (d < 10) ? '0' + d : d;
var m = date.getMonth() + 1;
var month = (m < 10) ? '' + m : m;
var yy = date.getYear();
var year = (yy < 1000) ? yy + 1900 : yy;
document.write(month + "/" + day + "/" + "08");

}

