function Utils()
{
	this.className = 'Utils';
	this.error = false;
	this.currentIdShowHide = 0;
	this.currentImgArrow = 0;
	this.oAjaxThreads = new Array();
	this.loadingThreads = 0;
	this.temp = new Array();
	this.msgContainer = "";
	this.inputConfirm = "";
	this.msgContainerScreenName = "";
	this.inputConfirmScreenName = "";
	this.controllerCss = "";
	this.viewCss = "";
	this.zspaceBoxes = false;
}

Utils.prototype.getNextThread = function()
{
	var i = 0;
	
	if (this.oAjaxThreads.length == 0)
	{
		var oAjax = new AJAX();
		this.oAjaxThreads.push(oAjax);		
	}

	while (this.oAjaxThreads[i] && this.oAjaxThreads[i].working && i < this.oAjaxThreads.length )
	{
		i++;
	}
	
	if (!this.oAjaxThreads[i])
	{
		var oAjax = new AJAX();
		this.oAjaxThreads.push(oAjax);		
	}
	
	return this.oAjaxThreads[i];
}

Utils.prototype.showHide = function(objId, imgArrow)
{
	var object = document.getElementById(objId);
	if(object)
	{
		if (object.style.display == 'none')
		{
			object.style.display = '';
			if(imgArrow)
			{
				imgArrow.src = "/graphics/arrowup.gif";
			}
		}
		else
		{
			object.style.display = 'none';
			if(imgArrow)
			{
				imgArrow.src = "/graphics/arrowdown.gif";
			}
		}
	}
}

Utils.prototype.showHide2 = function(objId1, objId2)
{
	var object1 = document.getElementById(objId1);
	var object2 = document.getElementById(objId2);
	
	if(object1)
	{
		if (object1.style.display == 'none')
		{
			object1.style.display = '';
			if(object2)
			{
				object2.style.display = 'none';
			}
		}
		else
		{
			object1.style.display = 'none';
			if(object2)
			{
				object2.style.display = '';
			}
		}
	}
}

Utils.prototype.showHideContent = function(objId, imgArrow, notCloseAll)
{
	var object = document.getElementById(objId);
	if(this.currentIdShowHide!=0 && this.currentIdShowHide!=objId)
	{
		if(!notCloseAll)
		{
			document.getElementById(this.currentIdShowHide).style.display = "none";
		}
		this.currentImgArrow.src = "/graphics/arrowdown.gif";
	}
	this.currentIdShowHide = objId;
	this.currentImgArrow = imgArrow;
	if(object)
	{
		if (object.style.display == 'none')
		{
			object.style.display = '';
			if(imgArrow)
			{
				imgArrow.src = "/graphics/arrowup.gif";
			}
		}
		else
		{
			object.style.display = 'none';
			if(imgArrow)
			{
				imgArrow.src = "/graphics/arrowdown.gif";
			}
		}
	}
}

Utils.prototype.stringReplace = function(sp, rp, ss)
{
	if (ss.indexOf(sp) < 0)
	{
		return ss;
	}
	else
	{
		fp = ss.indexOf(sp);
		
		if (fp==0)
		{
			first = true;
		}
		else
		{
			first = false;
		}
		
		if (sp == ss.substr(-(sp.length)))
		{
			last = true;
		}
		else 
		{
			last = false;
		}
		
		rest = ss.split(sp);
		
		if (first == true)
		{
			fs = rp;
		}
		else
		{
			fs = '';
		}
				
		for (i = 0; i < rest.length; i++)
		{
			if (rest[i]!='')
			{
				fs = fs + rest[i] + rp;
			}
		}
		
		if (!last)
		{
			fs = fs.substr(0, (fs.length - rp.length));
		}
		
		return fs;
	}
}

Utils.prototype.showMessage = function(responseText, xmlDocument)
{
	if (responseText.indexOf('xml') > -1)
	{
		response = xmlDocument.getElementsByTagName('response')[0];

		messages = response.getElementsByTagName('message');
		message = messages[0].firstChild.nodeValue;
		
		errors = response.getElementsByTagName('error');
		error = errors[0].firstChild.nodeValue;
		
		if (error != '1')
		{
			this.showSuccessMessage(message);
		}
		else
		{
			this.showErrorMessage(message);
		}
	}
	else
	{	
		this.showErrorMessage('Error: '+responseText.substring(0,100)+'...');
	}
}

Utils.prototype.showSuccessMessage = function(message)
{
	alert(message);
}

Utils.prototype.showErrorMessage = function(message)
{
	alert('Erro: '+message);
	this.error = true;
}

Utils.prototype.formatDate = function(dateSQL)
{
	var dateSQL = dateSQL.toString();
	var arrayDate = dateSQL.split("-");
	
	var year = arrayDate[0];
	var month = arrayDate[1];
	var day = arrayDate[2];
	
	var dateFormated = day+"/"+month+"/"+year;
	
	return dateFormated;
}

