$(document).ready(function()
{
	$("a[rel='references']").colorbox({previous: "előző", next: "következő", close: "bezár", current:"{current}/{total}"});
});

function checkForm()
{
	var req_name = document.getElementById("name");
	var req_email = document.getElementById("email");
	var req_phone = document.getElementById("phone");
	var req_service = document.getElementById("service");
	var req_details = document.getElementById("details");
	
	var name = req_name.value;
	var email = req_email.value;
	var phone = req_phone.value;
	var service = req_service.value;
	var details = req_details.value;
	
	var error = false;
	
	if(name == "")
	{
		showError(req_name);
		error = true;
	}
	
	if(email == "" || email.indexOf("@") < 1 || email.lastIndexOf(".") < 2)
	{
		showError(req_email);
		error = true;
	}
	
	if(phone == "")
	{
		showError(req_phone);
		error = true;
	}
	
	if(details == "")
	{
		showError(req_details);
		error = true;
	}
	
	if (error) return;
	else
	{
		$.get("http://polytex.hu/php/offer-request.php", { name: name, email: email, phone: phone, service: service, details: details },
		function(data)
		{
			document.getElementById("success").innerHTML = data;
			document.getElementById("submit").style.cssText = "display: none";
		})
	}
}

function showError(input)
{
	input.style.cssText = "border-color: red";
}

function clearError(input)
{
	input.style.cssText = "border-color: #e3e3e3";
}

function startMap()
{
	if (GBrowserIsCompatible()) {
		map = new GMap2($('#companyMap')[0]);
		map.enableScrollWheelZoom();
        map.addControl(new GSmallMapControl());
        map.addControl(new GMapTypeControl());
		if (null == mapLong || null == mapLat) {
			geocoder = new GClientGeocoder();
			geocoder.getLatLng(mapAddr, addPin);
			
		} else {
			addPin(new GLatLng(mapLat,mapLong));
		}
	}
}

function addPin(latLong)
{
	if (null == latLong) {
		geocoder = new GClientGeocoder();
		geocoder.getLatLng('Budapest', addPin);
	}
	lastLatLong = latLong;
	map.setCenter(latLong, 16);
	map.addOverlay(new GMarker(latLong));
	var divElement = document.createElement('div');
	divElement.className = 'maps_company_info';
	divElement.innerHTML = '<img src="img/polytex-logo-map.gif" alt="Polytex" /><div class="google_map_address">'+mapAddr+'</div>';
	map.openInfoWindow(latLong, divElement);
}


