
function LoadSection(sectionID){

	document.location = "redcms_contentlist.php?sectionID=" + sectionID;

}

function FormatLocation(){

	loc = new String(document.location);
	
	var RegEx = /&/g;

	while (RegEx.test(loc)){
		loc = loc.replace(RegEx," ");
	}

	return loc;
}

function ValidatePasswordStrength(szPassword){

	var result = CheckPassword(szPassword)
	//alert(result);


	if(result == 0){

		SetInvalid(strengthWeak);
		SetInvalid(strengthMedium);
		SetInvalid(strengthHigh);
	}
	else if(result == 1){
		SetWeak(strengthWeak);
		SetInvalid(strengthMedium);
		SetInvalid(strengthHigh);
		SetHighlight(strengthWeak);	  
	}
	else if(result == 2){

		SetMedium(strengthWeak);
		SetMedium(strengthMedium);
		SetInvalid(strengthHigh);
		SetHighlight(strengthMedium);
	}
	else if(result == 3){

		SetHigh(strengthWeak);
		SetHigh(strengthMedium);
		SetHigh(strengthHigh);
		SetHighlight(strengthHigh);
	}

}

function SetHighlight(entity){
	entity.style.fontWeight = "bold";
	entity.style.color = "#000000";
}

function SetInvalid(entity){
  
		entity.style.background = "EEEEEE";
		entity.style.fontWeight = "normal";
		entity.style.color = "#CCCCCC";  
}

function SetWeak(entity){

		entity.style.background = "#FFFF99";
		entity.style.fontWeight = "normal";
		entity.style.color = "#FFFF99";
}
function SetMedium(entity){
		entity.style.color = "#FFCC33";
		entity.style.background = "#FFCC33";
}
function SetHigh(entity){
		entity.style.color = "#66CC66";
		entity.style.background = "#66CC66";

}
function CheckPassword(szPassword){


	var currentChar;

	var bNumeric = false;
	var bCapAlpha= false;
	var bLowAlpha= false;
	var bSymbol= false;
	var lPass =0;

	if(szPassword.length < 6){
		return 0;
	}

	if(szPassword.length == 6){
		return 1;
	}
	
	for(var i=0; i<szPassword.length;i++){

		currentChar = szPassword.charAt(i);

		if (('0123456789').indexOf(currentChar) > -1 && !bNumeric){

			bNumeric = true;

		}
		if (('ABCDEFGHIJKLMNOPQRSTUVWXYZ').indexOf(currentChar) > -1 && !bCapAlpha){

			bCapAlpha = true;

		}
		if (('abcdefghijklmnopqrstuvwxyz').indexOf(currentChar) > -1  && !bLowAlpha){

			bLowAlpha = true;

		}
	}
	
	if(bNumeric){
			lPass++;
	}
	if(bCapAlpha){
			lPass++;
	}		
	if(bLowAlpha){
			lPass++;
	}
	return lPass;

}
function ChangeDocumentView(documentType){
  
	if(documentType >= 0){
		document.location = "redcms_MemberDocuments.php?documentType=" + documentType;
	}
	else{
		document.location = "redcms_MemberDocuments.php";  
	}

}

function SelectAllElements(typeID,bChecked){

	var counter = 0;

	while(eval("document.getElementById(\"Info_" + typeID + "_" + counter + "\")")){
		var chk = eval("document.getElementById(\"Info_" + typeID + "_" + counter + "\")");
		chk.checked = bChecked;
		counter += 1;
	}
}

function ValidateSelection(typeID,bChecked){
  
	var chk = document.getElementById("TYPE_" + typeID)
	
	if(!bChecked){
	  	chk.checked = false;
	}
	 
}

function SubmitRegistration(){
  
 if(CheckRegistrationDetails()){
 	document.RegistrationForm.submit();
 }

}
function CheckRegistrationDetails(){
  
  CheckTextArea(RegistrationForm.OtherInformation,512)
  NormaliseInvalidCharacters(RegistrationForm.Phone);
  NormaliseInvalidCharacters(RegistrationForm.Fax);
  NormaliseInvalidCharacters(RegistrationForm.Address1);
  NormaliseInvalidCharacters(RegistrationForm.City);
  NormaliseInvalidCharacters(RegistrationForm.Postcode); 
        
  if (CheckField("Forename",RegistrationForm.Forename) == false) return false;
  if (CheckField("Surname",RegistrationForm.Surname) == false) return false;
  if (CheckField("Company",RegistrationForm.Company) == false) return false;

  if(RegistrationForm.Country.value == 'Select Country'){
  	alert("Please select a Country.");
	return false;  
  }
  
  if (CheckField("Email",RegistrationForm.Email) == false) return false;
  if (CheckField("Username",RegistrationForm.Username) == false) return false;
  if (CheckField("Password",RegistrationForm.Password) == false) return false;

  if (RegistrationForm.Password.value.length < 6){
  	
  	alert("The password must be at least 6 characters.");
	return false;
  }
  
  if (CheckField("Password Confirmation",RegistrationForm.ConfirmPassword) == false) return false;
  
  if(CompareStrings(RegistrationForm.Password.value,RegistrationForm.ConfirmPassword.value) == false){
  	
	  alert("The passwords you entered do not match.");
	  return false;
	    
  }
  
  if (CheckField("Security Code",RegistrationForm.SecurityCode) == false) return false;
  
  return true;
}

function CheckField(fieldName,fieldEntity){

	if(fieldEntity.value == ""){
	  alert(fieldName + " must be entered.");
	  return false;
	}
	
	NormaliseInvalidCharacters(fieldEntity);
}

function NormaliseInvalidCharacters(fieldEntity){
	fieldEntity.value = fieldEntity.value.replace(/'/g,"");  
}

function CompareStrings(x,y){
  
  if(x.length != y.length){
  	return false;  
  }
  
  for(var i=0; i<x.length;i++){

	if(x.charAt(i) != y.charAt(i)){
	  return false;
	}
  }
  return true;
}

function CheckTextArea(tArea,len){
  
  if(tArea.value.length >= len){
    tArea.value = tArea.value.substring(0,len-1); 
	}
  
}

function RedwoodMemberLogin(){
  
 if(MemberLogin.Username.value == ""){
 	LoginError.innerHTML = "ERROR: Please enter Username";
	 return false;  
 }
 
if(MemberLogin.Password.value == ""){
	LoginError.innerHTML = "ERROR: Please enter Password";
 	return false;  
 }
 MemberLogin.submit(); 
  
}

function ExecuteSearch(){
  
  SearchForm.SearchKeywords.style.display = "none";
  SearchForm.SearchProgress.style.display = "block";
  SearchColumnB.innerHTML = 'Searching...';
  setTimeout("SearchForm.submit()",1000);

}


function SendReminder(email){
	if(email == ""){
		alert("Please enter a valid email address.");
	}
	else{
		document.location = "redcms_SendReminder.php?email=" + email;
  	}
}

	