$(document).ready(
	function()
	{
	    
        $("a.tomail").each (
            function () {
                var dest = this.rel.replace ("%%", "@");
                this.href = "mailto: " + dest;
                $(this).text(dest);
            }
        );

		// set up rollover
		$("img.rollover").hover(
			function()
			{
				this.src = this.src.replace("_off","_on");
			},
			function()
			{
				this.src = this.src.replace("_on","_off");
			}
		);
	}
);

var hayprovincias=0;
var en1 = 0;
var en2 = 0;
var en3 = 0;
var en4 = 0;

$(document).ready(function(){

// Languages

	$("a#lang_trigger").mouseover(function () {
		$("div#languages").fadeIn("slow");
	});
	$("div#languages").click(function () {
		$("div#languages").fadeOut("slow");
	});


//	Company

	$("a#com_trigger").mouseover(function () {
		$("div.subcom").fadeIn("slow");
		$("div.subsec").fadeOut("slow");
		$("div.subsol").fadeOut("slow");
		$("div.subpar").fadeOut("slow");
	});
	$("div.subcom a").mouseout(function() {
		$("div.subcom").hover(function () {
		}, function () {
			$("div.subcom").fadeOut("slow");
		});
	});


//	Section

	$("a#sec_trigger").mouseover(function () {
		$("div.subsec").fadeIn("slow");
		$("div.subcom").fadeOut("slow");
		$("div.subsol").fadeOut("slow");
		$("div.subpar").fadeOut("slow");
	});
	$("div.subsec a").mouseout(function() {
		$("div.subsec").hover(function () {
		}, function () {
			$("div.subsec").fadeOut("slow");
		});
	});
	
	
// Solutions

	$("a#sol_trigger").mouseover(function () {
		$("div.subsol").fadeIn("slow");
		$("div.subsec").fadeOut("slow");
		$("div.subcom").fadeOut("slow");
		$("div.subpar").fadeOut("slow");
	});
	$("div.subsol a").mouseout(function() {
		$("div.subsol").hover(function () {
		}, function () {
			$("div.subsol").fadeOut("slow");
		});
	});
		

// Partners

	$("a#par_trigger").mouseover(function () {
		$("div.subpar").fadeIn("slow");
		$("div.subsec").fadeOut("slow");
		$("div.subsol").fadeOut("slow");
		$("div.subcom").fadeOut("slow");
	});
	$("div.subpar a").mouseout(function() {
		$("div.subpar").hover(function () {
		}, function () {
			$("div.subpar").fadeOut("slow");
		});
	});
	
//	Company

	$("a#com_trigger_en").mouseover(function () {
		$("div.ensubcom").fadeIn("slow");
		$("div.ensubsec").fadeOut("slow");
		$("div.ensubsol").fadeOut("slow");
		$("div.ensubpar").fadeOut("slow");
		$("div.ensubnew").fadeOut("slow");
	});
	$("div.ensubcom a").mouseout(function() {
		$("div.ensubcom").hover(function () {
		}, function () {
			$("div.ensubcom").fadeOut("slow");
		});
	});


//	Products

	$("a#sec_trigger_en").mouseover(function () {
		$("div.ensubsec").fadeIn("slow");
		$("div.ensubcom").fadeOut("slow");
		$("div.ensubsol").fadeOut("slow");
		$("div.ensubpar").fadeOut("slow");
		$("div.ensubnew").fadeOut("slow");
	});
	$("div.ensubsec a").mouseout(function() {
		$("div.ensubsec").hover(function () {
		}, function () {
			$("div.ensubsec").fadeOut("slow");
		});
	});
	
	
// Solutions

	$("a#sol_trigger_en").mouseover(function () {
		$("div.ensubsol").fadeIn("slow");
		$("div.ensubsec").fadeOut("slow");
		$("div.ensubcom").fadeOut("slow");
		$("div.ensubpar").fadeOut("slow");
		$("div.ensubnew").fadeOut("slow");
	});
	$("div.ensubsol a").mouseout(function() {
		$("div.ensubsol").hover(function () {
		}, function () {
			$("div.ensubsol").fadeOut("slow");
		});
	});
		

// Customers

	$("a#par_trigger_en").mouseover(function () {
		$("div.ensubpar").fadeIn("slow");
		$("div.ensubsec").fadeOut("slow");
		$("div.ensubsol").fadeOut("slow");
		$("div.ensubcom").fadeOut("slow");
		$("div.ensubnew").fadeOut("slow");
	});
	$("div.ensubpar a").mouseout(function() {
		$("div.ensubpar").hover(function () {
		}, function () {
			$("div.ensubpar").fadeOut("slow");
		});
	});
			

// News & Events

	$("a#new_trigger_en").mouseover(function () {
		$("div.ensubpar").fadeOut("slow");
		$("div.ensubsec").fadeOut("slow");
		$("div.ensubsol").fadeOut("slow");
		$("div.ensubcom").fadeOut("slow");
		$("div.ensubnew").fadeIn("slow");
	});
	$("div.ensubnew a").mouseout(function() {
		$("div.ensubnew").hover(function () {
		}, function () {
			$("div.ensubnew").fadeOut("slow");
		});
	});
	
});