Utils.prototype.allTrim = function(sString)
{
	while (sString.substring(0,1) == ' ')
	{
		sString = sString.substring(1, sString.length);
	}
	while (sString.substring(sString.length-1, sString.length) == ' ')
	{
		sString = sString.substring(0,sString.length-1);
	}
	return sString;
}

Utils.prototype.countChar = function(description, spanCount, limit)
{
	var spanCount = document.getElementById(spanCount);
	var description = document.getElementById(description);
	
	if(spanCount && description)
	{
		var lengthDescription = description.value.length;
		if(lengthDescription>limit)
		{
			description.value = description.value.substring(0,limit);	
		}
		else
		{
			oDOMUtils.removeChilds(spanCount);
			spanCount.appendChild(document.createTextNode(lengthDescription));
		}
	}
}

Utils.prototype.setNextPrev = function(id, tipo)
{
	var link = document.getElementById(id);
	
	if(tipo=="proximo")
	{
		var linkNext = document.getElementById('linkNext');
		if(linkNext!=null)
		{
			var linkPaginate = linkNext.getAttribute('href');
			link.setAttribute("href", linkPaginate);
		}
	}
	else if("anterior")
	{
		var linkPrev = document.getElementById('linkPrev');
		if(linkPrev!=null)
		{
			var linkPaginate = linkPrev.getAttribute('href');
			link.setAttribute("href", linkPaginate);
		}
	}
}

Utils.prototype.in_array = function(x, matriz)
{
	var txt = "¬" + matriz.join("¬") + "¬";
	var er = new RegExp ("¬" + x + "¬", "gim");
	return ( (txt.match (er)) ? true : false );
}

Utils.prototype.validateFilters = function()
{
	var form = document.getElementById("filters");
	var validate = false;
	
	if(form.authorFirstName)
	{
		if(form.authorFirstName.value != "")
		{
			validate = true;
		}
	}
	
	if(form.authorLastName)
	{
		if(form.authorLastName.value != "")
		{
			validate = true;
		}
	}
	
	if(form.authorEmail)
	{
		if(form.authorEmail.value != "")
		{
			validate = true;
		}
	}
	
	if(document.getElementById("categoryTopic"))
	{
		if(document.getElementById("categoryTopic").value != "")
		{
			validate = true;
		}
	}
	
	if(document.getElementById("categoryGeo"))
	{
		if(document.getElementById("categoryGeo").value != "")
		{
			validate = true;
		}
	}
	
	if(document.getElementById("articleTypeId"))
	{
		if(document.getElementById("articleTypeId").value != "")
		{
			validate = true;
		}
	}
	
	if(document.getElementById("body"))
	{
		if(document.getElementById("body").value != "")
		{
			validate = true;
		}
	}
	
	if(document.getElementById("content"))
	{
		if(document.getElementById("content").value != "")
		{
			validate = true;
		}
	}
	
	if(document.getElementById("isInterview"))
	{
		if(document.getElementById("isInterview").checked == true)
		{
			validate = true;
		}
	}

	if(document.getElementById("accountTypeId"))
	{
		if(document.getElementById("accountTypeId").value != "")
		{
			validate = true;
		}
	}
	
	if(document.getElementById("donationFrom"))
	{
		if(document.getElementById("donationFrom").value != "")
		{
			validate = true;
		}
	}
	
	if(document.getElementById("donationTo"))
	{
		if(document.getElementById("donationTo").value != "")
		{
			validate = true;
		}
	}
	
	if(document.getElementById("frequency"))
	{
		if(document.getElementById("frequency").value != "")
		{
			validate = true;
		}
	}
	
	if(document.getElementById("donationTypeId"))
	{
		if(document.getElementById("donationTypeId").value != "")
		{
			validate = true;
		}
	}
	
	if(document.getElementById("accountFirstName"))
	{
		if(document.getElementById("accountFirstName").value != "")
		{
			validate = true;
		}
	}
	
	if(document.getElementById("accountLastName"))
	{
		if(document.getElementById("accountLastName").value != "")
		{
			validate = true;
		}
	}
	
	if(document.getElementById("artist"))
	{
		if(document.getElementById("artist").value != "")
		{
			validate = true;
		}
	}
	
	if(document.getElementById("title"))
	{
		if(document.getElementById("title").value != "")
		{
			validate = true;
		}
	}
	
	if(document.getElementById("categoryName"))
	{
		if(document.getElementById("categoryName").value != "")
		{
			validate = true;
		}
	}
	
	if(document.getElementById("categoryType"))
	{
		if(document.getElementById("categoryType").value != "")
		{
			validate = true;
		}
	}
	
	if(document.getElementById("categoryRoot"))
	{
		if(document.getElementById("categoryRoot").value != "")
		{
			validate = true;
		}
	}
	
	if(document.getElementById("categoryLeft"))
	{
		if(document.getElementById("categoryLeft").value != "")
		{
			validate = true;
		}
	}
	
	if(document.getElementById("categoryRight"))
	{
		if(document.getElementById("categoryRight").value != "")
		{
			validate = true;
		}
	}
	
	if(document.getElementById("commentName"))
	{
		if(document.getElementById("commentName").value != "")
		{
			validate = true;
		}
	}
	
	if(document.getElementById("email"))
	{
		if(document.getElementById("email").value != "")
		{
			validate = true;
		}
	}
	
	if(document.getElementById("closedAtS"))
	{
		if(document.getElementById("closedAtS").value != "")
		{
			validate = true;
		}
	}
	
	if(document.getElementById("closedAtF"))
	{
		if(document.getElementById("closedAtF").value != "")
		{
			validate = true;
		}
	}
	
	if(document.getElementById("issueS"))
	{
		if(document.getElementById("issueS").value != "")
		{
			validate = true;
		}
	}
	
	if(document.getElementById("issueF"))
	{
		if(document.getElementById("issueF").value != "")
		{
			validate = true;
		}
	}
	
	if(document.getElementById("createdOnS"))
	{
		if(document.getElementById("createdOnS").value != "")
		{
			validate = true;
		}
	}
	
	if(document.getElementById("createdOnF"))
	{
		if(document.getElementById("createdOnF").value != "")
		{
			validate = true;
		}
	}
	
	if(document.getElementById("addedOnS"))
	{
		if(document.getElementById("addedOnS").value != "")
		{
			validate = true;
		}
	}
	
	if(document.getElementById("addedOnF"))
	{
		if(document.getElementById("addedOnF").value != "")
		{
			validate = true;
		}
	}
	
	if(document.getElementById("holder"))
	{
		if(document.getElementById("holder").value != "")
		{
			validate = true;
		}
	}
	
	if(document.getElementById("accountEmail"))
	{
		if(document.getElementById("accountEmail").value != "")
		{
			validate = true;
		}
	}
	
	if(document.getElementById("address"))
	{
		if(document.getElementById("address").value != "")
		{
			validate = true;
		}
	}
	
	if(document.getElementById("city"))
	{
		if(document.getElementById("city").value != "")
		{
			validate = true;
		}
	}
	
	if(document.getElementById("country"))
	{
		if(document.getElementById("country").value != "")
		{
			validate = true;
		}
	}
	
	if(document.getElementById("commentariesSent"))
	{
		if(document.getElementById("commentariesSent").value != "")
		{
			validate = true;
		}
	}
	
	
	if(validate)
	{
		form.submit();
	}
	else
	{
		alert("Fill a filter");
	}
}

