<!--

function getFormType(name)
{
  name = name.replace(/[\[]/,"\\\[").replace(/[\]]/,"\\\]");
  var regexS = "[\\?&]"+name+"=([^&#]*)";
  var regex = new RegExp( regexS );
  var results = regex.exec( window.location.href );
  if( results == null )
    return "";
  else
    return results[1];
}

function initForm()
{
	//document.getElementById("tab-login").style.display="inline";
	//document.getElementById("tab-forgotpassword").style.display="none";
	//document.getElementById("form_type").value = "short";
	//document.getElementById("error-register").style.display="none";
}

function passwordForm()
{
	//document.getElementById("tab-login").style.display="none";
	//document.getElementById("tab-forgotpassword").style.display="inline";
	//document.getElementById("error-register").style.display="none";
	//_hbPageView('FORGOT_PASSWORD', '#');
}

function submitFormShort(theForm)
{
	var f = 0;
	if (!validateSection1(theForm))
	{
		f++;
		document.getElementById("error-register").style.display="inline";
		document.getElementById("error-register").innerHTML = "Error: Missing fields";
	}
	/*if (f == 0)
	{
		if (!checkEmail()) { f++; }
		if (!checkPassword()) { f++; }
		if (!checkPasswordMatch()) { f++; }
	}*/
	if (f == 0) { return true; } else { return false; }
}

function submitFormLogin(theForm)
{
	var f = 0;
	//if (!validateLogin(theForm)) { f++; }
	if (f == 0) { return true; } else { return false; }
}

function submitFormIf(n)
{
    if (document.forms[n])
    {
        document.forms[n].submit();
    }
}

function submitFormForgotpassword(theForm)
{
	var f = 0;
	if (!validateForgotpassword(theForm)) { f++; }
	if (f == 0) { return true; } else { return false; }
}

function validateSection1(theForm)
{
	var f = 0;
	if (theForm.firstname.value.replace(/^\s*|\s*$/g, "") == "") { document.getElementById("label-firstname").style.color="#FF0000"; theForm.firstname.focus(); f++; } else { document.getElementById("label-firstname").style.color="#CCCCCC"; }
	if (theForm.lastname.value.replace(/^\s*|\s*$/g, "") == "") { document.getElementById("label-lastname").style.color="#FF0000"; theForm.lastname.focus(); f++; } else { document.getElementById("label-lastname").style.color="#CCCCCC"; }
	if (theForm.email.value.replace(/^\s*|\s*$/g, "") == "") { document.getElementById("label-email").style.color="#FF0000"; theForm.email.focus(); f++; } else { document.getElementById("label-email").style.color="#CCCCCC"; }
	if (theForm.password.value.replace(/^\s*|\s*$/g, "") == "") { document.getElementById("label-password").style.color="#FF0000"; theForm.password.focus(); f++; } else { document.getElementById("label-password").style.color="#CCCCCC"; }
	if (theForm.password_confirm.value.replace(/^\s*|\s*$/g, "") == "") { document.getElementById("label-confirmpassword").style.color="#FF0000"; theForm.password_confirm.focus(); f++; } else { document.getElementById("label-confirmpassword").style.color="#CCCCCC"; }
	if (theForm.company.value.replace(/^\s*|\s*$/g, "") == "") { document.getElementById("label-company").style.color="#FF0000"; theForm.company.focus(); f++; } else { document.getElementById("label-company").style.color="#CCCCCC"; }
	if (theForm.title.value.replace(/^\s*|\s*$/g, "") == "") { document.getElementById("label-jobtitle").style.color="#FF0000"; theForm.title.focus(); f++; } else { document.getElementById("label-jobtitle").style.color="#CCCCCC"; }
	if (f == 0) { return true; } else { return false; }
}

function validateLogin(theForm)
{
	var f = 0;
	if (theForm.login_email.value.replace(/^\s*|\s*$/g, "") == "") { document.getElementById("label-login_email").style.color="#FF0000"; f++; } else { document.getElementById("label-login_email").style.color="#CCCCCC"; }
	if (theForm.login_password.value.replace(/^\s*|\s*$/g, "") == "") { document.getElementById("label-login_password").style.color="#FF0000"; f++; } else { document.getElementById("label-login_password").style.color="#CCCCCC"; }
	if (f == 0) { return true; } else { return false; }
}

