/*function doSubmit(color) {
	fm = document.forms['gotoProd'];
	fm.color.value = color;
	fm.submit();
}
function doSubmit2(color) {
	fm = document.forms['gotoProd2'];
	fm.color.value = color;
	fm.submit();
}*/
function checkNewsletter(fm) {
	//fm = document.forms['listctrl'];
	var missing = "";
	if (fm.email.value == "")
		missing += "E-mail is required.";
	else {
		temp = fm.email.value + " ";
		found = temp.search(/[\w\.-]+@([\w-]+\.){1,3}[a-zA-Z]{2,}\s{1}/);
		if (found != 0)
			missing += "E-mail must be in the form username@domain.com"
	}
	if (missing != "") {
		alert(missing);
		return false;
	}
	return true;
}

function checkInv(inv,allowBO,BOdate,prodID,option) {
	fm = document.forms['addToBasket'];	
	if (inv < 10 && allowBO == 1 && BOdate != "") {		
		document.getElementById("outofstock").innerHTML = "<br />Available for pre-order. This item will ship " + BOdate;
		document.getElementById("add_to_bag_disabled").style.display = "none";
		document.getElementById("add_to_bag").style.display = "block";
		document.getElementById("checkout_disabled").style.display = "none";
		document.getElementById("checkout").style.display = "block";		
		if (document.getElementById("largeImageLink"))
			document.getElementById("largeImageLink").href = "javascript:document.forms['addToBasket'].submit();";
	} else if (inv < 10) {		
		document.getElementById("outofstock").innerHTML = "<br />We are sold out of this item.";
		if (prodID == 79) {
		document.getElementById("outofstock").innerHTML = "<br />We are sold out of this item.<br />Please check out our <a href='products.cfm?cID=22&pID=78&color=" + option + "'>" + option + " momAgenda Desktop</a>.";
		}
		if (prodID == 77 && option == 'rose-pink') {
		document.getElementById("outofstock").innerHTML = "<p>We are sold out of this item.<br />Please check out our <a href='products.cfm?cID=21&pID=77&color=spring-green'>Spring Green Faux Crocodile Desktop</a> or our <a href='products.cfm?cID=21&pID=78'>Fuchsia momAgenda Desktop</a>.</p>";
		}
		document.getElementById("add_to_bag").style.display = "none";
		document.getElementById("add_to_bag_disabled").style.display = "block";
		document.getElementById("checkout").style.display = "none";
		document.getElementById("checkout_disabled").style.display = "block";
		if (document.getElementById("largeImageLink"))
			document.getElementById("largeImageLink").href = "javascript:void(0);";		
	} else {
		document.getElementById("outofstock").innerHTML = "&nbsp;";
		document.getElementById("add_to_bag_disabled").style.display = "none";
		document.getElementById("add_to_bag").style.display = "block";
		document.getElementById("checkout_disabled").style.display = "none";
		document.getElementById("checkout").style.display = "block";
		if (document.getElementById("largeImageLink"))
			document.getElementById("largeImageLink").href = "javascript:document.forms['addToBasket'].submit();";
	}
}
function checkOptInvDropDown(optName) {
	fm = document.forms['addToBasket'];
	var optInv = fm[optName + "_inv"].value;
	if (optInv - 1 < 9)
		document.getElementById("outofstock").innerHTML = "This item is on back order for 1-2 weeks.";
	else
		document.getElementById("outofstock").innerHTML = "&nbsp;";	
}
function checkAddToCart() {
	fm = document.forms['addToBasket'];
	if (fm.selectOptions != null && fm.selectOptions.value == "") {
		alert ("Please choose a product option.");
		return false;
	}
	if (fm.peridlist && document.getElementById("do_personalization").value == 1) {
		var qty = parseInt(document.getElementById("qty").value);
		var perids = fm.peridlist.value.split(",");
		var perlines = fm.perlinelist.value.split(",");
		for (var i = 0; i < perids.length; i++) {
			for (var k = 1; k <= (((document.getElementById("addeach") && document.getElementById("addeach").checked) || document.getElementById("addeachhidden")) ? qty : 1); k++) {
				for (var j = 1; j <= perlines[i]; j++) {
					var fld = fm["inscription" + perids[i] + "_" + j + "_" + k];
					fld.value = fld.value.replace(/^ */g, '').replace(/ *$/g, '');
					if (fld && fld.value == "") {
						alert("Please fill out inscription line " + j + " for Item #" + k);
						return false;
					}
				} 
			}
		}
	}
	return true;
}

