if (typeof UPOC == "undefined" || !UPOC) {
    var UPOC = {};
}

UPOC.Util = {};

UPOC.Util.censor = function(text){
    if (text != null && text != ""){
        var censorPart = "sh1t shyt fcuk phuck fuck shit cum motherfuck mothafuck muthafuck";
        var censorPartArray = censorPart.split(" ");

        censorPartArray.each(function(item){
            var censorExp = new RegExp(item , "gim");
            text = text.replace(censorExp, "****************".slice(0, item.length));
        });

        //basic censor from string
        var censorString = "fuck fucks fucked fucking fcuk fuk fuking phuck phucking phuc shit sh1t shyt shitting sh1tting shytting pussy cunt cunts cuntz cock cocks dick dicks dicked dck dcks tit tits azz azzes ass asses niger nigers suck sucking clit clits balls bitch bitches bitchiz anal arse bastard bastards butt butts coon coons kike kikes cum cumming damn dildo dildos douche douches faggot faggots faggotz fart farts farted jizz jizzing jizzed nigger niggers niggaz niggre niggres nipple nipples penis penises shaft piss pissing queer queers screw screwing scrotum scrotum twat twats pu$$y $hit shyt pus$y pu$sy horny horney masturbate masterbate masturbating masterbating kum kumming 4uck sex mofo mofos mofoz muthafucka motherfucker muthafuckah n*gga sexx bytch bytches bytchez ";
        var censorArray = censorString.split(" ");

         // censor bad words
        censorArray.each(function(item){
            var censorExp = new RegExp("\\b" + item + "\\b", "gim");
            text = text.replace(censorExp, "****************".slice(0, item.length));
        });

        //censor phone numbers
        //phoneReg = new RegExp(/((\+\d{1,3}[^\d]*\(?\d\)?[^\d]*\d{1,5})|(\(?\d{2,6}\)?))[^\d]*(\d{3,4})[^\d]*(\d{4})(( x| ext)\d{1,5}){0,1}$/gim);
        phoneReg = new RegExp(/([^0-9A-Za-z]*\d){7,11}/gim);
        phoneReg2 = new RegExp(/([0-9]{10})/gim);
        text = text.replace(phoneReg, "**********");
        text = text.replace(phoneReg2,"**********");

        //strip html tags
        text = text.replace(/</g,"&lt;");
        text = text.replace(/>/g,"&gt;");
    }
    return text;
};

UPOC.Util.charCount = function(theTextField, theCountField, maxlimit){
    // update counter
    theCountField.value = maxlimit - theTextField.value.length;
    if(theTextField.value.length > 119)
    theTextField.value = theTextField.value.substring(0, 119);
};

//for menu dropdowns in IE6
UPOC.Util.hoverNav = function(){
  var sfEls = document.getElementById("Menu").getElementsByTagName("LI");
  for (var i=0; i<sfEls.length; i++) {
		sfEls[i].onmouseover=function() {
			this.className+=" sfhover";
			//alert(i);
		}
		sfEls[i].onmouseout=function() {
			this.className=this.className.replace(new RegExp("sfhover\\b"), "");
		}
	}
};

