var Global = {
	init : function(ev) {
		rDomLite.addEvent('submitContactUs', 'click', this.onSubmit, this);
	
	},
	
	
	// submit contact form
	onSubmit : function(ev) {
		var stop = false;
		if (!rDomLite.trim(rDomLite.$('fullName').value)) {
			alert ('יש להכניס שם מלא');
			rDomLite.$('fullName').focus();
			stop = true;
		}
		
		if (!stop)
			if (!rDomLite.trim(rDomLite.$('email').value) &&
			    !rDomLite.trim(rDomLite.$('phone').value)) {
				alert('יש לרשום דואר אלקטרוני או מספר טלפון');
				rDomLite.$('email').focus();
				stop = true;
			}
		if (!stop) 
			if (!this.isValidEmail(rDomLite.$('email').value)) {
				alert('הדוא"ל שהכנסת אינו תקני, יש להכניס כתובת חוקית');
				rDomLite.$('email').focus();
				stop = true;
			}
			
		if (!stop)
			if (!rDomLite.trim(rDomLite.$('subject').value)) {
				alert('יש לרשום את נושא ההודעה');
				rDomLite.$('subject').focus();
				stop = true;
			}
		
		if (!stop)
			if (!rDomLite.trim(rDomLite.$('msgContent').value)) {
				alert('יש לרשום את תוכן ההודעה');
				rDomLite.$('msgContent').focus();
				stop = true;
			}
		
		if (stop) rDomLite.stopEvent(ev);
	},
	
	/*
	  Validates e-mail address
	  Converted to js by Max Raskin,
	  Original php version taken from http://www.ilovejackdaniels.com/php/email-address-validation/
	 
	  Params:
			string email
	  Returns:
			bool
	 */
	isValidEmail : function (email)
	{
	  // First, we check that there's one @ symbol, and that the lengths are right
	  if (!/^[^@]{1,64}@[^@]{1,255}$/.test(email))
	  {
	    // Email invalid because wrong number of characters in one section, or wrong number of @ symbols.
	    return false;
	  }
	  // Split it into sections to make life easier
	  var emailArray = email.split('@');
	  var localArray = emailArray[0].split('.');
	  for (var i = 0; i < localArray.length; i++) 
	  {
	     if (!/^(([A-Za-z0-9!#$%&'*+/=?^_`{|}~-][A-Za-z0-9!#$%&'*+/=?^_`{|}~\\.-]{0,63})|(\"[^(\\|\")]{0,62}\"))$/.test(localArray[i]))
			return false;
	  }
	  if (/^\\[?[0-9\\.]+\\]?$/.test(emailArray[1]))
	  { // Check if domain is IP. If not, it should be valid domain name
		var domainArray = emailArray[1].split('.');
	    if (domainArray.length < 2)
	        return false; // Not enough parts to domain
	        
	    for (i = 0; i < domainArray.length; i++) {
	      if (!/^(([A-Za-z0-9][A-Za-z0-9-]{0,61}[A-Za-z0-9])|([A-Za-z0-9]+))$/.test(domainArray[i])) {
	        return false;
	      }
	    }
	  }
	  return true;
	}

	
}

rDomLite.setInitHandler(Global);
