

//Hide & Show box
$(function() {

	  $(document).ready(function() {

		  $('#viewbox').hide();

			  $('a.viewboxLink').click(function() {

				  var id = $(this).attr('id');

				  $('#viewbox' + id).slideToggle("slow");   

				  return false;

			  });

	  });

});


//Go next form field
function goNext(the_val, field_name, amount,form_name) {

 
 if (the_val.length == amount) {

    		document.forms[form_name].elements[field_name].focus();

		}
}


//Mail to
function mailto(in1, in2) {

	out1 = '';
	for (i = in1.length - 1; i >= 0; i--) {
		out1 += in1.charAt(i);
	}
	out2 = '';
	for (i = in2.length - 1; i >= 0; i--) {
		out2 += in2.charAt(i);
	}
	window.open('mailto:'+out1+'@'+out2, '_self');
}

//Check email
function isValidEmailAddress(emailAddress) {
var pattern = new RegExp(/^(("[\w-\s]+")|([\w-]+(?:\.[\w-]+)*)|("[\w-\s]+")([\w-]+(?:\.[\w-]+)*))(@((?:[\w-]+\.)*\w[\w-]{0,66})\.([a-z]{2,6}(?:\.[a-z]{2})?)$)|(@\[?((25[0-5]\.|2[0-4][0-9]\.|1[0-9]{2}\.|[0-9]{1,2}\.))((25[0-5]|2[0-4][0-9]|1[0-9]{2}|[0-9]{1,2})\.){2}(25[0-5]|2[0-4][0-9]|1[0-9]{2}|[0-9]{1,2})\]?$)/i);
return pattern.test(emailAddress);
}

$(document).ready(function() {
 $("#email").change(function(){
 var email = $("#email").val();
 if(email != 0){
  if(isValidEmailAddress(email)){
   $("#submit").removeAttr('disabled');
  } else {
   $("#submit").attr('disabled','disabled');
  }
 } else {
  $("#submit").attr('disabled','disabled');
 }
 });
}); 





//Search
$(document).ready(function() {


	$("#search-field").keyup(function() 

	{

		var question = $(this).val();

		var dataString = 'question=' + question;


		$.ajax({

		
			type: "GET",

			url: "search.php",

			data: dataString,

			cache: false,

				

			success: function(html)

			{

				$("#search-results").html(html).fadeIn(300);

			},
			 
			error: function(){
		
		}
		  

		});

			

		return false;

		

	});


});




//Hotspots
var div = $('#hotnews').hide(),
    news = ['Registrera ditt lotto nummer (Isdraken på Slotts Biografen i Uppsala den 18 februari)' ,'Big news! We have released our PhotoPearls iPhone app..', 'World record in Ireland', 'Download Catalog for 2011', 'How to mount your finished PhotoPearls bead motif'],
    address = ['contest','iphone','world-record', 'download-catalog', 'how-to-videos'],
    arrl = news.length,
    counter = 0;

function HotNews() {
    div.fadeIn(500).delay(5000).fadeOut(500, function() {
        HotNews();
    }).text(news[counter]);

    $("a#hotnews").attr('href', 'http://www.photopearls.se/'+address[counter++]+'.php');

    if (arrl <= counter) {
        counter = 0;
    }

}

HotNews();
