String.prototype.trim = function() {
	return this.replace(/^\s+|\s+$/g,"");
}

function screensize(){
  var myWidth = 0, myHeight = 0;
  if( typeof( window.innerWidth ) == 'number' ) {
    //Non-IE
    myWidth = window.innerWidth;
    myHeight = window.innerHeight;
  } else if( document.documentElement && ( document.documentElement.clientWidth || document.documentElement.clientHeight ) ) {
    //IE 6+ in 'standards compliant mode'
    myWidth = document.documentElement.clientWidth;
    myHeight = document.documentElement.clientHeight;
  } else if( document.body && ( document.body.clientWidth || document.body.clientHeight ) ) {
    //IE 4 compatible
    myWidth = document.body.clientWidth;
    myHeight = document.body.clientHeight;
  }
  screensize.w = myWidth;
  screensize.h = myHeight;
  return screensize;
}

function getAnchorPosition (anchorName) {
  if (document.layers && !document.all) {
    var anchor = document.anchors[anchorName];
    return { x: anchor.x, y: anchor.y };
  }else if (document.getElementById && !document.all) {
    var anchor = document.anchors[anchorName];
    var coords = {x: 0, y: 0 };
    while (anchor) {
      coords.x += anchor.offsetLeft;
      coords.y += anchor.offsetTop;
      anchor = anchor.offsetParent;
    }
    return coords;
  }else if(document.all){
	var coords=new Object();
	var x=0,y=0;
	if(document.all[anchorName]){
		x=AnchorPosition_getPageOffsetLeft(document.all[anchorName]);
		y=AnchorPosition_getPageOffsetTop(document.all[anchorName]);
	}
	coords.x=x;
	coords.y=y;	
	return coords;
	  }
}

function checkScrollNecessary (link,mode) {	
	if(document.all){
  	 var coords = getAnchorPosition(link);
	}
	else if (document.layers) {
    var coords = getAnchorPosition(link);
  }
  else if (!document.all && document.getElementById) {
    var coords = getAnchorPosition(link);
  }
  else  return false;
  if(mode==0) window.scrollTo(coords.x , coords.y);

	//fix loader size
	 var scollY = getScrollXY();
	 var scrollbottom = getAnchorPosition('bottom');

	 var divloader = document.getElementById("loadingfull");
	 var divloader2 = document.getElementById("loading");
	 if(divloader){
		var pagescreen = screensize();
		myHeight = pagescreen.h;
		if(scrollbottom.y>myHeight ) divloader.style.height=scrollbottom.y+"px";
		else divloader.style.height=myHeight+"px";
		my_width_center_div = (myWidth-divWidth)/2;
		my_height_center_div = (myHeight-100)/2;
		if(divloader2) divloader2.style.top=my_height_center_div+scollY[1]+"px";
	}
	//end ifx
}
// Functions for IE to get position of an object
function AnchorPosition_getPageOffsetLeft (el) {
	var ol=el.offsetLeft;
	if(ol){
		while ((el=el.offsetParent) != null) { ol += el.offsetLeft; }
		return ol;
	}else return 0;
}
function AnchorPosition_getPageOffsetTop (el) {
	var ot=el.offsetTop;
	while((el=el.offsetParent) != null) { ot += el.offsetTop; }
	return ot;
}

//

function translate(langobject) {
	var types = ["span", "option", "td", "button", "div", "label", "a","img", "legend","strong","font","b","input"];
	for (var type in types) {
		var spans = document.getElementsByTagName(types[type]);
		for (var i = spans.length; --i >= 0;) {
			var span = spans[i];
			if (span.firstChild && span.firstChild.data) {				
				var txt = langobject[span.firstChild.data];
				if (txt) span.firstChild.data = txt;
			}
			if(span.title){
				var txt = langobject[span.title];
				if(txt) span.title = txt;
			}
			if(span.alt){
				var txt = langobject[span.alt];
				if(txt) span.alt = txt;
			}

			if(span.value){
				var txt = langobject[span.value];
				if(txt) span.value = txt;
			}

		}
	}
	var txt = langobject[document.title];
	if (txt)
		document.title = txt;
};

//

