/*
Enbu COnsulting - SageApplications.com
Costi Craciunescu 
02 Feb 2009
*/
//------------------------------------------------------------------------------
function downloadfile(docId) {
  var upwin = window.open('/download.asp?docId='+docId,
                          'documentdownload', 'status=1,width=1, height=1, resizable=yes');
}

//------------------------------------------------------------------------------
allFields = $([]);
var act=0;
tips=new Object();
function updateTips(t) {
	tips.html(t);
}

//------------------------------------------------------------------------------
// modal window to login and go to myinterests
function openMyLoginWindow(_recid) {
	act = 2; // goto my interests
	var recid = $("#recid");recid.val(_recid);	
	$('#dialog').dialog('open');
}
//------------------------------------------------------------------------------
// modal window to login to book course
function openBookNowLoginWindow(_recid) {
	act = 1; // book now
	var recid = $("#recid");recid.val(_recid);	
	$('#dialog').dialog('open');
}
//------------------------------------------------------------------------------
// modal window to login to download
function openDlLoginWindow(_recid) {
	
	act= 0; //download	
	var recid = $("#recid");
	recid.val(_recid);
	
	$('#dialog').dialog('open');
}
//------------------------------------------------------------------------------
function checkLength(o,n,min,max) {

	if ( o.val().length > max || o.val().length < min ) {
		o.addClass('ui-state-error');
		updateTips("Length of " + n + " must be between "+min+" and "+max+".");
		return false;
	} else {
		return true;
	}

}
//------------------------------------------------------------------------------
function checkRegexp(o,regexp,n) {

	if ( !( regexp.test( o.val() ) ) ) {
		o.addClass('ui-state-error');
		updateTips(n);
		return false;
	} else {
		return true;
	}

}
//------------------------------------------------------------------------------
/* opens modal login window to enable doc downloads*/
function initDlLoginWindow() {
	$("#dialog").dialog({
		bgiframe: true,
		height: 350,
		modal: true,
		autoOpen: false,
		buttons: {
				'Cancel': function() {
					$(this).dialog('close');
				},				
				'Login': function() {
					
					var username = $("#username");
					var password = $("#password");
					var recid = $("#recid");
					
					allFields = $([]).add(username).add(password);
					tips = $("#validateTips");

					var bValid = true;
					allFields.removeClass('ui-state-error');

					bValid = bValid && checkLength(username,"email",6,80);
					bValid = bValid && checkLength(password,"password",6,20);
					
					bValid = bValid && checkRegexp(username,/^((([a-z]|\d|[!#\$%&'\*\+\-\/=\?\^_`{\|}~]|[\u00A0-\uD7FF\uF900-\uFDCF\uFDF0-\uFFEF])+(\.([a-z]|\d|[!#\$%&'\*\+\-\/=\?\^_`{\|}~]|[\u00A0-\uD7FF\uF900-\uFDCF\uFDF0-\uFFEF])+)*)|((\x22)((((\x20|\x09)*(\x0d\x0a))?(\x20|\x09)+)?(([\x01-\x08\x0b\x0c\x0e-\x1f\x7f]|\x21|[\x23-\x5b]|[\x5d-\x7e]|[\u00A0-\uD7FF\uF900-\uFDCF\uFDF0-\uFFEF])|(\\([\x01-\x09\x0b\x0c\x0d-\x7f]|[\u00A0-\uD7FF\uF900-\uFDCF\uFDF0-\uFFEF]))))*(((\x20|\x09)*(\x0d\x0a))?(\x20|\x09)+)?(\x22)))@((([a-z]|\d|[\u00A0-\uD7FF\uF900-\uFDCF\uFDF0-\uFFEF])|(([a-z]|\d|[\u00A0-\uD7FF\uF900-\uFDCF\uFDF0-\uFFEF])([a-z]|\d|-|\.|_|~|[\u00A0-\uD7FF\uF900-\uFDCF\uFDF0-\uFFEF])*([a-z]|\d|[\u00A0-\uD7FF\uF900-\uFDCF\uFDF0-\uFFEF])))\.)+(([a-z]|[\u00A0-\uD7FF\uF900-\uFDCF\uFDF0-\uFFEF])|(([a-z]|[\u00A0-\uD7FF\uF900-\uFDCF\uFDF0-\uFFEF])([a-z]|\d|-|\.|_|~|[\u00A0-\uD7FF\uF900-\uFDCF\uFDF0-\uFFEF])*([a-z]|[\u00A0-\uD7FF\uF900-\uFDCF\uFDF0-\uFFEF])))\.?$/i,"Email address not valid");
					bValid = bValid && checkRegexp(password,/^([0-9a-zA-Z])+$/,"Password field only allow : a-z 0-9");
					
					if (bValid) {
						
						//make ajax call to remote login
						$.ajax({
						type: 'POST',
						url: 'http://www.collierbroderick.ie/remoteLogin.asp',
						data: "act="+act+"&recid="+recid.val()+"&username="+username.val()+"&password="+password.val(),
						success: function(data) {
							$("#dialog").dialog('option','title',' Logged In Successfully');
							
							if (act ==0) {
								$("#dialog").dialog('option', 'height', 130);
								$("#dialog").html(data);	
							}
							
							if (act==1) {
								$("#dialog").dialog('close');
								bookNow(data);								
							}
							
							if (act ==2)  { // go to my interests page							if (act==1) {
							$("#dialog").dialog('close');
							  document.location.href='/wwwcb/myinterests.asp';
							}
							
							
							//$("#dialog").dialog('option', 'buttons', {'Download':function() { window.open(data);$(this).dialog("close"); }});							
							//$(this).dialog('close');							
						},
						error : function (data) {							
							updateTips(data.responseText);
						},
						complete:function (XMLHttpRequest, textStatus) {
							var headers = XMLHttpRequest.getAllResponseHeaders();
							//alert(headers);
						    }

					      });
					}
				}
			},
			close: function() {
				allFields.val('').removeClass('ui-state-error');
			}
	});
}
//------------------------------------------------------------------------------
function initRegisterWindow() {
	$("#dialog").dialog({
		bgiframe: true,
		height: 300,		
		modal: true,
		autoOpen: false,
		buttons: {
				'Cancel': function() {
					$(this).dialog('close');
				},				
				'Register': function() {
					
					var username = $("#username");
					var password = $("#password");
					var recid = $("#recid");
					
					allFields = $([]).add(username).add(password);
					tips = $("#validateTips");

					var bValid = true;
					allFields.removeClass('ui-state-error');

					bValid = bValid && checkLength(username,"email",6,80);
					bValid = bValid && checkLength(password,"password",6,20);
					
					bValid = bValid && checkRegexp(username,/^((([a-z]|\d|[!#\$%&'\*\+\-\/=\?\^_`{\|}~]|[\u00A0-\uD7FF\uF900-\uFDCF\uFDF0-\uFFEF])+(\.([a-z]|\d|[!#\$%&'\*\+\-\/=\?\^_`{\|}~]|[\u00A0-\uD7FF\uF900-\uFDCF\uFDF0-\uFFEF])+)*)|((\x22)((((\x20|\x09)*(\x0d\x0a))?(\x20|\x09)+)?(([\x01-\x08\x0b\x0c\x0e-\x1f\x7f]|\x21|[\x23-\x5b]|[\x5d-\x7e]|[\u00A0-\uD7FF\uF900-\uFDCF\uFDF0-\uFFEF])|(\\([\x01-\x09\x0b\x0c\x0d-\x7f]|[\u00A0-\uD7FF\uF900-\uFDCF\uFDF0-\uFFEF]))))*(((\x20|\x09)*(\x0d\x0a))?(\x20|\x09)+)?(\x22)))@((([a-z]|\d|[\u00A0-\uD7FF\uF900-\uFDCF\uFDF0-\uFFEF])|(([a-z]|\d|[\u00A0-\uD7FF\uF900-\uFDCF\uFDF0-\uFFEF])([a-z]|\d|-|\.|_|~|[\u00A0-\uD7FF\uF900-\uFDCF\uFDF0-\uFFEF])*([a-z]|\d|[\u00A0-\uD7FF\uF900-\uFDCF\uFDF0-\uFFEF])))\.)+(([a-z]|[\u00A0-\uD7FF\uF900-\uFDCF\uFDF0-\uFFEF])|(([a-z]|[\u00A0-\uD7FF\uF900-\uFDCF\uFDF0-\uFFEF])([a-z]|\d|-|\.|_|~|[\u00A0-\uD7FF\uF900-\uFDCF\uFDF0-\uFFEF])*([a-z]|[\u00A0-\uD7FF\uF900-\uFDCF\uFDF0-\uFFEF])))\.?$/i,"Email address not valid");
					bValid = bValid && checkRegexp(password,/^([0-9a-zA-Z])+$/,"Password field only allow : a-z 0-9");
					
					if (bValid) {
						
						//make ajax call to remote login
						$.ajax({
						type: 'POST',
						url: '/register.asp',
						data: "act="+act+"&recid="+recid.val()+"&username="+username.val()+"&password="+password.val(),
						success: function(data) {
							$("#dialog").dialog('option','title',' Logged In Successfully');
							
							if (act ==0) {
								$("#dialog").dialog('option', 'height', 130);
								$("#dialog").html(data);	
							}
							
							if (act==1) {
								$("#dialog").dialog('close');
								bookNow(data);								
							}	
						},
						error : function (data) {							
							updateTips(data.responseText);
						},
						complete:function (XMLHttpRequest, textStatus) {
							var headers = XMLHttpRequest.getAllResponseHeaders();
						}
					      });
					}
				}
			},
			close: function() {
				allFields.val('').removeClass('ui-state-error');
			}
	});
	
}
//------------------------------------------------------------------------------
var currentButton;
var submitButtonObj;
function checkEmailForm(f) {	
	reqFields = new Array("pers_firstname", "pers_lastname", "comp_name", "pers_emailaddress",
			      "addr_postcode", "addr_address1", "enqtext");
	for (i = 0; i< reqFields.length; i++ ) {
		val = f[reqFields[i]].value.length;
		if (val < 1) {
			alert("Fields marked with * are required!");
			f[reqFields[i]].style.backgroundColor = 'pink';
			f[reqFields[i]].focus();
			return false;
		}
	}
	//**** check if values in captcha
	if (f.recaptcha_response_field.value.length == 0){
		alert("Please type in the two words!");
		f.recaptcha_response_field.focus();
		return false;
	}
	
	if (!validEmail(f.pers_emailaddress.value)) {
	    alert("Invalid email address!");
	    f.email.focus();
	    return false;
	}
	return true;
}

function emptyBox() {
    box = document.getElementById('inputBox');
    box.value = '';
}

function checkConfirmPasswords(formObj) {
  //*** validate passwords
   
    pwd0 = formObj.p0;
    pwd1 = formObj.p1;
    pwd2 = formObj.p2;
   
   
   
    if (pwd0.value.length < 6) {
	alert("Old Password should be at least 6 characters!");
	pwd0.focus();
	return false;
    }
   
   
    if (pwd1.value.length < 6) {
	alert("Password should be at least 6 characters!");
	pwd1.focus();
	return false;
    }
    
    
    if (pwd2.value.length < 6) {
	alert("Password should be at least 6 characters!");
	pwd2.focus();
	return false;
    }
    
    if (pwd1.value.length > 12) {
	alert("Password should be max 12 characters!");
	pwd1.focus();
	return false;
    }
    
     if (pwd2.value.length > 12) {
	alert("Password should be max 12 characters!");
	pwd2.focus();
	return false;
    }
    
    
    
    if (pwd1.value != pwd2.value) {
	alert("Passwords don't match!");
	pwd1.focus();
	return false;
    }
    return true;
}

//***********************************************************
function addMorePeople2() {
   var inp = document.getElementById("_hidden_add_more_people");
   inp.value = "yes";
   //alert("test");
   //$("#_hidden_add_more_people").value = "yes";
}
//***********************************************************
function editAttendee(courseId, attdNodeId) {
    document.location.href = "courseBooking.asp?entity=SS_WebMenuTop&caption=Courses%20%26%20Seminars&cour_courseId="
	+ courseId + "&step=2&attdId=" + attdNodeId +"&cmd=e";
}
//***********************************************************
function remAttendee(courseId, attdNodeId) {
    if (confirm("Are you sure you want to remove this attendee?")) {
	document.location.href = "courseBooking.asp?entity=SS_WebMenuTop&caption=Courses%20%26%20Seminars&cour_courseId="
	+ courseId + "&step=2&attdId="+attdNodeId + "&cmd=r";
    } else {
	return;
    }
}
//***********************************************************
function skipAddMorePeople(courseId) {
    document.location.href = "courseBooking.asp?entity=SS_WebMenuTop&caption=Courses%20%26%20Seminars&cour_courseId=" + courseId + "&step=3";
}
//***********************************************************
function addMorePeople3(courseId) {
   document.location.href = "courseBooking.asp?entity=SS_WebMenuTop&caption=Courses%20%26%20Seminars&cour_courseId=" + courseId + "&step=2";
}
//***********************************************************
function iscaptchaok() {
    rechallenge = document.getElementById("recaptcha_challenge_field").value;
    reresponse = document.getElementById("recaptcha_response_field").value;
    pkey = document.getElementById("pkey").value;
    ip = document.getElementById("ip").value;    
    $.ajax({
	    method: "POST",
	    url : "http://api-verify.recaptcha.net/verify" ,
	    data: { 'privatekey': pkey, 'remoteip': ip, 'challenge': rechallenge, 'response' : reresponse  },
	    dataType: 'xml',
	    success: function() {
		    alert('test');
	    }    
    });  
}
//***********************************************************
///***** ajax call to save notifyme email address
function getNotified(url) {
    box = document.getElementById('inputBox');
    if (box != null) {
	em = box.value;
     if (validEmail(em)) {
	
	    var win = window.open(url, 'winnotifier', 'width=500, height=300, resizable=true');
	
	    //*** jquery ajax call
	    /*$.post("addSubscriber.asp",
		   { email:em },
		   function (response) {
		    alert(response);
		   });
	    */
	} else {
	    alert('Please enter a valid email address');
	    return false;
        }
    }
    return true;
}
//***********************************************************
function validEmail(sVal) {
  var reg = /^([a-zA-Z0-9_\-\.]{2,})@((\[[0-9]{1,3}\.[0-9]{1,3}\.[0-9]{1,3}\.)|(([a-zA-Z0-9\-]{2,}\.)+))([a-zA-Z]{2,4}|[0-9]{1,3})(\]?)$/;
  if (!reg.test(sVal)) {
    return false;
  }
  return true;
}
//***********************************************************
function alertValidEmail(field) {
	if (!validEmail(field.value)) {
		alert("This is not a valid e-mail address");
		field.focus();
		return false;
	}
	return true;
}

//***********************************************************
//eg : change from text to password 
function changeInputType(oldObject, oType) {
  var newObject = document.createElement('input');
  newObject.type = oType;
  if(oldObject.size) newObject.size = oldObject.size;
  if(oldObject.value) newObject.value = oldObject.value;
  if(oldObject.name) newObject.name = oldObject.name;
  if(oldObject.id) newObject.id = oldObject.id;
  if(oldObject.className) newObject.className = oldObject.className;
  oldObject.parentNode.replaceChild(newObject,oldObject);
  return newObject;
}
//***********************************************************
function changeInputNameId(oldObject, newName, newId) {
  var newObject = document.createElement('input');
  if(oldObject.size) newObject.size = oldObject.size;
  if(oldObject.value) newObject.value = oldObject.value;
  if(oldObject.name) newObject.name = newName;
  if(oldObject.id) newObject.id = newId;
  if(oldObject.className) newObject.className = oldObject.className;
  oldObject.parentNode.replaceChild(newObject,oldObject);
  return newObject;
}
//***********************************************************
function deleteApplication(appId) {
    if (confirm("Are you sure you want to delete this application?")) 
        AjaxObjectDelete.startRequest('record/deleteRecord.asp?appId='+appId); 
    else 
        return ;
  return;
}
//***********************************************************
function changeAccRegisterType(sAccType) {
   x = "myindex.asp?main_page=register&acctype=" + sAccType;
   document.location.href = x;    
}
//***********************************************************
//******* add/edit/delete review
function UserManageReview(formObj) {
   AjaxUserManageReview.startRequest('includes/app_user_manage_review.asp', formObj);
   return false;
}
//***********************************************************
//*** return the submit parent form
function buttonParentForm(obj) {
    par = obj.parentElement;
    currentButton = obj;
    
    theAjaxLoaderGif = obj.parentElement;
  
    while (par.parentElement.nodeName != 'FORM') {
        par = par.parentElement;
    }
    return par.parentElement;
}

//**** global var to update attendees number
countAttd = 2;
//***************************************************************************
//**** receives block execute html and inserts it into the html dom
function addMorePeople(sHTML) {
    var divContainer = document.getElementById('add_more_people');
    
    var newTable = document.createElement("TABLE");
    newTable.id = 'person_' + countAttd;
    //*** the table caption
    var newrow = newTable.insertRow(0);
    var newcell0 = newrow.insertCell(0);
    newcell0.innerHTML = 'Person ' + countAttd;
    var newcell1= newrow.insertCell(1);
    newcell1.innerHTML = "<input type=button onclick=removePerson("+ countAttd + ") value='Remove Person " + countAttd + "'/>";
    
    //*** the block fields
    var newrow = newTable.insertRow(1);
    var newcell = newrow.insertCell(0);
    newcell.innerHTML = unescape(sHTML);
    
    divContainer.appendChild(newTable);
    countAttd++;
}
//***************************************************************************
//*** remove a table from the dom document
function removePerson(newTableObjId) {
    if (confirm ("Remove person " + newTableObjId + "?")) {
	var divContainer = document.getElementById('add_more_people');
	toRemove = document.getElementById('person_' + newTableObjId);
	divContainer.removeChild(toRemove);
	//countAttd--;
    }
}

//***************************************************************************
//*** block is wrapped in our own custom form element with calls this function 
//**** to validate fields
function BookingFormValidate(formObj) {
    reqfields = formObj._hidden_reqfields;
    if (reqfields != null && reqfields.value != "") {
      fields = reqfields.value.split(",");
      //alert(fields);
      for (i=0; i<fields.length;i++) {
        fieldProps = fields[i].split("|");
        fid = fieldProps[0];
        ftype = fieldProps[1];
        fsize = fieldProps[2];
        fcapt = fieldProps[3];
        
        formField = document.getElementById(fid);
	
        if ( formField !=null ) {
		v = formField.value;
            //***check empty 
            if (v == "" || v == " ") {
              alert(fcapt +" is required!");
              formField.focus();
              return false;
            }
            //***check size
            if (v.length > fsize && ftype !=11 && ftype != 12 && ftype != 21 && ftype != 10 ) { 
            
              //***for some reason email and address, selection filed is size 1
              alert(fcapt + " length should not be longer than " + fsize + "!");
              formField.focus();
              return false;
            }
            //*** if email validate email address
            if (ftype == 12 && !validEmail(v)) {
              alert("Invalid email address!");
              formField.focus();
              return false;
            }
            //*** if integer 
            if (ftype == 31) {
              if (v < 0 || parseInt(v)!=v-0) {
                alert(fcapt + " is not integer!");
                formField.focus();
                return false;
              }
            }
	}
      }
    }
    
    
    //**** email and email confirm
    em1 = formObj.pers_emailaddress;
    em2 = formObj.pers_emailaddressconfirm;
    if (em1 != null && em2 != null) {
	if (!validEmail(em1.value)) {
	    alert("Invalid e-mail address!");
	    em1.focus();
	    return false;           
	} 
	if (!validEmail(em2.value)) {
	    alert("Invalid e-mail address!");
	    em2.focus();
	    return false;                   
	} 
	if (em1.value != em2.value) {
	    alert("E-mails don't match");
	    em1.focus();
	    return false;
	}
    }
    
    //**** email and email confirm on cotnact us form (lead_emaiaddress)
    lead_em1 = formObj.lead_personemail;
    lead_em2 = formObj.lead_personemailconfirm;
    if (lead_em1 != null && lead_em2 != null) {
	if (!validEmail(lead_em1.value)) {
	    alert("Invalid e-mail address!");
	    lead_em1.focus();
	    return false;           
	} 
	if (!validEmail(lead_em2.value)) {
	    alert("Invalid e-mail address!");
	    lead_em2.focus();
	    return false;                   
	} 
	if (lead_em1.value != lead_em2.value) {
	    alert("E-mails don't match");
	    lead_em1.focus();
	    return false;
	}
    }
    
    
    
      //*** validate passwords
    pwd1 = formObj.p1;
    pwd2 = formObj.p2;
    if (pwd1 == null && pwd2 == null) {
	return true;
    }
    if (pwd1.value.length < 6) {
	alert("Password should be at least 6 characters!");
	pwd1.focus();
	return false;
    }
    if (pwd2.value.length < 6) {
	alert("Password should be at least 6 characters!");
	pwd2.focus();
	return false;
    }
    if (pwd1.value != pwd2.value) {
	alert("Passwords don't match!");
	pwd1.focus();
	return false;
    }
    
    return true;
}

//-------------------------------------------------
function LoginFormValidate(formObj) {
    username = formObj.username;
    
    if (!validEmail(username.value)) {
	    alert("Invalid e-mail address!");
	    username.focus();
	    return false;           
    } 
    
    pwd1 = formObj.password;
    if (pwd1.value.length < 6) {
	alert("Password should be at least 6 characters!");
	pwd1.focus();
	return false;
    }
    
    return true;
}

//-------------------------------------------------
function checkScreen(formObj, formType) {
   //*** required fields are hold in the hidden field called reqfields
    reqfields = formObj._hidden_reqfields;
    if (reqfields != null && reqfields.value != "") {
      fields = reqfields.value.split(",");
      for (i=0; i<fields.length;i++) {
        fieldProps = fields[i].split("|");
        fid = fieldProps[0];
        ftype = fieldProps[1];
        fsize = fieldProps[2];
        fcapt = fieldProps[3];
        
        formField = document.getElementById(fid);  
        v = formField.value;
            //***check empty 
            if (v == "" || v == " ") {
              alert(fcapt +" is required!");
              formField.focus();
              return false;
            }
            //***check size
            if (v.length > fsize && ftype !=11 && ftype != 12 && ftype != 21 && ftype != 10 ) { 
            
              //***for some reason email and address, selection filed is size 1
              alert(fcapt + " length should not be longer than " + fsize + "!");
              formField.focus();
              return false;
            }
            //*** if email validate email address
            if (ftype == 12 && !validEmail(v)) {
              alert("Invalid email address!");
              formField.focus();
              return false;
            }
            //*** if integer 
            if (ftype == 31) {
              if (v < 0 || parseInt(v)!=v-0) {
                alert(fcapt + " is not integer!");
                formField.focus();
                return false;
              }
            }
      }
    }

if (formType) {
    if (formType == 1) {
            //****if it's the register form check email and confirm email, also check pass and conf pass
            //**************************************************
             
            em1 = formObj.pers_emailaddress;
            em2 = formObj.pers_emailaddress_confirm;
            if (!validEmail(em1.value)) {
                alert("Invalid e-mail address!");
                em1.focus();
                return false;           
            } 
            if (!validEmail(em2.value)) {
                alert("Invalid e-mail address!");
                em2.focus();
                return false;                   
            } 
            if (em1.value != em2.value) {
                alert("E-mails don't match");
                em1.focus();
                return false;
            }
            
            
            //*** validate passwords
            pwd1 = formObj.pers_password;
            pwd2 = formObj.pers_password_confirm;
            if (pwd1.value.length < 6) {
                alert("Password should be at least 6 characters!");
                pwd1.focus();
                return false;
            }
            if (pwd2.value.length < 6) {
                alert("Password should be at least 6 characters!");
                pwd2.focus();
                return false;
            }
            if (pwd1.value != pwd2.value) {
                alert("Passwords don't match!");
                pwd1.focus();
                return false;
            }
    } else if (formType==2) {
      
            em1 = formObj.visi_logonid;
            if (!validEmail(em1.value)) {
                alert("Invalid e-mail address!");
                em1.focus();
                return false;           
            }
            //*** validate passwords
            pwd1 = formObj.visi_password;
            if (pwd1.value.length < 6) {
                alert("Password should be at least 6 characters!");
                pwd1.focus();
                return false;
            }
      
    }
}    
    //**************************************************
  /*  
  submitButtonObj = document.getElementById("submit_"+formObj.name);
  if (formObj.whereclause != null) {
    AjaxObject.startRequest('record/updateRecord.asp', formObj, submitButtonObj);
    return false; 
  }
  */
  return true;
}
//**********************************
function checkSubscriberForm(f) {
 if (f.username.value.length < 4 ) {
     alert('Email must be at least 4 characters.');
     return false;
   }
  var reg = /^([a-zA-Z0-9_\-\.]{2,})@((\[[0-9]{1,3}\.[0-9]{1,3}\.[0-9]{1,3}\.)|(([a-zA-Z0-9\-]{2,}\.)+))([a-zA-Z]{2,4}|[0-9]{1,3})(\]?)$/;

  var address = f.username.value; 
  var result = reg.test(address);
  
  if(!result) {
      alert('Invalid Email Address');
      return false;
  }

  if (!f.agree.checked) {
      alert('You must Agree to receive email notification.');
      return false;
  }


  //AjaxObject.startRequest('subscribe.asp', f); 
  //return false;
  return true;
}

//**********************************
function checkContactUsForm(f) {
   if (f.realname.value.length < 4 || f.username.value.length < 4 ) {
     alert('Name and Email must be at least 4 characters.');
     return false;
   }

  var reg = /^([a-zA-Z0-9_\-\.]{2,})@((\[[0-9]{1,3}\.[0-9]{1,3}\.[0-9]{1,3}\.)|(([a-zA-Z0-9\-]{2,}\.)+))([a-zA-Z]{2,4}|[0-9]{1,3})(\]?)$/;

  var address = f.username.value; 
   var result = reg.test(address);
  
   if(!result) {
      alert('Invalid Email Address');
      return false;
   }
	
   if (!f.ischecked.checked) {
      alert('You must tick the check box before sending this message to us.');
      return false;
   }
   return true;
}
//**********************************
function checkForm(form, n) {
  valid = true;
  for (i=0; i< form.elements.length; i++) {
    elem = form.elements[i];
    if (elem.type == 'hidden' && elem.id.indexOf('required') > 0) {
      fieldProps = elem.id.split("|");
      
      if (!validateField(form, fieldProps)) 
        return false;
      
     
    } 
  }
  
  if (n == 1) {
    AjaxObject.startRequest('record/updateRecord.asp', form);  
    return false;
  } else {
    return true;
  }
}
//**********************************************
//*** handle cookies
function getCookie(c_name)
{
  c_name = c_name.replace(/_/g, "%5F");
  if (document.cookie.length>0) {
    cookiename = "eWareScreen=";
    s_start = document.cookie.indexOf(cookiename)+ cookiename.length;
    s_end = document.cookie.indexOf(";", s_start);
    if (s_end == -1) s_end = document.cookie.length;
    s = document.cookie.substring(s_start , s_end);
    c_start = s.indexOf(c_name + "=");
    if (c_start!=-1) { 
      c_start=c_start + c_name.length+1; 
      c_end=s.indexOf("&",c_start);
      if (c_end==-1) c_end=s.length;
        return decodeURI(unescape(s.substring(c_start,c_end)));
      }
  }
  return "";
}
//**********************************************
function setFormFromCookie(formObj) {
   for(i=0; i<formObj.length; i++) {
    if (formObj[i].type != 'hidden' && formObj[i].type != 'submit' && formObj[i].type != 'password') {
        //set the field value from the cookie
        formObj[i].value = getCookie(formObj[i].name);
    }
  }
 //delete the main cookie 
 document.cookie = "eWareScreen=; expires=Tue, 01-Jan-1980 00:00:01 UTC; path=/";
}
//**********************************************
function start_rotating() {
	var total_elements = $('#testimonials > div').length;
	var starting_number = Math.ceil(Math.random() * total_elements);
	$('#testimonials > div').hide();
	$('#testimonials >div:nth-child(' + starting_number + ')').show()
	.addClass('active');
	show_timer1 = setTimeout(function(){continue_rotating()}, 18000);
}
function continue_rotating() {
	var element = $('#testimonials > div.active').next();
	if ($(element).parent().attr('id') != 'testimonials') {
		element = $('#testimonials > div:first');
	}
	$('#testimonials > div.active').hide().removeClass('active');
	$(element).show().addClass('active');
	show_timer1 = setTimeout(function(){continue_rotating()}, 18000);
}

