$(function() {
	$('.dialog').click(function(e) {
		e.preventDefault();
		var $this = $(this);
    var horizontalPadding = 30;
    var verticalPadding = 30;
    $('<iframe id="externalSite" frameBorder="0" class="externalSite" src="' + this.href + '" />').dialog({
			title: ($this.attr('title')) ? $this.attr('title') : 'External Site',
			autoOpen: true,
			width: 800, 
      height: 500,
      modal: true,
      resizable: false,
      autoResize: true,
      overlay: {
        opacity: 0.5,
        background: "black"
      },
			buttons: {
				"Salva": function() {
					var $currentIFrame = $('#externalSite'); 
					//alert(getPageData('cmd=save&' + $currentIFrame.contents().find("#pageform").serialize() ));
					fnz(getPageData($currentIFrame.contents().find("#pageform").serialize() ));
					$( this ).dialog( "close" );
					},
				"Annulla": function() {
					$( this ).dialog( "close" );
					}
			},
			open: function() {
				var $currentIFrame = $('#externalSite');
				$currentIFrame.attr('src',$currentIFrame.attr('src'));
			},
			close: function() {
					// $( this ).dialog( "destroy" );

				// $('#workarea').html("ff");
			}
    }).width(800 - horizontalPadding).height(500 - verticalPadding);            
  });
});

/*
$(function() {
$("#slider").slider(
    { change: handleChange,
        slide: handleSlide,
        min: -100,
    max: 0 });
});

function handleChange(e, ui) {
    var maxScroll = $("#scroller")
      .attr("scrollHeight") -
      $("#scroller").height();
    $("#scroller")
      .animate({ scrollTop: -ui.value *
     (maxScroll / 100)
    }, 1000);

}

function handleSlide(e, ui) {
    var maxScroll = $("#scroller")
      .attr("scrollHeight") -
      $("#scroller").height();
    $("#scroller")
      .attr({ scrollTop: -ui.value
        * (maxScroll / 100)   });

}
 */

$(document).ready(function () {
  $(".loginform").animate({"left": "+=900px"}, "slow");
  $(".pageform").animate({"left": "+=920px"}, "fast");
});



function btnSave()
{
//	alert(getPageData());
	fnz(getPageData());
}
function btnCancel()
{
//  window.parent.jw.closedialog();
//alert(0);
  window.parent.dlg.closedialog();
}














var http_request = false;

function fnz(parameters) {
  http_request = false;
  if (window.XMLHttpRequest) {
    http_request = new XMLHttpRequest();
    if (http_request.overrideMimeType) {
      http_request.overrideMimeType('text/html');
    }
  } else if (window.ActiveXObject) {
    try {
      http_request = new ActiveXObject("Msxml2.XMLHTTP");
    } catch (e) {
      try {
        http_request = new ActiveXObject("Microsoft.XMLHTTP");
      } catch (e) {}
    }
  }
  if (!http_request) {
    alert('Cannot create XMLHTTP instance');
    return false;
  }
      
  http_request.onreadystatechange = onResponse;
  http_request.open('POST', '_proxy.php', true);
  http_request.setRequestHeader("Content-type", "application/x-www-form-urlencoded");
  http_request.setRequestHeader("Content-length", parameters.length);
  http_request.setRequestHeader("Connection", "close");
  http_request.send(parameters);
}

function onResponse() {
  if(http_request.readyState == 4) {
    if (http_request.status == 200) {
      var st=http_request.responseText;		
			var rx =  st.slice(0,4);
			var cm = st.substr(4);
      if(rx=="{JS}"){ eval(cm); }
      if(rx=="{64}"){ eval(decodeBase64(cm));}
      if(rx=="{ER}"){	alert(cm); }
    } else {
        alert('There was a problem with the request.\n\n' + http_request.responseText);
    }
    
  }
}

j$ = document.all ?
	function (id) { return document.all[id] } :
	function (id) { return document.getElementById(id) };

j$$ = function (n) { return document.getElementsByTagName(n) };


