(function($) {
var href = '';
var leadsource = '';
    $(document).ready(
		function() {
			$('a.launch-short-form').click(
				function() {
					form.short.launch();
					return false;
				}
			);	
			
			$('a.launch-mail-form').click(
				function() {
					form.mail.launch();
					return false;
				}
			);			
			//form.short.launch();
			$('a.launch-long-form').click(
				function() {
					form.long.launch();
					return false;
				}
			);			
		}
		
	);
})(jQuery);
function GetEnrollmentPath()
{
var array;
if(document.location.href.indexOf("https://") > -1)
	array = document.location.href.replace("https://","").split('/');
else if(document.location.href.indexOf("http://")  > -1)
	array = document.location.href.replace("http://","").split('/');
if(array[1].toLowerCase() == "virginlifecare")
	return "http://" + array[0] + "/" + array[1] + "/group/CompanySearchResults.aspx";
else
	return "http://" + array[0] + "/group/CompanySearchResults.aspx";
}
function GetContactPath()
{
var array;
if(document.location.href.indexOf("https://") > -1)
	array = document.location.href.replace("https://","").split('/');
else if(document.location.href.indexOf("http://")  > -1)
	array = document.location.href.replace("http://","").split('/');
if(array[1].toLowerCase() == "virginlifecare")
	return "http://" + array[0] + "/" + array[1] + "/corporate/about_us.html?sel=3&max=3";
else
	return "http://" + array[0] + "/corporate/about_us.html?sel=3&max=3";
}
var enrollpath = GetEnrollmentPath();
var enrollmentMessage = "<br/><span>Looking to enroll? If your employer is subscribed, you can </span><a href='" + enrollpath + "' style='text-decoration:underline;color:Red;cursor:hand;font-weight:normal;'>enroll here</a>.";
var statictext = "Please fill out the fields below and let us know how we can assist you. For additional ways to reach us, see the <a href='" + GetContactPath() + "'>CONTACT INFORMATION</a> page.";
var statictitle = "What can we do for you?";
var altsftext1 = "Please fill out the fields below to discover a new approach to employee health and productivity. Once you click the Submit button, you will immediately receive the Virgin HealthMiles White Paper, <span class='bolditalic'>Pay-for-Prevention: An Emerging Health and Productivity Paradigm</span>. ";
var altsftext2 = "Please fill out the fields below to discover strategies proven to increase employee participation and long-term engagement in wellness initiatives. Once you click the Submit button, you will immediately receive the Virgin HealthMiles White Paper, <span class='bolditalic'>Identifying Best Practices in Corporate Wellness Programs</span>. ";
function hideDropdowns()
		{
		if(document.forms[0].className == "frmLong")
		{
				var elements = document.forms[0].elements;
				for (e = 0; e < elements.length; e++)
				{
					if (elements[e].type == "select-one")
					{
				
						elements[e].style.display = 'none';
					}
				}
				}
		}
function showDropdowns()
		{
		if(document.forms[0].className == "frmLong")
		{
				var elements = document.forms[0].elements;
				for (e = 0; e < elements.length; e++)
				{
					if (elements[e].type == "select-one")
					{
						elements[e].style.display = 'inline';
					}
				}
				}
		}
					
function showShortFormData(urlpopup) {

sb = "first_name";
sb+= " value:" + document.getElementById('sFirstName').value;
sb+= " key:" + "last_name";
sb+= " value:" + document.getElementById('sLastName').value;
sb+= " key:" + "company" ;
sb+= " value:" + document.getElementById('sCompanyName').value;
sb+= " key:" + "00N50000001v3iR" ;

if(document.getElementById('sMember').value == "true")
sb+= " value:1";
else
sb+= " value:0";
sb+= " key:" + "email" ;
sb+= " value:" + document.getElementById('sEmailAddress').value;
sb+= " key:" + "emailOptOut" ;
if(document.getElementById('sOptIn').checked)
sb+= " value:0";
else
sb+= " value:1";

sb+= " key:" + "oid" ;
sb+= " value:" + "00D300000005vTn";
sb+= " key:" + "retURL" ;
sb+= " value:" + "http://";

sb+= " key:" + "lead_source" ;
sb+= " value:" + "Web - Newsletter";

var ism = "false";

$.webservice({
		            url:"../../virginlifecare.webservices/wsSalesforce.asmx",
					data: {data: sb,IsMember :ism},
					contentType: "text/xml",
					dataType: "text",
					nameSpace:"http://www.virginlifecare.com/webservices/",
					methodName: "submitForm",
					error: function(XMLHttpRequest,textStatus, errorThrown){
					 $('.short-form-form').hide();
                     $('.lshort-form-working').hide();
                     $('.short-form-thankyou').show();
					 $('.short-form-thankyou')[0].innerText = "Your data has not been submitted. Please try again later.";
					},
					success:function(msg){
					    if(urlpopup != '')
                            {window.open(urlpopup);
                            $('div#short-form-dialog').dialog('close');
                            }
                        else
                            {
                            $('.short-form-form').hide();
                            $('.short-form-working').hide();
                            $('.short-form-thankyou').show();
                            }
					}
					});		

//this method submits the form to Salesforce via WebService if the user is not a  member; if the user is a member it sends an email to the callcenter; login in webservice
}		
		