Utils.prototype.setFilter = function(field, type, POST, controller,notOwn)
{
	if(POST)
	{
		document.getElementById("field").value = field;
		document.getElementById("type").value = type;
		this.validateFilters();
	}
	else
	{
		if(notOwn)
		{
			window.location.href = "/admin/"+controller+"/getAllOwn/"+field+"/"+type;
		}
		else
		{
			window.location.href = "/admin/"+controller+"/getAll/"+field+"/"+type;			
		}
	}
}
	
Utils.prototype.checkAll = function(form, checkMaster)
{
	if(form.elements.length>0)
	{
		for(var f=0; f<form.elements.length; f++)
		{
			if(form.elements[f].type == "checkbox")
			{
				if(checkMaster.checked == true)
				{
					form.elements[f].checked = true;
				}
				else
				{
					form.elements[f].checked = false;
				}
			}
		}
	}
}

Utils.prototype.newAttachment = function()
{
	var div = document.getElementById("newAttachments");
	
	var input = document.createElement("input");
	input.setAttribute("type", "file");
	input.setAttribute("name", "attachments[]");
	
	div.appendChild(input);
	div.appendChild(document.createElement("br"));
}

Utils.prototype.createFCK = function(id, width, height, toolbarSet)
{
	 var oFCKeditor = new FCKeditor( id ) ;
     oFCKeditor.Width = width+"px";
     oFCKeditor.Height = height+"px";
     if(toolbarSet!="")
     {
     	oFCKeditor.ToolbarSet = toolbarSet;
     }
	 oFCKeditor.BasePath = "/FCKeditor/" ;
	 oFCKeditor.ReplaceTextarea();
}

Utils.prototype.selectElementMultiple = function(all, select, select_temp)
{
	var Tstrat = document.getElementById(select_temp);
    var Fstrat = document.getElementById(select);
    if(all==1)
    {
    	$("#"+select_temp).copyOptions("#"+select,"all");
       	$("#"+select_temp).removeOption(/./);
    }
    else
    {
    	$("#"+select_temp).copyOptions("#"+select); 
        $("#"+select_temp).removeOption("selected"); 
    }
    $("#"+select).sortOptions();
    this.selectAllElementMultiple(Fstrat, 1); 
}

