
var request;
ajaxFunction();

function resetForm() {
if (document.getElementById("username").value == "") {
	document.getElementById("username").value = "Username";
}
if (document.getElementById("password").value == "") {
	document.getElementById("password").type = "text";
	document.getElementById("password").value = "Password";
}
}

function loginFocus() {
if (document.getElementById("username").value == "Username"){
	document.getElementById("username").value = "";
	}

if (document.getElementById("password").value == "") {
	document.getElementById("password").type = "text";
	document.getElementById("password").value = "Password";
}

}
function passwordFocus() {
	if (document.getElementById("password").value == "Password") {
		document.getElementById("password").value = "";
		document.getElementById("password").type = "password";
	}

	
	if (document.getElementById("username").value == "")
		document.getElementById("username").value = "Username";
}

function submitLogin() {
	var username = document.getElementById("username").value;
	var password = document.getElementById("password").value;
	document.getElementById("username").value = "Username";
	document.getElementById("password").type = "text";
	document.getElementById("password").value = "Password";
	var params = "username=" + username + "&password=" + password;
	request.open("POST", "checkLogin.php", true);
	request.onreadystatechange = confirmLogin;
	request.setRequestHeader("Content-type", "application/x-www-form-urlencoded");
	request.send(params);
}

function confirmLogin() {
	if (request.readyState == 4) {
		if (request.status == 200) {
			alert(request.responseText);
		}
	}	
}

function ajaxFunction() {
	try {
		request = new XMLHttpRequest();
	}
	catch (e) {
		try {
			request = new ActiveXObject("Msxml2.XMLHTTP");
		}
		catch (e) {
			try {
				request = new ActiveXObject("Microsoft.XMLHTTP");
			}
			catch (e) {
				alert("Your browser doesn't support AJAX!");
				return false;
			}
		}
	}
}

function firstpiccss(dog) {
	var css = "<style type=\"text/css\">#gallery {background:transparent url(../photos/" + dog + ".jpg) 125px 0 no-repeat;}</style>";

return css;
}

function picpop(pic)
{
	var filename = "../photos/" + pic + ".jpg";
	var args="";
	var wdth = document.images[pic].width;
	var ht = document.images[pic].height;
	args += "\'location=no,menupar=no,width=" + wdth + ", height=" + ht + ",toolbar=no," + "left=350," + "top=100\'";
	window.open(filename, pic, args);
}

function picopen(pic, wdth, ht)
{
var filename = "photos/photos/" + pic + ".jpg";
var args = "'location=no,menupar=no,width=" + wdth + ",height=" + ht + ",toolbar=no,left=350,top=100'";
window.open(filename, pic, args);
}

function validate() {
var firstname = trim(document.visitor.firstname.value);
var lastname = trim(document.visitor.lastname.value);
var phone = trim(document.visitor.phone.value);
var email = trim(document.visitor.email.value);
var apos = email.indexOf("@");
var dotpos = email.lastIndexOf(".");
var zip = trim(document.visitor.zipcode.value);
var zipchk = parseFloat(zip).toString();

if (!firstname | firstname.match(/[0-9\W]/))  // check first name
{ alert('Please enter a valid first name.'); 
document.visitor.firstname.focus(); return false;}
if (!lastname | lastname.match(/[0-9\W]/))  //check last name
{ alert('Please enter your last name.');  
document.visitor.lastname.focus(); return false;}
if (!phone || !phonechk(phone))
{ alert('Please enter a valid phone number.');  
document.visitor.phone.focus(); return false;}
if (apos < 1 || (dotpos - apos) < 2)  //check email
{ alert('Please enter a valid email address.');  
document.visitor.email.focus(); return false;}
if (zip) {  //check zipcode (if exists)
	if (zipchk.length != zip.length || zipchk == "NaN" || zipchk.length !=5)
	{ alert('Please enter a valid zipcode.');  
document.visitor.zipcode.focus(); return false;}
}
}

function trim(s)
{
var returnString = "";
var i; var c;
for (i=0; i<s.length; i++) {
c = s.charAt(i); if (c != " " && c!="(" && c!=")" && c!="-") {returnString += c;} } return returnString;
}

function phonechk(num)
{
var i; var c;
for (i=0; i<num.length; i++)
{ c = num.charAt(i); if (((c < "0") || (c > "9"))) {return false;} }
if (num.length != 10) {return false;}
return true;
}
