var message_no_click = "Sorry, rechter muisklik functie is uitgeschakeld op deze site.";

function click(e)
{
	if(document.all)
	{
		if(2 == event.button)
		{
			alert(message_no_click);
			return false;
		}
	}
	if(document.layers)
	{
		if(3 == e.which)
		{
			alert(message_no_click);
			return false;
		}
	}
}
if(document.layers)
{
	document.captureEvents(Event.MOUSEDOWN);
}
document.onmousedown = click;

// firefox
//document.oncontextmenu = new Function("alert(message_no_click); return false;");



var ajaxErrorTimes = 0;
function handleAjaxError(calledBy)
{
	ajaxErrorTimes ++;
	if(ajaxErrorTimes < 5)
	{
		eval(calledBy);
	}
	else
	{
		ajaxErrorTimes = 0;
		alert("Onverwachte fout opgetreden! Controlleer uw Internet-verbinding en probeer opnieuw.");
	}
}


function trim(astring)
{
	return new String(astring).replace(/^\s*/, "").replace(/\s*$/, "");
}


function _getOffsets(el_id)
{
	var el = document.getElementById(el_id);

	var offsetLeft = 0;
	var offsetTop = 0;

	if(el.offsetParent)
	{
		do
		{
			offsetLeft += el.offsetLeft;
			offsetTop += el.offsetTop;
		}
		while(el = el.offsetParent);
		return [offsetLeft, offsetTop];
	}
}


function resetForm(formname, hide_spans, hide_elements)
{
	formname.reset();

	for(var f = 0; f < hide_spans.length; f ++)
	{
		//$("span[id^='" + hide_spans[f] + "']").css("display", "none");
		$("span[id^='" + hide_spans[f] + "']").hide("fast");
	}

	for(var f = 0; f < hide_elements.length; f ++)
	{
		$("#" + hide_elements[f]).hide("fast");
	}
}


function emailValid(email)
{
	if("" == new String(email).replace(/[a-z\d_\-\.]+@[a-z\d_\-\.]+\.[a-z\.]{2,5}/, ""))
	{
		return true;
	}
	else {
		return false;
	}
}


function passwordStrength(password)
{
	return true;
}


function logInClient(in_garden)
{
	$.post("../includes/getLoggedInClient.php", { login: document.getElementById("login_login").value, password: document.getElementById("login_password").value, remember_client: document.getElementById("remember_client").checked ? "yes" : "no" },
		function(reply)
		{
			if(reply == "ok")
			{
				//alert("U bent nu ingelogd.");
				if(in_garden)
				{
					document.location.href = "../tuin/index.php";
				} else
				{
					$("#div_main_left").load("../klant/menu.php?nd=" + new Date().getTime());
					$("#td_menu_top").load("../includes/menu_top.php?nd=" + new Date().getTime());
					$("#div_main_right").load("../klant/?content=1&nd=" + new Date().getTime());
				}
			} else
			{
				alert("Sorry! we zijn niet bekend met deze inlogcombinatie.");
			}
		}
	);
}
function logOutClient(hash)
{
	$.post("../includes/getLoggedOutClient.php", { logout: "yes", hash: hash },
		function(reply)
		{
			if(reply == "ok")
			{
				//alert("U bent nu uitgelogd.");
				//$("#td_menu_top").load("../includes/menu_top.php?nd=" + new Date().getTime());
				//$("#div_main_right").load("../inloggen/?content=1&nd=" + new Date().getTime());
				document.location.href = "../inloggen/index.php?nd=" + new Date().getTime();
			} else
			{
				document.location.href = "../inloggen/index.php?nd=" + new Date().getTime();
				//handleAjaxError("logOutClient('" + hash + "')");
			}
		}
	);

}