Utils.prototype.unselectElementMultiple = function(all, select, select_temp)
{
	var Tstrat = document.getElementById(select_temp);
    var Fstrat = document.getElementById(select);
    var ops='';
    if(all==1)
    {
    	$("#"+select).copyOptions("#"+select_temp,"all");
        $("#"+select).removeOption(/./); 
    }
    else
    {
    	$("#"+select).copyOptions("#"+select_temp); 
        $("#"+select).removeOption("selected");
    }     
    $("#"+select_temp).sortOptions();
    this.selectAllElementMultiple(Tstrat, 1); 
}

Utils.prototype.selectAllElementMultiple = function(items, unsel)
{
	if(unsel)
	{
		var select = items;
		for(var s=0;s<select.options.length;s++)
		{
	    	select.options[s].selected = false;   
	  	}
	}
	else
	{
		if(items)
		{
			for(var t=0; t<items.length; t++)
			{
				var select  = document.getElementById(items[t]);
				if(select)
				{
					for(var s=0;s<select.options.length;s++)
					{
				    	select.options[s].selected = true;   
				  	}
				}
			}		
		}
	}
}

Utils.prototype.createJSCalendar = function(fieldId)
{
	Calendar.setup(
	{
		inputField  : fieldId,         // ID of the input field
		ifFormat    : "%Y-%m-%d",    // the date format
		button      : fieldId+"Trigger"       // ID of the button
	});
}

Utils.prototype.cleanSearchField = function(input)
{
	if(input.value=="Search" || input.value=="Basic Search")
	{
		input.value = "";
	}
}

Utils.prototype.showContent = function(id)
{
	var span = document.getElementById(id);
	if(span.style.display == "none")
	{
		span.style.display = "";
	}
	else if(span.style.display == "")
	{
		span.style.display = "none";
	}
}

Utils.prototype.validateMail = function(mailString)
{
	var myRegEx = new RegExp(".+@.+\\.[a-z]+");
	
	if(!myRegEx.test(mailString))
	{
		alert('Invalid mail format.');
	}
	return myRegEx.test(mailString);
}

