var url = document.URL;
var filename = url.substring(url.lastIndexOf("\/")+1,url.length,10);
var newwindow;


function view(url)
{

	newwindow=window.open(url,'PictureViewer','height=700,width=855,left=150,resizable=yes,status=yes,scrollbars=yes');
	if (window.focus) {newwindow.focus()}
}

function pic_submit( imagenum, formnum, location )
{
	if (formnum == null)
		formnum = 0;
	with (document.forms[formnum+1])
	{
		var loc = document.images[imagenum+parseInt(low.value)+3].src;
		if (loc.match("s.jp"))
		{
			src.value = (location == null) ? loc.replace("s.jp",".jp") : "images/" + location + ".jpg";
		} else {
			src.value = (location == null) ? document.images[imagenum+parseInt(low.value)+3].src : "images/" + location + ".jpg";
		}
		caption.value = document.images[imagenum+parseInt(low.value)+3].alt;
		submit();
	}

}

function checkName(strng)
{
	var error = "";
	var illegalChars = /[^\w\s-']/;
	
	if (strng == "")
	{
		error = "You didn't enter a name.\n";
    } else if ((strng.length < 3) || (strng.length > 22)) {
    	error = "The name is the wrong length.\n";
    } else if (illegalChars.test(strng))
    {
    	error = "The name contains illegal characters.\n";
    }
    return error;
}

function checkPassword(strng)
{
	var error = "";
    return error;
}

function checkNewPassword(strng)
{
	var error = "";
	var illegalChars = /[\W_]/;
	if (strng == "" || strng == null)
	{
		error = "You didn't enter a password.\n";
	} else if ((strng.length < 6) || (strng.length > 12))
    {
    	error = "The password is the wrong length.\n";
    }
    else if (illegalChars.test(strng))
    {
    	error = "The password contains illegal characters.\n";
    }
    else if (!((strng.search(/[a-z]+/i) > -1)
    	&& (strng.search(/[0-9]+/) > -1)))
    {
    	error = "The password must contain at least one letter and one numeral.\n";
    }
    return error;
}

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

function checkTitle(strng)
{
	var error = "";
	if (strng.length == 0)
	{
		error = "You didn't enter a Title.\n";
	}
    return error;
}

function checkMessage(strng)
{
	var error = "";
	if (strng.length == 0)
	{
		error = "You didn't enter a Message.\n";
	}
    return error;
}

function checkLogin(theForm)
{
    var why = "";
    why += checkEmail(theForm.email.value);
    why += checkPassword(theForm.password.value);
    
    if (why != "")
    {
       alert(why);
       return false;
    }
	return true;
}

function checkChangePass(theForm)
{
    var why = "";
    why += checkName(theForm.name.value);
    why += checkEmail(theForm.email.value);
    
    if (why != "")
    {
    	why+= "\nIf you are still having trouble accessing your account,\n email sandlund@familywheatens.com for assistance.\n";
       alert(why);
       return false;
    }
	return true;
}

function checkSignup(theForm)
{
    var why = "";
    why += checkName(theForm.name.value);
    why += checkEmail(theForm.email.value);
    why += checkNewPassword(theForm.password.value);
        
    if (why != "")
    {
       alert(why);
       return false;
    }
	return true;
}

function checkPost(theForm)
{
    var why = "";
    why += checkTitle(theForm.title.value);
    why += checkMessage(theForm.message.value);
    
    if (why != "")
    {
       alert(why);
       return false;
    }
	return true;
}


function fixH(one,two) {
	if (document.getElementById(one)) {
	var lh=document.getElementById(one).offsetHeight;
	var rh=document.getElementById(two).offsetHeight;
	var nh = Math.max(lh, rh);
	document.getElementById(one).style.height=nh+"px";
	document.getElementById(two).style.height=nh+"px";
	}
}


window.onload=function(){
	fixH('update','content');
	if (filename == "wheatens.php" || filename == "puppies.php")
	{
		cyclePics();
	} else if (filename.substring(0, 18) == "picture-viewer.php" )
	{
		initializePic();
	}
}