function submitform(myform,mybutton){
	myformname = eval('document.'+myform);
	mybutton = eval('document.'+myform+'.'+mybutton);
	mybutton.value = "Invio in corso...";
	mybutton.disabled = true;
	myformname.submit();
}

function startLogin(username,password,formname,hideusername,hidepassword){
	var myformname = 'document.'+formname;
	var md5username = hex_md5(eval(myformname+'.'+username+'.value'));
	var md5password = hex_md5(eval(myformname+'.'+password+'.value'));
	eval(myformname+'.'+hideusername+'.value="'+md5username+'"');
	eval(myformname+'.'+hidepassword+'.value="'+md5password+'"');
	eval(myformname+'.'+username+'.disabled=true');
	eval(myformname+'.'+password+'.disabled=true');
	eval(myformname+'.submit()');
	//var mybutton = eval(myformname+'.'+button);
	//mybutton.disabled = true;
}
function changePwd(oldpassword,newpassword,repnewpassword,formname,hideoldpass,hidenewpass,hiderepnewpass){
	var myformname = 'document.'+formname;
	//var newpassordValue = eval(myformname+'.'+newpassword+'.value');
	var newpassordValue =  eval(myformname+'.'+newpassword+'.value');
	newpassordValue = newpassordValue.trim();
	if(newpassordValue.length!=0){
		var md5newpassword = hex_md5(newpassordValue);
	}
	var md5oldpassword = hex_md5(eval(myformname+'.'+oldpassword+'.value'));
	var md5repnewpassword = hex_md5(eval(myformname+'.'+repnewpassword+'.value'));
	eval(myformname+'.'+hideoldpass+'.value="'+md5oldpassword+'"');
	eval(myformname+'.'+hidenewpass+'.value="'+md5newpassword+'"');
	eval(myformname+'.'+hiderepnewpass+'.value="'+md5repnewpassword+'"');
	eval(myformname+'.'+oldpassword+'.disabled=true');
	eval(myformname+'.'+newpassword+'.disabled=true');
	eval(myformname+'.'+repnewpassword+'.disabled=true');
	eval(myformname+'.submit()');
}

function startRegister(password,hidepassword,formname){
	var myformname = 'document.'+formname;
	var mypassword = eval(myformname+'.'+password+'.value');
	mypassword = mypassword.trim();
	if(mypassword.length!=0){
		var md5password = hex_md5(mypassword);
		eval(myformname+'.'+hidepassword+'.value="'+md5password+'"');
	}
	eval(myformname+'.'+password+'.value=""');
	eval(myformname+'.submit()');
}

//ARRAY prototype
Array.prototype.indexof = function(myItem) {
	result=-1;
	if ((this.length<1)||(arguments.length==0))
	{
	return -1;
	exit;
	}
	for (i=0;i<this.length;i++) {
	
	if (this[i]==myItem) {
	result=i;
	break;
	}//end of if statement
	}//end of for statement
	return result;
	//Attach custom method to array object
	if (!Array.prototype.indexof)
	{
	Array.prototype.indexof=indexof; 
	}
} 

Array.prototype.lastindexof = function(myItem) {
	result=-1;
	if ((this.length<1)||(arguments.length==0))
	{
	return -1;
	exit;
	}
	for (i=this.length-1;i>-1;i--) {
	
	if (this[i]==myItem) {
	result=i;
	break;
	}//end of if statement
	}//end of for statement
	return result;
	//Attach custom method to array object
	if (!Array.prototype.lastindexof)
	{
	Array.prototype.lastindexof=lastindexof; 
	}
} 
//

//START multiselect ----------------------------------------------------------------------------------------
function selectAll(form,field){
	myfield = eval('document.'+form+'.'+field);
	var boxLength = myfield.length;
	for (i = 0; i < boxLength; i++) {
		myfield.options[i].selected = true;
	}
}

