	//-- [ GENERIC FUNCTIONS ] --//
		// [ Popup Generic Window ] //
		function generic($array)
			{
			/* [ URL,SCROLLBAR,PAGE TYPE,DOMAIN ] */
			$array = $array.split(",");
				
			/* [ UNIQUE WINDOWS FOR WEBSITES ] */
			$domain = document.domain;
			$domain = $domain.replace(/\b(www)\b/g,"");
			$domain = $domain.replace(/[\.-]/g,"");
			
			if(typeof($array[3])!=="undefined"&&$array[3]!=="0"){$domain = $array[3];} // [ WORLDPAY DIFFERNT ADDRESS ] //
									
			/* [ PAGE TYPE ] */
			switch($array[2])
				{
				case '1': /* [ FORM PAGES ] */
					if(typeof($array[4])=="undefined"){$array[4]=430;}
					if(typeof($array[5])=="undefined"){$array[5]=635;}
					g_win1 = window.open($array[0],$domain,"toolbar=0,location=0,directories=0,status=0,menubar=0,resizable=0,scrollbars="+$array[1]+",width="+$array[4]+",height="+$array[5]+",left=0,top=0");			
					g_win1.focus();				
					break;
				case '2': /* [ LETTER PREVIEW ] */
					if(typeof($array[4])=="undefined"){$array[4]=860;}
					if(typeof($array[5])=="undefined"){$array[5]=650;}				
					g_win2 = window.open($array[0],$domain+'_1',"toolbar=0,location=0,directories=0,status=0,menubar=0,resizable=0,scrollbars="+$array[1]+",width="+$array[4]+",height="+$array[5]+",left=0,top=0");			
					g_win2.focus();
					break;
				}
			}
			
		// [ LETTER_B4 Letter Preview ] //
		function mgeneric(form)
			{
			var newIndex = form.llist.selectedIndex; 
			$url = form.llist.options[ newIndex ].value;
			generic('preview_b.php?id='+$url+',1,2');
			}			
			
		// [ Deletion Confirmation Window ] //
		function deletion($url,$id,$msg)
			{
			var answer = confirm ("------ L-Mail Confirmation ------\n\n"+$msg+$id);
			if (answer)
			window.location=$url;
			}
			
		// [ CHECK ALL CHECKBOXES ] //	
		function checkall(chk,v)
			{
			t = 0;
			if(chk.value > 0){chk[0]=chk; lr=1;}else{lr=chk.length;}
			
			// [ SELECTION TYPE ] //
			switch(v)
				{
				case 1: // [ CHECK CHECKBOXES ] //
					switch(chk[0].checked)
						{
						case false: /* [ TURN ON ] */
							for($rloop=0; $rloop<lr; $rloop++){chk[$rloop].checked=true;}
							break;
						default: /* [ TURN OFF ] */
							for($rloop=0; $rloop<lr; $rloop++){chk[$rloop].checked=false;}
							break;
						}				
					break;
				case 2: // [ FORM VALIDATION ] //	
					for($rloop=0; $rloop<lr; $rloop++)
						{
						switch(chk[$rloop].checked)
							{ 
							case true:
								t = 1;
								break;
							}				
						}
					if(t==0){alert("------ L-Mail Confirmation ------\n\n Please select letters before proceeding."); return(false);}					
					break;
				}
			}

		// [ Set Field to Focus ] //
		function f_focus()
			{
			this.focus();
			}	
		
		// [ Pre-format Field ] //
		function preformat($var)
			{
			switch($var.defaultValue)
				{
				case $var.value:			
					$var.value = "";
					break;
				}
			}
			
		// [ HIDDEN EMAIL ADDRESS STOP SPAM ] //
		function email($v)
			{
			//var $a,$b,$c;
			$a = '@';
			$b = 'l-mail.com';
			$c = $v+$a+$b;
			return("<a href=\"mailto:"+$c+"\">"+$c+"</a>");
			}							
		
		// [ Date Format Selector Function - formatting.php ] //
		function df_format($session_var) 
			{
			if(document.formatting_form.df_menu.value != "")
				{
				variable = "";
				variable2 = "";
				replacement = "";
				variable = document.formatting_form.l_formatting.value;

				if(variable.indexOf($session_var) != -1)
					{
					replacement = $session_var;			
					}
				else
					{
					replacement = variable1;
					}
		
				variable1 = document.formatting_form.df_menu.value;			
				variable2 = variable.replace(replacement, variable1);
				document.formatting_form.l_formatting.value = variable2;
				this.FCKeditorAPI.__Instances['l_formatting'].SetHTML(variable2); 
				}
			else
				{
				alert("Please select a date format");
				}
			}
			
		// [ Browser Detection ] //	
		function get($str)
			{
			// [ Browser Information ] //
			var $browser = navigator.userAgent.toLowerCase();		
			$browser = $browser.indexOf($str);
			if($browser > -1){$browser = 1;}
			return($browser);
			}
			
		// [ PRINTER SETUP ] //
		function PrintBasic($ps) 
			{
			
			/* [ PAPER SIZE SELECTION ] */
			switch($ps)
				{
				case 1: /* [ A4 PAPER ] */
					document.factory.printing.paperSize = "A4";
					break;
				case 2: /* [ LETTER PAPER ] */
					document.factory.printing.paperSize = "Letter";
					break;
				}
			
			document.factory.printing.SetMarginMeasure(1);    	//  [ SET MILLIMETERS ]
			document.factory.printing.SetPrintScale(100);	  	//  [ TURN PAGE SCALING OFF ] 
			document.factory.printing.header = ""; 		      	//  [ CLEAR HEADER ]
			document.factory.printing.footer = ""; 		      	//  [ CLEAR FOOTER ]
			document.factory.printing.portrait = true 	      	//  [ SET TO PORTRAIT ]
			document.factory.printing.leftMargin = 20.0       	//  [ SET LEFT MARGIN TO 20 MILLIMETERS ]
			document.factory.printing.topMargin = 20.0        	//  [ SET TOP MARGIN TO 20 MILLIMETERS ]
			document.factory.printing.rightMargin = 20.0      	//  [ SET RIGHT MARGIN TO 20 MILLIMETERS ]
			document.factory.printing.bottomMargin = 20.0     	//  [ SET BOTTOM MARGIN TO 20 MILLIMETERS ]
			document.factory.printing.copies = 1;    	   	  	//  [ SET NUMBER OF COPIES TO 1 ]
			document.factory.printing.printBackground = false; 	//  [ SET TO PRINT BACKGROUND IMAGE ]
			document.factory.printing.Print(true); 			  	//  [ INITIATE PRINTER DIALOG WINDOW ]
			}			
			
		// [ LIA Automatic Form Submission (PAGECOUNT) ] //
		function lia_fs($count)
			{
			/* [ Reset Fields ] */
			$pc = "";
			$pc1 = "";
			$pc2 = "";
			
			/* [ Page Count Field Check ] */
			if(document.paying_form.pagecount_a4.value != ""){ $pc1=1; }
			if(document.paying_form.pagecount_l.value != ""){ $pc2=1; } 
 			$pc = $pc1+$pc2;
			
			/* [ Analyse Results ] */			
			switch($pc)
				{
				case 2: /* [ Fields Complete ] */
					document.forms[0].submit();
					break;
				default: /* [ Fields Empty ] */
					$count++;
					if($count!=20){lia_fs($count);}					
					break;
				}
			}
			
		// [ SUBMITTING FORMS TO MULTIPLE IFRAMES ] //							
		function multiform(form) 
			{
			/* [ RETRIEVE SPECIFIC FORM ELEMENT ] */
			for(i=0; i<form.elements.length; i++)
				{
				if(form.elements[i].name=="mform"){var mform=form.elements[i].value; break;}
				}
			
			/* [ SPLIT MUITPLE PAGE SUBMIT INFO ] */
			mform = mform.split(",");
			
			/* [ LOOP THROUGH ALL PAGE SUMBITS ] */
			for(rloop=0; rloop<=mform.length-1; rloop++)
				{
				mform_sub=mform[rloop].split("#");
				form.action = mform_sub[0];
				form.target = mform_sub[1];
				form.submit();			
				}
			}
			
		// [ ONSUBMISSION RESETTING ALL OTHER FORM INFORMATION document.forms.length ] //	
		function resetform(form)
			{
			var fname;
			for(rloop=0; rloop<=100; rloop++)
				{
				if (document.forms[rloop] == null || document.forms[rloop] == undefined){break;}
				fname = document.forms[rloop].name;
				if(form.name!=fname)
					{
					if (document.getElementById(fname) != null || document.getElementById(fname) != undefined){document.getElementById(fname).reset();}
					}
				}
			}
		
		// [ CHANGE SP2 TABLE HEIGHT IF TABLE TOO SMALL ] //	
		function table_resize()
			{
			/* [ RETRIEVE SPECIFIC DOCUMENT ELEMENT ] */
			var tb = new Array();
			tb[0] = document.getElementById("letter_tb").offsetHeight; 					 // [ Return Table Height ] //
			tb[1] = 650;																 // [ Table Standard Size] //
			if(tb[0]<=tb[1]){tb[0]=tb[1];}else{tb[1]=tb[0];}							 // [ Store New Size ] //
			window.parent.document.getElementById("sp2_tb").style.height = tb[1]; 	 	 // [ Return Layer Height ] //						
			window.parent.document.getElementById("sp2_layer1").style.height = tb[0]; 	 // [ Return Layer Height ] //
			window.parent.document.getElementById("sp2_layer2").style.height = tb[0];  	 // [ Return Layer Height ] //
			window.parent.document.getElementById('sp2').style.height = tb[0]+150; 		 // [ Change IFrame Height ] // 
			}	
					
			

	//-- [ PAGE COUNT SECTION ] --//
		// [ Page counting function ] //
		function count($return,$popup)
			{
			// [ DEFAULTS ] //
			var $array = new Array();
			var $earray = new Array();
			$array[0] = 3; // [ Page Limits ] //
			$array[1] = 972; // [ Letter Page Size in Pixels A4 ] //
			$array[2] = 904; // [ Letter Page Size in Pixels LETTER ] //
						
			// [ Browser Detection ] //
			// [ NOTE: Bigger the difference in spacing between browsers the smaller the percentage ] //
			switch(1)
				{
				case get("msie"): // [ Internet Explorer ] //
					$array[5] = 3; // [UK PAGE SIZE] // 
					$array[6] = 5; // [USA PAGE SIZE] //
					break;
				case get("firefox"): // [ Firefox ] //
					$array[5] = 1; // [UK PAGE SIZE] //
					$array[6] = 3; // [USA PAGE SIZE] //
					break;
				default: // [ ALL OTHER BROWSERS ] //
					$array[5] = 3; // [UK PAGE SIZE] // 
					$array[6] = 5; // [USA PAGE SIZE] //
					break;				
				}
			
			// [ RETURN OPTIONS ] //
			switch($return)
				{
				case 1: // [ Page Height Restriction ] //
					
					// [ A4 CALCULATIONS ] //
					$earray[2] = 2;
					$earray[0] = $array[0]*$array[1];
					$earray[1] = $array[5]; // [ UK Page Error Percentage ] //
					$array[7] = error_percentage($earray); // [ UK A4 Boundary ] //
					
					// [ LETTER CALCULATIONS ] //
					$earray[0] = $array[0]*$array[2];
					$earray[1] = $array[6]; // [ USA Page Error Percentage ] //
					$array[8] = error_percentage($earray); // [ USA A4 Boundary ] //									
					
					// [ Letter Outputs ] //
					document.getElementById('l_end_a4').style.height = $array[7]+'px'; // [ UK A4 Letter End Marker ] //
					document.getElementById('l_end_l4').style.height = $array[8]+'px'; // [ USA A4 Letter End Marker ] //
					document.getElementById('l_size_a4').style.height = $array[7]+'px'; // [ A4 Letter ] //
					document.getElementById('w_pagesize').style.height = $array[7]+'px'; // [ Width Page Height ] //
					document.getElementById('pagesize').style.height = $array[7]+'px'; // [ UK A4 Page Height ] //
					break
				case 2: // [ Page Count ] //
					$earray[0] = document.getElementById("letter_tb").offsetHeight; // [ Return Table Height ] //
				
					// [ A4 CALCULATIONS ] //
					$earray[2] = 1;
					$earray[1] = $array[5]; // [ UK Page Error Percentage ] //
					$array[7] = error_percentage($earray); // [ UK A4 Table Size Including Error Percentage ] //
					
					// [ LETTER CALCULATIONS ] //
					$earray[1] = $array[6]; // [ USA Page Error Percentage ] //
					$array[8] = error_percentage($earray); // [ USA A4 Table Size Including Error Percentage ] //

					// [ Page Count ] //
					$array[7] = Math.ceil(($array[7]/$array[1])); // [ UK A4 PAGE COUNT ] //
					$array[8] = Math.ceil(($array[8]/$array[2])); // [ USA A4 PAGE COUNT ] //
					
					switch($popup)
						{
						case 1:
							//alert("Page Count ["+$array[7]+"] A4\nPage Count ["+$array[8]+"] LETTER"); // [ DISPLAY PAGE NUMBERS ALERT BOX ] //
							break;
						default:
							window.parent.document.paying_form.pagecount_a4.value = $array[7]; // [ SEND COUNT TO FORMATTING PAGE [A4] ] //
							window.parent.document.paying_form.pagecount_l.value = $array[8]; // [ SEND COUNT TO FORMATTING PAGE [LETTER] ] //							
							break;
						}
					break;
				}
			}
			
		// [ Page Error Percentage ] //
		function error_percentage($array) // [ [0] Pagesize [1] Percentage ] //
			{
			var $h
			$h = ($array[0]*$array[1])/100;
			
			switch($array[2])
				{
				case 1:
					return($array[0]+$h);
				case 2:
					return($array[0]-$h);
				}
			}		
			

				
				
				
	//-- [ SIGNATURE UPLOAD PREVIEW SECTION] --//
		// [Load Image Preview] //
		function pre_image() 
			{
			// [ New Image Object ] //
			var img = new Image();

			// [ Uploaded Image Preview Exists ] //
			switch(document.image_form.file.value != "")
				{
				case true:
					// [ Browser Detection ] //
					switch(1)
						{
						case get("msie"): // [ Internet Explorer ] //
							img.src = document.image_form.file.value;
							break;
						default: // [ ALL OTHER BROWSERS ] //
							img.src = "../../images/signatures/2.jpg";
							break;				
						}
					break;
				default:
					img.src = "../../images/signatures/0.jpg";
					break;
				}			
			document.images['img_preview'].src = img.src;
			}
			
		//  [Image Preview Details] //	
		function image() 
			{
			// [ Browser Detection ] //
			switch(1)
				{
				case get("msie"): // [ Internet Explorer ] //
					
					// [ New Image Object ] //
					var img = new Image();
					img.src = document.image_form.file.value;	
						
					// [ Uploaded Image Preview Exists ] //	
					switch(document.image_form.file.value != "")
						{
						case true:
							// [ Display Image Dimensions & Filesize ] //
							document.image_form.iwidth.value = img.width;
							document.image_form.iheight.value = img.height;
							document.image_form.isize.value = img.fileSize;
							break;
						default:
							// [ Display Image Dimensions & Filesize Set to Empty ] //
							document.image_form.iwidth.value = "";
							document.image_form.iheight.value = "";
							document.image_form.isize.value = "";
							break;			
						}					
					break;				
				}			
			}
			
// [ PAGE LOADER ] //	
	function pageLoader(iframe,id)
		{
		/* [ RETRIEVE IFRAME CONTENT ] */
		var myIFrame = document.getElementById(iframe);
		var content = myIFrame.contentWindow.document.body.innerHTML;
		
		/* [ OUTPUT CONTENT TO DIV ] */
		document.getElementById(id).innerHTML=content;
		}			