        
// Register Development Function Version 1.0
	
	/*
		A. Description
			Register is used to check if the user inputs the correct values in the 
			correct way and to show the user the error messages.
		
		B. Parameters
			1. array
			Contains all input fields what should have a real value.
			Usage ex: 'username, password'
		
			2. length
			Contains all input fields what should have a minimum and a maximum length.
			Useage ex: "username:password=6"
		
			3. matches
			Contains all input fields what should match.
			Usage ex: "password:passwordAgain"
		
			4. groups
			Contains all input fields or select options what should be work as one.
			Usage ex: "year:month:day=date"
			
			5.chars
			Contains all input fields what should enable special chars
			Usage ex: username=@;#,email=@;! OR username=all, password=all
			
		C. Returns
			1. True
			If "errors" array is NULL.
			
			2. False
			If "errors" array is NOT NULL.
			
		D. General Usage Rules
			1. If you want to use multiple sets then you should use add ", " (comma+space) after the first set.
			Usage ex: username:password=6, email=3, year:month:day=3
			
		E. Extra features
			1. Email Validation
			Usage ex: Input id should be "email"
			
			2. Error Messages for error types
			
			3. Style change on Error
			
	*/
	
	function register(array, length, matches, groups, chars){
		// Errors Array
		// Wrong Elements will be pushed here
		errors = []; 
		
		
		
		// Error Message Displayer
		function eMessage(i, m, s){
			var msg = $(i);
			if(s == 1){
				msg.innerHTML = m;
			} else {
				msg.innerHTML = "";
			}
		}
		
		
		// Array
		if(array.length > 1){
			var units = array.split(", ");	// Split array string with ", " (comma+space)
			// Loop trought units
			for(var a = 0; a < units.length; a++){
				var unit 	= $(units[a]); 				// Get Unit Element
				var value	= unit.value; 				// Get Unit Value
				var holder	= $(unit.id + "Holder"); 	// Get Unit Holder
			
			
				
				// If value is empty
				if(value == null || value == "" || value == "default" || value == "undefined"){
					// Show to user the problem:	
					holder.className = "fieldset-focus"; 		// Change Style
					eMessage(unit.id + "Msg", msg.empty, 1); 	// Write Message
					show(unit.id+"Msg");						// Show Message Holder
					// If not id doesn't exists				
					if(errors.indexOf(unit.id) == -1){
						errors.push(unit.id); // Push ID to errors
					}
				
				// If value is not empty	
				} else { 	
					// Hide from user the problem:
					holder.className = "fieldset";		// Change Back Style
					eMessage(unit.id + "Msg", 0, 0); 	// Delete Message
					hide(unit.id+"Msg");				// Hide Message Holder
					// If unit id exists
					if(errors.indexOf(unit.id) != -1){
						errors.pop(unit.id); // Pop ID from errors
					}
				}
			
				// Email Validation
				if(unit.id == "email"){
					var validEmail = validateEmail(unit.value); // Start Email Validation Function
					// If email is not valid
					if(validEmail != 1){
						// Show to user the problem:
						holder.className = "fieldset-focus"; 		// Change Style 
						eMessage(unit.id + "Msg", msg.email, 1); 	// Write Message
						show(unit.id+"Msg");						// Show Message Holder
						errors.push(unit.id+"Invalid"); 			// Push ID to Errors
					// If email is valid	
					} else {
						// Hide from user the problem:
						// If Invalid Email Error exists
						if(errors.indexOf(unit.id+"Invalid") != -1){
							eMessage(unit.id + "Msg", 0, 0); 	// Delete Message
							hide(unit.id+"Msg");				// Hide Message Holder
							errors.pop(unit.id+"Invalid"); 		// Pop ID from Errors
						}
					}
				}
				
				
				// Character Restrictions

				// If the value is not null
				if(value.length > 0){
					if(value.match(/[^a-z0-9]/gi)){
						var charMatches = value.match(/[^a-z0-9]/gi);
						var charErrors = [];
						for(var m=0; m < charMatches.length; m++){
							var charMatch = charMatches[m];					// Character Match
							errors.push(unit.id+"InvalidChar"+charMatch);	// Push ID to Errors
							charErrors.push(charMatch);


							// Free Characters
							
							if(chars.length > 0){
								
								// Multiple
								if(chars.indexOf(", ") != -1){
									var charResults = chars.split(", "); 			// Split Content Sets
									for(var sr=0; sr < charResults.length; sr++){
										var charResult 	= charResults[sr];			// Character Results
										var split 		= charResult.split(/\=/gi); // Split Content and Result Part
										var content 	= split[0]; 				// The Content Part
										var result 		= split[1]; 				// The Result Part
										
										// If The Unit ID matches with the Content ID
										if(unit.id == content){
											
											// Multiple : If Contains ;
											if(result.indexOf(";") != -1){
												var results = result.split(/\;/gi); // Split Characters
												for(var i=0; i < results.length; i++){
													var character = results[i]; // Character
													if(character == charMatch){
														errors.pop(unit.id+"InvalidChar"+charMatch);
														charErrors.pop(charMatch);
													}
												}
												
											// Single : If DOES NOT Contains ; 
											} else {
												// If Character is equal with the Restricted Special Character
												// OR result is equal with "all"
												if(result == charMatch || result == "all"){
													errors.pop(unit.id+"InvalidChar"+charMatch); // Pop ID from Errors
													charErrors.pop(charMatch);					 // Pop ID from CharErrors
												}
											}
										}
									}
									
								// Single
								} else {
									var split 		= chars.split(/\=/gi); 		// Split Content and Result Part
									var content 	= split[0]; 				// The Content Part
									var result 		= split[1]; 				// The Result Part
									
									// If The Unit ID matches with the Content ID
									if(unit.id == content){
										
										// Multiple : If Contains ;
										if(result.indexOf(";") != -1){
											var results = result.split(/\;/gi); // Split Characters
											for(var i=0; i < results.length; i++){
												var character = results[i]; // Character
												
												// If Character is equal with the Restricted Special Character
												if(character == charMatch){
													errors.pop(unit.id+"InvalidChar"+charMatch); // Pop ID from Errors
													charErrors.pop(charMatch); 					 // Pop ID from CharErrors
												}
											}
											
										// Single : If DOES NOT Contains ; 	
										} else {
											// If Character is equal with the Restricted Special Character
											// OR result is equal with "all"
											if(result == charMatch || result == "all"){
												errors.pop(unit.id+"InvalidChar"+charMatch); // Pop ID from Errors
												charErrors.pop(charMatch); 					 // Pop ID from CharErrors
											}
										}
									}
								}
							}
						}
						
						if(charErrors != "" && charErrors != "undefined" && charErrors != null){
							holder.className = "fieldset-focus"; 		// Change Style
							eMessage(unit.id + "Msg", msg.chars, 1); 	// Write Message
							show(unit.id+"Msg");						// Show Message Holder
						}
					}
				}
			}
		}
		
		// Length
		
		// Plural / If ", " exists in length
		if(length.indexOf(", ") != -1){
			var lengthGroups 	= length.split(", "); 		// Split Length Groups with ", " (comma+space)
			
			// Loop trought lengthGroups
			for(var g = 0; g < lengthGroups.length; g++){
				var lengthGroup = lengthGroups[g]; 			// Get Full Group
				var split 		= lengthGroup.split("="); 	// Split content and lengths part with "="
				var content 	= split[0]; 				// Get Content Part
				var lengths 	= split[1].split(";"); 		// Get Lengths Part
				var min 		= lengths[0]; 				// Get Minimum Length
				var max 		= lengths[1]; 				// Get Maximum Length	
						
				// Plural / If ":" exists in content
				if(content.indexOf(":") != -1){
					var elements = content.split(":");	// Split elements with ":"
					
					// Loop trought elements
					for(var i = 0; i < elements.length; i++){
						checkLengths(elements[i]);	// Start Length Checking
					}
					
				// Single / If ":" NOT exists in content	
				} else {
					checkLengths(content); // Start Length Checking
				}
			}
			
		// Single / If ", " NOT exists in length	
		} else {
			var split 	= length.split("="); 			// Split content and lengths part with "="
			var content = split[0]; 					// Get Content Part
			var lengths = split[1].split(";"); 			// Get Lengths Part
			var min 	= lengths[0]; 					// Get Minimum Length
			var max 	= lengths[1]; 					// Get Maximum Length
			if(content.indexOf(":") != -1){
				var elements = content.split(":"); 		// Split elements with ":"
				for(var i = 0; i < elements.length; i++){
					checkLengths(elements[i]);
				}
			} else {
				checkLengths(content);
			}
		}
		
		function checkLengths(units){
			// Unit Details
			var unit 		= $(units);					// Get Unit Element
			var holder		= $(unit.id+"Holder");		// Get Unit Holder
			var unitLength 	= unit.value.length;		// Get Unit Value
			// If Unit Length is too short
			if(unitLength < min){
				holder.className = "fieldset-focus"; 	// Change Style
				eMessage(unit.id + "Msg", msg.min, 1); 	// Write Message
				show(unit.id+"Msg");
				errors.push(unit.id+"MinLength"); 		// Push Unit ID to Errors
			// If Unit Length is NOT too short
			} else {
				// If Min Length Error exists
				if(errors.indexOf(unit.id+"MinLength") != -1){
					eMessage(unit.id + "Msg", 0, 0); 	// Delete Message
					hide(unit.id+"Msg");
					errors.pop(unit.id+"MinLength"); 	// Pop Unit ID from Errors
				}	
			}
			// If Unit Length is too long
			if(unitLength > max){
				holder.className = "fieldset-focus"; 	// Change Style
				eMessage(unit.id + "Msg", msg.max, 1); 	// Write Message
				show(unit.id+"Msg");					// Show Message Holder
				errors.push(unit.id+"MaxLength"); 		// Push Unit ID to Errors
			// If Unit Length is NOT too long	
			} else {
				// If Max Length Error exists
				if(errors.indexOf(unit.id+"MaxLength") != -1){
					eMessage(unit.id + "Msg", 0, 0); 	// Delete Message
					hide(unit.id+"Msg");				// Hide Message Holder
					errors.pop(unit.id+"MaxLength"); 	// Pop Unit ID from Errors
				}
			}
		}
		
		
		// Matches
		
		// Plural / If "," exists in matches
		if(matches.length > 1){
			if(matches.indexOf(",") != -1){
				var groups = matches.split(", "); // Split matches with ", " (comma+space)

				// Loop trough groups
				for(var g = 0; g <= groups.length; g++){
					var container = groups[g]; 				// Get Group
					var items = []; 						// Create items Array
					var elements = container.split(":"); 	// Split Group with ":"
				
					// Loop trough elements
					for(var e = 0; e <= elements.length; e++){
						var match = $(elements[e]); // Get Element ID
						items.push(match.id); 		// Push match ID into items Array
					}
				
					// If items Array is not empty
					if(items != ","){
						// Loop trough items Array
						for(i=0; i<items.length; i++){
							var item = $(items[i]); 				// Get Item Element
							var item2 = $(items[i+1]); 				// Get Next Item Element
							var holder = $(items[i]+"Holder");		// Get Item Holder Element
							var holder2 = $(items[i+1]+"Holder"); 	// Get Next Item Holder Element
						
							// If Next Item exists
							if(item2 != "undefined" && item2 != null){
							
								// If item and next item value doesn't matches
								if(item.value != item2.value){
								
									// Show to user the problem:
									holder.className = "fieldset-focus"; 			// Change Style for Item
									holder2.className = "fieldset-focus"; 			// Change Style for Next Item
									eMessage(item.id + "Msg", msg.match, 1); 		// Write Message for Item
									eMessage(item2.id + "Msg", msg.match, 1); 		// Write Message for Next Item
									show(unit.id+"Msg");							// Show Message Holder
									errors.push(item.id + "NoMatchWith" + item2.id);// Push item ID to Errors
								
								// If item and next item matches
								} else {
									eMessage(item.id + "Msg", 0, 0); 				// Delete Message from Item
									eMessage(item2.id + "Msg", 0, 0); 				// Delete Message from Next Item
									hide(unit.id+"Msg");							// Hide Message Holder
									errors.pop(item.id + "NoMatchWith" + item2.id);	// Pop item ID from Errors
								}
							}
						}
					}
				}
		
			// Single / If "," NOT exists in matches	
			} else {
				var items = []; 					// Create items Array
				var elements = matches.split(":"); 	// Split Group with ":"
			
				// Loop trough elements
				for(element in elements){
					var match = $(elements[element]);
					items.push(match.id);
				}
			
				// If items Array is not empty
				if(items != ","){
					// Loop trough items Array
					for(i=0; i<items.length; i++){
						var item = $(items[i]); 				// Get Item Element
						var item2 = $(items[i+1]); 				// Get Next Item Element
						var holder = $(items[i]+"Holder");		// Get Item Holder Element
						var holder2 = $(items[i+1]+"Holder"); 	// Get Next Item Holder Element
					
						if(item2 != "undefined" && item2 != null){
						
							if(item.value != item2.value){
								// Show to user the problem:
								if(errors.indexOf(item.id + "NoMatchWith" + item2.id) == -1){
									holder.className = "fieldset-focus"; 			// Change Style for Item
									holder2.className = "fieldset-focus"; 			// Change Style for Next Item
									eMessage(item.id + "Msg", msg.match, 1); 		// Write Message for Item
									eMessage(item2.id + "Msg", msg.match, 1); 		// Write Message for Next Item
									show(item.id+"Msg");							// Show Message Holder
									show(item2.id+"Msg");							// Show Message Holder 2
									errors.push(item.id + "NoMatchWith" + item2.id);// Push item ID to Errors
								}
							} else {
								if(errors.indexOf(item.id + "NoMatchWith" + item2.id) != -1){
									eMessage(item.id + "Msg", 0, 0); 				// Delete Message from Item
									eMessage(item2.id + "Msg", 0, 0); 				// Delete Message from Next Item
									hide(item.id+"Msg");							// Hide Message Holder
									hide(item2.id+"Msg");							// Hide Message Holder 2
									errors.pop(item.id + "NoMatchWith" + item2.id);	// Pop item ID from Errors
								}
							}
						}
					}
				}
			}
		}
		
		
		// Groups
		
		if(groups.length > 1){
			// Plural / If "," exists in groups
			if(groups.indexOf(",") != -1){
				var container = groups.split(", ");
				var units = {};
				for(var i=0; i<container.length; i++){
					units[container[i]] = []; 				// Create Units Error Array
					var split = container[i].split("="); 	// Split container with "="
					var content = split[0]; 				// Get Content Part from split
					var result = split[1]; 					// Get Result Part from split
					var holder = $(result+"Holder"); 		// Get Unit Holder
					var elements = content.split(":"); 		// Split Content into elements with ":"
				
					// Loop trough elements
					for(var e = 0; e < elements.length; e++){
						var unit = $(elements[e]);	// Get Unit Element
					
						// If unit value is empty
						if(unit.value == "default" || unit.value == "null" || unit.value == "" || unit.value == " "){
						
							// If Unit ID doesn't exists in Units Error Array
							if(units[container[i]].indexOf(unit.id) == -1){
								holder.className = "fieldset-focus"; 		// Change Style for Holder
								units[container[i]].push(unit.id); 			// Push Unit ID into Units Error Array
								eMessage(result + "Msg", msg.empty, 1);		// Write Message for Unit
								show(result + "Msg");						// Show Message Holder
								errors.push(unit.id); 						// Push Unit ID into Errors
							}
						
						// If unit value is NOT empty
						} else { 
							// If Unit ID exists in Units Error Array
							if(units[container[i]].indexOf(unit.id) != -1){
								units[container[i]].pop(unit.id); 	// Pop Unit ID from Units Error Array
								errors.pop(unit.id); 				// Pop Unit ID from Errors
							}
						}
					}
				
					// If no errors were found 
					if(units[container[i]] == "" || units[container[i]] == null){
						holder.className = "fieldset";	// Change Back Style
						hide(result + "Msg");			// Hide Message Holder
						eMessage(result + "Msg", 0, 0);	// Delete Message from Unit
					}
				
				}
			
			// Single / If "," NOT exists in groups	
			} else {
				var units 		= []; 						// Units Error Array
				var split 		= groups.split(/\=/gi); 	// Split Content and Result Part
				var content 	= split[0]; 				// The Content Part
				var result 		= split[1]; 				// The Result Part
				var holder 		= $(result+"Holder"); 		// The Holder of input elements
				var elements 	= content.split(/\:/gi); 	// Split Unit parts
			
				// Loop trought elements
				for(var e = 0; e < elements.length; e++){
					var unit = $(elements[e]); // Get Unit Element
				
					// If unit value is empty
					if(unit.value == "default" || unit.value == "null" || unit.value == "" || unit.value == " "){
						// If Unit ID doesn't exists in Units Error Array
						if(units.indexOf(unit.id) == -1){
							holder.className = "fieldset-focus"; 	// Change Style for Holder
							units.push(unit.id); 					// Push Unit ID into Units Error Array
							eMessage(result + "Msg", msg.empty, 1);	// Write Message for Unit
							show(result + "Msg");					// Show Message Holder
							errors.push(unit.id); 					// Push Unit ID into Errors
						}
					
					// If unit value is not empty
					} else { 
						// If Unit ID exists in Units Error Array
						if(units.indexOf(unit.id) != -1){
							units.pop(unit.id);		// Pop Unit ID from Units Error Array
							errors.pop(unit.id);	// Pop Unit ID from Errors
						}
					}
				}
			
				// If no errors were found 
				if(units == "" || units == null){
					holder.className = "fieldset"; 	// Change Back Style
					hide(result + "Msg");			// Hide Message Holder
					eMessage(result + "Msg", 0, 0);	// Delete Message from Unit
				}
			}
		}
		
		// Returns
		
		if(errors == ""){
			return true;
		} else {
			return false;
		}
	}
	

