//Can't get it to work for Radio Buttons yet. All options should be valid anyway

    var passScore = 0;
    var passwordLevel = 'Weak';
    
    function passwordStrength( bootsPassword ) 
    {
        if(bootsPassword.length < 6) 
        { 
            if(bootsPassword.length < 1)
            {
                passScore = 0;
            }
            passScore = (passScore+3) 
        }
        if(bootsPassword.length > 6 && bootsPassword.length < 12) { passScore = (passScore+5) }
        if(bootsPassword.match(/[a-z]/)) { passScore = (passScore+2) }
        if(bootsPassword.match(/[A-Z]/)) { passScore = (passScore+5) }
        if(bootsPassword.match(/(.*[!,@,#,$,%,^,&,*,?,_,~].*[!,@,#,$,%,^,&,*,?,_,~])/)) { passScore = (passScore+5) }
        if(bootsPassword.match(/([a-zA-Z0-9].*[!,@,#,$,%,^,&,*,?,_,~])|([!,@,#,$,%,^,&,*,?,_,~].*[a-zA-Z0-9])/)) { passScore = (passScore+2) } 
             
        if(passScore < 9) { passwordLevel = 'Weak'; }
        else if(passScore < 16 && passScore > 10) { passwordLevel = 'Short'; }
        else if(passScore < 26 && passScore > 17) { passwordLevel = 'Strong'; }
        else { passwordLevel = 'Stronger'; }
        
        document.getElementById('passwordStrength').innerHTML = passwordLevel;
    }

    function OpenCloseDiv()
    {
            document.getElementById('cinner').style.display = "block";
            document.getElementById('c1').style.display = "none";
            
            
            
    }
    
	function validateForm(form)
	{
		//TODO add radio back in to the mix
		$(form).getElementsBySelector('input[type="text"],input[type="password"],input[type="checkbox"], select,textarea').each(
			function(item)
			{
				if(item.getAttribute('type')=='checkbox')
				{//TODO: Fix Safari Bug, no focus onblur...
					item.observe('click',validateLine);
				}
				else 
				{
					item.observe('blur',validateLine);
				}
				
				if(item != 'HTMLUListElement'){
					if(item.getAttribute('type') != 'radio' && item.getAttribute('type') != 'checkbox')
					{
						item.observe('focus',setInputFocus);
					}
				}	
			});
			
		
	}
	
	function validateLine(e)
	{	
		var element = e.element();	
		if(element.name != 'register_optin')
		{
		    validateInput(element.name, $F(element), element.form.id);
		}
	}
	
	function validateInput(iId, sValue, sForm)
	{
		var iId, sValue, sForm;
		
		/*
		
		new Ajax.Request(window.location.href.replace(/#.*$/ig,''),
		{
			method:'get',
			parameters: 'ajax=true'+'&'+'_submitted=' + sForm + '&' + iId + '=' + sValue,
			onSuccess: function(transport){
				var response = transport.responseXML || "no response text";
						
				validated = response.getElementsByTagName('validated');
				if(validated[0].firstChild.nodeValue=='true')
				{
					if($(validated[0].getAttribute('id')).type != 'radio')
				 	{
				 		setInputValid(validated[0].getAttribute('id'));
				 	}
				 	//TODO: Radio Buttons, also leave in as using for 'previous' memory
				 }
				 else
				 {
				 	var aError = response.getElementsByTagName('error');
			
				 	for(var i=0;i<aError.length;i++)
				 	{
				 		if(aError[i].firstChild)
				 		{
					 		var error = aError[i].firstChild.nodeValue;
				 		}
				 		else
				 		{
				 			var error = '';
				 		}
				 		setInputInvalid(aError[i].getAttribute('fieldname'),error);
				 	}
				}
			},
			onFailure: function(){ alert('An error occured on validateInput') }
		});
		
		*/
		if(sValue == '' || sValue == null && $(iId).getAttribute('type')!='checkbox')
		{
			if(iId == 'register_title_other_')
			{
				setInputValid(iId);
			}
			else
			{
				setInputInvalid(iId,'This is not a valid value');
			}
		}
		else
		{
		    if (iId == 'register_email') {
		        var at = "@"
		        var dot = "."
		        var lat = sValue.indexOf(at)
		        var lstr = sValue.length
		        var ldot = sValue.indexOf(dot)
		        if (sValue.indexOf(at) == -1) {
		            setInputInvalid(iId, "Email Address is invalid");
		        }
		        else if (sValue.indexOf(at) == -1 || sValue.indexOf(at) == 0 || sValue.indexOf(at) == lstr) {
		            setInputInvalid(iId, "Email Address is invalid");
		        }
		        else if (sValue.indexOf(dot) == -1 || sValue.indexOf(dot) == 0 || sValue.indexOf(dot) == lstr) {
		            setInputInvalid(iId, "Email Address is invalid");
		        }
		        else if (sValue.indexOf(at, (lat + 1)) != -1) {
		            setInputInvalid(iId, "Email Address is invalid");
		        }
		        else if (sValue.substring(lat - 1, lat) == dot || sValue.substring(lat + 1, lat + 2) == dot) {
		            setInputInvalid(iId, "Email Address is invalid");
		        }
		        else if (sValue.indexOf(dot, (lat + 2)) == -1) {
		            setInputInvalid(iId, "Email Address is invalid");
		        }
		        else if (sValue.indexOf(" ") != -1) {
		            setInputInvalid(iId, "Email Address is invalid");
		        }
		        else {
		            setInputValid(iId);
		        }

		    }
		    else if (iId == 'register_ZipCode') {

		    var valid = "0123456789";
		    var Result = "1";
		    for (var i = 0; i < sValue.length; i++) {
		        temp = "" + sValue.substring(i, i+1);
		        if (valid.indexOf(temp) == "-1") {
		            Result = "0";
		            break;
		        }
		    }

		    if (sValue.length != 5 || Result!= "1") {
		        setInputInvalid(iId, "This is not a valid zip code");
		    } 
		    else {
		        setInputValid(iId);
		    }
		      
		    }

		    else {
		        setInputValid(iId);
		    }
		}
		
		if(iId == 'register_password_confirm')
		{
		    var firstpass = document.getElementById('register_password').value;
		    if(sValue != firstpass)
		    {
		        setInputInvalid(iId, "Password and confirm password must be same");
		    }
		}
	}
	
	function setInputFocus(e)
	{
		var input = e.element();			
		var parent = $(input.parentNode);
		
		parent.removeClassName('iconFail');
		parent.removeClassName('iconPass');
		parent.addClassName('iconFocus');
		
	}
	
	function setInputValid(id)
	{
		var input = $(id);			
		var parent = $(input.parentNode);
		var inputGroup = $(input.parentNode.parentNode);
	
		parent.addClassName('iconPass');
		parent.removeClassName('iconFocus');
		parent.removeClassName('iconFail');
		
		
		$$('label[for="'+input.name+'"] span.error').each(function(item){
				item.removeClassName('error');
				if(!item.hasClassName('required'))
				{//Remove "!" span
					item.remove();
				}
			});
			
			
		inputGroup.getElementsBySelector('.errorBottom').each(function(item){
				item.addClassName('removeEffect');
				//new Effect.BlindUp(item);
				new Effect.Fade(item,{
					afterFinish: function(element) 
					{//Remove object
						$$('.removeEffect').reduce().remove();
					}
				});
			});
			
	}
	
	function setInputInvalid(id,error)
	{
		var input = $(id);			
		var parent = $(input.parentNode);
		var inputGroup = $(input.parentNode.parentNode);
		
		parent.removeClassName('iconPass');
		parent.removeClassName('iconFocus');
		parent.addClassName('iconFail');
		
		var bIsRequired = false;
		
		$$('label[for="'+input.name+'"] span.required').each(function(item){
				bIsRequired = true;
				if(item.previous('.error'))
				{
					item.previous('.error').remove();
				}
				
				item.addClassName('error');
				//new Insertion.Before(item, '<span class="error">!</span>');
			});
			
		if(!bIsRequired)
		{	
			item = $$('label[for="'+input.name+'"]').reduce();
			//new Insertion.Bottom(item, '<span class="error">!</span>');
		}
		
		var bErrorRemoved = false;
		
		inputGroup.getElementsBySelector('.errorBottom').each(function(item){
				item.remove();
				bErrorRemoved = true;
			});
			
		if(error)
		{	
			errorPara = Builder.node( 'p', error);	
	
			errorDiv = Builder.node( 'div', {className:'errorBottom error'}, errorPara);	
	
			inputGroup.appendChild(errorDiv);
			
			if(bErrorRemoved == false)
			{
				Element.setStyle(errorPara,{display:'none'});
				//new Effect.BlindDown(errorPara);
				new Effect.Appear(errorPara);
			}
		}
	}	