﻿
var ValidationErrorMessage = '';

function ValidateEmail(emailToValidate) {
    var RegexPattern = new RegExp("^([0-9a-zA-Z]+[-._+&amp;])*[0-9a-zA-Z]+@([-0-9a-zA-Z]+[.])+[a-zA-Z]{2,6}$");
    return RegexPattern.test(emailToValidate);
}
function ValidateEmptyValue(valueToValidate) {
    return (!valueToValidate || valueToValidate.length <= 0);
}

function EmptyValueClientValidate(source, clientside_arguments) {

    var ErrorMessageControl = document.getElementById('ValidatorErrorMessage');

    if (!clientside_arguments.Value || clientside_arguments.Value.length <= 0) {
        clientside_arguments.IsValid = false;
        if (ErrorMessageControl) {ErrorMessageControl.style.display = 'block';}
    }
    else {
        clientside_arguments.IsValid = true
        if (ErrorMessageControl) { ErrorMessageControl.style.display = 'none'; }
    };
}

function EmailClientValidate(source, clientside_arguments) {
    var RegexPattern = new RegExp("^([0-9a-zA-Z]+[-._+&amp;])*[0-9a-zA-Z]+@([-0-9a-zA-Z]+[.])+[a-zA-Z]{2,6}$");
    if (RegexPattern.test(clientside_arguments.Value)) {
        clientside_arguments.IsValid = true;
        if (ErrorMessageControl) { ErrorMessageControl.style.display = 'block'; }
    }
    else {
        clientside_arguments.IsValid = true
        if (ErrorMessageControl) { ErrorMessageControl.style.display = 'none'; }
    };
}


function setElementVisible(ID)
{
    var element = document.getElementById(ID);
    if (element.style.display == 'inline' || element.style.display == 'block')
        element.style.display = 'none';
    else
        element.style.display = 'inline';
}


function initializeGMap(longitud, latitud) 
{      
    // Per aconseguir la longitus i la latitud, es a dir les coordenades
    // es busca la direcció mitjançant la web i quan es té tot correcte
    // es fot copy paste a la barra de direccions del codi següent:
    // javascript:void(prompt('',gApplication.getMap().getCenter()));
    //alert('hau!');
    if (GBrowserIsCompatible()) {        
        var map = new GMap2(document.getElementById("map_canvas"));

        //new GLatLng(41.602334543439774, 2.2952628135681152)
        map.setCenter(new GLatLng(longitud, latitud), 13);      
        map.setZoom(50);
        map.addControl(new GSmallMapControl());
        map.addControl(new GMapTypeControl());
        var latlng = new GLatLng(longitud, latitud);
        map.addOverlay(new GMarker(latlng));                
    }    
}    