function logInCompany(in_garden)
{
	$.post("../includes/getLoggedInCompany.php", { login: document.getElementById("login_login").value, password: document.getElementById("login_password").value, remember_company: document.getElementById("remember_company").checked ? "yes" : "no" },
		function(reply)
		{
			if(reply == "ok")
			{
				//alert("U bent nu ingelogd.");
				if(in_garden)
				{
					document.location.href = "../tuin/index.php";
				} else
				{
					$("#div_main_left").load("../hovenier/menu.php?nd=" + new Date().getTime());
					$("#td_menu_top").load("../includes/menu_top.php?nd=" + new Date().getTime());
					$("#div_main_right").load("../hovenier/?content=1&nd=" + new Date().getTime());
				}
			} else
			{
				alert("Sorry! we zijn niet bekend met deze inlogcombinatie.");
			}
		}
	);
}
function logOutCompany(hash)
{
	$.post("../includes/getLoggedOutCompany.php", { logout: "yes", hash: hash },
		function(reply)
		{
			if(reply == "ok")
			{
				//alert("U bent nu uitgelogd.");
				//$("#td_menu_top").load("../includes/menu_top.php?nd=" + new Date().getTime());
				//$("#div_main_right").load("../inloggen/?content=1&nd=" + new Date().getTime());
				document.location.href = "../inloggen/index.php?nd=" + new Date().getTime();
			} else
			{
				document.location.href = "../inloggen/index.php?nd=" + new Date().getTime();
				//handleAjaxError("logOutCompany('" + hash + "')");
			}
		}
	);
}

function passwordClient(div_id, login)
{
	$("#" + div_id).hide("slow");

	$.post("../includes/getPasswordClient.php", { login: login },
		function(reply)
		{
			if(reply == "ok")
			{
				$("#" + div_id).show("slow");
			} else
			{
				alert(reply);
			}
		}
	);
}
function passwordCompany(div_id, login)
{
	$("#" + div_id).hide("slow");

	$.post("../includes/getPasswordCompany.php", { login: login },
		function(reply)
		{
			if(reply == "ok")
			{
				$("#" + div_id).show("slow");
			} else
			{
				alert(reply);
			}
		}
	);
}


function openGardenDescription(id)
{
	try
	{
		$("#div_dialog").dialog("option", "width", 450);
		$("#div_dialog").dialog("option", "height", 600);
		$("#div_dialog").dialog("option", "position", [10, 10]);
		$("#div_dialog").dialog("option", "modal", true);
		$("#div_dialog").dialog("option", "resizable", false);
		$("#div_dialog").dialog("option", "title", "VERKLARING TUIN");
		$("#div_dialog").bind("dialogclose", function(event, ui)
										{
											//
										}
						);
		$("#div_dialog").load("../tuin/verklaring.php?id=" + id + "&nd=" + new Date().getTime(), "", function()
										{
											$("#div_dialog").dialog('open');
										}
						);
	}
	catch(e)
	{
		var attributes = "top=10, left=10, width=450, height=400, location=0, scrollbars=1, menubar=0, status=0, resizable=0";
		window.open("../tuin/verklaring.php?id=" + id + "&nd=" + new Date().getTime(), "verklaring_tuin", attributes);
	}
}

function openConditions()
{
	try
	{
		$("#div_dialog").dialog("option", "width", 600);
		$("#div_dialog").dialog("option", "height", 600);
		$("#div_dialog").dialog("option", "position", [10, 10]);
		$("#div_dialog").dialog("option", "modal", true);
		$("#div_dialog").dialog("option", "resizable", false);
		$("#div_dialog").dialog("option", "title", "ALGEMENE VOORWAARDEN");
		$("#div_dialog").bind("dialogclose", function(event, ui)
										{
											//
										}
						);
		$("#div_dialog").load("../home/algemene_voorwaarden.php?content=" + new Date().getTime(), "", function()
										{
											$("#div_dialog").dialog('open');
										}
						);
	}
	catch(e)
	{
		var attributes = "top=10, left=10, width=450, height=400, location=0, scrollbars=1, menubar=0, status=0, resizable=0";
		window.open("../home/algemene_voorwaarden.php?content=" + new Date().getTime(), "algemene_voorwaarden", attributes);
	}
}

function openExplanation()
{
	try
	{
		$("#div_dialog").dialog("option", "width", 600);
		$("#div_dialog").dialog("option", "height", 600);
		$("#div_dialog").dialog("option", "position", [10, 10]);
		$("#div_dialog").dialog("option", "modal", true);
		$("#div_dialog").dialog("option", "resizable", false);
		$("#div_dialog").dialog("option", "title", "UITLEG");
		$("#div_dialog").bind("dialogclose", function(event, ui)
										{
											//
										}
						);
		$("#div_dialog").load("../home/uitleg.php?content=" + new Date().getTime(), "", function()
										{
											$("#div_dialog").dialog('open');
										}
						);
	}
	catch(e)
	{
		var attributes = "top=10, left=10, width=450, height=400, location=0, scrollbars=1, menubar=0, status=0, resizable=0";
		window.open("../home/uitleg.php?content=" + new Date().getTime(), "uitleg", attributes);
	}
}