var err_txt				= new Array ();
var err_company			= new Array ();
var err_country			= new Array ();
var err_province		= new Array ();
var err_city			= new Array ();
var err_contact			= new Array ();
var err_phone			= new Array ();
var err_email			= new Array ();
var err_contribution	= new Array ();
var err_firstname		= new Array ();
var err_lastname		= new Array ();
var err_title			= new Array ();

err_txt[1]			= "Por favor, rellene lo siguiente:";
err_txt[2]			= "Please, fill in:";
err_txt[3]			= "Veuillez remplir le formulaire suivant:";
err_txt[4]			= "Por favor, preencha as informa&ccedil;&otilde;es:";
err_company[1]		= "Compa&ntilde;&iacute;a";
err_company[2]		= "Company";
err_company[3]		= "Entreprise";
err_company[4]		= "Companhia";
err_country[1]		= "Pa&iacute;s";
err_country[2]		= "Country";
err_country[3]		= "Pays";
err_country[4]      = "Pa&iacute;s";
err_province[1]		= "Provincia";
err_province[2]		= "State";
err_province[3]		= "R&eacute;gions";
err_province[4]     = "Estado";
err_city[1]			= "Ciudad";
err_city[2]			= "City";
err_city[3]			= "Ville";
err_city[4]         = "Cidade";
err_contact[1]		= "Contacto";
err_contact[2]		= "Person to Contact";
err_contact[3]		= "Contact";
err_contact[4]      = "Contato";
err_phone[1]		= "Tel&eacute;fono";
err_phone[2]		= "Telephone";
err_phone[3]		= "T&eacute;l&eacute;phone";
err_phone[4]        = "Telefone";
err_email[1]		= "Email";
err_email[2]		= "E-mail";
err_email[3]		= "Courriel";
err_email[4]        = "E-mail";
err_contribution[1]	= "Introduzca por favor la Dirección de la página web";
err_contribution[2]	= "Please, fill in the field Web page address";
err_contribution[3]	= "Veuillez, remplir le champ Adresse du site web";
err_contribution[4] = "Introduza o endere&ccedil;o do site";
err_firstname[1]	= "Name";
err_firstname[2]	= "Name";
err_firstname[3]	= "Name";
err_firstname[4]	= "Name";
err_lastname[1]		= "Last Name";
err_lastname[2]		= "Last Name";
err_lastname[3]		= "Last Name";
err_lastname[4]		= "Last Name";
err_title[1]		= "T&iacute;tulo";
err_title[2]		= "Title";
err_title[3]		= "Title";
err_title[4]		= "Title";


var expEmail = /^([a-zA-Z0-9])+([.a-zA-Z0-9_-])*@([a-zA-Z0-9_-])+(.[a-zA-Z0-9_-]+)+/;
var expNumbers = /^([0-9])+/;
var expOthers = /^([a-zA-Z0-9])+/;
var idlan = 1;
var divi;

divi = location.href.split ('/en-us/');
if (divi.length > 1)	idlan = 2;
divi = location.href.split ('/en-gb/');
if (divi.length > 1)	idlan = 2;
divi = location.href.split ('/fr/');
if (divi.length > 1)	idlan = 3;
divi = location.href.split ('/pt-br/');
if (divi.length > 1)	idlan = 4;
divi = location.href.split ('/it/');
if (divi.length > 1)	idlan = 5;
divi = location.href.split ('/de/');
if (divi.length > 1)	idlan = 6;

function checkForm (theForm, theField, objRegex) {

	objField = eval("document.getElementById('" + theForm + "')." + theField);
	if (!objRegex.test (objField.value)) {
		return false;
	}
	return true;
}

