//  Sniff, sniff,  let's find out which browser and version you're using!

var browser = navigator.appName;
var browserVer = navigator.appVersion;
var showDiv = "";
var hideDiv = "";
	if (browser == "Netscape" && browserVer.indexOf("4.7")> -1)
	{
		layerRef = "document.";
		endLayerRef = "";
		styleRef = "";
		NS4 = true;
		hideDiv = "hide";
		showDiv = "show";
	}
	else if (browser == "Netscape" && browserVer.indexOf("5.0")> -1)
	{
		layerRef = "document.getElementById('";
		endLayerRef = "')";
		styleRef = ".style";
		NS6 = true;
		hideDiv = "hidden";
		showDiv = "visible";
	}
	else  // if IE
	{
		layerRef = "document.all['";
		endLayerRef = "']";
		styleRef = ".style";
		IE = true;
		hideDiv = "hidden";
		showDiv = "visible";
	}
// usage
// 	eval(layerRef + "divName" + endLayerRef + styleRef + ".visibility = '" + message + "'");
//		eval(layerRef + "messageDiv" + endLayerRef + ".innerHTML = '" + message + "'");


var onOff = 1;
function blink()
{	onOff++;
	if(onOff%2 == 0) 	{	eval(layerRef + "waitDiv" + endLayerRef + styleRef + ".visibility = '" + showDiv + "'");}
	 else {eval(layerRef + "waitDiv" + endLayerRef + styleRef + ".visibility = '" + hideDiv + "'");}

}

var waitGif = new Image();
waitGif.src = "DWimages/wait2.gif";


function setCardType()
{		
	switch (document.forms['photoForm'].ccType.value)
		{
			case "MC":			document.forms['photoForm'].cc1.value = "";
								document.forms['photoForm'].cc2.value = "";
								document.forms['photoForm'].cc3.value = "";
								document.forms['photoForm'].cc4.value = "";
								document.forms['photoForm'].cc1.size=4;
								document.forms['photoForm'].cc2.size=4;
								document.forms['photoForm'].cc3.size=4;
								document.forms['photoForm'].cc4.size=4;
								document.forms['photoForm'].cc1.maxLength=4;
								document.forms['photoForm'].cc2.maxLength=4;
								document.forms['photoForm'].cc3.maxLength=4;
								document.forms['photoForm'].cc4.maxLength=4;
								break;
		
			case "Visa":		document.forms['photoForm'].cc1.value = "";
								document.forms['photoForm'].cc2.value = "";
								document.forms['photoForm'].cc3.value = "";
								document.forms['photoForm'].cc4.value = "";
								document.forms['photoForm'].cc1.size=4;
								document.forms['photoForm'].cc2.size=4;
								document.forms['photoForm'].cc3.size=4;
								document.forms['photoForm'].cc4.size=4;
								document.forms['photoForm'].cc1.maxLength=4;
								document.forms['photoForm'].cc2.maxLength=4;
								document.forms['photoForm'].cc3.maxLength=4;
								document.forms['photoForm'].cc4.maxLength=4;
								break;
		
			case "Discover":	document.forms['photoForm'].cc1.value = "";
								document.forms['photoForm'].cc2.value = "";
								document.forms['photoForm'].cc3.value = "";
								document.forms['photoForm'].cc4.value = "";
								document.forms['photoForm'].cc1.size=4;
								document.forms['photoForm'].cc2.size=4;
								document.forms['photoForm'].cc3.size=4;
								document.forms['photoForm'].cc4.size=4;
								document.forms['photoForm'].cc1.maxLength=4;
								document.forms['photoForm'].cc2.maxLength=4;
								document.forms['photoForm'].cc3.maxLength=4;
								document.forms['photoForm'].cc4.maxLength=4;
								break;
		
			case "AX":			document.forms['photoForm'].cc1.value = "";
								document.forms['photoForm'].cc2.value = "";
								document.forms['photoForm'].cc3.value = "";
								document.forms['photoForm'].cc4.value = "";
								document.forms['photoForm'].cc1.size=4;
								document.forms['photoForm'].cc2.size=6;
								document.forms['photoForm'].cc3.size=5;
								document.forms['photoForm'].cc4.size=1;
								document.forms['photoForm'].cc1.maxLength=4;
								document.forms['photoForm'].cc2.maxLength=6;
								document.forms['photoForm'].cc3.maxLength=5;
								document.forms['photoForm'].cc4.maxLength=0;
								break;
		}
}



function ccLength(item,next)