function openGardenPhoto(garden_id)
{
	try
	{
		$("#div_dialog").dialog("option", "width", 900);
		$("#div_dialog").dialog("option", "height", 700);
		$("#div_dialog").dialog("option", "position", [10, 10]);
		$("#div_dialog").dialog("option", "modal", true);
		$("#div_dialog").dialog("option", "resizable", false);
		$("#div_dialog").dialog("option", "title", "PHOTOS");
		$("#div_dialog").bind("dialogclose", function(event, ui)
										{
											//
										}
						);
		$("#div_dialog").load("../tuin/photos.php?id=" + garden_id + "&content=" + new Date().getTime(), "", function()
										{
											$("#div_dialog").dialog('open');
										}
						);
	}
	catch(e)
	{
		var attributes = "top=10, left=10, width=450, height=400, location=0, scrollbars=1, menubar=0, status=0, resizable=0";
		window.open("../tuin/photos.php?id=" + garden_id + "&content=" + new Date().getTime(), "tuin_photos", attributes);
	}
}

function loadPage(container, page, parameters)
{
	$("#" + container).load(page + "?nd=" + new Date().getTime() + parameters);
}

function loadGarden(id)
{
	loadPage("div_main_left", "../tuin/garden_show.php", "&id=" + id);
	loadPage("div_main_right", "../tuin/garden_design.php", "&id=" + id);
}

var footer_width = 0;
var scroller_width = 900;
function scrollBlock(block_id, direction, scrollamount)
{
	var el = document.getElementById(block_id);
	var left = el.scrollLeft;

	if ("left" == direction)
	{
		var change = scrollamount;
	} else
	{
		var change = -scrollamount;
	}

	var newleft = left + change + "px";

	$("#" + block_id).animate( { scrollLeft:newleft }, 500);

	if(document.getElementById("img_arrow_left"))
	{
		if((left + change) > 0)
		{
			document.getElementById("img_arrow_left").src = "../images/arrow_left.jpg";
		} else
		{
			document.getElementById("img_arrow_left").src = "../images/arrow_left_idle.jpg";
		}
		if((left + change) < (footer_width - scroller_width))
		{
			document.getElementById("img_arrow_right").src = "../images/arrow_right.jpg";
		} else
		{
			document.getElementById("img_arrow_right").src = "../images/arrow_right_idle.jpg";
		}
	}
}


function scrollSubMenu(block_id, direction, scrollamount)
{
	var el = document.getElementById(block_id);
	var top = el.scrollTop;

	if ("up" == direction)
	{
		var change = scrollamount;
	} else
	{
		var change = -scrollamount;
	}
	var newtop = top + change + "px";

	$("#" + block_id).animate( { scrollTop:newtop }, 500);
}



function isNumberKey(evt)
{
	var charCode = (evt.which) ? evt.which : event.keyCode;

	if((190 == charCode) || (110 == charCode))
	{
		return true;
	}
	if(13 == charCode)
	{
		var scr_element_id = (evt.target) ? evt.target : evt.srcElement;
		scr_element_id.blur();
		return false;
	}

	if( (8 == charCode) || (9 == charCode) || (46 == charCode) )
	{
		return true;
	}
	if( (95 < charCode) && (106 > charCode) )
	{
		return true;
	}
	if( (36 < charCode) && (41 > charCode) )
	{
		return true;
	}

	if (charCode > 31 && (charCode < 48 || charCode > 57))
	{
		return false;
	}
	return true;
}

function openPDF()
{
	alert("PDF komt gauw...");
}

function toggleView(children_type, children_id)
{
	try
	{
		var children = $(children_type + "[id^='" + children_id + "']");
		var first_child = children[0];

		if("none" == first_child.style.display)
		{
			$(children_type + "[id^='" + children_id + "']").css("display", "");
		} else
		{
			$(children_type + "[id^='" + children_id + "']").css("display", "none");
		}
	}
	catch(e)
	{

	}
}
