//FORMULAIRE CONTACTO//
function doJump(menu) { 
    window.location = menu.options[menu.selectedIndex].value;
}

function checkdate(inputID,invalidDateFormat,invalidrange,mandatorymsg,mandatory){    
    var returnval="";
    var input = document.getElementById(inputID);    
    
    if (mandatory && input.value.length == 0) {
        return mandatorymsg;
    }
    
    
    if (input.value.length > 0) {    
        var validformat=/^\d{2}[\/\.]\d{2}[\/\.]\d{4}$/; //Basic check for format validity    
        
        if (!validformat.test(input.value))
            returnval = invalidDateFormat;
        else{ //Detailed check for valid date ranges
            
         var spv = input.value.split("/");
            if (spv.length < 2) {
                spv = input.value.split(".");
            }
        
        var dayfield=spv[0];
        var monthfield=spv[1];
        var yearfield=spv[2];
        var dayobj = new Date(yearfield, monthfield-1, dayfield);
        
        if ((dayobj.getMonth()+1!=monthfield)||(dayobj.getDate()!=dayfield)||(dayobj.getFullYear()!=yearfield))
            returnval=invalidrange;
        else
            returnval="";
        }
    } 
    
    return returnval
}


function validateMandatoryTextField(id,txtob,mandatory)
{
	var result = "";
	
	if (mandatory) {	    
	    var txt = document.getElementById(id).value;
	    var number = "";
		if(txt.length == 0)
			result = "- "+txtob+"\n"; 
	}
	
	/// add labels data to hidden field in case of error
	var oid_elem = document.getElementsByName('oid')[0];
	var oid_ = oid_elem.value;	
	if (oid_.indexOf('@') == -1) {
	
		for (I=0;I<=100;I++) {
		   try {
			 var lblName = "Label_"+I;
		   	 var lbl = document.getElementById(lblName);
		   	 if (lbl) {
			    var v_ = lbl.innerHTML;
                            oid_ = oid_+'@'+v_ ;
		   	 }
		   }
		   catch (err){
		   }
		}
	
	   oid_elem.value = oid_;
	}
	else oid_elem.value = oid_ + "error";

	return result;
}


function validateMail(mailStr)
{
    var emailPat = /^(.+)@(.+)$/;
    var specialChars = "\\(\\)<>@,;:\\\\\\\"\\.\\[\\]";
    var validChars = "\[^\\s" + specialChars + "\]";
    var quotedUser = "(\"[^\"]*\")";
    var ipDomainPat = /^\[(\d{1,3})\.(\d{1,3})\.(\d{1,3})\.(\d{1,3})\]$/;
    var atom = validChars + '+';
    var word = "(" + atom + "|" + quotedUser + ")";
    var userPat = new RegExp("^" + word + "(\\." + word + ")*$");
    var domainPat = new RegExp("^" + atom + "(\\." + atom +")*$");
    var matchArray = mailStr.match(emailPat);
    
    if (matchArray == null)
	    return false;
	    
    var user = matchArray[1];
    var domain = matchArray[2];

    if (user.match(userPat)==null)
        return false;

    var IPArray = domain.match(ipDomainPat);
    
    if (IPArray != null)
    {
	    for (var i = 1; i <= 4; i++)
	    {
	        if (IPArray[i] > 255)
		        return false;
	    }
    
        return true;
    }

    var domainArray = domain.match(domainPat);

    if (domainArray == null)
        return false;

    var atomPat = new RegExp(atom,"g");
    var domArr = domain.match(atomPat);
    var len = domArr.length;
    
    if (domArr[domArr.length-1].length < 2 || domArr[domArr.length-1].length > 6)
        return false;

    if (len < 2)
        return false

    return true;
}

function validateEmail(id,invdateerror,mandatorymsg,mandatory)
{
	var result = "";
	var txtMail = document.getElementById(id).value;
	
	if(txtMail.length == 0 && mandatory){
	   return result;
	}	
	else {
	    if((txtMail.indexOf(".") < 0) && (txtMail.indexOf("@") < 0)) //!validateMail(txtMail))  	    
		    result = "- "+invdateerror+"\n";
    }
								
	return result;
}