Utils.prototype.testPassword = function(valor, elementSecurityId) {
   var d = document.getElementById(elementSecurityId);
   var legendText = new Array("Low", "Medium", "High")
   ERaz = /[a-z]/;
   ERAZ = /[A-Z]/;
   ER09 = /[0-9]/;
   ERxx = /[@!#$%&*+=?|-]/;

   if(valor.length == ''){
      d.innerHTML = '&nbsp;';
   } else {
      if(valor.length < 5){
         d.innerHTML = '<font color=\'red\'>'+legendText[0]+'</font>';
      } else {
         if(valor.length > 7 && valor.search(ERaz) != -1 && valor.search(ERAZ) != -1 && valor.search(ER09) != -1 || valor.length > 7 && valor.search(ERaz) != -1 && valor.search(ERAZ) != -1 && valor.search(ERxx) || valor.length > 7 && valor.search(ERaz) != -1 && valor.search(ERxx) != -1 && valor.search(ER09) || valor.length > 7  && valor.search(ERxx) != -1 && valor.search(ERAZ) != -1 && valor.search(ER09)){
            d.innerHTML = '<font color=\'green\'>'+legendText[2]+'</font>';
         } else {
            if(valor.search(ERaz) != -1 && valor.search(ERAZ) != -1 || valor.search(ERaz) != -1 && valor.search(ER09) != -1 || valor.search(ERaz) != -1 && valor.search(ERxx) != -1 ||valor.search(ERAZ) != -1 && valor.search(ER09) != -1 ||valor.search(ERAZ) != -1 && valor.search(ERxx) != -1 ||valor.search(ER09) != -1 && valor.search(ERxx) != -1){
               d.innerHTML = '<font color=\'orange\'>'+legendText[1]+'</font>';
            } else {
               d.innerHTML = '<font color=\'red\'>'+legendText[0]+'</font>';
            }
         }
      }
   }
}

Utils.prototype.setOverlay = function()
{
	var footer = document.getElementById("footer");
	if(footer)
	{
		//var oDebug = new Debug();
		//oDebug.debugObject(footer)
		var diffFromTop = footer.offsetTop;
		var diffOverlayToTop = 265;
		var diffFinal = (diffFromTop-diffOverlayToTop)-60;
		
		if (currentId == "zblog") 
		{
			var divs = getElementsByClassName(document, "div", "zblogs");
			if (divs) {
				for (i = 0; i < divs.length; i++) {
					divs[i].style.height = diffFinal + "px";
				}
			}
		}
		else
		{
			var divs = getElementsByClassName(document, "div", "overlayMini");
			if(divs)
			{
				for(i=0; i<divs.length;i++)
				{
					divs[i].style.height = diffFinal+"px";
				}
			}			
		}
	}
}

Utils.prototype.setQuickChange = function(type)
{
	if(type=='NamePass')
	{
		document.getElementById('sustainerQuickChanges').style.display = '';
		document.getElementById('sustainerQuickEmail').style.display = 'none';
		this.showHide('sustainerQuickNamePass');
		document.getElementById("sustainerRaise").style.display = 'none';
	}
	else if(type=='Email')
	{
		document.getElementById('sustainerQuickChanges').style.display = '';
		document.getElementById('sustainerQuickNamePass').style.display = 'none';
		this.showHide('sustainerQuickEmail');
		document.getElementById("sustainerRaise").style.display = 'none';
	}
	else if(type=='Raise')
	{
		this.showHide('sustainerRaise'); 
		document.getElementById('sustainerQuickChanges').style.display = 'none';
		document.getElementById('sustainerQuickEmail').style.display = 'none';
		document.getElementById('sustainerQuickNamePass').style.display = 'none';
	}
}

Utils.prototype.setMemberQuickChange = function(type)
{
	if(type=='Email')
	{
		document.getElementById('memberQuickChanges').style.display = '';
		document.getElementById('memberQuickNamePass').style.display = 'none';
		this.showHide('memberQuickEmail');
	}
}

Utils.prototype.setZspaceQuickChange = function(type)
{
	if(type=='Raise')
	{
		this.showHide('zspaceRaise'); 
	}
}

Utils.prototype.setWriterQuickChange = function(type)
{
	if(type=='NamePass')
	{
		document.getElementById('writerQuickChanges').style.display = '';
		document.getElementById('writerQuickEmail').style.display = 'none';
		this.showHide('writerQuickNamePass');
		document.getElementById("writerRaise").style.display = 'none';
	}
	else if(type=='Email')
	{
		document.getElementById('writerQuickChanges').style.display = '';
		document.getElementById('writerQuickNamePass').style.display = 'none';
		this.showHide('writerQuickEmail');
		document.getElementById("writerRaise").style.display = 'none';
	}
}

Utils.prototype.checkAmountFrequency = function(formId, type)
{
	var amount = document.getElementById("amount_"+type).value;
	var frequency = document.getElementById("frequency_"+type).options[document.getElementById("frequency_"+type).selectedIndex].value;
	var formOptionsRaise = document.getElementById(formId);
	var validated = false;

	switch(frequency)
	{
		case 'monthly':
			if(amount >= 1)
			{
				validated = true;
			}
		break;
		case 'quarterly':
			if(amount > 4)
			{
				validated = true;
			}
		break;
		case 'semiannually':
			if(amount >= 6)
			{
				validated = true;
			}
		break;
		case 'annually':
			if(amount >= 12)
			{
				validated = true;
			}
		break;
	}

	if(validated)
	{
		formOptionsRaise.submit();
	}
	else
	{
		alert("The amount or frequency are invalid.");
		return false;
	}
}

Utils.prototype.verifyUniqueEmail = function(obj, msgContainer, inputConfirm)
{	
	var isHttps = document.getElementById("isHttps");	
	
	if(!msgContainer)
	{
		msgContainer = 'verify_email';
	}
	
	if(!inputConfirm)
	{
		inputConfirm = 'confirmEmail';
	}
	
	this.msgContainer = msgContainer;
	this.inputConfirm = inputConfirm;
	
	if(obj.value.indexOf(" ") >= "0")
	{
		document.getElementById(this.msgContainer).style.color = '#FF0000';
		document.getElementById(this.msgContainer).innerHTML = 'the email field must not have spaces !';
		document.getElementById(this.inputConfirm).setAttribute('value','2');
	}
	else
	{
		var email = obj.value;
		var oAjax =  this.getNextThread();
		oAjax.url = '/zsustainers/verifyEmail';
		oAjax.method = 'post';
		oAjax.data = 'email='+email;
		if(isHttps)
		{
			if(isHttps.value=="1")
			{
				oAjax.url = 'https://'+document.getElementById("prefix").value+'.zcommunications.org'+oAjax.url;
			}
		}
		oAjax.addRequestListener(this, this.finishUniqueEmail, false);
		oAjax.open();		
	}
}

Utils.prototype.finishUniqueEmail = function(xmlDocument, text)
{
	var oParser = new XMLParser(xmlDocument);
    var email = oParser.getNodeValue('email');
  	document.getElementById(this.msgContainer).style.display = '';

	if(!email || email =="0")
	{
		document.getElementById(this.msgContainer).style.color = '#00AA00';
		document.getElementById(this.msgContainer).innerHTML = 'OK !';
		document.getElementById(this.inputConfirm).setAttribute('value','0');
	}
	else
	{
		document.getElementById(this.inputConfirm).setAttribute('value','1');
		document.getElementById(this.msgContainer).style.color = '#FF0000';
		document.getElementById(this.msgContainer).innerHTML = ' has already been taken.';
	}
}

Utils.prototype.verifyPassword = function(pass2, pass1, verifyField)
{	
	if(!pass1)
	{
		pass1 = "password1";
	}
	
	if(!verifyField)
	{
		verifyField = "verify_password";
	}
	
	if(document.getElementById(pass1).value == pass2.value)
	{
		document.getElementById(verifyField).style.color = '#00AA00';
		document.getElementById(verifyField).innerHTML = 'OK !';
	}
	else
	{
		document.getElementById(verifyField).style.color = '#FF0000';
		document.getElementById(verifyField).innerHTML = 'Password values don\'t match'+'\n !';
	}
}

Utils.prototype.verifyUniqueScreenName = function(obj, msgContainer, inputConfirm)
{	
	var isHttps = document.getElementById("isHttps");	
		
	if(!msgContainer)
	{
		msgContainer = "verify_screenName";
	}
	
	if(!inputConfirm)
	{
		inputConfirm = "confirmScreenName";
	}
	
	this.msgContainerScreenName = msgContainer;
	this.inputConfirmScreenName = inputConfirm;
	
	if(obj.value.indexOf(" ") >= "0")
	{
		document.getElementById(this.msgContainerScreenName).style.color = '#FF0000';
		document.getElementById(this.msgContainerScreenName).innerHTML = 'the screen name field must not have spaces!';
		document.getElementById(this.inputConfirmScreenName).setAttribute('value','2');
	}
	else
	{
		var screenName = obj.value;
		var oAjax =  this.getNextThread();
		oAjax.url = '/zsustainers/verifyScreenName';
		oAjax.method = 'post';
		oAjax.data = 'screenName='+screenName;
		if(isHttps)
		{
			if(isHttps.value=="1")
			{
				oAjax.url = 'https://'+document.getElementById("prefix").value+'.zcommunications.org'+oAjax.url;
			}
		}
		oAjax.addRequestListener(this, this.finishUniqueScreenName, false);
		oAjax.open();
	}
}

Utils.prototype.finishUniqueScreenName = function(xmlDocument, text)
{
	var oParser = new XMLParser(xmlDocument);
    var screenName = oParser.getNodeValue('screenName');
  	document.getElementById(this.msgContainerScreenName).style.display = '';

	if(!screenName || screenName =="0")
	{
		document.getElementById(this.msgContainerScreenName).style.color = '#00AA00';
		document.getElementById(this.msgContainerScreenName).innerHTML = 'OK !';
		document.getElementById(this.inputConfirmScreenName).setAttribute('value','0');
	}
	else
	{
		document.getElementById(this.inputConfirmScreenName).setAttribute('value','1');
		document.getElementById(this.msgContainerScreenName).style.color = '#FF0000';
		document.getElementById(this.msgContainerScreenName).innerHTML = ' has already been taken.';
	}
}

Utils.prototype.expandAll = function(expandLink, arrayImgs)
{
	var display = 'none';
	if(expandLink.innerHTML.search("Hide")>-1)
	{
		display = 'block';
		expandLink.innerHTML = "Expand All";		
	} else {
		expandLink.innerHTML = "Hide All";
	}
	for(var i = 0; i < arrayImgs.length; i++)
	{
		var elementsId = arrayImgs[i].split(",");
		var divElement = document.getElementById(elementsId[0]);
		var imgElement = document.getElementById(elementsId[1]);
		if(divElement)
		{
			divElement.style.display = display;
			this.showHide(divElement.id,imgElement);
		//} else {
		//	alert(arrayImgs[i]);
		}
	}
}

Utils.prototype.checkInputs = function(inputs, inputAll)
{
	if(inputs)
	{
		for(var i=0; i<inputs.length;i++)
		{
			var input = document.getElementById(inputs[i]);
			if(inputAll.checked)
			{
				input.checked = 1;
			}
			else
			{
				input.checked = 0;
			}
		}
	}
}

Utils.prototype.urlencode = function(sStr) 
{
    return escape(sStr).
    replace(/\+/g, '%2B').
    replace(/\"/g,'%22').
    replace(/\'/g, '%27').
    replace(/\//g,'%2F');
}

Utils.prototype.saveFavPage = function(url)
{
	if(url && document.getElementById("controller"))
	{
		document.getElementById("spanFav").style.display = "";
		if(document.getElementById("spanFav2"))
		{
			document.getElementById("spanFav2").style.display = "";
		}
		
		var oAjax =  this.getNextThread();
		oAjax.url = '/znet/saveFavPage';
		oAjax.method = 'post';
		oAjax.data = "url="+url+"&title="+document.title+"&typePage="+document.getElementById("controller").value;
		oAjax.addRequestListener(this, this.finishSaveFavPage, false);
		oAjax.open();	
	}
}

Utils.prototype.finishSaveFavPage = function(data)
{
	document.getElementById("spanFav").style.display = "none";
	if(document.getElementById("spanFav2"))
	{
		document.getElementById("spanFav2").style.display = "none";
	}
	alert('Favorite saved successfully.')
}

Utils.prototype.toggleLayout = function(css, controller, view, menuSlim, zspaceBoxes)
{
	this.controllerCss = controller;
	this.viewCss = view;
	this.zspaceBoxes = zspaceBoxes;
	var onlyReload = false;
	
	if(zspaceBoxes)
	{
		onlyReload = true;
	}
	
	if(!onlyReload)
	{
		var cssStyle = document.getElementById("cssStyle");
		if(cssStyle && css!="")
		{
			var cssStyleHref = new String(cssStyle.getAttribute("href"));
			if(cssStyleHref.indexOf("slim") != -1)
			{
				cssStyle.setAttribute("href", "/themes/"+css+"_large.css");
			}
			else
			{
				cssStyle.setAttribute("href", "/themes/"+css+"_slim.css");		
			}		
		}
	}
	
	var loginMenuSlim = document.getElementById("loginMenuSlim");
	var loginMenu = document.getElementById("loginMenu");
	
	var barInfoSlim = document.getElementById("barInfoSlim");
	var barInfo = document.getElementById("barInfo");
	
	var infoBoxZVid = document.getElementById("infoBoxZVid");
	var infoBoxCurrentIssue = document.getElementById("infoBoxCurrentIssue");
	
	var infoBoxZVidSlim = document.getElementById("infoBoxZVidSlim");
	var infoBoxCurrentIssueSlim = document.getElementById("infoBoxCurrentIssueSlim");
	
	var boxesLayout = "";
	var menuSlim = "";
	
	var loginInputUsernameSlim = document.getElementById("loginInputUsernameSlim");
	var loginInputPasswordSlim = document.getElementById("loginInputPasswordSlim");
		
	var imgLogo = document.getElementById("imgLogo");
	var imgLogoSlim = document.getElementById("imgLogoSlim");
	
	var linkAction = document.getElementById("linkAction");
	var linkActionSlim = document.getElementById("linkActionSlim");
	
	var lastFeaturedBox = document.getElementById("lastFeaturedBox");
	
	if(imgLogoSlim.style.display == "")
	{
		if(!onlyReload)
		{
			imgLogo.style.display = "";
			imgLogoSlim.style.display = "none";
			
			if(loginMenuSlim)
			{
				loginMenuSlim.style.display = "none";
				loginMenu.style.display = "";
			}
			
			if(barInfoSlim)
			{
				barInfoSlim.style.display = "none";
				barInfo.style.display = "";
			}
			
			infoBoxZVid.style.display = "";
			infoBoxCurrentIssue.style.display = "";
			
			if(infoBoxZVidSlim)
			{
				infoBoxZVidSlim.style.display = "none";
				infoBoxCurrentIssueSlim.style.display = "none";
			}
		}
			
		menuSlim = "0";
		if(!zspaceBoxes)
		{
			linkAction.innerHTML = "Small Screen";
			linkActionSlim.innerHTML = "Small Screen";
		}
		
		if(lastFeaturedBox)
		{
			lastFeaturedBox.style.display = "";
		}
	}
	else
	{
		if(!onlyReload)
		{
			imgLogo.style.display = "none";
			imgLogoSlim.style.display = "";
			
			if(loginMenuSlim)
			{
				loginMenuSlim.style.display = "";
				loginMenu.style.display = "none";
			}
			
			if(barInfoSlim)
			{
				barInfoSlim.style.display = "";
				barInfo.style.display = "none";
			}
			
			infoBoxZVid.style.display = "none";
			infoBoxCurrentIssue.style.display = "none";
			
			if(infoBoxZVidSlim)
			{
				infoBoxZVidSlim.style.display = "";
				infoBoxCurrentIssueSlim.style.display = "";
			}
			
			if(loginInputUsernameSlim)
				loginInputUsernameSlim.style.width = "100px";
				
			if(loginInputPasswordSlim)
				loginInputPasswordSlim.style.width = "80px";
		}
		menuSlim = "1";
		
		if(!zspaceBoxes)
		{
			linkAction.innerHTML = "Large Screen";
			linkActionSlim.innerHTML = "Large Screen";
		}
		
		if(lastFeaturedBox)
		{
			lastFeaturedBox.style.display = "none";
		}
	}
	
	var oAjax =  this.getNextThread();
	oAjax.url = '/znet/toggleLayout';
	oAjax.method = 'post';
	if(zspaceBoxes)
		oAjax.data = 'boxesLayout=1';
	else
		oAjax.data = 'menuSlim='+menuSlim;		
	oAjax.addRequestListener(this, this.finishToggleLayout, false);
	oAjax.open();
}

Utils.prototype.finishToggleLayout = function(data)
{
	if(this.zspaceBoxes)
	{
		setTimeout("window.location.reload();", 100);		
	}
}

Utils.prototype.isNumeric = function(strString, floatNumber)
{
	//  check for valid numeric strings
	if(floatNumber)
	{
		var strValidChars = "0123456789.-";	
	}
	else
	{
		var strValidChars = "0123456789";
	}
	
	var strChar;
	var blnResult = true;
	
	if (strString.length == 0) return false;
	
	//  test strString consists of valid characters listed above
	for (i = 0; i < strString.length && blnResult == true; i++)
	{
		strChar = strString.charAt(i);
	    if (strValidChars.indexOf(strChar) == -1)
	    {
	    	blnResult = false;
	    }
	}
	   
	return blnResult;
}

Utils.prototype.revertDonationLevel = function(accountId)
{
	var oAjax = this.getNextThread();
	oAjax.url = '/zsustainers/revertDonationLevel/'+accountId;
	oAjax.method = 'post';
	oAjax.data = '';
	oAjax.addRequestListener(this, this.donationLevelReverted, false);
	document.getElementById('revertLinks').innerHTML = 'Reverting... <img src="/images/loading.gif" />';
	oAjax.open();
}

Utils.prototype.donationLevelReverted = function(xmlDocument, text)
{
	document.getElementById('revertNew').innerHTML = document.getElementById('revertOld').innerHTML;
	alert(text);
	document.getElementById('revertLinks').style.display = 'none';
}

Utils.prototype.addBookmark =  function()
{
	if (document.all)
	{
		window.external.AddFavorite(document.location.href , document.title);
	} 
	else 
	{
		window.sidebar.addPanel(document.title, document.location.href,""); 
	}
}

Utils.prototype.truncate = function(trunc, len)
{
  if (trunc.length > len) 
  {
    trunc = trunc.substring(0, len);
    trunc = trunc.replace(/\w+$/, '');
    
    trunc += "...";
  }
  
  return trunc;
}

Utils.prototype.setDivEventPos = function(event, id, offsetLeft)
{
	//IE hack
	// Calculate pageX/Y if missing and clientX/Y available
	if ( event.pageX == undefined && event.clientX != undefined ) {
		var e = document.documentElement, b = document.body;
		event.pageX = event.clientX + (e.scrollLeft || b.scrollLeft);
		event.pageY = event.clientY + (e.scrollTop || b.scrollTop);
	}
	
	var pageX = event.pageX;
	var pageY = event.pageY;
	
	if(offsetLeft)
	{
		pageX = pageX-offsetLeft;
	}
	
	var x = pageX+'px';
	var y = pageY+'px';
	
	$("#"+id).css("left", x);
	$("#"+id).css("top", y);
}

Utils.prototype.strip_tags = function(str, allowed_tags) 
{
    // http://kevin.vanzonneveld.net
    // +   original by: Kevin van Zonneveld (http://kevin.vanzonneveld.net)
    // +   improved by: Luke Godfrey
    // +      input by: Pul
    // +   bugfixed by: Kevin van Zonneveld (http://kevin.vanzonneveld.net)
    // +   bugfixed by: Onno Marsman
    // +      input by: Alex
    // +   bugfixed by: Kevin van Zonneveld (http://kevin.vanzonneveld.net)
    // +      input by: Marc Palau
    // +   improved by: Kevin van Zonneveld (http://kevin.vanzonneveld.net)
    // *     example 1: strip_tags('<p>Kevin</p> <br /><b>van</b> <i>Zonneveld</i>', '<i><b>');
    // *     returns 1: 'Kevin <b>van</b> <i>Zonneveld</i>'
    // *     example 2: strip_tags('<p>Kevin <img src="someimage.png" onmouseover="someFunction()">van <i>Zonneveld</i></p>', '<p>');
    // *     returns 2: '<p>Kevin van Zonneveld</p>'
    // *     example 3: strip_tags("<a href='http://kevin.vanzonneveld.net'>Kevin van Zonneveld</a>", "<a>");
    // *     returns 3: '<a href='http://kevin.vanzonneveld.net'>Kevin van Zonneveld</a>'
 
    var key = '', tag = '', allowed = false;
    var matches = allowed_array = [];
 
    var replacer = function(search, replace, str) {
        return str.split(search).join(replace);
    };
 
    // Build allowes tags associative array
    if (allowed_tags) {
        allowed_array = allowed_tags.match(/([a-zA-Z]+)/gi);
    }
  
    str += '';
 
    // Match tags
    matches = str.match(/(<\/?[^>]+>)/gi);
 
    // Go through all HTML tags
    for (key in matches) {
        if (isNaN(key)) {
            // IE7 Hack
            continue;
        }
 
        // Save HTML tag
        html = matches[key].toString();
 
        // Is tag not in allowed list? Remove from str!
        allowed = false;
 
        // Go through all allowed tags
        for (k in allowed_array) {
            // Init
            allowed_tag = allowed_array[k];
            i = -1;
 
            if (i != 0) { i = html.toLowerCase().indexOf('<'+allowed_tag+'>');}
            if (i != 0) { i = html.toLowerCase().indexOf('<'+allowed_tag+' ');}
            if (i != 0) { i = html.toLowerCase().indexOf('</'+allowed_tag)   ;}
 
            // Determine
            if (i == 0) {
                allowed = true;
                break;
            }
        }
 
        if (!allowed) {
            str = replacer(html, "", str); // Custom replace. No regexing
        }
    }
 
    return str;
}

Utils.prototype.validateNumeric = function(field)
{
	if(!this.isNumeric(field.value)) 
	{
		field.value = '';
		alert('This field must be a number.');
		field.focus();		
	}
}

var oUtils = new Utils();