//Standard site functions
function fnChangeImage(Obj, Img){
	Obj.src = '/images/update/nav/'+Img;
}

function fnSubmitForm(Obj1, IPValue){
		Obj1.mode.value = IPValue;
		Obj1.submit();
}

function fnSubmitItem(obj){
	var i
	for (i=0; i<document.all.item(obj).options.length; i++){
			document.all.item(obj).options[i].selected = true
	}
	
	return true;
}


function fnProfileSubmitForm(IPValue){
		document.frmProfile.mode.value = IPValue;
		document.frmProfile.submit();
}

function fnCheckKeyPress(Obj, Obj1, IPValue){
	if (Obj == 13){
		Obj1.mode.value = IPValue;
		Obj1.submit();
	}
}

function fnCheckContact(){
	if (document.getElementById('txtName').value == ""){
		alert("Please provide your name");
		document.getElementById('txtName').focus();
		return false;
	}
	
	if (document.getElementById('txtEmail').value == ""){
		alert("Please provide your email or contact number");
		document.getElementById('txtEmail').focus();
		return false;
	}
	
	return true;
}

function fnStatusChange(Obj){
	window.status = Obj
}

function fbreakout(obj){
	if (window.top!=window.self) 
	{
		window.top.location=obj
	}
}

function addCatItem(obj, obj1, obj2, obj3){
	var i
	
	for (i=0; i<document.all.item(obj1).options.length; i++){
		if (document.all.item(obj1).options[i].selected==true){
			addNewItem(obj, obj3, obj2, document.all.item(obj1).options[i].value, document.all.item(obj1).options[i].text)
		}
	}	
}

function addNewItem(obj, obj1, obj2, id, name){
	var i
	addOption = true
	for (i=0; i<document.all.item(obj2).options.length; i++){
		if(document.all.item(obj2).options[i].value == id){
			addOption = false
		}
	}
	
	if (addOption == true){
		document.all.item(obj2).options[document.all.item(obj2).options.length] = new Option(name, id)

		if (obj == 'event' || obj == 'categories'){
			if (document.all.item(obj2).options.length == 1){
				document.all.item(obj1).value = id
			}else{
				document.all.item(obj1).value = document.all.item(obj1).value +','+id
			}
		}
	}
}

function fnImagePop(){
	window.open('/ext/load-image.asp','Image','width=500,height=200,scrollbars=0,resizable=0,toolbars=0')
}

function fnSendSMS(){
	var bChecked
	var type, dc, no
	
	//bChecked = false;
	
	//for (i=1;i<=2;i++){
		//if (document.getElementById("txtContact"+i).checked == true){
			//type = document.getElementById("txtContact"+i).value
			//bChecked = true;
			//break;
		//}
	//}
	
	//if (!bChecked){
		//alert("Please select a contact type from the radio buttons available");
		//return false;
	//}
		
	if (document.getElementById("txtDialCountry").value == ""){
		alert("Please select your dial code country.");
		document.getElementById("txtDialCountry").focus();
		return false;
	}
	
	if (document.getElementById("txtCell").value == ""){
		alert("Please provide your cell number.");
		document.getElementById("txtCell").focus();
		return false;
	}
	
	dc = document.getElementById("txtDialCountry").value
	no = document.getElementById("txtCell").value
	
	window.open('/smscomplete.asp?type=indirect&dc='+dc+'&no='+no,'Image','width=630,height=420,scrollbars=0,resizable=0,toolbars=0')
}

function removeCatItem(obj, obj1, obj2){
	var i
	var oElements
	var CatID
	var SelCat
	for (i=0; i<document.all.item(obj2).options.length; i++){
		if (document.all.item(obj2).options[i].selected==true){
			CatID = document.all.item(obj2).options[i].value
			document.all.item(obj2).options.remove(i)
		}
	}
	
	if (obj == 'event' || obj == 'categories'){
		for (i=0; i<document.all.item(obj2).options.length; i++){
			document.all.item(obj2).options[i].selected = true
		}
		
		oElements = document.all.item(obj2).value.split(",");
		document.all.item(obj1).value = "";
		for (i=0;i<oElements.length;i++){
			if (oElements.length == 1){
				document.all.item(obj1).value = oElements[i]
			}else{
				document.all.item(obj1).value = document.all.item(obj1).value +','+oElements[i]
			}
		}
	}
	
	if (obj == 'request'){
		document.location.replace("default.asp?cid=7&rid="+CatID)
	}
}

