/*
 * Bug report - Javascript logic
 */ 
var flashinstalled = 0;
var flashversion = 0;
MSDetect = "false";
if (navigator.plugins && navigator.plugins.length)
{
	x = navigator.plugins["Shockwave Flash"];
	if (x)
	{
		flashinstalled = 2;
		if (x.description)
		{
			y = x.description;
			flashversion = y.charAt(y.indexOf('.')-1);
		}
	}
	else
		flashinstalled = 1;
	if (navigator.plugins["Shockwave Flash 2.0"])
	{
		flashinstalled = 2;
		flashversion = 2;
	}
}
else if (navigator.mimeTypes && navigator.mimeTypes.length)
{
	x = navigator.mimeTypes['application/x-shockwave-flash'];
	if (x && x.enabledPlugin)
		flashinstalled = 2;
	else
		flashinstalled = 1;
}
else
	MSDetect = "true";


function setBrowserInfo() {
	if (flashinstalled==2) {
		var flashV = flashversion;
	} else {
		var flashV = "Esse usuário não tem o plug-in do flash instalado\n"
	}
	var browser = navigator.appName;
	var os = navigator.appVersion;
	var codinome = navigator.appCodeName;
	var plataforma = navigator.platform;
	var header = navigator.userAgent;
	document.getElementById('userBrowserInfo').value = "\nHeader:"+header + "\nOs:" + os + "\nBrowser:"+ browser + "\nVersÃ£o plug-in do flash:" + flashV + "\nCodinome:"+codinome + "\nPlataforma:"+plataforma + "\n" + "***************************" + "\n"
}

function checkMail(email) {
	var filter  = /^([a-zA-Z0-9_\.\-])+\@(([a-zA-Z0-9\-])+\.)+([a-zA-Z0-9]{2,4})+$/;
	return filter.test(email);
}

function validateData() {
    validate = new Validation("error");
    validate.registerField("#name",    '#error_empty_contact_name', '#lb_name', validate.TYPE_TEXT, true);
    validate.registerField("#city",    '#error_empty_contact_city', '#lb_city', validate.TYPE_TEXT, true),
	validate.registerField("#state",   '#error_empty_contact_state', '#lb_state', validate.TYPE_TEXT, true);
    validate.registerField("#subject", '#error_empty_contact_subject', '#lb_subject', validate.TYPE_TEXT, true);
	validate.registerField("#contactText",    '#error_empty_contact_text', '#lb_text', validate.TYPE_TEXT, true);
	validate.registerField("#email",   '#error_empty_contact_email', '#lb_email', validate.TYPE_TEXT, true);
    if($("#email").val().length > 0) {
        validate.registerField("#email",   '#error_invalid_contact_email', '#lb_email', validate.TYPE_EMAIL, true);
    } else {
        $("#error_invalid_contact_email").hide();
    }
    if ( $("#subject").val() == "2-1" ) {
        validate.registerField("#contactPhone",   '#error_empty_contact_phone', '#lb_phone', validate.TYPE_TEXT, true);
    } else {
      $('#error_empty_contact_phone').hide();
    }

    return validate.validate();
}

function handleSendLoad(data) {
	//$('#message').html("Sending...");
}
		
function handleSendResponse(obj) {
	//$('#message').html(obj.status + " " + obj.message);
	//alert(obj.status + " " + obj.message);
	atmCLL('orolix_fale-conosco_sucesso');
	openModal('msgmodalOk');
	document.getElementById('frm_contact').reset();
}
		
function cleanFields() {
	$('#name').val('');
	$('#email').val('');
	$('#login').val('');
	$('#state').val('');
	$('#city').val('');
	$('#contactText').val('');
	//$('#subject').selectedIndex = 0;
	document.getElementById('subject').selectedIndex = 0
}

function sendData() {
  setBrowserInfo();

  var params = $('#frm_contact').formSerialize();
  var url = "contactservice.send.ajax.logic";

  $.ajax({
    type: "POST",
    url: url,
    data: params,
  dataType: "json",
    beforeSend: handleSendLoad,
    success: handleSendResponse
  });
}

