// pop a window?
popWinUp=0;
ns = (navigator.appVersion.indexOf("MSIE")<0) ? true : false; //alert(ns);
function popWin(xURL,xX,xY) { 
	if (!ns) { xX+=17; xY+=8; }
	if (!ns && popWinUp) { poppedWin.close(); popWinUp=0; }
		//poppedWin=window.open(xURL,'PopWin','width=' + xX + ',height=' + xY + ',resizable=yes,title=yes,toolbar=no,scrollbars=yes,screenX=40,screenY=5,top=40,left=5');
	poppedWin=window.open(xURL,'PopWin','width=' + xX + ',height=' + xY + ',resizable=yes,title=yes,toolbar=no,scrollbars=yes,screenX=5,screenY=5,top=5,left=5');
	popWinUp=1;
   if (ns && poppedWin) { poppedWin.focus(); }
 }

function submitForm(thisForm,validationString,noUpperCase) {
	// pass parameters like this: submitForm(document.forms[0],'name=min5&email=min7&comments=min1');
	alertBase="You must complete at least the following fields:\n";
	alertStr=""; checkField=""; checkType="";checkTypeMin=0; firstField="";
	toValidate=validationString.split(/\&/);
	for (i=0;i<toValidate.length;i++) {
		checks=toValidate[i].split(/\=/);
		checkField=checks[0]; checkType=checks[1]; checkTypeMin=0;
		if (checkType.indexOf("min")>=0) {
			checkTypeMin=checkType.substr(3);
		}
		//alert("-" + checkField + "-, " + checkType + ", " + checkTypeMin + "\n" + thisForm.elements[checkField].value);
		if (checkType.indexOf("min")>=0) {
			if ( checkField.indexOf("email")>=0 && thisForm.elements[checkField].value.indexOf("@")<0 ) {
				alertStr+="  * "+titleCase(checkField.replace(/([^a-zA-Z\-0-9]+)/g," "))+"  (min length of "+checkTypeMin+", must contain an \@)\n";
				if (!firstField){ firstField=checkField; }
			} else if ((checkField.indexOf("your_thumb")>=0 || checkField.indexOf("your_photo")>=0) && thisForm.elements[checkField].value.length<checkTypeMin ) {
				alertStr+="  * "+titleCase(checkField.replace(/([^a-zA-Z\-0-9]+)/g," "))+"  (must be attached - click 'Attach' button)\n";
				if (!firstField){ firstField=checkField; }
			} else if (thisForm.elements[checkField].value.length<checkTypeMin ) {
				alertStr+="  * "+titleCase(checkField.replace(/([^a-zA-Z\-0-9]+)/g," "))+"  (min length of "+checkTypeMin+")\n";
				if (!firstField){ firstField=checkField; }
			}
		}
	}
	if (alertStr !="") {
		alert(alertBase+alertStr);
		document.forms[0].elements[firstField].focus();
	} else {
		// omit fields: theDate (i=0), theShortDate (i=1), and comments (i=thisForm.elements.length-1)
		if (!noUpperCase && thisForm.elements.length>=4) {
			for (i=2;i<thisForm.elements.length;i++) { 
				if (thisForm && thisForm.elements && thisForm.elements[i] && thisForm.elements[i].type=="text"){
					thisForm.elements[i].value=thisForm.elements[i].value.toUpperCase(); // make 'em all uppercase
				}
			}
		}
		today = new Date();
		thisMo=today.getMonth()+1;
		thisYr=today.getYear();
		if (thisYr<2000) { thisYr+=1900; }
		//alert(thisMo+"/"+thisYr);
		if (thisForm.theShortDate) { thisForm.theShortDate.value=thisMo+"/"+thisYr; }
		if (thisForm.theDate) { thisForm.theDate.value=today; }
		//for (i=0;i<thisForm.elements.length;i++){ alert(thisForm.elements[i].name+"="+thisForm.elements[i].value); }
		thisForm.submit();
	}
}
function resetForm(thisForm) {
	thisForm.reset();
}

function titleCase(sIn) {
	if (sIn.indexOf(" ")>=0) {
		var s=sIn.split(" ");
	} else {
		var s=new Array(sIn);
	}
	var sOut="";
	for (var q in s)	{
		if (q!=0)	{	sOut+=" "; }
		sOut+=s[q].substr(0,1).toUpperCase()+s[q].substr(1).toLowerCase();
	}
	return sOut;
}

function getSearchAsArray() {
	var results = new Array()
	if ((is_nav4up || is_ie4up)) {
		var input = location.search.substring(1)
		if (input) {
			var srchArray = input.split("&")
			var tempArray = new Array()
			for (i = 0; i < srchArray.length; i++) {
				tempArray = srchArray[i].split("="); 
// Replaces "null" and then unescapes name-value pair. 
				for (a in tempArray) { 
					tempArray[a] = tempArray[a].replace( "null" , "");
				}
				results[tempArray[0]] = unescape(tempArray[1]);
			}
		}
	}
	return results;
}