function showLongFormData(url,source) {
sb = "first_name";
sb+= " value:" + document.getElementById('lFirstName').value;
sb+= " key:" + "last_name";
sb+= " value:" + document.getElementById('lLastName').value;
sb+= " key:" + "company" ;
sb+= " value:" + document.getElementById('lCompanyName').value;
sb+= " key:" + "00N50000001v3iR" ;
if(document.getElementById('lMember').value == "false")
sb+= " value:" + "0";
else
sb+= " value:" + "1";
sb+= " key:" + "email" ;
sb+= " value:" + document.getElementById('lEmailAddress').value;
sb+= " key:" + "phone" ;
sb+= " value:" + document.getElementById('lPhone').value;
sb+= " key:" + "city" ;
sb+= " value:" + document.getElementById('lCity').value;
sb+= " key:" + "state" ;
sb+= " value:" + document.getElementById('lState').value;
sb+= " key:" + "industry" ;
sb+= " value:" + document.getElementById('lIndustry').value;
sb+= " key:" + "00N50000001KYR5" ;
sb+= " value:" + document.getElementById('lEmployees').value;
sb+= " key:" + "emailOptOut" ;
if(document.getElementById('lOptIn').checked)
sb+= " value:0";
else
sb+= " value:1";
sb+= " key:" + "description" ;
sb+= " value:" + document.getElementById('lComments').value;
sb+= " key:" + "oid" ;
sb+= " value:" + "00D300000005vTn";
sb+= " key:" + "retURL" ;
sb+= " value:" + "http://";
sb+= " key:" + "lead_source" ;
var ism;

if(source != '')
{
//if the form is called on the whitepaper links or the home page calculator, etc. send in leadsource; then it goes straight to salesforce weather the user is member or not
    sb+= " value:" +  source;//"Web - P4P Wppr";// "Web - BP Wppr";
    ism = "false";
}
else
{//if it is the regular contact us link, either go to SF or send email; depending on membership dropdown
    sb+= " value:" + "Web - Contact Us";
    ism = document.getElementById('lMember').value;
}

//this method submits the form to Salesforce via WebService if the user is not a  member; if the user is a member it sends an email to the callcenter; login in webservice

$.webservice({
					url:"../../virginlifecare.webservices/wsSalesforce.asmx",
					data: {data: sb,IsMember :ism},
					contentType: "text/xml",
					dataType: "text",
					nameSpace:"http://www.virginlifecare.com/webservices/",
					methodName: "submitForm",
					error: function(XMLHttpRequest,textStatus, errorThrown){
					 $('.long-form-form').hide();
                     $('.long-form-working').hide();
                     $('.long-form-thankyou').show();
					 $('.long-form-thankyou')[0].innerText = "Your data has not been submitted. Please try again later.";
					},
					success:function(msg){
					    if(url != '')
                            {window.open(url);
                            $('div#long-form-dialog').dialog('close');
                            }
                        else
                            {
                            $('.long-form-form').hide();
                            $('.long-form-working').hide();
                            $('.long-form-thankyou').show();
                            }
					}
					});		
}

