

function popUp(URL) {
		day = new Date();
		id = day.getTime();
		eval("page" + id + " = window.open(URL, '" + id + "', 'scrollbars=1,width=1600,height=400,left = -80,top = 250');");
}
function getimage(){
	
		var textsays = document.image_generator.text_string.value;
		newtext = escape(textsays);
		var tcolorselect = document.image_generator.text_color.value;
		tcolorselect = escape(tcolorselect);
		var bgcolorselect = document.image_generator.bg_color.value;
		bgcolorselect = escape(bgcolorselect);
		var fontselect = document.image_generator.font.value;
		fontselect = escape(fontselect);
		document.preview_image.src = "preview_image.php?text_string=" + newtext + "&text_color=" + tcolorselect + "&bg_color=" + bgcolorselect + "&font=" + fontselect;
		newtext = escape(newtext);
		document.getElementById("lg_prev").href = "javascript:popUp('preview_lg_image.php?text_string=" + newtext + "&text_color=" + tcolorselect + "&bg_color=" + bgcolorselect + "&font=" + fontselect + "')";
		

		var stringcount = document.image_generator.text_string.value;
		var nospaces = stringcount.replace(" ","");
		while(nospaces.match(" ") != null){
			nospaces = (nospaces.replace(" ",""));
		}
		var charactercount = nospaces.length;
		document.getElementById("totalchars").firstChild.nodeValue = charactercount;

		
		document.getElementById("onelength").firstChild.nodeValue = Math.round(charactercount * .5);
		document.getElementById("onehalflength").firstChild.nodeValue = Math.round(1.5 * charactercount * .5);
		document.getElementById("twolength").firstChild.nodeValue = Math.round(2 * charactercount * .5);
		document.getElementById("twohalflength").firstChild.nodeValue = Math.round(2.5 * charactercount * .5);
		document.getElementById("threelength").firstChild.nodeValue = Math.round(3 * charactercount * .5);
		document.getElementById("fourlength").firstChild.nodeValue = Math.round(4 * charactercount * .5);
		document.getElementById("fivelength").firstChild.nodeValue = Math.round(5 * charactercount * .5);
		document.getElementById("sixlength").firstChild.nodeValue = Math.round(6 * charactercount * .5);
		document.getElementById("sevenlength").firstChild.nodeValue = Math.round(7 * charactercount * .5);
		document.getElementById("eightlength").firstChild.nodeValue = Math.round(8 * charactercount * .5);
		document.getElementById("ninelength").firstChild.nodeValue = Math.round(9 * charactercount * .5);
		document.getElementById("tenlength").firstChild.nodeValue = Math.round(10 * charactercount * .5);
		document.getElementById("elevenlength").firstChild.nodeValue = Math.round(11 * charactercount * .5);
		document.getElementById("twelvelength").firstChild.nodeValue = Math.round(12 * charactercount * .5);

		//displays the price in the selct table
		document.getElementById("onemoney").firstChild.nodeValue = "$" + getcents(Math.round(100 * charactercount * .5)/100);
		document.getElementById("onehalfmoney").firstChild.nodeValue = "$" + getcents(Math.round(100 * charactercount * .6)/100);
		document.getElementById("twomoney").firstChild.nodeValue = "$" + getcents(Math.round(100 * charactercount * .75)/100);
		document.getElementById("twohalfmoney").firstChild.nodeValue = "$" + getcents(Math.round(100 * charactercount * .9)/100);
		document.getElementById("threemoney").firstChild.nodeValue = "$" + getcents(Math.round(100 * charactercount * 1)/100);
		document.getElementById("fourmoney").firstChild.nodeValue = "$" + getcents(Math.round(100 * charactercount * 1.1)/100);
		document.getElementById("fivemoney").firstChild.nodeValue = "$" + getcents(Math.round(100 * charactercount * 1.25)/100);
		document.getElementById("sixmoney").firstChild.nodeValue = "$" + getcents(Math.round(100 * charactercount * 1.5)/100);
		document.getElementById("sevenmoney").firstChild.nodeValue = "$" + getcents(Math.round(100 * charactercount * 1.75)/100);
		document.getElementById("eightmoney").firstChild.nodeValue = "$" + getcents(Math.round(100 * charactercount * 2)/100);
		document.getElementById("ninemoney").firstChild.nodeValue = "$" + getcents(Math.round(100 * charactercount * 2.25)/100);
		document.getElementById("tenmoney").firstChild.nodeValue = "$" + getcents(Math.round(100 * charactercount * 2.5)/100);
		document.getElementById("elevenmoney").firstChild.nodeValue = "$" + getcents(Math.round(100 * charactercount * 3)/100);
		document.getElementById("twelvemoney").firstChild.nodeValue = "$" + getcents(Math.round(100 * charactercount * 3.5)/100);	

		var theone
		for (i=0;i<(document.image_generator.per_letter.length);i++){
			if (document.image_generator.per_letter[i].checked==true){
				theone=i;
			break; //exist for loop, as target acquired.
			}
		}
		
		var lettercost = document.image_generator.per_letter[theone].value;
		var price = lettercost * charactercount;
		price=Math.round(price*100)/100;
		//alert(price);
				
		var height_equals
		if(lettercost == .5){height_equals = 1;}
		if(lettercost == .6){height_equals = 1.5;}
		if(lettercost == .75){height_equals = 2;}
		if(lettercost == .9){height_equals = 2.5;}
		if(lettercost == 1){height_equals = 3;}
		if(lettercost == 1.1){height_equals = 4;}
		if(lettercost == 1.25){height_equals = 5;}
		if(lettercost == 1.5){height_equals = 6;}
		if(lettercost == 1.75){height_equals = 7;}
		if(lettercost == 2){height_equals = 8;}
		if(lettercost == 2.25){height_equals = 9;}
		if(lettercost == 2.5){height_equals = 10;}
		if(lettercost == 3){height_equals = 11;}
		if(lettercost == 3.5){height_equals = 12;}
		document.image_generator.letter_height.value = height_equals;
		
		
		document.image_generator.amount.value = price;
		document.image_generator.os0.value = document.image_generator.text_string.value + ' ' + '(' +  height_equals + ' inches)';
		document.image_generator.os1.value = document.image_generator.font.value + ' ' + '(' + document.image_generator.text_color.value + ')';
		//document.image_generator.os2.value = document.image_generator.text_color.value;
		
		
		

}
		