function jwx (hwnd) {

	this.closedialog = function(e)
	{
		var objBody = document.getElementsByTagName("body").item(0);
	  var olddiv = document.getElementById("modal" + hwnd);
		var ovl = j$("msgOverlay" + hwnd);

		objBody.removeChild(olddiv);
		olddiv = null;
		objBody.removeChild(ovl);
		ovl = null;
	};

	this.show = function(url,tit,w,h)
	{
		var cw = 400;
		var ch = 180;
		
		if(w) cw = w;
		if(h) ch = h;
		var objBody = document.getElementsByTagName("body").item(0);
		var objOverlay = document.createElement("div");
		objOverlay.setAttribute('id','msgOverlay' + hwnd);
		objOverlay.style.display = 'none';
		objBody.appendChild(objOverlay);
		var o =  "modal" + hwnd;

	  var objMsgBox = this.el("div","jlook",o); // "msgBox");
		objMsgBox.style.zIndex = (hwnd*100) + 1;
		objMsgBox.style.display = 'none';
		objBody.appendChild(objMsgBox);
		

		var objWrap = this.el("div","mceWrapper");
		objMsgBox.appendChild(objWrap);

		var objTop = this.el("div","mceTop","msgCaption" + hwnd);
		objWrap.appendChild(objTop);

		var objTopL = this.el("div","mceLeft");
		objTop.appendChild(objTopL);

		var objTopC = this.el("div","mceCenter");
		objTop.appendChild(objTopC);

		var objTopR = this.el("div","mceRight");
		objTop.appendChild(objTopR);

	  var objTopSpan = this.el("span",0,"mainTitle");
		objTopSpan.innerHTML = tit; 
		objTop.appendChild(objTopSpan);

		var objMid = this.el("div","mceMiddle");
		objWrap.appendChild(objMid);

		var objMidL = this.el("div","mceLeft");
		objMid.appendChild(objMidL);

		var objMidSpan = this.el("span",0);
		objMid.appendChild(objMidSpan);
    
		this.ifr = this.el("iframe",0,"msgIf" + hwnd);
	  this.ifr.frameBorder=0;
		this.ifr.style.position = 'absolute';
		this.ifr.style.width = (cw-10) + "px";
		this.ifr.style.height = (ch-30) + "px";
	  this.ifr.src = url;
		objMidSpan.appendChild(this.ifr);

	  var objMidR = this.el("div","mceRight");
		objMid.appendChild(objMidR);
    
		var objBot = this.el("div","mceBottom");
		objWrap.appendChild(objBot);

		var objBotL = this.el("div","mceLeft");
		objBot.appendChild(objBotL);

		var objBotC = this.el("div","mceCenter");
		objBot.appendChild(objBotC);
    
		var objBotR = this.el("div","mceRight");
		objBot.appendChild(objBotR);

		var objBotSpan = this.el("span",0);
		objBotSpan.innerHTML = "";  
		objBot.appendChild(objBotSpan);

		var objBtn = this.el("a","mceClose");
	  objBtn.href = "javascript:;";
		objBtn.onclick = this.closedialog; 

		objWrap.appendChild(objBtn);

    if(j$("msgOverlay" + hwnd))
		{
			j$("msgOverlay" + hwnd).style.display = 'block';
			var ovl = j$("msgOverlay" + hwnd).style;
	    ovl.left = "0px";
			ovl.top = "0px";
			ovl.height = '100%';
			ovl.width = '100%';
		}



    var mbx = objMsgBox.style;
    mbx.display = 'block';
	  var tp = posT()+((pageH()-ch)/2) - 12;
		var lt = posL()+((pageW()-cw)/2) - 12;
		mbx.top = (tp<0?0:tp)+"px";
		mbx.left = (lt<0?0:lt)+"px";
		mbx.width = cw + "px";
		mbx.height = ch + "px";
    
    Drag.init(objTop,objMsgBox);

		/*return 4432;*/
	};
	this.el = function(type,classname,id) {
  	var e = document.createElement(type);
    if(classname!=0) e.className = classname;
    if(id!=0) e.setAttribute('id',id);
    return e;
  };


};



function jwm () {

	this.closedialog = function(e)
	{
		var objBody = document.getElementsByTagName("body").item(0);
	  var olddiv = document.getElementById('modal');
		var ovl = j$("msgOverlay2");

		objBody.removeChild(olddiv);
		olddiv = null;
		objBody.removeChild(ovl);
		ovl = null;
	};

	this.show = function(url,id,tit,w,h)
	{

		var cw = 400;
		var ch = 180;
		
		if(w) cw = w;
		if(h) ch = h;
		var objBody = document.getElementsByTagName("body").item(0);
		var objOverlay = document.createElement("div");
		objOverlay.setAttribute('id','msgOverlay2');
		objOverlay.style.display = 'none';
		objBody.appendChild(objOverlay);
		var o =  "modal";

	  var objMsgBox = this.el("div","jlook",o); // "msgBox");
		objMsgBox.style.zIndex = 201;
		objMsgBox.style.display = 'none';
		objBody.appendChild(objMsgBox);
		

		var objWrap = this.el("div","mceWrapper");
		objMsgBox.appendChild(objWrap);

		var objTop = this.el("div","mceTop","msgCaption3");
		objWrap.appendChild(objTop);

		var objTopL = this.el("div","mceLeft");
		objTop.appendChild(objTopL);

		var objTopC = this.el("div","mceCenter");
		objTop.appendChild(objTopC);

		var objTopR = this.el("div","mceRight");
		objTop.appendChild(objTopR);

	  var objTopSpan = this.el("span",0,"mainTitle");
		objTopSpan.innerHTML = tit; 
		objTop.appendChild(objTopSpan);

		var objMid = this.el("div","mceMiddle");
		objWrap.appendChild(objMid);

		var objMidL = this.el("div","mceLeft");
		objMid.appendChild(objMidL);

		var objMidSpan = this.el("span",0);
		objMid.appendChild(objMidSpan);
    
		this.ifr = this.el("iframe",0,"msgIf2");
	  this.ifr.frameBorder=0;
		this.ifr.style.position = 'absolute';
		this.ifr.style.width = (cw-10) + "px";
		this.ifr.style.height = (ch-30) + "px";
		if(id!=undefined)url+="?id="+id;
	  this.ifr.src = url;//"dlg-addtipologia.php";
		objMidSpan.appendChild(this.ifr);

	  var objMidR = this.el("div","mceRight");
		objMid.appendChild(objMidR);
    
		var objBot = this.el("div","mceBottom");
		objWrap.appendChild(objBot);

		var objBotL = this.el("div","mceLeft");
		objBot.appendChild(objBotL);

		var objBotC = this.el("div","mceCenter");
		objBot.appendChild(objBotC);
    
		var objBotR = this.el("div","mceRight");
		objBot.appendChild(objBotR);

		var objBotSpan = this.el("span",0);
		objBotSpan.innerHTML = "";  
		objBot.appendChild(objBotSpan);

		var objBtn = this.el("a","mceClose");
	  objBtn.href = "javascript:;";
		objBtn.onclick = this.closedialog; 

		objWrap.appendChild(objBtn);

    if(j$("msgOverlay2"))
		{
			j$("msgOverlay2").style.display = 'block';
			var ovl = j$("msgOverlay2").style;
	    ovl.left = "0px";
			ovl.top = "0px";
			ovl.height = '100%';
			ovl.width = '100%';
		}



    var mbx = objMsgBox.style;
    mbx.display = 'block';
	  var tp = posT()+((pageH()-ch)/2) - 12;
		var lt = posL()+((pageW()-cw)/2) - 12;
		mbx.top = (tp<0?0:tp)+"px";
		mbx.left = (lt<0?0:lt)+"px";
		mbx.width = cw + "px";
		mbx.height = ch + "px";
    
    Drag.init(objTop,objMsgBox);

		return 4432;
	};
	this.el = function(type,classname,id) {
  	var e = document.createElement(type);
    if(classname!=0) e.className = classname;
    if(id!=0) e.setAttribute('id',id);
    return e;
  };


};


