// JavaScript Document

var errors = "";
var valid = true;



	function chracterCounter()
	{

		if (document.frmUpload.txtDescription.value.length > 50)
		{
			alert("Maximum of 50 characters!");
		}

		
	}



	function submitInterested()
		
		{
			
			

			
			if (document.frmUpload.txtFirstName.value == '')
				{
					errors = errors + "You must supply your First Name\n";
					valid = false;
				}
				
			if (document.frmUpload.txtSurname.value == '')
				{
					errors = errors + "You must supply your Last Name\n";
					valid = false;
				}
				
			if (document.frmUpload.txtEmail.value == '')
				{
					errors = errors + "You must supply your Email Address\n";
					valid = false;
				}
			else
				{
					var x = document.frmUpload.txtEmail.value;
					var filter  = /^([a-zA-Z0-9_\.\-])+\@(([a-zA-Z0-9\-])+\.)+([a-zA-Z0-9]{2,4})+$/;
					if (filter.test(x))
						{
							valid = true;
						}
						else
						{
						valid = false;
						errors = errors + "You must supply a valid Email Address\n";
						}
				}
				
				
			if (document.frmUpload.lstCountry.value == '')
				{
					errors = errors + "You must supply your Country\n";
					valid = false;
				}
				
			if (errors != "")
				{
					alert('There was a problem with your details.\n\n' + errors);
					errors = "";
				}
				else
				{
					document.frmUpload.submit()
					
				}
				
		}





	function submitSendPostcard()
	{
		
			if (document.frmsendpostcard.txtYourName.value == '')
				{
					errors = errors + "You must supply your Name\n";
					valid = false;
				}
				
				
			if (document.frmsendpostcard.txtYourSurname.value == '')
				{
					errors = errors + "You must supply your Surname\n";
					valid = false;
				}

			if ( document.frmsendpostcard.chkOriginal.checked == false )
			{
				errors = errors + "You must agree to the Terms & Conditions before submitting.";
				valid = false;
			}				

			if (document.frmsendpostcard.txtYourEmail.value == '')
				{
					errors = errors + "You must supply your Email Address\n";
					valid = false;
				}
			else
				{
					var x = document.frmsendpostcard.txtYourEmail.value;
					var filter  = /^([a-zA-Z0-9_\.\-])+\@(([a-zA-Z0-9\-])+\.)+([a-zA-Z0-9]{2,4})+$/;
					if (filter.test(x))
						{
							valid = true;
						}
						else
						{
						valid = false;
						errors = errors + "You must supply a valid Email Address\n";
						}
				}
		
		
		
			if (document.frmsendpostcard.txtFriendsName.value == '')
				{
					errors = errors + "You must supply your Friends Name\n";
					valid = false;
				}
				
			if (document.frmsendpostcard.txtFriendsSurname.value == '')
				{
					errors = errors + "You must supply your Friends Surname\n";
					valid = false;
				}
				
			if (document.frmsendpostcard.txtFriendsEmail.value == '')
				{
					errors = errors + "You must supply your Friends Email Address\n";
					valid = false;
				}
			else
				{
					var x = document.frmsendpostcard.txtFriendsEmail.value;
					var filter  = /^([a-zA-Z0-9_\.\-])+\@(([a-zA-Z0-9\-])+\.)+([a-zA-Z0-9]{2,4})+$/;
					if (filter.test(x))
						{
							//valid = true;
						}
						else
						{
						valid = false;
						errors = errors + "You must supply a valid Email Address\n";
						}
				}
		

			if (document.frmsendpostcard.txtYourMessage.value == '')
				{
					errors = errors + "You must supply a Message\n";
					valid = false;
				}



		
			if (errors != "")
				{
					alert('There was a problem with your details.\n\n' + errors);
					errors = "";
					return false;
				}
				else
				{
					return true;
					//document.frmsendpostcard.submit()
				}
				
				
				
		
	}









	function submitPostcardForm()
	{




			if (document.frmUpload.txtFirstName.value == '')
				{
					errors = errors + "You must supply your First Name\n";
					valid = false;
				}
				
			if (document.frmUpload.txtSurname.value == '')
				{
					errors = errors + "You must supply your Last Name\n";
					valid = false;
				}
				
			if (document.frmUpload.txtEmail.value == '')
				{
					errors = errors + "You must supply your Email Address\n";
					valid = false;
				}
			else
				{
					var x = document.frmUpload.txtEmail.value;
					var filter  = /^([a-zA-Z0-9_\.\-])+\@(([a-zA-Z0-9\-])+\.)+([a-zA-Z0-9]{2,4})+$/;
					if (filter.test(x))
						{
							valid = true;
						}
						else
						{
						valid = false;
						errors = errors + "You must supply a valid Email Address\n";
						}
				}
				
				
			if (document.frmUpload.txtAddress1.value == '')
				{
					errors = errors + "You must supply your Address\n";
					valid = false;
				}
				
			if (document.frmUpload.txtCity.value == '')
				{
					errors = errors + "You must supply your City\n";
					valid = false;
				}
				
			if (document.frmUpload.txtPostcode.value == '')
				{
					errors = errors + "You must supply your Postcode\n";
					valid = false;
				}
				
			if (document.frmUpload.lstCountry.value == '')
				{
					errors = errors + "You must supply your Country\n";
					valid = false;
				}
				
			if (document.frmUpload.txtImageTitle.value == '')
				{
					errors = errors + "You must supply your Image Title\n";
					valid = false;
				}				
				
				
				

			if (document.frmUpload.txtImage.value == '')
				{
					errors = errors + "You must supply an Image\n";
					valid = false;
				}
				else
				{
					
					// check its a valid jpg or jpeg file
					myString = new String(document.frmUpload.txtImage.value)
					splitString = myString.split(".")

					if (splitString[splitString.length-1].toLowerCase() == "jpg" || splitString[splitString.length-1].toLowerCase() == "jpeg")
					{
						// do nowt
					}
					else
					{
						errors = errors + "You must supply a JPG or JPEG Image\n";
						valid = false;
					}
					
					
				}




			
			if (document.frmUpload.ddlCategory.value == '')
				{
					errors = errors + "You must supply your Image Category\n";
					valid = false;
				}
				
			if (!document.frmUpload.chkTsAndCs.checked)
				{
					errors = errors + "You must agree to the Terms & Cnditions\n";
					valid = false;
				}				
			
			
			if (!document.frmUpload.chkOriginal.checked)
				{
					errors = errors + "You must confirm this is your own photograph";
					valid = false;
				}					
			
	
			if (document.frmUpload.txtDescription.value.length > 50)
			{
				errors = errors + "Maximum of 50 characters for your Image Description";
				valid = false;
			}

				if (errors != "")
				{
					alert('There was a problem with your details.\n\n' + errors);
					errors = "";
				}
				else
				{
					document.frmUpload.submit()
					
				}



		// check the captcha thing
//		if (document.frmUpload.strCaptcha.value == '')
//			{
//				errors = errors + "You must enter the Validation Code.\n";
//				valid = false;
//				if (errors != "")
//				{
//					alert('There was a problem with your details.\n\n' + errors);
//					errors = "";
//				}
//
//			}
//			else
//			{
//				// captcha does stuff shen its finished
//				makeRequest()
//
//			}
			

		
	}




	
	function makeRequest() {
        var httpRequest;

		url = '../lib/validate_captcha.asp?captchaValue=' + document.frmUpload.strCaptcha.value;

        if (window.XMLHttpRequest) { // Mozilla, Safari, ...
            httpRequest = new XMLHttpRequest();
        } else if (window.ActiveXObject) { // IE
            try {
                httpRequest = new ActiveXObject("Msxml2.XMLHTTP");
            } catch (e) {
                try {
                    httpRequest = new ActiveXObject("Microsoft.XMLHTTP");
                } catch (e) {}
            }
        }

        if (!httpRequest) {
            alert('There was a problem submitting your form, this could be due to your browser.');
        }
		
        httpRequest.onreadystatechange = function() { alertContents(httpRequest); };
		// set the asch value to false to wait for the response before carrying on
        httpRequest.open('GET', url, true);
        httpRequest.send(null);
		
        //function below deals with results...
    }
	







function alertContents(httpRequest) {

		if (httpRequest.readyState == 4) {
            if (httpRequest.status == 200) {
				if (httpRequest.responseText != "true")
				{
					// wrong or some problem
					errors += "Please check the numbers you entered in the text box.";
				}
				
				//now, did we have errors from captcha or other fields?
				if (errors != "")
				{
				    alert('There was a problem with your details.\n\n' + errors);
				    errors = "";
				}
				else
				{
				    //ok!
				    document.frmUpload.submit();
				}
				
            } else {
                alert('There was a problem verifying your submission, please try again later.');
            }
		}

    }