function getcents(num){
		 num = num.toString();
		 digitcount = num.length; 
		 decimalpoint = num.indexOf(".");
		 if(decimalpoint == -1){
		 	num += ".00"
		 }else if(digitcount - decimalpoint == 2){ 
		 	num += "0";
		 }
		return(num);	
}

function getprice(num){
	var stringcount = document.image_generator.text_string.value;
		var nospaces = stringcount.replace(" ","");
		while(nospaces.match(" ") != null){
			nospaces = (nospaces.replace(" ",""));
		}
		var charactercount = nospaces.length;
		var price = num * charactercount;
		
		document.image_generator.amount.value = price;
		
		var height_equals
		if(num == .5){height_equals = 1;}
		if(num == .6){height_equals = 1.5;}
		if(num == .75){height_equals = 2;}
		if(num == .9){height_equals = 2.5;}
		if(num == 1){height_equals = 3;}
		if(num == 1.1){height_equals = 4;}
		if(num == 1.25){height_equals = 5;}
		if(num == 1.5){height_equals = 6;}
		if(num == 1.75){height_equals = 7;}
		if(num == 2){height_equals = 8;}
		if(num == 2.25){height_equals = 9;}
		if(num == 2.5){height_equals = 10;}
		if(num == 3){height_equals = 11;}
		if(num == 3.5){height_equals = 12;}
		document.image_generator.letter_height.value = height_equals;
		document.image_generator.os0.value = document.image_generator.text_string.value + ' ' + '(' +  height_equals + ' inches)';
}

