<!--

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("form-tab1").style.display="inline";
	document.getElementById("form_type").value = "short";
	initSetErrors();
}

function submitFormShort(theForm)
{
	// Check for guest_account checkbox first
	var f = 0;
	if (theForm.firstname.value == "") { document.getElementById("error-firstname").style.display="inline"; theForm.firstname.focus(); f++; } else { document.getElementById("error-firstname").style.display="none"; }
	if (theForm.lastname.value == "") { document.getElementById("error-lastname").style.display="inline"; theForm.lastname.focus(); f++; } else { document.getElementById("error-lastname").style.display="none"; }
	if (theForm.email.value == "") { document.getElementById("error-email").style.display="inline"; theForm.email.focus(); f++; } else { document.getElementById("error-email").style.display="none"; }
	if (theForm.password.value == "") { document.getElementById("error-password").style.display="inline"; theForm.password.focus(); f++; } else { document.getElementById("error-password").style.display="none"; }
	if (theForm.password_confirm.value == "") { document.getElementById("error-password_confirm").style.display="inline"; theForm.password_confirm.focus(); f++; } else { document.getElementById("error-password_confirm").style.display="none"; }
	if (theForm.company.value == "") { document.getElementById("error-company").style.display="inline"; theForm.company.focus(); f++; } else { document.getElementById("error-company").style.display="none"; }
	if (theForm.title.value == "") { document.getElementById("error-title").style.display="inline"; theForm.title.focus(); f++; } else { document.getElementById("error-title").style.display="none"; }

	if (f == 0)
	{
		if (!checkEmail()) { f++; }
		if (!checkPassword()) { f++; }
		if (!checkPasswordMatch()) { f++; }
		//if (!checkAgreement(document.subscriptionForm["terms_type"].value)) { 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 validateSection1(theForm)
{
	var f = 0;
	if (theForm.firstname.value.trim() == "") { document.getElementById("error-firstname").style.color="#FF0000"; theForm.firstname.focus(); f++; } else { document.getElementById("error-firstname").style.color="#000000"; }
	if (theForm.lastname.value.trim() == "") { document.getElementById("error-lastname").style.color="#FF0000"; theForm.lastname.focus(); f++; } else { document.getElementById("error-lastname").style.color="#000000"; }
	if (theForm.email.value == "") { document.getElementById("error-email").style.color="#FF0000"; theForm.email.focus(); f++; } else { document.getElementById("error-email").style.color="#000000"; }
	if (theForm.password.value == "") { document.getElementById("error-password").style.color="#FF0000"; theForm.password.focus(); f++; } else { document.getElementById("error-password").style.color="#000000"; }
	if (theForm.password_confirm.value == "") { document.getElementById("error-password_confirm").style.color="#FF0000"; theForm.password_confirm.focus(); f++; } else { document.getElementById("error-password_confirm").style.color="#000000"; }
	if (theForm.company.value.trim() == "") { document.getElementById("error-company").style.color="#FF0000"; theForm.company.focus(); f++; } else { document.getElementById("error-company").style.color="#000000"; }
	if (theForm.title.value.trim() == "") { document.getElementById("error-title").style.color="#FF0000"; theForm.title.focus(); f++; } else { document.getElementById("error-title").style.color="#000000"; }
	//if (theForm.phone_number.value.trim() == "") { document.getElementById("error-phone_number").style.color="#FF0000"; theForm.phone_number.focus(); f++; } else { document.getElementById("error-phone_number").style.color="#000000"; }
	if (theForm.address1.value.trim() == "") { document.getElementById("error-address1").style.color="#FF0000"; theForm.address1.focus(); f++; } else { document.getElementById("error-address1").style.color="#000000"; }
	//if (theForm.address2.value.trim() == "") { document.getElementById("error-address2").style.color="#FF0000"; theForm.address2.focus(); f++; } else { document.getElementById("error-address2").style.color="#000000"; }
	if (theForm.city.value.trim() == "") { document.getElementById("error-city").style.color="#FF0000"; theForm.city.focus(); f++; } else { document.getElementById("error-city").style.color="#000000"; }
	if (theForm.state.value.trim() == "") { document.getElementById("error-stateprovince").style.color="#FF0000"; theForm.state.focus(); f++; } else { document.getElementById("error-stateprovince").style.color="#000000"; }
	if (theForm.postal_code.value.trim() == "") { document.getElementById("error-zippostalcode").style.color="#FF0000"; theForm.postal_code.focus(); f++; } else { document.getElementById("error-zippostalcode").style.color="#000000"; }
	//alert("debug region:" + theForm.region.value + " value");
	switch(theForm.region.value)
	{
		case 'Asia Pacific':
			if (theForm.apac_siebel_question1.value == "") { document.getElementById("error-apac_siebel_question1").style.color="#FF0000"; theForm.apac_siebel_question1.focus(); f++; } else { document.getElementById("error-apac_siebel_question1").style.color="#000000"; }
			if (theForm.apac_siebel_question2.value == "") { document.getElementById("error-apac_siebel_question2").style.color="#FF0000"; theForm.apac_siebel_question2.focus(); f++; } else { document.getElementById("error-apac_siebel_question2").style.color="#000000"; }
			if (theForm.apac_siebel_question3.value == "") { document.getElementById("error-apac_siebel_question3").style.color="#FF0000"; theForm.apac_siebel_question3.focus(); f++; } else { document.getElementById("error-apac_siebel_question3").style.color="#000000"; }
			if ((!theForm.apac_terms_agreecapturing[0].checked) && (!theForm.apac_terms_agreecapturing[1].checked)) { document.getElementById("error-apac_terms_agreecapturing").style.color="#FF0000"; f++; } else { document.getElementById("error-apac_terms_agreecapturing").style.color="#000000"; }
			if ((!theForm.apac_terms_byemail[0].checked) && (!theForm.apac_terms_byemail[1].checked)) { document.getElementById("error-apac_terms_byemail").style.color="#FF0000"; f++; } else { document.getElementById("error-apac_terms_byemail").style.color="#000000"; }
			if ((!theForm.apac_terms_byphone[0].checked) && (!theForm.apac_terms_byphone[1].checked)) { document.getElementById("error-apac_terms_byphone").style.color="#FF0000"; f++; } else { document.getElementById("error-apac_terms_byphone").style.color="#000000"; }
			break;
		case 'EMEA':
			if (theForm.emea_siebel_question1.value == "") { document.getElementById("error-emea_siebel_question1").style.color="#FF0000"; theForm.emea_siebel_question1.focus(); f++; } else { document.getElementById("error-emea_siebel_question1").style.color="#000000"; }
			if (theForm.emea_siebel_question2.value == "") { document.getElementById("error-emea_siebel_question2").style.color="#FF0000"; theForm.emea_siebel_question2.focus(); f++; } else { document.getElementById("error-emea_siebel_question2").style.color="#000000"; }
			if (theForm.emea_siebel_question3.value == "") { document.getElementById("error-emea_siebel_question3").style.color="#FF0000"; theForm.emea_siebel_question3.focus(); f++; } else { document.getElementById("error-emea_siebel_question3").style.color="#000000"; }
			if (theForm.emea_siebel_question4.value == "") { document.getElementById("error-emea_siebel_question4").style.color="#FF0000"; theForm.emea_siebel_question4.focus(); f++; } else { document.getElementById("error-emea_siebel_question4").style.color="#000000"; }
			if ((!theForm.emea_terms_agreecapturing[0].checked) && (!theForm.emea_terms_agreecapturing[1].checked)) { document.getElementById("error-emea_terms_agreecapturing").style.color="#FF0000"; f++; } else { document.getElementById("error-emea_terms_agreecapturing").style.color="#000000"; }
			if ((!theForm.emea_terms_byemail[0].checked) && (!theForm.emea_terms_byemail[1].checked)) { document.getElementById("error-emea_terms_byemail").style.color="#FF0000"; f++; } else { document.getElementById("error-emea_terms_byemail").style.color="#000000"; }
			if ((!theForm.emea_terms_byphone[0].checked) && (!theForm.emea_terms_byphone[1].checked)) { document.getElementById("error-emea_terms_byphone").style.color="#FF0000"; f++; } else { document.getElementById("error-emea_terms_byphone").style.color="#000000"; }
			break;
		case 'Americas': // default
		default:
			if (theForm.na_siebel_question1.value == "") { document.getElementById("error-na_siebel_question1").style.color="#FF0000"; theForm.na_siebel_question1.focus(); f++; } else { document.getElementById("error-na_siebel_question1").style.color="#000000"; }
			if (theForm.na_siebel_question2.value == "") { document.getElementById("error-na_siebel_question2").style.color="#FF0000"; theForm.na_siebel_question2.focus(); f++; } else { document.getElementById("error-na_siebel_question2").style.color="#000000"; }
			if (theForm.na_siebel_question3.value == "") { document.getElementById("error-na_siebel_question3").style.color="#FF0000"; theForm.na_siebel_question3.focus(); f++; } else { document.getElementById("error-na_siebel_question3").style.color="#000000"; }
			if ((!theForm.na_terms_byemail[0].checked) && (!theForm.na_terms_byemail[1].checked)) { document.getElementById("error-na_terms_byemail").style.color="#FF0000"; f++; } else { document.getElementById("error-na_terms_byemail").style.color="#000000"; }
			if ((!theForm.na_terms_byphone[0].checked) && (!theForm.na_terms_byphone[1].checked)) { document.getElementById("error-na_terms_byphone").style.color="#FF0000"; f++; } else { document.getElementById("error-na_terms_byphone").style.color="#000000"; }
			break;
	}

	if (f == 0) {
		return true;
	} else {
		document.getElementById("error-required_fields").style.display="inline";
		return false;
	}
}

function validateLogin(theForm)
{
	var f = 0;
	if (theForm.password_email.value == "") { document.getElementById("error-password_email").style.display="inline"; f++; } else { document.getElementById("error-password_email").style.display="none"; }
	if (f == 0) { return true; } else { return false; }
}

function validatePassword(theForm)
{
	var f = 0;
	if (theForm.login_email.value == "") { document.getElementById("error-login_email").style.display="inline"; f++; } else { document.getElementById("error-login_email").style.display="none"; }
	if (theForm.login_password.value == "") { document.getElementById("error-login_password").style.display="inline"; f++; } else { document.getElementById("error-login_password").style.display="none"; }
	if (f == 0) { return true; } else { return false; }
}

function checkEmail()
{
	email = document.getElementById("email").value;
	if (validateEmail(email))
	{
		document.getElementById("error-email_format").style.display="none";
		return true;
	} else {
		document.getElementById("error-email_format").style.display="inline";
		return false;
	}
}

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

function checkPassword()
{
	pwd = document.getElementById("password").value;
	if (validatePassword(pwd))
	{
		document.getElementById("error-password_format").style.display="none";
		return true;
	} else {
		document.getElementById("error-password_format").style.display="inline";
		return false;
	}
}

function checkAgreement(f)
{
	if (document.subscriptionForm[f])
	{
		agreement = document.subscriptionForm[f][0].checked ? 1 : 0;
		if (agreement == 1)
		{
			document.getElementById('error-must_agree_to_capture').style.display="none";
			return true;
		}
		else
		{
			document.getElementById('error-must_agree_to_capture').style.display="inline";
			return false;
		}
	}
	else
	{
		return true;
	}
}

function checkPasswordMatch()
{
	pwd = document.getElementById("password").value;
	pwd2 = document.getElementById("password_confirm").value;
	if (pwd == pwd2)
	{
		document.getElementById("error-password_confirm_format").style.display="none";
		return true;
	} else {
		document.getElementById("error-password_confirm_format").style.display="inline";
		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 initSetErrors()
{
	document.getElementById("error-firstname").style.display="none";
	document.getElementById("error-lastname").style.display="none";
	document.getElementById("error-email").style.display="none";
	document.getElementById("error-email_format").style.display="none";
	document.getElementById("error-password").style.display="none";
	document.getElementById("error-password_format").style.display="none";
	document.getElementById("error-password_confirm").style.display="none";
	document.getElementById("error-password_confirm_format").style.display="none";
	document.getElementById("error-company").style.display="none";
	document.getElementById("error-title").style.display="none";
}

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

String.prototype.trim = function ()
{
    return this.replace(/^\s*/, "").replace(/\s*$/, "");
}


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

function hidePasswords()
{
	document.getElementById("form-password").style.display="none";
}
//-->