UPOC.Util.sourceToType = function(strCode){

  if(strCode == "WAP"  ){ return {'src': 'assets/images/mobile.gif', 'alt': 'mobile'}; }
  if(strCode == "SMPP" ){ return {'src': 'assets/images/mobile.gif', 'alt': 'mobile'}; }
  if(strCode == "EMAILSMS" ){ return {'src': 'assets/images/mobile.gif', 'alt': 'mobile'}; }
  if(strCode == "EMAILMMS" ){ return {'src': 'assets/images/mobile.gif', 'alt': 'mobile'}; }
  if(strCode == "WEB"  ){ return {'src': 'assets/images/web.gif', 'alt': 'web'}; }
  if(strCode == "EMAIL"){ return {'src': 'assets/images/web.gif', 'alt': 'web'}; }
  if(strCode == "APP"  ){ return {'src': 'assets/images/web.gif', 'alt': 'web'}; }
  if(strCode == "NONE"  ){ return {'src': 'assets/images/web.gif', 'alt': 'web'}; }
  if(strCode == "MODEMSMS"  ){ return {'src': 'assets/images/web.gif', 'alt': 'mobile'}; }
  if(strCode == "API"  ){ return {'src': 'assets/images/web.gif', 'alt': 'web'}; }
  if(strCode == "IVR"  ){ return {'src': 'assets/images/web.gif', 'alt': 'web'}; }
  if(strCode == "IM"  ){ return {'src': 'assets/images/web.gif', 'alt': 'web'}; }
  if(strCode == "XML"  ){ return {'src': 'assets/images/web.gif', 'alt': 'web'}; }
  if(strCode == "SYSTEM"  ){ return {'src': 'assets/images/web.gif', 'alt': 'web'}; }
  if(strCode == "IVRAUTO"  ){ return {'src': 'assets/images/web.gif', 'alt': 'web'}; }
  if(strCode == "EMAILPAG"  ){ return {'src': 'assets/images/web.gif', 'alt': 'web'}; }
  if(strCode == "WRLS_EML"  ){ return {'src': 'assets/images/web.gif', 'alt': 'web'}; }
  if(strCode == "BREW"  ){ return {'src': 'assets/images/web.gif', 'alt': 'web'}; }
  if(strCode == "AWS_CHAT"  ){ return {'src': 'assets/images/web.gif', 'alt': 'web'}; }
  if(strCode == "CARRIER"  ){ return {'src': 'assets/images/web.gif', 'alt': 'web'}; }

//MODEMSMS SMS via cell modem
//APP Handset application
//API API
//WEB Web UI.
//IVR IVR UI.
//IM Messenger UI.
//WAP WAP UI.
//EMAIL Email UI.
//XML XML UI.
//SYSTEM SystemUI.
//IVRAUTO Autogened text msgs
//EMAILSMS mobile orig SMS.
//EMAILPAG mobile orig text pag
//SMPP SMPP UI.
//WRLS_EML Wireless emaildevice
//NONE No interface.
//BREW BREW UI
//AWS_CHAT ATT Wireless UI
//EMAILMMS MMS from phone
//CARRIER Carrier Signup Tool
  //What do we want for this??
  //if(strCode == "IVR"  ){ return 1; } 
}

UPOC.Util.timeSincePost = function(postTime){

	var days, hours, minutes, seconds, timeElapsed;
	var currentTime = new Date();



	timeElapsed = currentTime.getTime() - postTime;
	if(timeElapsed == 0){timeElapsed = 1000}
	if(timeElapsed < 0){timeElapsed = 1000}

	days = (timeElapsed / (1000 * 60 * 60 * 24));
	days = days - (days % 1);

	timeElapsed -= (days * 1000 * 60 * 60 * 24);

	hours = (timeElapsed / (1000 * 60 * 60));
	hours = hours - (hours % 1);
	timeElapsed -= (hours * 1000 * 60 * 60);

	minutes = (timeElapsed / (1000 * 60));
	minutes = minutes - (minutes % 1);
	timeElapsed -= (minutes * 1000 * 60);

	seconds = (timeElapsed / (1000));
	seconds = seconds - (seconds % 1);
	timeElapsed -= (seconds * 1000);

	//alert("days " + days + " hours " + hours + " minutes " + minutes + " seconds " + seconds );

	if(days){
		var returnDays = days + " day";
		if(days > 1){ returnDays += "s"}
		return returnDays;
	}
	if(hours){
		var returnHours = hours + " hour"
		if(hours > 1){ returnHours += "s"}
		return returnHours;
	}
	if(minutes){
		var returnMinutes = minutes + " minute";
		if(minutes > 1){ returnMinutes += "s"}
		return returnMinutes;
	}
	if(seconds){
		var returnSeconds = seconds + " second";
		if(seconds > 1){ returnSeconds += "s"}
		if (seconds < 1){'1'}
		return returnSeconds;
	}
}

// Link-like styliing for non-A tags, necessary for IE6as it does not support pseudo-classes in css.
UPOC.Util.fakeLink = function(elClass, cssClass) {
	var e = document.getElementsByClassName(elClass);
	for (var i=0; i<e.length; i++) {e[i].onmouseover=function() {this.className+= (cssClass);}
		e[i].onmouseout=function() {this.className=this.className.replace(new RegExp(cssClass), "");}
	}
};

UPOC.Util.moreLink = function(el, target){
	var more = new Fx.Slide(target);
	var tog=false;
	more.hide();

	$(el).addEvent('click', function(e){
	e = new Event(e);
	more.toggle();
	if (tog==false){
		$(el).setText('Less(-)');
		tog=true;
		}else{
			$(el).setText('More(+)');
			tog=false;
			}
	});
};