

img_left= new Image();
img_left.src = "themes/PCtech/images/mn_left_up.gif";
img_up = new Image();
img_up.src = "themes/PCtech/images/mn_up_up.gif";
img_right = new Image();
img_right.src = "themes/PCtech/images/mn_right_up.gif";

var bV=parseInt(navigator.appVersion);
NS4=(document.layers)?true:false;
IE4=(document.all)?true:false;
ver4=(NS4 || IE4)?true:false;
if (document.images) {
    arImLoad=new Array ("themes/PCtech/images/up");
    arImList=new Array ();
    for (counter in arImLoad) {
        arImList[counter]=new Image();
        arImList[counter].src=arImLoad[counter] + ".gif";
    }
}

function expandIt() {return}
function expandAll() {return}

isExpanded=false;
function reDo(){window.location.reload()}
function getIndex(el) {
    ind=null;
    for (i=0; i<document.layers.length; i++) {
        whichEl=document.layers[i];
        if (whichEl.id==el) {
            ind=i;
            break;
        }
    }
    return ind;
}
function arrange() {
    nextY=document.layers[firstInd].pageY + document.layers[firstInd].document.height-10;
    for (i=firstInd+1; i<document.layers.length; i++) {
        whichEl=document.layers[i];
        if (whichEl.visibility != "hide") {
            whichEl.pageY=nextY;
            nextY += whichEl.document.height-10;
        }
    }
}
function initIt(){
    if (NS4) {
        scrollTo(0,pageYOffset-30);
        for (i=0; i<document.layers.length; i++) {
            whichEl=document.layers[i];
            if (whichEl.id.indexOf("Child") != -1) {
                whichEl.visibility="show";
                whichEl.isExpanded=true;
            }
        }
        arrange();
        setTimeout("window.onresize=reDo",1000)
    } else {
        tempColl=document.getElementsByTagName("DIV");
        for (i=0; i<tempColl.length; i++) {
            if (tempColl[i].className == "child") {
                tempColl[i].style.display="block";
                tempColl[i].isExpanded=true;
            }
        }
    }
}

function expandIt(el) {
    if (!ver4) return;
    if (IE4) {expandIE(el)} 
    else {expandNS(el)}
}

function expandIE(el) { 
    whichEl=eval(el + "Child");
    whichIm=event.srcElement;
    if (whichEl.style.display == "none") {
        whichEl.style.display="block";
        whichEl.isExpanded=true;
        whichIm.src="themes/PCtech/style/up.gif";
    } else {
        whichEl.style.display="none";
        whichEl.isExpanded=false;
        whichIm.src="themes/PCtech/style/down.gif";
    }
}

function expandNS(el) {
    whichEl=eval("document." + el + "Child");
    whichIm=eval("document." + el + "Parent.document.images['imEx']");
    if (whichEl.visibility == "hide") {
        whichEl.visibility="show";
        whichEl.isExpanded=true;
        whichIm.src="themes/PCtech/style/up.gif";
    } else {
        whichEl.visibility="hide";
        whichEl.isExpanded=false;
        whichIm.src="themes/PCtech/style/down.gif";
    }
    arrange();
}

function showAll() {
    for (i=firstInd; i<document.layers.length; i++) {
        whichEl=document.layers[i];
        whichEl.visibility="show";
    }
}

function expandAll(isBot) {
    newSrc=(isExpanded)?"themes/PCtech/style/down.gif":"themes/PCtech/style/up.gif";
    if (NS4) {
        document.images["imEx"].src=newSrc;
        for (i=firstInd; i<document.layers.length; i++) {
            whichEl=document.layers[i];
            if (whichEl.id.indexOf("Parent") != -1) {
                whichEl.document.images["imEx"].src=newSrc;
            }
            if (whichEl.id.indexOf("Child") != -1) {
                whichEl.visibility=(isExpanded)?"hide":"show";
                whichEl.isExpanded=(isExpanded)?false:true;
            }
        }
        arrange();
        if (isBot && isExpanded) scrollTo(0,document.layers[firstInd].pageY);
    } else {
        divColl=document.all.tags("DIV");
        for (i=0; i<divColl.length; i++) {
            if (divColl(i).className == "child") {
                divColl(i).style.display=(isExpanded)?"none":"block";
                divColl(i).isExpanded=(isExpanded)?false:true;
            }
        }
        imColl=document.images.item("imEx");
        for (i=0; i<imColl.length; i++) {
            imColl(i).src=newSrc;
        }
    }
    isExpanded=!isExpanded;
}
with (document) {
    write("<STYLE TYPE='text/css'>");
    write(".parent {");
    if (NS4) {write("position:absolute; visibility:hidden;")};
    if (IE4) {write("margin-top:-1;")};
    write("margin-left:0;");
    write("color:#006");
    write("}");
    write(".child {");
    if (NS4) {write("position:absolute; visibility:hidden;")};
    if (IE4) {write("display:none;")};
    write("margin-left:0;");
    write("}");
    write(".other {");
    if (NS4) {write("position:absolute; visibility:hidden;")};
    write("margin-left:0;");
    write("}");
    write("</STYLE>");
}