function fnValidateRequest(obj){
	if (document.getElementById('txtFirstName').value == ""){
		alert("Please provide a first name");
		document.getElementById('txtFirstName').focus();
		return false;
	}
	
	if (document.getElementById('txtLastName').value == ""){
		alert("Please provide a last name");
		document.getElementById('txtLastName').focus();
		return false;
	}
	
	if (document.getElementById('txtContactEmail').value == ""){
		alert("Please provide a contact email address");
		document.getElementById('txtContactEmail').focus();
		return false;
	}
	
	var addr = document.getElementById('txtContactEmail').value
	var invalidChars = '\/\'\\ ";:?!()[]\{\}^|';
	for (i=0; i<invalidChars.length; i++) {
	   if (addr.indexOf(invalidChars.charAt(i),0) > -1) {
		  alert('The email address contains invalid characters');
		  return false;
	   }
	}
	
	for (i=0; i<addr.length; i++) {
	   if (addr.charCodeAt(i)>127) {
		  alert("The email address contains non ascii characters.");
		  return false;
	   }
	}
	
	var atPos = addr.indexOf('@',0);
	if (atPos == -1) {
	   alert('The email address must contain an @');
	   return false;
	}
	if (atPos == 0) {
	   alert('The email address must not start with @');
	   return false;
	}
	if (addr.indexOf('@', atPos + 1) > - 1) {
	   alert('The email address must contain only one @');
	   return false;
	}
	if (addr.indexOf('.', atPos) == -1) {
	   alert('The email address must contain a period in the domain name');
	   return false;
	}
	if (addr.indexOf('@.',0) != -1) {
	   alert('The period must not immediately follow @ in email address');
	   return false;
	}
	if (addr.indexOf('.@',0) != -1){
	   alert('The period must not immediately precede @ in email address');
	   return false;
	}
	if (addr.indexOf('..',0) != -1) {
	  alert('The two periods must not be adjacent in email address');
	   return false;
	}
	
	var suffix = addr.substring(addr.lastIndexOf('.')+1);
	if (suffix.length != 2 && suffix != 'com' && suffix != 'net' && suffix != 'org' && suffix != 'edu' && suffix != 'int' && suffix != 'mil' && suffix != 'gov' & suffix != 'arpa' && suffix != 'biz' && suffix != 'aero' && suffix != 'name' && suffix != 'coop' && suffix != 'info' && suffix != 'pro' && suffix != 'museum') {
	   alert('The primary domain in email address is invalid');
	   return false;
	}	
	return true;
}

