// Global vars
var ns = (document.all)?false:true;
var str_tmp_line_one;
var str_tmp_line_two;
var str_tmp_line_three;
var str_tmp_line_four;


// Initialize default Options.
function start_application(refer) {
	// Erase text fields if the user refreshes the browser.
	erase_fields();
	
	// Set order id.
	$('oc_order_id').setProperty('value', generate_random_number(10));
	
	// Set default envelope.
	if(refer == '1') {
		select_envelope('Env #6 3/4');
	}
	else {
		select_envelope('Env #10');
	}
	
	// Load introductory color option for the envelope.
	$('oc_color_option').setProperty('value', 'Black & White');
	
	// Set default color.
	select_color('#000000');
	
	// Set default font.
	select_font('arial');
	
	// Load introductory text into the envelope.
	$('oc_text_one').setProperty('value', 'Company/Office/Name');
	load_text_one();
	
	$('oc_text_two').setProperty('value', 'Specification');
	load_text_two();
	
	$('oc_text_three').setProperty('value', 'Address');
	load_text_three();
	
	$('oc_text_four').setProperty('value', 'City, State Zip');
	load_text_four();
}


// Checks what kind of submission was chosen for the form.
function check_submission() {
	var str_env_id;
	var str_envelope_chosen;
	
	// Get which envelope to pass proper id
	str_envelope_chosen = $('oc_envelope').getProperty('value');
	
	// Get envelope color information
	var str_envelope_color = $('oc_color_option').getProperty('value');
	
	// Clean_font_name
	$('oc_font_face').setProperty('value', clean_font_name($('oc_font_face').getProperty('value')));
	
	// Get the string color value
	$('oc_text_color').setProperty('value', hex_to_word($('oc_text_color').getProperty('value')));
	
	// Get the iamge name.
	var str_image = remove_extension($('oc_image').getProperty('value'));
	
	// Check if they uploaded an image.
	if(str_image == "no_image") {
		str_image = $('oc_order_id').getProperty('value') + '_' + remove_extension($('oc_image').getProperty('value'))
	}
	
	// Set the image.
	$('oc_image_order').setProperty('value', str_image);
	
	// Setup the action to submit to store.

	var product_id = document.getElementById('products_id').value;
//	var quantity_name = document.getElementById('real_quantity_name').value;
//	var quantity_value = document.getElementById('real_quantity_value').value;

//	if(document.getElementById('real_sample_name')) {
//		var sample_name = document.getElementById('real_sample_name').value;
//	}
//	if(document.getElementById('real_sample_value')) {
//		var sample_value = document.getElementById('real_sample_value').value;
//	}
	
//	var send_to = 'Store/index.php?main_page=product_info&action=add_product&cPath=1&products_id='+product_id+'&'+quantity_name+'='+quantity_value;
	// Get the customization options
//	var extra_stuff = 'Color Option: '+document.getElementById('oc_color_option').value+'\r\n';

	// Get the font
	var extra_stuff = 'Font: '+document.getElementById('oc_font_face').value+'\r\n';

	// Get the color
	extra_stuff += 'Color: '+document.getElementById('oc_text_color').value+'\r\n';

	// Get the lines of text
	extra_stuff += 'Line 1: '+document.getElementById('oc_text_one').value+'\r\n';
	extra_stuff += 'Line 2: '+document.getElementById('oc_text_two').value+'\r\n';
	extra_stuff += 'Line 3: '+document.getElementById('oc_text_three').value+'\r\n';
	extra_stuff += 'Line 4: '+document.getElementById('oc_text_four').value+'\r\n';

	// Get the image chosen if any
	extra_stuff += 'Envelope Proof: http://myenvelopes247.com/Uploads/orders/'+document.getElementById('oc_image_order').value+'.png\r\n';
	extra_stuff += 'PDF: http://myenvelopes247.com/Uploads/orders/'+document.getElementById('oc_file').value;

	document.getElementById('extra_stuff').innerHTML = '<textarea name=id[txt_'+product_id+']>'+extra_stuff+'</textarea>';
	var send_to = 'Store/index.php?main_page=product_info&action=add_product&cPath=1&products_id='+product_id;

//	if(sample_name && sample_value) {
//		send_to = send_to + '&'+sample_name+'='+sample_value;
//	}
//
//	alert(send_to);

	$('envelope_form').action = send_to;	
	$('envelope_form').target = '_self';
	
	$('order_envelope').setProperty('disabled', 'true');
	return true;
}


