// JavaScript Document
function updateInput(id, price, productNum){
	quantity = document.getElementById("quantity"+id);
	total = document.getElementById("total"+id);
	var valo = new String();
	var numere = "0123456789";
	var chars = quantity.value;
	/*
	if (numere.indexOf(chars[chars.length-1]) == -1){
		alert("Non-numeric character is not allowed");
		quantity.value = chars.substr(0,chars.length-1);
	}*/
	/*var remainder = 0;
    var quotient = 0;
	if(id==2 ){// 60 Minute Massage Gift Certificate 
    	remainder = quantity.value % 3;
    	quotient = ( quantity.value - remainder ) / 3;
		total.value = (remainder*price)+(quotient*132);
    }else */
	total.value = price * quantity.value;
    
	var a = "";
	var sumT = 0;
	var sumQ = 0;
	for(var i=1;i<=productNum;i++){
		sumT += document.getElementById("total"+i).value * 1;
		sumQ += document.getElementById("quantity"+i).value * 1;
	}
	sumTotal = document.getElementById("sumTotal");
	sumTotal.value = sumT;
	sumTotalHidden = document.getElementById("sumTotalHidden");
	sumTotalHidden.value = sumT;
	sumQuantity = document.getElementById("sumQuantity");
	sumQuantity.value = sumQ;

}
function charCount(id){
	var note = document.getElementById("note"+id);
	var length = 45 - note.value.length;
	//alert("len:"+length);
	var charCountText = document.getElementById("charCountText"+id);
	parentObj = charCountText.parentNode;
	parentObj.removeChild(charCountText);

	var div = document.createElement('div');
	div.setAttribute('id','charCountText'+id);
	var txt = document.createTextNode(length+' of 45 remaining');
	div.appendChild(txt) ;
	parentObj.appendChild(div) ;
}

function movepic(img_name,img_src, img_input) {
	var preview = document.getElementById(img_name);
	document[img_name].src=img_src;
	var image = document.getElementById(img_input);
	image.value = img_src;
}
function doUpdateImage(id,img_src){
	//alert("doPassVar");
	//alert("id:"+id+" img_src:"+img_src);
	document.getElementById("image"+id).value = img_src;	
	var myPreview= document.getElementById("preview"+id);
	myPreview.src = img_src;
}
/*function doPassVar(id){
	//alert("doPassVar");
	//alert("id:"+id);
	var myFlashMovie = document.getElementById("preview"+id);
	//alert("id:"+id+" myFlashMovie:"+myFlashMovie);
	var image = document.getElementById("image"+id);
	var to = document.getElementById("to"+id);
	var from = document.getElementById("from"+id);
	var note = document.getElementById("note"+id);
	//alert("image:"+image.value+" to:"+to.value+" from:"+from.value+" note:"+note.value);
	myFlashMovie.myFunctionId(image.value,to.value,from.value,note.value);
}*/
//function MM_openBrWindow(theURL,winName,features) { //v2.0
//	window.open(theURL,winName,features);
//}
function doPassVar(id){
	var myFlashMovie = document.getElementById("preview"+id);
	//alert("id:"+id+" myFlashMovie:"+myFlashMovie);
	var image = document.getElementById("image"+id);
	var to = document.getElementById("to"+id);
	var from = document.getElementById("from"+id);
	var note = document.getElementById("note"+id);
	//alert("image:"+image.value+" to:"+to.value+" from:"+from.value+" note:"+note.value);
	var theURL = 'preview.php?cardTo='+escape(to.value)+'&cardFrom='+escape(from.value)+'&cardNote='+escape(note.value)+'&img='+image.value;
	window.open(theURL,'preview','width=750,height=540,toolbar=no,resizable=no');
}