function writeAltImgL(img,prodName) {
	document.getElementById("product-zoom").innerHTML = '<div><a href="javascript:closeAltImgL()"><img src="nr/store/images/product/altImages/' + img + '" alt="' + prodName + ' zoom shot"></a><a href="javascript:closeAltImgL()" id="close-pop">click to close</a></div>';	
}

function closeAltImgL() {
	document.getElementById("product-zoom").innerHTML = '';	
}

//personalized-zoom image
function writeOptImgL(img,prodName) {
	document.getElementById("option-zoom").innerHTML = '<div><a href="javascript:closeOptImgL()"><img src="img/' + img + '" alt="' + prodName + ' zoom shot" id="option-zoomshot"></a><a href="javascript:closeOptImgL()" id="close-pop">click to close</a></div>';	
}

function closeOptImgL() {
	document.getElementById("option-zoom").innerHTML = '';	
}

//personalized-zoom image end

function TellFriendWin(var1) {
	window.open(var1,'agreement','toolbar=no,location=no,directories=no,status=no,scrollbars=yes,resizable=no,width=770, height=500');
}
function TellFriendDollarsWin(var1) {
	window.open(var1,'agreement','toolbar=no,location=no,directories=no,status=no,scrollbars=yes,resizable=no,width=500, height=770');
}
function checkEmailDollarsForm ( ) {
    var fm = document.emailFriend;
	fm.yourname.value = fm.yourname.value.replace(/^ */g, '').replace(/ *$/g, '');
	if (fm.yourname.value == "")
		fm.missing.value += "," + "Your Name is required."
	fm.youremail.value = fm.youremail.value.replace(/^ */g, '').replace(/ *$/g, '');	
	if (fm.youremail.value == "")
		fm.missing.value += "," + "Your E-mail is required."
	else {
		temp = fm.youremail.value + " ";
		found = temp.search(/[\w\.-]+@([\w-]+\.){1,3}[a-zA-Z]{2,}\s{1}/);
		if (found != 0)
			fm.missing.value += "," + "Your E-mail must be in the form username@domain.com"
	} 
	fm.friendemail1.value = fm.friendemail1.value.replace(/^ */g, '').replace(/ *$/g, '');	
	if (fm.friendemail1.value == "")
		fm.missing.value += "," + "Your Friend's E-mail is required."
	else {
		temp = fm.friendemail1.value + " ";
		found = temp.search(/[\w\.-]+@([\w-]+\.){1,3}[a-zA-Z]{2,}\s{1}/);
		if (found != 0)
			fm.missing.value += "," + "Your Friend's E-mail must be in the form username@domain.com"
	}
	fm.friendemail2.value = fm.friendemail2.value.replace(/^ */g, '').replace(/ *$/g, '');	
	if (fm.friendemail2.value != "") {
		temp = fm.friendemail2.value + " ";
		found = temp.search(/[\w\.-]+@([\w-]+\.){1,3}[a-zA-Z]{2,}\s{1}/);
		if (found != 0)
			fm.missing.value += "," + "Your 2nd Friend's E-mail must be in the form username@domain.com"
	}
	fm.friendemail3.value = fm.friendemail3.value.replace(/^ */g, '').replace(/ *$/g, '');	
	if (fm.friendemail3.value != "") {
		temp = fm.friendemail3.value + " ";
		found = temp.search(/[\w\.-]+@([\w-]+\.){1,3}[a-zA-Z]{2,}\s{1}/);
		if (found != 0)
			fm.missing.value += "," + "Your 3rd Friend's E-mail must be in the form username@domain.com"
	}
	fm.friendemail4.value = fm.friendemail4.value.replace(/^ */g, '').replace(/ *$/g, '');	
	if (fm.friendemail4.value != "") {
		temp = fm.friendemail4.value + " ";
		found = temp.search(/[\w\.-]+@([\w-]+\.){1,3}[a-zA-Z]{2,}\s{1}/);
		if (found != 0)
			fm.missing.value += "," + "Your 4th Friend's E-mail must be in the form username@domain.com"
	}
	fm.friendemail5.value = fm.friendemail5.value.replace(/^ */g, '').replace(/ *$/g, '');	
	if (fm.friendemail5.value != "") {
		temp = fm.friendemail5.value + " ";
		found = temp.search(/[\w\.-]+@([\w-]+\.){1,3}[a-zA-Z]{2,}\s{1}/);
		if (found != 0)
			fm.missing.value += "," + "Your 5th Friend's E-mail must be in the form username@domain.com"
	}
	fm.friendemail6.value = fm.friendemail6.value.replace(/^ */g, '').replace(/ *$/g, '');	
	if (fm.friendemail6.value != "") {
		temp = fm.friendemail6.value + " ";
		found = temp.search(/[\w\.-]+@([\w-]+\.){1,3}[a-zA-Z]{2,}\s{1}/);
		if (found != 0)
			fm.missing.value += "," + "Your 6th Friend's E-mail must be in the form username@domain.com"
	}
	
	if (fm.missing.value == "")
		fm.action = fm.action + "?thanks";
}

