var ctimer = 0;
var blnCTimer = false;
var blnCurTimers = false;
var frmS = false;
var ajStatus = '';
var ajMsg = '';
$(document).ready(function()
{
	if($('.frms .btn').length) { $('.frms .btn').click(function() { FormID = '#' + $(this).parents('form').attr('id'); bln = valForm(FormID); if(bln) { frmS = true; $(FormID).submit(); } else { frmS = false; showMSG('<p class="twarn">An error occurred. Please check the fields</p>', '30%', '', false); } return false; }); }
	$("#frmcnt").submit
	(
		function()
		{
			if(frmS)
			{
				$('.sus, .err', this).remove();
				frmS = false;
				$(".frmsg").html('<p class="thgl">Sending Message, Please wait.</p>');
				var surl = $('#surl').val();
				var str = $(this).serialize();
				$.ajax(
				{
					type: "POST", url: surl+"vs-process.php", data: str, success: 
					function(msgStatus)
					{
						$(".frmsg").ajaxComplete(function(event, request, settings)	{ showMSG(msgStatus, '30%', '', false); $(this).html(msgStatus); });
					}
				});
				$("#securecode").attr("src", surl+"vs-scode.php?" +  Math.floor(Math.random()*100));
				$("#scoder").val('');
			}
			return false;
		}
	);
		
	if($('.clrform').length) { $('.clrform').click(function(){ frmClear('#'+$(this).parents('form').attr('id')); return false; }); }
	if($('#cleft .ulnone').length) { $('#cleft .ulnone li:last').css({'border':'0px'}); }
	if($('#faqs li').length) { $('#faqs li .qus').click(function(){ $('#faqs li .qus').removeClass('qushg'); $('#faqs li .ans').slideUp(); $(this).addClass('qushg'); $(this).next('.ans').slideDown(); }); }
	if($('input,textarea,select').length) { $('input,textarea,select').focus(function(){ $(this).addClass("fids-hgl"); $(this).next('.sus, .err').remove(); }); $('input,textarea,select').blur(function(){ $(this).removeClass("fids-hgl"); $(this).next('.sus, .err').remove(); }); }
	if($('#chathistory .tbl').length) { $("#chathistory .tbl .row").click(function() { window.location.replace($(this).find('a').attr('href')); }); }
	if($('#ctbar').length) { $("#ctbar").live({ mouseover: function() { $(this).stop().animate({ width: '350px'}, 500); }, mouseout: function() { $(this).stop().animate({ width: '25px'}, 500); } }); }
	if($('.tbl').length) { $(".tbl tr").live({ mouseover: function() { $(this).addClass("hvr"); }, mouseout: function() { $(this).removeClass("hvr"); } }); $(".tbl tr:odd").addClass('alt'); }
	$('.goback').click(function(){ parent.history.back(); return false; });	
	if($('#packages').length) { $("#packages .blks:first").addClass('blkshgl');	$("#packages .blks:first .selpack").attr('checked', 'checked'); $("#packages .selpack").change(function() { $("#packages .blks").removeClass('blkshgl'); $(".selpack:checked").parents().addClass('blkshgl'); }); }
	if($('#lbposts ul li').length) { $('#lbposts ul li:last').css({'border':'0'}); }
	if($('#menu ul').length)
	{
		$('#menu ul li').hover(function() { $('ul:first', this).css({'left': ($(this).offset().left)+'px'}); $('ul:first', this).slideDown('fast'); $(this).addClass('hgl'); },
		function() { $('ul', this).slideUp('fast'); $(this).removeClass('hgl'); });
		$('#menu li a').click(function() { if($(this).attr('href')=='#') { return false; } });
	}

});

var crstatus=window.setInterval(loadStatus, 3000);
function loadStatus() { if($('#status').length) { loadPage('#status','includes/status.php?type=stat'); } else { if(typeof crstatus != 'undefined'){ clearInterval(crstatus); } } }
function resetSize() { $('#loading').css({'top': ($(window).scrollTop() - $('#loading').height()) + 'px', 'left': ( $(window).width() - $('#loading').width() ) / 2+$(window).scrollLeft() + "px"}) }
function loadPage(strID, strPage) { var ajLP = $.ajax({ url: BASEURL+'/'+strPage, cache: false, timeout: 2000, error: function(x, t, m) { if(t=="timeout") { ajLP.abort(); loadPage(strID, strPage); } }, success: function(data) { $(strID).html(data); } }); }

