 // Move an element directly on top of another element (and optionally
// make it the same size)
function Cover(bottom, top, ignoreSize) {
    var location = Sys.UI.DomElement.getLocation(bottom);
    top.style.position = 'absolute';
    top.style.top = location.y + 'px';
    top.style.left = location.x + 'px';
    if (!ignoreSize) {
        top.style.height = bottom.offsetHeight + 'px';
        top.style.width = bottom.offsetWidth + 'px';
    }
}

function changeColor(fieldID, event, myColor){
	//alert("document.forms['" + formName + "']." + formField + ".style.backgroundColor='#75A1D0'");
	//window.status=formName + '-' + formField  + '-' +  event + '-' +  myColor;
	if(event=='ERROR'){
		if(myColor!=''){
			document.getElementById(fieldID).style.backgroundColor=myColor;	
		}
		else{
			document.getElementById(fieldID).style.backgroundColor='#75A1D0';
		}
	}
	else{
		document.getElementById(fieldID).style.backgroundColor='#FFFFFF';
	}
}

/*
 *seleziona tutti i checkBox
 */

function all_check(formName, fieldName, boolCheck){

	try{
		var i;
		with(eval("document.forms['" + formName + "']")){
			if(eval("elements." + fieldName + ".length")==undefined){
				eval(fieldName+".checked=boolCheck");
			}
			else{
				for(i=0;i<eval("elements." + fieldName + ".length");i++){
					eval(fieldName+"[i].checked=boolCheck");
				}
			}
		}
	}
	catch(e){
	}
}


/*
inserisce il valore dal pop-up al campo della pagina
*/
function inserisci(valore, campo, nomeForm){	
	eval("window.opener.document.forms['" + nomeForm + "']." + campo + ".value='" + valore + "'");
}


/*
apre popup generico
*/

function newPopUp(newurl,newname,param) {
	apopup = window.open(newurl,newname,param);
	apopup.focus();
}

function openUpload(campo,formName){
	//alert(formName);
	var sLink = "/upload.asp?campo=" + campo + "&formName=" + formName;
	newPopUp(sLink ,'popUpUpload','toolbar=no,  location=no,directories=no,status=no,scrollbars=yes,resizable=no,copyhistory=no,width=510,height=420');

}


function openRicerca(pagina,campo,formName){
	var sLink = "/Cerca/" + pagina + "?campo=" + campo + "&formName=" + formName;
	var a = newPopUp(sLink ,'popUpRicerca','toolbar=no,  location=no,directories=no,status=no,scrollbars=yes,resizable=no,copyhistory=no,width=400,height=300');
}

function f_UTENTI(id){
	//alert(id.replace(':', ''));
	id = id.replace(':', '_');
	id = id.replace(':', '');
	id = id.replace('insertID', '');
	//alert(id);
	var doppioUnderscore = id.indexOf("__")+2;
	var ctlTemp = id.substring(doppioUnderscore,id.length);
	//alert(ctlTemp);
	var singoloUnderscore = ctlTemp.indexOf("_");
	var ctl = id.substring(0,singoloUnderscore+doppioUnderscore);
	//alert(ctl);
	var myID=id;
	if(ctl.length>6)
		myID = ctl;
	
	var tipoTxt = getDDLtext(myID + '_ID_TIPOUTENTE_c_Id_TipoUtente');
	var socioValue = getDDLvalue(myID + '_ID_SOCIO_c_Id_Socio');
	var installatoreValue = getDDLvalue(myID + '_ID_INSTALLATORE_c_Id_Installatore');
	var agenteValue = getDDLvalue(myID + '_ID_AGENTE_c_Id_Agente');

//	alert(tipoTxt);
//	alert(socioValue);
	switch(tipoTxt){
		case "M"://manager
			if(socioValue>0 || installatoreValue>0 || agenteValue>0){
				alert("Il Tipo Utente [M] non puņ avere \n utenti associati");
				return false;
			}
			break;
		case "I"://installatore
			if(socioValue>0 || agenteValue>0){
				alert("Il Tipo Utente [I] puņ avere soltanto il Cliente associato");
				return false;
			}
			else{
				if(installatoreValue==""){
				alert("Il Tipo Utente [I] deve avere il Cliente associato");
				return false;
				}
			}
			break;
		case "C"://cliente
			if(socioValue>0 || agenteValue>0){
				alert("Il Tipo Utente [C] puņ avere soltanto il Cliente associato");
				return false;
			}
			else{
				if(installatoreValue==""){
				alert("Il Tipo Utente [C] deve avere il Cliente associato");
				return false;
				}
			}
			break;
		case "A"://agente
			if(socioValue>0 || installatoreValue>0){
				alert("Il Tipo Utente [A] puņ avere soltanto l'Agente associato");
				return false;
			}
			else{
				if(agenteValue==""){
				alert("Il Tipo Utente [A] deve avere l'Agente associato");
				return false;
				}
			}
			break;
		case "S"://socio
			if(installatoreValue>0 || agenteValue>0){
				alert("Il Tipo Utente [S] puņ avere soltanto il Socio associato");
				return false;
			}
			else{
				if(socioValue==""){
				alert("Il Tipo Utente [S] deve avere il Socio associato");
				return false;
				}
			}
			break;
	}
	if (typeof(Page_ClientValidate) == 'function') Page_ClientValidate();
}

function getDDLvalue(id){
	var ddl=document.getElementById(id);
	return ddl.value;
}
function getDDLindex(id){
	var ddl=document.getElementById(id);
	return ddl.selectedIndex;
}
function getDDLtext(id){
	//alert(id);
	var ddl=document.getElementById(id);
	return ddl.options[ddl.selectedIndex].text;
}

