//* Evetuoso Global JS *//
//* Variables *//
var regEmail = /^([A-Za-z0-9_\-\.])+\@([A-Za-z0-9_\-\.])+\.([A-Za-z]{2,4})$/;
var regPhone = /^\(([0-9]{3})\) ([0-9]{3})\-([0-9]{4})$/;
var contactScript='http://www.td-systems.com/contact/';
var supportScript='http://www.td-systems.com/support/';
var regCaptcha = /^([A-Za-z]{6})$/;
var ajaxLoadImg=['<img src="/images/ajaxloader2.gif" alt="" />'];

//* Public routines *//
//* Validator *//
function checkSupport()
{
	var bcontent=$("#subbut").html();
	$("#subbut").html(ajaxLoadImg[0]);
	if ($("#fullname").val().length<1)
	{
		var errorContent='Please enter your name';
		Sexy.alert(errorContent);
		$("#subbut").html(bcontent);
		return false;
	}
	if (regEmail.test($("#email").val())==false)
	{
		var errorContent='Please enter valid email address';
		Sexy.alert(errorContent);
		$("#subbut").html(bcontent);
		return false;
	}
	if ($("#summary").val()=='')
	{
		var errorContent='Please set problem summary';
		Sexy.alert(errorContent);
		$("#subbut").html(bcontent);
		return false;
	}
	if ($("#description").val()=='')
	{
		var errorContent='Please set problem description';
		Sexy.alert(errorContent);
		$("#subbut").html(bcontent);
		return false;
	}
	if (regCaptcha.test($("#captcha").val())==false)
	{
		var errorContent='Please enter valid code';
		Sexy.alert(errorContent);
		$("#subbut").html(bcontent);
		return false;
	}
	pBody='rtype='+escape($("#rtype").val())+'&fullname='+escape($("#fullname").val())+'&email='+escape($("#email").val())+'&description='+escape($("#description").val())+'&captcha='+escape($("#captcha").val())+'&summary='+escape($("#summary").val());
	ajaxCallSilent(supportScript,pBody,bcontent);
	return false;
}
function checkContact()
{
	var bcontent=$("#subbut").html();
	$("#subbut").html(ajaxLoadImg[0]);
	if ($("#fullname").val().length<1)
	{
		var errorContent='Please enter your name';
		Sexy.alert(errorContent);
		$("#subbut").html(bcontent);
		return false;
	}
	if (regEmail.test($("#email").val())==false)
	{
		var errorContent='Please enter valid email address';
		Sexy.alert(errorContent);
		$("#subbut").html(bcontent);
		return false;
	}
	if ($("#summary").val()=='')
	{
		var errorContent='Please type message subject';
		Sexy.alert(errorContent);
		$("#subbut").html(bcontent);
		return false;
	}
	if ($("#description").val()=='')
	{
		var errorContent='Please type your message';
		Sexy.alert(errorContent);
		$("#subbut").html(bcontent);
		return false;
	}
	if (regCaptcha.test($("#captcha").val())==false)
	{
		var errorContent='Please enter valid code';
		Sexy.alert(errorContent);
		$("#subbut").html(bcontent);
		return false;
	}
	pBody='rtype='+escape($("#rtype").val())+'&fullname='+escape($("#fullname").val())+'&email='+escape($("#email").val())+'&description='+escape($("#description").val())+'&captcha='+escape($("#captcha").val())+'&summary='+escape($("#summary").val());
	ajaxCallSilent(contactScript,pBody,bcontent);
	return false;
}
//* AJAX *//
function ajaxCallSilent(systemScript,pBody,bcontent)
{
	$.ajax({
		cache: false,
		contentType: "application/x-www-form-urlencoded",
		processData: false,
		type: "POST",
		url: systemScript,
		data: pBody,
		dataType: "html",
		success: function(response){
			if (response.indexOf('Error')>=0 || response.indexOf('error')>=0 || response.indexOf('Warning')>=0)
			{
				Sexy.alert(response);
				$("#subbut").html(bcontent);
			}
			else
			{
				Sexy.info(response);
				$("#subbut").html(bcontent);
			}
		},
		error: function(response,error,error2){
			Sexy.alert('AJAX Error: something went wrong, please try again later');
			$("#subbut").html(bcontent);
		}
	});
}