function clearVar(id){
	//alert("doPassVar");
	//alert("id:"+id);
	var myFlashMovie = document.getElementById("preview"+id);
	//alert("id:"+id+" myFlashMovie:"+myFlashMovie);
	
	var to = document.getElementById("to"+id);
	var from = document.getElementById("from"+id);
	var email = document.getElementById("email"+id);
	var note = document.getElementById("note"+id);
	to.value = "";
	from.value = "";
	email.value = "";
	note.value = "";
	
	//doPassVar(id);
	//alert("image:"+image+" to:"+to+" from:"+from+" note:"+note);
}
/*function doUpdateImage(id,img_src){
	//alert("doPassVar");
	//alert("id:"+id+" img_src:"+img_src);
	document.getElementById("image"+id).value = img_src;
	
	var myFlashMovie = document.getElementById("preview"+id);//thisMovie("preview"+id);
	alert("myFlashMovie:"+myFlashMovie);
	myFlashMovie.myUpdateImage(img_src);
}*/
function thisMovie(movieName) {
	var isIE = navigator.appName.indexOf("Microsoft") != -1;
	return (isIE) ? window[movieName] : document[movieName];
}
/////////////////////////////////////
function addLoc(id,productName,quantity,minute){
document.getElementById("sumTotal").value = document.getElementById("sumTotal").value * 1 + document.getElementById("price"+id).value * 1;

for(index = 0;index<quantity;index++){
	var cardNum = document.getElementById("cardNum");
	cardNum.value++;

// Start cloning new location, +, and - buttons from the default buttons which are those whose name end with 1.
	locTable = document.getElementById('cardTable');
	
	var newHTable = document.createElement('table');
	newHTable.setAttribute('width','100%');
	newHTable.setAttribute('border','0');
	newHTable.setAttribute('id','giftCard'+cardNum.value);
	
	var newTable = document.createElement('tbody');
	newHTable.appendChild(newTable);
	//newTable.appendChild();
// Part 1: Title	
		var row1=document.createElement('tr');
		row1.setAttribute('bgColor','#e2ebee');
			var cell1_1=document.createElement('td');
			cell1_1.setAttribute('colSpan','2');
				var title1 = document.createTextNode('Gift Certificate #'+cardNum.value+': ');
				var titleSpan1 = document.createElement('span');
				//titleSpan1.setAttribute('class','style9');
				var attr = document.createAttribute('class');
				attr.value = 'style9'; 
				titleSpan1.setAttributeNode(attr);
				
				titleSpan1.setAttribute('id','num'+cardNum.value);
				var title2 = document.createTextNode(productName);
				var titleSpan2 = document.createElement('span');
				//titleSpan2.setAttribute('class','style8');
				//attr = document.createAttribute('class');
				attr = document.createAttribute('class');
				attr.value = 'style8'; 
				titleSpan2.setAttributeNode(attr);
				
				titleSpan1.appendChild(title1) ;	
				titleSpan2.appendChild(title2) ;
			cell1_1.appendChild(titleSpan1) ;
			cell1_1.appendChild(titleSpan2) ;
		row1.appendChild(cell1_1);
	newTable.appendChild(row1);
// Part 2: Card
		var row2=document.createElement('tr');
			var cell2_1=document.createElement('td');
			cell2_1.setAttribute('width','275');
			cell2_1.setAttribute('valign','top');
			//cell2_1.setAttribute('class', 'preview');
			attr = document.createAttribute('class');
				attr.value = 'preview'; 
				cell2_1.setAttributeNode(attr);
				/*var divSWF = document.createElement('div');
				divSWF.setAttribute('id',"flashcontent"+cardNum.value);
				var divSWFTxt = document.createTextNode('This text is replaced by the Flash movie.');*/
				var previewImg = document.createElement('img');
				previewImg.setAttribute('id','preview'+cardNum.value);
				previewImg.setAttribute('src','giftcards/Generic_'+minute+'.jpg');
				previewImg.setAttribute('width','350');
				previewImg.setAttribute('height','252');
				
			var cell2_2=document.createElement('td');
			cell2_2.setAttribute('width','333');
			cell2_2.setAttribute('valign','top');
			var inputHTable = document.createElement('table');
				inputHTable.setAttribute('width','100%');
				inputHTable.setAttribute('border','0');
		var inputTable = document.createElement('tbody');		
				inputHTable.appendChild(inputTable);
				// Row 1
/*	var inputRow1 = document.createElement('tr');
						var inputCell1_1 = document.createElement('td');
						var inputCell1_2 = document.createElement('td');
						
					inputRow1.appendChild(inputCell1_1);
					inputRow1.appendChild(inputCell1_2);
					*/
					var inputRow1 = document.createElement('tr');
						var inputCell1_1 = document.createElement('td');
						inputCell1_1.setAttribute('colSpan','2');
						var inputSpan1_1 = document.createElement('span');
				attr = document.createAttribute('class');
				attr.value = 'style8'; 
				inputSpan1_1.setAttributeNode(attr);
try{
	var cpInfo = document.createElement('<input name="cpInfo'+cardNum.value+'" id="cpInfo'+cardNum.value+'" type="checkbox" onClick="copyInfo(this,'+eval(cardNum.value-1)+','+cardNum.value+')" /> Click here to use the same information as above');
		inputSpan1_1.appendChild(cpInfo);						
}catch(e){								
						
						var cpInfo = document.createElement('input');
						cpInfo.setAttribute('name','cpInfo'+cardNum.value);
						cpInfo.setAttribute('type','checkbox');
						cpInfo.setAttribute('id','cpInfo'+cardNum.value);
						cpInfo.setAttribute('Onclick','copyInfo(this,'+eval(cardNum.value-1)+','+cardNum.value+')');
						inputSpan1_1.appendChild(cpInfo);
						inputSpan1_1.appendChild(document.createTextNode(' Click here to use the same information as above'));
}
					inputCell1_1.appendChild(inputSpan1_1);
					inputRow1.appendChild(inputCell1_1);
					// Row 2	
					var inputRow2 = document.createElement('tr');
						var inputCell2_1 = document.createElement('td');
							var inputSpan2_1 = document.createElement('span');
							//inputSpan2_1.setAttribute('class','style8');
	attr = document.createAttribute('class');
				attr.value = 'style8'; 
				inputSpan2_1.setAttributeNode(attr);						
							inputSpan2_1.appendChild(document.createTextNode('To:'));
						inputCell2_1.appendChild(inputSpan2_1);
						
						var inputCell2_2 = document.createElement('td');
try{
	var to = document.createElement('<input name="to'+cardNum.value+'" id="to'+cardNum.value+'" type="text" size="20"  maxlength="40" />');
}catch(e){								
						
							var to = document.createElement('input');
							to.setAttribute('name','to'+cardNum.value);
							to.setAttribute('type','text');
							to.setAttribute('id','to'+cardNum.value);
							to.setAttribute('size','20');
							to.setAttribute('maxlength','40');
}
						inputCell2_2.appendChild(to);						
					inputRow2.appendChild(inputCell2_1);
					inputRow2.appendChild(inputCell2_2);
				// Row 3	
					var inputRow3 = document.createElement('tr');
						var inputCell3_1 = document.createElement('td');
							var inputSpan3_1 = document.createElement('span');
							//inputSpan3_1.setAttribute('class','style8');
							attr = document.createAttribute('class');
				attr.value = 'style8'; 
				inputSpan3_1.setAttributeNode(attr);	
							
							inputSpan3_1.appendChild(document.createTextNode('From:'));
						inputCell3_1.appendChild(inputSpan3_1);
						
						var inputCell3_2 = document.createElement('td');
try{
	var from = document.createElement('<input name="from'+cardNum.value+'" id="from'+cardNum.value+'" type="text" size="20"  maxlength="40" />');
}catch(e){								
							var from = document.createElement('input');
							from.setAttribute('name','from'+cardNum.value);
							from.setAttribute('type','text');
							from.setAttribute('id','from'+cardNum.value);
							from.setAttribute('size','20');
							from.setAttribute('maxlength','40');
}
						inputCell3_2.appendChild(from);						
					inputRow3.appendChild(inputCell3_1);
					inputRow3.appendChild(inputCell3_2);
				// Row 4	
					var inputRow4 = document.createElement('tr');
						var inputCell4_1 = document.createElement('td');
							var inputSpan4_1 = document.createElement('span');
							//inputSpan4_1.setAttribute('class','style8');
							attr = document.createAttribute('class');
				attr.value = 'style8'; 
				inputSpan4_1.setAttributeNode(attr);	
							
							inputSpan4_1.appendChild(document.createTextNode('Recipient\nEmail:'));
						inputCell4_1.appendChild(inputSpan4_1);
						
						var inputCell4_2 = document.createElement('td');
try{
	var email = document.createElement('<input name="email'+cardNum.value+'" id="email'+cardNum.value+'" type="text" size="20"  />');
}catch(e){				
						
							var email = document.createElement('input');
							email.setAttribute('name','email'+cardNum.value);
							email.setAttribute('type','text');
							email.setAttribute('id','email'+cardNum.value);
							email.setAttribute('size','20');
}
						var divCard = document.createElement('div');
						//divCard.setAttribute('class','style8');
						attr = document.createAttribute('class');
				attr.value = 'style8'; 
				divCard.setAttributeNode(attr);	
						var txtCard = document.createTextNode('Gift card will be sent to this email address');
							divCard.appendChild(txtCard) ;
							
						inputCell4_2.appendChild(email);
						inputCell4_2.appendChild(document.createElement('br'));
						inputCell4_2.appendChild(divCard);
					inputRow4.appendChild(inputCell4_1);
					inputRow4.appendChild(inputCell4_2);
					
				// Row 5	
					var inputRow5 = document.createElement('tr');
						var inputCell5_1 = document.createElement('td');
							var inputSpan5_1 = document.createElement('span');
							//inputSpan5_1.setAttribute('class','style8');
							attr = document.createAttribute('class');
				attr.value = 'style8'; 
				inputSpan5_1.setAttributeNode(attr);
							
							inputSpan5_1.appendChild(document.createTextNode('Note:'));
						inputCell5_1.appendChild(inputSpan5_1);
						
						var inputCell5_2 = document.createElement('td');
						//inputCell5_2.setAttribute('class','style8');
						attr = document.createAttribute('class');
				attr.value = 'style8'; 
				inputCell5_2.setAttributeNode(attr);
try{
	var note = document.createElement('<input name="note'+cardNum.value+'" id="note'+cardNum.value+'" type="text" size="20"  maxlength="40" OnKeyUp="charCount('+cardNum.value+')"/>');
}catch(e){				
							var note = document.createElement('input');
							note.setAttribute('name','note'+cardNum.value);
							note.setAttribute('type','text');
							note.setAttribute('id','note'+cardNum.value);
							note.setAttribute('size','20');
							note.setAttribute('maxlength','40');
							note.setAttribute('OnKeyUp','charCount('+cardNum.value+')');
}
							var divCC = document.createElement('div');
							divCC.setAttribute('id','charCountText'+cardNum.value);
							var txtCC = document.createTextNode('Limit of 45 characters');
							divCC.appendChild(txtCC) ;
							
							
						inputCell5_2.appendChild(note);
						inputCell5_2.appendChild(document.createElement('br'));
						inputCell5_2.appendChild(divCC);
					inputRow5.appendChild(inputCell5_1);
					inputRow5.appendChild(inputCell5_2);

// Row SendMail	
		var inputRowMail = document.createElement('tr');	
	attr = document.createAttribute('class');
	attr.value = 'style8'; 
	inputRowMail.setAttributeNode(attr);	
		var inputCellMail_1 = document.createElement('td');		
		inputCellMail_1.setAttribute('vAlign','top');
		inputCellMail_1.setAttribute('align','right');								
		
		try{
var chkMail = document.createElement("<input name=\"viaMail"+cardNum.value+"\" type=\"checkbox\" value=\"viaMail\" onClick=\"chkViamail("+cardNum.value+")\"/>");
//<input name="viaMail<?=$cardNum?>" type="checkbox" value="viaMail" onClick="chkViamail(<?=$cardNum?>)">
}catch(e){
var chkMail = document.createElement('input');
chkMail.name = 'viaMail'+cardNum.value;
chkMail.setAttribute('type','checkbox');
				chkMail.setAttribute('value','viaMail');
				chkMail.setAttribute('Onclick','chkViamail('+cardNum.value+')');
}
//				var chkMail = document.createElement('input');
	//			chkMail.name = 'viaMail'+cardNum.value;
				
	//attr = document.createAttribute('name');
	//attr.value = 'viaMail'+cardNum.value; 
	//chkMail.setAttributeNode(attr);	
				
			inputCellMail_1.appendChild(chkMail);
			
			var inputCellMail_2 = document.createElement('td');
			
			attr = document.createAttribute('class');
	attr.value = 'purple'; 
	inputCellMail_2.setAttributeNode(attr);	
			//inputCellMail_2.setAttribute('style','color:#660099; font-style:italic;');
				inputCellMail_2.appendChild(document.createTextNode('Check this box if you want this gift card sent via USPS Standard mail rather than sent via email. It will be mailed within 24 hours of your purchase.'));
try{
	var mailTo = document.createElement('<input name="emailTo'+cardNum.value+'" type="hidden"/>');
}catch(e){						
	  var mailTo = document.createElement('input');
	  mailTo.setAttribute('name','emailTo'+cardNum.value);
	  mailTo.setAttribute('type','hidden');
}
			inputCellMail_2.appendChild(mailTo);
		inputRowMail.appendChild(inputCellMail_1);
		inputRowMail.appendChild(inputCellMail_2);
					
			// Row 6
				var inputRow6 = document.createElement('tr');
					var inputCell6_1 = document.createElement('td');
					var inputCell6_2 = document.createElement('td');
					
					inputCell6_1.appendChild(document.createTextNode(' '));
					inputCell6_2.appendChild(document.createTextNode(' '));						
				inputRow6.appendChild(inputCell6_1);
				inputRow6.appendChild(inputCell6_2);
			// Row 7
				var inputRow7 = document.createElement('tr');
					/*var inputCell7_1 = document.createElement('td');
						var inputSpan7_1 = document.createElement('span');
						inputSpan7_1.setAttribute('class','style8');
						
						inputSpan7_1.appendChild(document.createTextNode(' '));
					inputCell7_1.appendChild(inputSpan7_1);
					*/
					var inputCell7_2 = document.createElement('td');
					inputCell7_2.setAttribute('colSpan','2');
					//inputCell7_2.setAttribute('class','previewBtnStyle');
					attr = document.createAttribute('class');
			attr.value = 'previewBtnStyle'; 
			inputCell7_2.setAttributeNode(attr);
try{
	var previewBtn = document.createElement('<input name="previewBtn'+cardNum.value+'" id="previewBtn'+cardNum.value+'" type="button" value="preview" Onclick="doPassVar('+cardNum.value+')"/>');
}catch(e){
					var previewBtn = document.createElement('input');
					previewBtn.setAttribute('name','previewBtn'+cardNum.value);
					previewBtn.setAttribute('type','button');
					previewBtn.setAttribute('id','previewBtn'+cardNum.value);
					previewBtn.setAttribute('value','preview');
					previewBtn.setAttribute('Onclick','doPassVar(\''+cardNum.value+'\')');
}
try{
	var clearBtn = document.createElement('<input name="clearBtn'+cardNum.value+'" id="clearBtn'+cardNum.value+'" type="button" value="clear" Onclick="clearVar('+cardNum.value+')"/>');
}catch(e){

					var clearBtn = document.createElement('input');
					clearBtn.setAttribute('name','clearBtn'+cardNum.value);
					clearBtn.setAttribute('type','button');
					clearBtn.setAttribute('id','clearBtn'+cardNum.value);
					clearBtn.setAttribute('value','clear');
					clearBtn.setAttribute('Onclick','clearVar('+cardNum.value+')');
}
try{
	var deleteBtn = document.createElement('<input name="deleteBtn'+cardNum.value+'" id="deleteBtn'+cardNum.value+'" type="button" value="delete" Onclick="deletePackage('+cardNum.value+','+quantity+','+index+','+id+')"/>');
}catch(e){

					var deleteBtn = document.createElement('input');
					deleteBtn.setAttribute('name','deleteBtn');
					deleteBtn.setAttribute('type','button');
					deleteBtn.setAttribute('id','deleteBtn'+cardNum.value);
					deleteBtn.setAttribute('value','delete');
					//deleteBtn.setAttribute('onclick','deleteVar('+cardNum.value+')');
					deleteBtn.setAttribute('Onclick','deletePackage('+cardNum.value+','+quantity+','+index+','+id+')');
					//deletePackage(<?=$cardNum?>,<?=$_POST['Lot'.$i]?>,<?=$j?>,<?=$i?>)
}
try{
	var image = document.createElement('<input name="image'+cardNum.value+'" id="image'+cardNum.value+'" type="hidden" value="giftcards/Generic_'+minute+'.jpg" />');
}catch(e){
					var image = document.createElement('input');
					image.setAttribute('name','image'+cardNum.value);
					image.setAttribute('type','hidden');
					image.setAttribute('id','image'+cardNum.value);
					//image.setAttribute('size','25');
					image.setAttribute('value','giftcards/Generic_'+minute+'.jpg');
}
try{
	var cardID = document.createElement('<input name="cardID'+cardNum.value+'" id="cardID'+cardNum.value+'" type="hidden" value="'+id+'" />');
}catch(e){
					var cardID = document.createElement('input');
					cardID.setAttribute('name','cardID'+cardNum.value);
					cardID.setAttribute('type','hidden');
					cardID.setAttribute('id','cardID'+cardNum.value);
					cardID.setAttribute('value',id);
}
try{
	var cardName = document.createElement('<input name="cardName'+cardNum.value+'" id="cardName'+cardNum.value+'" type="hidden" value="'+document.getElementById('productName'+id).value+'" />');
}catch(e){
					var cardName = document.createElement('input');
					cardName.setAttribute('name','cardName'+cardNum.value);
					cardName.setAttribute('type','hidden');
					cardName.setAttribute('id','cardName'+cardNum.value);
					cardName.setAttribute('value',document.getElementById('productName'+id).value);
}
							
					inputCell7_2.appendChild(previewBtn);
					inputCell7_2.appendChild(clearBtn);
					inputCell7_2.appendChild(deleteBtn);
					inputCell7_2.appendChild(image);
					inputCell7_2.appendChild(cardID);
					inputCell7_2.appendChild(cardName);
				//inputRow7.appendChild(inputCell7_1);
				inputRow7.appendChild(inputCell7_2);
			
			// ATTACHING ROWS
			inputTable.appendChild(inputRow1);
			inputTable.appendChild(inputRow2);
			inputTable.appendChild(inputRow3);
			inputTable.appendChild(inputRow4);
			inputTable.appendChild(inputRow5);
			inputTable.appendChild(inputRowMail);								
			inputTable.appendChild(inputRow6);
			inputTable.appendChild(inputRow7);

			//divSWF.appendChild(divSWFTxt);
		//cell2_1.appendChild(divSWF) ;
		cell2_1.appendChild(previewImg) ;
		cell2_2.appendChild(inputHTable) ;
	row2.appendChild(cell2_1);
	row2.appendChild(cell2_2);
newTable.appendChild(row2);
	
// Part 3: Background
		var row3=document.createElement('tr');
			var cell3=document.createElement('td');
			cell3.setAttribute('colSpan','2');
			cell3.setAttribute('valign','top');
			///-------------------
			var bgHTable = document.createElement('table');
			bgHTable.setAttribute('border','0');
			var bgTable = document.createElement('tbody');
			bgHTable.appendChild(bgTable);
				var bgRow = document.createElement('tr');
				// Cell 1
					var bgCell1 = document.createElement('td');
					//bgCell1.setAttribute('class','thumb');
					attr = document.createAttribute('class');
				attr.value = 'thumb'; 
				bgCell1.setAttributeNode(attr);
						var a1 = document.createElement('a');
						a1.setAttribute('id','a1_'+cardNum.value);
						a1.setAttribute('href','javascript:doUpdateImage('+cardNum.value+',\'giftcards/Generic_'+minute+'.jpg\')');
						var img1 = document.createElement('img');
						img1.setAttribute('src','giftcards/Generic_'+minute+'_Thumb.jpg');
						img1.setAttribute('src','giftcards/Generic_'+minute+'_Thumb.jpg');
						img1.setAttribute('width','60');
						img1.setAttribute('height','60');
						img1.setAttribute('border','0');					
						
						var br1 = document.createElement('br');
						a1.appendChild(img1);
						a1.appendChild(br1);
						a1.appendChild(document.createTextNode('Any Occasion'));
					bgCell1.appendChild(a1);
				// Cell 2
					var bgCell2 = document.createElement('td');
					//bgCell2.setAttribute('class','thumb');
					attr = document.createAttribute('class');
				attr.value = 'thumb'; 
				bgCell2.setAttributeNode(attr);
						var a2 = document.createElement('a');
						a2.setAttribute('id','a2_'+cardNum.value);
						a2.setAttribute('href','javascript:doUpdateImage('+cardNum.value+',\'giftcards/Birthday_'+minute+'.jpg\')');
						var img2 = document.createElement('img');
						img2.setAttribute('src','giftcards/Birthday_'+minute+'_Thumb.jpg');
						img2.setAttribute('width','60');
						img2.setAttribute('height','60');
						img2.setAttribute('border','0');					
						
						var br2 = document.createElement('br');
						a2.appendChild(img2);
						a2.appendChild(br2);
						a2.appendChild(document.createTextNode('Birthday'));
					bgCell2.appendChild(a2);
				// Cell 3
					var bgCell3 = document.createElement('td');
					//bgCell3.setAttribute('class','thumb');
					attr = document.createAttribute('class');
				attr.value = 'thumb'; 
				bgCell3.setAttributeNode(attr);
						var a3 = document.createElement('a');
						a3.setAttribute('id','a3_'+cardNum.value);
						a3.setAttribute('href','javascript:doUpdateImage('+cardNum.value+',\'giftcards/Valentines_'+minute+'.jpg\')');
						var img3 = document.createElement('img');
						img3.setAttribute('src','giftcards/Valentines_Thumb.jpg');
						img3.setAttribute('width','60');
						img3.setAttribute('height','60');
						img3.setAttribute('border','0');					
						
						var br3 = document.createElement('br');
						a3.appendChild(img3);
						a3.appendChild(br3);
						a3.appendChild(document.createTextNode('Valentine\'s'));
					bgCell3.appendChild(a3);
				// Cell 4
					var bgCell4 = document.createElement('td');
					//bgCell4.setAttribute('class','thumb');
					attr = document.createAttribute('class');
				attr.value = 'thumb'; 
				bgCell4.setAttributeNode(attr);
						var a4 = document.createElement('a');
						a4.setAttribute('id','a4_'+cardNum.value);
						a4.setAttribute('href','javascript:doUpdateImage('+cardNum.value+',\'giftcards/MothersDay_'+minute+'.jpg\')');
						var img4 = document.createElement('img');
						img4.setAttribute('src','giftcards/MothersDay_Thumb.jpg');
						img4.setAttribute('width','60');
						img4.setAttribute('height','60');
						img4.setAttribute('border','0');					
						
						var br4 = document.createElement('br');
						a4.appendChild(img4);
						a4.appendChild(br4);
						a4.appendChild(document.createTextNode('Mother\'s Day'));
					bgCell4.appendChild(a4);
				// Cell 5
					var bgCell5 = document.createElement('td');
					//bgCell5.setAttribute('class','thumb');
					attr = document.createAttribute('class');
				attr.value = 'thumb'; 
				bgCell5.setAttributeNode(attr);
						var a5 = document.createElement('a');
						a5.setAttribute('id','a5_'+cardNum.value);
						a5.setAttribute('href','javascript:doUpdateImage('+cardNum.value+',\'giftcards/FathersDay_'+minute+'.jpg\')');
						var img5 = document.createElement('img');
						img5.setAttribute('src','giftcards/FathersDay_Thumb.jpg');
						img5.setAttribute('width','60');
						img5.setAttribute('height','60');
						img5.setAttribute('border','0');					
						
						var br5 = document.createElement('br');
						a5.appendChild(img5);
						a5.appendChild(br5);
						a5.appendChild(document.createTextNode('Father\'s Day'));
					bgCell5.appendChild(a5);
				// Cell 6
					var bgCell6 = document.createElement('td');
					//bgCell6.setAttribute('class','thumb');
					attr = document.createAttribute('class');
				attr.value = 'thumb'; 
				bgCell6.setAttributeNode(attr);
						var a6 = document.createElement('a');
						a6.setAttribute('id','a6_'+cardNum.value);
						a6.setAttribute('href','javascript:doUpdateImage('+cardNum.value+',\'giftcards/Holiday_Certificate_'+minute+'.jpg\')');
						var img6 = document.createElement('img');
						img6.setAttribute('src','giftcards/Holiday_Certificate_Thumb.jpg');
						img6.setAttribute('width','60');
						img6.setAttribute('height','60');
						img6.setAttribute('border','0');					
						
						var br6 = document.createElement('br');
						a6.appendChild(img6);
						a6.appendChild(br6);
						a6.appendChild(document.createTextNode('Happy Holidays'));
					bgCell6.appendChild(a6);
					
					// Cell 7
					var bgCell7 = document.createElement('td');
					attr = document.createAttribute('class');
				attr.value = 'thumb'; 
				bgCell7.setAttributeNode(attr);
						var a7 = document.createElement('a');
						a7.setAttribute('id','a7_'+cardNum.value);
						a7.setAttribute('href','javascript:doUpdateImage('+cardNum.value+',\'giftcards/Hannukah_Gift_'+minute+'.jpg\')');
						var img7 = document.createElement('img');
						img7.setAttribute('src','giftcards/Hannukah_Gift_Thumb.jpg');
						img7.setAttribute('width','60');
						img7.setAttribute('height','60');
						img7.setAttribute('border','0');					
						
						var br7 = document.createElement('br');
						a7.appendChild(img7);
						a7.appendChild(br7);
						a7.appendChild(document.createTextNode('Hannukah'));
					bgCell7.appendChild(a7);
					
					// Cell 8
					var bgCell8 = document.createElement('td');
					//bgCell8.setAttribute('class','thumb');
					attr = document.createAttribute('class');
				attr.value = 'thumb'; 
				bgCell8.setAttributeNode(attr);
						var a8 = document.createElement('a');
						a8.setAttribute('id','a8_'+cardNum.value);
						a8.setAttribute('href','javascript:doUpdateImage('+cardNum.value+',\'giftcards/Christmas_Gift_'+minute+'.jpg\')');
						var img8 = document.createElement('img');
						img8.setAttribute('src','giftcards/Christmas_Gift_Thumb.jpg');
						img8.setAttribute('width','60');
						img8.setAttribute('height','60');
						img8.setAttribute('border','0');					
						
						var br8 = document.createElement('br');
						a8.appendChild(img8);
						a8.appendChild(br8);
						a8.appendChild(document.createTextNode('Christmas'));
					bgCell8.appendChild(a8);
					//ATTACHING CELLS
					bgRow.appendChild(bgCell1);
					bgRow.appendChild(bgCell2);
					bgRow.appendChild(bgCell3);
					bgRow.appendChild(bgCell4);
					bgRow.appendChild(bgCell5);
					bgRow.appendChild(bgCell6);
					bgRow.appendChild(bgCell7);
					bgRow.appendChild(bgCell8);
				// ATTACHING ROWS
				bgTable.appendChild(bgRow);
			//--------------------
			cell3.appendChild(bgHTable) ;
		row3.appendChild(cell3);
	newTable.appendChild(row3);
//Attach new table to the main table	
//	locTable.appendChild(newTable);
locTable.appendChild(newHTable);
	
	//var so = new SWFObject("swfs/card"+minute+".swf", "preview"+cardNum.value, "350", "252", "8", "#336699");
	//so.write("flashcontent"+cardNum.value);
}// for index
}