function checkJoinRewardsForm() {
	var fm = document.joinRewardsForm;
	var missing = "";
	fm.name.value = fm.name.value.replace(/^ */g, '').replace(/ *$/g, '');
	if (fm.name.value == "")
		missing += "Your Name is required.\n"
	fm.email.value = fm.email.value.replace(/^ */g, '').replace(/ *$/g, '');	
	if (fm.email.value == "")
		missing += "Your E-mail is required.\n"
	else {
		temp = fm.email.value + " ";
		found = temp.search(/[\w\.-]+@([\w-]+\.){1,3}[a-zA-Z]{2,}\s{1}/);
		if (found != 0)
			missing += "Your E-mail must be in the form username@domain.com\n"
	}
	if (fm.pass.value == "")
		missing += "Your password is required.\n";
	else if (fm.pass.value.length < 4 || fm.pass.value.length > 16)
		missing += "Your password must be between 4 and 16 characters.\n";
	else {
		var re = /\W/;		
		if (re.test(fm.pass.value))		
			missing += "Your password must be between 4 and 16 characters and contain only characters and numbers.\n";
	}
	if (fm.confirmpass.value == "")
		missing += "Your password confirmation is required.\n";
	if (fm.pass.value != fm.confirmpass.value)
		missing += "Your password and confirm password values do not match. Please type your password exactly the same in the confirmation field.\n";
		
	if (missing != "") {
		alert(missing);
		return false;
	}
	return true;
}

function checkChangeRewardsPassword ( ) {
    var fm = document.changePasswordForm;
	var missing = "";
	if (fm.oldpass.value == "")
		missing = "Your old password is required.\n";
	if (fm.newpass.value == "")
		missing += "Your new password is required.\n";
	else if (fm.newpass.value.length < 4 || fm.newpass.value.length > 16)
		missing += "Your new password must be between 4 and 16 characters and contain only characters and numbers.\n";
	else {
		var re = /\W/;		
		if (re.test(fm.newpass.value))		
			missing += "Your new password must be between 4 and 16 characters and contain only characters and numbers.\n";
	}
	if (fm.confirmpass.value == "")
		missing += "Your new password confirmation is required.\n";
	if (fm.newpass.value != fm.confirmpass.value)
		missing += "Your new password and confirm password values do not match. Please type your new password exactly the same in the confirmation field.\n";	
	
	if (missing != "") {
		alert(missing);
		return false;
	}
	return true;
}

