<!--
if (/msie/i.test (navigator.userAgent)) //only override IE
{
  document.nativeGetElementById = document.getElementById; 
  document.getElementById = function(id)
  {
    var elem = document.nativeGetElementById(id);
    if(elem)
    {
      //make sure that it is a valid match on id
      if(elem.attributes['id'].value == id)
      {
        return elem;
      }
      else
      {
        //otherwise find the correct element
        for(var i=1;i<document.all[id].length;i++)
        {
          if(document.all[id][i].attributes['id'].value == id)
          {
            return document.all[id][i];
          }
        }
      }
    }
    return null;
  }
}


function findObject(idObject)
{
	if( document.getElementById(idObject) )
	{
		return document.getElementById(idObject);
	} else
		{
			return ZZ_findObjectP(idObject,null);
		}
	
}
function ZZ_findObjectP(n, d) {
  var p,i,x;  if(!d) d=document; if((p=n.indexOf("?"))>0&&parent.frames.length) {
    d=parent.frames[n.substring(p+1)].document; n=n.substring(0,p);}
  if(!(x=d[n])&&d.all) x=d.all[n]; for (i=0;!x&&i<d.forms.length;i++) x=d.forms[i][n];
  for(i=0;!x&&d.layers&&i<d.layers.length;i++) x=MM_findObj(n,d.layers[i].document);
  if(!x && d.getElementById) x=d.getElementById(n); return x;
}

//------------------------------------------------------------

// JavaScript Document
var xmlhttp;
function loadXMLDoc(url)
{
	xmlhttp=null;
	ret = null;
	
	if (window.XMLHttpRequest)
	{// code for Firefox, Opera, IE7, etc.
		xmlhttp=new XMLHttpRequest();
	}
	
	else if (window.ActiveXObject)
	{// code for IE6, IE5
		xmlhttp=new ActiveXObject("Microsoft.XMLHTTP");
	}
	
	if (xmlhttp!=null)
	{
		xmlhttp.onreadystatechange=state_Change;
		xmlhttp.open("GET",url,true);
		xmlhttp.send(null);
		
		ret = xmlhttp.responseText;
		
		alert('ret: ' + ret);
	}
	else
	{
		alert("Your browser does not support XMLHTTP.");
	}
	
	return ret;
}

function state_Change()
{
	if (xmlhttp.readyState==4)
	{// 4 = "loaded"
		if (xmlhttp.status==200)
		{// 200 = "OK"
			//document.getElementById('T1').innerHTML=xmlhttp.responseText;
			alert(xmlhttp.responseText);
			return xmlhttp;
		}
		else
		{
			alert("Problem retrieving data:" + xmlhttp.statusText);
		}
	}
}


var prv_func_name;



function state_ChangeFunct()
{
	if (xmlhttp.readyState==4)
	{// 4 = "loaded"
		if (xmlhttp.status==200)
		{// 200 = "OK"
			//document.getElementById('T1').innerHTML=xmlhttp.responseText;
			//alert(prv_func_name);
			//alert(xmlhttp.responseText);
			
			//return xmlhttp;
			strFunct = new String(prv_func_name);
			strFunct += '(';
			strFunct += ');';
						  
			return eval(strFunct);			  
						  
		}
		else
		{
			alert("Problemi nel recupero dati:" + xmlhttp.statusText);
		}
	}
}

function doAjaxRequest(url,functName)
{
	xmlhttp=null;
	prv_func_name = null;
	prov_func_params = null;
	
	if (window.XMLHttpRequest)
	{// code for Firefox, Opera, IE7, etc.
		xmlhttp=new XMLHttpRequest();
	}
	
	else if (window.ActiveXObject)
	{// code for IE6, IE5
		xmlhttp=new ActiveXObject("Microsoft.XMLHTTP");
	}
	
	if (xmlhttp!=null)
	{
		//alert(url);
		
		prv_func_name = functName;
		xmlhttp.onreadystatechange=state_ChangeFunct;
		
		xmlhttp.open("GET",url,true);
		xmlhttp.send(null);
		
	}
	else
	{
		alert("Il tuo browser non sembra supportare XMLHTTP. Impossibile completare la richiesta.");
	}
	
}