///////////////////////////////////////////
function deleteVar(id){
	//document.getElementById("sumTotal").value = document.getElementById("sumTotal").value * 1 - document.getElementById("price"+id).value * 1;
	var giftCard = document.getElementById('giftCard'+id);
	//alert('id:'+id+' giftCard:'+giftCard);
	parentObj = giftCard.parentNode;
	parentObj.removeChild(giftCard);

	var cardNum = document.getElementById("cardNum");
	var maxCard = cardNum.value *1;
	cardNum.value = maxCard-1;//cardNum.value - 1;
	start = id*1+1;
	//alert("max:"+maxCard+" start:"+start+" cardNum:"+cardNum.value);
	
	//if(start < cardNum.value){	
		for (var i = start; i <= maxCard; i++) {
			//alert("i:"+i);
			newLoc = i-1;
			//alert("newLoc:"+newLoc);
			var giftCard = document.getElementById("giftCard"+i);
			giftCard.id = "giftCard"+newLoc;
			giftCard.name = "giftCard"+newLoc;
			
			var num = document.getElementById("num"+i);
			num.removeChild(num.childNodes[0]);
			num.appendChild(document.createTextNode('Gift Certificate #'+newLoc+': '))
			num.id = "num"+newLoc;
			num.name = "num"+newLoc;
			
			var cardTo = document.getElementById("to"+i);
			cardTo.id = "to"+newLoc;
			cardTo.name = "to"+newLoc;
			
			var cardFrom = document.getElementById("from"+i);
			cardFrom.id = "from"+newLoc;
			cardFrom.name = "from"+newLoc;
			
			var cardEmail = document.getElementById("email"+i);
			cardEmail.id = "email"+newLoc;
			cardEmail.name = "email"+newLoc;
			
			var cardNote = document.getElementById("note"+i);
			cardNote.id = "note"+newLoc;
			cardNote.name = "note"+newLoc;
			cardNote.setAttribute('OnKeyUp','charCount('+newLoc+')');
							
			var divCC = document.getElementById("charCountText"+i);
			divCC.id = "charCountText"+newLoc;


			var image = document.getElementById("image"+i);
			image.id = "image"+newLoc;
			image.name = "image"+newLoc;
			
			var cardID = document.getElementById("cardID"+i);
			cardID.id = "cardID"+newLoc;
			cardID.name = "cardID"+newLoc;
			//alert("cardID:"+cardID.value);
			var cardName = document.getElementById("cardName"+i);
			cardName.id = "cardName"+newLoc;
			cardName.name = "cardName"+newLoc;
			
			var preview = document.getElementById("preview"+i);
			preview.id = "preview"+newLoc;
			preview.name = "preview"+newLoc;
			
			var previewBtn = document.getElementById('previewBtn'+i);
			previewBtn.setAttribute('onclick','doPassVar(\''+newLoc+'\')');
			previewBtn.id = "previewBtn"+newLoc;
			previewBtn.name = "previewBtn"+newLoc;
			
			var clearBtn = document.getElementById('clearBtn'+i);
			clearBtn.setAttribute('onclick','clearVar('+newLoc+')');
			clearBtn.id = "clearBtn"+newLoc;
			clearBtn.name = "clearBtn"+newLoc;
			
			var deleteBtn = document.getElementById('deleteBtn'+i);
			var newFn = updateDeleteFn(deleteBtn.getAttribute('onclick'),newLoc);
			deleteBtn.setAttribute('onclick',newFn);
			deleteBtn.id = "deleteBtn"+newLoc;
			deleteBtn.name = "deleteBtn"+newLoc;
			
			for(j=1;j<=6;j++){
				var a6 = document.getElementById('a'+j+'_'+i);
				//alert("i exit:"+i+" j:"+j+" a6:"+a6.href);
				var abc = updateURL(a6.href,newLoc);
				//alert(abc);
				a6.setAttribute('href',abc);
				a6.id = 'a'+j+'_'+newLoc;
				a6.name = 'a'+j+'_'+newLoc;
				
			}
			
		}
	//}

}
function deletePackage(id,lot,lotID,productID){
	//alert("id:"+id+" lot:"+lot+" lotID:"+lotID);
	if(lot==1){
		var where_to= confirm("Would you like to delete this card?");
	}else{
		var where_to= confirm("This card is a part of the package deal. Would you like to delete the entire package?");
	}
	var minID = id-lotID;
	var maxID = minID+lot-1;
	if (where_to== true)
 	{
		document.getElementById("sumTotal").value = document.getElementById("sumTotal").value * 1 - document.getElementById("price"+productID).value * 1;
		for(iDel=maxID;iDel>=minID;iDel--){
			//alert("iDel:"+iDel);
			deleteVar(iDel);
		}
	}else{
  		return false;
  	}
}
function updateURL(url,newLoc){
	var str = url.split(',');
	var id = str[0].split('(');
	return id[0]+'('+newLoc+','+str[1];
}
function updateDeleteFn(fn,newLoc){
	var str = fn.split(',');
	var id = str[0].split('(');
	return id[0]+'('+newLoc+','+str[1]+','+str[2]+','+str[3];
}
function deleteSubMenu(id){
	//Delete the old sub menu
	oldCurrent = document.getElementById("currentInput"+id);
	parentCur = oldCurrent.parentNode;
	
	if(oldCurrent.value!="none"){
		oldInput = document.getElementById(oldCurrent.value+id);
		if(oldInput != null){
			oldParent = oldInput.parentNode;
			oldParent.removeChild(oldInput);
		}
		//deleteAddDelete(id);
	}
	parentCur.removeChild(document.getElementById("currentInput"+id));
}
function alertCancel(){
	var where_to= confirm("Are you sure you want to cancel this order?");
	if (where_to== true)
 	{
   		window.location = "giftcards.php";
 	}
	else
 	{
  		return false;
  	}
}
/*
function autoEllipseText(element, text, width)
{
   element.innerHTML = '<span id="ellipsisSpan"
      style="white-space:nowrap;">' + text + '</span>';
   inSpan = document.getElementById('ellipsisSpan');
   if(inSpan.offsetWidth> width)
   {
      var i = 1;
      inSpan.innerHTML = '';
      while(inSpan.offsetWidth <(width) && i <text.length)
      {
         inSpan.innerHTML = text.substr(0,i) + '...';
         i++;
      }
       
      returnText = inSpan.innerHTML;
      element.innerHTML = '';
      return returnText;
   }
   return text;
}
function setCellText()
{	alert("setCellText");
	//alert(str);
   cellElement = document.getElementById('textCell'+str);
   textBoxElement = document.getElementById('to'+str);
   cellElement.innerHTML = autoEllipseText(cellElement, textBoxElement.value, 80);
}
*/
