﻿function getContactForm() { 

var contact='<div id="contactA" style="display:none;">';
contact+= '<span id="email">Please enter your e-mail address</span><br />';
contact+= '<input type="text" id="txtEmail" style="width:320px" />';
contact+= '<br /><br />';
contact+= '<span id="subject">Message subject</span><br />';
contact+= '<input type="text" id="txtSubject" style="width:320px;"  />';
contact+= '<br /><br />';
contact+= '<span id="message">Please enter your message</span><br />';
contact+= '<textarea id="txtMessage" rows="6" style="width:320px;" cols="10"></textarea>';
contact+= '<br /><div id="plhButton" style="display:none;"></div><br /><br />';
contact+= '</div>';

return contact;

}

isActivated = false;
var timerConfirmed = false;
function doConfirmTimer() { timerConfirmed = true;}

function SetFieldV(fieldID) { $("#" + fieldID).css({'color':'red','font-weight':'bold'});$("#" + fieldID).focus();}

function isValid() { 
if ($("#txtEmail").val().length < 7) { SetFieldV("email"); return false; }
if ($("#txtSubject").val().length < 3) { SetFieldV("subject"); return false; }
if ($("#txtMessage").val().length < 20) { SetFieldV("message"); return false; }
return true;
}


function doThankYou() { 

t= '<div id="divThankYou" style="display:none;">';
t+= '<strong>Thank you!</strong><br /><br />';
t+= 'Your message was sent.&nbsp;<br /><br />';
t+= 'We will respond within the next 24 hours.';
t+='<img src="/images/thank-you.png" style="display:block;padding-top:33px;padding-left:33px;" alt="Thank you!" />';
t+= '</div>';

$("#divContact").html(t);
$("#divThankYou").slideDown(500);
}

function doPost() { 
var cal = doPost.caller.toString();
if (cal.toLowerCase().indexOf("if (timerconfirmed)" > 0)) { 

$("#plhButton").html('<div style="padding-top:15px;float:left;"><img src="/images/ajax-load2.gif" align="absmiddle" alt="Sending" style="margin-right:25px;" /> <br/><span style="color:#333;font-weight:bold;font-size:12px;">Now sending your message</span></div>');

$.post("/contact2/", {c:cal, e:$("#txtEmail").val(), s:$("#txtSubject").val(), m:$("#txtMessage").val()}, function(data) { 
if (data == "ok|do|key") { 
$("#contactA").slideUp(500, function() {doThankYou();});}
});

}

}

function doSendForm() {if (timerConfirmed) { if (isValid()) { doPost(); }}}

function doButton() { 
if (! isActivated) { 
isActivated = true;
$("#plhButton").html('<br /><br /><input type="button" id="btnSend" value=" Send Message " class="btn" style="cursor:pointer;" />');
$("#plhButton").fadeIn(1000);
$("#btnSend").click(function() { doSendForm(); });
}
 }

function doContact() { 

$("#divContact").html(getContactForm());

$("#contactA").fadeIn('slow');
$("#container").mousemove(function(e){ doButton();});
}

$(function() { 
$("#divContact").html(getContactForm());
window.setTimeout("doContact()", 1000);
window.setTimeout("doConfirmTimer()", 5000);
});

//var $tabs = jQuery.noConflict();

$tabs(document).ready(function() {
// setting the tabs in the sidebar hide and show, setting the current tab
	$tabs('div.tabbed div').hide();
	$tabs('div.t1').show();
	$tabs('#home-categories div.post').show();
	$tabs('#home-categories div.entry').show();
	$tabs('#home-categories div.c').hide();
	$tabs('#home-categories div.c1').show();
	$tabs('div.tabbed ul.tabs li.t1 a').addClass('tab-current');
	$tabs('div.tabbed ul.tabs li.c1 a').addClass('tab-current');
	$tabs('div.tabbed ul li a').css('cursor', 'pointer');

// SIDEBAR TABS
$tabs('.tabs-block div.tabbed ul.tabs li a').click(function(){
	var thisClass = this.className.slice(0,2);
	$tabs('.tabs-block div.tabbed div').hide();
	$tabs('.tabs-block div.' + thisClass).show();
	$tabs('.tabs-block div.tabbed ul.tabs li a').removeClass('tab-current');
	$tabs(this).addClass('tab-current');
	});

// CATEGORY TABS
$tabs('#home-categories div.tabbed ul.tabs li a').click(function(){
	var categoryClass = this.className.slice(0,2);
	$tabs('#home-categories div.tabbed div.c').hide();
	$tabs('#home-categories div.' + categoryClass).show();
	$tabs('#home-categories div.tabbed ul.tabs li a').removeClass('tab-current');
	$tabs(this).addClass('tab-current');
	});
});
