var el, content, objSender;
function PrepareText(objSender, strText)
{
	if(objSender.value == strText)
	{objSender.value = "";}
	else{
		if(objSender.value == "")
		{objSender.value = strText;}
		else
		{objSender.value = objSender.value;}
	}
}

// Switch the password fields so the user can type his actual password
function PasswordControlSwap(OriginalId, FakeId, aForce)
{
	var original = document.getElementById(OriginalId); 
	var fake = document.getElementById(FakeId); 
	// force the switch
	if (aForce)
	{
		fake.style.display = "none";
		original.style.display = "block";
		//original.focus();
	}
	// Did the user already type the password
	if (original.value != "")
	{
		return;
	}
	else
	{
		// Show/hide the real password field
		if (fake.style.display == "" || fake.style.display == "block")
		{
			fake.style.display = "none";
			original.style.display = "block";
			original.focus();
		}
		else
		{
			fake.style.display = "block";
			original.style.display = "none";
		}
	}
}

function ShowTxtBox()
{
    var nIndex = getElementsByClassName(document,"select","comboBx")[0].selectedIndex;
     if(getElementsByClassName(document,"select","comboBx")[0].options[nIndex].value == '3')
     {
       getElementsByClassName(document,"table","PlusSignUpFormComboCol3")[0].style.display = 'block';
     }
     else
     {
       getElementsByClassName(document,"table","PlusSignUpFormComboCol3")[0].style.display = 'none';
       getElementsByClassName(document,"div","divInvitationErr")[0].style.display = "none";
       document.getElementById('ImgErrRef').style.display = "none";
     }
}

function ShowTxtBoxUpgradeMember()
{
   var nIndex = getElementsByClassName(document,"select","comboBx")[0].selectedIndex;
     if(getElementsByClassName(document,"select","comboBx")[0].options[nIndex].value == '3')
     {
       getElementsByClassName(document,"table","PlusSignUpFormComboCol3")[0].style.display = 'block';
     }
     else
     {
       getElementsByClassName(document,"table","PlusSignUpFormComboCol3")[0].style.display = 'none';
     }
     getElementsByClassName(document,"img","ErrClass")[0].style.display = "none";
}
//These function is to reset the Reference combo in Clubsignup form abd upgrade member
function ResetReferenceList()
{
  getElementsByClassName(document,"select","comboBx")[0].selectedIndex = 0;
}
function ValidateTextBox(textBox,initial,errorRow,button)
{
	var txt = document.getElementById(textBox).value;	
	if(txt=="" || txt == initial)
	{
		document.getElementById(errorRow).style.display='Block';
		
	}
	else
	{ 
		document.getElementById(errorRow).style.display='None';
		__doPostBack(button,'');
			
	}
}
var cat = 1;
function showForm(category)
{
	cat = category;
	$("#contact").hide();
	$("#confirm1").hide();
	$("#confirm2").hide();	
	$("#contactForm").show();	
}
function validateContactForm()
{
	var txtboxes = getElementsByClassName(document,"input","textBox");
	ClearFormErrors(txtboxes);	
	var validName = validateIsEmpty(txtboxes[0]);
	if(validName)
		validName = IsValidString(txtboxes[0].value);	
		
	var validEmail = validateIsEmpty(txtboxes[1]);
	if(validEmail)
		validEmail = IsValidEmail(txtboxes[1].value);
		
	var validPhone = validateIsEmpty(txtboxes[2]);	
	
	var txtboxesMulti = getElementsByClassName(document,"textArea","textBoxMulti");
	var validMessage = validateIsEmpty(txtboxesMulti[0]);
	/*if(validMessage)
		validMessage = IsValidString(txtboxesMulti[0].value);*/
	
	if(validName && validEmail && validPhone && validMessage)
	{
		AjaxPro.timeoutPeriod = 60*1000;
		Dtf.WebSite.Default.SendContactMail(txtboxes[0].value,txtboxes[1].value,txtboxes[2].value,txtboxes[3].value,txtboxesMulti[0].value,cat,false,SCMCallBack,null,null, null, CMTimeout, null);
	}
	else
	{
		if(!validName)			
			txtboxes[0].style.border = '1px dotted red';
			
		if(!validEmail)
			txtboxes[1].style.border = '1px dotted red';
		
		if(!validPhone)
			txtboxes[2].style.border = '1px dotted red';
			
		if(!validMessage)
			txtboxesMulti[0].style.border = '1px dotted red';
	}
	
}
function CMTimeout(ret){alert('Timed out');}
function SCMCallBack(ret)
{
	$("#contact").hide();	
	$("#contactForm").hide();
	$("#confirm2").hide();
	$("#confirm1").show();
	setTimeout("GoToHome('"+ ret.value +"')",10000);
}
function sendCMail()
{
	var txtboxes = getElementsByClassName(document,"input","textBox");
	var txtboxesMulti = getElementsByClassName(document,"textArea","textBoxMulti");
	Dtf.WebSite.Default.SendContactMail(txtboxes[0].value,txtboxes[1].value,txtboxes[2].value,txtboxes[3].value,txtboxesMulti[0].value,cat,true,SCMAgainCallBack,null,null, null, null, null);
}
function SCMAgainCallBack(ret)
{
	$("#contact").hide();	
	$("#contactForm").hide();
	$("#confirm1").hide();
	$("#confirm2").show();
	setTimeout("GoToHome('"+ ret.value +"')",10000);
}
function GoToHome(url)
{
	location.href = url;
}
function ClearFormErrors(txtboxes)
{
	for(var i=0;i<txtboxes.length-1;i++)
	{
		txtboxes[i].style.border = '1px solid #CED3D6';
	}		
	var txtboxesMulti = getElementsByClassName(document,"textArea","textBoxMulti");
	txtboxesMulti[0].style.border = '1px solid #CED3D6';
	
}
function validateIsEmpty( Element )
{
  var Valid = true;
  if(Element == null || Element.value == "")
       Valid = false;
 return Valid;       
}
function IsValidEmail( EmailAddress )
{
     var objRegex = new RegExp(/^.+@.+\..{2,4}$/);
     return objRegex.test(EmailAddress);
}
function IsValidString( UserData )
{		
	var objStringRegex = new RegExp(/^\D{1,1000}$/);	
	return objStringRegex.test(UserData);
}