// Generates the image for the order.
function generate_image_order() {
	// Get Envelope
	var str_envelope = $('oc_envelope').getProperty('value');
	str_envelope = str_envelope.replace("#", "");
	
	// Get the font
	var str_font_face = $('oc_font_face').getProperty('value');
	
	// Get the color
	var str_color = $('oc_text_color').getProperty('value');
	str_color = str_color.replace("#", "");
	
	// Get the text
	var str_text_one = $('oc_text_one').getProperty('value');
	var str_text_two = $('oc_text_two').getProperty('value');
	var str_text_three = $('oc_text_three').getProperty('value');
	var str_text_four = $('oc_text_four').getProperty('value');
	
	// Get the text left and top
	var int_text_top = $('line_container').getStyle('top');
	var int_text_left = $('line_container').getStyle('left');
	
	// Get order id
	var int_order_id = $('oc_order_id').getProperty('value'); 
	
	// Get the image left, top, width, height, name.
	var int_image_top = $('graphic_container').getStyle('top');
	var int_image_left = $('graphic_container').getStyle('left'); 
	var str_image_name = remove_extension($('oc_image').getProperty('value')); 
	var str_image_ext = get_extension($('oc_image').getProperty('value')); 
	var int_image_width = $('envelope_graphic').getStyle('width');
	var int_image_height = $('envelope_graphic').getStyle('height');
	
	var str_file = $('oc_file').getProperty('value');

	// Setup parameters to generate image.
	var str_url = "lib/functions/merge.php?e="+str_envelope+
					  "&f="+str_font_face+
					  "&c="+str_color+
					  "&t1="+urlencode(str_text_one)+
					  "&t2="+urlencode(str_text_two)+
					  "&t3="+urlencode(str_text_three)+
					  "&t4="+urlencode(str_text_four)+
					  "&t_t="+int_text_top+
					  "&t_l="+int_text_left+
					  "&i_t="+int_image_top+
					  "&i_l="+int_image_left+
					  "&i_id="+int_order_id+
					  "&i_n="+str_image_name+
					  "&i_e="+str_image_ext+
					  "&i_w="+parseInt(int_image_width)+
					  "&i_h="+parseInt(int_image_height)+
					  "&file="+str_file+
					  "&keepThis=true&TB_iframe=true&height=150&width=300";
		
		// Show the generation of the image.
		TB_show('Generating Envelope Image...', str_url, 'false');
}


// Disables the enter key from submitting form.
function disable_enter_key(e) {
    var key;

    if(window.event) {
		key = window.event.keyCode; //IE
	}  
    else {
        key = e.which;     			// Others
	}
	
    if(key == 13) {
        return false;
    }
    else {
		return true;
	}
}


// Displays the envelope hovered over.
function show_envelope() {	
	var layer_object;
	
	if (ns) {
		layer_object = document.getElementById('envelope_container').style;
	} 
	else  {
		layer_object = eval('envelope_container' + ".style");
	}
	
	switch ($('oc_envelope').getProperty('value')) {
		case "Env #10":
			str_env = "envelope_ten";
			break;
			
		case "Env #10 Win":
			str_env = "envelope_ten_w";
			break;
			
		case "Env #9":
			str_env = "envelope_nine";
			break;
			
		case "Env #9 Win":
			str_env = "envelope_nine_w";
			break;
			
		case "Env #6 3/4":
			str_env = "envelope_six";
			break;
	}
	
	layer_object.backgroundImage = "url('lib/images/envelopes/" + str_env + ".png')";
}

