function showProducts(productType) { 
	hideAllProducts();
	document.getElementById(productType).style.visibility = 'visible';
}
	

function test() {
alert('test');
}


function RankFactorImg ( ClickedItem, numItems ) {
	document.forms[0].name = "theForm";
	if(document.forms.theForm[ClickedItem].value != "") {return}
	var nextRank = 1
	for(var i=1;i<=numItems;i++) {
		var theElement = ClickedItem.substring(0,ClickedItem.length - String(numItems).length) + String(i)
		if (document.forms.theForm[theElement].value>=nextRank) {
			nextRank = parseInt(document.forms.theForm[theElement].value) +1
		}
	}
	document.forms.theForm[ClickedItem].value = nextRank
}


function RankFactor ( field, numItems ) {
	
	ClickedItem = field.name;
//	alert (ClickedItem);
	document.forms[0].name = "theForm";
	if(document.forms.theForm[ClickedItem].value != "") {return}
	var nextRank = 1
	for(var i=1;i<=numItems;i++) {
		var theElement = ClickedItem.substring(0,ClickedItem.length - String(numItems).length) + String(i)
	//	var theElement = ClickedItem.substring(0,ClickedItem.length - String(numItems).length) + String(i)
		//	alert(theElement);
		if (document.forms.theForm[theElement].value>=nextRank) {
			nextRank = parseInt(document.forms.theForm[theElement].value) +1;
		}
	}
	document.forms.theForm[ClickedItem].value = nextRank
//	alert("all done!");
	
}
// uses the common string in the field names to make determining the value easier if the the total number of elements is in the double digits
function RankFactorB ( field, numItems, mainname ) {
	ClickedItem = field.name;
	document.forms[0].name = "theForm";
	if(document.forms.theForm[ClickedItem].value != "") {return}
	var nextRank = 1
	for(var i=1;i<=numItems;i++) {
		var theElement = String(mainname) + String(i)
		if (document.forms.theForm[theElement].value>=nextRank) {
			nextRank = parseInt(document.forms.theForm[theElement].value) +1;
		}
	}
	document.forms.theForm[ClickedItem].value = nextRank
	
}


function clearChoices(mystring) {
	document.forms[0].name = "theForm";
	elements = document.forms.theForm.length;
	i = 0;
	for(var i=0;i<elements;i++) {
		if (document.forms.theForm[i].name.indexOf(mystring) != -1) {
			document.forms.theForm[i].value = "";
		}
	}
}



//function used by amenities editor to switch field content
function clickedElm(element) 
{
var index = 0;
// I ran into trouble using an equal sign in the condition statement of the for loop so rather than trace the infinite loop problem, I took the easy way out and created a variable, cycle, and set it to 1 greater than the form element array so I could use the less than sign
var lenAnd1 = document.forms[1].elements.length + 1;
 for (var i = 0; i < lenAnd1; i++) 
	{
		if (document.forms[1].elements[i] == element) 
		{
		index = i;
		}
	}
	
	//switch the select elements
//	select1 = index -1;
//	select2 = index +2;
//	sv1 = document.forms[0].elements[select1].selectedIndex;
//	sv2 = document.forms[0].elements[select2].selectedIndex;
//	document.forms[0].elements[select1].selectedIndex = sv2;
//	document.forms[0].elements[select2].selectedIndex = sv1;

	// switch the text fields
	var text1 = index -1;
	var text2 = index +1;
	a = document.forms[1].elements[text1].value;
	b = document.forms[1].elements[text2].value;
	document.forms[1].elements[text1].value = b;
	document.forms[1].elements[text2].value = a;
	// force browser to update content of text fields
	document.forms[1].elements[text1].focus();
	document.forms[1].elements[text2].focus();
	document.forms[1].elements[text2].blur();

//don't submit form
return false;

}

var newwin;

function launchwin(winurl,winname,winfeatures)
{
	//This launches a new window and then
	//focuses it if window.focus() is supported.
	newwin = window.open(winurl,winname,winfeatures);
	
	if(javascript_version > 1.0)
	{
		//delay a bit here because IE4 encounters errors
		//when trying to focus a recently opened window
 		setTimeout('newwin.focus();',250);
	}
}

//Checks length of textarea to make sure length is compatible with database field allowance
function checkchars(cur) {
var error = "";
var maxlength = 150;
if (cur.value.length > maxlength) {
error = "Please shorten your amenity description. \nIt must be less than " + maxlength + " characters.";
}

if (error) {
alert(error);
return false;
} else {
return false;
}
}