function getAjaxResponse()
{
	//alert('function getAjaxResponse');
	/*
	if(xmlhttp.responseXML)
	{
		var gValRisposta =xmlhttp.responseXML;
	} else
		{
			var gValRisposta = xmlhttp.responseText;
		}
		
	return gValRisposta;
	*/
	return xmlhttp.responseText;
}


function AJsendAutolettura()
{
	//var risposta = new String(getAjaxResponse());
	//alert(eval(risposta) );
	ris = getAjaxResponse();
	
	alert(ris);
}

function riempiStringaDaSxConZeri(totaleCifre,stringa)
{
	ret = '';
	num = totaleCifre - stringa.length;
	for(var i=0; i < num; i++)
	{
		ret += '0';
	}
	ret += stringa;
	return ret;
}

function prvReplaceApici(stringa)
{
	nValue = new String(stringa);	
	var lastValue = new String();
	//alert(nValue + ' ' + nValue.length);
	for(var l = 0; l <  nValue.length ; l++  )
	{
		pos = nValue.length-(nValue.length - l);
		c = nValue.substr(pos,1);
		//alert(l + ': ' + c);
		if ( c.search("'") == 0 )
		{
			c = "^^";
		} else
			{
				c = c.replace("'","^^");
			}
		lastValue += c;
	}
	return lastValue;
}

function prvReplaceA(stringa)
{
	nValue = new String(stringa);	
	var lastValue = new String();
	//alert(nValue + ' ' + nValue.length);
	for(var l = 0; l <  nValue.length ; l++  )
	{
		pos = nValue.length-(nValue.length - l);
		c = nValue.substr(pos,1);
		//alert(l + ': ' + c);
		if ( c.search("à") == 0 )
		{
			c = "a'";
		} else
			{
				c = c.replace("à","a'");
			}
		lastValue += c;
	}
	return lastValue;
}

function prvReplaceE(stringa)
{
	nValue = new String(stringa);	
	var lastValue = new String();
	//alert(nValue + ' ' + nValue.length);
	for(var l = 0; l <  nValue.length ; l++  )
	{
		pos = nValue.length-(nValue.length - l);
		c = nValue.substr(pos,1);
		//alert(l + ': ' + c);
		if ( c.search("è") == 0 )
		{
			c = "e'";
		} else
			{
				c = c.replace("è","e'");
			}
		lastValue += c;
	}
	return lastValue;
}

function prvReplaceEE(stringa)
{
	nValue = new String(stringa);	
	var lastValue = new String();
	//alert(nValue + ' ' + nValue.length);
	for(var l = 0; l <  nValue.length ; l++  )
	{
		pos = nValue.length-(nValue.length - l);
		c = nValue.substr(pos,1);
		//alert(l + ': ' + c);
		if ( c.search("é") == 0 )
		{
			c = "e'";
		} else
			{
				c = c.replace("é","e'");
			}
		lastValue += c;
	}
	return lastValue;
}

function prvReplaceI(stringa)
{
	nValue = new String(stringa);	
	var lastValue = new String();
	//alert(nValue + ' ' + nValue.length);
	for(var l = 0; l <  nValue.length ; l++  )
	{
		pos = nValue.length-(nValue.length - l);
		c = nValue.substr(pos,1);
		//alert(l + ': ' + c);
		if ( c.search("ì") == 0 )
		{
			c = "i'";
		} else
			{
				c = c.replace("ì","i'");
			}
		lastValue += c;
	}
	return lastValue;
}

function prvReplaceO(stringa)
{
	nValue = new String(stringa);	
	var lastValue = new String();
	//alert(nValue + ' ' + nValue.length);
	for(var l = 0; l <  nValue.length ; l++  )
	{
		pos = nValue.length-(nValue.length - l);
		c = nValue.substr(pos,1);
		//alert(l + ': ' + c);
		if ( c.search("ò") == 0 )
		{
			c = "o'";
		} else
			{
				c = c.replace("ò","o'");
			}
		lastValue += c;
	}
	return lastValue;
}



