function clickclear(thisfield, defaulttext) {
	if (thisfield.value == defaulttext) {
	   thisfield.value = "";
	}
}
function clickrecall(thisfield, defaulttext) {
	if (thisfield.value == "") {
	   thisfield.value = defaulttext;
	}
}

function trim(value) {
	  value = value.replace(/^\s+/,'');
	  value = value.replace(/\s+$/,'');
	  return value;
}

function random(){
	
	var now = new Date().getTime() / 1000;  
    var s = parseInt(now);  
	   
	var time = parseInt(now);
	return Math.floor(Math.random() * time);
	
}
var preloaddiv = $('<div id="preloaddiv"></div>');
preloaddiv.css("display", "none");
$("body").append(preloaddiv);

function preloadimg(img){
	var img = $('<img src="assets/images/' + img + '">');
	$("#preloaddiv").append(img);
}

function newsitem_get(id){
	
	 $(".news_item_full").fadeTo(100, 0.1);
     $(".news_item_full").html("");
	 $.ajax({
		   type: "POST",
		   url: "news.php",
		   data: "do=detailnews&newsid=" + id,
		   success: function(msg){
		      $(".news_item_full").html(msg);
		      $(".news_item_full").fadeTo(700, 1.0);

			  $("#news-mid-shadow").css({'height':$(".news_item_full").height() + 'px'});
		   }
	});
	 
	 
	
}

function newsitem_switchpage(page){
	 $(".newslistingwrapper").fadeTo(100, 0.1);
     $(".newslistingwrapper").html("");
	 $.ajax({
		   type: "POST",
		   url: "news.php",
		   data: "do=switchpage&page=" + page,
		   success: function(msg){
		      $(".newslistingwrapper").html(msg);
		      $(".newslistingwrapper").fadeTo(700, 1.0);
		   }
	});
}



function fold_menu(id){
	$("#submenu_menu_" + id).hide();

}

function unfold_menu(id){
	
	if($("#submenu_menu_" + id))
	$("#submenu_menu_" + id).toggle();
}

function sucker_menu(el){	
	$(el).find('li ul.submenu_menu').each(function(){
		var _ul = $(this);
		var _parent = $(this).parent();
		
		_parent.hover(function(){ _ul.show(); }, function(){ _ul.hide(); });
		//sucker_submenu(_ul);
	});
}

$(document).ready(function(){	
	sucker_menu('#mainmenu');

});
/* --------------------------------------------------------------------------- */


function change_border(el, defaulttext) {
	if(((el.val() == "") || el.val() == defaulttext || (el.val() == el.attr('alt'))) && (el.attr('type') == 'text')) {
		el.css("border", "1px solid #B11C0F");
		el.css("background-color", "#FFCC99");
		return true;
	} 
	else if(((el.val() == "") || (el.val() == el.attr('label'))) && (el.attr('label') != '')) {
		el.css("border", "1px solid #B11C0F");
		el.css("background-color", "#FFCC99");
		return true;

	}
	else if(el.attr('name') == 'email') {
		if(validateemail(el) && el.val() != defaulttext) {
			el.css("border", "none");	
			el.css("background-color", "#FFFFFF");
			return false;
		}
		else {
			el.css("border", "1px solid #B11C0F");
			el.css("background-color", "#FFCC99");
			return true;
		}
	}	
	else if(el.attr('name') == 'Telefoonnummer') {	     
		if(validatephone(el)) {			
			el.css("border", "none");	
			el.css("background-color", "#FFFFFF");
			return false;
		}
		else {			
			el.css("border", "1px solid #B11C0F");
			el.css("background-color", "#FFCC99");			
			return true;
		}		
	}	
	else if(el.attr('name') == 'Postcode') {	     
		if(validatepostalcode(el)) {
		    el.css("border", "none");	
			el.css("background-color", "#FFFFFF");
			return false;
		}
		else {
			el.css("border", "1px solid #B11C0F");
			el.css("background-color", "#FFCC99");
			return true;
		}		
	}	
	else {
		el.css("border-bottom", "none");
		el.css("background-color", "#FFFFFF");
		return false;
	}
}

function validateemail(el) {
	var matchArray = el.val().match(/^\w+([-+.]\w+)*@\w+([-.]\w+)*\.\w+([-.]\w+)*/);	
	if (matchArray == null) return false;
	else return true;
}

function validatepostalcode(el){	
    var value = el.val();
	if(value.length > 5) return true;
	else return false;	
}

function validatephone(el){	
	var value = el.val();	
	if(value.length > 9){		   
		 if(isNumeric(el)) return true;
		 else return false;
	}
	else return false;
}

function isNumeric(el){
	var numericExpression = /^[0-9]+$/;
	if(el.val().match(numericExpression)) return true;
	else return false;
}