function cookieset(){
		var textsays = document.image_generator.text_string.value;
		newtext = escape(textsays);
		var tcolorselect = document.image_generator.text_color.value;
		tcolorselect = escape(tcolorselect);
		var bgcolorselect = document.image_generator.bg_color.value;
		bgcolorselect = escape(bgcolorselect);
		var fontselect = document.image_generator.font.value;
		fontselect = escape(fontselect);
		var productname = document.image_generator.product_name.value;
		productname = escape(productname);
		var price = document.image_generator.price.value;
		price = escape(price);
		var quantity = document.image_generator.quantity.value;
		quantity = escape(quantity);
		var letter_height = document.image_generator.letter_height.value;
		letter_height = escape(letter_height);
		
		if(document.cookie == ""){//no previous cookie
			var product_cookie_info = "-x-" + productname + "||" + price + "||" + quantity + "||" + tcolorselect + "||" + letter_height + "||" + textsays + "||" + fontselect + "||" + bgcolorselect;
			document.cookie="cart=" + product_cookie_info;
		}else{
			var old_cookie = document.cookie;
			cookie_addon = "-x-" + productname + "||" + price + "||" + quantity + "||" + tcolorselect + "||" + letter_height + "||" + textsays + "||" + fontselect + "||" + bgcolorselect;
			document.cookie="cart=" + old_cookie + cookie_addon;
		}
}

function process_cookies(){
//reading and splitting the whole cookie
	var total_price = 0;

	var whole_cookie = unescape(document.cookie);
	var each_cookie = whole_cookie.split(";");
	for (a = 0; a < each_cookie.length; a++){
		if (each_cookie[a].indexOf("cart") > -1){
			var cart = each_cookie[a].split("-x-");
			for (b = 1; b < cart.length; b++){
				var product = cart[b];
				var product_elements = product.split("||");
				var total_amount = cart_creation(product_elements);
				total_price += parseFloat(total_amount);
			}//ends for loop parsing products	
		}//ends if cookie is the cart cookie		
	}//ends for loop parsing all cookies				
	return(total_price);
}//ends process_cookie() function

function cart_creation(product_elements){
	var product_name = product_elements[0];
		var price = product_elements[1];
		var quantity = product_elements[2];
		var text_color = product_elements[3];
		var height = product_elements[4];
		var text_says = product_elements[5];
		var font = product_elements[6];
		
		price = Math.round(price *100)/100;
		price = quantity * price;
		price = getcents(price);
		
		counter++;
		//create table from cart cookie info
		document.write("<tr><td>");
			document.write("<input type='checkbox' name='delete_me' value='" + counter + "'>");
		document.write("</td><td>");	
			document.write("<h3>" + product_name + "</h3>");
		document.write("</td><td>");
			if(text_says != ""){document.write("\"" + text_says + "\"<br/>");}
			if(height != "" && isNaN(height)){
				document.write(height + "<br/>")
			}else{if (height != ""){document.write("Height: " + height + " in.<br/>");}}
			if(font != ""){document.write("Font: " + font + "<br/>");}
			if(text_color != ""){document.write("Color: " + text_color + "<br/>");}		
		document.write("</td><td>");	
			document.write("<input type='text' name='quantity" + counter + "' size='2' value='" + quantity + "'");
		document.write("</td><td>");	
			if(price != ""){document.write("$" + price);}
		document.write("</td>");
		
		return(price);
}