function showLandingFormData(source, whitepaper) {

sb = "first_name";
sb+= " value:" + document.getElementById('lFirstName').value;
sb+= " key:" + "last_name";
sb+= " value:" + document.getElementById('lLastName').value;
sb+= " key:" + "company" ;
sb+= " value:" + document.getElementById('lCompanyName').value;
sb+= " key:" + "00N50000001v3iR" ;
if(document.getElementById('lMember').value == "false")
sb+= " value:" + "0";
else
sb+= " value:" + "1";
sb+= " key:" + "email" ;
sb+= " value:" + document.getElementById('lEmailAddress').value;
sb+= " key:" + "phone" ;
sb+= " value:" + document.getElementById('lPhone').value;
sb+= " key:" + "city" ;
sb+= " value:" + document.getElementById('lCity').value;
sb+= " key:" + "state" ;
sb+= " value:" + document.getElementById('lState').value;
sb+= " key:" + "industry" ;
sb+= " value:" + document.getElementById('lIndustry').value;
sb+= " key:" + "00N50000001KYR5" ;
sb+= " value:" + document.getElementById('lEmployees').value;
sb+= " key:" + "emailOptOut" ;
if(document.getElementById('lOptIn').checked)
sb+= " value:0";
else
sb+= " value:1";
sb+= " key:" + "oid" ;
sb+= " value:" + "00D300000005vTn";
sb+= " key:" + "retURL" ;
sb+= " value:" + "http://";
sb+= " key:" + "lead_source" ;
var ism;

if(source != '')
{
    sb+= " value:" +  source;
    ism = "false";
}

$.webservice({
					url:"../../../virginlifecare.webservices/wsSalesforce.asmx",
					data: {data: sb,IsMember :ism},
					contentType: "text/xml",
					dataType: "text",
					nameSpace:"http://www.virginlifecare.com/webservices/",
					methodName: "submitForm",
					error: function(XMLHttpRequest,textStatus, errorThrown){
					 $('#txt')[0].innerText = "Your data has not been submitted. Please try again later.";
					},
					success:function(msg){
					//document.location.href = document.location.href;
					window.open(whitepaper);
					clearFields();
					}
					});
	
}
						
function showMailFormData() {
var sender = document.getElementById('mYourEmail').value;
var receiver = document.getElementById('mRecepientEmail').value;
var message = document.getElementById('mComments').value;
var link =  document.location.href;
var bodytext = "<![CDATA[" + message + "]]>";
var linktext = "<![CDATA[" + link + "]]>";
//this method sends an email via WebService to email addresses supplied by the user of the site
var param= {to:receiver,from:sender,cc:sender,body:bodytext,link:linktext};

$.webservice({
		url:"../../virginlifecare.webservices/wsEmail.asmx",
		data: param,
		contentType: "text/xml",
		dataType: "text",
		nameSpace:"http://www.virginlifecare.com/webservices/",
		methodName: "SendEmail",
		error: function(XMLHttpRequest,textStatus, errorThrown){
			$('.mail-form-thankyou')[0].innerText = "Your email has not been sent. Please try again later.";
		} 
		});		         
		$('.mail-form-form').hide();
		$('.mail-form-working').hide();
		$('.mail-form-thankyou').show();

}		