function linkIt(whichEl, whichHref) {
    lay=(NS4)?eval("document."+whichEl+"Child"):eval(whichEl+"Child");
    if (!lay.isExpanded) expandIt(whichEl);
    nlay=(NS4)?lay.document.images[whichHref]:document.images[whichHref];
    if (NS4) {
        sY=nlay.y+lay.pageY-20
        window.scrollTo(0,sY);
    } else {
        nlay.scrollIntoView();scroll(0,document.body.scrollTop-20);
        nlay.parentElement.style.backgroundColor="#FF99FF";
        setTimeout("nlay.parentElement.style.backgroundColor='white'",1000);
    }
}

 var submiting = false;  
 var whitespace = " \t\n\r";
 var defaultEmptyOK = false

function isEmpty(s)
 {
  return ((s == null) || (s.length == 0));
 }

function isWhitespace(s)
 {
  var i;
  if (isEmpty(s)) return true;
  for (i = 0; i < s.length; i++)
   {   
    var c = s.charAt(i);
    if (whitespace.indexOf(c) == -1) return false;
   }
  return true;
 }

function isEmail (s)
 {
  if (isEmpty(s))
   if (isEmail.arguments.length == 1) 
    return defaultEmptyOK;
   else 
    return (isEmail.arguments[1] == true);
  if (isWhitespace(s)) return false;
  var i = 1;
  var sLength = s.length;
  while ((i < sLength) && (s.charAt(i) != "@"))
   {
    i++
   }

  if ((i >= sLength) || (s.charAt(i) != "@"))
   return false;
  else 
   i += 2;
  while ((i < sLength) && (s.charAt(i) != "."))
   {
    i++
   }
  if ((i >= sLength - 1) || (s.charAt(i) != "."))
   return false;
  else
   return true;
 }

function isIP (s)
 {
  if (s.search(/^\d{1,3}\.\d{1,3}\.\d{1,3}\.\d{1,3}$/) != -1) {
        var myArray = s.split(/\./);
        if (myArray[0] > 255 || myArray[1] > 255 || myArray[2] > 255 || myArray[3] > 255)
            return false;
        if (myArray[0] == 0 && myArray[1] == 0 && myArray[2] == 0 && myArray[3] == 0)
            return false;
        return true;
    }
    else
        return false;
 }

function isURL (s)
 {
  if (s.search(/[\w-]+\.+[\w-]+\.+[a-z]/) != -1) {
        return true;
    }
    else
        return false;
 }

function isNumber(s)
 {
  if (isEmpty(s)) return false;
   var ValidChars = "0123456789.";
   var IsNumber=true;
   var Char;

 
   for (i = 0; i < s.length && IsNumber == true; i++) 
      { 
      Char = s.charAt(i); 
      if (ValidChars.indexOf(Char) == -1) 
         {
         IsNumber = false;
         }
      }
   return IsNumber;
 }
 
function warnEmpty (theField, s)
 {
  theField.focus()
  alert("Il campo " + s + " è obbligatorio.")
  return false
 }
 
function warnNumber (theField, s)
 {
  theField.focus()
  alert("Il campo " + s + " deve essere un numero.")
  return false
 }
 
function warnInvalid (theField, s)
 {
  theField.focus()
  theField.select()
  alert(s)
  return false
 }
              
function checkString (theField, s, emptyOK)
 {   
  if (theField == null) return true;
  if (checkString.arguments.length == 2) emptyOK = defaultEmptyOK;
  if ((emptyOK == true) && (isEmpty(theField.value))) return true;
  if (isWhitespace(theField.value))
   return warnEmpty (theField, s);
  else 
   return true;
 }