jw_init = false;
var jwd;
var jw = {
	init : function(s,w,h) {
	var objBody = document.getElementsByTagName("body").item(0);
	var objOverlay = document.createElement("div");
	objOverlay.setAttribute('id','msgOverlay');
	objOverlay.style.display = 'none';
	objBody.appendChild(objOverlay);

  var objMsgBox = this.newElement("div","jlook","msgBox4");
	objMsgBox.style.display = 'none';
	objBody.appendChild(objMsgBox);

  var objWrap = this.newElement("div","mceWrapper");
	objMsgBox.appendChild(objWrap);

  var objTop = this.newElement("div","mceTop","msgCaption4");
	objWrap.appendChild(objTop);

  var objTopL = this.newElement("div","mceLeft");
	objTop.appendChild(objTopL);

  var objTopC = this.newElement("div","mceCenter");
	objTop.appendChild(objTopC);

  var objTopR = this.newElement("div","mceRight");
	objTop.appendChild(objTopR);

  var objTopSpan = this.newElement("span",0,"mainTitle");
	objTopSpan.innerHTML = "Titolo"; 
	objTop.appendChild(objTopSpan);

  var objMid = this.newElement("div","mceMiddle");
	objWrap.appendChild(objMid);

  var objMidL = this.newElement("div","mceLeft");
	objMid.appendChild(objMidL);

  var objMidSpan = this.newElement("span",0);
	objMid.appendChild(objMidSpan);
    
  var ifr = this.newElement("iframe",0,"msgIf");
  ifr.frameBorder=0;
	ifr.style.position = 'absolute';
	ifr.style.width = (w-10) + "px";
	ifr.style.height = (h-30) + "px";
  ifr.src = "about:blank";
  objMidSpan.appendChild(ifr);
    
  var objMidR = this.newElement("div","mceRight");
	objMid.appendChild(objMidR);
    
  var objBot = this.newElement("div","mceBottom");
	objWrap.appendChild(objBot);

  var objBotL = this.newElement("div","mceLeft");
	objBot.appendChild(objBotL);

  var objBotC = this.newElement("div","mceCenter");
	objBot.appendChild(objBotC);
    
  var objBotR = this.newElement("div","mceRight");
	objBot.appendChild(objBotR);

  var objBotSpan = this.newElement("span",0);
	objBotSpan.innerHTML = "";  
	objBot.appendChild(objBotSpan);

  var objBtn = this.newElement("a","mceClose");
  objBtn.href = "javascript:;";
	objBtn.onclick = function() { jw.closedialog(); };
	objWrap.appendChild(objBtn);

    jw_init = true;
		return null;
	},
	newElement : function(type,classname,id) {
  	var e = document.createElement(type);
    if(classname!=0) e.className = classname;
    if(id!=0) e.setAttribute('id',id);
    return e;
  }, 
	enableinput : function() {
    j$("msgText").style.display = 'none';
    j$("msgAnimation").style.display = 'none';
  },
	closedialog : function() {
    j$("msgIf").src = "about:blank";
    j$("msgBox4").style.display = 'none'; 
    j$("msgOverlay").style.display = 'none';
  },
	showprogress : function(msg) {
    if (msg==null) {
      j$("msgText").style.display = 'none';
      j$("msgAnimation").style.display = 'none';
      j$("msgAnimation").innerHTML = "";
    }
    else {
      j$("msgText").style.display = 'block';
      j$("msgAnimation").style.display = 'block';
      j$("msgAnimation").innerHTML = msg;
    }
  },
	showdialog : function(style,title,width,height,url,id) {
    if(!jw_init) this.init(style,width,height);

		if(id!=undefined)url+="?id="+id;
		j$("msgIf").src = url;
		j$("msgIf").style.width = (width-10) + "px";
		j$("msgIf").style.height = (height-30) + "px";
    j$("msgOverlay").style.display = 'block';

    var ovl = j$("msgOverlay").style;
    ovl.left = "0px";
    ovl.top = "0px";
		ovl.height = '100%';
		ovl.width = '100%';


    var mbx = j$("msgBox4").style;
    mbx.display = 'block';


	  var tp = posT()+((pageH()-height)/2) - 12;
		var lt = posL()+((pageW()-width)/2) - 12;
		mbx.top = (tp<0?0:tp)+"px";
		mbx.left = (lt<0?0:lt)+"px";
		mbx.width = width + "px";
		mbx.height = height + "px";

    
		j$("mainTitle").innerHTML = title;
    
    Drag.init(j$("msgCaption4"),j$("msgBox4"));
	
	}
};





/**************************************************
 * dom-drag.js
 * 09.25.2001
 * www.youngpup.net
 * Script featured on Dynamic Drive (http://www.dynamicdrive.com) 12.08.2005
 **************************************************
 * 10.28.2001 - fixed minor bug where events
 * sometimes fired off the handle, not the root.
 **************************************************/