function fnValidate(obj){
	if (document.getElementById('txtCompanyName').value == ""){
		alert("Please provide a company name");
		document.getElementById('txtCompanyName').focus();
		return false;
	}
	
	if (document.getElementById('txtContactPerson').value == ""){
		alert("Please provide the name of the contact person");
		document.getElementById('txtContactPerson').focus();
		return false;
	}
	
	if (document.getElementById('txtContactNo').value == ""){
		alert("Please provide a contact number");
		document.getElementById('txtContactNo').focus();
		return false;
	}
	
	if (document.getElementById('txtContactEmail').value == ""){
		alert("Please provide a contact email address");
		document.getElementById('txtContactEmail').focus();
		return false;
	}
	
	var addr = document.getElementById('txtContactEmail').value
	var invalidChars = '\/\'\\ ";:?!()[]\{\}^|';
	for (i=0; i<invalidChars.length; i++) {
	   if (addr.indexOf(invalidChars.charAt(i),0) > -1) {
		  alert('The email address contains invalid characters');
		  return false;
	   }
	}
	
	for (i=0; i<addr.length; i++) {
	   if (addr.charCodeAt(i)>127) {
		  alert("The email address contains non ascii characters.");
		  return false;
	   }
	}
	
	var atPos = addr.indexOf('@',0);
	if (atPos == -1) {
	   alert('The email address must contain an @');
	   return false;
	}
	if (atPos == 0) {
	   alert('The email address must not start with @');
	   return false;
	}
	if (addr.indexOf('@', atPos + 1) > - 1) {
	   alert('The email address must contain only one @');
	   return false;
	}
	if (addr.indexOf('.', atPos) == -1) {
	   alert('The email address must contain a period in the domain name');
	   return false;
	}
	if (addr.indexOf('@.',0) != -1) {
	   alert('The period must not immediately follow @ in email address');
	   return false;
	}
	if (addr.indexOf('.@',0) != -1){
	   alert('The period must not immediately precede @ in email address');
	   return false;
	}
	if (addr.indexOf('..',0) != -1) {
	  alert('The two periods must not be adjacent in email address');
	   return false;
	}
	
	var suffix = addr.substring(addr.lastIndexOf('.')+1);
	if (suffix.length != 2 && suffix != 'com' && suffix != 'net' && suffix != 'org' && suffix != 'edu' && suffix != 'int' && suffix != 'mil' && suffix != 'gov' & suffix != 'arpa' && suffix != 'biz' && suffix != 'aero' && suffix != 'name' && suffix != 'coop' && suffix != 'info' && suffix != 'pro' && suffix != 'museum') {
	   alert('The primary domain in email address is invalid');
	   return false;
	}	
}

function fnQuestionnaireContact(){
	if (document.getElementById("firstname").value == ""){
		alert("Please supply your first name.");
		document.getElementById("firstname").focus();
		return false;
	}
	
	if (document.getElementById("surname").value == ""){
		alert("Please supply your surname.");
		document.getElementById("surname").focus();
		return false;
	}
	
	if (document.getElementById("age").value == ""){
		alert("Please supply your age.");
		document.getElementById("age").focus();
		return false;
	}
	
	if (document.getElementById("gender").value == ""){
		alert("Please specify your gender.");
		document.getElementById("gender").focus();
		return false;
	}
	
	document.getElementById("mode").value = "next";
	
	return true;
}

function fnContact(){
	if (document.getElementById("name").value == ""){
		alert("Please supply your name.");
		document.getElementById("name").focus();
		return false;
	}
	
	if (document.getElementById("contact").value == ""){
		alert("Please supply your preferred contact number.");
		document.getElementById("contact").focus();
		return false;
	}
	
	if (document.getElementById("email").value == ""){
		alert("Please supply your email address.");
		document.getElementById("email").focus();
		return false;
	}
	
	var addr = document.getElementById('email').value
	var invalidChars = '\/\'\\ ";:?!()[]\{\}^|';
	for (i=0; i<invalidChars.length; i++) {
	   if (addr.indexOf(invalidChars.charAt(i),0) > -1) {
		  alert('The email address contains invalid characters');
		  return false;
	   }
	}
	
	for (i=0; i<addr.length; i++) {
	   if (addr.charCodeAt(i)>127) {
		  alert("The email address contains non ascii characters.");
		  return false;
	   }
	}
	
	var atPos = addr.indexOf('@',0);
	if (atPos == -1) {
	   alert('The email address must contain an @');
	   return false;
	}
	if (atPos == 0) {
	   alert('The email address must not start with @');
	   return false;
	}
	if (addr.indexOf('@', atPos + 1) > - 1) {
	   alert('The email address must contain only one @');
	   return false;
	}
	if (addr.indexOf('.', atPos) == -1) {
	   alert('The email address must contain a period in the domain name');
	   return false;
	}
	if (addr.indexOf('@.',0) != -1) {
	   alert('The period must not immediately follow @ in email address');
	   return false;
	}
	if (addr.indexOf('.@',0) != -1){
	   alert('The period must not immediately precede @ in email address');
	   return false;
	}
	if (addr.indexOf('..',0) != -1) {
	  alert('The two periods must not be adjacent in email address');
	   return false;
	}
	
	var suffix = addr.substring(addr.lastIndexOf('.')+1);
	if (suffix.length != 2 && suffix != 'com' && suffix != 'net' && suffix != 'org' && suffix != 'edu' && suffix != 'int' && suffix != 'mil' && suffix != 'gov' & suffix != 'arpa' && suffix != 'biz' && suffix != 'aero' && suffix != 'name' && suffix != 'coop' && suffix != 'info' && suffix != 'pro' && suffix != 'museum') {
	   alert('The primary domain in email address is invalid');
	   return false;
	}	
	
	return true;
}

