	//=============================================================================
	// File: signup.js
	// Common javascript code
	//
	// Author: 
	// carl.phillips@gmail.com
	//=============================================================================	

	function updatePasswordStrength()
	{		
		var password = document.signup_basic_form.newpassword.value;
		var strength = 0;

		// easy_guesses: strings that should not be used in password
		var easy_guesses = new Array();
		easy_guesses.push('password'); // does this need to be localized?
		easy_guesses.push('invideous');

		var email_words = document.signup_basic_form.youremail.value.match(/\w+/g); // contiguous words contained in email
		if (email_words)
			easy_guesses = easy_guesses.concat(email_words);
		//if (document.signup_basic_form.username.value) // could change this to fullname
		//	easy_guesses.push(document.signup_basic_form.username.value);

		var locase_matches = password.match(/[a-z_]/g); // lowercase and '_' matches
		var digit_matches = password.match(/[0-9]/g);   // numeric matches
		var upcase_matches = password.match(/[A-Z]/g);  // uppercase matches
		var special_matches = password.match(/\W/g);    // special matches (not in a-z, A-Z, 0-9, _)
		
		//document.write("special_matches : " + special_matches);
		
		/*for(var i=0; i<easy_guesses.length; i++)
		{			
			document.write("easy_guesses: " + easy_guesses[i] + "<br>");
		}*/

		if (password.length>5) {
			// for less than 5, leave strength at 0 since password too short

			// 1 point for each character more than 5
			strength += password.length - 5;

			// 1 point for each upcase character mixed with lowercase
			if (locase_matches && upcase_matches)
				strength += upcase_matches.length;

			// 1 point for each numeric character mixed with lowercase
			if (locase_matches && digit_matches)
				strength += digit_matches.length;

			// 1 point for each special characters
			if (special_matches)
				strength += special_matches.length;

			// 2 bonus points if mix of letters, numbers and special
			if ((locase_matches || upcase_matches) && special_matches && digit_matches)
				strength += 2;
		}

		// Reset strength to 0 if any easy guess in password (easy guess should be more than 3 chars)
		for (var i=0; i < easy_guesses.length; i++)
		{			
			if (easy_guesses[i].length>3 && (password.indexOf(easy_guesses[i])!=-1)) {
				strength=0;
				break;
			}
		}

		var passwordStrength = document.getElementById('password_strength');
		var passwordStrengthText = document.getElementById('password_strength_text');
		if (password.length==0)
		{
			passwordStrength.className = 'password_empty';
			passwordStrengthText.innerHTML = 'None';
		}
		else if (strength<3)
		{			
			passwordStrength.className = 'password_weak';
			passwordStrengthText.innerHTML = 'Weak';
		}
		else if (strength<7)
		{
			passwordStrength.className = 'password_fair';
			passwordStrengthText.innerHTML = 'Fair';
		}
		else if (strength<10)
		{
			passwordStrength.className = 'password_good';
			passwordStrengthText.innerHTML = 'Good';
		}
		else
		{
			passwordStrength.className = 'password_strong';			
			passwordStrengthText.innerHTML = 'Strong';
		}
	}
	
	function clearPasswordStrength()
	{
		var passwordStrength = document.getElementById('password_strength');
		var passwordStrengthText = document.getElementById('password_strength_text');		
		passwordStrength.className = 'password_empty';
		passwordStrengthText.innerHTML = 'None';		
	}
	
	function checkSignupValid()
	{
		var invalidBox = document.getElementById('invalid_box');
		var invalidBoxStyle = invalidBox.style;
		
		var email = document.getElementById('youremail');
		var newpassword = document.getElementById('newpassword');
		var newpassword2 = document.getElementById('newpassword2');
		var username = document.getElementById('username');
		var fullname = document.getElementById('fullname');		
		var sex = document.getElementById('sex');
		var day = document.getElementById('day');
		var month = document.getElementById('month');
		var year = document.getElementById('year');
		var country = document.getElementById('country');
		
		var sexid = sex.options[document.getElementById('sex').selectedIndex].value;
		var dayid = day.options[document.getElementById('day').selectedIndex].value;
		var monthid = month.options[document.getElementById('month').selectedIndex].value;
		var yearid = year.options[document.getElementById('year').selectedIndex].value;
		var countryid = country.options[document.getElementById('country').selectedIndex].value;
		
		// if 1st selection (i.e. default) then treat as null string.
		if(sexid == '0') sexid = "";
		if(dayid == '0') dayid = "";
		if(monthid == '0') monthid = "";
		if(yearid == '0') yearid = "";
		if(countryid == '0') countryid = "";
		
		//alert("email : " + email.value);
		
		// Check #1 - scan for an empty field
		if(email.value == "" || newpassword.value == "" || newpassword2.value == "" || username.value == "" ||
		fullname.value == "" || sexid == "" || dayid == "" || monthid == "" || yearid == "" || countryid == "")
		{			
			//invalidBoxStyle.display = 'block';
			var result = "Testing123 fields not completed!";
			return result;
		}
		else
		{
			//invalidBoxStyle.display = 'none';
			return false;
		}
				
		/*
		if(invalidBoxStyle.display == 'visible' || invalidBoxStyle.display == 'none')
		{
			invalidBoxStyle.display = 'block';
		}
		else
		{
			invalidBoxStyle.display = 'none';
		}
		*/
				
		//alert("email : " + email);
		//alert("password : " + pass);
		
		/*
		for(var i in document.register_basic_form)
		{
			document.write("register_basic_form[" + i + "] = " + register_basic_form[i].value + "<br>");	
		}
		*/
		
		return "Failed to blah blah blah....";		
	}
	
	function registerBasicFailed()
	{
		// turn off indicator busy
		var indicatorBlueSmall = document.getElementById('indicator_blue_small');
		var indicatorBlueSmallStyle = indicatorBlueSmall.style;
		indicatorBlueSmallStyle.display = 'none';
		
		// turn on invalid Box
		var invalidBox = document.getElementById('invalid_box');
		var invalidBoxStyle = invalidBox.style;		
		invalidBoxStyle.display = 'block';
	}
	
	function registerBasicPassed()
	{
		// turn off indicator busy
		var indicatorBlueSmall = document.getElementById('indicator_blue_small');
		var indicatorBlueSmallStyle = indicatorBlueSmall.style;
		indicatorBlueSmallStyle.display = 'none';
		
		// turn off invalid Box
		var invalidBox = document.getElementById('invalid_box');
		var invalidBoxStyle = invalidBox.style;		
		invalidBoxStyle.display = 'none';		
		
		// clear password strength indicator
		clearPasswordStrength();		
	}
	
	function checkSubscribeValid()
	{
		var email = document.getElementById('youremail');
		var fullname = document.getElementById('fullname');		
				
		alert("email : " + email.value);
		
		// Check #1 - scan for an empty field
		if(email.value == "" || fullname.value == "")
		{			
			return false;
		}
		else
		{
			return true;
		}		
	}
	
	function onSubmitSubscribe()
	{	
		//document.write('onSubmitSubscribe!');
		/*
		if( checkSubscribeValid() )
		{
			// valid! So now we can submit form to s.php (ready to send account details to mySQL database for creation).
			document.subscribe_form.submit();
		}
		else
		{
			// failed! Do nothing...	
		}*/
		
		/*
		// turn on indicator busy!
		var indicatorBlueSmall = document.getElementById('indicator_blue_small');
		var indicatorBlueSmallStyle = indicatorBlueSmall.style;
		indicatorBlueSmallStyle.display = 'block';
		
		// turn off invalid Box
		var invalidBox = document.getElementById('invalid_box');
		var invalidBoxStyle = invalidBox.style;		
		invalidBoxStyle.display = 'none';
				
		// check for valid sign-up details
		var result = checkSignupValid();
		if(!result)
		{
			registerBasicPassed();
			
			// valid! So now we can submit form to r.php (ready to send account details to mySQL database for creation).
			document.register_basic_form.submit();
		}
		
		else
		{		
			window.setTimeout(registerBasicFailed, 1000*0.7); // add pseudo ~1 second delay, to make user think we are doing some hard work, mainly to show effect we've clicked sign-up button.
			//alert("sign up invalid!");
		}
		*/

/*		
		var frm = document.getElementById('register_basic_form');		
		var fullname = document.getElementById('fullname').value;
		var email = document.getElementById('youremail').value;
		var pass = document.getElementById('newpassword').value;
		var sex = document.getElementById('sex');
		var day = document.getElementById('day');
		var month = document.getElementById('month');
		var year = document.getElementById('year');
		var country = document.getElementById('country');
		
		var sexid = sex.options[document.getElementById('sex').selectedIndex].value;
		var dayid = day.options[document.getElementById('day').selectedIndex].value;
		var monthid = month.options[document.getElementById('month').selectedIndex].value;
		var yearid = year.options[document.getElementById('year').selectedIndex].value;
		var countryid = country.options[document.getElementById('country').selectedIndex].value;
		
		document.write("full name: " + fullname + "<br>");
		document.write("email: " + email + "<br>");
		document.write("password: " + pass + "<br>");
		document.write("sex: " + sexid + "<br>");
		document.write("day: " + dayid + "<br>");
		document.write("month: " + monthid + "<br>");
		document.write("year: " + yearid + "<br>");
		document.write("country: " + countryid + "<br>");
*/		
		
		//var show = form.sexid.options[sexid.selectedIndex].value;
		//document.write(show);

		//DEB_R( form );
		//DEB_R( form['sex'] );
		
		
		
		
		/*
		var vis = form.style;
		
		if(vis.display == 'visible' || vis.display == 'none')
		{
			vis.display = 'block';
		}
		else
		{
			vis.display = 'none';
		}
		*/
		
		/*for(var i in sex.option)
		{
			//if( form[i].value != null )
			{
				
				document.write("\'" + i + "\' =&gt; " + form[i] + " value=&gt;" + form[i].value + "<br>");			
			}			
		}*/
		//DEB_R( div.style );
		
		//var form = document.getElementById("birthday_popup");
		/*div.innerHTML = "piss";
		div.top = 20;
	}
	
	function onSubmit()
	{	
		document.write('submitted!');
		
		//document.register_basic_form.submit();		

		/*
		if(document.register_basic_form.value.length ==0)//.value.length==0)
		{			
			document.write('register_basic_form...');
		}
		else if(document.cp_form1.value.length ==0)//.value.length==0)
		{			
			document.write('cp_form1...');
		}
		*/
		
		//var div = document.getElementById("birthday_popup");
		/*div.innerHTML = "piss";
		div.top = 20;
		for(var i in div)
		{
		
		}*/
		//DEB_R( div.style );
		//div.offsetLeft = 20;
		
		/*
		document.write('
		<div id='popup' width=300 Height=400>Testing123</div>
		');*/
		
		/*
		if(document.cp_form1.email.value.length==0)
		{
			document.cp_form1.email.value = 'enter username';
			document.cp_form1.email.style.backgroundColor = '#f0f0ff';	
		}
		else if(document.cp_form1.email.value == 'enter username')
		{";
			
		if(isset($g_userdata)) // Logged in, therefore, if you hit View Profile, it should view your own profile.
		{
			$msg.="document.cp_form1.username.value = '".$g_userdata['name']."';
			document.cp_form1.submit();		
			
			";
		}
			
		$msg.="		
		}		
		else document.cp_form1.submit();
		return false;
		*/
	}
	
	
	
	
	/*
	As an example, if you wanted to ensure that the name <input> field was not empty, we could use a JavaScript regular expression for checking the user input: /^\s+|\s+$/g which would check for all leading and trailing white spaces including tabs.
	
	function trim (str) {
	return str.replace (/^\s+|\s+$/g, '');
	} 
	We could then use this function:
	
	var name_element = document.getElementById ('txt_name');
	
	if (trim(name_element.value) == '') {
	alert ('Please enter your name');
	}	
	*/
	
	function onSignup()
	{		
		//document.write('onSignup()...' + '<br>');
		
		if( checkSignupValid() )
		{
			// valid! So now we can submit form to s.php (ready to send account details to mySQL database for creation).
			document.signup_basic_form.submit();
		}
		else
		{
			// failed! Do nothing...	
		}		
	}	
	
	function checkSignupValid()
	{
		var email = document.getElementById('youremail');
		var email2 = document.getElementById('youremail2');
		var fullname = document.getElementById('fullname');
		var username = document.getElementById('username');
		var password = document.getElementById('newpassword');
		var password2 = document.getElementById('newpassword2');		
				
		// Check #1 - scan for empty fields
		if(email.value == '' || email2.value == ''
      || fullname.value == '' || username.value == ''
      || password.value == '' || password2.value == '')
		{			
			alert('Please enter all fields correctly.');
			return false;
		}
		// Check #2 - 'password' and 're-type password' fields don't match
		else if(password.value != password2.value || email.value != email2.value)
		{
			alert('Please enter \'Password\' or \'Email\' fields correctly.');
			
			// clear passwords.
			document.getElementById('youremail2').value = "";
			document.getElementById('newpassword').value = "";
			document.getElementById('newpassword2').value = "";
			return false;
		}
		else
		{
			return true;
		}		
	}