
function toggleColor (colorID) {
	var toHide = "img" + curColor;
	var toAppear = "img" + colorID;
	if (curColor > 0) {
		Effect.Fade(toHide, {duration:1});
	}
	Effect.Appear(toAppear, {duration:1});
	curColor = colorID;
}

function rotateText() {
	if(playingText) {
		var toFade = "news" + curText;
		var appearId = curText + 1;
		if (appearId > limitText) { appearId = 1; }
		var toAppear = "news" + appearId;
		Effect.Fade(document.getElementById(toFade), {duration:2});
		var timStri = "Effect.Appear('" + toAppear + "', {duration:2})";
		setTimeout(timStri, 1200);
		curText = appearId;
	}
}

function togglePlayText() {
	if (playingText) { playingText = false; } else { playingText = true; }
}

function rotateImage() {
	if(playing) {
		var toFade = "img" + curImage;
		var appearId = curImage + 1;
		if (appearId > limit) { appearId = 1; }
		var toAppear = "img" + appearId;
		Effect.Fade(toFade, {duration:2});
		var timStri = "Effect.Appear('" + toAppear + "', {duration:2})";
		setTimeout(timStri, 300);
		curImage = appearId;
	}
}

function rotateImage2() {
	if(playing2) {
		var toFade = "sponsor" + curImage2;
		var appearId = curImage2 + 1;
		if (appearId > limit2) { appearId = 1; }
		var toAppear = "sponsor" + appearId;
		Effect.Fade(toFade, {duration:2});
		var timStri = "Effect.Appear('" + toAppear + "', {duration:2})";
		setTimeout(timStri, 300);
		curImage2 = appearId;
	}
}

function togglePlay() {
	if (playing) { playing = false; } else { playing = true; }
}

function validateFormOnSubmit(theForm) {	var reason = "";
	reason += validateCompatibility(theForm.compatibility);
	reason += validateCompound(theForm.compound);
	reason += validateColor(theForm.color);
	reason += validateNumber(theForm.quantity);      
    if (reason != "") {    	alert("Some of the fields need correction:\n" + reason);    	return false;  	}
  	theForm.submit();  	return true;}

function validateFormOnSubmit(theForm) {	var reason = "";
	
	reason += validateText(theForm.company, "company name", "a");
	reason += validateText(theForm.contact, "contact person", "a");
	reason += validateText(theForm.email, "email address", "an");
	reason += validateText(theForm.website, "website", "a");
	reason += validateText(theForm.address, "address", "an");
	reason += validateText(theForm.lines, "lines to be shown", "the");
	reason += validateTotal(theForm.booth_deposit, "paying today amount");
	reason += validateNumber(theForm.booth_deposit);
	
    if (reason != "") {    	alert("Some of the fields need correction:\n" + reason);    	return false;  	}
  	theForm.submit();  	return true;}

function validateText(fld, fldname, trans) {
	var error = "";    if (fld.value == "") {        error = "You didn't provide " + trans + " " + fldname + ".\n";    }
    return error;
}

function validateTotal(fld, fldname) {
	var error = "";    if (fld.value == "") {        error = "The " + fldname + " could not be calculated.  Please make sure that all of your entries are numbers.\n";    }
    return error;
}


function validateDonutzFormOnSubmit(theForm) {	var reason = "";
	reason += validatePack(theForm.pack);
	if ((getPackId(theForm.pack)) != 2) 
		reason += validateColor(theForm.color);
	reason += validateNumber(theForm.quantity);      
    if (reason != "") {    	alert("Some of the fields need correction:\n" + reason);    	return false;  	}
  	theForm.submit();  	return true;}

function validateSocksFormOnSubmit(theForm) {	var reason = "";
	reason += validateSize(theForm.size);
	reason += validateNumber(theForm.quantity);      
    if (reason != "") {    	alert("Some of the fields need correction:\n" + reason);    	return false;  	}
  	theForm.submit();  	return true;}

function validateShirtsFormOnSubmit(theForm) {	var reason = "";
	reason += validateSize(theForm.size);
	reason += validateColor(theForm.color);
	reason += validateNumber(theForm.quantity);      
    if (reason != "") {    	alert("Some of the fields need correction:\n" + reason);    	return false;  	}
  	theForm.submit();  	return true;}

function validateSelectionFormOnSubmit(theForm) {	var reason = "";

	for (i=theForm.producttype.length-1; i>-1; i--) 
	{		if (theForm.producttype[i].checked) {			myOption = i; 
			i = -1;
		}	}
	
	if (myOption == 0)
		document.location.href = "order-hudz.php";
	else if (myOption == 1)
		document.location.href = "order-donutz.php";
	else if (myOption == 2)
		document.location.href = "order-shirts.php";
	else if (myOption == 3)
		document.location.href = "order-socks.php";
  	return true;}


function validateCompatibility(fld) {	var myOption = -1;	for (i=fld.length-1; i>-1; i--) 
	{		if (fld[i].checked) {			myOption = i; 
			i = -1;
		}	}    var error = "";    if (myOption == -1) {        error = "You did not select a compatibility.\n"    } else {    }    return error;  }

function validateCompound(fld) {	var myOption = -1;	for (i=fld.length-1; i>-1; i--) 
	{		if (fld[i].checked) {			myOption = i; 
			i = -1;
		}	}    var error = "";    if (myOption == -1) {        error = "You did not select a compound.\n"    } else {    }    return error;  }

function validateSize(fld) {	var myOption = -1;	for (i=fld.length-1; i>-1; i--) 
	{		if (fld[i].checked) {			myOption = i; 
			i = -1;
		}	}    var error = "";    if (myOption == -1) {        error = "Please select a size.\n"    } else {    }    return error;  }

function validateColor(fld) {	var myOption = -1;	for (i=fld.length-1; i>-1; i--) 
	{		if (fld[i].checked) {			myOption = i; 
			i = -1;
		}	}    var error = "";    if (myOption == -1) {        error = "Please select a color.\n"    } else {    }    return error;  }

function validatePack(fld) {	var myOption = -1;	for (i=fld.length-1; i>-1; i--) 
	{		if (fld[i].checked) {			myOption = i; 
			i = -1;
		}	}    var error = "";    if (myOption == -1) {        error = "Please select the type of pack (30, 250, or 560).\n"    } else {    }    return error;  }


function getPackId(fld) {	var myOption = -1;	for (i=fld.length-1; i>-1; i--) 
	{		if (fld[i].checked) {			myOption = i; 
			i = -1;
		}	}    return myOption;  }

function validateNumber(fld) {    var error = "";    var stripped = fld.value.replace(/[\(\)\.\-\ ]/g, '');       if (fld.value == "" || fld.value == "0") {        error = "You didn't enter a quantity.\n";    } else if (isNaN(parseInt(stripped))) {        error = "The quantity is not a number.\n";    }
    return error;}

