//Standard site functions
var min=11;
var max=20;
function increaseFontSize() {
   var p = document.getElementsByTagName('p');
   for(i=0;i<p.length;i++) {
      if(p[i].style.fontSize) {
         var s = parseInt(p[i].style.fontSize.replace("px",""));
      } else {
         var s = 12;
      }
      if(s!=max) {
         s += 1;
      }
      p[i].style.fontSize = s+"px"
   }
}
function decreaseFontSize() {
   var p = document.getElementsByTagName('p');
   for(i=0;i<p.length;i++) {
      if(p[i].style.fontSize) {
         var s = parseInt(p[i].style.fontSize.replace("px",""));
      } else {
         var s = 12;
      }
      if(s!=min) {
         s -= 1;
      }
      p[i].style.fontSize = s+"px"
   }   
}


function fnChangeImage(Obj, Img){
	Obj.src = '../images/'+Img;
}

function fnSubmitForm(Obj1, IPValue){
	Obj1.mode.value = IPValue;
	Obj1.submit();
}

function fnChangeStyle(obj, swap, style){
	if (swap == 1){
		document.getElementById(obj).className = style;
	}else{
		document.getElementById(obj).className = style;
	}
}

function fnLoadDetail(obj){
	window.open('oneonone-booking.asp?id='+obj,'Booking','width=450,height=450');
}

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 showStatus(sMsg) {
    window.status = sMsg ;
    return true ;
}

function fnProfileSubmitForm(IPValue){
		document.frmProfile.mode.value = IPValue;
		document.frmProfile.submit();
}

function fnLoadForgottenPassword(){
	document.getElementById('lightbox').style.display = 'none';
	document.getElementById('forgotten').style.display = 'block';
	document.getElementById('txtForgotten').focus();
}

function fnCheckKeyPress(Obj, Obj1, IPValue){
	if (Obj == 13){
		Obj1.mode.value = IPValue;
		Obj1.submit();
	}
}

function fnStatusChange(Obj){
	window.status = Obj
}

function fbreakout(obj){
	if (window.top!=window.self) 
	{
		window.top.location=obj
	}
}

function fnReloadLocation(obj){
	if (obj != ""){
		document.location = '/?Nedsec/17:0:'+obj+':0/OneOnOneBooking.html'
	}
}

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 fnPrintSchedule(obj){
	var obj1 = document.getElementById('printdate').value
	window.open('/bin/oneonone.asp?id='+obj+'&pid='+obj1+'','Schedule','width=700,height=500,menubar=1,resizable=1,scrollbars=1');
}

function fnBookingAlert(){
	alert("Please note:\r\n\nA booking has already been made by a representative of your company to attend this One-on-One.\r\nShould you wish, you are able to add yourself as an attendee at the One-on-One timeslot booked.\r\n\nThank you")
}

function fnTimeslotAlert(){
	alert("Please note:\r\n\nA booking has already been made by a representative of your company to attend a One-on-One over the chosen timeslot.\r\n\nThank you")
}

function fnPopupNews(obj){
	window.open('/popup-news.asp?Nedsec/2:0:0:'+obj+'/NewsSummary.html','News','width=450,height=380,scrollbars=0,resizable=0')
}

function fnOneonOneReport(obj){
	if (obj == 1){
		window.open('/bin/oneonone-report.asp','Reports','width=450,height=170,scrollbars=0,resizable=0')
	}else if (obj ==2){
		window.open('/bin/oneonone-report.asp?cid=999','Reports','width=450,height=170,scrollbars=0,resizable=0')
	}else{
		window.open('/bin/oneonone-report.asp?cid=998','Reports','width=450,height=170,scrollbars=0,resizable=0')
	}
}

function fnPopupContact(obj){
	window.open('/contact.asp?etid='+obj+'','Contact','width=450,height=380,scrollbars=0,resizable=0')
}

function fnRevertParent(obj){
	window.location = '/?Nedsec/2:0:0:'+obj+'/News.html';
	document.getElementById("newspopup").style.display = 'none';
}

function fnClose(obj){
	if (obj == 1){
		document.getElementById("newspopup").style.display = 'none';
	}else if (obj == 2){
		document.getElementById("peoplepopup").style.display = 'none';
	}else {
		document.getElementById("bookingpopup").style.display = 'none';
	}
}

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 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 fnLoadSheet(conf, obj, option){
	var oConf = conf.split(":");
		
	if (option == 1){
		for (i=0;i<oConf.length;i++){
			document.getElementById("div"+oConf[i]).style.display = 'none';
			document.getElementById("timediv"+oConf[i]).style.display = 'none';
		}
		
		document.getElementById("printdate").value = obj;
		if (obj == 1){
			document.getElementById("link1").className = 'oneonone-linkover';
			document.getElementById("link2").className = 'oneonone-link';
		}else{
			document.getElementById("link1").className = 'oneonone-link';
			document.getElementById("link2").className = 'oneonone-linkover';
		}
		
		document.getElementById("div"+obj).style.display = 'block';
		document.getElementById("timediv"+obj).style.display = 'block';
	}else{
		for (i=0;i<oConf.length;i++){
			document.getElementById("divprint"+oConf[i]).style.display = 'none';
			document.getElementById("timediv"+oConf[i]).style.display = 'none';
			document.getElementById("labeldiv"+oConf[i]).style.display = 'none';
		}
		
		document.getElementById("divprint"+obj).style.display = 'block';
		document.getElementById("timediv"+obj).style.display = 'block';
		document.getElementById("labeldiv"+obj).style.display = 'block';
	}
	
}