{

	// alert("Length: " +item.value.length + "Max: " + item.maxLength + " Next: " + next);

	//document.forms['photoForm'].orderNo.value=item.value.length;

	if(item.value.length >= item.maxLength) eval("document.forms['photoForm']." + next + ".focus();");

}

function validate()

{	errorArray = new Array();

	// Create regular expression to search for illegal characters
	// The only characters allowed are upper and lower case alpha, numeric, the underscore, ampersand, space, pound sign, and dot
	var photoError = false;
	var errorString = "";
	rExp = /'/gi;

	newString = "`";

	re = /[^A-Za-z0-9_,\-\/ `."'#]/;
	if (re.test(document.forms['photoForm'].firstName.value)  || (document.forms['photoForm'].firstName.value == "")) { errorArray.push(" First Name"); }
	if (re.test(document.forms['photoForm'].lastName.value)  || (document.forms['photoForm'].lastName.value == "")) { errorArray.push(" Last Name"); }
	if (re.test(document.forms['photoForm'].address.value)   || (document.forms['photoForm'].address.value == "") || (document.forms['photoForm'].address.value == "Maximum 256 characters")) { errorArray.push(" Address "); }

	// Now check city against it's own regex -  Accept only upper and lower alpha, spaces, underscore, dash
	reCity = /[^A-Za-z0-9_ .-]/;
	if (reCity.test(document.forms['photoForm'].city.value)  ||(document.forms['photoForm'].city.value == "")) { errorArray.push(" City"); }

	if(document.forms['photoForm'].state[0].selected == true){ errorArray.push(" State "); }

	// Check for zip - Accept only numeric and dash
	reZip= /[^0-9-]/;
	if (reZip.test(document.forms['photoForm'].zip.value)  || (document.forms['photoForm'].zip.value == "")) { errorArray.push(" Zip"); }

	if (re.test(document.forms['photoForm'].country.value)  ||(document.forms['photoForm'].country.value == "")) { errorArray.push(" Country "); }

	reCC = /[^0-9]/;
	if (reCC.test(document.forms['photoForm'].cc1.value) || reCC.test(document.forms['photoForm'].cc2.value) || reCC.test(document.forms['photoForm'].cc3.value) || reCC.test(document.forms['photoForm'].cc4.value)  ) { errorArray.push(" Credit Card Number "); }
	if (reCC.test(document.forms['photoForm'].ccCode.value) ) { errorArray.push(" Credit Card Security Code"); }

	
	
	// Now a special check for the phone number
	// Allow only alpa, digits, (,), space, and dot.
	rePhone = /[^A-Za-z0-9-() .]/;
	if (rePhone.test(document.forms['photoForm'].phone.value)  ||(document.forms['photoForm'].phone.value == "")) { errorArray.push(" Phone"); }

	// Now check email address against the regular expression and to see if both @ and . are present.
	// This is like the other regular expression, except that no spaces are allowed
	reEmail = /[^A-Za-z0-9_@.]/;
	if (reEmail.test(document.forms['photoForm'].email.value)  || (document.forms['photoForm'].email.value.indexOf("@") == -1) || (document.forms['photoForm'].email.value.indexOf(".") == -1) ) 
	{ errorArray.push(" Email"); }

	if(errorArray.length >= 1)

	{	errorString = "Please correct errors in the following fields";

		for (var i = 0; i < errorArray.length; i++) {	errorString +=  errorArray[i] + ","; }

		alert(errorString);

	}
	// Check to see if photo is png, gif, jpg or bmp format
	if(document.forms['photoForm'].userfile.value.indexOf(".jpg") === false || document.forms['photoForm'].userfile.value.indexOf(".JPG")  === false
		|| document.forms['photoForm'].userfile.value.indexOf(".gif") === false ||document.forms['photoForm'].userfile.value.indexOf(".GIF") === false 
		|| document.forms['photoForm'].userfile.value.indexOf(".bmp") === false ||document.forms['photoForm'].userfile.value.indexOf(".BMP") === false 
		|| document.forms['photoForm'].userfile.value.indexOf(".png") === false ||document.forms['photoForm'].userfile.value.indexOf(".PNG") === false )
	{	alert("Sorry, the photo must have a \".jpg\", \".png\", \".bmp\" or \"gif\" extension");	
		photoError = true;
	}



	if(errorString == "" && photoError == false) 
	{	eval(layerRef + "waitDiv" + endLayerRef + styleRef + ".visibility='" + showDiv + "'");
		var holdOn = setInterval('blink()', 750);
		// var finalle = stripChars(document.forms['photoForm'].photoName.value);
		// alert(finalle);
		document.forms['photoForm'].submit(); 
	}
	
	
	
	

	// alert("It's all good!");

}
