function calculateCorrect (mcWidth, mcHeight) {
	if (self.screen) {     
   	    width = screen.width
	} else if (self.java) {
		var javakit = java.awt.Toolkit.getDefaultToolkit();
	    var scrsize = javakit.getScreenSize();       
	    width = scrsize.width; 
	} else {
		width = height = '?' 
	}
	
	misureWidth = mcWidth;
	misureHeight = mcHeight;
	
	
		y = (screen.height - misureHeight -68)/2;
		x = (screen.width - misureWidth -10)/2; 
		
   } 
   
function openWindow (mWidth, mHeight, page) { // Non ha la scrollbar
    calculateCorrect(mWidth, mHeight);
	popup = window.open(page,'newWin','scrollbars=no, width='+misureWidth+',height='+misureHeight+',top='+y+',left='+x); 
}

function openWindowOff (mWidth, mHeight, page) { // Ha la scrollbar
    calculateCorrect(mWidth, mHeight);
	popup = window.open(page,'newWin','scrollbars=yes, width='+misureWidth+',height='+misureHeight+',top='+y+',left='+x); 
}

function openThickAlert(stringText)
{  
    tb_open_new('SecurityRED', 'alert.aspx?stringText=' + stringText + '&TB_iframe=true&height=200&width=300');       
}






function box (pagina) {
	alert ("Coming soon! May 11st 2010!");
}

function subMenu (id,action) {
	document.getElementById(id).style.display=action;
}


function subMenuDup (id,action) {
	document.getElementById(id).style.display=action;
	eval("var next = '" + id + "Next'");
	document.getElementById(next).style.display=action;
}

function swapNews2(newsArray, newsPanelId) 
{
  for (i=0; i<newsArray.length; i++)
  {
    if (newsArray[i] != newsPanelId)
    {
        document.getElementById(newsArray[i]).style.display='none';
    }
    else    
    {
        document.getElementById(newsArray[i]).style.display='block';
    }
  }
}

function swapForm() {
  forCompany = document.getElementById('forCompany');

	if (!forCompany.checked) {
    document.getElementById('divForCompany').style.display = 'none';
  } else {
    document.getElementById('divForCompany').style.display = 'block';
  }
}


















// VALIDATION

function txtMin(name,caption,min) {
  valid=true;
	obj=document.getElementsByName(name)[0];
	
	if (obj.value!="" && obj.value.length<min){
		if (lang=="ita"){
			alert("Inserire almeno "+min+" caratteri nel campo '"+caption+"'.");
		}
		else{
		  alert("Please enter at least "+min+" characters in the '"+caption+"' field.");
		}
		valid=false;
	}	
	return valid; 
 }
 
function txtObligatory(name,caption){
	valid=true;
	obj=document.getElementsByName(name)[0];

	if (obj.value==""){
		if (lang=="ita"){
			alert("Il campo '"+caption+"' e' obbligatorio.");
		}
		else{
		  alert("Please enter a value for the '"+caption+"' field.");			
		}
		valid=false;
	}	
	return valid;
 }


function txtValidation(name,caption,type){
	valid=true;
	obj=document.getElementsByName(name)[0];
	txtValue=obj.value;
	if (obj.value=="") return true;
	
	switch(type){
		case "mail":
			
			atpos=txtValue.indexOf("@");
			atpos2=txtValue.indexOf("@",atpos+1);
			
		
			if (atpos<1 || atpos==txtValue.length-1 || atpos2!=-1){
				valid=false;

			}
			else{

				dotpos=txtValue.lastIndexOf(".");
				dotpos2=dotpos - atpos;
				finale = txtValue.length - dotpos - 1;
				
				if ((dotpos==-1 || dotpos<atpos || dotpos==txtValue.length-1)||(dotpos2<1)||(finale<2)) {
					valid=false;
				}
				else{
					var validc="0123456789.@-_abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ";
					for (var i=0;i<txtValue.length;i++){
						valid=false;
						for (var j=0;j<validc.length;j++){
							if (validc.charAt(j)==txtValue.charAt(i)) valid=true;
						}
					}	
				}
			}						
			break;
			
			
			
			
			
		case "clever": /* Controllo di un dato finto */

			for (var i=0; i<=1; i++) {
				confronta = i + 1;
				confronta_dopo = confronta + 1;
		
				prima = txtValue.substring(i, confronta);
				dopo = txtValue.substring(confronta, confronta_dopo);
				
				if (prima==dopo) {
					valid = false;
				} else {
					valid = true;
					break;
				} 
			}
			
			// Non ci può essere più di un blank
			spacepos=txtValue.indexOf("  ");
			
			if (spacepos>-1) {
				valid = false;
			}
			
			
			
			
			
			
				
			break;
			
			
		
		
	
	
	
			case "antispam": /* controllo se l'indirizzo http può essere considerato spam */
			
				if (txtValue != "http://") {
					piece = txtValue.split(".");
					piece = piece[0].split("//");
					pieceCont = piece[1];
					
					if (!isNaN(pieceCont)) {
						valid = false;
						
					} else {
						valid = true;
						
					}
				}	
				
			break;
		
			
			
					
			
			
	case "??":
			break;
	}
	
	
	
	if (!valid){
		if (lang=="ita"){
			alert("Il campo '"+caption+"' non e' valido. (Dati inesatti o doppio spazio o indirizzo http spam)");
		}
		else{
		  alert("The '"+caption+"' field is not valid. Please, control.");			
		}
	}	
	return valid;
}