function checkEmailFriendForm ( ) {
    var fm = document.emailFriend;
	fm.yourname.value = fm.yourname.value.replace(/^ */g, '').replace(/ *$/g, '');
	if (fm.yourname.value == "")
		fm.missing.value += "," + "Your Name is required."
	fm.youremail.value = fm.youremail.value.replace(/^ */g, '').replace(/ *$/g, '');	
	if (fm.youremail.value == "")
		fm.missing.value += "," + "Your E-mail is required."
	else {
		temp = fm.youremail.value + " ";
		found = temp.search(/[\w\.-]+@([\w-]+\.){1,3}[a-zA-Z]{2,}\s{1}/);
		if (found != 0)
			fm.missing.value += "," + "Your E-mail must be in the form username@domain.com"
	} 
	fm.friendname.value = fm.friendname.value.replace(/^ */g, '').replace(/ *$/g, '');
	if (fm.friendname.value == "")
		fm.missing.value += "," + "Your Friend's Name is required."	
	fm.friendemail.value = fm.friendemail.value.replace(/^ */g, '').replace(/ *$/g, '');	
	if (fm.friendemail.value == "")
		fm.missing.value += "," + "Your Friend's E-mail is required."
	else {
		temp = fm.friendemail.value + " ";
		found = temp.search(/[\w\.-]+@([\w-]+\.){1,3}[a-zA-Z]{2,}\s{1}/);
		if (found != 0)
			fm.missing.value += "," + "Your Friend's E-mail must be in the form username@domain.com"
	}
	if (fm.missing.value == "")
		fm.action = fm.action + "&thanks=eaf";
}
function goTo (url) {
	window.location = url;
}


// show/hide arbitrary element
/*function showHideElement(state,elemID) {

	if ((document.all) && document.all[elemID]) {
		if (state == 'show') document.all[elemID].style.visibility = 'visible';
		if (state == 'hide') document.all[elemID].style.visibility = 'hidden';
	}
	else {	if (document.getElementById(elemID)) {
				if (state == 'show') document.getElementByID(elemID).style.visibility = 'visible';
				if (state == 'hide') document.getElementByID(elemID).style.visibility = 'hidden';
			}
	}
	return;
}*/

function showHide(state,elemID) {
	if ((document.all) && document.all[elemID]) {
		// alert('in ie4 or above');
		if (state == 'show' && document.all(elemID)) document.all[elemID].style.visibility = 'visible';
		else if (state == 'hide' && document.all(elemID)) document.all[elemID].style.visibility = 'hidden';
		} // end if document.all is recognized
	else {
		if (document.getElementById(elemID)) {
			// Netscape 6 & IE5, access the text's ID, then use the property innerHTML
			// alert('getElementById');
			if (state == 'show' && document.getElementById(elemID)) document.getElementById(elemID).style.visibility = 'visible';
			else if (state == 'hide' && document.getElementById(elemID)) document.getElementById(elemID).style.visibility = 'hidden';
		} // end if getElementById is recognized	
	}
	return;
	
}