function validateForgotpassword(theForm)
{
	var f = 0;
	if (theForm.password_email.value.replace(/^\s*|\s*$/g, "") == "") { document.getElementById("label-password_email").style.color="#FF0000"; f++; } else { document.getElementById("label-password_email").style.color="#CCCCCC"; }
	if (f == 0) { return true; } else { return false; }
}

function validatePassword(theForm)
{
	var f = 0;
	if (theForm.login_email.value.replace(/^\s*|\s*$/g, "") == "") { document.getElementById("label-login_email").style.color="#FF0000"; f++; } else { document.getElementById("label-login_email").style.color="#CCCCCC"; }
	if (theForm.login_password.value.replace(/^\s*|\s*$/g, "") == "") { document.getElementById("label-login_password").style.color="#FF0000"; f++; } else { document.getElementById("label-login_password").style.color="#CCCCCC"; }
	if (f == 0) { return true; } else { return false; }
}

function checkEmail()
{
	email = document.getElementById("email").value;
	if (validateEmail(email))
	{
		document.getElementById("label-email").style.color="#CCCCCC";
		return true;
	} else {
		document.getElementById("label-email").style.color="#FF0000";
		document.getElementById("error-register").style.display="inline";
		document.getElementById("error-register").innerHTML = "Error: invalid email";
		return false;
	}
}

function validateEmail(email)
{
	if (/^\w+([\.-]?\w+)*@\w+([\.-]?\w+)*(\.\w{2,8})+$/.test(email))
	{
		return true;
	} else {
		return false;
	}
}

function checkPassword()
{
	pwd = document.getElementById("password").value;
	if (validatePassword(pwd))
	{
		document.getElementById("label-password").style.color="#CCCCCC";
		return true;
	} else {
		document.getElementById("label-password").style.color="#FF0000";
		document.getElementById("error-register").style.display="inline";
		document.getElementById("error-register").innerHTML = "Error: invalid password";
		return false;
	}
}

function checkPasswordMatch()
{
	pwd = document.getElementById("password").value;
	pwd2 = document.getElementById("password_confirm").value;
	if (pwd == pwd2)
	{
		document.getElementById("label-confirmpassword").style.color="#CCCCCC";
		return true;
	} else {
		document.getElementById("label-confirmpassword").style.color="#FF0000";
		document.getElementById("error-register").style.display="inline";
		document.getElementById("error-register").innerHTML = "Error: password doesn't match";
		document.getElementById("password_confirm").value = "";
		return false;
	}
}

function validatePassword(pwd)
{
	var invalid = " "; // Invalid character is a space
	var minLength = 6; // Minimum length
	// check for minimum length
	if (pwd.length < minLength)
	{
		return false;
	}
	// check for spaces
	else if (pwd.indexOf(invalid) > -1)
	{
		return false;
	}
	else
	{
		return true;
	}
}

function moveToTop()
{
    if (location.href.indexOf("#TOP") > 0)
    {
        location.href  = location.href;
    } else {
        location.href  = location.href + "TOP";
    }
}

function formAlert()
{
	alert("Test: " + document.getElementById("form_type").value)
}

function onRegister(lang, country)
{
	var frm = document.getElementById('regForm');
	if(frm.country.selectedIndex > 0) 
	{
		window.location = '/uc/application/controllers/regPage.php?lang_code=' + lang + '&country=' + country;	
	}	
	else
	{
        //alert(" please select a country")
		//$('#errorMessage').html('<p>Please select a country.</p>').css('visibility', 'visible');
        document.getElementById("errorMessage").style.visibility="visible";
        if (lang== "en_US"){
		    document.getElementById("errorMessage").innerHTML = "Please select a country";
        }else{
            document.getElementById("errorMessage").innerHTML = "请选择一个国家";
        }
		return false;
	}
}

if (typeof jQuery != 'undefined')
{
	$(document).ready(function()
	{
		if(location.href.indexOf('registration-short-form.php') != -1)
		{
			$('#navi_home span').addClass('selected');
		}
		else if(location.href.indexOf('sessions.php') != -1)
		{
			$('#navi_sessions span').addClass('selected');
		}
		else if(location.href.indexOf('speakers.php') != -1)
		{
			$('#navi_speakers span').addClass('selected');
		}
		else if(location.href.indexOf('about.php') != -1)
		{
			$('#navi_sponsors span').addClass('selected');
		}
		
	});
}

//-->