var debug = false;
//var newwindow ='';

if (debug) { alert("loading upload_photo.js"); }

var today = new Date();
var h=today.getHours()
var mi=today.getMinutes()
var s=today.getSeconds()
var d=today.getDate()
var m=today.getMonth() + 1
var y=today.getFullYear()

//function checkTime(i)
//{
//if (i<10) 
//  {i="0" + i}
//  return i
//}
//mi=checkTime(mi)
//s=checkTime(s)
//document.getElementById('txt').innerHTML=h+":"+m+":"+s

// if (debug) { alert(today + " == " + y + m + d + h + mi + s); }

//function Guidelines()
//{
//	newwindow = window.open("http://www.thesnitcherdesk.com/SubmitGuidelines.php","mywindow",
//	"status=0,toolbar=0,resizable=0,scrollbars=1,width=680 height=450");
//	if (window.focus) {newwindow.focus()}
//	return false;
//}

function check_photo_files()
{
	var photo_attached = false;

	if (debug) { alert("checking photos ..."); }
	
	if( document.photo_form.Photo1.value != "" )
	{
		if (debug) { alert("photo 1 has a value ..."); }
		
		if (ImageExtension(document.photo_form.Photo1.value)) { photo_attached = true; }
		else { document.photo_form.Photo1.value = ""; }
	}

	if( document.photo_form.Photo2.value != "" )
	{
		if (debug) { alert("photo 2 has a value ..."); }
		
		if (ImageExtension(document.photo_form.Photo2.value)) { photo_attached = true; }
		else { document.photo_form.Photo2.value = ""; }
	}
	
	if (debug && photo_attached) { alert("... a photo was attached."); }
	
	return photo_attached
	
}

function upload_photo_submit() {
	
	if (debug) { alert("form submitted - processing ..."); }
	
	if( document.photo_form.processing.value == "yes")
	{
		if (debug) { alert("already processing - return."); }
		return;
	}
	
	// alert(document.photo_form.currentDay.value + " " + document.photo_form.currentMonth.value + " " + document.photo_form.currentYear.value);
	if (debug) { alert("checking form ..."); }
	
	if( (document.photo_form.Firstname.value == "") ||
	    (document.photo_form.Lastname.value == "") ||
	    (document.photo_form.Address1.value == "") ||
	    (document.photo_form.Town.value == "") ||
	    (document.photo_form.Postcode.value == "") ||
	    (document.photo_form.Celebrity.value == "") ||
	    (document.photo_form.Location.value == "") ||
	    (document.photo_form.PhotoDescriptionFromPhotographer.value == ""))
	{
		alert("Please complete all fields marked with  * ");
	}
	else if ( debug && confirm('done required fields - stop?') ) { return; }
	else if	( (!document.photo_form.OtherPhotographers[0].checked && !document.photo_form.OtherPhotographers[1].checked) ||
	    (!document.photo_form.Exclusive[0].checked && !document.photo_form.Exclusive[1].checked) ||
	    (!document.photo_form.OwnWork[0].checked && !document.photo_form.OwnWork[1].checked) )
	{
		alert("Please complete all fields marked with  * ");
	}
	else if ( debug && confirm('done tick boxes - stop?') ) { return; }
	else if((document.photo_form.Phonenumber.value != "") && !ValidateNumericString(document.photo_form.Phonenumber.value))
	{
		alert('Please enter a correct phone number');
	}
	else if ( debug && confirm('done phone number - stop?') ) { return; }
	else if((	document.photo_form.Email.value == "") ||
		(document.photo_form.Email.value != document.photo_form.Email2.value))
	{
		alert("Please check that your e-mail addresses match");
	}
	else if ( debug && confirm('done email addr - stop?') ) { return; }
	else if(!ValidateDate(document.photo_form.DOBDay.value, //
			 	    document.photo_form.DOBMonth.value, //
				    document.photo_form.DOBYear.value ) ||
		  !IsEarlier(document.photo_form.DOBDay.value, //
				 document.photo_form.DOBMonth.value, //
				 document.photo_form.DOBYear.value, //
				 d, m, y) ||
		  (document.photo_form.DOBYear.value - '0') < 1900)
	{
		alert(' Please enter a valid Date Of Birth ');
	}
	else if ( debug && confirm('done dob - stop?') ) { return; }
	else if(!ValidateDate(document.photo_form.PhotoDay.value, //
			 	    document.photo_form.PhotoMonth.value, //
				    document.photo_form.PhotoYear.value ) || // 
		  !IsEarlier(document.photo_form.PhotoDay.value, //
				 document.photo_form.PhotoMonth.value, //
				 document.photo_form.PhotoYear.value, //
				 d, m, y) ||
		  (document.photo_form.PhotoYear.value - '0') < 1900)

	{
		alert(' Please enter a valid date of when the photo was taken');
	}
	else if ( debug && confirm('done photo date - stop?') ) { return; }
	else if( ! check_photo_files() )
	{
		alert("Please choose a picture file to upload (jpg, jpeg, jpg2, jpeg2, gif, tif, tiff, png, pict, psd and pdf accepted)");
	}
	else if ( debug && confirm('checked photos - stop?') ) { return; }
	else if( !document.photo_form.TnCs.checked )
	{
		alert("Please confirm you have read the terms and conditions!");
	}
	else if ( debug && confirm('done t&cs - stop?') ) { return }
	else if(confirm("Right, so you are ready to submit your photographs to The Snitcher Desk? Let's make sure. Please confirm again that you have read and agreed to our Terms & Conditions and have particularly understood the following key points:\n\r\n\r- You must own the copyright of the photo you are about to submit.\n\r\n\r- You grant The Snitcher Desk an exclusive license to market and sell your photo for a period of 90 days. After this point you may downgrade the license to a non-exclusive license if you contact us.\n\r\n\r- The information you have provided is completely truthful and that you will be held liable for any lack of truth on your part.\n\r\n\r- You indemnify The Snitcher Desk against any action as a consequence of breaching any term, condition, or clause on your part.\n\r\n\rIf you answered yes to all of the above, click OK and we'll get to work for you."))
	//else if(confirm('Right, so you are ready to submit your photographs to The Snitcher  Desk?  Let’s make sure. Please confirm again that you have read and  agreed to our Terms & Conditions and have particularly understood the  following key points:\n\r\n\r - You must own the copyright of the photo you are about to submit.\n\r\ - You grant The Snitcher Desk an exclusive license to market and sell  your photo for a period of 120 days. After this point you may  downgrade the license to a non-exclusive license if you contact us.\n\r - The information you have provided is completely truthful and that  you will be held liable for any lack of truth on your part.\n\r - You indemnify The Snitcher Desk against any action as a consequence  of breaching any term, condition, or clause on your part.\n\r\n\rAnd further to the terms and conditions:\n\r\n\r - You are sending the highest quality of photograph you can.\n\r - You want us to make you as much money as possible.\n\r\n\r If you answered yes to all of the above, click OK and we’ll get  to work for you.'))
	{
		if ( debug )
		{
			alert('Would have submitted but debugging! :)');
		}
		else
		{
			progress_text = document.getElementById("upload_progress_text")
			progress_flash = document.getElementById("upload_progress_flash")
			upload_button = document.getElementById("upload_submit_button")
			//alert("Please be patient if uploading a large file or if you have a slow connection");
			// unhide the graphic
			document.photo_form.processing.value="yes";
			progress_text.style.display="block";
			progress_flash.style.display="block";
			upload_button.style.display="none";
			document.photo_form.processForm.value="yes";
			document.photo_form.submit();
		}
	}
}