//Field validation
//Only numbers
function validateNum(field) {
var valid = "0123456789"
var ok = "yes";
var temp;
for (var i=0; i<field.value.length; i++) {
temp = "" + field.value.substring(i, i+1);
if (valid.indexOf(temp) == "-1") ok = "no";
}
if (ok == "no") {
alert("Please change your entry. Only numbers are permitted.");
field.focus();
field.select();
   }
}

//No special characters
function isProper(fieldString) {
   string = fieldString.value;
   if (!string) return false;
   stringStatus = "good";
   var iChars = "*|,\":<>[]{}`\';()@&$#%";
   for (var i = 0; i < string.length; i++) {
      if (iChars.indexOf(string.charAt(i)) != -1)
      	stringStatus = "bad";    
   }
   if (stringStatus == "bad") {
   	alert("Please change your entry. Special characters are not permitted.");
   	} else {
   return false;
   }
}

 function copyAddress()
 {
 document.forms.addressInfo.contactFirst2.value = document.forms.addressInfo.contactFirst.value;
// document.forms[0].contactMI2.value = document.forms[0].contactMI.value;
document.forms.addressInfo.contactLast2.value = document.forms.addressInfo.contactLast.value;
document.forms.addressInfo.company2.value = document.forms.addressInfo.company.value;
document.forms.addressInfo.phone2.value = document.forms.addressInfo.phone.value;
// document.forms[0].fax2.value = document.forms[0].fax.value;
  document.forms.addressInfo.address12.value = document.forms.addressInfo.address1.value;
    document.forms.addressInfo.address22.value = document.forms.addressInfo.address2.value;
      document.forms.addressInfo.city2.value = document.forms.addressInfo.city.value;
document.forms.addressInfo.state2.options.selectedIndex = document.forms.addressInfo.state.options.selectedIndex;
document.forms.addressInfo.zip2.value = document.forms.addressInfo.zip.value;
document.forms.addressInfo.country2.value = document.forms.addressInfo.country.value;
 }

/*
 function copyAddress()
 {
 document.forms[0].contactFirst2.value = document.forms[0].contactFirst.value;
// document.forms[0].contactMI2.value = document.forms[0].contactMI.value;
document.forms[0].contactLast2.value = document.forms[0].contactLast.value;
document.forms[0].company2.value = document.forms[0].company.value;
document.forms[0].phone2.value = document.forms[0].phone.value;
// document.forms[0].fax2.value = document.forms[0].fax.value;
  document.forms[0].address12.value = document.forms[0].address1.value;
    document.forms[0].address22.value = document.forms[0].address2.value;
      document.forms[0].city2.value = document.forms[0].city.value;
document.forms[0].state2.options.selectedIndex = document.forms[0].state.options.selectedIndex;
document.forms[0].zip2.value = document.forms[0].zip.value;
document.forms[0].country2.value = document.forms[0].country.value;
 }
 */
 
 function noBlank(field) {
 	if (field.value == "") {
 		field.value = 1;
 	}
 } 
 