// Setup the new envelop options
function has_security() {
	if(document.getElementById('security_checkbox')) {
		var sec_checked = document.getElementById('security_checkbox').checked;
	}
	if(($('oc_envelope').value == "Env #6 3/4") || (document.getElementById('type_3') && document.getElementById('type_3').checked == true)) {
		var no_sec = true;
	}
	else {
		var no_sec = false;
	}

	var security_div = '<input type="checkbox" name="security_checkbox" value="65" id="security_checkbox" onClick=\"price_updater(); has_types();\"/><label class="attribsCheckbox" for="security_checkbox" alt="Blue tinted inlet to protect inserts from shining thru. Additional $10/500 envelopes." title="Blue tinted inlet to protect inserts from shining thru. Additional $10/500 envelopes." style="font-size: 10px;"> Security Tinted</label><br />';

	if(!no_sec) {
		document.getElementById('show_security').innerHTML = security_div;
	}
	else {
		document.getElementById('show_security').innerHTML = '';
	}
	if(sec_checked && document.getElementById('security_checkbox')) {
		document.getElementById('security_checkbox').checked = true;
	}

	price_updater();
}
function has_types() {
	if(document.getElementById('type_1')) {
		var t1_checked = document.getElementById('type_1').checked;
	}
	if(document.getElementById('type_2')) {
		var t2_checked = document.getElementById('type_2').checked;
	}
	if(document.getElementById('type_3')) {
		var t3_checked = document.getElementById('type_3').checked;
	}
	if(document.getElementById('security_checkbox')) {
		var sec_checked = document.getElementById('security_checkbox').checked;
	}

	var type1 = '<input type="radio" name="env_type" value="62" id="type_1" onClick=\"price_updater(); has_security();\" checked/><label class="attribsRadioButton zero" for="type_1" alt="Standard envelope stock" title="Standard envelope stock" style="font-size: 10px;">24lb Std. White Wove</label><br />';
	var type2 = '<input type="radio" name="env_type" value="63" id="type_2" onClick=\"price_updater(); has_security();\" /><label class="attribsRadioButton zero" for="type_2" alt="Also known as Redi-Seal, Easy Seal or Stick\'n Seal - No moisture necessary, just raise flap and seal. Additional $15/500 envelopes." title="Also known as Redi-Seal, Easy Seal or Stick\'n Seal - No moisture necessary, just raise flap and seal. Additional $15/500 envelopes." style="font-size: 10px;">Simple Seal</label><br />';
	var type3 = '<input type="radio" name="env_type" value="64" id="type_3" onClick=\"price_updater(); has_security();\" /><label class="attribsRadioButton zero" for="type_3" alt="We use envelopes made from recycled paper - only available as gummed envelopes. Additional $10/500 envelopes." title="We use envelopes made from recycled paper - only available as gummed envelopes. Additional $10/500 envelopes." style="font-size: 10px;">Eco-friendly <img src=\"recyclelogonw.jpg\" width=20 align=right></label>';

	var show_types = '';

	switch($('oc_envelope').value) {
		case "Env #10":
			if(!sec_checked) show_types = type1 + type2 + type3;
			else show_types = type1 + type2;
			document.getElementById('show_type').innerHTML = show_types;
		break;
		
		case "Env #10 Win":
			if(!sec_checked) show_types = type1 + type2 + type3;
			else show_types = type1 + type2;
			document.getElementById('show_type').innerHTML = show_types;
		break;
		
		case "Env #9":	
			if(!sec_checked) show_types = type1 + type3;
			else show_types = type1;
			document.getElementById('show_type').innerHTML = show_types;
		break;
			
		case "Env #9 Win":
			if(!sec_checked) show_types = type1 + type3;
			else show_types = type1;
			document.getElementById('show_type').innerHTML = show_types;
		break;
			
		case "Env #6 3/4":	
			show_types = type1 + type3;
			document.getElementById('show_type').innerHTML = show_types;
		break;
	}

	if(t1_checked) {
		document.getElementById('type_1').checked = true;
	}
	if(t2_checked) {
		document.getElementById('type_2').checked = true;
	}
	if(t3_checked) {
		document.getElementById('type_3').checked = true;
	}
}