function delete_product(){
	var new_cookie_stuff = "drop this";
	var whole_cookie = unescape(document.cookie);
	var each_cookie = whole_cookie.split(";");
	var no_name = each_cookie[0].split("=");
	var cart = no_name[1].split("-x-");
	var counter_int = document.cart_form.delete_me.length;
	
	if (typeof counter_int  == "undefined"){counter_int = 1;}
	for (i = 0; i < counter_int; i++){
		if (document.cart_form.delete_me[i].checked == false){
				if (each_cookie[0].indexOf("cart") > -1){
						new_cookie_stuff = new_cookie_stuff + "-x-" + cart[i + 1];
				}
			
		}else{
			
		}
	}//endsFOR

	if(new_cookie_stuff.split("drop this") != ""){
	  	var clean_cookie_string_1 = new_cookie_stuff.split("drop this");
		var clean_cookie_string = clean_cookie_string_1[1];
	}else{
		document.cookie="cart=";	
	}
	if (clean_cookie_string != ""){
	document.cookie = "cart=" + clean_cookie_string;
	}
	
	window.location = "cart.php";					
	
}

function getnameboard(){
		var textsays = document.image_generator.text_string.value;
		newtext = escape(textsays.toUpperCase());
		var tcolorselect = document.image_generator.text_color.value;
		tcolorselect = escape(tcolorselect);
		var bgcolorselect = document.image_generator.bg_color.value;
		bgcolorselect = escape(bgcolorselect);
		var fontselect = document.image_generator.font.value;
		fontselect = escape(fontselect);
		var overlaytext = document.image_generator.overlay_says.value;
		overlaytext = escape(overlaytext);
		var overlaycolor = document.image_generator.overlay_color.value;
		overlaycolor = escape(overlaycolor);
		var overlayfont = document.image_generator.overlay_font.value;
		overlayfont = escape(overlayfont);
		document.preview_image.src = "name_preview.php?text_string=" + newtext + "&text_color=" + tcolorselect + "&bg_color=" + bgcolorselect + "&font=" + fontselect + "&overlay=" + overlaytext + "&overlaycolor=" + overlaycolor + "&overlayfont=" + overlayfont;
		newtext = escape(newtext);

		document.image_generator.os0.value = document.image_generator.text_string.value + ' ' + '(' +  document.image_generator.text_color.value + ' ' + document.image_generator.font.value + ')';
		document.image_generator.os1.value = document.image_generator.overlay_says.value + ' ' + '(' +  document.image_generator.overlay_color.value + ' ' + document.image_generator.overlay_font.value + ')';

}

function cookiekit(){
		var textsays = document.image_generator.text_string.value;
		newtext = escape(textsays);
		var tcolorselect = document.image_generator.text_color.value;
		tcolorselect = escape(tcolorselect);
		var bgcolorselect = document.image_generator.bg_color.value;
		bgcolorselect = escape(bgcolorselect);
		var fontselect = document.image_generator.font.value;
		fontselect = escape(fontselect);
		var productname = document.image_generator.product_name.value;
		productname = escape(productname);
		var price = document.image_generator.price.value;
		price = escape(price);
		var quantity = document.image_generator.quantity.value;
		quantity = escape(quantity);
		var overlay = document.image_generator.overlay_font.value + " " + document.image_generator.overlay_says.value + " " + document.image_generator.overlay_color.value;
		overlay = escape(overlay);
		
		if(document.cookie == ""){//no previous cookie
			var product_cookie_info = "-x-" + productname + "||" + price + "||" + quantity + "||" + tcolorselect + "||" + overlay + "||" + textsays + "||" + fontselect + "||" + bgcolorselect;
			document.cookie="cart=" + product_cookie_info;
		}else{
			var old_cookie = document.cookie;
			cookie_addon = "-x-" + productname + "||" + price + "||" + quantity + "||" + tcolorselect + "||" + overlay + "||" + textsays + "||" + fontselect + "||" + bgcolorselect;
			document.cookie="cart=" + old_cookie + cookie_addon;
		}
}

function sendcolor(y){
	
	 document.forms[y].os0.value = document.forms[y].text_color.value
	
}