function hideAllProducts() { 
document.getElementById('stickersA').style.visibility = 'hidden'
document.getElementById('stickersB').style.visibility = 'hidden'
document.getElementById('stickersC').style.visibility = 'hidden'
document.getElementById('stickersD').style.visibility = 'hidden'
document.getElementById('stickersE').style.visibility = 'hidden'
document.getElementById('stickersF').style.visibility = 'hidden'
document.getElementById('stickersG').style.visibility = 'hidden'
document.getElementById('stickersH').style.visibility = 'hidden'
document.getElementById('stickersI').style.visibility = 'hidden'
document.getElementById('stickersJ').style.visibility = 'hidden'
document.getElementById('stickersK').style.visibility = 'hidden'
document.getElementById('stickersL').style.visibility = 'hidden'
document.getElementById('stickersM').style.visibility = 'hidden'
document.getElementById('stickersN').style.visibility = 'hidden'
document.getElementById('stickersO').style.visibility = 'hidden'
document.getElementById('stickersP').style.visibility = 'hidden'
document.getElementById('stickersQ').style.visibility = 'hidden'
document.getElementById('stickersR').style.visibility = 'hidden'
document.getElementById('stickersS').style.visibility = 'hidden'
document.getElementById('stickersT').style.visibility = 'hidden'
document.getElementById('stickersU').style.visibility = 'hidden'
document.getElementById('stickersV').style.visibility = 'hidden'
document.getElementById('stickersW').style.visibility = 'hidden'
document.getElementById('stickersX').style.visibility = 'hidden'
document.getElementById('stickersY').style.visibility = 'hidden'
document.getElementById('stickersZ').style.visibility = 'hidden'
document.getElementById('stickerGrabBag').style.visibility = 'hidden'
document.getElementById('kits').style.visibility = 'hidden'
document.getElementById('adhesives').style.visibility = 'hidden'
document.getElementById('books').style.visibility = 'hidden'
document.getElementById('embellish').style.visibility = 'hidden'
document.getElementById('gift').style.visibility = 'hidden'
document.getElementById('lettering').style.visibility = 'hidden'
document.getElementById('library').style.visibility = 'hidden'
document.getElementById('pack12').style.visibility = 'hidden'
document.getElementById('pack8').style.visibility = 'hidden'
document.getElementById('pages').style.visibility = 'hidden'
document.getElementById('pattern12').style.visibility = 'hidden'
document.getElementById('pattern8').style.visibility = 'hidden'
document.getElementById('postbound').style.visibility = 'hidden'
document.getElementById('punches').style.visibility = 'hidden'
document.getElementById('solid12').style.visibility = 'hidden'
document.getElementById('solid8').style.visibility = 'hidden'
document.getElementById('spiral').style.visibility = 'hidden'
document.getElementById('templates').style.visibility = 'hidden'
document.getElementById('universal').style.visibility = 'hidden'
document.getElementById('classic').style.visibility = 'hidden'
document.getElementById('cutting').style.visibility = 'hidden'
document.getElementById('diecuts').style.visibility = 'hidden'
document.getElementById('writing').style.visibility = 'hidden'
document.getElementById('misc').style.visibility = 'hidden'
document.getElementById('pagesClassic').style.visibility = 'hidden'
document.getElementById('pagesLibrary').style.visibility = 'hidden'
document.getElementById('pagesPostBound').style.visibility = 'hidden'
document.getElementById('pagesUniversal').style.visibility = 'hidden'
document.getElementById('pagesSpiral').style.visibility = 'hidden'
document.getElementById('rubons').style.visibility = 'hidden'
document.getElementById('irregular3Ring').style.visibility = 'hidden'
document.getElementById('irregularPost').style.visibility = 'hidden'
document.getElementById('irregularPost8x8').style.visibility = 'hidden'
}

function findPosX(obj)
{
        var curleft = 0;
        if (obj.offsetParent)
        {
                while (obj.offsetParent)
                {
                        curleft += obj.offsetLeft
                        obj = obj.offsetParent;
                }
        }
        else if (obj.x)
                curleft += obj.x;
        return curleft;
}

function findPosY(obj)
{
        var curtop = 0;
        if (obj.offsetParent)
        {
                while (obj.offsetParent)
                {
                        curtop += obj.offsetTop
                        obj = obj.offsetParent;
                }
        }
        else if (obj.y)
                curtop += obj.y;
        return curtop;
}


function positionProdDivs() {
alert('positionProdDivs called');
var yVal = findPosY(document.getElementById('positioner'));
alert(yVal);
document.getElementById('kits').style.top = yVal + 25
document.getElementById('adhesives').style.top = yVal + 25
document.getElementById('animal').style.top = yVal + 25
document.getElementById('baby').style.top = yVal + 25
document.getElementById('books').style.top = yVal + 25
document.getElementById('disney').style.top = yVal + 25
document.getElementById('embellish').style.top = yVal + 25
document.getElementById('fun').style.top = yVal + 25
document.getElementById('gift').style.top = yVal + 25
document.getElementById('holiday').style.top = yVal + 25
document.getElementById('jolee').style.top = yVal + 25
document.getElementById('letter').style.top = yVal + 25
document.getElementById('lettering').style.top = yVal + 25
document.getElementById('library').style.top = yVal + 25
document.getElementById('love').style.top = yVal + 25
document.getElementById('mary').style.top = yVal + 25
document.getElementById('pack12').style.top = yVal + 25
document.getElementById('pack8').style.top = yVal + 25
document.getElementById('pages').style.top = yVal + 25
document.getElementById('party').style.top = yVal + 25
document.getElementById('pattern12').style.top = yVal + 25
document.getElementById('pattern8').style.top = yVal + 25
document.getElementById('postbound').style.top = yVal + 25
document.getElementById('punches').style.top = yVal + 25
document.getElementById('school').style.top = yVal + 25
document.getElementById('scissors').style.top = yVal + 25
document.getElementById('cleaning').style.top = yVal + 25
document.getElementById('seasonal').style.top = yVal + 25
document.getElementById('solid12').style.top = yVal + 25
document.getElementById('solid8').style.top = yVal + 25
document.getElementById('spiral').style.top = yVal + 25
document.getElementById('sports').style.top = yVal + 25
document.getElementById('straphinge').style.top = yVal + 25
document.getElementById('templates').style.top = yVal + 25
document.getElementById('travel').style.top = yVal + 25
document.getElementById('tropical').style.top = yVal + 25
document.getElementById('universal').style.top = yVal + 25
document.getElementById('classic').style.top = yVal + 25
document.getElementById('cutting').style.top = yVal + 25
document.getElementById('diecuts').style.top = yVal + 25
document.getElementById('writing').style.top = yVal + 25
document.getElementById('misc').style.top = yVal + 25
document.getElementById('layer1').style.top = yVal + 10;

}