function fnAssessmentContact(){
	if (document.getElementById("firstname").value == ""){
		alert("Please supply your first name.");
		document.getElementById("firstname").focus();
		return false;
	}
	
	if (document.getElementById("surname").value == ""){
		alert("Please supply your last name.");
		document.getElementById("surname").focus();
		return false;
	}
	
	if (document.getElementById("email").value == ""){
		alert("Please supply your email address.");
		document.getElementById("email").focus();
		return false;
	}
	
	var addr = document.getElementById('email').value
	var invalidChars = '\/\'\\ ";:?!()[]\{\}^|';
	for (i=0; i<invalidChars.length; i++) {
	   if (addr.indexOf(invalidChars.charAt(i),0) > -1) {
		  alert('The email address contains invalid characters');
		  return false;
	   }
	}
	
	for (i=0; i<addr.length; i++) {
	   if (addr.charCodeAt(i)>127) {
		  alert("The email address contains non ascii characters.");
		  return false;
	   }
	}
	
	var atPos = addr.indexOf('@',0);
	if (atPos == -1) {
	   alert('The email address must contain an @');
	   return false;
	}
	if (atPos == 0) {
	   alert('The email address must not start with @');
	   return false;
	}
	if (addr.indexOf('@', atPos + 1) > - 1) {
	   alert('The email address must contain only one @');
	   return false;
	}
	if (addr.indexOf('.', atPos) == -1) {
	   alert('The email address must contain a period in the domain name');
	   return false;
	}
	if (addr.indexOf('@.',0) != -1) {
	   alert('The period must not immediately follow @ in email address');
	   return false;
	}
	if (addr.indexOf('.@',0) != -1){
	   alert('The period must not immediately precede @ in email address');
	   return false;
	}
	if (addr.indexOf('..',0) != -1) {
	  alert('The two periods must not be adjacent in email address');
	   return false;
	}
	
	var suffix = addr.substring(addr.lastIndexOf('.')+1);
	if (suffix.length != 2 && suffix != 'com' && suffix != 'net' && suffix != 'org' && suffix != 'edu' && suffix != 'int' && suffix != 'mil' && suffix != 'gov' & suffix != 'arpa' && suffix != 'biz' && suffix != 'aero' && suffix != 'name' && suffix != 'coop' && suffix != 'info' && suffix != 'pro' && suffix != 'museum') {
	   alert('The primary domain in email address is invalid');
	   return false;
	}	
	
	if (document.getElementById("company").value == ""){
		alert("Please supply your company name.");
		document.getElementById("company").focus();
		return false;
	}
	
	return true;
}

