var submitCounter = 0;
var mainUrl = 'http://www.alexvanderlely.com/'
$(document).ready(function() {
	$('#mainMenu a').click(function(e) { e.preventDefault(); });
	$('#languageSwitch a').click(function(e) { e.preventDefault(); });
	$('#rightPane a').click(function(e) { e.preventDefault(); });
});

function ajaxCall(Page) {
	resetMenu(Page);
	pageTitles(Page,currentLanguage);
	$.ajax({
				type:'GET',
				url: mainUrl + 'funciones/llamadas_ajax.php',
				data : 
				{ 	'accion' : 'load_text',
					'page' : Page,
					'ajaxCall': 'Yes',
					'idioma': currentLanguage 
				},
				success: function(data) {
					if (Page == 'home') {
						$('#bodyContainer').html('<img class="main_pic" src="'+ mainUrl + 'imagenes/sitio/home.png" alt="AVDL, Quality Web development in Marbella"/>' + data);
					}
					else {
						$('#bodyContainer').html(data);
						$('#rightPane a').click(function(e) { e.preventDefault(); });
					}
				}
	});
	return;
}

function showPost(Id) {
	$.ajax({
		type:'GET',
		url: mainUrl + 'funciones/llamadas_ajax.php',
		data : 
			{ 	'accion_blog' : 'show_post',
				'id': Id,
				'ajaxCall': 'Yes',
				'idioma': currentLanguage
			},
		success: function(data) {
				$('#leftPane').html(data);
			}
	});
	return;
}


function pageTitles(Page,CurrentLanguage) {
	$('title').remove();
	if (CurrentLanguage == 'es') {
		if (Page == 'home') {
			$('head').append('<title> Dise&ntilde;o Web Marbella, Espa&ntilde;a | Desarrollo Web Marbella, Espa&ntilde;a | Sitios Web en Marbella | Programaci&oacute;n Web Marbella | Marbella, Dise&ntilde;ador Web </title>');
		}
		if (Page == 'services') {
			$('head').append('<title>Servicios de desarrollo web | dise&ntilde;o web y programaci&oacute;n de Sitios web por AVDL | Programaci&oacute;n de Sitios Web en Marbella | Programador Web Marbella | Maquetaci&oacute;n Xhtml/CSS en Marbella</title>');
		}
		if (Page == 'expertise') {
			$('head').append('<title>Expertos en PHP en Marbella | Programador MySQL | Servicios de Programaci&oacute;n Web | Programador Javascript en Marbella | Expertos en Desarrollo Web, Xhtml, CSS y Ajax en Marbella</title>');
		}
		if (Page == 'portfolio') {
			$('head').append('<title>Sitios web desarrollados por AVDL | Desarrollo, Programaci&oacute;n y Dise&ntilde;o Web en Marbella | Portfolio de sitios Web Desarrollados por AVDL</title>');
		}
		if (Page == 'standards') {
			$('head').append('<title>Sitios Web v&aacute;lidos Marbella | Standards W3C Sitios Web | Sitios Web de Calidad | Standards para tener en cuenta para su sitio web</title>');
		}
		if (Page == 'contact') {
			$('head').append('<title>Contactar AVDL, Desarrollo, Programacion y Dise&ntilde;o Web en Marbella.</title>');
		}
	}
	else if (CurrentLanguage == 'nl') {
		if (Page == 'home') {
			$('head').append('<title>Webontwerp Marbella | Web Programmatuur en Websiteontwikkeling in Marbella Spanje | AVDL Web Ontwerp in Marbella | Webontwerp Studio in Marbella | Nederlandse Web ontwikkelaar in Spanje</title>');
		}
		if (Page == 'services') {
			$('head').append('<title>Webontwerp services in Marbella Spanje | Marbella web design en web-applicatie-ontwikkeling door AVDL | Websites Marbella</title>');
		}
		if (Page == 'expertise') {
			$('head').append('<title>Onze expertisegebieden, PHP, MySQL, Javascript, XHTML, CSS en Ajax</title>');
		}
		if (Page == 'portfolio') {
			$('head').append('<title>Websites ontwikkeld door AVDL, Web Development, Programming en Design</title>');
		}
		if (Page == 'standards') {
			$('head').append('<title>Webstandaarden om in aanmerking te nemen bij het winkelen voor een website.</title>');
		}
		if (Page == 'contact') {
			$('head').append('<title>Contact opnemen met AVDL, Web Development Programming and Design in Marbella  </title>');
		}
	}
	else {
		if (Page == 'home') {
			$('head').append('<title>Marbella Web Design | Web designer in Marbella | Website Development, Web Programming and Web Design in Marbella, Spain by AVDL | Web designer in Marbella, Spain | </title>');
		}
		if (Page == 'services') {
			$('head').append('<title>Web Software Development Marbella | Marbella Web programming and Web design services by AVDL | Quality Web Development Programming and Design in Marbella, Spain | Web Programmer Marbella</title>');
		}
		if (Page == 'expertise') {
			$('head').append('<title>Website Planning | Website design, programming, Contents-writing and Production Marbella, Spain | Marbella PHP programmer | Expertise in PHP, MySQL, Javascript, Xhtml, CSS and Ajax | Website Plan </title>');
		}
		if (Page == 'portfolio') {
			$('head').append('<title>Websites developed by AVDL | Portfolio of AVDL Web Development, Programming en Design | Web applications in Marbella</title>');
		}
		if (Page == 'standards') {
			$('head').append('<title>Valid Websites Marbella | W3C Web Standards are important | Standards Web to take into consideration | Shopping for a Website in Spain </title>');
		}
		if (Page == 'contact') {
			$('head').append('<title>Contact AVDL, Web Development Programming and Design in Marbella, Spain</title>');
		}
	}
}