var Drag = {

	obj : null,

	init : function(o, oRoot, minX, maxX, minY, maxY, bSwapHorzRef, bSwapVertRef, fXMapper, fYMapper)
	{
		o.onmousedown	= Drag.start;

		o.hmode			= bSwapHorzRef ? false : true ;
		o.vmode			= bSwapVertRef ? false : true ;

		o.root = oRoot && oRoot != null ? oRoot : o ;

		if (o.hmode  && isNaN(parseInt(o.root.style.left  ))) o.root.style.left   = "0px";
		if (o.vmode  && isNaN(parseInt(o.root.style.top   ))) o.root.style.top    = "0px";
		if (!o.hmode && isNaN(parseInt(o.root.style.right ))) o.root.style.right  = "0px";
		if (!o.vmode && isNaN(parseInt(o.root.style.bottom))) o.root.style.bottom = "0px";

		o.minX	= typeof minX != 'undefined' ? minX : null;
		o.minY	= typeof minY != 'undefined' ? minY : null;
		o.maxX	= typeof maxX != 'undefined' ? maxX : null;
		o.maxY	= typeof maxY != 'undefined' ? maxY : null;

		o.xMapper = fXMapper ? fXMapper : null;
		o.yMapper = fYMapper ? fYMapper : null;

		o.root.onDragStart	= new Function();
		o.root.onDragEnd	= new Function();
		o.root.onDrag		= new Function();
	},

	start : function(e)
	{
		var o = Drag.obj = this;
		e = Drag.fixE(e);
		var y = parseInt(o.vmode ? o.root.style.top  : o.root.style.bottom);
		var x = parseInt(o.hmode ? o.root.style.left : o.root.style.right );
		o.root.onDragStart(x, y);

		o.lastMouseX	= e.clientX;
		o.lastMouseY	= e.clientY;

		if (o.hmode) {
			if (o.minX != null)	o.minMouseX	= e.clientX - x + o.minX;
			if (o.maxX != null)	o.maxMouseX	= o.minMouseX + o.maxX - o.minX;
		} else {
			if (o.minX != null) o.maxMouseX = -o.minX + e.clientX + x;
			if (o.maxX != null) o.minMouseX = -o.maxX + e.clientX + x;
		}

		if (o.vmode) {
			if (o.minY != null)	o.minMouseY	= e.clientY - y + o.minY;
			if (o.maxY != null)	o.maxMouseY	= o.minMouseY + o.maxY - o.minY;
		} else {
			if (o.minY != null) o.maxMouseY = -o.minY + e.clientY + y;
			if (o.maxY != null) o.minMouseY = -o.maxY + e.clientY + y;
		}

		document.onmousemove	= Drag.drag;
		document.onmouseup		= Drag.end;

		return false;
	},

	drag : function(e)
	{
		e = Drag.fixE(e);
		var o = Drag.obj;

		var ey	= e.clientY;
		var ex	= e.clientX;
		var y = parseInt(o.vmode ? o.root.style.top  : o.root.style.bottom);
		var x = parseInt(o.hmode ? o.root.style.left : o.root.style.right );
		var nx, ny;

		if (o.minX != null) ex = o.hmode ? Math.max(ex, o.minMouseX) : Math.min(ex, o.maxMouseX);
		if (o.maxX != null) ex = o.hmode ? Math.min(ex, o.maxMouseX) : Math.max(ex, o.minMouseX);
		if (o.minY != null) ey = o.vmode ? Math.max(ey, o.minMouseY) : Math.min(ey, o.maxMouseY);
		if (o.maxY != null) ey = o.vmode ? Math.min(ey, o.maxMouseY) : Math.max(ey, o.minMouseY);

		nx = x + ((ex - o.lastMouseX) * (o.hmode ? 1 : -1));
		ny = y + ((ey - o.lastMouseY) * (o.vmode ? 1 : -1));

		if (o.xMapper)		nx = o.xMapper(y)
		else if (o.yMapper)	ny = o.yMapper(x)

		Drag.obj.root.style[o.hmode ? "left" : "right"] = nx + "px";
		Drag.obj.root.style[o.vmode ? "top" : "bottom"] = ny + "px";
		Drag.obj.lastMouseX	= ex;
		Drag.obj.lastMouseY	= ey;

		Drag.obj.root.onDrag(nx, ny);
		return false;
	},

	end : function()
	{
		document.onmousemove = null;
		document.onmouseup   = null;
		Drag.obj.root.onDragEnd(	parseInt(Drag.obj.root.style[Drag.obj.hmode ? "left" : "right"]), 
									parseInt(Drag.obj.root.style[Drag.obj.vmode ? "top" : "bottom"]));
		Drag.obj = null;
	},

	fixE : function(e)
	{
		if (typeof e == 'undefined') e = window.event;
		if (typeof e.layerX == 'undefined') e.layerX = e.offsetX;
		if (typeof e.layerY == 'undefined') e.layerY = e.offsetY;
		return e;
	}
};

//
// getPageSize()
// Returns array with page width, height and window width, height
// Core code from - quirksmode.com
// Edit for Firefox by pHaez
//
function getPageSizeEx(){
	
	var xScroll, yScroll;
	
	if (window.innerHeight && window.scrollMaxY) {	
		xScroll = window.innerWidth + window.scrollMaxX;
		yScroll = window.innerHeight + window.scrollMaxY;
	} else if (document.body.scrollHeight > document.body.offsetHeight){ // all but Explorer Mac
		xScroll = document.body.scrollWidth;
		yScroll = document.body.scrollHeight;
	} else { // Explorer Mac...would also work in Explorer 6 Strict, Mozilla and Safari
		xScroll = document.body.offsetWidth;
		yScroll = document.body.offsetHeight;
	}
	
	var windowWidth, windowHeight;
	
//	console.log(self.innerWidth);
//	console.log(document.documentElement.clientWidth);

	if (self.innerHeight) {	// all except Explorer
		if(document.documentElement.clientWidth){
			windowWidth = document.documentElement.clientWidth; 
		} else {
			windowWidth = self.innerWidth;
		}
		windowHeight = self.innerHeight;
	} else if (document.documentElement && document.documentElement.clientHeight) { // Explorer 6 Strict Mode
		windowWidth = document.documentElement.clientWidth;
		windowHeight = document.documentElement.clientHeight;
	} else if (document.body) { // other Explorers
		windowWidth = document.body.clientWidth;
		windowHeight = document.body.clientHeight;
	}	
	
	// for small pages with total height less then height of the viewport
	if(yScroll < windowHeight){
		pageHeight = windowHeight;
	} else { 
		pageHeight = yScroll;
	}

//	console.log("xScroll " + xScroll)
//	console.log("windowWidth " + windowWidth)

	// for small pages with total width less then width of the viewport
	if(xScroll < windowWidth){	
		pageWidth = xScroll;		
	} else {
		pageWidth = windowWidth;
	}
//	console.log("pageWidth " + pageWidth)

	arrayPageSize = new Array(pageWidth,pageHeight,windowWidth,windowHeight) 
	return arrayPageSize;
}