function fnValidateArchetype(){
	if (document.all.item('company').value == ""){
		alert("Please provide a company name.")
		document.all.item('company').focus();
		return false;
	}
	
	if (document.all.item('firstname').value == ""){
		alert("Please provide your first name.")
		document.all.item('firstname').focus();
		return false;
	}
	
	if (document.all.item('surname').value == ""){
		alert("Please provide your surname.")
		document.all.item('surname').focus();
		return false;
	}
	
	if (document.all.item('email').value == ""){
		alert("Please provide your email address.")
		document.all.item('email').focus();
		return false;
	}
	
	var addr = document.getElementById('email').value
	var invalidChars = '\/\'\\ ";:?!()[]\{\}^|';
	for (i=0; i<invalidChars.length; i++) {
	   if (addr.indexOf(invalidChars.charAt(i),0) > -1) {
		  alert('The email address contains invalid characters');
		  return false;
	   }
	}
	
	for (i=0; i<addr.length; i++) {
	   if (addr.charCodeAt(i)>127) {
		  alert("The email address contains non ascii characters.");
		  return false;
	   }
	}
	
	var atPos = addr.indexOf('@',0);
	if (atPos == -1) {
	   alert('The email address must contain an @');
	   return false;
	}
	if (atPos == 0) {
	   alert('The email address must not start with @');
	   return false;
	}
	if (addr.indexOf('@', atPos + 1) > - 1) {
	   alert('The email address must contain only one @');
	   return false;
	}
	if (addr.indexOf('.', atPos) == -1) {
	   alert('The email address must contain a period in the domain name');
	   return false;
	}
	if (addr.indexOf('@.',0) != -1) {
	   alert('The period must not immediately follow @ in email address');
	   return false;
	}
	if (addr.indexOf('.@',0) != -1){
	   alert('The period must not immediately precede @ in email address');
	   return false;
	}
	if (addr.indexOf('..',0) != -1) {
	  alert('The two periods must not be adjacent in email address');
	   return false;
	}
	
	var suffix = addr.substring(addr.lastIndexOf('.')+1);
	if (suffix.length != 2 && suffix != 'com' && suffix != 'net' && suffix != 'org' && suffix != 'edu' && suffix != 'int' && suffix != 'mil' && suffix != 'gov' & suffix != 'arpa' && suffix != 'biz' && suffix != 'aero' && suffix != 'name' && suffix != 'coop' && suffix != 'info' && suffix != 'pro' && suffix != 'museum') {
	   alert('The primary domain in email address is invalid');
	   return false;
	}	
	
	return true;
}

function fnHighlightNav(){
	var sNav
	
	sNav = document.getElementById('navigation').value
	switch(sNav){
		case "home":
			document.getElementById('Image1').src = '/images/home-over.gif';
			document.getElementById('Image2').src = '/images/whoweare-normal.gif';
			document.getElementById('Image3').src = '/images/whatwedo-normal.gif';
			document.getElementById('Image4').src = '/images/brandevol-normal.gif';
			document.getElementById('Image5').src = '/images/contactus-normal.gif';
			document.getElementById('Image6').src = '/images/login-normal.gif';
			break;
		case "who":
			document.getElementById('Image1').src = '/images/home-normal.gif';
			document.getElementById('Image2').src = '/images/whoweare-over.gif';
			document.getElementById('Image3').src = '/images/whatwedo-normal.gif';
			document.getElementById('Image4').src = '/images/brandevol-normal.gif';
			document.getElementById('Image5').src = '/images/contactus-normal.gif';
			document.getElementById('Image6').src = '/images/login-normal.gif';
			break;
		case "what":
			document.getElementById('Image1').src = '/images/home-normal.gif';
			document.getElementById('Image2').src = '/images/whoweare-normal.gif';
			document.getElementById('Image3').src = '/images/whatwedo-over.gif';
			document.getElementById('Image4').src = '/images/brandevol-normal.gif';
			document.getElementById('Image5').src = '/images/contactus-normal.gif';
			document.getElementById('Image6').src = '/images/login-normal.gif';
			break;
		case "brandevolution":
			document.getElementById('Image1').src = '/images/home-normal.gif';
			document.getElementById('Image2').src = '/images/whoweare-normal.gif';
			document.getElementById('Image3').src = '/images/whatwedo-normal.gif';
			document.getElementById('Image4').src = '/images/brandevol-over.gif';
			document.getElementById('Image5').src = '/images/contactus-normal.gif';
			document.getElementById('Image6').src = '/images/login-normal.gif';
			break;
		case "contact":
			document.getElementById('Image1').src = '/images/home-normal.gif';
			document.getElementById('Image2').src = '/images/whoweare-normal.gif';
			document.getElementById('Image3').src = '/images/whatwedo-normal.gif';
			document.getElementById('Image4').src = '/images/brandevol-normal.gif';
			document.getElementById('Image5').src = '/images/contactus-over.gif';
			document.getElementById('Image6').src = '/images/login-normal.gif';
			break;
		case "login":
			document.getElementById('Image1').src = '/images/home-normal.gif';
			document.getElementById('Image2').src = '/images/whoweare-normal.gif';
			document.getElementById('Image3').src = '/images/whatwedo-normal.gif';
			document.getElementById('Image4').src = '/images/brandevol-normal.gif';
			document.getElementById('Image5').src = '/images/contactus-normal.gif';
			document.getElementById('Image6').src = '/images/login-over.gif';
			break;
	}
		
}

