﻿// JScript File
function sendMessage(p_target, p_featureId){
	var args = {};
	var container = $(p_target).parent().parent();
	container.find(":input").each(function(i){
		args[this.name] = this.value;
	}).end();
	
	container.find(".js-processing").show().end().find(".js-form").hide().end();
	try{
		if(p_featureId){
			AjaxService.SendFeatureMessage(p_featureId, args.name, args.email, args.phone, args.comments, onMessageSuccess, onMessageFailure, container);
		}
		else{
			AjaxService.SendMessage(args.name, args.email, args.phone, args.comments, onMessageSuccess, onMessageFailure, container);
		}
	}
	catch(err){
		container.find(".js-processing").hide().end().find(".js-form").show().end();
		alert(err)
	};
	return false;
};

function onMessageSuccess(result, userContext, methodName){
	userContext.find(".js-processing").hide().end().find(".js-sent").show().end();
};

function onMessageFailure(result, userContext, methodName){
	userContext.find(".js-processing").hide().end().find(".js-form").show().end();
};

$(document).ready(function(){
	$(".js-form :input").each(function(i){
	    this._labelText = this.value;
	    $(this).blur(function(){
	        if(!$(this).val()){
	            $(this).val(this._labelText);
	        }
	    });
	    $(this).focus(function(){
	        if($(this).val() == this._labelText){
	            $(this).val('');
	        }
	    });
	}).end();
});

if (typeof(Sys) !== "undefined") Sys.Application.notifyScriptLoaded();