function checkNumber(theField, s, emptyOK)
 {   
  if (theField == null) return true;
  if (checkNumber.arguments.length == 2) emptyOK = defaultEmptyOK;
  if ((emptyOK == true) && (isEmpty(theField.value))) return true;
  if (!isNumber(theField.value))
   return warnNumber (theField, s);
  else 
   return true;
  }
 
function checkEmail (theField, emptyOK)
 {
  if (checkEmail.arguments.length == 1) emptyOK = defaultEmptyOK;
  if ((emptyOK == true) && (isEmpty(theField.value)))
   return true;
  else 
   if (!isEmail(theField.value, false))
    return warnInvalid (theField, "L'indirizzo Email deve essere un indirizzo valido!");
   else
    return true;
 }

function checkIP(theField, emptyOK)
 {
  if (checkIP.arguments.length == 1) emptyOK = defaultEmptyOK;
  if ((emptyOK == true) && ((isIP(theField.value))||(isURL(theField.value))) )
   return true;
  else 
   if ((!isIP(theField.value, false))&&(!isURL(theField.value, false)))
    return warnInvalid (theField, "L'indirizzo immesso non è corretto!");
   else
    return true;
 }

function validateFormAdd(form)
 {
  if ( submiting )
   {
	return false;
   }

   if (checkString(form.elements["nome"],"Nome")&&checkString(form.elements["desc"],"Descrizione")&&
      (checkString(form.elements["add_ip"],"Indirizzo")&&checkIP(form.elements["add_ip"],"Indirizzo IP"))&&
      checkNumber(form.elements["port"],"Porta"))
   {
    	submiting = true;
    	return true;
   } 
   else return false;
 }

function validateFormSearch(form)
 {
  if ( submiting )
   {
	return false;
   }

   if (checkString(form.elements["query"],"Query"))
   {
    	submiting = true;
    	return true;
   } 
   else return false;
 }

function showhidemenuie5(){
		var rightedge=document.body.clientWidth-event.clientX
		var bottomedge=document.body.clientHeight-event.clientY
		if (ie5menu.style.visibility=="visible") {
			ie5menu.style.visibility="hidden"
		} else {
			ie5menu.style.visibility="visible"
			if (rightedge<ie5menu.offsetWidth) {
				ie5menu.style.left=document.body.scrollLeft+event.clientX-ie5menu.offsetWidth
			} else {
				ie5menu.style.left=document.body.scrollLeft+event.clientX
			}
			if (bottomedge<ie5menu.offsetHeight) {
				ie5menu.style.top=document.body.scrollTop+event.clientY-ie5menu.offsetHeight
			} else {
				ie5menu.style.top=document.body.scrollTop+event.clientY
			}
			
		}
		return false
}

function hidemenuie5(){
		ie5menu.style.visibility="hidden"
}

function highlightie5(){
		if (event.srcElement.className=="menuitems"){
			event.srcElement.style.backgroundColor="#ffffff"
			event.srcElement.style.color="#000000"
		}
}
function lowlightie5(){
		if (event.srcElement.className=="menuitems"){
			event.srcElement.style.backgroundColor="#41729e"
			event.srcElement.style.color="#99CCFF"
		}
} 
function jumptoie5(){
		if (event.srcElement.className=="menuitems"){
			if (event.srcElement.url != ''){
				if (event.srcElement.getAttribute("target")!=null){
					window.open(event.srcElement.url,event.srcElement.getAttribute("target"))
				} else {
					window.location=event.srcElement.url
				}
			if (event.srcElement.url == 'back') { history.go(-1) }
			}
			window.status=document.links[4]
		}
}

function btnover(obj, text) {
	obj.className="menu";
	window.status="[P2PItalia]™ - "+text;
}
function btnout(obj) {
	obj.className="";
	window.status="";
}

function toggleDisplay(itemname, hideitems, img, text) {
    tmp = document.getElementsByTagName('div');
	for (i=0;i<tmp.length;i++)
	{
 		if (tmp[i].className == itemname) {
			tmp[i].style.display = (tmp[i].style.display == 'none') ? 'block' : 'none';		
			if (tmp[i].style.display == 'none') {
				if(img) {
					img1.src = 'themes/P2PItalia/images/open_notes.gif';
					img1.alt = 'Mostra ' + text;
				}
			} else {
				if(img) {
					img1.src = 'themes/P2PItalia/images/close_notes.gif';
					img1.alt = 'Nascondi ' + text;
				}
			}
		} else if (tmp[i].id !== '' && tmp[i].className !== '') {
			tmp[i].style.display = 'none';
		}
	}
}

window.onload=initIt;