
function makeImageVisible(activeImage, activePlus) {
	document.getElementById(currentImage).style.display= "none";
	document.getElementById(currentPlus).style.display= "none";
	currentImage = activeImage;
	currentPlus = activePlus;
	document.getElementById(currentImage).style.display = "block";
	document.getElementById(currentPlus).style.display = "block";
}

function getMoveStatus(currMove) {
	var theLeft = document.getElementById('imageBoxInside').style.left;

	theLeft = parseInt(theLeft.replace('px',''));
	if (isNaN(theLeft)) {
		theLeft = 0;
	}
	
	if (currMove == 'next') {
		theLeft = theLeft - validWImg;
	}
	else {
		theLeft = theLeft + validWImg;
	} 
	
	if (theLeft == leftLimit) {
		return false;
	} else if (theLeft > 0) {
		return false;
	} else {
		return true;
	}
	return true;
}

function moveToPrevious() {
	var validMove = getMoveStatus('prev');
	if (validMove) {
		new Effect.Move('imageBoxInside', { x: validWImg, y: 0, transition: Effect.Transitions.sinoidal, duration: 0.1  });
	}
}

function moveToNext() {
	var validMove = getMoveStatus('next');
	if (validMove) {
		new Effect.Move('imageBoxInside', { x: (0-validWImg), y: 0, transition: Effect.Transitions.sinoidal, duration: 0.1  });
	}
}

function moveToNextLoad(spots) {
	var validMove = getMoveStatus('next');
	if(validMove) {
		new Effect.Move('imageBoxInside', { x: (0-validWImg), y: 0, transition: Effect.Transitions.sinoidal, queue: 'front', duration: 0 });
		if (spots == 2)
			new Effect.Move('imageBoxInside', { x: (0-validWImg), y: 0, transition: Effect.Transitions.sinoidal, queue: 'end', duration: 0  });
	}
}


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, 1200);
		curImage = 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 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;}

function validateDistributorAndRetailer(theForm) {  var reason = "";  reason += validateName(theForm.name);  reason += validateAddress(theForm.address);
  reason += validateCity(theForm.city);
  reason += validateTelephone(theForm.telephone);
  reason += validateEmail(theForm.email);        if (reason != "") {    alert("Some of the fields need correction:\n" + reason);    return false;  }  theForm.submit();  return true;}

function validateName(fld) {    var error = "";    if (fld.value == "") {        error = "You didn't enter a name.\n";    }
    return error;}

function validateAddress(fld) {    var error = "";    if (fld.value == "") {        error = "You didn't enter an address.\n";    }
    return error;}

function validateCity(fld) {    var error = "";    if (fld.value == "") {        error = "You didn't enter a city.\n";    }
    return error;}


function validateStateRegion(fld) {    var error = "";    if (fld.value == "") {        error = "You didn't enter a state or region.\n";    }
    return error;}

function validateTelephone(fld) {    var error = "";    if (fld.value == "") {        error = "You didn't enter a phone number.\n";    }
    return error;}

function validateEmail(fld) {    var error = "";    if (fld.value == "") {        error = "You didn't enter an email address.\n";    }
    return error;}

