
function getdate() {
	var ourDate = new Date();
	var d = ourDate.getMonth() +"-"+ ourDate.getDate() +"-"+ ourDate.getFullYear();
	var dl = ourDate.toLocaleString()
	var ed = escape(dl);
	return d;
}

function showDiv(id)
{
	if (document.getElementById) {
		var style2 = document.getElementById(id).style;
		style2.display = style2.display? "":"block";
	} else if (document.all) {
		var style2 = document.all[id].style;
		style2.display = style2.display? "":"block";
	} else if (document.layers) {
		var style2 = document.layers[id].style;
		style2.display = style2.display? "":"block";
	}
}

function hideDiv(id)
{
	if (document.getElementById) {
		var style2 = document.getElementById(id).style;
		style2.display = style2.display? "":"hidden";
	} else if (document.all) {
		var style2 = document.all[id].style;
		style2.display = style2.display? "":"hidden";
	} else if (document.layers) {
		var style2 = document.layers[id].style;
		style2.display = style2.display? "":"hidden";
	}
}


function textCounterOld(field, countfield, maxlimit) {
	//eg. textCounter(document.mainform.what, document.mainform.remLen, 125)
	if (field.value.length > maxlimit) {
		field.value = field.value.substring(0, maxlimit);
	} else {
		countfield.value = maxlimit - field.value.length;
	}
}

function textCounter(field, countfield, maxlimit) {
	
	var fwhat = document.mainform.what.value;
	var fwhy = document.mainform.why.value;

	//eg. textCounter(document.mainform.what, document.mainform.remLen, 125)
	if (field.value.length > maxlimit) {
		field.value = field.value.substring(0, maxlimit);
	} else {
		countfield.value = (maxlimit * 2) - fwhat.length - fwhy.length;
	}
}

function popUp(strURL,strType,strHeight,strWidth) {
	var strOptions="";
	if (strType=="console") strOptions="resizable,height="+strHeight+",width="+strWidth;
	if (strType=="fixed") strOptions="status,height="+strHeight+",width="+strWidth;
	if (strType=="elastic") strOptions="toolbar,menubar,scrollbars,resizable,location,height="+strHeight+",width="+strWidth;
	window.open(strURL, 'newWin', strOptions);
}
function popUp2(strURL,strType,strHeight,strWidth) {
	var strOptions="";
	strOptions="status,height="+strHeight+",width="+strWidth;
	window.open(strURL, 'newWin', strOptions);
}

function stopRequest() {
	if (document.all) {
		document.execCommand('Stop');
	} else {
		window.stop();
	}
}


function isJpeg(fn) {
	//alert ("checking filename : "+fn);
	var fna = fn.split(".");
	//alert ("split result : "+fna);
	var ext = fna[fna.length-1].toLowerCase();
	//alert("extension is: "+ext);
	if (ext=='jpg' || ext=='jpeg') {
		return true;
	} else {
		return false;
	}
}


function mysubmit() {
	
	var iconsarray = new Array();
	var selectedfile;
	var selectedicons;

	if(document.getElementById("type").options[document.getElementById("type").selectedIndex].value==1)
	{
		for (var i = 0; i < document.mainform.things.length; i++) 
		{
			if(document.mainform.things[i].checked) 
			{
				iconsarray.push(1);
			} else 
			{
				iconsarray.push(0);	
			}
		}
	}else
	{
		for (var i = 0; i < document.mainform.kidthings.length; i++) 
		{
			if(document.mainform.kidthings[i].checked) 
			{
				iconsarray.push(1);
			} else 
			{
				iconsarray.push(0);	
			}
		}
	}
	selectedicons = iconsarray.join("");

	for (i=0;i<document.mainform.imagenames.length;i++) {
		if (document.mainform.imagenames[i].checked) {
			selectedfile = document.mainform.imagenames[i].value;
			// if on edit page, and it's zero, flag to keep
			if(document.mainform.edit_keep_original_upload && (i==0)) {
				document.mainform.edit_keep_original_upload.value = 'true';
			}
		}
	}

	if(selectedfile=="library")
	{
		selectedfile = document.getElementById("filename2").value;
	}

// VALIDATION

	
	if (selectedfile=="upload" && !document.mainform.Filedata.value) { alert('Please select an image to upload.'); return false }
	
	if (selectedfile=="upload" && !isJpeg(document.mainform.Filedata.value)) { alert('Please make sure your image is a jpeg.'); return false }
	
	if (document.mainform.tou_agree.checked==false) { alert('Please read and agree to the terms of use before proceeding.'); return false }
	
	if (document.mainform.opt_in.checked==false) { alert('Please confirm that you are over 18 or have consent of a guardian before sending your information');  return false }	
	
	//if(selectedfile=="upload") { alert ("Your upload is beginning.	If the page doesn't refresh, your file might be too big. If this happens, stop loading the page, and try again with a different image."); }	

// END VALIDATION
	if (selectedfile=="upload") {showDiv("uploadMsg");}

	document.mainform.icons.value = selectedicons;
	document.mainform.localtimestr.value = getdate();
	document.mainform.filename.value = selectedfile;

	return true;
}

