var preError = "The following errors have been found:\n------------------------------------\n";
var errorString = "";
var postError = "------------------------------------\nPlease correct these errors and re-submit.";
var errorNumber = 0;
var errorNumDot = ". ";



var navRefOne = "";
var navRefTwo = "";

if (document.layers) {
	navRefOne = "document.layers[";
	navRefTwo = "]";
} else if (document.getElementById && !document.all) {
	navRefOne = "document.getElementById(\'";
	navRefTwo = "\').style";
} else if (document.all) {
	navRefOne = "document.all.";
	navRefTwo = ".style";
}

var currentDiv = "intro";
function homePopup(state,pict,divShow) {
	if (state == "over") {
		eval("document." + pict +"Pict.src=" + pict + "PictOn.src");
		eval(navRefOne + "intro" + navRefTwo + ".display = 'none'");
		eval(navRefOne + divShow + navRefTwo + ".display = 'block'");
	} else {
		eval("document." + pict +"Pict.src=" + pict + "PictOff.src");
		eval(navRefOne + currentDiv + navRefTwo + ".display = 'none'");
		eval(navRefOne + "intro" + navRefTwo + ".display = 'block'");
	}
	currentDiv = divShow;
}

function openWindow(i) {
	var newWin = window.open(i, 'samples', 'width=700,height=420,top=0,left=0,resizable,scrollbars=yes,statusbar');
	newWin.focus();
}

var currentMenuDiv = "";
var currentSamplesDiv = "";
var menuStatus = "closed"; /* open or closed */

function showGroup(menuList,samples) {
	var menuDiv = menuList;
	var samplesDiv = samples;

	if (menuDiv == currentMenuDiv) {
		if (menuStatus == "open") {
			eval(navRefOne + currentMenuDiv + navRefTwo + ".display = 'none'");
			eval(navRefOne + currentSamplesDiv + navRefTwo + ".display = 'none'");
			eval(navRefOne + "chooseCategory" + navRefTwo + ".display = 'block'");
			menuStatus = "closed";
		} else {
			eval(navRefOne + currentMenuDiv + navRefTwo + ".display = 'block'");
			eval(navRefOne + currentSamplesDiv + navRefTwo + ".display = 'block'");
			eval(navRefOne + "chooseCategory" + navRefTwo + ".display = 'none'");
			menuStatus = "open";
		}
		currentMenuDiv = menuDiv;
		currentSamplesDiv = samplesDiv;
	} else {
		if (menuStatus == "open") {
			eval(navRefOne + currentMenuDiv + navRefTwo + ".display = 'none'");
			eval(navRefOne + currentSamplesDiv + navRefTwo + ".display = 'none'");
			eval(navRefOne + "chooseCategory" + navRefTwo + ".display = 'block'");
		}

		eval(navRefOne + menuDiv + navRefTwo + ".display = 'block'");
		eval(navRefOne + samplesDiv + navRefTwo + ".display = 'block'");
		eval(navRefOne + "chooseCategory" + navRefTwo + ".display = 'none'");

		currentMenuDiv = menuDiv;
		currentSamplesDiv = samplesDiv;
		menuStatus = "open";
	}
}

function showGroups(menuDiv,samplesDiv) {
	if (samplesDiv == currentSamplesDiv) {
		if (menuStatus == "open") {
			eval(navRefOne + currentSamplesDiv + navRefTwo + ".display = 'none'");
			eval(navRefOne + menuDiv + "ChooseCategory" + navRefTwo + ".display = 'block'");
			menuStatus = "closed";
		} else {
			eval(navRefOne + currentSamplesDiv + navRefTwo + ".display = 'block'");
			eval(navRefOne + menuDiv + "ChooseCategory" + navRefTwo + ".display = 'none'");
			menuStatus = "open";
		}
		currentSamplesDiv = samplesDiv;
	} else {
		if (menuStatus == "open") {
			eval(navRefOne + currentSamplesDiv + navRefTwo + ".display = 'none'");
			eval(navRefOne + menuDiv + "ChooseCategory" + navRefTwo + ".display = 'block'");
		}
		eval(navRefOne + samplesDiv + navRefTwo + ".display = 'block'");
		eval(navRefOne + menuDiv + "ChooseCategory" + navRefTwo + ".display = 'none'");

		currentSamplesDiv = samplesDiv;
		menuStatus = "open";
	}
}

var currentSubMenu = "";
var currentSubMenuStatus = "closed";

function toggleSampleMenu(subMenu) {
	var menuDiv = subMenu;

	if (menuDiv == currentSubMenu) {
		if (currentSubMenuStatus == "open") {
			eval(navRefOne + currentSubMenu + navRefTwo + ".display = 'none'");

			currentSubMenuStatus = "closed";
		} else {
			eval(navRefOne + currentSubMenu + navRefTwo + ".display = 'block'");

			currentSubMenuStatus = "open";
		}
		currentSubMenu = menuDiv;

	} else {
		if (currentSubMenuStatus == "open") {
			eval(navRefOne + currentSubMenu + navRefTwo + ".display = 'none'");
		}
		eval(navRefOne + menuDiv + navRefTwo + ".display = 'block'");

		currentSubMenu = menuDiv;
		currentSubMenuStatus = "open";
	}
}