function pageW() {return window.innerWidth != null? window.innerWidth: document.documentElement && document.documentElement.clientWidth ? document.documentElement.clientWidth:document.body != null? document.body.clientWidth:null;}
function pageH() {return window.innerHeight != null? window.innerHeight: document.documentElement && document.documentElement.clientHeight ? document.documentElement.clientHeight:document.body != null? document.body.clientHeight:null;}
function posL() {return typeof window.pageXOffset != 'undefined' ? window.pageXOffset:document.documentElement && document.documentElement.scrollLeft? document.documentElement.scrollLeft:document.body.scrollLeft? document.body.scrollLeft:0;}
function posT() {return typeof window.pageYOffset != 'undefined' ? window.pageYOffset:document.documentElement && document.documentElement.scrollTop? document.documentElement.scrollTop: document.body.scrollTop?document.body.scrollTop:0;}


function getPageData(poststr) {
	if(poststr==undefined){poststr="";}
	if(document.getElementsByTagName) {
    var objs = document.getElementsByTagName("input");
    for(i=0; i < objs.length; i++){
			
      if(objs.item(i).getAttribute("type")=="button"){
				continue;
			}
      if(objs.item(i).getAttribute("type")=="checkbox"){
				var chk = document.getElementById(objs.item(i).getAttribute("id")).checked
				if(poststr!="")poststr+="&";
        if(chk) {
					poststr += objs.item(i).getAttribute("name") + "=1";
				}
				else {
					poststr += objs.item(i).getAttribute("name") + "=0";					
				}
			}
      else if(objs.item(i).getAttribute("type")=="password" & objs.item(i).getAttribute("name")!="usrpass" & objs.item(i).getAttribute("name")!="password1" & objs.item(i).getAttribute("name")!="password2"){
        if(poststr!="")poststr+="&";
					poststr += objs.item(i).getAttribute("name") + "=" + MD5(objs.item(i).value);
			}
      else {
        if(poststr!="")poststr+="&";
         poststr += objs.item(i).getAttribute("name") + "=" + escape(encodeURI(objs.item(i).value));	
      }
    }
    var objs = document.getElementsByTagName("select");
    for(i=0; i < objs.length; i++){
      if(poststr!="")poststr+="&";
      var iix = objs.item(i).selectedIndex;
      poststr += objs.item(i).getAttribute("name") + "=" + escape(encodeURI(objs.item(i).options[iix].value));		
    }
    var objs = document.getElementsByTagName("textarea");
    for(i=0; i < objs.length; i++){
      if(poststr!="")poststr+="&";
      poststr += objs.item(i).getAttribute("name") + "=" + escape(encodeURI(objs.item(i).value));
    }

  }
	poststr += "&MD5=" + MD5(poststr);
  return poststr;
}