function checkWholesaleForm(fm, missingurl) {
	fm.store_name.value = fm.store_name.value.replace(/^ */g, '').replace(/ *$/g, '');
	if (fm.store_name.value == "")
		fm.missing.value += "," + "Store Name is required.";
	fm.store_type.value = fm.store_type.value.replace(/^ */g, '').replace(/ *$/g, '');
	if (fm.store_type.value == "")
		fm.missing.value += "," + "Store Type is required.";
	fm.contact_name.value = fm.contact_name.value.replace(/^ */g, '').replace(/ *$/g, '');
	if (fm.contact_name.value == "")
		fm.missing.value += "," + "Contact Name is required.";
	fm.wholesale_email.value = fm.wholesale_email.value.replace(/^ */g, '').replace(/ *$/g, '');	
	if (fm.wholesale_email.value == "")
		fm.missing.value += "," + "E-mail is required.";
	else {
		temp = fm.wholesale_email.value + " ";
		found = temp.search(/[\w\.-]+@([\w-]+\.){1,3}[a-zA-Z]{2,}\s{1}/);
		if (found != 0)
			fm.missing.value += "," + "E-mail must be in the form username@domain.com";
	}
	fm.wholesale_address.value = fm.wholesale_address.value.replace(/^ */g, '').replace(/ *$/g, '');	
	if (fm.wholesale_address.value == "")
		fm.missing.value += "," + "Address is required.";
	fm.wholesale_city.value = fm.wholesale_city.value.replace(/^ */g, '').replace(/ *$/g, '');	
	if (fm.wholesale_city.value == "")
		fm.missing.value += "," + "City is required.";
	fm.wholesale_state_province.value = fm.wholesale_state_province.value.replace(/^ */g, '').replace(/ *$/g, '');	
	if (fm.wholesale_state_province.value == "")
		fm.missing.value += "," + "State/Province is required."		
	fm.wholesale_zip.value = fm.wholesale_zip.value.replace(/^ */g, '').replace(/ *$/g, '');
	if (fm.wholesale_zip.value == "")
		fm.missing.value += "," + "Zip/Postal Code is required."
	else {
		temp = fm.wholesale_zip.value + " ";							
		if (fm.wholesale_zip.value != "") {
			if (temp.search(/[\-a-zA-Z0-9]{1,10}\s{1}/) != 0)
				fm.missing.value += "," + "Zip/Postal Code must be letters, numbers and dashes"
		}				
	}
	fm.wholesale_phone.value = fm.wholesale_phone.value.replace(/^ */g, '').replace(/ *$/g, '');
	if (fm.wholesale_phone.value == "")
		fm.missing.value += "," + "Phone number is required.";
	else {						
		temp = fm.wholesale_phone.value + " ";
		if (temp.search(/\d{10}\s{1}/) == 0)
			fm.wholesale_phone.value = fm.wholesale_phone.value.substring(0, 3) + "-" + fm.wholesale_phone.value.substring(3, 6) + "-" + fm.wholesale_phone.value.substring(6);
		temp = fm.wholesale_phone.value + " ";							
		if (temp.search(/[\d-]+\s{1}/) != 0)
			fm.missing.value += "," + "Phone must be digits and dashes only in the form 123-456-7890";
	}
	fm.wholesale_fax.value = fm.wholesale_fax.value.replace(/^ */g, '').replace(/ *$/g, '');
	if (fm.wholesale_fax.value != "") {
		temp = fm.wholesale_fax.value + " ";
		if (temp.search(/\d{10}\s{1}/) == 0)
			fm.wholesale_fax.value = fm.wholesale_fax.value.substring(0, 3) + "-" + fm.wholesale_fax.value.substring(3, 6) + "-" + fm.wholesale_fax.value.substring(6);
		temp = fm.wholesale_fax.value + " ";							
		if (temp.search(/[\d-]+\s{1}/) != 0)
			fm.missing.value += "," + "Fax must be digits and dashes only in the form 123-456-7890";
	}
	if (fm.missing.value != "")
		fm.action = missingurl;	
}


/*---- Personalized ----*/
/*--------------------------------------------------------------------*/
/*---- Personalized content tab ----*/
/*---- Personalized content tab ----*/
var bustcachevar=1 //bust potential caching of external pages after initial request? (1=yes, 0=no)
var loadstatustext="<img src='ajaxtabs/loading.gif' /> Requesting content..."
var enabletabpersistence=1 //enable tab persistence via session only cookies, so current tab is remembered (1=yes, 0=no)?

////NO NEED TO EDIT BELOW////////////////////////
var loadedobjects=""
var defaultcontentarray=new Object()
var bustcacheparameter=""