function checkcontact (theForm) {
	var txterrors = '';
	var idForm = theForm.id;
	
	document.getElementById(idForm).country.value = document.getElementById(idForm).countrysel[document.getElementById(idForm).countrysel.selectedIndex].text;
	if (hayprovincias)	document.getElementById(idForm).province.value = document.getElementById(idForm).provincesel[document.getElementById(idForm).provincesel.selectedIndex].text;
	
	if (!checkForm (idForm, 'company', expOthers))						txterrors = txterrors + err_company[idlan] + '<br />';
	if (!checkForm (idForm, 'country', expOthers))						txterrors = txterrors + err_country[idlan] + '<br />';
/*	if (hayprovincias && !checkForm (idForm, 'province', expOthers))	txterrors = txterrors + err_province[idlan] + '<br />';*/
	if (!checkForm (idForm, 'city', expOthers))							txterrors = txterrors + err_city[idlan] + '<br />';
	if (!checkForm (idForm, 'contact', expOthers))						txterrors = txterrors + err_contact[idlan] + '<br />';
	if (!checkForm (idForm, 'phone', expNumbers))						txterrors = txterrors + err_phone[idlan] + '<br />';
	if (!checkForm (idForm, 'email', expEmail))							txterrors = txterrors + err_email[idlan] + '<br />';
	
	if (txterrors != '') {
		document.getElementById ('formerrors').style.display = 'block';
		document.getElementById ('formerrors').innerHTML = err_txt[idlan] + '<br />' + txterrors;
		return false;
	}
	
	return true;
}

function checkcontactnew (theForm) {
	var txterrors = '';
	var idForm = theForm.id;
	

document.getElementById(idForm).Cpais.value=document.getElementById(idForm).pais[document.getElementById(idForm).pais.selectedIndex].value;
document.getElementById(idForm).indexpais.value=document.getElementById(idForm).pais.selectedIndex;
document.getElementById(idForm).selpais.value=document.getElementById(idForm).pais[document.getElementById(idForm).pais.selectedIndex].text;
//alert(document.getElementById(idForm).hayprov.value);
//alert(document.getElementById(idForm).Cpais.value);
//	document.getElementById(idForm).Cpais.value = document.getElementById(idForm).pais[document.getElementById(idForm).pais.selectedIndex].text;
	if (document.getElementById(idForm).hayprov.value==1)
	{
	document.getElementById(idForm).selprovincia.value=document.getElementById(idForm).provincia[document.getElementById(idForm).provincia.selectedIndex].text;
	document.getElementById(idForm).Cprovincia.value=document.getElementById(idForm).provincia[document.getElementById(idForm).provincia.selectedIndex].value;
	//alert(document.getElementById(idForm).Cprovincia.value);
	document.getElementById(idForm).indexprovincia.value=document.getElementById(idForm).provincia.selectedIndex;
	}
	
	if (!checkForm (idForm, 'company', expOthers))						txterrors = txterrors + err_company[idlan] + '<br />';
	if (!checkForm (idForm, 'Cpais', expOthers))						txterrors = txterrors + err_country[idlan] + '<br />';
	if (document.getElementById(idForm).hayprov.value == 1 && document.getElementById(idForm).Cprovincia.value==0)	txterrors = txterrors + err_province[idlan] + '<br />';
	if (!checkForm (idForm, 'city', expOthers))							txterrors = txterrors + err_city[idlan] + '<br />';
	if (!checkForm (idForm, 'contact', expOthers))						txterrors = txterrors + err_contact[idlan] + '<br />';
	if (!checkForm (idForm, 'phone', expNumbers))						txterrors = txterrors + err_phone[idlan] + '<br />';
	if (!checkForm (idForm, 'email', expEmail))							txterrors = txterrors + err_email[idlan] + '<br />';
	
	if (txterrors != '') {
		document.getElementById ('formerrors').style.display = 'block';
		document.getElementById ('formerrors').innerHTML = err_txt[idlan] + '<br />' + txterrors;
		return false;
	}
	
	return true;
}

