$(document).ready(function(){
	$(".pfbody").hide();
	$(".pfhead").click(function(){
		$(this).next(".pfbody").slideToggle(100);
	});		
	
	$('#regForm').submit(function(e) {

		register();
		e.preventDefault();
		
	});
	
	$('#logForm').submit(function(e) {

		login();
		e.preventDefault();
		
	});
	
	$('#pswdForm').submit(function(e) {

		password();
		e.preventDefault();
		
	});
	$('#quoteForm').submit(function(e) {
		if(!$("#firstname").val() || !$("#lastname").val() || !$("#email").val() || !$("#comments").val()){
			$('#error').html("The following fields are required:<br />First Name, Last Name, Email, Company, Comment");
			$('#error').css({'visibility':'visible'});
			return false;
		}
		else
			return true;
		//requestqt();
		e.preventDefault();
		
	});
	
	$('#requestMapForm').submit(function(e) {
		if(!$("#firstname").val() || !$("#lastname").val() || !$("#email").val() || !$("#site-locations").val()){
			$('#error').html("The following fields are required:<br />First Name, Last Name, Email, Company, Site Locations");
			$('#error').css({'visibility':'visible'});
			return false;
		}
		else
			return true;
		//requestqt();
		e.preventDefault();
		
	});
	
	$('#moreinfo').submit(function(e) {
		if(!$("#firstname").val() || !$("#lastname").val() || !$("#email").val() || !$("#comment").val()){
			$('#error').html("The following are required:<br />First Name, Last Name, Email, and Comment");
			$('#error').css({'visibility':'visible'});
			return false;
		}
		else
			return true;
		//moreinfo();
		e.preventDefault();
		
	});
	
	var jQinputDefault = new jquery_inputDefault();
	jQinputDefault.init();
});


function register()
{
	hideshow('loading',1);
	error(0);
	
	$.ajax({
		type: "POST",
		url: "http://www.fiberlight.com/mapsystem/regprocessor.php?sid="+$sid,
		data: $('#regForm').serialize(),
		dataType: "json",
		success: function(msg){
		
			if(parseInt(msg.status)==1)
			{
				window.location=msg.txt;
			}
			else if(parseInt(msg.status)==0)
			{
				error(1,msg.txt);
			}
			
			hideshow('loading',0);
		}
	});

}

function login()
{
	hideshow('loading',1);
	error(0);
	
	$.ajax({
		type: "POST",
		url: "/mapsystem/logprocessor.php?sid="+$sid,
		data: $('#logForm').serialize(),
		dataType: "json",
		success: function(msg){
		
			if(parseInt(msg.status)==1)
			{
				window.location=msg.txt;
			}
			else if(parseInt(msg.status)==0)
			{
				logerror(1,msg.txt);
				$('#logerror').css({'visibility': 'visible', 'background-color': '#FFEBE8', 'border': '1px solid #DD3C10'});
			}
			
			hideshow('loading',0);
		}
	});

}

function password()
{
	hideshow('pswdloading',1);
	error(0);
	
	$.ajax({
		type: "POST",
		url: "/mapsystem/logprocessor.php?pswd=true",
		data: $('#pswdForm').serialize(),
		dataType: "json",
		success: function(msg){
		
			if(parseInt(msg.status)==1)
			{
				logerror(1,msg.txt);
				$('#logerror').css({'visibility': 'visible', 'background-color': '#ccffcc', 'border': '1px solid #33CC33'});
			}
			else if(parseInt(msg.status)==0)
			{
				logerror(1,msg.txt);
				$('#logerror').css({'visibility': 'visible', 'background-color': '#FFEBE8', 'border': '1px solid #DD3C10'});
			}
			
			hideshow('pswdloading',0);
		}
	});

}

function requestqt()
{
	hideshow('loading',1);
	error(0);
	
	$.ajax({
		type: "POST",
		url: "/wp-content/themes/fiberlight2.3/request-quote.php",
		data: $('#quoteForm').serialize(),
		dataType: "json",
		success: function(msg){
		
			if(parseInt(msg.status)==1)
			{
				window.location=msg.txt;
			}
			else if(parseInt(msg.status)==0)
			{
				error(1,msg.txt);
			}
			
			hideshow('loading',0);
		}
	});

}

function moreinfo()
{
	hideshow('loading',1);
	error(0);
	
	$.ajax({
		type: "POST",
		url: "/wp-content/themes/fiberlight2.3/includes/more-info.php",
		data: $('#moreinfo').serialize(),
		dataType: "json",
		success: function(msg){
		
			if(parseInt(msg.status)==1)
			{
				window.location=msg.txt;
			}
			else if(parseInt(msg.status)==0)
			{
				error(1,msg.txt);
			}
			
			hideshow('loading',0);
		}
	});

}


function hideshow(el,act)
{
	if(act) $('#'+el).css('visibility','visible');
	else $('#'+el).css('visibility','hidden');
}

function error(act,txt)
{
	hideshow('error',act);
	if(txt) $('#error').html(txt);
}
function logerror(act,txt)
{
	hideshow('logerror',act);
	if(txt) $('#logerror').html(txt);
}

$('#success').css('visibility','visible');
$('#error').html('Your registration was processed successfully');

/** Copyright (c) 2009 Pavel Virskiy - virskiy-p@mail.ru http://twitter.com/Paaashka*/
jquery_inputDefault = function() {	this.init = function(){var inputs = $("input.inputDef");inputs.each(function(){$(this).attr('value',$(this).attr('default')).addClass('jqueryInputDefault');});inputs.focus(function(){if($(this).attr('value') == $(this).attr('default')){$(this).attr('value','').removeClass('jqueryInputDefault');}});inputs.blur(function(){if($(this).attr('value') == ''){$(this).attr('value',$(this).attr('default')).addClass('jqueryInputDefault');}});}};