// Selects the envelope clicked.
function select_envelope(str_value) {
	// Set the envelope chosen to our hidden field.
	$('oc_envelope').setProperty('value', str_value);
	
	// Shows the envelope.
	show_envelope();
	
	// Highlight the slected envelope.
	highlight_selected_envelope();

	has_types();
	has_security();
}

// Highlights the envelope clicked.
function highlight_selected_envelope() {
	switch($('oc_envelope').value) {
		case "Env #10":
			$('a_envelope_ten').className = 'env_buttons_current';
			$('a_envelope_ten_w').className = 'env_buttons';
			$('a_envelope_nine').className = 'env_buttons';
			$('a_envelope_nine_w').className = 'env_buttons';
			$('a_envelope_six').className = 'env_buttons';
			document.getElementById('note_6').style.display = 'none';
			break;
		
		case "Env #10 Win":
			$('a_envelope_ten').className = 'env_buttons';
			$('a_envelope_ten_w').className = 'env_buttons_current';
			$('a_envelope_nine').className = 'env_buttons';
			$('a_envelope_nine_w').className = 'env_buttons';
			$('a_envelope_six').className = 'env_buttons';
			document.getElementById('note_6').style.display = 'none';
			break;
		
		case "Env #9":	
			$('a_envelope_ten').className = 'env_buttons';
			$('a_envelope_ten_w').className = 'env_buttons';
			$('a_envelope_nine').className = 'env_buttons_current';
			$('a_envelope_nine_w').className = 'env_buttons';
			$('a_envelope_six').className = 'env_buttons';
			document.getElementById('note_6').style.display = 'none';
			break;
			
		case "Env #9 Win":
			$('a_envelope_ten').className = 'env_buttons';
			$('a_envelope_ten_w').className = 'env_buttons';
			$('a_envelope_nine').className = 'env_buttons';
			$('a_envelope_nine_w').className = 'env_buttons_current';
			$('a_envelope_six').className = 'env_buttons';
			document.getElementById('note_6').style.display = 'none';
			break;
			
		case "Env #6 3/4":	
			$('a_envelope_ten').className = 'env_buttons';
			$('a_envelope_ten_w').className = 'env_buttons';
			$('a_envelope_nine').className = 'env_buttons';
			$('a_envelope_nine_w').className = 'env_buttons';
			$('a_envelope_six').className = 'env_buttons_current';
			document.getElementById('note_6').style.display = '';
			break;
	}	
}