function prvReplaceU(stringa)
{
	nValue = new String(stringa);	
	var lastValue = new String();
	//alert(nValue + ' ' + nValue.length);
	for(var l = 0; l <  nValue.length ; l++  )
	{
		pos = nValue.length-(nValue.length - l);
		c = nValue.substr(pos,1);
		//alert(l + ': ' + c);
		if ( c.search("ù") == 0 )
		{
			c = "u'";
		} else
			{
				c = c.replace("ù","u'");
			}
		lastValue += c;
	}
	return lastValue;
}

function prvReplaceCaratteri(stringa)
{
	//var str = prvReplaceApici(stringa);
	var str = prvReplaceA(stringa);
	str = prvReplaceE(str);
	str = prvReplaceEE(str);
	str = prvReplaceI(str);
	str = prvReplaceO(str);
	str = prvReplaceU(str);
	
	return prvReplaceApici(str);
	
}



function sendAutolettura(azienda)
{
	var aUrl = '/AJIntesa/autolettura/autolettura.asp?az=';
	aUrl += azienda;
	
	//findObject(idObject)
	// var nomecontatto = document.getElementById('nomecontatto');
	
	 var nomecontatto = findObject('nomecontatto');
	 	aUrl += '&n=' + prvReplaceCaratteri(nomecontatto.value);
	 
	 //var cognomecontatto = document.getElementById('cognomecontatto');
	 var cognomecontatto = document.getElementById('cognomecontatto');
	 	aUrl += '&c=' + prvReplaceCaratteri(cognomecontatto.value);
	 
	// var mailcontatto = document.getElementById('mailcontatto');
	 var mailcontatto = findObject('mailcontatto');
	 	aUrl += '&ml=' + mailcontatto.value;
	 
	// var codice = document.getElementById('codice');
	 var codice = findObject('codice');
	 	var cdxD = riempiStringaDaSxConZeri(10,codice.value);
	 	aUrl += '&cod=' + cdxD;
	
	 //var matr = document.getElementById('matr');
	 var matr = findObject('matr');
	 	var matrxD = riempiStringaDaSxConZeri(18,matr.value);
	 	aUrl += '&matr=' + matrxD;
	 
	 //var lett = document.getElementById('lett');
	 var lett = findObject('lett');
	 	var lettxD = riempiStringaDaSxConZeri(10,lett.value);
	 	aUrl += '&lett=' + lettxD;
	 
	 //var ddata = document.getElementById('ddata');
	 var ddata = findObject('ddata');
	 var cDat = new String(ddata.value);
	 var arrD = cDat.split("/");
	 var strD = arrD[2] + arrD[1] + arrD[0];
	 	aUrl += '&dta=' + strD;
	
	var hdTipoCliente = findObject('hdTipoCliente');
	aUrl += '&TPC=' + prvReplaceCaratteri(nomecontatto.value);
		

	
	aUrl += '&send=yes';
	
	
	//alert(aUrl);
	
	aUrl = encodeURI(aUrl);
	
	
	var pattern = /^([a-zA-Z0-9_\.\-+])+@(([a-zA-Z0-9-])+\.)+([a-zA-Z0-9]{2,4})+$/;
	var re = new RegExp(pattern);

	//alert( re.test("paonath@gmail..com") );
	//alert( re.test("p.innocenti@vivatec.it") );
	if( re.test( mailcontatto.value ) )
	{
		doAjaxRequest(aUrl,'AJsendAutolettura');
	} else
		{
			alert("Inserire un indirizzo e-mail valido");
		}
}



 function attachAnEventToObject(ObjectReferenceSender,onEvnType,fnct)
 {
 	//alert('function attachAnEventToObject(ObjectReferenceSender=' + ObjectReferenceSender + ',onEvnType=' + onEvnType + ',fnct=' + fnct + ')');
 	if(ObjectReferenceSender.addEventListener)
 	{
 		//alert('addEventListener');
 		evnType = onEvnType.replace("on","");
 		ObjectReferenceSender.addEventListener(evnType,fnct,false);
 	} else
 		{
 			if(ObjectReferenceSender.attachEvent)
 			{
 				//alert('attachEvent');
 				ObjectReferenceSender.attachEvent(onEvnType,fnct);
 			}
 		}
 }