function openNewWindow(URLtoOpen, windowName, windowFeatures) {
newWindow=window.open(URLtoOpen, windowName, windowFeatures); }

function findPosX(obj)
{
        var curleft = 0;
        if (obj.offsetParent)
        {
                while (obj.offsetParent)
                {
                        curleft += obj.offsetLeft
                        obj = obj.offsetParent;
                }
        }
        else if (obj.x)
                curleft += obj.x;
        return curleft;
}

function findPosY(obj)
{
        var curtop = 0;
        if (obj.offsetParent)
        {
                while (obj.offsetParent)
                {
                        curtop += obj.offsetTop
                        obj = obj.offsetParent;
                }
        }
        else if (obj.y)
                curtop += obj.y;
        return curtop;
}

function halfShipping() {
 
	window.open('/cgi-bin/WebObjects/cmStore.woa/wa/applycoupon?code=HalfShip','Shipping','width=400,height=350,resizable=yes,menubar=yes,scrollbars=yes');
	}
	
function clearCCInfo() {
alert('clearing cc info');
	var theForm = document.paymentInfo;
	theForm.CARDNUM.value = "";
	theForm.CSC.value = "";
}
	
function validatePymtInfo() {
var numbers = "0123456789";
 var theForm = document.paymentInfo;
if (theForm.CARDNUM.value == "") {
	alert('Please enter your credit card number');
	return false;
} else {
	// extract only numbers from user entered credit card number
	var numString = "";
	for (i = 0; i < theForm.CARDNUM.value.length; i++) {
		num = theForm.CARDNUM.value.charAt(i);
		if (numbers.indexOf(num) >= 0) {
			numString = numString + num;
		}
	}
	if (numString.length == 0) {
		alert('Please enter your credit card number');
		return false;
	} else if (numString.length < 12) {
		alert('Your credit card number is too short. Please re-enter it.');
		return false;
	} else if (numString.length > 32) {
		alert('Your credit card number is too long. Please re-enter it.');
		return false;
	} else {
		theForm.CARDNUM.value = numString;
		//alert('CARDNUM: ' + theForm.CARDNUM.value);
	}
}
if (theForm.CSC.value == "") {
	alert('Please enter your CSC number');
	return false;
} else {
// extract only numbers from user CSC number
	var numString2 = "";
	for (i = 0; i < theForm.CSC.value.length; i++) {
		num2 = theForm.CSC.value.charAt(i);
		if (numbers.indexOf(num2) >= 0) {
			numString2 = numString2 + num2;
		}
	}
	if (numString2.length == 0) {
		alert('Please enter your credit card CSC number');
		return false;
	} else if (numString2.length < 3) {
		alert('Your CSC number is too short. Please re-enter it.');
		return false;
	} else if (numString2.length > 4) {
		alert('Your CSC number is too long. Please re-enter it.');
		return false;
	} else {
		theForm.CSC.value = numString2;
		//alert('CSC: ' + theForm.CSC.value);
	}
}
theForm.EXPDATE.value = "";
var today = new Date();
	var todayYear = today.getYear();
	if (todayYear < 1000) {
		todayYear = todayYear + 1900;
	}
	var todayMonth = today.getMonth() + 1;
	var selectedMonth = theForm.month.options[theForm.month.selectedIndex].value;
	var selectedYear = theForm.year.options[theForm.year.selectedIndex].value;
	if (selectedYear < todayYear) {
	alert ('Please enter a valid expiration date');
	return false;
	} else if ((selectedYear == todayYear) && (selectedMonth < todayMonth)) {
	alert('Please enter a valid expiration date');
	return false;
	}  else {
	theForm.EXPDATE.value = selectedMonth + selectedYear;
//	alert('exp date: ' + theForm.EXPDATE.value);
	}
	theForm.submit();
}