function sendEmail(whichForm) {
	errorString = "";
	errorNumber = 0;

	if (eval("document." + whichForm + ".dept.value") == "") {
		errorString += "You must select a department! \n";
	} else
	if (eval("document." + whichForm + ".emailAddress.value") == "") {
		errorString += "You must supply an email address! \n";
	} else
	if (checkEmailCharacters(whichForm) == false) {
		errorString += "Email address has illegal characters! \n";
	} else
	if (checkEmailFormat(whichForm) == false) {
		errorString += "Email address format is incorrect! \n";
	} else
	if (eval("document." + whichForm + ".name.value") == "") {
		errorString += "Please supply your name! \n";
	} else
	if (eval("document." + whichForm + ".message.value") == "") {
		errorString += "Please supply a message! \n";
	} else
	if (checkEmailURL(whichForm) == false) {
		errorString += "\"http://\" is NOT allowed in your message! \n";
	} else
	if (checkEmailSample(whichForm) == false) {
		errorString += "Sample Requests are NOT ALLOWED through this form!\nPlease click on the sample button on the left side of this form.\n";
	}
	submitForm(whichForm);
}
function checkEmailFormat(whichForm) {
	var emailAddress = eval("document." + whichForm + ".emailAddress.value");
	var theAt = emailAddress.indexOf("@");
	var theDot = emailAddress.lastIndexOf(".");
	var aSpace = emailAddress.indexOf(" ");

	if (emailAddress != "") {
		if ((theAt != -1) && (theAt != 0) && (theDot != -1) && (theDot > theAt + 1) && (theDot < emailAddress.length - 1) && (aSpace == -1)) {
			return true;
		} else {
			return false;
		}
	}
}
function checkEmailURL(whichForm) {
	var emailMessage = eval("document." + whichForm + ".message.value");
	var theSample = emailMessage.toUpperCase().indexOf("HTTP://");

	if (theSample == -1) {
		return true;
	} else {
		return false;
	}
}
function checkEmailSample(whichForm) {
	var emailMessage = eval("document." + whichForm + ".message.value");
	var theSample = emailMessage.toUpperCase().indexOf("SAMPLE");

	if (theSample == -1) {
		return true;
	} else {
		return false;
	}
}
function checkEmailCharacters(whichForm) {
	var emailAddress = eval("document." + whichForm + ".emailAddress.value");
	var illegalChar = false;
	var theChar = "";
	var illegalChars = "!#$%^&*()/:;,+";
	for (x = 0; x < illegalChars.length; x++) {
		theChar = illegalChars.charAt(x);
		if (emailAddress.indexOf(theChar) != -1) {
			illegalChar = true;
		}
	}
	if (illegalChar == true) {
		return false;
	} else {
		return true;
	}
}
function submitForm(formName) {
	if (errorString != "") {
		alert(preError + errorString + postError);
	} else {
		eval ('document.' + formName + '.submit()');
	}
}

function addTestimonial() {
	var errors = false;
	errorString = "";
	errorNumber = 0;
	var testimonialText = document.addTestimonialForm.testimonialText.value;
	var testimonialSigned = document.addTestimonialForm.testimonialSigned.value;
	if (testimonialText == "") {
		errors = true;
		errorNumber++;
		errorString += errorNumber + errorNumDot + "Please enter a testimonial.\n";
	}
	if (testimonialSigned == "") {
		errors = true;
		errorNumber++;
		errorString += errorNumber + errorNumDot + "Please enter your signature.\n";
	}
	if (!errors) {
		document.addTestimonialForm.submit();
	} else {
		alert(preError + errorString + postError);
	}
}

function showTestimonial() {
	eval(navRefOne + "testimonials" + navRefTwo + ".display = 'none'");
	eval(navRefOne + "addTestimonial" + navRefTwo + ".display = 'block'");
}

function loadIframe(iframeName, newurl) {
  if (window.frames[iframeName]) {
    frames[iframeName].location.replace(newurl);
    return false;
  } else {
	  return true;
	}
}

var ie=document.all;
var ns6=document.getElementById&&!document.all;

function ietruebody(){
return (document.compatMode && document.compatMode!="BackCompat" && !window.opera)? document.documentElement : document.body;
}