function checkcontactgartner (theForm) {
	var txterrors = '';
	var idForm = theForm.id;
	

document.getElementById(idForm).Cpais.value=document.getElementById(idForm).pais[document.getElementById(idForm).pais.selectedIndex].value;
document.getElementById(idForm).indexpais.value=document.getElementById(idForm).pais.selectedIndex;
document.getElementById(idForm).selpais.value=document.getElementById(idForm).pais[document.getElementById(idForm).pais.selectedIndex].text;
//alert(document.getElementById(idForm).hayprov.value);
//alert(document.getElementById(idForm).Cpais.value);
//	document.getElementById(idForm).Cpais.value = document.getElementById(idForm).pais[document.getElementById(idForm).pais.selectedIndex].text;
	if (document.getElementById(idForm).hayprov.value==1)
	{
	document.getElementById(idForm).selprovincia.value=document.getElementById(idForm).provincia[document.getElementById(idForm).provincia.selectedIndex].text;
	document.getElementById(idForm).Cprovincia.value=document.getElementById(idForm).provincia[document.getElementById(idForm).provincia.selectedIndex].value;
	//alert(document.getElementById(idForm).Cprovincia.value);
	document.getElementById(idForm).indexprovincia.value=document.getElementById(idForm).provincia.selectedIndex;
	}
	
	if (!checkForm (idForm, 'company', expOthers))						txterrors = txterrors + err_company[idlan] + '<br />';
	if (!checkForm (idForm, 'Cpais', expOthers))						txterrors = txterrors + err_country[idlan] + '<br />';
	if (document.getElementById(idForm).hayprov.value == 1 && document.getElementById(idForm).Cprovincia.value==0)	txterrors = txterrors + err_province[idlan] + '<br />';
	//if (!checkForm (idForm, 'city', expOthers))							txterrors = txterrors + err_city[idlan] + '<br />';
	if (!checkForm (idForm, 'contact', expOthers))						txterrors = txterrors + err_contact[idlan] + '<br />';
	if (!checkForm (idForm, 'phone', expNumbers))						txterrors = txterrors + err_phone[idlan] + '<br />';
	if (!checkForm (idForm, 'email', expEmail))							txterrors = txterrors + err_email[idlan] + '<br />';
	
	if (txterrors != '') {
		document.getElementById ('formerrors').style.display = 'block';
		document.getElementById ('formerrors').innerHTML = err_txt[idlan] + '<br />' + txterrors;
		return false;
	}
	
	return true;
}


function checkwebinars (theForm) {
	var txterrors = '';
	var idForm = theForm.id;
	
	document.getElementById(idForm).province.value = document.getElementById(idForm).provincesel[document.getElementById(idForm).provincesel.selectedIndex].text;

	if (!checkForm (idForm, 'firstname', expOthers))					txterrors = txterrors + err_firstname[idlan] + '<br />';
	if (!checkForm (idForm, 'lastname', expOthers))						txterrors = txterrors + err_lastname[idlan] + '<br />';
	if (!checkForm (idForm, 'title', expOthers))						txterrors = txterrors + err_title[idlan] + '<br />';
	if (!checkForm (idForm, 'company', expOthers))						txterrors = txterrors + err_company[idlan] + '<br />';
	if (!checkForm (idForm, 'city', expOthers))							txterrors = txterrors + err_city[idlan] + '<br />';
	if (!checkForm (idForm, 'email', expEmail))						txterrors = txterrors + err_email[idlan] + '<br />';
	if (!checkForm (idForm, 'phone', expOthers))						txterrors = txterrors + err_phone[idlan] + '<br />';
	
	if (txterrors != '') {
		document.getElementById ('formerrors').style.display = 'block';
		document.getElementById ('formerrors').innerHTML = err_txt[idlan] + '<br />' + txterrors;
		return false;
	}
	
	return true;
}

function checksearch (theForm) {
	var txterrors = '';
	var idForm = theForm.id;
	
	document.getElementById(idForm).country.value = document.getElementById(idForm).countrysel[document.getElementById(idForm).countrysel.selectedIndex].text;
	if (hayprovincias)	document.getElementById(idForm).province.value = document.getElementById(idForm).provincesel[document.getElementById(idForm).provincesel.selectedIndex].text;
	
	if (!checkForm (idForm, 'country', expOthers))						txterrors = txterrors + err_country[idlan] + '<br />';
	
	if (txterrors != '') {
		document.getElementById ('formerrors').style.display = 'block';
		document.getElementById ('formerrors').innerHTML = err_txt[idlan] + '<br />' + txterrors;
		return false;
	}
	
	return true;
}


function checksearchnew (theForm) {
	var txterrors = '';
	var idForm = theForm.id;
	
document.getElementById(idForm).Cpais.value=document.getElementById(idForm).pais[document.getElementById(idForm).pais.selectedIndex].value;
document.getElementById(idForm).indexpais.value=document.getElementById(idForm).pais.selectedIndex;
document.getElementById(idForm).selpais.value=document.getElementById(idForm).pais[document.getElementById(idForm).pais.selectedIndex].text;
//alert(document.getElementById(idForm).hayprov.value);
//alert(document.getElementById(idForm).Cpais.value);
//	document.getElementById(idForm).Cpais.value = document.getElementById(idForm).pais[document.getElementById(idForm).pais.selectedIndex].text;
	if (document.getElementById(idForm).hayprov.value==1)
	{
	document.getElementById(idForm).selprovincia.value=document.getElementById(idForm).provincia[document.getElementById(idForm).provincia.selectedIndex].text;
	document.getElementById(idForm).Cprovincia.value=document.getElementById(idForm).provincia[document.getElementById(idForm).provincia.selectedIndex].value;
	//alert(document.getElementById(idForm).Cprovincia.value);
	document.getElementById(idForm).indexprovincia.value=document.getElementById(idForm).provincia.selectedIndex;
	}
	
	return true;
}