// Updates and displays all of the options chosen.
function update_options_chosen(int_step) {
	// Get the envelope type chosen
	var str_envelope_type = $('oc_envelope').getProperty('value');
		
	// The color.
	var str_color;
	
	// Get the color Chosen
	switch($('oc_text_color').getProperty('value')) {
		case "#000000":
			str_color = 'Color: <span style="color: #000000;">' + hex_to_word("#000000") +'</span>';
			break;
		
		case "#00aeef":
			str_color = 'Color: <span style="color: #00aeef;">' + hex_to_word("#00aeef") +'</span>';
			break;
			
		case "#ee1c23":
			str_color = 'Color: <span style="color: #ee1c23;">' + hex_to_word("#ee1c23") +'</span>';
			break;	
		
		case "#00a54f":
			str_color = 'Color: <span style="color: #00a54f;">' + hex_to_word("#00a54f") +'</span>';
			break;		
		
		case "#c80067":
			str_color = 'Color: <span style="color: #c80067;">' + hex_to_word("#c80067") +'</span>';
			break;	
		
		case "#0075b8":
			str_color = 'Color: <span style="color: #0075b8;">' + hex_to_word("#0075b8") +'</span>';
			break;		
	}
	
	
	// Get Font information
	var str_font_face = $('oc_font_face').getProperty('value');
	var str_font = 'Font: ' + clean_font_name(str_font_face); 
	var str_quantity = $('env_quantity').getProperty('value');

	// Get envelope color information
	var str_envelope_color = $('oc_color_option').getProperty('value');

	if(document.getElementById('security_checkbox')) {		
		if(document.getElementById('security_checkbox').checked) {
			var str_tinted = ' Security Tinted ';
		}
	}
	if(!str_tinted) {
		var str_tinted = '';
	}

	str_price = document.getElementById('show_price').innerHTML;

	// Check to see what step we are in and update the options chosen.
	switch(int_step) {
		case 1:
			//show_active_envelope(str_envelope_type);
//			$('options_chosen').innerHTML = str_envelope_type;
//			$('options_chosen').innerHTML = str_envelope_type + ' &raquo; ' + str_envelope_color + ' Envelope';
			$('options_chosen').innerHTML = str_envelope_type + str_tinted + ' x ' + str_quantity + ' &raquo; ' + str_envelope_color + ' Print &raquo; ' + str_price;

			break;
			
		case 2:
//			$('options_chosen').innerHTML = str_envelope_type + ' &raquo; ' + str_envelope_color + ' Envelope';
//			$('options_chosen').innerHTML = str_envelope_type + ' &raquo; ' + str_envelope_color + ' Envelope' + ' &raquo; ' + str_font + ' &raquo; ' + str_color;

			break;
			
		case 3:
			$('options_chosen').innerHTML = str_envelope_type + str_tinted + ' x ' + str_quantity + ' &raquo; ' + str_envelope_color + ' Print &raquo; ' + str_font + ' &raquo; ' + str_color + ' &raquo; ' + str_price;

//			$('options_chosen').innerHTML = str_envelope_type + ' &raquo; ' + str_envelope_color + ' Envelope' + ' &raquo; ' + str_font + ' &raquo; ' + str_color;

//			$('options_chosen').innerHTML = str_envelope_type + ' &raquo; ' + str_envelope_color + ' Envelope' + ' &raquo; ' + str_font + ' &raquo; ' + str_color;
			break;
	}
}


// Changes  the hex value of color to word
function set_color_option(str_value) {
	$('oc_color_option').setProperty('value', str_value);
}


// Changes  the hex value of color to word
function hex_to_word(str_hex) {
	// Get the color Chosen
	switch(str_hex) {
		case "#000000":
			return "Black";
			break;
		
		case "#00aeef":
			return "Process Blue";
			break;
			
		case "#ee1c23":
			return "Red PMS 185";
			break;	
		
		case "#00a54f":
			return "Amazon Green";
			break;		
		
		case "#c80067":
			return "Burgundy";
			break;	
		
		case "#0075b8":
			return "Reflex Blue";
			break;		
	}
}


// Cleans the font name.
function clean_font_name(str_font_face) {
	var str_font = str_font_face.replace(/_/gi, ' ');
	str_font = word_to_upper(str_font);
	return str_font;
}


// Uppercases every first word.
function word_to_upper(str_sentence) {
    return str_sentence.toLowerCase().replace(/\b[a-z]/g, convert_it);
        
	function convert_it() {
		return arguments[0].toUpperCase();
    }
}


// Updates text colors and fonts after user has changed an option.
function update_customization() {
	var str_text_one = $('oc_text_one').getProperty('value');
	var str_text_two = $('oc_text_two').getProperty('value');
	var str_text_three = $('oc_text_three').getProperty('value');
	var str_text_four = $('oc_text_four').getProperty('value');
	
	if (str_text_one == "" && str_text_two == "" && str_text_three == "" && str_text_four == "") {
		return;
	}
	else {
		load_text_one();
		load_text_two();
		load_text_three();
		load_text_four();	
	}
}


