	var field1 = true;
	var field2 = true;
	var field3 = true;
	var field4 = true;
	var sendType = "email";

	//on focus function
	function focusEmailField(name){
		if( name == "recipient" && (document.sendform.recipient.value == emailText1)){
			document.sendform.recipient.value = "";
		}	
		if( name == "sendername" && (document.sendform.sendername.value == emailText2)){
			document.sendform.sendername.value = "";
		}
		if( name == "senderemail" && (document.sendform.senderemail.value == emailText3)){
			document.sendform.senderemail.value = "";
		}
    }
	
	//on blur function
	function blurEmailField(name){
		//if blur and nothing has been filled out, show message
        if( name == "recipient"){
			if( (document.sendform.sendername.value == emailText1) || (document.sendform.recipient.value == "") ){
				$("#emailForm fieldset.emailMain input#recipient").attr({"style": 'border-color: #f00'});
			}
		}
		if( name == "sendername"){
			if( (document.sendform.sendername.value == emailText2) || (document.sendform.sendername.value == "") ){
				$("#emailForm fieldset.emailMain input#sendername").attr({"style": 'border-color: #f00'});
			}
		}
		if( name == "senderemail"){					
			if( (document.sendform.senderemail.value == emailText3) || (document.sendform.senderemail.value == "") ){
				$("#emailForm fieldset.emailMain input#senderemail").attr({"style": 'border-color: #f00'});
				
			} else{
				verifyEmailAddress(document.sendform.senderemail.value);
			}
		}
		
		//if blur and something has been filled out, hide message
        if( name == "recipient"){
			if( (document.sendform.recipient.value != emailText1) && (document.sendform.recipient.value != "") ){
				$("#emailForm fieldset.emailMain input#recipient").attr({"style": 'border-color: #bcbbbb'});
			} else{
				verifyEmailAddress(document.sendform.recipient.value);
			}
		}
		if( name == "sendername"){
			if( (document.sendform.sendername.value != emailText2) && (document.sendform.sendername.value != "") ){
				$("#emailForm fieldset.emailMain input#sendername").attr({"style": 'border-color: #bcbbbb'});
			} 
		}
		if( name == "senderemail"){
			if( (document.sendform.senderemail.value != emailText3) && (document.sendform.senderemail.value != "") ){
				$("#emailForm fieldset.emailMain input#senderemail").attr({"style": 'border-color: #bcbbbb'});
			}
		}
	}//blurEmailField(name)


	function validateEmailForm(){
		field1 = true;
		field2 = true;
		field3 = true;	

		if( (document.sendform.recipient.value == emailText1) || (document.sendform.recipient.value == "") ){
			field1 = false;
		}							
		if( (document.sendform.sendername.value == emailText2) || (document.sendform.sendername.value == "") ){
			field2 = false;
		} 
		if( (document.sendform.senderemail.value == emailText3) || (document.sendform.senderemail.value == "") ){
			field3 = false;
		} 
		
		if( (field1 == true) && (field2 == true) && (field3 == true) ){
			return true;
		} else{
			$("#emailForm form p.errorMsg").attr({"style": 'visibility: visible'});
                  $("#emailForm fieldset.emailMain input#recipient").attr({"style": 'border-color: #f00'});
			$("#emailForm fieldset.emailMain input#sendername").attr({"style": 'border-color: #f00'});
			$("#emailForm fieldset.emailMain input#senderemail").attr({"style": 'border-color: #f00'});
			return false;
		}
	}
	
	function verifyEmailAddress(email)
	{
		var splitted = email.match("^(.+)@(.+)$");
		if(splitted == null) {$("#emailForm fieldset.emailMain input#senderemail").attr({"style": 'border-color: #f00'});field3 = false;} else {
		if(splitted[1] != null )
		{
		  var regexp_user=/^\"?[\w-_\.]*\"?$/;
		  if(splitted[1].match(regexp_user) == null) {$("#emailForm fieldset.emailMain input#senderemail").attr({"style": 'border-color: #f00'});field3 = false;}
		}
		if(splitted[2] != null)
		{
		  var regexp_domain=/^[\w-\.]*\.[A-Za-z]{2,4}$/;
		  if(splitted[2].match(regexp_domain) == null) 
		  {
			var regexp_ip =/^\[\d{1,3}\.\d{1,3}\.\d{1,3}\.\d{1,3}\]$/;
			if(splitted[2].match(regexp_ip) == null) {$("#emailForm fieldset.emailMain input#senderemail").attr({"style": 'border-color: #f00'});field3 = false;}
		  }// if
		  field3 = true;
		  return true;
		}
	{$("#emailForm fieldset.emailMain input#senderemail").attr({"style": 'border-color: #f00'});field3 = false;}
	  }
	}	
	
	function checkEmailForm(formData, jqForm, options) {
		var passFlag = false;
		passFlag = validateEmailForm();
		if ($("#recipient").val() == "") {
			$("#recipient_error").slideDown("slow");
			passFlag = false;
		} else {
			$("#recipient_error").hide();
		}

		if ($("#senderemail").val() == "") {
			$("#senderemail_error").slideDown("slow");
			passFlag = false;
		} else {
			$("#senderemail_error").hide();
		}

		if ($("#sendername").val() == "") {
			$("#sendername_error").slideDown("slow");
			passFlag = false;
		} else {
			$("#sendername_error").hide();
		}
		return passFlag;
            
    }

	function showThanks(responseText, statusText) {
		$("#form-area").slideUp();
		$("#thankyou").fadeIn("def");
    }
			
	function setServer() {
 	    var servname = document.URL.match(/^https?:\/\/(.*?)\.?ul\.com/i);
 	    if (servname && servname[1]) {
			switch (servname[1]) {
 	        case "www":
 	        case "beta":
 	           //document.sendform.smtpSvr.value="mailhost-core.vsvcs.cscehub.com";
			   document.sendform.smtpSvr.value="localhost";
			   break;
 	         default:
 	           document.sendform.smtpSvr.value="usnbkm201.us.ul.com";
 	       }
	    }
		return true;
	}	
	

	// Hide thank you message
    $("#thankyou").hide();

    // Add and hide validation errors
    $("#recipient").after("<p id='recipient_error' class='error'>" + pleaseEnterText + emailText1 + "</p>");
    $("#sendername").after("<p id='sendername_error' class='error'>" + pleaseEnterText + emailText2 + "</p>");
	$("#senderemail").after("<p id='senderemail_error' class='error'>" + pleaseEnterText + emailText3 + "</p>");
    $(".error").hide();

    // Setup form options
    var options = {
					target: "#output",
                    beforeSubmit: checkEmailForm,
                    success: showThanks
				  };
                $("#sendform").ajaxForm(options);
				