function Validator(theForm) {
	if (theForm.URL.value == "http://" || theForm.URL.value == "") {
		alert (err_contribution[idlan]);
		theForm.URL.focus();
		return (false);
	}
}

function fnVolver() {
	if(navigator.appName=='Microsoft Internet Explorer') {
		history.back();
		history.back();
		history.back();
	} else
		top.history.go(-2);
}

function toogleCheckAll (sId) {
	var eContainer = document.getElementById (sId);
	var aInputs = eContainer.getElementsByTagName ("input");
	
	for (var i = 1; i < aInputs.length; i++)
		aInputs[i].checked = aInputs[0].checked;
}

function change_prov (idForm) {
	var dividir1;
	var dividir2;
	var dividir3;
	
	document.getElementById (idForm).provincesel.options.length = 0;
	hayprovincias = 0;
	dividir1 = asProvincias.split ('?');
	for (i = 0; i < dividir1.length; i++) {
		dividir2 = dividir1[i].split (',');
		dividir3 = dividir2[1].split ('#');
		if (dividir3[0] == document.getElementById (idForm).countrysel.value) {
			hayprovincias = 1;
			break;
		}
	}
	
	if (hayprovincias) {
		document.getElementById (idForm).provincesel.disable = false;
		var oOption = document.createElement('option');
		document.getElementById (idForm).provincesel.options.add (oOption);
		oOption.text = '';
		oOption.value = '0';
		oOption.selected = true;
		dividir1 = asProvincias.split ('?');
	
		for (i = 0; i < dividir1.length; i++) {
			dividir2 = dividir1[i].split (',');
			dividir3 = dividir2[1].split ('#');
			if (dividir3[0] == document.getElementById (idForm).countrysel.value) {
				var oOption = document.createElement ('option');
				document.getElementById (idForm).provincesel.options.add (oOption);					
				oOption.text = dividir2[0];
				oOption.value = dividir3[1];		
			}
		}
		document.getElementById (idForm).hayprov.value = 1;
	} else {
		document.getElementById (idForm).provincesel.disable = true;
		document.getElementById (idForm).hayprov.value = 0;
	}
}

function sended (lan) {
	switch (lan) {
		case 1:
			alert ('Su solicitud se ha cursado con exito. En breve nos pondremos en contacto con usted.');
		break;
		case 2:
			alert ('Your request has been processed correctly. We will be contacting you soon.');
		break;
		case 3:
			alert ('Votre requ&ecirc;te a &eacute;t&eacute; trait&eacute;e avec succ&egrave;s. Nous vous contacterons rapidement.');
		break;
		case 4:
		    alert ('Sua solicita&ccedil;&atilde;o foi enviada com sucesso. Em breve entraremos em contato.');
		break;
	}
}

function send_form (theForm, idpage) {
	document.getElementById (theForm).page.value = idpage;
	document.getElementById (theForm).submit ();
}

function toggleLanguages (what, valor) {
	document.getElementById (what).value = valor;
	document.getElementById ('change_language').submit ();
}

function send_preview (idNew, what, cant, idLang) {
  
   switch (idLang) {
        case '2':
            var dest = 'en-gb/';
        break;
        case '3':
            var dest = 'fr/';
        break;
        case '4':
            var dest = 'pt-br/';
        break;
        case '5':
            var dest = 'it/';
        break;
        case '6':
            var dest = 'de/';
        break;
        case '7':
            var dest = 'en-us/';
        break;
        default:
            var dest = 'es/';
    }
	
    if (what == 'new') {
        dest = dest + 'new';
    } 
	else if(what == 'index') {
        dest = dest + 'indexnews';
    } 
	else {
        dest = dest + 'event';
    }
    if (cant == 1) {
        dest = dest + '.asp';
    } else {
        dest = dest + 's.asp';
    }
    document.getElementById ('preview').action = "../../" +dest + '?id=' + idNew;
    document.getElementById ('preview').submit ();
}