//
//	Link to AK Action Photo home page
//
function linkHome()
{	top.window.location="http://www.akactionphoto.com";	}
//
//	Link to AK Action Photo photos/events page
//
function linkEvents()
{	top.window.location="http://www.akactionphoto.com/execak/ap000.cgi";	}
//
//	Link to AK Action Photo gallery page
//
function linkGallery()
{	top.window.location="http://www.akactionphoto.com/execak/ap600.cgi";	}
//
//	Link to AK Action Photo FAQ page about cropping
//
function linkFAQimage()
{	top.window.location="http://www.akactionphoto.com/ap535.htm";	}
//
//	Link to AK Action Photo season search page
//
function linkSearch()
{	top.window.location="http://www.akactionphoto.com/ap050.htm";	}
//
//	Based on select box click, link to events by sport page.
//
function linkSports(target, selectObject, reset) {
	eval(target+".location='"+ selectObject.options[selectObject.selectedIndex].value+"'");
	if (reset) { selectObject.selectedIndex=0; }
	selectObject.selectedIndex=0;
}
//
//	Open the Services/About window.
//
function openInformation(inputURL) {
	infoWindow=open(inputURL,"infoWin",'toolbar=no,location=no,directories=no,status=no,menubar=no,scrollbars=yes,resizable=yes,width=350,height=400,left=100,top=100');
}
//
//	Open the Framing Tool window.
//
function openVisualize(url) {
	valid = true;
	var tempName = document.order.name.value;
	var tempEmail = document.order.email.value;
	var tempPhone = document.order.phone.value;
//	if (tempName == "" ) { 
//		alert("Please enter your name. The information will only be used if you order a custom print.");
//		valid = false;
//	}			
//	if (tempEmail == "" ) { 
//		alert("Please enter your email address. The information will only be used if you order a custom print.");
//		valid = false;
//	}		
	if (valid) {
		tempName = compressString(tempName);
		tempEmail = compressString(tempEmail);
		tempPhone = compressString(tempPhone);
//		tempName = "+"+tempName;
//		tempEmail = "+"+tempEmail;
//		tempPhone = "+"+tempPhone;
		tempName = "&name="+tempName;
		tempEmail = "&email="+tempEmail;
		tempPhone = "&phone="+tempPhone;
		var tempURL = url+tempEmail+tempName+tempPhone;
		newWindow = window.open(tempURL , 'imageVisualize' , 'toolbar=no,location=no,scrollbars=yes,resizable=yes,width=800,height=600');
	}
}
function compressString(inputText) {
	if (inputText == "") { return ""; }
	if (inputText.length == 0) { return ""; }
	tempText = inputText;
	tempIndex = tempText.indexOf(' ');
	if (tempIndex == -1) { return inputText; }
	while (tempIndex != -1) {
		tempText = tempText.substr(0, tempIndex) + "_" + tempText.substring(tempIndex+1, inputText.length);
		tempIndex = tempText.indexOf(' ');
	}
	return tempText;		
}	
//
//	Open the sales process movie window.
//
function openSale() {
	saleWindow=open("","salewin",'toolbar=no,location=no,directories=no,status=no,menubar=no,scrollbars=yes,resizable=yes,width=400,height=400,left=50,top=10');
	saleWindow.document.write("<HTML>");	
	saleWindow.document.write("<LINK rel=stylesheet href=\"ap.css\" type=\"text/css\">");
	saleWindow.document.write("<HEAD><TITLE>Sale Process</TITLE></HEAD>");
	saleWindow.document.write("<BODY><BR><CENTER>");
	saleWindow.document.write("<TABLE border=0>");
	saleWindow.document.write("<TR><TD width=10>&nbsp;</TD>");
	saleWindow.document.write("<TD>");
	saleWindow.document.write("<OBJECT classid=\"clsid:D27CDB6E-AE6D-11cf-96B8-444553540000\" codebase=\"http://download.macromedia.com/pub/shockwave/cabs/flash/swflash.cab#version=5,0,0,0\" WIDTH=\"300\" HEIGHT=\"300\"><PARAM NAME=movie VALUE=\"saletest.swf\"> <PARAM NAME=quality VALUE=high> <PARAM NAME=bgcolor VALUE=\"#FFFFFF\"> <EMBED src=\"saletest.swf\" quality=high bgcolor=\"#FFFFFF\"  WIDTH=\"300\" HEIGHT=\"300\" TYPE=\"application/x-shockwave-flash\" PLUGINSPAGE=\"http://www.macromedia.com/shockwave/download/index.cgi?P1_Prod_Version=ShockwaveFlash\"></EMBED></OBJECT>");
	saleWindow.document.write("</TD>");
	saleWindow.document.write("<TD width=10>&nbsp;</TD></TR>");
	saleWindow.document.write("<TR><TD>&nbsp;</TD></TR>");
	saleWindow.document.write("<TR><TD>&nbsp;</TD>");
	saleWindow.document.write("<TD align=center><A href='javascript:window.close()'>Close Window</A></TD>");
	saleWindow.document.write("<TD>&nbsp;</TD></TR>");
	saleWindow.document.write("</TABLE></CENTER></BODY></HTML>");
	saleWindow.document.close();
	saleWindow.focus();
}
//
//	Validate the Notify and Order (name, email, and bib fields).
//
function validate(form, type) {
	if (form.name.value == "" ) { 
		alert("Your name is required.");
		return false;
	}			
	if (form.email.value == "" ) { 
		alert("Your email address is required.");
		return false;
	}		
	inputEMail = form.email.value;	
	if (notValidEMail(inputEMail)) { return false; }
//	inputBIB = form.bib.value;	
//	if (notValidBIB(inputBIB)) { return false; }
	if (type == "order") { return checkPurchase(form); }
	return true;
}
function gggnotValidEMail(testEMail) {
	invalidChars = " /:;,";
	indexAt = testEMail.indexOf("@",1);
	if (indexAt == -1) {
		alert("Invalid eMail address. It is missing an '@' character.");
		return true;
	}
	indexDot = testEMail.indexOf(".",indexAt);
	if (indexDot == -1) {
		alert("Invalid eMail address. It is missing a  '.' character.");
		return true;
	}
	indexDot = indexDot + 4;
	if (indexDot > testEMail.length) {
		alert("Invalid eMail address. Fewer than 2 characters follow the '.' of the eMail address.");
		return true;
	}
	if (testEMail.indexOf("@",indexAt+1) != -1) {
		alert("Invalid eMail address. There is an extra '@' character.");
		return true;
	}
	max = invalidChars.length;
	for (i=0; i<max; ++i) {
		testChar = invalidChars.charAt(i);
		if (testEMail.indexOf(testChar) != -1) {
		  alert("Invalid character("+testChar+") detected in the eMail address.");
		  return true;
		}
	}
	return false;
}
//
//	Validate the eMail address.
//	Also appears in ap.js
//
function notValidEMail(testEMail) {
//alert("AK00 ("+testEMail+")");
//	destination@.com
//	Test the destination. Reg1 has invalid combinations. 
	var reg1 = /(@.*@)|(\.\.)|(@\.)|(\.@)|(^\.)/;
//	Test the host (@.com). Reg2 has valid combinations.
	var reg2 = /^.+\@(\[?)[a-zA-Z0-9\-\.]+\.([a-zA-Z]{2,3}|[0-9]{1,3})(\]?)$/;
	if (testEMail == "") {
		alert("Your email address is required.");
		return true;
	}
	if (!reg1.test(testEMail) && reg2.test(testEMail)) {
//		Valid syntax.
		return false;
	} else {
//		Invalid syntax.
		alert("(" + testEMail + ") is an invalid e-mail address.");
		return true;
	}
}
function notValidBIB(testBIB) {
	if (isNaN(testBIB)) {
		alert("Only numbers are allowed for BIB / jersey number. For multiple BIB / jersey numbers, submit another Notification request.");
		return true;
	}
	return false;
}
function checkPurchase(form) {
	isCheck = form.inquiry.checked;
	if (isCheck) { return true; }
	test = Number(form.countNegative.value);
	if (test > 0) { return true; }
	test = Number(form.countDigital.value);
	if (test > 0) { return true; }
//	max = form.elements.length;
//	for (i=0; i<max; i++) {
//		testName = form.elements[i].name;
//		if (testName.substr(0,3) == "buy") {
//			isCheck = eval("form."+testName+".checked");
//			if (isCheck) { return true; }
//			}
//		}
	alert("The order is not complete. For any package selected, a quantity greater than 0 is expected.");
	return false;
	
//	max = form.counter.value;
//	++max;
//	for (i=1; i<max; ++i) {
//		isCheck = eval("form.buy"+i+".checked");
//		if (isCheck) { return true; }
//		}
//	alert("The order is not complete. In the Purchase column, check the negative(s) you wish to order.");
//	return false;		
}
//
//	Collect size of current window and set resolution.
//
function setResolution(inputBrowser) {
	currentW = 0;
	currentH = 0;
	if (browser == "IE") {
		currentW = document.body.offsetWidth;
		currentH = document.body.offsetHeight;
	}
	if (browser == "NS") {
		currentW = window.innerWidth;
		currentH = window.innerHeight;
	}
	if (browser == "SF") {
		currentW = window.innerWidth;
		currentH = window.innerHeight;
	}
	if (currentW > 1152) {
		tempW = 1280;
	} else if (currentW > 1024) {
		tempW = 1152;
	} else if (currentW > 800) {
		tempW = 1024;
	} else if (currentW > 640) {
		tempW = 800;
	} else {		
		tempW = 640;
	}
	if (currentH > 864) {
		tempH = 1280;
	} else if (currentH > 768) {
		tempH = 1152;
	} else if (currentH > 600) {
		tempH = 1024;
	} else if (currentH > 480) {
		tempH = 800;
	} else {		
		tempH = 640;
	}
	if (tempW < tempH) {
		tempW = tempH;
	}
	if (currentW == 0) {
		tempW = 0;
	}
	document.homeform.apresolution.value = tempW;
}
//
//	Functions for ap100.cgi, where users select
//	negatives and files for purchase.
//
function clickDigital(inputObject,inputChecked) {
	var counterTotal = Number(document.order.countDigital.value);
	var counterLocal = Number(inputObject.value);
	var currentDigital = Number(document.order.totalDigital.value);
	if (inputChecked) {
	  counterTotal++;			
	  counterLocal++;
	  if (counterLocal == 1) {
	  	currentDigital = currentDigital + 20;
	  } else {
	  	currentDigital = currentDigital + 3;
	  } 	  			  	
	} else {
	  counterTotal--;
	  counterLocal--;
	  if (counterLocal == 0) {
	  	currentDigital = currentDigital - 20;
	  } else {
	  	currentDigital = currentDigital - 3;
	  } 	  			  	
 	} 
	inputObject.value = counterLocal;
	document.order.countDigital.value = counterTotal; 
  	document.order.totalDigital.value = currentDigital;
}
function clickNegative(inputObject, inputQty, inputItem) {
//	if (inputItem == "none" && !document.order.inquiry.checked) {
	if (inputItem == "none") {
		alert("Before specifying the quantity, you need to select a package.");
		inputObject.value = 0;
	}
	var counterTotal = Number(document.order.countNegative.value);
	if (inputQty >0) {
	  counterTotal++;			
	}
	if (inputQty == 0 || inputQty == "") {
	  counterTotal--;
 	} 
	document.order.countNegative.value = counterTotal;
//	if (document.order.inquiry.checked) {
//		document.order.totalNegative.value = 0;
//	} else {
		document.order.totalNegative.value = counterTotal;
//	}
}
function clickInquiry(inputChecked) {
	if (inputChecked) {
		document.order.totalNegative.value = 0;
	} else {
		counterTotal = Number(document.order.countNegative.value);
		document.order.totalNegative.value = counterTotal;
 	} 
}
