﻿function pcTermsPop() {
	pcTerms = window.open("", "pcTerms", "width=550,height=514");
}
function pcPrivacyPop() {
	pcPrivacy = window.open("", "pcPrivacy", "width=550,height=391");
}

function selectCategory(index) {
	document.forms[0].hidCategory.value = index;
	for (x=0; x<4; x++) {
		//toggling button images
		img = document.getElementById("categoryImg" + x);
		imgSrcBase = img.src.split(".gif").join("").split("_on").join("");
		img.src = imgSrcBase + ((x==index) ? "_on.gif" : ".gif");
		//toggling selects
		document.getElementById("categoryContent" + x).style.display = (x==index) ? "block" : "none";
	}
	
	//resetting dropdowns
	select0 = document.getElementById("hidCategory" + index + "select0");
	select1 = document.getElementById("hidCategory" + index + "select1");
	if (select0) select0.selectedIndex = 0;
	if (select1) {
		for (x = select1.options.length-1; x>0; x--)
			select1.options[x] = null;
		select1.style.display = "none";
		}
			
	//validating
	validateScreen2();
	
}

function populateSecondaryDropdown() {
	category = parseInt(document.forms[0].hidCategory.value);
	select0 = document.getElementById("category0select0");
	select1 = document.getElementById("category0select1");
	
	//removing pre-existing options
	select1.selectedIndex = 0;
	for (x = select1.options.length-1; x>0; x--) select1.options[x] = null;
	
	//populating select1
	switch (select0.selectedIndex) {
		case 0:
			break;
		case 1:
			break;
		case 2:
			break;
		case 3:
			select1.options[1] = new Option("Text", "text");
			select1.options[2] = new Option("Attachment", "attachment");
			break;
		case 4:
		  select2 = document.getElementById("category2select0"); // copy from cheating
			for (x = 1; x < select2.options.length; x++) select1.options[x] = new Option(select2.options[x].text, select2.options[x].value);
			break;
	}
	
	//showing/hiding select1, depending if options exist
	select1.style.display = (select1.options.length > 1) ? "block" : "none";
}

function validateScreen2() {
	validated = false;
	category = parseInt(document.forms[0].hidCategory.value);
	select0 = document.getElementById("hidCategory" + category + "select0");
	select1 = document.getElementById("hidCategory" + category + "select1");
	if (select0 && select1) {
		if (select0.selectedIndex > 0 && (select1.selectedIndex > 0 || select1.options.length == 1)) validated = true;
	} else {
		if (select0) {
			if (select0.selectedIndex > 0) validated = true;
		} else {
			validated = true;
		}
	}

	//enabling submit
	document.getElementById("submitDisabled").style.display = (validated) ? "none" : "inline";
	document.getElementById("submitEnabled").style.display = (validated) ? "inline" : "none";

}