$(function(){
	$(".iframe").fancybox({
		'width'				: 490,
		'height'			: 586,
        'autoScale'     	: false,
	//	'transitionIn'		: 'none',
	//	'transitionOut'		: 'none',
		'type'				: 'iframe'
		
	});
	
	$(".column_3 .banner_images img").css('opacity', '0.2');
	//$(".banner_images img").pixastic("desaturate");
	$(".column_3 .banner_images img").hover(function() {
		//$(this).pixastic("revert");
		$(this).animate({opacity: "1"}, {queue:false,duration:200});
	
	}, function() {
			//$(this).pixastic("desaturate");
			$(this).animate({opacity: "0.2"}, {queue:false,duration:200});
	});
	
	
	
	$('#frmSearch').submit(function(){
			
		if(validateNotEmpty($('#txtSearch').val())){
			var data = "txtSearch="+encodeURIComponent($('#txtSearch').val())+"&site_id="+encodeURIComponent($('#site_id').val());
			$('.column_2').html("<div style='text-align:center'><img src='/img/loading.gif'/></div>");
			$.ajax({
			  url: $(this).attr('action'),
			  data: data,
			  success: function(html){
			  $('.column_2').html(html);
			  }

			});
		}
		return false;
	});
	
$('.btnFrmNewsltter').hover(function(){ $(this).css('opacity','0.5');},function(){$(this).css('opacity','1');})	
$('.btnFrmNewsltter').click(function(){
	if(validateNotEmpty($('#txtEmail').val()))
	{
		$.ajax({
			  type: 'POST',
			  url: '/processemails.php',
			  data: { email: $('#txtEmail').val(), active: $(this).attr('rel') },
			  success: function(data){
					$('#frmNewsletter_notice').html(data);
			  }
			  
			});
	}
	
})
	
});

function play_clicked(){
	$.cookie('autoPlay', 'true');
}

function pause_clicked(){
	$.cookie('autoPlay', null);
}


/*
Strip whitespace from the beginning and end of a string
Input : a string
*/
function trim(str)
{
	return str.replace(/^\s+|\s+$/g,'');
}

/*
Make sure that textBox only contain number
*/
function checkNumber(textBox)
{
	while (textBox.value.length > 0 && isNaN(textBox.value)) {
		textBox.value = textBox.value.substring(0, textBox.value.length - 1)
	}
	
	textBox.value = trim(textBox.value);
/*	if (textBox.value.length == 0) {
		textBox.value = 0;		
	} else {
		textBox.value = parseInt(textBox.value);
	}*/
}

/*
	Check if a form element is empty.
	If it is display an alert box and focus
	on the element
*/
function isEmpty(formElement, message) {
	formElement.value = trim(formElement.value);
	
	_isEmpty = false;
	if (formElement.value == '') {
		_isEmpty = true;
		alert(message);
		formElement.focus();
	}
	
	return _isEmpty;
}

/*
	Set one value in combo box as the selected value
*/
function setSelect(listElement, listValue)
{
	for (i=0; i < listElement.options.length; i++) {
		if (listElement.options[i].value == listValue)	{
			listElement.selectedIndex = i;
		}
	}	
}
function trimAll( strValue ) {
/************************************************
DESCRIPTION: Removes leading and trailing spaces.

PARAMETERS: Source string from which spaces will
  be removed;

RETURNS: Source string with whitespaces removed.
*************************************************/
 var objRegExp = /^(\s*)$/;

    //check for all spaces
    if(objRegExp.test(strValue)) {
       strValue = strValue.replace(objRegExp, '');
       if( strValue.length == 0)
          return strValue;
    }

   //check for leading & trailing spaces
   objRegExp = /^(\s*)([\W\w]*)(\b\s*$)/;
   if(objRegExp.test(strValue)) {
       //remove leading and trailing whitespace characters
       strValue = strValue.replace(objRegExp, '$2');
    }
  return strValue;
}

function validateNotEmpty( strValue ) {
/************************************************
DESCRIPTION: Validates that a string is not all
  blank (whitespace) characters.

PARAMETERS:
   strValue - String to be tested for validity

RETURNS:
   True if valid, otherwise false.
*************************************************/
   var strTemp = strValue;
   strTemp = trimAll(strTemp);
   if(strTemp.length > 0){
     return true;
   }
   return false;
}



function validateEmail( strValue) {
/************************************************
DESCRIPTION: Validates that a string contains a
  valid email pattern.

 PARAMETERS:
   strValue - String to be tested for validity

RETURNS:
   True if valid, otherwise false.

REMARKS: Accounts for email with country appended
  does not validate that email contains valid URL
  type (.com, .gov, etc.) or valid country suffix.
*************************************************/
var objRegExp  = /^([0-9a-zA-Z]+([_.-]?[0-9a-zA-Z]+)*@[0-9a-zA-Z]+[0-9,a-z,A-Z,.,-]*(.){1}[a-zA-Z]{2,4})+$/;

  //check for valid email
  return objRegExp.test(strValue);
}


$(function(){
$('#btnSuggesties').click(function(){
	if(validateNotEmpty($('#txtSuggesties').val()) && $('#txtSuggesties').val()!='Type hier uw suggestie')
	{
	
	$.ajax({  
				   type: "POST",  
				   url: "/sendEmail.php",  
				   data: $('#frmSuggesties').serialize(),  
				   success: function(data) {  
					if(data){
								$('#frmSuggesties').slideUp();
								$('#infoSuggesties').hide().html(data).fadeIn();
						
					}
				   }  
				 });  
				 
				 
	
	} else {
	
	}
	
	return false;
});

$('#txtSuggesties').focus(function(){
	if($(this).val()=='Type hier uw suggestie')
	{
		$(this).val("");
	}
});

$('#txtSuggesties').blur(function(){
	if(!validateNotEmpty($('#txtSuggesties').val()))
	{
		$(this).val("Type hier uw suggestie");
	}
});
});