function changeLanguage(Idioma) {
	$('#languageSwitch a').css({'text-decoration': 'none', 'color': '#676767'});
	currentLanguage = Idioma;
	if (Idioma == 'es') {
		$('#mainMenu a:eq(0)').text('QUIENES SOMOS');
		$('#mainMenu a:eq(1)').text('SERVICIOS');
		$('#mainMenu a:eq(2)').text('EFICACIA');
		$('#mainMenu a:eq(3)').text('PORTFOLIO');
		$('#mainMenu a:eq(4)').text('STANDARDS WEB');
		$('#mainMenu a:eq(5)').text('NOTICIAS');
		$('#mainMenu a:eq(6)').text('CONTACTAR');
		$('#es').css({'text-decoration':'underline','color': '#73013c'});
	}
	else if (Idioma == 'nl') {
		$('#mainMenu a:eq(0)').text('WIE WE ZIJN');
		$('#mainMenu a:eq(1)').text('DIENSTEN');
		$('#mainMenu a:eq(2)').text('EXPERTISE');
		$('#mainMenu a:eq(3)').text('PORTEFEUILLE');
		$('#mainMenu a:eq(4)').text('WEB STANDAARDEN');
		$('#mainMenu a:eq(5)').text('NIEUWS');
		$('#mainMenu a:eq(6)').text('CONTACT');
		$('#nl').css({'text-decoration':'underline','color': '#73013c'});
	}
	else {
		$('#mainMenu a:eq(0)').text('ABOUT US');
		$('#mainMenu a:eq(1)').text('SERVICES');
		$('#mainMenu a:eq(2)').text('EXPERTISE');
		$('#mainMenu a:eq(3)').text('PORTFOLIO');
		$('#mainMenu a:eq(4)').text('STANDARDS WEB');
		$('#mainMenu a:eq(5)').text('NEWS');
		$('#mainMenu a:eq(6)').text('CONTACT');
		$('#en').css({'text-decoration':'underline','color': '#73013c'});
	}
	setSessionLanguage(Idioma);
	ajaxCall(currentPage);
	return true;
}

function setSessionLanguage(Idioma) {
	$.ajax({
				type:'GET',
				url: mainUrl + 'funciones/llamadas_ajax.php',
				data : 
				{ 	'accion' : 'session_language',
					'idioma': Idioma 
				},
				success: function(data) {
					return;
				}
	});
	return;
}

function resetMenu(Page) {
	$('#mainMenu a').css({'text-decoration':'none', 'color': '#ffffff'});
	if (Page == 'home') {
		$('#mainMenu a:eq(0)').css({'text-decoration':'underline', 'color': '#f34aa2'});
	}
	if (Page == 'services') {
		$('#mainMenu a:eq(1)').css({'text-decoration':'underline', 'color': '#f34aa2'});
	}
	if (Page == 'expertise') {
		$('#mainMenu a:eq(2)').css({'text-decoration':'underline', 'color': '#f34aa2'});
	}
	if (Page == 'portfolio') {
		$('#mainMenu a:eq(3)').css({'text-decoration':'underline', 'color': '#f34aa2'});
	}
	if (Page == 'standards') {
		$('#mainMenu a:eq(4)').css({'text-decoration':'underline', 'color': '#f34aa2'});
	}
	if (Page == 'blog') {
		$('#mainMenu a:eq(5)').css({'text-decoration':'underline', 'color': '#f34aa2'});
	}
	if (Page == 'contact') {
		$('#mainMenu a:eq(6)').css({'text-decoration':'underline', 'color': '#f34aa2'});
	}
	currentPage = Page;
	return true;
}

function resizeWindow() {
	var wHeight = $(window).height();
	var AccHeight = $("#accordion").height();
	if (wHeight >= 700) {
		if ((AccHeight + 300) < wHeight) {
			$('#footerContainer').css({'position':'absolute','bottom': '0px'});
		}
		else {
			$('#footerContainer').css({'position':'relative'});
		}
	}
	else {
		$('#footerContainer').css({'position':'relative'});
	}
	return true;
}

function submitMail(currentLanguage) {
	if (currentLanguage == 'es') {
		loadingMessage = 'Un momento por favor...';
	}
	else if (currentLanguage == 'nl') {
		loadingMessage = 'Een moment A.U.B...';
	}
	else {
		loadingMessage = 'Please Wait...';
	}
	if ($.active) {
		document.currentAjaxRequest.abort();
	}
	var tel = document.getElementById('tel').value;
	var name = document.getElementById('name').value;
	var email = document.getElementById('email').value;
	var msg = document.getElementById('msg').value;
	var code = document.getElementById('code').value;
	currentAjaxRequest = $.ajax({
				type:'POST',
				url: mainUrl + 'funciones/llamadas_ajax.php',
				data : 
				{ 	'gest_correo' : 'true',
					'idioma': currentLanguage,
					'name': name,
					'telephone': tel,
					'email': email,
					'mensaje': msg,
					'codigo': code
				},
				success: function(data) {
					$('#bodyContainer').html(data);
				}
	});
	return false;
}

function clearErrorMsg() {
	$('#error_msg_box').empty();
}

function setCaretPosition(ctrl, pos) {
	if(ctrl.setSelectionRange)
	{
		ctrl.focus();
		ctrl.setSelectionRange(pos,pos);
	}
	else if (ctrl.createTextRange) {
		var range = ctrl.createTextRange();
		range.collapse(true);
		range.moveEnd('character', pos);
		range.moveStart('character', pos);
		range.select();
	}
}