function txtVChars(type, e){

	var keynum;

  if(window.event) // IE
  {
    keynum = e.keyCode;
  }
  else if(e.which) // Netscape/Firefox/Opera
  {
    keynum = e.which;
  } 
			
	switch(type){
		case "letnum":
			if ((keynum<48 || keynum>57) && (keynum<65 || keynum>90) && (keynum<96 || keynum>105) && keynum!=8 && keynum!=9 && keynum!=32 && keynum!=46) e.returnValue=false;
			break;
			
		case "num":
			if ((keynum<48 || keynum>57) && (keynum<96 || keynum>105) && keynum!=8 && keynum!=9 && keynum!=16) e.returnValue=false;
			break;
			
		case "let":
			if ((keynum<65 || keynum>90) && (keynum<1 || keynum>32) && keynum!=219 && keynum!=186 && keynum!=191 && keynum!=222 && keynum!=192 && keynum!=221 ) e.returnValue=false;
			break;
			
		case "tel":
			if ((keynum<48 || keynum>57) && (keynum<96 || keynum>105) && keynum!=8 && keynum!=9 && keynum!=32 && keynum!=111 && keynum!=187 && keynum!=189 && keynum!=16 && keynum!=107 && keynum!=109) e.returnValue=false;
			break;
			
	}
 }

// END VALIDATION



function highlight() { 
  var elements = document.getElementsByTagName("input");
  for (i=0; i < elements.length; i++) { 

     var type = elements[i].getAttribute('type');
     if(type=="text" || type=="password") { 
       elements[i].onfocus=function() {
         //this.style.borderColor='#5789C6'; 
         this.style.backgroundColor='#FFFFE0';
       }; 
       elements[i].onblur=function() {
         //this.style.borderColor='#AABBCC'; 
         this.style.backgroundColor='#FFFFFF';
      }; 

    } 
  } 
} 




// New Panel
function iShow (divRight, divRedTechIsActive) {

  cDivLeft = new Array();
  cDivRight = new Array();
  cTdLeft = new Array();
  cDivTitle = new Array();
  
  cDivLeft [0]="divLeft1";
  cDivLeft [1]="divLeft2";
  cDivLeft [2]="divLeft3";
  cDivLeft [3]="divLeft4";
  
  cDivRight [0]="divRight1";
  cDivRight [1]="divRight2";
  cDivRight [2]="divRight3";
  cDivRight [3]="divRight4";
  
  cTdLeft [0]="tdLeft1";
  cTdLeft [1]="tdLeft2";
  cTdLeft [2]="tdLeft3";
  cTdLeft [3]="tdLeft4";
  
  cDivTitle [0]="divTitle1";
  cDivTitle [1]="divTitle2";
  cDivTitle [2]="divTitle3";
  cDivTitle [3]="divTitle4";
 
  
  document.getElementById(divRedTechIsActive).style.display='none';
 

  for (i=0; i<=3; i++) {
    if (cDivRight [i] == divRight) {
      // ATTIVA
      
      document.getElementById(cDivLeft [i]).style.borderBottom='1px #ffffff solid';
      document.getElementById(cDivLeft [i]).style.backgroundColor='#FFFFFF';
      
      document.getElementById(cTdLeft [i]).style.borderBottom='1px #C0C0C0 solid';
      
      document.getElementById(cDivRight [i]).style.display='block';
      
      document.getElementById(cDivTitle [i]).style.color='#E63E31';
      
    } else {
      // RESETTA 
      
      document.getElementById(cDivLeft [i]).style.borderBottom='1px #c0c0c0 solid';
      document.getElementById(cDivLeft [i]).style.backgroundColor='#F6F6F6';
      
      document.getElementById(cTdLeft [i]).style.borderBottom='1px #FFFFFF solid';
      
      document.getElementById(cDivRight [i]).style.display='none';
      
      document.getElementById(cDivTitle [i]).style.color='#767676';
    }    
  }
}

function chImg (type, idImg, strImg, strImgOn) {
  /*
    Questa funzione è usata nell'UC LeftMenu.ascx
    type: 1 (over) 2 (out)
  */
  
  if (type == "1") {
    document.getElementById(idImg).src=strImg;
  } else {
    document.getElementById(idImg).src=strImgOn;
  }
  
}

/*
    Geolocalization win open
*/
function openGeo(el)
{ 
    if (el == null) return;
        
    var opLogID = el.getAttribute("operationlogid");
                   
    if (opLogID > 0)
        tb_open_new('SecurityRED', 'geolocalization.aspx?id=47&operationlogid=' + new String(opLogID) + '&grp=cmdSubGrpDevice&TB_iframe=true&height=570&width=550');    
}