function ajaxpage(url, containerid, targetobj){
var page_request = false
if (window.XMLHttpRequest) // if Mozilla, IE7, Safari etc
page_request = new XMLHttpRequest()
else if (window.ActiveXObject){ // if IE
try {
page_request = new ActiveXObject("Msxml2.XMLHTTP")
} 
catch (e){
try{
page_request = new ActiveXObject("Microsoft.XMLHTTP")
}
catch (e){}
}
}
else
return false
var ullist=targetobj.parentNode.parentNode.getElementsByTagName("li")
for (var i=0; i<ullist.length; i++)
ullist[i].className=""  //deselect all tabs
targetobj.parentNode.className="current"  //highlight currently clicked on tab
if (url.indexOf("#default")!=-1){ //if simply show default content within container (verus fetch it via ajax)
document.getElementById(containerid).innerHTML=defaultcontentarray[containerid]
return
}
document.getElementById(containerid).innerHTML=loadstatustext
page_request.onreadystatechange=function(){
loadpage(page_request, containerid)
}
if (bustcachevar) //if bust caching of external page
bustcacheparameter=(url.indexOf("?")!=-1)? "&"+new Date().getTime() : "?"+new Date().getTime()
page_request.open('GET', url+bustcacheparameter, true)
page_request.send(null)
}

function loadpage(page_request, containerid){
if (page_request.readyState == 4 && (page_request.status==200 || window.location.href.indexOf("http")==-1))
document.getElementById(containerid).innerHTML=page_request.responseText
}

function loadobjs(revattribute){
if (revattribute!=null && revattribute!=""){ //if "rev" attribute is defined (load external .js or .css files)
var objectlist=revattribute.split(/\s*,\s*/) //split the files and store as array
for (var i=0; i<objectlist.length; i++){
var file=objectlist[i]
var fileref=""
if (loadedobjects.indexOf(file)==-1){ //Check to see if this object has not already been added to page before proceeding
if (file.indexOf(".js")!=-1){ //If object is a js file
fileref=document.createElement('script')
fileref.setAttribute("type","text/javascript");
fileref.setAttribute("src", file);
}
else if (file.indexOf(".css")!=-1){ //If object is a css file
fileref=document.createElement("link")
fileref.setAttribute("rel", "stylesheet");
fileref.setAttribute("type", "text/css");
fileref.setAttribute("href", file);
}
}
if (fileref!=""){
document.getElementsByTagName("head").item(0).appendChild(fileref)
loadedobjects+=file+" " //Remember this object as being already added to page
}
}
}
}

function expandtab(tabcontentid, tabnumber){ //interface for selecting a tab (plus expand corresponding content)
var thetab=document.getElementById(tabcontentid).getElementsByTagName("a")[tabnumber]
if (thetab.getAttribute("rel")){
ajaxpage(thetab.getAttribute("href"), thetab.getAttribute("rel"), thetab)
loadobjs(thetab.getAttribute("rev"))
}
}

function savedefaultcontent(contentid){// save default ajax tab content
if (typeof defaultcontentarray[contentid]=="undefined") //if default content hasn't already been saved
defaultcontentarray[contentid]=document.getElementById(contentid).innerHTML
}