function fnValidateSelection(objlist, obj, count){
	var oList, oElement, oEle, oChoice
	var i, j, k, l, m, n
	var iCount, bAlert
	var sChoice
	
	iCount = 0
	iNewCount = 0
	sChoice = ""
	
	document.getElementById(obj).checked = true;
	
	oList = objlist.split("|")
	
	for (i=0;i<oList.length;i++){
		oElement = oList[i].split(";")
		for (k=1;k<oElement.length;k++){
			for(j=1;j<=count;j++){
				//Choice check
				if (document.getElementById('rd'+j+''+oElement[0]).checked){
					if (sChoice == ""){
						sChoice = document.getElementById('rd'+j+''+oElement[0]).value
					}else{
						sChoice = sChoice + "," + document.getElementById('rd'+j+''+oElement[0]).value
					}
					
					if (sChoice != ""){
						iArrayEle = ""
						oChoice = sChoice.split(",")
						oChoice = oChoice.sort();
						for (k=0;k<oChoice.length;k++){
							if (iArrayEle == oChoice[k]){
								alert("You have made an incorrect selection.\r\nPlease ensure you have chosen only one option per question or per choice.\r\nThank You.")
								for (l=0;oList.length;l++){
									oEle = oList[l].split(";")
									for (m=1;m<oEle.length;m++){
										for(n=1;n<=count;n++){
											document.getElementById('rd'+n+''+oEle[0]).checked = false;
										}
									}
								}
								bAlert = 1
							}
							
							if (bAlert == 1){
								break;
							}else{							
								iArrayEle = oChoice[k]
							}
						}
					}
					
					
				}
				//end of choice check
			}

			if (bAlert == 1){
				break;
			}
		}
		
		if (bAlert == 1){
			break;
		}
	}
}

function fnValidateRank(objlist, obj, count){
	var oList, oElement, oEle, oChoice
	var i, j, k, l, m, n
	var iCount, bAlert
	var sChoice
	
	iCount = 0
	sChoice = ""
	
	oList = objlist.split("|")
	
	for (i=0;i<oList.length;i++){
		oElement = oList[i].split(";")
		for (k=1;k<oElement.length;k++){
			for(j=1;j<=count;j++){
				if (sChoice != ""){
					oChoice = sChoice.split(",")
					for (l=0;l<oChoice.length;l++){
						if (oChoice[l] == document.getElementById('drp'+oElement[0]).value){
							alert("Please ensure that you choose a distinct choice for each question, of the four ranks")
							document.getElementById('drp'+oElement[0]).value = ""
							bAlert = 1
							break
						}
					}
				}
				
				if (bAlert == 1){
					break
				}
			}
			
			if (document.getElementById('drp'+oElement[0]).value != ""){
				if (sChoice == ""){
					sChoice = document.getElementById('drp'+oElement[0]).value
				}else{
					sChoice = sChoice + "," + document.getElementById('drp'+oElement[0]).value
				}
			}
			
			if (bAlert == 1){
				break
			}
		}
		
		if (bAlert == 1){
			break
		}
	}
}