// Erases the fields when the browser is refreshed.
function erase_fields() {
	$('oc_envelope').setProperty('value', '');
	$('oc_color_option').setProperty('value', '');
	$('oc_font_face').setProperty('value', '');
	$('oc_text_color').setProperty('value', '');
	$('oc_text_one').setProperty('value', '');
	$('oc_text_two').setProperty('value', '');
	$('oc_text_three').setProperty('value', '');
	$('oc_text_four').setProperty('value', '');
	$('oc_image').setProperty('value', 'no_image.png');
	$('oc_file').setProperty('value', '');
	$('oc_image_order').setProperty('value', '');
}


// Sets the text color in the div of the color chosen.
function hide_text() {
	//
	str_tmp_line_one = $('oc_text_one').getProperty('value');
	str_tmp_line_two = $('oc_text_two').getProperty('value');;
	str_tmp_line_three = $('oc_text_three').getProperty('value');;
	str_tmp_line_four = $('oc_text_four').getProperty('value');;
	
	//
	$('oc_text_one').setProperty('value', '');
	$('envelope_text_one').src='lib/images/no_image.png';
	$('oc_text_two').setProperty('value', '');
	$('envelope_text_two').src='lib/images/no_image.png';
	$('oc_text_three').setProperty('value', '');
	$('envelope_text_three').src='lib/images/no_image.png';
	$('oc_text_four').setProperty('value', '');
	$('envelope_text_four').src='lib/images/no_image.png';
}


// Sets the text color in the div of the color chosen.
function show_text() {
	$('oc_text_one').setProperty('value', str_tmp_line_one);
	load_text_one();
	$('oc_text_two').setProperty('value', str_tmp_line_two);
	load_text_two();
	$('oc_text_three').setProperty('value', str_tmp_line_three);
	load_text_three();
	$('oc_text_four').setProperty('value', str_tmp_line_four);
	load_text_four();
}


// Sets the text color in the div of the color chosen.
function select_color(int_color) {
	$('active_color').style.background = int_color;
	$('oc_text_color').setProperty('value', int_color);
	
	update_customization();
}

function show_colors() {
	var one_color = document.getElementById('one_color');
	var button = document.getElementById('color_button');

	if(one_color && one_color.checked == true) {
		button.style.display = '';
	}
	else {
		button.style.display = 'none';
	}
}
// Selects the font chosen.	
function select_font(str_font) {
	$('font_face_chosen').src = 'lib/images/font_drop_down/' + str_font + '.png';
	$('oc_font_face').setProperty('value', str_font);
	
	update_customization();
}


// Prints the envelope.
function print_envelope() {
	// Get Envelope
	var str_envelope = $('oc_envelope').getProperty('value');
	str_envelope = str_envelope.replace("#", "");
	
	// Get the font
	var str_font_face = $('oc_font_face').getProperty('value');
	
	// Get the color
	var str_color = $('oc_text_color').getProperty('value');
	str_color = str_color.replace("#", "");
	
	// Get the text
	var str_text_one = $('oc_text_one').getProperty('value');
	var str_text_two = $('oc_text_two').getProperty('value');
	var str_text_three = $('oc_text_three').getProperty('value');
	var str_text_four = $('oc_text_four').getProperty('value');
	
	// Get the text left and top
	var int_text_top = $('line_container').getStyle('top');
	var int_text_left = $('line_container').getStyle('left');
	
	// Get the image left, top, width, height, name.
	var int_image_top = $('graphic_container').getStyle('top');
	var int_image_left = $('graphic_container').getStyle('left'); 
	var str_image_name = remove_extension($('oc_image').getProperty('value')); 
	var str_image_ext = get_extension($('oc_image').getProperty('value')); 
	var int_image_width = $('envelope_graphic').getStyle('width');
	var int_image_height = $('envelope_graphic').getStyle('height');
	
	var str_url = "PrintEnvelope.php?e="+str_envelope+
				  "&f="+str_font_face+
				  "&c="+str_color+
				  "&t1="+urlencode(str_text_one)+
				  "&t2="+urlencode(str_text_two)+
				  "&t3="+urlencode(str_text_three)+
				  "&t4="+urlencode(str_text_four)+
				  "&t_t="+int_text_top+
				  "&t_l="+int_text_left+
				  "&i_t="+int_image_top+
				  "&i_l="+int_image_left+
				  "&i_n="+str_image_name+
				  "&i_e="+str_image_ext+
				  "&i_w="+parseInt(int_image_width)+
				  "&i_h="+parseInt(int_image_height)+
				  "&keepThis=true&TB_iframe=true&height=460&width=700";
				
	$('pbc').setProperty('href', str_url);
}


