$(document).ready(function() {
	// main ajax settings
	$.ajaxSetup({
		url: '/ajax/ajax',
		type: 'post',
		dataType: 'json'
	});
	
    emptyCell('#loginForm #loginEmail');
	emptyCell('#loginForm #loginPassword');
	
	
	$("#errorDialog").dialog({
		autoOpen: false,
		width: 300,
		minHeight: 75,
		draggable: false,
		closeOnEscape: false,
		modal: false,
		resizable: false,
		zIndex: 100,
		buttons: {
			"Ok": function() { 
				$(this).dialog("close"); 
				}
			}
		});


	$("#infoDialog").dialog({
		autoOpen: false,
		width: 300,
		minHeight: 75,
		draggable: false,
		closeOnEscape: false,
		modal: false,
		resizable: false,
		zIndex: 100,
		buttons: {
			"Ok": function() { 
				$(this).dialog("close"); 
				}
			}
		});

	$("#questionDialog").dialog({
		autoOpen: false,
		width: 300,
		minHeight: 75,
		draggable: false,
		closeOnEscape: false,
		modal: true,
		resizable: false,
		zIndex: 100,
		buttons: {
			"Ok": function() { 
				$(this).dialog("close"); 
				return 'a';
				},
			"Annuleren": function() { 
				$(this).dialog("close"); 
				return 'b';
				}
			}
		});

	$(".horeca_in_vizier").click(function(){
		id = $(this).attr('id').split('_')[1]
		location.href = "/advertentie/"+id;
	});
});

function error(text){
	$("#errorDialog").find('.ui-state-error-text').html(text);
	$("#errorDialog").dialog("open");
}

function info(text){
	$("#infoDialog").find('.ui-state-info-text').html(text);
	$("#infoDialog").dialog("open");
}

//functie om bij een onfocus de cel leeg te maken, bij een blur wordt deze weer gevuld, indien leeg , met de standaardwaarde
function emptyCell(celid){
	
	$(celid).focus(function() {
	
		if (this.value == this.defaultValue){  
		    this.value = '';  
		} 
		
		if(this.value != this.defaultValue){  
		    this.select();  
		} 
		
		$(celid).blur(function() {  
        	if ($(this).val() == ''){  
            	$(this).val(this.defaultValue);  
        	}  
    	});
	
	});
}

function stripslashes(str) 
{
	str = str.replace(/\\'/g,'\'');
	str = str.replace(/\\"/g,'"');
	str = str.replace(/\\\\/g,'\\');
	str = str.replace(/\\0/g,'\0');
	return str;
}

function inc(filename){
	var body = document.getElementsByTagName('body').item(0);
	script = document.createElement('script');
	script.src = '/public/js/'+filename;
	script.type = 'text/javascript';
	body.appendChild(script)
}