function fnLoadPage(obj){
	var iPg, iCount, iQuestions
	var sQuestions
	var bAlert
	
	if (obj == 'Add'){
		//Check that fields have been filled out
		bAlert = 0
		if (document.getElementById('PageDiv').value == 2){
			sQuestions = "397,404,398,401,403,399,396,391,400,402|406,408,417,413,405,419,407,410,415,411|422,432,434,438,436,424,427,429,425,430|409,418,420,414,423,412,428,426,416,421|445,439,441,431,433,448,435,443,440,437|463,458,461,462,455,450,465,459,460,453|467,483,473,479,477,482,481,470,484,475|442,449,457,456,451,446,447,452,454,444|474,471,466,472,468,476,478,464,480,469|514,516,521,522,515,519,517,520,518,513"
		
			oQuestions = sQuestions.split("|");
			for (i=0;i<oQuestions.length;i++){
				iCount = 0
				oQuestion = oQuestions[i].split(",");
				for (j=0;j<oQuestion.length;j++){
					for (k=1;k<=3;k++){
						if (document.getElementById('rd'+k+''+oQuestion[j]+'').checked == true){
							iCount = iCount + 1
						}
					}
				}
				
				if (iCount < 3){
					alert("Please ensure that you have completed all the questions")
					bAlert = 1;
					break;
				}
			}
		}else if (document.getElementById('PageDiv').value == 3){
			sQuestions = "485,486,487|489,492,494|502,496,498|506,504,509"
		
			oQuestions = sQuestions.split("|");
			for (i=0;i<oQuestions.length;i++){
				iCount = 0
				oQuestion = oQuestions[i].split(",");
				for (j=0;j<oQuestion.length;j++){
					for (k=1;k<=3;k++){
						if (document.getElementById('rd'+k+''+oQuestion[j]+'').checked == true){
							iCount = iCount + 1
						}
					}
				}
				
				if (iCount < 2){
					alert("Please ensure that you have completed all the questions")
					bAlert = 1;
					break;
				}
			}
		}
		
		if (bAlert == 1){
			return false;
		}
		
		for (i=2;i<=4;i++){
			document.getElementById('Page'+i).style.display = 'none';
		}
		iPg = Number(document.getElementById('PageDiv').value)+1
		
		document.getElementById('Page'+iPg).style.display = 'block';
		document.getElementById('PageDiv').value = iPg
		
		if (iPg >2){
			document.getElementById('iPageHome').style.display = 'none';
			document.getElementById('iPagePrevious').style.display = 'block';
		}
		
		if (iPg == 4){
			document.getElementById('iPageNext').style.display = 'none';
			document.getElementById('iPageFinalise').style.display = 'block';
		}
		
		return true;
	}else{
		for (i=2;i<=4;i++){
			document.getElementById('Page'+i).style.display = 'none';
		}
		iPg = Number(document.getElementById('PageDiv').value)-1
		document.getElementById('Page'+iPg).style.display = 'block';
		document.getElementById('PageDiv').value = iPg
		
		if (iPg < 4){
			if (iPg = 2){
				document.getElementById('iPageHome').style.display = 'block';
				document.getElementById('iPagePrevious').style.display = 'none';
			}else{
				document.getElementById('iPageNext').style.display = 'block';
				document.getElementById('iPageFinalise').style.display = 'none';
			}
		}
	}
}

function fnValidateQuestionnaire(){
	sQuestions = "397,404,398,401,403,399,396,391,400,402|406,408,417,413,405,419,407,410,415,411|422,432,434,438,436,424,427,429,425,430|409,418,420,414,423,412,428,426,416,421|445,439,441,431,433,448,435,443,440,437|463,458,461,462,455,450,465,459,460,453|467,483,473,479,477,482,481,470,484,475|442,449,457,456,451,446,447,452,454,444|474,471,466,472,468,476,478,464,480,469|514,516,521,522,515,519,517,520,518,513"
		
	oQuestions = sQuestions.split("|");
	for (i=0;i<oQuestions.length;i++){
		iCount = 0
		oQuestion = oQuestions[i].split(",");
		for (j=0;j<oQuestion.length;j++){
			for (k=1;k<=3;k++){
				if (document.getElementById('rd'+k+''+oQuestion[j]+'').checked == true){
					iCount = iCount + 1
				}
			}
		}
		
		if (iCount < 3){
			alert("Please ensure that you have completed all the questions")
			bAlert = 1;
			break;
		}
	}
	
	if (bAlert == 1){
		return false;
	}
	
	return true;	
}