var MD5 = function (string) {
 
	function RotateLeft(lValue, iShiftBits) {
		return (lValue<<iShiftBits) | (lValue>>>(32-iShiftBits));
	}
 
	function AddUnsigned(lX,lY) {
		var lX4,lY4,lX8,lY8,lResult;
		lX8 = (lX & 0x80000000);
		lY8 = (lY & 0x80000000);
		lX4 = (lX & 0x40000000);
		lY4 = (lY & 0x40000000);
		lResult = (lX & 0x3FFFFFFF)+(lY & 0x3FFFFFFF);
		if (lX4 & lY4) {
			return (lResult ^ 0x80000000 ^ lX8 ^ lY8);
		}
		if (lX4 | lY4) {
			if (lResult & 0x40000000) {
				return (lResult ^ 0xC0000000 ^ lX8 ^ lY8);
			} else {
				return (lResult ^ 0x40000000 ^ lX8 ^ lY8);
			}
		} else {
			return (lResult ^ lX8 ^ lY8);
		}
 	}
 
 	function F(x,y,z) { return (x & y) | ((~x) & z); }
 	function G(x,y,z) { return (x & z) | (y & (~z)); }
 	function H(x,y,z) { return (x ^ y ^ z); }
	function I(x,y,z) { return (y ^ (x | (~z))); }
 
	function FF(a,b,c,d,x,s,ac) {
		a = AddUnsigned(a, AddUnsigned(AddUnsigned(F(b, c, d), x), ac));
		return AddUnsigned(RotateLeft(a, s), b);
	};
 
	function GG(a,b,c,d,x,s,ac) {
		a = AddUnsigned(a, AddUnsigned(AddUnsigned(G(b, c, d), x), ac));
		return AddUnsigned(RotateLeft(a, s), b);
	};
 
	function HH(a,b,c,d,x,s,ac) {
		a = AddUnsigned(a, AddUnsigned(AddUnsigned(H(b, c, d), x), ac));
		return AddUnsigned(RotateLeft(a, s), b);
	};
 
	function II(a,b,c,d,x,s,ac) {
		a = AddUnsigned(a, AddUnsigned(AddUnsigned(I(b, c, d), x), ac));
		return AddUnsigned(RotateLeft(a, s), b);
	};
 
	function ConvertToWordArray(string) {
		var lWordCount;
		var lMessageLength = string.length;
		var lNumberOfWords_temp1=lMessageLength + 8;
		var lNumberOfWords_temp2=(lNumberOfWords_temp1-(lNumberOfWords_temp1 % 64))/64;
		var lNumberOfWords = (lNumberOfWords_temp2+1)*16;
		var lWordArray=Array(lNumberOfWords-1);
		var lBytePosition = 0;
		var lByteCount = 0;
		while ( lByteCount < lMessageLength ) {
			lWordCount = (lByteCount-(lByteCount % 4))/4;
			lBytePosition = (lByteCount % 4)*8;
			lWordArray[lWordCount] = (lWordArray[lWordCount] | (string.charCodeAt(lByteCount)<<lBytePosition));
			lByteCount++;
		}
		lWordCount = (lByteCount-(lByteCount % 4))/4;
		lBytePosition = (lByteCount % 4)*8;
		lWordArray[lWordCount] = lWordArray[lWordCount] | (0x80<<lBytePosition);
		lWordArray[lNumberOfWords-2] = lMessageLength<<3;
		lWordArray[lNumberOfWords-1] = lMessageLength>>>29;
		return lWordArray;
	};
 
	function WordToHex(lValue) {
		var WordToHexValue="",WordToHexValue_temp="",lByte,lCount;
		for (lCount = 0;lCount<=3;lCount++) {
			lByte = (lValue>>>(lCount*8)) & 255;
			WordToHexValue_temp = "0" + lByte.toString(16);
			WordToHexValue = WordToHexValue + WordToHexValue_temp.substr(WordToHexValue_temp.length-2,2);
		}
		return WordToHexValue;
	};
 
	function Utf8Encode(string) {
		string = string.replace(/\r\n/g,"\n");
		var utftext = "";
 
		for (var n = 0; n < string.length; n++) {
 
			var c = string.charCodeAt(n);
 
			if (c < 128) {
				utftext += String.fromCharCode(c);
			}
			else if((c > 127) && (c < 2048)) {
				utftext += String.fromCharCode((c >> 6) | 192);
				utftext += String.fromCharCode((c & 63) | 128);
			}
			else {
				utftext += String.fromCharCode((c >> 12) | 224);
				utftext += String.fromCharCode(((c >> 6) & 63) | 128);
				utftext += String.fromCharCode((c & 63) | 128);
			}
 
		}
 
		return utftext;
	};
 
	var x=Array();
	var k,AA,BB,CC,DD,a,b,c,d;
	var S11=7, S12=12, S13=17, S14=22;
	var S21=5, S22=9 , S23=14, S24=20;
	var S31=4, S32=11, S33=16, S34=23;
	var S41=6, S42=10, S43=15, S44=21;
 
	string = Utf8Encode(string);
 
	x = ConvertToWordArray(string);
 
	a = 0x67452301; b = 0xEFCDAB89; c = 0x98BADCFE; d = 0x10325476;
 
	for (k=0;k<x.length;k+=16) {
		AA=a; BB=b; CC=c; DD=d;
		a=FF(a,b,c,d,x[k+0], S11,0xD76AA478);
		d=FF(d,a,b,c,x[k+1], S12,0xE8C7B756);
		c=FF(c,d,a,b,x[k+2], S13,0x242070DB);
		b=FF(b,c,d,a,x[k+3], S14,0xC1BDCEEE);
		a=FF(a,b,c,d,x[k+4], S11,0xF57C0FAF);
		d=FF(d,a,b,c,x[k+5], S12,0x4787C62A);
		c=FF(c,d,a,b,x[k+6], S13,0xA8304613);
		b=FF(b,c,d,a,x[k+7], S14,0xFD469501);
		a=FF(a,b,c,d,x[k+8], S11,0x698098D8);
		d=FF(d,a,b,c,x[k+9], S12,0x8B44F7AF);
		c=FF(c,d,a,b,x[k+10],S13,0xFFFF5BB1);
		b=FF(b,c,d,a,x[k+11],S14,0x895CD7BE);
		a=FF(a,b,c,d,x[k+12],S11,0x6B901122);
		d=FF(d,a,b,c,x[k+13],S12,0xFD987193);
		c=FF(c,d,a,b,x[k+14],S13,0xA679438E);
		b=FF(b,c,d,a,x[k+15],S14,0x49B40821);
		a=GG(a,b,c,d,x[k+1], S21,0xF61E2562);
		d=GG(d,a,b,c,x[k+6], S22,0xC040B340);
		c=GG(c,d,a,b,x[k+11],S23,0x265E5A51);
		b=GG(b,c,d,a,x[k+0], S24,0xE9B6C7AA);
		a=GG(a,b,c,d,x[k+5], S21,0xD62F105D);
		d=GG(d,a,b,c,x[k+10],S22,0x2441453);
		c=GG(c,d,a,b,x[k+15],S23,0xD8A1E681);
		b=GG(b,c,d,a,x[k+4], S24,0xE7D3FBC8);
		a=GG(a,b,c,d,x[k+9], S21,0x21E1CDE6);
		d=GG(d,a,b,c,x[k+14],S22,0xC33707D6);
		c=GG(c,d,a,b,x[k+3], S23,0xF4D50D87);
		b=GG(b,c,d,a,x[k+8], S24,0x455A14ED);
		a=GG(a,b,c,d,x[k+13],S21,0xA9E3E905);
		d=GG(d,a,b,c,x[k+2], S22,0xFCEFA3F8);
		c=GG(c,d,a,b,x[k+7], S23,0x676F02D9);
		b=GG(b,c,d,a,x[k+12],S24,0x8D2A4C8A);
		a=HH(a,b,c,d,x[k+5], S31,0xFFFA3942);
		d=HH(d,a,b,c,x[k+8], S32,0x8771F681);
		c=HH(c,d,a,b,x[k+11],S33,0x6D9D6122);
		b=HH(b,c,d,a,x[k+14],S34,0xFDE5380C);
		a=HH(a,b,c,d,x[k+1], S31,0xA4BEEA44);
		d=HH(d,a,b,c,x[k+4], S32,0x4BDECFA9);
		c=HH(c,d,a,b,x[k+7], S33,0xF6BB4B60);
		b=HH(b,c,d,a,x[k+10],S34,0xBEBFBC70);
		a=HH(a,b,c,d,x[k+13],S31,0x289B7EC6);
		d=HH(d,a,b,c,x[k+0], S32,0xEAA127FA);
		c=HH(c,d,a,b,x[k+3], S33,0xD4EF3085);
		b=HH(b,c,d,a,x[k+6], S34,0x4881D05);
		a=HH(a,b,c,d,x[k+9], S31,0xD9D4D039);
		d=HH(d,a,b,c,x[k+12],S32,0xE6DB99E5);
		c=HH(c,d,a,b,x[k+15],S33,0x1FA27CF8);
		b=HH(b,c,d,a,x[k+2], S34,0xC4AC5665);
		a=II(a,b,c,d,x[k+0], S41,0xF4292244);
		d=II(d,a,b,c,x[k+7], S42,0x432AFF97);
		c=II(c,d,a,b,x[k+14],S43,0xAB9423A7);
		b=II(b,c,d,a,x[k+5], S44,0xFC93A039);
		a=II(a,b,c,d,x[k+12],S41,0x655B59C3);
		d=II(d,a,b,c,x[k+3], S42,0x8F0CCC92);
		c=II(c,d,a,b,x[k+10],S43,0xFFEFF47D);
		b=II(b,c,d,a,x[k+1], S44,0x85845DD1);
		a=II(a,b,c,d,x[k+8], S41,0x6FA87E4F);
		d=II(d,a,b,c,x[k+15],S42,0xFE2CE6E0);
		c=II(c,d,a,b,x[k+6], S43,0xA3014314);
		b=II(b,c,d,a,x[k+13],S44,0x4E0811A1);
		a=II(a,b,c,d,x[k+4], S41,0xF7537E82);
		d=II(d,a,b,c,x[k+11],S42,0xBD3AF235);
		c=II(c,d,a,b,x[k+2], S43,0x2AD7D2BB);
		b=II(b,c,d,a,x[k+9], S44,0xEB86D391);
		a=AddUnsigned(a,AA);
		b=AddUnsigned(b,BB);
		c=AddUnsigned(c,CC);
		d=AddUnsigned(d,DD);
	}
 
	var temp = WordToHex(a)+WordToHex(b)+WordToHex(c)+WordToHex(d);
 
	return temp.toLowerCase();
}


