// JavaScript Document
$('document').ready(function(){initMenu()})

function initMenu()
{
	$("li.pete-fraser-menu").mouseover(function(){
		$(this).find("div:first").show();
		$(this).find("a:first").removeClass().addClass("pete-fraser-menu-active");
	})
	$("li.pete-fraser-menu").mouseout(function(){
		$(this).find("div:first").hide();
		$(this).find("a:first").removeClass().addClass("pete-fraser-menu");
	})
	
	$(".inputBox").focus(function(){
		$(".help-outer").show();						  
		$(".help-outer").css('top', $(this).position().top);
		$(".help-outer").css('left', $(this).position().left + $(this).outerWidth() +20);
		$(".help-content").html($(this).attr("helptext"))
	})
	$(".inputBox").focusout(function(){
		$(".help-outer").hide();						  
		validateObj($(this));
	})
	

	var itemScroller = new BOLI.ItemScroller;
	itemScroller.itemClassName =	"testimonial-item";
	itemScroller.numberOfItemsToDisplay = 3;
	itemScroller.interval = 6000;
    $('#testimonials-container').append(itemScroller.render());

	

}




/****************************************************************************************************************/
function in_array(str, arr)
{
	for (i in arr)
	{
		if (arr[i] == str)
		{
			return i;
		}
	}
	return false;
}

function empty(obj)
	{
		if (obj.attr('disabled')) return false; //if the field is disabled by a switch
		if (obj.get(0).tagName == 'INPUT') 
		{
			if (obj.attr('type') == 'text')
			{
				if (obj.val()=='') {
					return true
				} 
				else {
					if (obj.attr('id') == 'tbEmail') {
						var reg = /^([A-Za-z0-9_\-\.])+\@([A-Za-z0-9_\-\.])+\.([A-Za-z]{2,4})$/;
						if (!(reg.test(obj.attr('value'))))
						{
							return true;
						}
					}
					return false
				}
			}
		}
		if (obj.get(0).tagName == 'TEXTAREA')
		{
			if (obj.val()=='') {return true} else {return false}
		}
	}

function markError(obj)
	{
		if (!in_array(obj.attr('id'), errmsg))
		{
			errmsg.push(obj.attr('id'));
		}
		if (obj.attr('type') == "checkbox")
		{
			obj.removeClass().addClass('inputBoxError');
		}
		else
		{
			obj.removeClass().addClass('inputBoxError');
		}
	}

function clearError(obj)
	{
		//remove from error array
		if (in_array(obj.attr('id'), errmsg))
		{
			errmsg.splice(in_array(obj.attr('id'), errmsg), 1);
		}
		if (obj.attr('type') == "checkbox")
		{
			obj.removeClass().addClass('inputBox');
		}
		else
		{
			obj.removeClass().addClass('inputBox');
		}
	}

var errmsg = [];

function validateForm()
{
	var items = ['tbName', 'tbEmail', 'tbQuery'];
	for (var i = 0; i< items.length; i++)
	{
		var obj = $('#'+items[i]);
		validateObj(obj)
	}
	if (errmsg.length > 0)
	{
		alert('Please check the form!')
	}
	else
	{
		$('.button').hide();
		var img = $('<img src="img/loading.gif" />');
		img.css('padding-top', '14px');
		img.css('padding-bottom', '13px');
		$('.button').parent().append(img);
		$.ajax({ 
		   type: "POST", 
		   url: "pages/contact-submit.php", 
		   data: "tbName=" + $("#tbName").attr('value')
		   +"&tbEmail=" + $("#tbEmail").attr('value')
		   +"&tbQuery=" + $("#tbQuery").attr('value'), 
		   success: function(msg){ 
		   	 $('#contactForm').parent().html("<h2>Thank you, we will answer your question as soon as possible. </h2>" + msg)
			 $('#contactForm').hide();
		   } 
		 });
	}
}
function validateObj(obj)
{
	if (empty(obj)) 
	{
		markError(obj);
	}
	else
	{
		clearError(obj);
	}
}

function getPressItem(name)
{
	window.open (name, "mywindow","");
}

//$(document).ready(function(){new ctrlDisable})

ctrlDisable = function ()
{
	this.lastKey = null
	var This = this;
	$(document).keydown(function(e){ This.checkKeyDown(e) })
	$(document).keyup(function(e){ This.checkKeyUp(e) })
	
	this.checkKeyDown = function(e)
	{
		if (this.lastKey != null)
		{
			$('.content-container').append('<div>keydown: '+e.which+'</div>')
		}
		this.lastKey = e.which;
		//$('.content-container').append('<div>keydown: '+e.which+'</div>')
	}
	this.checkKeyUp = function(e)
	{
		//$('.content-container').append('<div>keyup: '+e.which+'</div>')
		this.lastKey = null;
	}
}





