function validateCombos(id,txtob)
{
	var result = "";
	var cmb1 = document.getElementById(id);
	
	if(cmb1.selectedIndex == 0)
		result = "- "+txtob+"\n"; 
		
	return result;
}



function validateNumericField(id,txtob,mandatorymsg,mandatory)
{
	var result = true;
	var i = 0;
	var str = document.getElementById(id).value;	
	
	if(str.length == 0 && mandatory)
		return mandatorymsg;
	else if (str.length > 0)
	{
		str = str.replace(/ /g, "");		
		
		while(result && i < str.length)
		{
			result = (str.charAt(i) >= '0' && str.charAt(i) <= '9')
			i++;
		}		
	}
	else return "";
	
	//else return mandatorymsg;	
	
	if(result)
		return "";
	else
		return "- "+txtob+"\n";
}



function BrowserCheck() {
var b = navigator.appName;
if (b == "Netscape") this.b = "NS";
else if (b == "Microsoft Internet Explorer") this.b = "IE";
else this.b = b;
this.v = parseInt(navigator.appVersion);
this.NS = (this.b == "NS" && this.v>=4);
this.NS4 = (this.b == "NS" && this.v == 4);
this.NS5 = (this.b == "NS" && this.v == 5);
this.IE = (this.b == "IE" && this.v>=4);
this.IE4 = (navigator.userAgent.indexOf('MSIE 4')>0);
this.IE5 = (navigator.userAgent.indexOf('MSIE 5')>0);
if (this.IE5 || this.NS5) this.VER5 = true;
if (this.IE4 || this.NS4) this.VER4 = true;
this.OLD = (! this.VER5 && ! this.VER4) ? true : false;
this.min = (this.NS||this.IE);
}


function hideAlert(){
alertBox.visibility = "hidden";}


function makeAlert(aTitle,aMessage){
is = new BrowserCheck();
alertBox = (is.VER5) ? document.getElementById("alertLayer").style
: (is.NS) ? document.layers["alertLayer"]
: document.all["alertLayer"].style;

    document.all.alertLayer.innerHTML = "<table border=0 width=100% height=100%>" +
    "<tr height=5><td colspan=4 class=alertTitle>" + " " + aTitle + "</td></tr>" +
    "<tr height=5><td width=5></td></tr>" +
    "<tr><td width=5></td><td width=20 align=left><img src='alert.gif'></td><td align=center class=alertMessage>" + aMessage + "<BR></td><td width=5></td></tr>" + 
    "<tr height=5><td width=5></td></tr>" +
    "<tr><td width=5></td><td colspan=2 align=center><input type=button value='OK' onClick='hideAlert()' class=okButton><BR></td><td width=5></td></tr>" +
    "<tr height=5><td width=5></td></tr></table>";
    thisText = aMessage.length;
    if (aTitle.length > aMessage.length){ thisText = aTitle.length; }

    aWidth = (thisText * 5) + 80;
    aHeight = 100;
    if (aWidth < 150){ aWidth = 200; }
    if (aWidth > 350){ aWidth = 350; }
    if (thisText > 60){ aHeight = 110; }
    if (thisText > 120){ aHeight = 130; }
    if (thisText > 180){ aHeight = 150; }
    if (thisText > 240){ aHeight = 170; }
    if (thisText > 300){ aHeight = 190; }
    if (thisText > 360){ aHeight = 210; }
    if (thisText > 420){ aHeight = 230; }
    if (thisText > 490){ aHeight = 250; }
    if (thisText > 550){ aHeight = 270; }
    if (thisText > 610){ aHeight = 290; }

    alertBox.width = aWidth;
    alertBox.height = aHeight;
    alertBox.left = (document.body.clientWidth - aWidth)/2;
    alertBox.top = (document.body.clientHeight - aHeight)/2;

alertBox.visibility = "visible";
}