// Equivalent to PHP's urlencode() function.
function urlencode(str) {            
    var histogram = {}, histogram_r = {}, code = 0, tmp_arr = [];
    var ret = str.toString();
    
    var replacer = function(search, replace, str) {
        var tmp_arr = [];
        tmp_arr = str.split(search);
        return tmp_arr.join(replace);
    };
    
    // The histogram is identical to the one in urldecode.
    histogram['!']   = '%21';
    histogram['%20'] = '+';
    
    // Begin with encodeURIComponent, which most resembles PHP's encoding functions
    ret = encodeURIComponent(ret);
    
    for (search in histogram) {
        replace = histogram[search];
        ret = replacer(search, replace, ret) // Custom replace. No regexing
    }
    
    // Uppercase for full PHP compatibility
    return ret.replace(/(\%([a-z0-9]{2}))/g, function(full, m1, m2) {
        return "%"+m2.toUpperCase();
    });
    
    return ret;
}


// Loads the text through ajax as an image.
function load_text_one() {
	var str_text = $('oc_text_one').getProperty('value');
	load_text(str_text, 1);
	check_if_empty(1);
}


// Loads the text through ajax as an image.
function load_text_two() {
	var str_text = $('oc_text_two').getProperty('value');
	load_text(str_text, 2);
	check_if_empty(2);
}


// Loads the text through ajax as an image.
function load_text_three() {
	var str_text = $('oc_text_three').getProperty('value');
	load_text(str_text, 3);
	check_if_empty(3);
}


// Loads the text through ajax as an image.	
function load_text_four() {
	var str_text = $('oc_text_four').getProperty('value');
	load_text(str_text, 4);
	check_if_empty(4);
}



function check_if_empty(int_line) {
	switch(int_line) {
		case 1:
			if($('oc_text_one').getProperty('value') == "") {
				$('envelope_text_one').src='lib/images/no_image.png';
			}
			break;
		
		case 2:
			if($('oc_text_two').getProperty('value') == "") {
				$('envelope_text_two').src='lib/images/no_image.png';
			}
			break;
			
		case 3:
			if($('oc_text_three').getProperty('value') == "") {
				$('envelope_text_three').src='lib/images/no_image.png';
			}
			break;
			
		case 4:
			if($('oc_text_four').getProperty('value') == "") {
				$('envelope_text_four').src='lib/images/no_image.png';
			}
			break;
	}
}


// Loads the text, color & font chosen in the specified div.	
function load_text(str_text, int_line) {
	// Text Color
	int_color = $('oc_text_color').getProperty('value');
	int_color = int_color.replace("#", "");
	
	// Font face
	str_font = $('oc_font_face').getProperty('value');
	
	switch(int_line) {
		case 1:
			$('envelope_text_one').src='lib/functions/generator.php?t=' + urlencode(str_text) + '&l=' + int_line + '&c=' + int_color + '&f=' + str_font;
			break;
		
		case 2:
			$('envelope_text_two').src='lib/functions/generator.php?t=' + urlencode(str_text) + '&l=' + int_line + '&c=' + int_color + '&f=' + str_font;
			break;
			
		case 3:
			$('envelope_text_three').src='lib/functions/generator.php?t=' + urlencode(str_text) + '&l=' + int_line + '&c=' + int_color + '&f=' + str_font;
			break;
			
		case 4:
			$('envelope_text_four').src='lib/functions/generator.php?t=' + urlencode(str_text) + '&l=' + int_line + '&c=' + int_color + '&f=' + str_font;
			break;
	}
}