function urlDecode(str){
    str=str.replace(new RegExp('\\+','g'),' ');
    return unescape(str);
}
function urlEncode(str){
    str=escape(str);
    str=str.replace(new RegExp('\\+','g'),'%2B');
    return str.replace(new RegExp('%20','g'),'+');
}
var END_OF_INPUT = -1;
var base64Chars = new Array(
    'A','B','C','D','E','F','G','H',
    'I','J','K','L','M','N','O','P',
    'Q','R','S','T','U','V','W','X',
    'Y','Z','a','b','c','d','e','f',
    'g','h','i','j','k','l','m','n',
    'o','p','q','r','s','t','u','v',
    'w','x','y','z','0','1','2','3',
    '4','5','6','7','8','9','+','/'
);
var reverseBase64Chars = new Array();
for (var i=0; i < base64Chars.length; i++){
    reverseBase64Chars[base64Chars[i]] = i;
}
var base64Str;
var base64Count;
function setBase64Str(str){
    base64Str = str;
    base64Count = 0;
}
function readBase64(){    
    if (!base64Str) return END_OF_INPUT;
    if (base64Count >= base64Str.length) return END_OF_INPUT;
    var c = base64Str.charCodeAt(base64Count) & 0xff;
    base64Count++;
    return c;
}
function encodeBase64(str){
    setBase64Str(str);
    var result = '';
    var inBuffer = new Array(3);
    var lineCount = 0;
    var done = false;
    while (!done && (inBuffer[0] = readBase64()) != END_OF_INPUT){
        inBuffer[1] = readBase64();
        inBuffer[2] = readBase64();
        result += (base64Chars[ inBuffer[0] >> 2 ]);
        if (inBuffer[1] != END_OF_INPUT){
            result += (base64Chars [(( inBuffer[0] << 4 ) & 0x30) | (inBuffer[1] >> 4) ]);
            if (inBuffer[2] != END_OF_INPUT){
                result += (base64Chars [((inBuffer[1] << 2) & 0x3c) | (inBuffer[2] >> 6) ]);
                result += (base64Chars [inBuffer[2] & 0x3F]);
            } else {
                result += (base64Chars [((inBuffer[1] << 2) & 0x3c)]);
                result += ('=');
                done = true;
            }
        } else {
            result += (base64Chars [(( inBuffer[0] << 4 ) & 0x30)]);
            result += ('=');
            result += ('=');
            done = true;
        }
        lineCount += 4;
        if (lineCount >= 76){
            result += ('\n');
            lineCount = 0;
        }
    }
    return result;
}
function readReverseBase64(){   
    if (!base64Str) return END_OF_INPUT;
    while (true){      
        if (base64Count >= base64Str.length) return END_OF_INPUT;
        var nextCharacter = base64Str.charAt(base64Count);
        base64Count++;
        if (reverseBase64Chars[nextCharacter]){
            return reverseBase64Chars[nextCharacter];
        }
        if (nextCharacter == 'A') return 0;
    }
    return END_OF_INPUT;
}
function ntos(n){
    n=n.toString(16);
    if (n.length == 1) n="0"+n;
    n="%"+n;
    return unescape(n);
}
function decodeBase64(str){
    setBase64Str(str);
    var result = "";
    var inBuffer = new Array(4);
    var done = false;
    while (!done && (inBuffer[0] = readReverseBase64()) != END_OF_INPUT
        && (inBuffer[1] = readReverseBase64()) != END_OF_INPUT){
        inBuffer[2] = readReverseBase64();
        inBuffer[3] = readReverseBase64();
        result += ntos((((inBuffer[0] << 2) & 0xff)| inBuffer[1] >> 4));
        if (inBuffer[2] != END_OF_INPUT){
            result +=  ntos((((inBuffer[1] << 4) & 0xff)| inBuffer[2] >> 2));
            if (inBuffer[3] != END_OF_INPUT){
                result +=  ntos((((inBuffer[2] << 6)  & 0xff) | inBuffer[3]));
            } else {
                done = true;
            }
        } else {
            done = true;
        }
    }
    return result;
}
var digitArray = new Array('0','1','2','3','4','5','6','7','8','9','a','b','c','d','e','f');
function toHex(n){
    var result = ''
    var start = true;
    for (var i=32; i>0;){
        i-=4;
        var digit = (n>>i) & 0xf;
        if (!start || digit != 0){
            start = false;
            result += digitArray[digit];
        }
    }
    return (result==''?'0':result);
}
function pad(str, len, pad){
    var result = str;
    for (var i=str.length; i<len; i++){
        result = pad + result;
    }
    return result;
}
function encodeHex(str){
    var result = "";
    for (var i=0; i<str.length; i++){
        result += pad(toHex(str.charCodeAt(i)&0xff),2,'0');
    }
    return result;
}
var hexv = {
  "00":0,"01":1,"02":2,"03":3,"04":4,"05":5,"06":6,"07":7,"08":8,"09":9,"0A":10,"0B":11,"0C":12,"0D":13,"0E":14,"0F":15,
  "10":16,"11":17,"12":18,"13":19,"14":20,"15":21,"16":22,"17":23,"18":24,"19":25,"1A":26,"1B":27,"1C":28,"1D":29,"1E":30,"1F":31,
  "20":32,"21":33,"22":34,"23":35,"24":36,"25":37,"26":38,"27":39,"28":40,"29":41,"2A":42,"2B":43,"2C":44,"2D":45,"2E":46,"2F":47,
  "30":48,"31":49,"32":50,"33":51,"34":52,"35":53,"36":54,"37":55,"38":56,"39":57,"3A":58,"3B":59,"3C":60,"3D":61,"3E":62,"3F":63,
  "40":64,"41":65,"42":66,"43":67,"44":68,"45":69,"46":70,"47":71,"48":72,"49":73,"4A":74,"4B":75,"4C":76,"4D":77,"4E":78,"4F":79,
  "50":80,"51":81,"52":82,"53":83,"54":84,"55":85,"56":86,"57":87,"58":88,"59":89,"5A":90,"5B":91,"5C":92,"5D":93,"5E":94,"5F":95,
  "60":96,"61":97,"62":98,"63":99,"64":100,"65":101,"66":102,"67":103,"68":104,"69":105,"6A":106,"6B":107,"6C":108,"6D":109,"6E":110,"6F":111,
  "70":112,"71":113,"72":114,"73":115,"74":116,"75":117,"76":118,"77":119,"78":120,"79":121,"7A":122,"7B":123,"7C":124,"7D":125,"7E":126,"7F":127,
  "80":128,"81":129,"82":130,"83":131,"84":132,"85":133,"86":134,"87":135,"88":136,"89":137,"8A":138,"8B":139,"8C":140,"8D":141,"8E":142,"8F":143,
  "90":144,"91":145,"92":146,"93":147,"94":148,"95":149,"96":150,"97":151,"98":152,"99":153,"9A":154,"9B":155,"9C":156,"9D":157,"9E":158,"9F":159,
  "A0":160,"A1":161,"A2":162,"A3":163,"A4":164,"A5":165,"A6":166,"A7":167,"A8":168,"A9":169,"AA":170,"AB":171,"AC":172,"AD":173,"AE":174,"AF":175,
  "B0":176,"B1":177,"B2":178,"B3":179,"B4":180,"B5":181,"B6":182,"B7":183,"B8":184,"B9":185,"BA":186,"BB":187,"BC":188,"BD":189,"BE":190,"BF":191,
  "C0":192,"C1":193,"C2":194,"C3":195,"C4":196,"C5":197,"C6":198,"C7":199,"C8":200,"C9":201,"CA":202,"CB":203,"CC":204,"CD":205,"CE":206,"CF":207,
  "D0":208,"D1":209,"D2":210,"D3":211,"D4":212,"D5":213,"D6":214,"D7":215,"D8":216,"D9":217,"DA":218,"DB":219,"DC":220,"DD":221,"DE":222,"DF":223,
  "E0":224,"E1":225,"E2":226,"E3":227,"E4":228,"E5":229,"E6":230,"E7":231,"E8":232,"E9":233,"EA":234,"EB":235,"EC":236,"ED":237,"EE":238,"EF":239,
  "F0":240,"F1":241,"F2":242,"F3":243,"F4":244,"F5":245,"F6":246,"F7":247,"F8":248,"F9":249,"FA":250,"FB":251,"FC":252,"FD":253,"FE":254,"FF":255
};
 
function decodeHex(str){
    str = str.toUpperCase().replace(new RegExp("s/[^0-9A-Z]//g"));
    var result = "";
    var nextchar = "";
    for (var i=0; i<str.length; i++){
        nextchar += str.charAt(i);
        if (nextchar.length == 2){
            result += ntos(hexv[nextchar]);
            nextchar = "";
        }
    }
    return result;
    
}

