$(document).ready(function() {
/*	$('#myselectbox').selectbox();
	
	$("#nyhetsfelt input").focus(function () {
		//$(this).next("span").css('display','inline').fadeOut(1000);
		$(this).val('');
	});

	$("#nyhetsfelt input").blur(function () {
		$(this).val('Din epostadresse');
		
	});
*/
	
});


function dropDown() {
	dojo.query('.submenu').style("display", "none");
    dojo.query('#menu ul li:has(ul)')
        .connect('onmouseenter', function(){
        	dojo.addClass(this, "selected");
        	dojo.query('ul:first', this).style("display", "block");
        })
        .connect('onmouseleave', function(){
        	dojo.query('ul:first', this).style("display", "none");
        	dojo.removeClass(this, "selected");
        });

}


$(function() {
	$('a.lightbox').lightBox(); // Select all links with lightbox class
//	$('select').mSelect();
//	$('#demo').mSelect();
	
});



function addLightboxes() {
	$('a.lightbox').lightBox(); // Select all links with lightbox class
}

/*
$("input").focus(function () {
	//$(this).next("span").css('display','inline').fadeOut(1000);
	$(this).val('');
   });
*/




/*****************************************
 Ajax Submit og Form Validering
*****************************************/

// pre-submit callback 
function beforeRequest(formData, jqForm, options) { 
    // formData is an array; here we use $.param to convert it to a string to display it 
    // but the form plugin does this for you automatically when it submits the data 
 
    // jqForm is a jQuery object encapsulating the form element.  To access the 
    // DOM element for the form do this: 
    // var formElement = jqForm[0]; 
 	
    var navnValue = $('input[name=navn]').fieldValue();
    var epostValue = $('input[name=epost]').fieldValue();
 	var telefonValue = $('input[name=telefon]').fieldValue();
    // var fdatoValue = $('input[name=fodt]').fieldValue();
 
    // usernameValue and passwordValue are arrays but we can do simple 
    // "not" tests to see if the arrays are empty
    if (!navnValue[0] ) { 
		//alert('Vennligst fyll ut navn, epost og telefon'); 
		//$('input[name=navn]').css("background-color","pink");   
		$('input[name=navn]').removeClass('valid').addClass('nonvalid');
       	return false;
        	
    }
    else 
    { 
		//alert('Vennligst fyll ut navn, epost og telefon'); 
		//$('input[name=navn]').css("background-color","pink");   
		$('input[name=navn]').removeClass('nonvalid').addClass('valid');
    }
    
    
    if (!epostValue[0] ) { 
		//alert('Vennligst fyll ut navn, epost og telefon'); 
		//$('input[name=navn]').css("background-color","pink");   
		$('input[name=epost]').removeClass('valid').addClass('nonvalid');
       	return false;
       	
    }
    else 
    { 
		//alert('Vennligst fyll ut navn, epost og telefon'); 
		//$('input[name=navn]').css("background-color","pink");   
		$('input[name=epost]').removeClass('nonvalid').addClass('valid');
       	
    }
    
    
    if (!telefonValue[0] ) { 
		//alert('Vennligst fyll ut navn, epost og telefon'); 
		//$('input[name=telefon]').css("background-color","pink");   
		$('input[name=telefon]').removeClass('valid').addClass('nonvalid');
       	return false;
       	
    }
    else 
    { 
		//alert('Vennligst fyll ut navn, epost og telefon'); 
		//$('input[name=navn]').css("background-color","pink");   
		$('input[name=telefon]').removeClass('nonvalid').addClass('valid');
       	
    } 
 
    // here we could return false to prevent the form from being submitted; 
    // returning anything other than false will allow the form submit to continue  
    return true; 
    
} 




function send_contact_mail() {
	var options = { 
        target:        '#submit_div',   // target element(s) to be updated with server response 
        beforeSubmit:  beforeRequest,  // pre-submit callback 
        success:       afterRequest_Contact,  // post-submit callback 
        url:       	   '/api/get?type=form_contact'	// override for form's 'action' attribute 
        

    }; 
	
	$('#contact').ajaxForm(options);
	
	
	// !!! Important !!! 
    // always return false to prevent standard browser submit and page navigation 
//    return false; 
  

}

function send_newsletter_mail() {
	var options = { 
        target:        '#submit_news_li',   // target element(s) to be updated with server response 
        beforeSubmit:  beforeRequest,  // pre-submit callback 
        success:       afterRequest_Contact,  // post-submit callback 
        url:       	   '/api/get?type=form_newsletter'	// override for form's 'action' attribute 
        

    }; 
	
	$('#newsletter').ajaxForm(options);
	
	
	// !!! Important !!! 
    // always return false to prevent standard browser submit and page navigation 
//    return false; 
    

}

function afterRequest_Contact(responseText, statusText)  { 

    // for normal html responses, the first argument to the success callback 
    // is the XMLHttpRequest object's responseText property 
 
    // if the ajaxSubmit method was passed an Options Object with the dataType 
    // property set to 'xml' then the first argument to the success callback 
    // is the XMLHttpRequest object's responseXML property 
 
    // if the ajaxSubmit method was passed an Options Object with the dataType 
    // property set to 'json' then the first argument to the success callback 
    // is the json data object returned by the server 
 	
	$('#konkurranse').html("<p class='success'>Takk for din henvendelse!</p>");
    
}

function afterRequest_Newsletter(responseText, statusText)  { 

    // for normal html responses, the first argument to the success callback 
    // is the XMLHttpRequest object's responseText property 
 
    // if the ajaxSubmit method was passed an Options Object with the dataType 
    // property set to 'xml' then the first argument to the success callback 
    // is the XMLHttpRequest object's responseXML property 
 
    // if the ajaxSubmit method was passed an Options Object with the dataType 
    // property set to 'json' then the first argument to the success callback 
    // is the json data object returned by the server 
 	
	$('#submit_news_li').html("<p class='success'>Takk for din henvendelse!</p>");
    
}


//Nyhetsbrev / MailChimp