function fnValidateArchetypes(pid){
	var iCount
	var oQuestions, oQuestion
	var bAlert
	
	if (pid == 2){
		sQuestions = "22,23,24,70,71,72,73,74,75,76,77,78|91,92,93,94,95,96,97,98,99,100,101,102|126,127,128,129,130,131,132,133,134,135,136,137|49,50,51,52,53,54,55,56,57,58,59,60|37,38,39,40,41,42,43,44,45,46,47,48|19,20,21,61,62,63,64,65,66,67,68,69|79,80,81,82,83,84,85,86,87,88,89,90"
	}else{
		sQuestions = "25,26,27,28,29,30,31,32,33,34,35,36|115,116,117,118,119,120,121,122,123,124,125,2593|103,104,105,106,107,108,109,110,111,112,113,114|2594,2595,2596,2597,2598,2599,2600,2601,2602,2603,2604,2605|2606,2607,2608,2609,2610,2611,2612,2613,2614,2615,2616,2617|2618,2619,2620,2621,2622,2623,2624,2625,2626,2627,2628,2629|2630,2631,2632,2633,2634,2635,2636,2637,2638,2639,2640,2641"
	}
		
	oQuestions = sQuestions.split("|");
	for (i=0;i<oQuestions.length;i++){
		iCount = 0
		oQuestion = oQuestions[i].split(",");
		for (j=0;j<oQuestion.length;j++){
			for (k=1;k<=3;k++){
				if (document.getElementById('rd'+k+''+oQuestion[j]).checked == true){
					iCount = iCount + 1
				}
			}
		}

		if (iCount < 3){
			alert("Please ensure that you have completed all the questions")
			bAlert = 1;
			break;
		}
	}
	
	if (bAlert == 1){
		return false;
	}
	
	return true;
}

function fnValidateContext(obj){
	alert("here")
	
	if (obj.txtContextFName.value == ""){
		alert("Please provide your first name");
		obj.txtContextFName.focus();
		return false;
	}
	
	if (obj.txtContextLName.value == ""){
		alert("Please provide your last name");
		obj.txtContextLName.focus();
		return false;
	}
	
	if (obj.txtContextCompany.value == ""){
		alert("Please provide your company name");
		obj.txtContextCompany.focus();
		return false;
	}
	
	if (obj.txtContextEmail.value == ""){
		alert("Please provide your email address");
		obj.txtContextEmail.focus();
		return false;
	}
	
	var addr = obj.txtContextEmail.value
	var invalidChars = '\/\'\\ ";:?!()[]\{\}^|';
	for (i=0; i<invalidChars.length; i++) {
	   if (addr.indexOf(invalidChars.charAt(i),0) > -1) {
		  alert('The email address contains invalid characters');
		  return false;
	   }
	}
	
	for (i=0; i<addr.length; i++) {
	   if (addr.charCodeAt(i)>127) {
		  alert("The email address contains non ascii characters.");
		  return false;
	   }
	}
	
	var atPos = addr.indexOf('@',0);
	if (atPos == -1) {
	   alert('The email address must contain an @');
	   return false;
	}
	if (atPos == 0) {
	   alert('The email address must not start with @');
	   return false;
	}
	if (addr.indexOf('@', atPos + 1) > - 1) {
	   alert('The email address must contain only one @');
	   return false;
	}
	if (addr.indexOf('.', atPos) == -1) {
	   alert('The email address must contain a period in the domain name');
	   return false;
	}
	if (addr.indexOf('@.',0) != -1) {
	   alert('The period must not immediately follow @ in email address');
	   return false;
	}
	if (addr.indexOf('.@',0) != -1){
	   alert('The period must not immediately precede @ in email address');
	   return false;
	}
	if (addr.indexOf('..',0) != -1) {
	  alert('The two periods must not be adjacent in email address');
	   return false;
	}
	
	var suffix = addr.substring(addr.lastIndexOf('.')+1);
	if (suffix.length != 2 && suffix != 'com' && suffix != 'net' && suffix != 'org' && suffix != 'edu' && suffix != 'int' && suffix != 'mil' && suffix != 'gov' & suffix != 'arpa' && suffix != 'biz' && suffix != 'aero' && suffix != 'name' && suffix != 'coop' && suffix != 'info' && suffix != 'pro' && suffix != 'museum') {
	   alert('The primary domain in email address is invalid');
	   return false;
	}	
	
	return true;
}