// Created for Mark Holtzman of Photo Pilot - All Rights Reserved
// Created by Scott Haines of Newfront Productions

var idArr = new Array("name","email","phone","longitude","latitude","address","description","infoextra");
var passed = true;
var theMessage = '';
function checkForm(id){
	theMessage = '';
	passed = true;
	var theMail = document.getElementById(id);
	// do check
	var theName = document.getElementById("name").value;
	var theEmail = document.getElementById("email").value;
	var thePhone = document.getElementById("phone").value;
	var theLong = document.getElementById("longitude").value;
	var theLat = document.getElementById("latitude").value;
	var theAddress = document.getElementById("address").value;
	var theDesc = document.getElementById("description").value;
	var theXtraInfo = document.getElementById("infoextra").value;
	
	// check the name
	if(theName.length <= 1){
		theMessage = theMessage + 'Problem with Name input: Please add a name.<br>';
		passed = false;
	}
	if(theName == "your name"){
		theMessage = theMessage + 'Please add your name. This is the default name.<br>';
		passed = false;
	}
	if(theEmail.length <= 1){
		theMessage = theMessage + 'Problem with Email input: Please add an email.<br>';
		passed = false;
	}
	if(theEmail == "your email"){
		theMessage = theMessage + 'Please add your email. This is just the description.<br>';
		passed = false;
	}
	// check for real email pattern
	var theAmp = theEmail.indexOf('@');
	var thePeriod = theEmail.indexOf('.');
	if(theAmp != -1 && theAmp != 1 && thePeriod != -1 && thePeriod != 1){
		// we know it is the correct format
	} else {
		passed = false;
		theMessage = theMessage + 'Problem with your Email: The Email needs to be in a correct format.<br>';
	}
	//
	if(thePhone.length <= 1){
		theMessage = theMessage + 'Problem with your Phone Number: Please add your number.<br>';
		passed = false;
	}
	if(thePhone == "your phone number"){
		theMessage = theMessage + 'Please add your Phone Number';
		passed = false;
	}
	//
	if(theLong.length <= 1){
		theMessage = theMessage + "Please search for your location again: The Longitude has been lost.<br>";
		passed = false;
	}
	if(theLat.length  <= 1){
		theMessage = theMessage + "Please search for your location again: The Latitude has been lost.<br>";
		passed = false;
	}
	if(passed == true){
		var theErr = document.getElementById("error");
		if(theErr.style.display = "block"){
			theErr.style.display = "none";
			theErr.innerHTML = "";
		}
		theMail.submit();
	}
	if(passed == false){
		var theErr = document.getElementById("error");
		theErr.style.display = "block";
		theErr.style.color = "#ff0000";
		theErr.innerHTML = theMessage;
		theErr.style.position = "relative";
	}
	
}

function checkheader(){
	if(window.location.search){
	var windowText = window.location.search.substring(1);
		if(windowText == "sentmail"){
			var thePlace = document.getElementById("error");
			thePlace.style.color = "#00FF00";
	 		if(thePlace.style.display == "none"){
				thePlace.style.display = "block";
			}
			thePlace.innerHTML = "Mail Sent Successfully";
		}
	}
}