function showMSG(strContent, strTop, strPage, callfunc)
{
	if(!$('#msg').length) { $('#page').append('<div id="msg_overlay"></div><div id="msg"></div>'); } $("#msg_overlay").height($(document).height()).css({'opacity' : 0.9, 'top' : '0px', 'left' : '0px'}).fadeIn('fast'); $("#msg").css("top", strTop);
	if(strContent=='ext') { $('#msg').html('<div id="msgcnt"></div>'); loadPage('#msgcnt', strPage); } else { $('#msg').html(strContent); }
	if($('#msg').width()==0) { $('#msg').css({'width':'400px'}); } $('#msg').css("left", ( $(window).width() - $('#msg').width() ) / 2+$(window).scrollLeft() + "px");
	$('#msg').fadeIn('slow'); $('#msg').prepend('<span id="msg_close"></span>');
	$('#msg_close').click(function() { if(callfunc) { doaction($('#creqid').val()); } $("#msg, #msg_overlay").fadeOut('slow');  });
}

function valForm(FormID)
{
	var blnErr = 'true';
	var bln = 'true';
	$('input',FormID).each(function()
	{
		if($(this).attr("type")!='hidden')
		{
			if($(this).hasClass('required'))
				bln = valInputBox("input[name="+ $(this).attr("name") +"]");
		}
		if(!bln)
			blnErr = false;
	});
	$('select',FormID).each(function()
	{
		if($(this).hasClass('required'))
			bln = valInputBox("select[name="+ $(this).attr("name") +"]");
		if(!bln)
			blnErr = false;
	});
	$('textarea',FormID).each(function()
	{
		if($(this).hasClass('required'))
			bln = valInputBox("textarea[name="+ $(this).attr("name") +"]");
		if(!bln)
			blnErr = false;
	});
	return blnErr;	
}

function valInputBox(obj)
{
	bln = true;
	if($(obj).length == 1)
	{
		$(obj).next('.sus, .err').remove();
		if(!$(obj).val()) { bln = false; }
		if(bln && $(obj).hasClass('email'))
			bln = valEmail($(obj).val());
		if(bln)
			$(obj).after('<span class="sus"></span>');
		else
			$(obj).after('<span class="err"></span>');
	}
	else if($(obj).length > 1)
	{
		$(obj).last().next('.sus, .err').remove();
		if($(obj).attr('type') != 'radio')
			{ $(obj).each(function() { if(!$(this).val()) { bln = false; } }); }
		else
			if(!$(obj+':checked').val()) { bln = false; }
		if(bln)
			$(obj).last().after('<span class="sus"></span>');
		else
			$(obj).last().after('<span class="err"></span>');
	}
	return bln;
}

function valEmail(email)
{
	var filter = /^([\w-]+(?:\.[\w-]+)*)@((?:[\w-]+\.)*\w[\w-]{0,66})\.([a-z]{2,6}(?:\.[a-z]{2})?)$/i;
	return filter.test(email);
}

function toFUcase(str)
{
	return str.charAt(0).toUpperCase() + str.replace(str.charAt(0),'');
}

function tblAltRow()
{
	$('.tbl .row').removeClass('row-alt');
	$('.tbl .row:nth-child(odd)').addClass('row-alt');
}

$('#ctbarhtime').live('click', function()
{
	if($('#chatwinmsg .cdtime').is(":visible"))
	{
		$('#ctbarhtime').html('Show Time');
		$('#chatwinmsg .cdtime').hide();
	}
	else
	{
		$('#ctbarhtime').html('Hide Time');
		$('#chatwinmsg .cdtime').show();
	}
	return false;
});

function frmClear(obj)
{
    $(obj).find(':input').each(function() {
        switch(this.type) {
            case 'password':
            case 'select-multiple':
            case 'select-one':
            case 'text':
            case 'textarea':
			{
                $(this).val('');
				$(this).next('.sus, .err').remove()
                break;
			}
            case 'checkbox':
            case 'radio':
			{
                this.checked = false;
				$(this).next('.sus, .err').remove()
			}
        }
    });
}

function taCount(objTAId, objCNTId, intCount)
{
	$('#'+objCNTId).html('0');
	$('#'+objTAId).keyup(function(e)
	{
    	var cLen = $('#'+objTAId).val().length;
	    if(cLen <= intCount) { $('#'+objCNTId).html(cLen); } 
		else { $(this).val($(this).val().substring(0, intCount)); }
	});
}

(function($) { $.fn.Heights = function(minHeight, maxHeight) { var tallest = (minHeight) ? minHeight : 0; this.each(function() { if($(this).height() > tallest) { tallest = $(this).height();	} }); if((maxHeight) && tallest > maxHeight) tallest = maxHeight; { return this.each(function() { $(this).height(tallest); }); } } })(jQuery);

Cufon.replace('h1, h2, h3, #menu a, .fnt, .baseline, .flinks');
Cufon.replace('#menu, .btn, .btn-hgl, .clrform', {textShadow: '1px 1px rgba(51, 51, 51, 1)'})('#cright h2', {textShadow: '1px 1px rgba(51, 51, 51, 1)'})('#baseline,#cright .blocks h2', {textShadow: '1px 1px rgba(255, 255, 255, 0.7)'});