function AttachEventToIdObject(idSender,onEvnType,fnct)
{
	//alert(idSender + ': ' + findObject(idSender) );
	if( findObject(idSender) )
	{
		attachAnEventToObject(findObject(idSender),onEvnType,fnct)
	}
}
 
function pInnerHTML(refToElement,htmlReplacement)
{
    return BetterInnerHTML(refToElement,htmlReplacement,true);
}


// BetterInnerHTML v1.15 - by Craig Buckler, http://www.optimalworks.net/
// usage: BetterInnerHTML(element, HTML, clearfirst)
// element    - the DOM element where the HTML will be loaded
// HTML        - the string of valid HTML code
// clearfirst    - if false, existing child nodes of the element will be retained
function BetterInnerHTML(_1,_2,_3){function Load(_4){var _5;if(typeof DOMParser!="undefined"){_5=(new DOMParser()).parseFromString(_4,"application/xml");}else{var _6=["MSXML2.DOMDocument","MSXML.DOMDocument","Microsoft.XMLDOM"];for(var i=0;i<_6.length&&!_5;i++){try{_5=new ActiveXObject(_6[i]);_5.loadXML(_4);}catch(e){}}}return _5;}function Copy(_8,_9,_a){if(typeof _a=="undefined"){_a=1;}if(_a>1){if(_9.nodeType==1){var _b=document.createElement(_9.nodeName);for(var a=0,attr=_9.attributes.length;a<attr;a++){var _d=_9.attributes[a].name,aValue=_9.attributes[a].value,evt=(_d.substr(0,2)=="on");if(!evt){switch(_d){case "class":_b.className=aValue;break;case "for":_b.htmlFor=aValue;break;default:_b.setAttribute(_d,aValue);}}}_8=_8.appendChild(_b);if(evt){_8[_d]=function(){eval(aValue);};}}else{if(_9.nodeType==3){var _e=(_9.nodeValue?_9.nodeValue:"");var _f=_e.replace(/^\s*|\s*$/g,"");if(_f.length<7||(_f.indexOf("<!--")!=0&&_f.indexOf("-->")!=(_f.length-3))){_8.appendChild(document.createTextNode(_e));}}}}for(var i=0,j=_9.childNodes.length;i<j;i++){Copy(_8,_9.childNodes[i],_a+1);}}_2="<root>"+_2+"</root>";var _11=Load(_2);if(_1&&_11){if(_3!=false){while(_1.lastChild){_1.removeChild(_1.lastChild);}}Copy(_1,_11.documentElement);}}


function changeRdbTipoCliente(val)
{
	//alert('function changeRdbTipoCliente: ' + val );
	var lblnomecontatto = findObject('lblnomecontatto');
	//alert(lblnomecontatto);
	var lblcognomecontatto = findObject('lblcognomecontatto');
	//alert(lblcognomecontatto);
	
	var nomecontatto = findObject('nomecontatto');
	//var cognomecontatto = findObject('cognomecontatto');
	var hdTipoCliente = findObject('hdTipoCliente');
	
	
	
	var stringlblnomecontatto = '';
	var stringlblcognomecontatto = '';
	
	switch(val)
	{
		case 'privato': 
			stringlblnomecontatto = 'Nome: *';
			lblnomecontatto.style.display = 'inline';
			nomecontatto.style.display = 'inline';
			
			stringlblcognomecontatto = 'Cognome: *';
			break
		case 'azienda':
			stringlblnomecontatto = 'pppppp';
			lblnomecontatto.style.display = 'none';
			nomecontatto.style.display = 'none';
			
			
			stringlblcognomecontatto = 'Ragione Sociale: *';

			break
	}
	
	hdTipoCliente.value = val;
	
	pInnerHTML(lblnomecontatto,stringlblnomecontatto);
	pInnerHTML(lblcognomecontatto,stringlblcognomecontatto);

}

//-->
