﻿function Right(str, num)
{
     return str.substring(str.length-num);  // pull out right num
}


function openScript6(url) {
        var Win = window.open(url, 'sizingImages', config='width=600,height=380,resizable=0,scrollbars=yes,menubar=no,status=no');
}

function checkForm() {

	if (document.theForm.Contact_FirstName.value=="") {
		alert("Please enter your first name.");
		return false; }
		
	if (document.theForm.Contact_LastName.value=="") {
		alert("Please enter your last name.");
		return false; }

	if (document.theForm.Contact_Address.value=="") {
		alert("Please enter your address.");
		return false; }

	if (document.theForm.Contact_CityStateZip.value=="") {
		alert("Please enter your city, state, and zip.");
		return false; }
		
	if (document.theForm.Contact_DayPhone.value=="" && document.theForm.Contact_EveningPhone.value=="") {
		alert("Please enter a phone number where you can be reached.");
		return false; }
		
	if (document.theForm.Contact_Email.value=="") {
		alert("Please enter your e-mail address.");
		return false;
	}
	
	if (document.theForm.Contact_Email.value!="" && echeck(document.theForm.Contact_Email.value)==false) {
		alert("Please enter a complete and accurate e-mail address.");
		return false; }

	if ((document.theForm.TitleEntry1_Name.value!="" && document.theForm.TitleEntry1_JPEG_File1.value=="") || (document.theForm.TitleEntry1_JPEG_File1.value!="" &&document.theForm.TitleEntry1_Name.value=="")) {
		alert("Entry #1 fields are incomplete.\nAt least one image is required for each entry and fields must not be skipped.");
		return false; }
		
	if (document.theForm.TitleEntry1_Name.value!="") {
		if (document.theForm.TitleEntry1_Size.value=="" || document.theForm.TitleEntry1_Media.value=="" || document.theForm.TitleEntry1_Price.value=="") {
			alert("The size, media, and price fields are required for Entry #1.");
			return false; }
		if (document.theForm.TitleEntry1_JPEG_File2.value=="" && document.theForm.TitleEntry1_JPEG_File3.value!="") {
			alert("Entry #1 fields are incomplete.\nAt least one image is required for each entry and fields must not be skipped.");
			return false; }
	}
		
	if ((document.theForm.TitleEntry2_Name.value!="" && document.theForm.TitleEntry2_JPEG_File1.value=="") || (document.theForm.TitleEntry2_JPEG_File1.value!="" &&document.theForm.TitleEntry2_Name.value=="")) {
		alert("Entry #2 fields are incomplete.\nAt least one image is required for each entry and fields must not be skipped.");
		return false; }

	if (document.theForm.TitleEntry2_Name.value!="") {
		if(document.theForm.TitleEntry2_Size.value=="" || document.theForm.TitleEntry2_Media.value=="" || document.theForm.TitleEntry2_Price.value=="") {
			alert("The size, media, and price fields are required for Entry #2.");
			return false; }
		if (document.theForm.TitleEntry2_JPEG_File2.value=="" && document.theForm.TitleEntry2_JPEG_File3.value!="") {
			alert("Entry #2 fields are incomplete.\nAt least one image is required for each entry and fields must not be skipped.");
			return false; }
	}
		
	if ((document.theForm.TitleEntry3_Name.value!="" && document.theForm.TitleEntry3_JPEG_File1.value=="") || (document.theForm.TitleEntry3_JPEG_File1.value!="" &&document.theForm.TitleEntry3_Name.value=="")) {
		alert("Entry #3 fields are incomplete.\nAt least one image is required for each entry and fields must not be skipped.");
		return false; }

	if (document.theForm.TitleEntry3_Name.value!="") {
		if(document.theForm.TitleEntry3_Size.value=="" || document.theForm.TitleEntry3_Media.value=="" || document.theForm.TitleEntry3_Price.value=="") {
			alert("The size, media, and price fields are required for Entry #3.");
			return false; }
		if (document.theForm.TitleEntry3_JPEG_File2.value=="" && document.theForm.TitleEntry3_JPEG_File3.value!="") {
			alert("Entry #3 fields are incomplete.\nAt least one image is required for each entry and fields must not be skipped.");
			return false; }
	}

	if (document.theForm.TitleEntry1_Name.value=="" && document.theForm.TitleEntry2_Name.value=="" && document.theForm.TitleEntry3_Name.value=="") {
		alert("Please enter your artwork information and upload at least one jpg file per entry.");
		return false; }

	image1a = document.theForm.TitleEntry1_JPEG_File1.value;
	image1b = document.theForm.TitleEntry1_JPEG_File2.value;
	image1c = document.theForm.TitleEntry1_JPEG_File3.value;
	
	image2a = document.theForm.TitleEntry2_JPEG_File1.value;
	image2b = document.theForm.TitleEntry2_JPEG_File2.value;
	image2c = document.theForm.TitleEntry2_JPEG_File3.value;
	
	image3a = document.theForm.TitleEntry3_JPEG_File1.value;
	image3b = document.theForm.TitleEntry3_JPEG_File2.value;
	image3c = document.theForm.TitleEntry3_JPEG_File3.value;
	
	jpgmess = "All images must be JPEG image files (.jpg extension).";
	
	if (image1a!="") {
		theExt = Right(image1a, 4).toLowerCase();
		theExt2 = Right(image1a, 5).toLowerCase();
		if (theExt!=".jpg" && theExt2!=".jpeg") {
			alert(jpgmess);
			return false;  }
	}
	if (image1b!="") {
		theExt = Right(image1b, 4).toLowerCase();
		theExt2 = Right(image1b, 5).toLowerCase();
		if (theExt!=".jpg" && theExt2!=".jpeg") {
			alert(jpgmess);
			return false;  }
	}
	if (image1c!="") {
		theExt = Right(image1c, 4).toLowerCase();
		theExt2 = Right(image1c, 5).toLowerCase();
		if (theExt!=".jpg" && theExt2!=".jpeg") {
			alert(jpgmess);
			return false;  }
	}
	if (image2a!="") {
		theExt = Right(image2a, 4).toLowerCase();
		theExt2 = Right(image2a, 5).toLowerCase();
		if (theExt!=".jpg" && theExt2!=".jpeg") {
			alert(jpgmess);
			return false;  }
	}
	if (image2b!="") {
		theExt = Right(image2b, 4).toLowerCase();
		theExt2 = Right(image2b, 5).toLowerCase();
		if (theExt!=".jpg" && theExt2!=".jpeg") {
			alert(jpgmess);
			return false;  }
	}
	if (image2c!="") {
		theExt = Right(image2c, 4).toLowerCase();
		theExt2 = Right(image2c, 5).toLowerCase();
		if (theExt!=".jpg" && theExt2!=".jpeg") {
			alert(jpgmess);
			return false;  }
	}
	if (image3a!="") {
		theExt = Right(image3a, 4).toLowerCase();
		theExt2 = Right(image3a, 5).toLowerCase();
		if (theExt!=".jpg" && theExt2!=".jpeg") {
			alert(jpgmess);
			return false;  }
	}
	if (image3b!="") {
		theExt = Right(image3b, 4).toLowerCase();
		theExt2 = Right(image3b, 5).toLowerCase();
		if (theExt!=".jpg" && theExt2!=".jpeg") {
			alert(jpgmess);
			return false;  }
	}
	if (image3c!="") {
		theExt = Right(image3c, 4).toLowerCase();
		theExt2 = Right(image3c, 5).toLowerCase();
		if (theExt!=".jpg" && theExt2!=".jpeg") {
			alert(jpgmess);
			return false;  }
	}
	
//alert("No errors.");
//return false;		
return true;
}

//this function disallows double quotes
function noDblQuotes() {
	if (event.keyCode==34) {
		alert("Double quotes are not allowed, please use single quotes instead.");
		event.returnValue = false; }	
}
//end disallow quotes function


// The following function checks to see if an email address is valid
function echeck(str) {
  var at="@"
  var dot="."
  var lat=str.indexOf(at)
  var lstr=str.length
  var ldot=str.indexOf(dot)
  if ((str.indexOf(at)==-1) && (str != "")) {
     return false
  }
  if ((str.indexOf(at)==-1 || str.indexOf(at)==0 || str.indexOf(at)==lstr) && (str != "")) {
     return false
  }
  if ((str.indexOf(dot)==-1 || str.indexOf(dot)==0 || str.indexOf(dot)==lstr) && (str != "")) {
      return false
  }
   if ((str.indexOf(at,(lat+1))!=-1) && (str != "")) {
      return false
   }
   if ((str.substring(lat-1,lat)==dot || str.substring(lat+1,lat+2)==dot) && (str != "")) {
      return false
   }
   if ((str.indexOf(dot,(lat+2))==-1) && (str != "")) {
      return false
   }
}
// end check email function