function deleteConfirm(){
	return confirm("Sei sicuro di eliminare i dati selezionati?");
}


function deleteRigheOrdine(){
	var myCont=0;
	
	with(eval("document.forms[0]")){
		for(var i=0;i<length;i++){
			if(elements[i].type=="checkbox")
				if(elements[i].checked){
					myCont++;
					break;
				}
		}
	}
	if(myCont>0)
		return confirm("Sei sicuro di eliminare le righe selezionate?");
	
	return false;
}

function oneCheckOnly(sText){
	var myCont=0;
	
	with(eval("document.forms[0]")){
		for(var i=0;i<length;i++){
			if(elements[i].type=="checkbox")
				if(elements[i].checked){
					myCont++;
				}
		}
	}
	if(myCont>1){
		alert(sText);
		return false;		
	}
	if(myCont==0){
		return false;		
	}
	return true;
}

function navigaPager(qryString){
	document.location.href=qryString
}
function autoComplete (field, select, property, forcematch) {
	var found = false;
	
	if(field.value.length<3){
		if(select.options.length==ragsoc.length+1)
			return;
		
		while (select.options.length >0)
				select.options[0]=null;
		
		select.options[0]=new Option('---','');
		for (var i = 0; i < ragsoc.length; i++) {
			select.options[select.options.length]=new Option(ragsoc[i],sigla[i]);
		}
	}
	else{ 
		while (select.options.length >0)
				select.options[0]=null;
		
		
		var nFind=0;
		for (var i = 0; i < ragsoc.length; i++) {
			if (ragsoc[i].toUpperCase().indexOf(field.value.toUpperCase()) >= 0) {
				nFind++;			
				select.options[nFind]=new Option(ragsoc[i],sigla[i]);
			}
		}
		select.options[0]=new Option(nFind + ' risultati','');
		select.selectedIndex = 0;

	}
	
	//if (found) { select.selectedIndex = i; }
	//else { select.selectedIndex = -1; }
	/*
	if (field.createTextRange) {
		if (forcematch && !found) {
			field.value=field.value.substring(0,field.value.length-1); 
			return;
		}
		var cursorKeys ="8;46;37;38;39;40;33;34;35;36;45;";
		if (cursorKeys.indexOf(event.keyCode+";") == -1) {
			var r1 = field.createTextRange();
			var oldValue = r1.text;
			var newValue = found ? select.options[i][property] : oldValue;
			if (newValue != field.value) {
				//field.value = newValue;
				var rNew = field.createTextRange();
				rNew.moveStart('character', oldValue.length) ;
				rNew.select();
				
				for (var i = 0; i < ragsoc.length; i++) {
					if (ragsoc[i].toUpperCase().indexOf(field.value.toUpperCase()) >= 0) {
						options[0]=null;
					}
				}
			}
		}
		
	}
	*/
}


function showHideTbody(idDiv,ddlValue){
  var rowDisplay = ( (ddlValue == "DDL" || ddlValue == "3") ? "block" : "none" ); 
  var oCategoryTBody = document.getElementById(idDiv); 
  if (oCategoryTBody) 
     oCategoryTBody.style.display = rowDisplay; 
}

function showHideTbodyByArray(){
    try{
        for(var i=0;i<ddlCType.length;i++)
            showHideTbody(TbodyID[i],document.getElementById(ddlCType[i]).value);
    }
    catch(e){}
}

function showHideDiv(_div){
    var _Display = ((document.getElementById(_div).style.display=="block") ? "none" : "block"); 
    document.getElementById(_div).style.display = _Display; 
}
/*
* MODAL POPUP
*/
function checkCarrelloModal(sender) {
    
    if(!ValidatorCommonOnSubmit()) {
        document.getElementById('innerModalPopUp').innerHTML='I dati inseriti non sono corretti!';
    }
    else
    {
  
    
   sender.style.display = "none";
    }
}
function onKo(){
    document.getElementById('innerModalPopUp').innerHTML='';
}
function isNumberKey(evt)
{
 var charCode = (evt.which) ? evt.which : event.keyCode
 if (charCode > 31 && (charCode < 48 || charCode > 57))
    return false;

 return true;
}
function moveDiv(calendarId, imgId, visible){
            var objDiv = document.getElementById(calendarId);
            var objImg = document.getElementById(imgId);
            if(visible){
                var iebody=(document.compatMode && document.compatMode != "BackCompat")? document.documentElement : document.body;
                var dsocleft=document.all? iebody.scrollLeft : pageXOffset;
                var dsoctop=document.all? iebody.scrollTop : pageYOffset;

                var winW = screen.width;
                var winH = screen.height;
                 
                var _w = 360;//dim div calendar
                var _h = 230;//dim div calendar
                //centro
                //nn uso + questo, ma trovo la x e la y dell'immagine che apre il calendar
                //var x = Math.round(((winW - _w)/2) + dsocleft);
                //var y = Math.round(((winH - _h)/2) + dsoctop); 
            
                //alert('top: ' + x + ' left: ' + y + ' scrollLeft: ' + dsocleft + ' scrollTop: ' + dsoctop)
            
                var oParent = objImg.offsetParent; 
                var iOffsetTop = oParent.offsetTop;
                var iOffsetLeft = oParent.offsetLeft;
                //var iClientHeight = oParent.clientHeight;
            
                var y = iOffsetTop + _h;
                var x = iOffsetLeft;
                objDiv.style.position = 'absolute';
                objDiv.style.top = y + 'px';
                objDiv.style.left = x + 'px';
                objDiv.style.display = 'block';
                
                
                //alert (oParent + ' - ' + iOffsetTop + ' - ' + iClientHeight );
            }
            else{
            
                objDiv.style.display = 'none';
            }
        }