function enlarge(which, e, position, imgwidth, imgheight, addhtml){
if (ie||ns6){
	crossobj=document.getElementById? document.getElementById("showimage") : document.all.showimage;
	if (position=="center"){
		pgyoffset=ns6? parseInt(pageYOffset) : parseInt(ietruebody().scrollTop);
		horzpos=ie? ietruebody().scrollLeft+ietruebody().clientWidth/2-imgwidth/2 : pageXOffset+window.innerWidth/2-imgwidth/2;
		vertpos=ie? pgyoffset+ietruebody().clientHeight/2-imgheight/2 : pgyoffset+window.innerHeight/2-imgheight/2;
		if (window.opera && window.innerHeight) //compensate for Opera toolbar
		vertpos=pgyoffset+window.innerHeight/2-imgheight/2;
		vertpos=Math.max(pgyoffset, vertpos);
	}
	else{
		var horzpos=ie? ietruebody().scrollLeft+event.clientX : pageXOffset+e.clientX;
		var vertpos=ie? ietruebody().scrollTop+event.clientY : pageYOffset+e.clientY;
	}
	crossobj.style.left=horzpos+"px";
	crossobj.style.top=vertpos+"px";

	crossobj.innerHTML='<div align="right" id="dragbar" style="width:' + (imgwidth - 2) + 'px;"><span id="closetext" onClick="closepreview()" style="text-align:right">Close</span> </div><img id="largei" src="'+which+'">';
	crossobj.style.visibility="visible";
	if (BrowserDetect.browser == "Explorer" && BrowserDetect.version < 7){
		imgobj=document.getElementById? document.getElementById("largei") : document.all.largei;
		setTimeout("imgobj.src='"+which+"'", 500);
	}
	
//	enlargeShowSelects();
	return false;
	}
else //if NOT IE 4+ or NS 6+, simply display image in full browser window
	return true;
}

function closepreview(){
crossobj.style.visibility="hidden";
//enlargeHideSelects();
}

function drag_drop(e){
if (ie&&dragapproved){
	crossobj.style.left=tempx+event.clientX-offsetx+"px";
	crossobj.style.top=tempy+event.clientY-offsety+"px";
}
else if (ns6&&dragapproved){
	crossobj.style.left=tempx+e.clientX-offsetx+"px";
	crossobj.style.top=tempy+e.clientY-offsety+"px";
}
return false
}

function initializedrag(e){
if (ie&&event.srcElement.id=="dragbar"||ns6&&e.target.id=="dragbar"){
	offsetx=ie? event.clientX : e.clientX;
	offsety=ie? event.clientY : e.clientY;

	tempx=parseInt(crossobj.style.left);
	tempy=parseInt(crossobj.style.top);

	dragapproved=true;
	document.onmousemove=drag_drop;
}
}

document.onmousedown=initializedrag;
document.onmouseup=new Function("dragapproved=false");

//function popAnswer(which, e, position, imgwidth, imgheight, addhtml){
//if (ie||ns6){
//	crossobj=document.getElementById? document.getElementById("showAnswer") : document.all.showAnswer;
//		pgyoffset=ns6? parseInt(pageYOffset) : parseInt(ietruebody().scrollTop);
//		horzpos=ie? ietruebody().scrollLeft+ietruebody().clientWidth/2-imgwidth/2 : pageXOffset+window.innerWidth/2-imgwidth/2;
//		vertpos=ie? pgyoffset+ietruebody().clientHeight/2-imgheight/2 : pgyoffset+window.innerHeight/2-imgheight/2;
//		if (window.opera && window.innerHeight) //compensate for Opera toolbar
//		vertpos=pgyoffset+window.innerHeight/2-imgheight/2;
//		vertpos=Math.max(pgyoffset, vertpos);
//	crossobj.style.left=horzpos+"px";
//	crossobj.style.top=vertpos+"px";
//	crossobj.innerHTML='<div align="right" id="dragbar" style="width:' + (imgwidth - 2) + 'px;"><span id="closetext" onClick="closepreview()">Close</span> </div>'+which+'<br>';
//	crossobj.style.visibility="visible";
//	return false;
//	}
//else //if NOT IE 4+ or NS 6+, simply display image in full browser window
//	return true;
//}

function getSelectValue(selectObject) {
return selectObject.options[selectObject.selectedIndex].value;
}
function getRadioValue(selectObject) {
   var checkedButton = "";
    for (var i = 0; i < selectObject.length; i++) {
      if (selectObject[i].checked) {
         checkedButton=selectObject[i].value;
      }
   }
return checkedButton;
}
function select(field) {
field.focus();
field.select();
}

function nextTip() {
	var showDiv, hideDiv;
	hideDiv = "hotTip".concat(currentTipNum);
	currentTipNum++;
	if(currentTipNum > maxTipNum) {
		currentTipNum = 0;
	}
	showDiv = "hotTip".concat(currentTipNum);
	eval(navRefOne + hideDiv + navRefTwo + ".display = 'none'");
	eval(navRefOne + showDiv + navRefTwo + ".display = 'block'");
}
	
function emailDesign() {
	if (checkErrors()) {
		alert(preError + errorString + postError);
	} else {
		document.addCartForm.cart_url.value = getPictUrl();
		edesignPopup();
	}		
}	
function printDesign() {
	document.printDesignForm.print_url.value = getPictUrl();
	document.printDesignForm.submit();		
}	