function addSelected(form,fieldFrom,fieldTo){
	//get selected on box 1
	var box1 = eval('document.'+form+'.'+fieldFrom);
	var box1len = box1.length;
	arrbox1Text = Array();
	arrbox1Value = Array();
	var count = 0;
	for (i = 0; i < box1len; i++) {
		if (box1.options[i].selected) {
			arrbox1Text[count] = box1.options[i].text;
			arrbox1Value[count] = box1.options[i].value;
			count++;
		}
	}
	//end
	//get selected on box 2
	var box2 = eval('document.'+form+'.'+fieldTo);
	var box2len = box2.length;
	arrbox2Text = Array();
	arrbox2Value = Array();
	for (i = 0; i < box2len; i++) {
		arrbox2Text[i] = box2.options[i].text;
		arrbox2Value[i] = box2.options[i].value;
	}
	//end
	if(box2len!=0){
		var count = box2len;
		for (x = 0; x < arrbox1Value.length; x++) {
			if(arrbox2Value.indexof(arrbox1Value[x])==-1){
				newoption = new Option(arrbox1Text[x], arrbox1Value[x], false, false);
				box2.options[count] = newoption;
				count++;	
			}
		}
	}else if(box2len==0){
		for (x = 0; x < arrbox1Value.length; x++) {
			newoption = new Option(arrbox1Text[x], arrbox1Value[x], false, false);
			box2.options[x] = newoption;			
		}
	}
}

function removeSelected(form,field) {
	var box = eval('document.'+form+'.'+field);
	var boxLength = box.length;
	arrSelected = new Array();
	var count = 0;
	for (i = 0; i < boxLength; i++) {
	if (box.options[i].selected) {
		arrSelected[count] = box.options[i].value;
	}
	count++;
	}
	var x;
	for (i = 0; i < boxLength; i++) {
	for (x = 0; x < arrSelected.length; x++) {
	if (box.options[i].value == arrSelected[x]) {
		box.options[i] = null;
	   }
	}
	boxLength =box.length;
	   }
}

function SaveMe(form,fieldFrom,fieldTo) {
	var strValues = "";
	var boxLength = eval('document.'+form+'.'+fieldFrom+'.length');
	var count = 0;
	if (boxLength != 0) {
		for (i = 0; i < boxLength; i++) {
		if (count == 0) {
			strValues = eval('document.'+form+'.'+fieldFrom+'.options['+i+'].value');
		}
		else {
			strValues = strValues + ":" + eval('document.'+form+'.'+fieldFrom+'.options['+i+'].value');
		}
		count++;
		   }
	}
	if (strValues=='') {
		eval('document.'+form+'.'+fieldTo+'.value = "null"');
	}else {
		eval('document.'+form+'.'+fieldTo+'.value = "'+strValues+'"');
	}
}
//END ----------------------------------------------------------------------------------------

function noEnter(e,searchvalue){
var characterCode
 if(e && e.which){
	 e = e
	 characterCode = e.which
 }else{
	 e = event
	 characterCode = e.keyCode
 }	 
 if(characterCode == 13){
	 searchact(searchvalue);
	 return false;
 }
 else{
	 return true;
 }
}

//

function hideloader(){
	var divloader;
	if (document.getElementById) {  // DOM3 = IE5, NS6
			divloader = document.getElementById('loadingfull');
			if(divloader) divloader.style.visibility = 'hidden';
	}else if (document.layers) {  // Netscape 4
			divloader = document.loadingfull;
			if(divloader) divloader.visibility = 'hidden';
	}else {  // IE 4
		divloader = document.all.loadingfull;
		if(divloader) divloader.style.visibility = 'hidden';
	}
	if(divloader){
		divloader.style.width = '0px';
		divloader.style.height = '0px';
	}
}

//

function getScrollXY() {
  var scrOfX = 0, scrOfY = 0;
  if( typeof( window.pageYOffset ) == 'number' ) {
    //Netscape compliant
    scrOfY = window.pageYOffset;
    scrOfX = window.pageXOffset;
  } else if( document.body && ( document.body.scrollLeft || document.body.scrollTop ) ) {
    //DOM compliant
    scrOfY = document.body.scrollTop;
    scrOfX = document.body.scrollLeft;
  } else if( document.documentElement && ( document.documentElement.scrollLeft || document.documentElement.scrollTop ) ) {
    //IE6 standards compliant mode
    scrOfY = document.documentElement.scrollTop;
    scrOfX = document.documentElement.scrollLeft;
  }
  return [ scrOfX, scrOfY ];
}