function calculateWholesalePrice() {
var theForm = document.forms[0];
if (((theForm.wholesalePrice.value == null) || (theForm.wholesalePrice.value == '')) && (theForm.retailPrice.value != null) && (theForm.retailPrice.value != '')) {
	var retail = theForm.retailPrice.value;
	if (retail.charAt(0) == '$') { 
		retail = retail.substring(1);
		
	}
	var wholesale = retail * .70;
	theForm.wholesalePrice.value = Math.round(wholesale*100)/100; // round to 2 decimal places
	}
}

function RunHeader1(tab)
{
    //alert(tab);
    document.write('<object classid="clsid:D27CDB6E-AE6D-11cf-96B8-444553540000" height="166" width="750">\n');
    document.write('<param name="movie" value="http://www.collectedmemories.com/cmheader.swf?tab=' + tab + '">\n');
    document.write('<param name="quality" value="best">\n');
    document.write('<param name="play" value="true">\n');
    document.write('<embed quality=best src="http://www.collectedmemories.com/cmheader.swf?tab="' + tab + ' width=750 type="application/x-shockwave-flash" play=true height=166>\n');
    document.write('</object>\n');
}

function RunHeader2(tab)
{
    document.write('<object classid=clsid:D27CDB6E-AE6D-11cf-96B8-444553540000 height=166 width=750>\n');
    document.write('<param name=movie value="http://www.collectedmemories.com/cmheader.swf?tab=' + tab + '&secure=yes">\n');
    document.write('<param name=quality value=best>\n');
    document.write('<param name=play value=true>\n');
    document.write('<embed type="application/x-shockwave-flash" play=true width=750 quality=best height=166 src="http://www.collectedmemories.com/cmheader.swf?tab=' + tab + '&secure=yes">\n');
    document.write('</object>\n');
}

function RunHeader3(tab)
{
    //alert(tab);
    document.write('<object classid="clsid:D27CDB6E-AE6D-11cf-96B8-444553540000" height="166" width="750">\n');
    document.write('<param name="movie" value="https://www.collectedmemories.com/cmheader.swf?tab=' + tab + '">\n');
    document.write('<param name="quality" value="best">\n');
    document.write('<param name="play" value="true">\n');
    document.write('<embed quality=best src="https://www.collectedmemories.com/cmheader.swf?tab="' + tab + ' width=750 type="application/x-shockwave-flash" play=true height=166>\n');
    document.write('</object>\n');
}


function RunSideMenu()
{
    document.write('<object classid=clsid:D27CDB6E-AE6D-11cf-96B8-444553540000 height=500 width=166>\n');
    document.write('<param name=movie value="http://www.collectedmemories.com/cmSideMenu.swf">\n');
    document.write('<param name=quality value=best>\n');
    document.write('<param name=play value=true>\n');
    document.write('<embed type="application/x-shockwave-flash" play=true width=166 quality=best height=500 src="http://www.collectedmemories.com/cmSideMenu.swf">\n');
    document.write('</object>\n');
}

function RunSpecialsMenu()
{
    document.write('<OBJECT CLASSID=clsid:D27CDB6E-AE6D-11cf-96B8-444553540000 WIDTH=525 CODEBASE="http://download.macromedia.com/pub/shockwave/cabs/flash/swflash.#version=5,0,30,0" HEIGHT=100>\n');
    document.write('<PARAM NAME=movie VALUE="/menu_specials.swf">\n');
    document.write('<PARAM NAME=quality VALUE=best>\n');
    document.write('<PARAM NAME=play VALUE=true>\n');
    document.write('<EMBED QUALITY=best SRC="/menu_specials.swf" PLUGINSPAGE="http://www.macromedia.com/shockwave/download/index.cgi?P1_Prod_Version=ShockwaveFlash" WIDTH=525 TYPE="application/x-shockwave-flash" PLAY=true HEIGHT=100>\n');
    document.write('</OBJECT>\n');
}