var form = {
	
	short: {
		launch: function(title,text,href) {
		if(href == undefined)
		    href = '';
	     $(this).attr('hr',href);
			$('div#short-form-dialog')
			.addClass('active')
			.dialog(
				{
					bgiframe: true,
					modal: true,
					width: 580,
					height: 450,
					draggable: false,
					position: 'center',
					open: function(event, ui) {
						var buttons = $('.ui-dialog-buttonpane button');
						buttons.eq(0).show();
						$('.short-form-form').show();
						$('.short-form-thankyou').hide();
						$('.short-form-working').hide();
						
					},
					buttons: { 
						Submit: function() {
							var cont = $(this);
							
							var valid = true;
							var member = $('#sMember'), cont
							var firstName = $('#sFirstName', cont)
							var lastName = $('#sLastName', cont)
							var companyName = $('#sCompanyName', cont)
							var emailAddress = $('#sEmailAddress', cont)
							var allFields = $([]).add(member).add(firstName).add(lastName).add(companyName).add(emailAddress)//.add(comments)
							
							var buttons = $('.ui-dialog-buttonpane button');
							var button_submit = buttons.eq(0);
							
							var iform = $('.short-form-form');
							var working = $('.short-form-working');
							var thankyou = $('.short-form-thankyou');
							
							allFields.removeClass('ui-state-error');
							
							try {
								valid = form.checkLength(firstName, 0, 100) && valid;
								valid = form.checkLength(member, 0, 100) && valid;
								valid = form.checkLength(lastName, 0, 100) && valid;
								valid = form.checkLength(companyName, 0, 100) && valid;
								valid = form.checkRegexp(emailAddress, /^((([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, "eg. ui@jquery.com") && valid;
							
								if (valid) {
																		
									iform.hide();
									working.show();
									thankyou.hide();
									buttons.hide();
									link = form.short.hr;
									showShortFormData(link);
									$('.short-form-fields input').val("");
                                    $('#sMember').val("");
									$('#sOptIn').attr('checked', true);
								}
								else
								buttons.show();

							} catch (ex) {
								alert(ex.message);
							}
						}
					}
				}
			)
			.dialog('open');
			if(text)
			    document.getElementById('ltxt').innerHtml= text;
			else
			    document.getElementById('ltxt').innerHtml = statictext;	
			if(title)
			   $('#ui-dialog-title-short-form-dialog')[0].innerHtml = title;
			else
			    $('#ui-dialog-title-short-form-dialog')[0].innerHtml = statictitle;
		}	
	},
		
	long: {
		launch: function(comments,title,text,href,leadsource) {
		hideDropdowns();
		 if(leadsource == undefined)
		    leadsource = '';
		 if(href == undefined)
		    href = '';
	     $(this).attr('ls',leadsource);
	     $(this).attr('hr',href);
			$('div#long-form-dialog')
			.addClass('active')
			.dialog(
				{
					bgiframe: true,
					modal: true,
					width: 625,
					height: 670,
					position: 'center',
					zIndex: 50000,
					draggable: false,
					open: function(event, ui) {
						var buttons = $('.ui-dialog-buttonpane button');
						buttons.eq(0).show();
						$('.long-form-form').show();
						$('.long-form-thankyou').hide();
						$('.long-form-working').hide();
						/*var labels = $(".long-form-field-label");
						labels.each(function(){
						if(this.htmlFor =='lMember')
						{	
						if(this.innerHTML.indexOf("If your employer") == -1)
							this.innerHTML = this.innerHTML + enrollmentMessage;
						}
						});*/
					},
					close : function(event,ui)
					{
					showDropdowns();
					},
					buttons: {
						Submit: function() {
							var cont = $(this);
							
							var valid = true;
							var member = $('#lMember'), cont
							var firstName = $('#lFirstName', cont)
							var lastName = $('#lLastName', cont)
							var companyName = $('#lCompanyName', cont)
							var emailAddress = $('#lEmailAddress', cont)
							var phone = $('#lPhone', cont)
							var city = $('#lCity', cont)
							var state = $('#lState', cont)
							var industry = $('#lIndustry', cont)
							var employees = $('#lEmployees', cont)
							var optin = $('#lOptIn', cont)
							var comments = $('#lComments', cont)
							var allFields = $([]).add(member).add(firstName).add(lastName).add(companyName).add(emailAddress).add(phone).add(city).add(state).add(industry).add(employees).add(optin)
							
							var buttons = $('.ui-dialog-buttonpane button');
							var button_submit = buttons.eq(0);
							
							var iform = $('.long-form-form');
							var working = $('.long-form-working');
							var thankyou = $('.long-form-thankyou');
							
							
							allFields.removeClass('ui-state-error');
							
							try {
								valid = form.checkLength(member, 0, 100) && valid;
								valid = form.checkLength(firstName, 0, 100) && valid;
								valid = form.checkLength(lastName, 0, 100) && valid;
								valid = form.checkLength(companyName, 0, 100) && valid;
								valid = form.checkRegexp(emailAddress, /^((([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, "eg. ui@jquery.com") && valid;
								valid = form.checkLength(phone, 0, 100) && valid;
								valid = form.checkLength(city, 0, 100) && valid;
								valid = form.checkLength(state, 0, 100) && valid;
								valid = form.checkPhone(phone, /^(?:(?:\+?1\s*(?:[.-]\s*)?)?(?:\(\s*([2-9]1[02-9]|[2-9][02-8]1|[2-9][02-8][02-9])\s*\)|([2-9]1[02-9]|[2-9][02-8]1|[2-9][02-8][02-9]))\s*(?:[.-]\s*)?)?([2-9]1[02-9]|[2-9][02-9]1|[2-9][02-9]{2})\s*(?:[.-]\s*)?([0-9]{4})(?:\s*(?:#|x\.?|ext\.?|extension)\s*(\d+))?$/i, "eg. ui@jquery.com") && valid;
								if (valid) {
									iform.hide();
									working.show();
									thankyou.hide();
									buttons.hide();
									lsource = form.long.ls;
									link = form.long.hr;
									showLongFormData(link,lsource);			
									$('.long-form-fields input').val("");
									$('.long-form-fields textarea').val("");
                                    $('.long-form-fields select').find('option:first').attr('selected', 'selected');
									$('#lOptIn').attr('checked', true);
								}
								else
								buttons.show();

							} catch (ex) {
								alert(ex.message);
							}
						}
					}
				}
			)
			.dialog('open');
			if(text)
			    document.getElementById('ltxt').innerHTML= text;
			else
			    document.getElementById('ltxt').innerHTML = statictext;	
			if(title)
			   $('#ui-dialog-title-long-form-dialog')[0].innerText = title;
			else
			    $('#ui-dialog-title-long-form-dialog')[0].innerText = statictitle;
			if (comments) { //show comments field
				if(comments == true){document.getElementById('long-form-comments').style.display = 'block';
				document.getElementById('long-form-dialog').style.height = '690px';}
				else
				{
				document.getElementById('long-form-comments').style.display = 'none';
				document.getElementById('long-form-dialog').style.height = '560px';
				}
			} else { // hide comments field
				document.getElementById('long-form-comments').style.display = 'none';
				document.getElementById('long-form-dialog').style.height = '560px';
			}			
		}	
	},
	
	mail: {
		launch: function() {
			$('div#mail-form-dialog')
			.addClass('active')
			.dialog(
				{
					bgiframe: true,
					modal: true,
					width: 630,
					height: 435,
					position: 'center',
					open: function(event, ui) {
						var buttons = $('.ui-dialog-buttonpane button');
						buttons.eq(0).show();
						$('.mail-form-form').show();
						$('.mail-form-thankyou').hide();
						$('.mail-form-working').hide();
					},
					buttons: { 
						Submit: function() {
							var cont = $(this);
							
							var valid = true;
							var yourEmail = $('#mYourEmail'), cont
							var recepientEmail = $('#mRecepientEmail', cont)
							var comments = $('#mComments', cont)
							var page = $('#mPage', cont)
							var allFields = $([]).add(yourEmail).add(recepientEmail).add(comments)
							
							var buttons = $('.ui-dialog-buttonpane button');
							var button_submit = buttons.eq(0);
							
							var iform = $('.mail-form-form');
							var working = $('.mail-form-working');
							var thankyou = $('.mail-form-thankyou');
							
							allFields.removeClass('ui-state-error');
							
							try {
								valid = form.checkRegexp(yourEmail, /^((([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, "eg. ui@jquery.com") && valid;
								valid = form.checkRegexp(recepientEmail,/^([\w-\.]+@([\w]+\.)+[a-zA-Z]{2,9}(\s*;\s*[\w-\.]+@([\w]+\.)+[a-zA-Z]{2,9})*)$/i, "eg. ui@jquery.com;us@jquery.com") && valid;													
								if (valid) {
																		
									iform.hide();
									working.show();
									thankyou.hide();
									buttons.hide();
									showMailFormData();			
									$('.mail-form-fields input').val("");
									$('.mail-form-fields textarea').val("");
                                    			$('.mail-form-fields select').find('option:first').attr('selected', 'selected');
								}
								else
								buttons.show();

							} catch (ex) {
								alert(ex.message);
							}
						}
					}
				}
			)
			.dialog('open');
			
		}	
	},
		
	
	checkLength: function(o, min, max) {
		var len = o.val().length;
		if (min < len && len <= max) {
		    $(o).parent().next().hide();
			return true;
		} else {
		    $(o).parent().next().show();
			return false;
		}

	},

	checkRegexp: function(o, regexp) {
		if (!(regexp.test(o.val()))) {
		    $(o).parent().next().show();
			return false;
		} else {
		    $(o).parent().next().hide();
			return true;
		}
	},
	
	checkPhone: function(o, regexp) {
		if (!(regexp.test(o.val()))) {
		    $(o).parent().next().show();
			return false;
		} else {
		    $(o).parent().next().hide();
			return true;
		}
	}

}