function fnLoadSchedule(obj){
	document.getElementById("div"+obj).style.display = 'block';
	document.getElementById("timediv"+obj).style.display = 'block';
	
	if (obj == 1){
		document.getElementById("link1").className = 'oneonone-linkover';
		document.getElementById("link2").className = 'oneonone-link';
	}else{
		document.getElementById("link1").className = 'oneonone-link';
		document.getElementById("link2").className = 'oneonone-linkover';
	}
}

function fnValidateBooking(){
	var bErr = false;
	
	if (document.getElementById('txtAttendee1').value == ""){
		alert("Please provide at least one attendee's details");
		document.getElementById('txtAttendee1').focus();
		return false;
	}
	
	for (i=1;i<=6;i++){
		var txtString = document.getElementById('txtAttendee'+i).value;
		var sArray = "1,2,3,4,5,6,7,8,9,0";
		var oArray = sArray.split(",");
		
		for (j=0;j<txtString.length;j++){
			for (k=0;k<oArray.length;k++){
				if (txtString.charAt(txtString[j]) == oArray[k]){
					alert("Please note: only alpha characters are permitted.\r\nPlease alter your attendee details and resubmit.");
					bErr = true;
					break;
				}
			}
			
			if (bErr){
				break;
			}
		}
		
		if (bErr){
			return false;
		}
	}
	
	return true;
}

function regEx(regString, regPattern, regFlag)
{
	if(regPattern.length>0){
		var regExp = new RegExp(regPattern,regFlag);
		regEx = regString.match(regExp);
	}
}

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;
	}	
	
	if (document.getElementById('cboLocal').value == ""){
		alert("Please select your location");
		document.getElementById('cboLocal').focus();
		return false;
	}
	
	if (document.getElementById('cboProdSel').value == ""){
		alert("Please ensure that you have at least one product category you would be interested in.");
		document.getElementById('cboProdSel').focus();
		return false;
	}
}

function fnValidateEmail(){
	if (document.getElementById('txtForgotten').value == ""){
		alert("Please provide your registration email address.");
		document.getElementById('txtForgotten').focus();
		return false;
	}
	
	var addr = document.getElementById('txtForgotten').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 fnFPwdValidate(obj){
	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 fnRegValidate(obj){
	if (document.getElementById('txtCompanyName').value == ""){
		alert("Please provide your company name");
		document.getElementById('txtCompanyName').focus();
		return false;
	}
	
	if (document.getElementById('txtContactPerson').value == ""){
		alert("Please provide a contact persons name");
		document.getElementById('txtContactPerson').focus();
		return false;
	}
	
	if (document.getElementById('txtContactNo').value == ""){
		alert("Please provide a contact persons 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 fnAddfavourite(){
   if (document.all){
      window.external.AddFavorite
      ("http://www.nedsec.co.za","Nedsec - Nedcor Securities")
   }
}

function fnPreload(){ 
  var args = fnPreload.arguments;
  document.imageArray = new Array(args.length);
  for(var i=0; i<args.length; i++)
  {
    document.imageArray[i] = new Image;
    document.imageArray[i].src = args[i];
  }
}

function fnValidateRegistration(formVar){
	var ReqVar, VarLabel
	var ReqArray, FieldArray
	var bReq
	var telVar, telNo, oTel, bExist
	
	bReq = false;
	if (formVar == 1){
		ReqVar = "txtFirstName,txtLastName,txtCompanyName,txtAddress1,txtAddress2,txtEmail,txtWorkTel";
		FieldVar = "First Name:,Last Name:,Company Name:,Address:,Please Complete:,Email Address:,Work Telephone:";
	}else if (formVar == 2){
		ReqVar = "txtFirstName,txtLastName,txtCompanyName,txtAddress1,txtAddress2,txtEmail,txtWorkTel,txtUserName,txtPassword";
		FieldVar = "First Name:,Last Name:,Company Name:,Address:,Please Complete:,Email Address:,Work Telephone:,Username:,Password:";
	}else if (formVar == 3){
		ReqVar = "txtEmail,txtSubject,txtComment";
		FieldVar = "Email Address:,Subject:,Comment:";
	}

	ReqArray = ReqVar.split(",");
	FieldArray = FieldVar.split(",");
	
	for (j=0;j<FieldArray.length;j++){
		for (i=0;i<ReqArray.length;i++){
			if (j == i){
					document.getElementById("label-"+ReqArray[i]).innerHTML = FieldArray[j].replace("Please Complete:","");
					break;
			}
		}
	}
	
	for (i=0;i<ReqArray.length;i++){
		if (document.getElementById(ReqArray[i]).value == ""){
			VarLabel = document.getElementById("label-"+ReqArray[i]).innerHTML;
			document.getElementById("label-"+ReqArray[i]).innerHTML = "<span style='color: #598787; font-weight: bold; text-decoration: none;'>"+VarLabel+"</span>";
			bReq = true;
		}
	}
	
	if (bReq){
		alert("- Please note -\r\n  The label(s) in bold text are mandatory fields.");
		
		for (i=0;i<=ReqArray.length;i++){
			if (document.getElementById(ReqArray[i]).value == ""){
				document.getElementById(ReqArray[i]).focus();
				break;
			}
		}
		return false;
	}
	
	var addr = document.getElementById('txtEmail').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 (formVar != 3){
		telVar = "(,),+,1,2,3,4,5,6,7,8,9,0"
		telNo = document.getElementById("txtWorkTel").value
		oTel = telVar.split(",")
		for (i=0;i<telNo.length;i++){
			bExist = false;
			for(j=0;j<oTel.length;j++){
				if (telNo.substring(i,i+1) == oTel[j]){
					bExist = true;
				}
			}
			
			if (!bExist){
				alert("Please ensure that you provide a valid telephone number removing all spaces.");
				document.getElementById("txtWorkTel").focus();
				break;
			}
		}
	}
	
	return true;
}