function startajaxtabs(){
for (var i=0; i<arguments.length; i++){ //loop through passed UL ids
var ulobj=document.getElementById(arguments[i])
var ulist=ulobj.getElementsByTagName("li") //array containing the LI elements within UL
var persisttabindex=(enabletabpersistence==1)? parseInt(getCookie(arguments[i])) : "" //get index of persisted tab (if applicable)
var isvalidpersist=(persisttabindex<ulist.length)? true : false //check if persisted tab index falls within range of defined tabs
for (var x=0; x<ulist.length; x++){ //loop through each LI element
var ulistlink=ulist[x].getElementsByTagName("a")[0]
ulistlink.index=x
if (ulistlink.getAttribute("rel")){
var modifiedurl=ulistlink.getAttribute("href").replace(/^http:\/\/[^\/]+\//i, "http://"+window.location.hostname+"/")
ulistlink.setAttribute("href", modifiedurl) //replace URL's root domain with dynamic root domain, for ajax security sake
savedefaultcontent(ulistlink.getAttribute("rel")) //save default ajax tab content
ulistlink.onclick=function(){
ajaxpage(this.getAttribute("href"), this.getAttribute("rel"), this)
loadobjs(this.getAttribute("rev"))
savecurrenttabindex(this.parentNode.parentNode.id, this.index)
return false
}
if ((enabletabpersistence==1 && persisttabindex<ulist.length && x==persisttabindex) || (enabletabpersistence==0 && ulist[x].className=="current")){
ajaxpage(ulistlink.getAttribute("href"), ulistlink.getAttribute("rel"), ulistlink) //auto load currenly current tab content
loadobjs(ulistlink.getAttribute("rev")) //auto load any accompanying .js and .css files
}
}
}
}
}



////////////Persistence related functions//////////////////////////

function savecurrenttabindex(ulid, index){ //remember currently current tab (based on order relative to other tabs)
if (enabletabpersistence==1) //if persistence feature turned on
setCookie(ulid, index)
}

function getCookie(Name){ 
var re=new RegExp(Name+"=[^;]+", "i"); //construct RE to search for target name/value pair
if (document.cookie.match(re)) //if cookie found
return document.cookie.match(re)[0].split("=")[1] //return its value
return ""
}

function setCookie(name, value){
document.cookie = name+"="+value //cookie value is domain wide (path=/)
}

/*---- Personalized content tab/ ----*/
/*---- Personalized content tab/ ----*/

function toggle(id)	{
	if (document.getElementById) {
		var el = document.getElementById(id);
		el.style.display = (el.style.display == 'none' ? 'block' : 'none');
	}
}
function openOptions () {
	toggle('check-personalize');
	toggle('detail-personalize-wrapper');
	document.getElementById("do_personalization").value = 1;
}
function closeOptions () {
	toggle('check-personalize');
	toggle('detail-personalize-wrapper');
	document.getElementById("do_personalization").value = 0;
}

/*---- Personalized content checkbox and radio buttons ----*/
/*document.write('<link rel="stylesheet" type="text/css" href="inputs.css" media="screen" />');

var Input = {
	initialize: function() {
		if(document.getElementsByTagName("form")) {
			var divs = document.getElementsByTagName("div");
			for(var i = 0; i < divs.length; i++) {
				if(divs[i].className.match("checkbox") || divs[i].className.match("radio")) {
					divs[i].onmousedown = Input.effect;
					divs[i].onmouseup = Input.handle;
					window.onmouseup = Input.clear;
				}
			}
		}
	},

	effect: function() {
		if(this.className == "checkbox" || this.className == "radio") {
			this.style.backgroundPosition = "0 -26px";
		} else {
			this.style.backgroundPosition = "0 -79px";
		}
	},

	handle: function() {
		selector = this.getElementsByTagName("input")[0];
		if(this.className == "checkbox") {
			selector.checked = true;
			this.className = "checkbox selected";
			this.style.backgroundPosition = "0 -52px";
		} else if(this.className == "checkbox selected") {
			selector.checked = false;
			this.className = "checkbox";
			this.style.backgroundPosition = "0 0";
		} else {
			selector.checked = true;
			this.className = "radio selected";
			this.style.backgroundPosition = "0 -52px";
			inputs = document.getElementsByTagName("input");
			for(i = 0; i < inputs.length; i++) {
				if(inputs[i].getAttribute("name") == selector.getAttribute("name")) {
					if(inputs[i] != selector) {
						inputs[i].parentNode.className = "radio";
						inputs[i].parentNode.style.backgroundPosition = "0 0";
					}
				}
			}
		}
	},

	clear: function() {
		divs = document.getElementsByTagName("div");
		for(var i = 0; i < divs.length; i++) {
			if(divs[i].className == "checkbox" || divs[i].className == "radio") {
				divs[i].style.backgroundPosition = "0 0";
			} else if(divs[i].className == "checkbox selected" || divs[i].className == "radio selected") {
				divs[i].style.backgroundPosition = "0 -52px";
			}
		}
	}
}
window.onload = Input.initialize;

--------*/


function checkItems() {
	var qty = parseInt(document.getElementById("qty").value);
	if (isNaN(qty) || qty <= 0)
		qty = 1;
	document.getElementById("qty").value = qty;
	var addeach = ((document.getElementById("addeach") && document.getElementById("addeach").checked) || document.getElementById("addeachhidden") ? true : false);
	var items = document.getElementById("personalized-items");
	for (var i = 2; i <= qty; i++) {
		if (addeach) {
			if (! document.getElementById("personalized-item_" + i)) {
				var newitem = items.getElementsByTagName("DIV")[0].cloneNode(true);
				newitem.id = "personalized-item_" + i;
				var temp1 = newitem.getElementsByTagName("DIV")[0];
				temp1.getElementsByTagName("H5")[0].innerHTML = "Item #" + i;
				var temp2 = temp1.getElementsByTagName("DIV")[0].getElementsByTagName("TABLE")[0].getElementsByTagName("TBODY")[0].getElementsByTagName("TR")[0].getElementsByTagName("TD")[1];
				for (var j = 0; j < temp2.getElementsByTagName("INPUT").length; j++) {
					var oldinput = temp2.getElementsByTagName("INPUT")[j];
					var newinput = createNamedElement("INPUT", oldinput.name.substr(0, oldinput.name.indexOf("_") + 1) + (j + 1) + "_" + i, "text");
					newinput.className = "field";
					if (oldinput.maxLength)
						newinput.maxLength = oldinput.maxLength;
					temp2.replaceChild(newinput, oldinput);
				}
				temp1 = newitem.getElementsByTagName("DIV")[0].getElementsByTagName("DIV")[1];
				for (var j = 0; j < temp1.getElementsByTagName("TABLE").length; j++) {
					temp2 = temp1.getElementsByTagName("TABLE")[j];
					temp2.id = temp2.id.substr(0, temp2.id.lastIndexOf("_") + 1) + i;
					var temp3 = temp2.getElementsByTagName("TBODY")[0].getElementsByTagName("TR")[0];
					for (k = 1; k < temp3.getElementsByTagName("TD").length; k++) {
						var temp4 = temp3.getElementsByTagName("TD")[k].getElementsByTagName("A")[0];
						if (k == 1)
							var defaultval = temp4.id.substr(0, temp4.id.lastIndexOf("-"));
						var oldonclick = temp4.onclick.toString();
						oldonclick = oldonclick.substring(oldonclick.indexOf("clicked"), oldonclick.lastIndexOf("_1") - 1) + "'_" + i + "');";
						temp4.onclick = new Function(oldonclick);
						var temp5 = temp4.getElementsByTagName("IMG")[0];
						temp5.id = temp5.id.substr(0, temp5.id.lastIndexOf("_") + 1) + i;
						temp5.style.visibility = (k == 1 ? "visible" : "hidden");
					}
					temp3 = temp2.getElementsByTagName("TBODY")[0].getElementsByTagName("TR")[1].getElementsByTagName("TD")[1].getElementsByTagName("DIV")[0].getElementsByTagName("DIV")[0].getElementsByTagName("SPAN")[0];
					temp3.id = temp3.id.substr(0, temp3.id.lastIndexOf("_") + 1) + i;
					temp3.innerHTML = defaultval;		
					oldinput = temp1.getElementsByTagName("INPUT")[j];
					newinput = createNamedElement("INPUT", oldinput.name.substr(0, oldinput.name.lastIndexOf("_") + 1) + i, "hidden");
					newinput.value = defaultval;									
					temp1.replaceChild(newinput, oldinput);
				}
				var cleardiv = document.createElement("DIV");
				cleardiv.className = "clear";
				items.appendChild(cleardiv);
				items.appendChild(newitem);
				//alert(newitem.innerHTML);
			} else document.getElementById("personalized-item_" + i).style.display = "block";
		} else if (document.getElementById("personalized-item_" + i))
			document.getElementById("personalized-item_" + i).style.display = "none";
	}
	for (var i = qty + 1; i <= 99; i++) {
		if (document.getElementById("personalized-item_" + i))
			document.getElementById("personalized-item_" + i).style.display = "none";
	}
}
function createNamedElement(tg, nm, tp) {
	/*@cc_on @if (@_jscript)
		var newNode = document.createElement("<" + tg + " name='" + nm + "'" + (tp != undefined ? " type='" + tp + "'" : "") + ">");
	@else */
		var newNode = document.createElement(tg);
		newNode.name = nm;
		newNode.type = tp;
	/* @end @*/
	return newNode;
}

