var Pyxis = { VERSION: '1.1' };
Pyxis.Util =
{
    clickCount:0,
	doClick:function(functionToExecute)
    {	
		Pyxis.Util.clickCount++;
        setTimeout(function(){
            var typeOfClick = Pyxis.Util.checkClick();
			if(typeOfClick=="singleClick"){
				functionToExecute();
				Pyxis.Util.clickCount--;
			}
        }, 600);	
		return true;
    },
	checkClick:function()
    {
        return Pyxis.Util.clickCount == 1? "singleClick": "doubleClick";
    },
	doDoubleClick:function(functionToExecute)
    {		
		functionToExecute();		
		Pyxis.Util.clickCount = 0;
		return true;
    },	
	show: function(id){ if($(id)){Element.show($(id));} },
	hide: function(id){ if($(id)){Element.hide($(id));} },
	showAll: function(ids){ ids.each(function(id){Pyxis.Util.show(id)}); },
	hideAll: function(ids){ ids.each(function(id){Pyxis.Util.hide(id)}); },
	switchView: function(switchShow, switchHide){ Pyxis.Util.hide(switchHide); Pyxis.Util.show(switchShow); },
	isVisible: function(id){ return $(id) && Element.visible($(id)); },
	stopObserving: function(id, name, handler){if($(id)){Event.stopObserving(id, name, handler);}},
	innerValue: function(id){ return ($(id) ? $(id).innerHTML : '');},
	write: function(id, content){ if($(id)){$(id).innerHTML = content; }},
	highLight: function(id, time){ if($(id)){new Effect.Highlight($(id), {duration:time,queue:'parallel'});}},
	setClassName: function(id, className){ if($(id)){$(id).className = className; }},
	setBackground: function(id, bcColor){ if($(id)){$(id).style.backgroundColor = bcColor;}},
	setValue:function(id, value){ if($(id)){$(id).value = value; }},
	setValueWithHTML:function(id, htmlId){ if($(id)){$(id).value=Pyxis.Util.trim(Pyxis.Util.innerValue(htmlId)); }},
	destroy:function(id){ if($(id)){ $(id).remove(); }},
	trim:function(s){ 
		if(!s)return ""; 
		s = s.replace( /^\s+/g, "" ); 
		s = s.replace( /&lt;/g, "<" ); 
		s = s.replace( /&gt;/g, ">" ); 
		return s; 
	},
	findPos: function(obj){ var curleft = curtop = 0; if(obj.offsetParent) { curleft = obj.offsetLeft; curtop = obj.offsetTop; while (obj = obj.offsetParent) { curleft += obj.offsetLeft; curtop += obj.offsetTop; } } return [curleft,curtop]; },
	getPopup:function(popupId, left, top, z){$(popupId).style.top=top+'px';$(popupId).style.left=left+'px';$(popupId).style.position="absolute";$(popupId).style.visibility="visible";if(z){$(popupId).style.zIndex=z;} return $(popupId);},
	toDate:function(s){ var d = '';	for(var i=0; i<s.length; i++){ if((s.charAt(i) >= "0") && (s.charAt(i) <= "9")){ var j=i; while((s.charAt(j) >= "0") && (s.charAt(j) <= "9") && j<s.length) d=d+s.charAt(j++); d=d+s.charAt(j+1)+' '; i=j+2; } } return d; },
	toggle:function(id){if($(id)){if($F(id)){$(id).checked='';}else{$(id).checked='checked';} }},
	setValue: function(id, value) {if ($(id)) $(id).value = value; },
	inputFocus: function(element, className){ element.className = className; element.value = ''; },
	selectionText: function(element){return element.options[element.selectedIndex].text;},
	forceWidth: function(id , size){if(!!(window.attachEvent && !window.opera)) $(id).style.width=size;},
	windownDim: function() {
	  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;
	  }
	  return [myWidth, myHeight];
	},
	charCounter: function(event, id, max, counterId){ 
		if($F(id).length > max) $(id).value = $F(id).substring(0, max);
		Pyxis.Util.write(counterId, ""+(max - $F(id).length));
	},
	verifyKeyCode: function(evt){
		var charCode = (evt.which) ? evt.which : evt.keyCode;
		if (charCode == 95 || charCode == 33 || charCode == 32 || charCode == 8){ return true; }
		if (charCode > 43 && charCode < 60){ return true; }
		if (charCode > 64 && charCode < 91){ return true; }
		if (charCode > 96 && charCode < 123){ return true; }
		return false;
	},
	isNumKey: function(evt){
		var charCode = (evt.which) ? evt.which : evt.keyCode;
		if (charCode > 47 && charCode < 58){ return true; }
		return false;
	},
	isSelectionModifier: function(e){
		var mac = (navigator.appVersion.indexOf("Mac")!==-1) ? true : false;
		return e.ctrlKey || ((mac && e.metaKey) || (!mac && e.altKey));
	},
	handleTextAreaDoubleClicked:function(e)
	{
		if(!e) var e = window.event;	
		e.cancelBubble = true;
		e.returnValue = false;	
		if (e.stopPropagation) {
			e.stopPropagation();
			e.preventDefault();
		}
	},
	switchParent: function (parentKey){
		$$('div[id^=parent_]').each(function(sub){Pyxis.Util.hide(sub)}); 
		Pyxis.Util.show('parent_'+parentKey);
	},
	switchPage: function (parentKey, pageNo){
		// pages_PRIO-14_1
		$$('div[id^=pages_'+parentKey+']').each(function(page){Pyxis.Util.hide(page)}); 
		Pyxis.Util.show('pages_'+parentKey+'_'+pageNo);
	},
	verifyNumInput:function(evt){
		var charCode = (evt.which) ? evt.which : evt.keyCode;
		if(charCode == 8 || charCode == 46) return true; // Backspace, Delete
		else if(charCode > 34 && charCode < 41) return true; // Arrows, End, Home
		else return Pyxis.Util.isNumKey(evt);
	},
	isNumKey:function(evt){
		var charCode = (evt.which) ? evt.which : evt.keyCode;
		if (charCode > 47 && charCode < 58){ return true; }
		return false;
	},
	checkNumAndPop:function(event, pop){
		if(Pyxis.Util.verifyNumInput(event)){
			Pyxis.Util.show(pop);
			return true;
		}
		else return false;
	},
	getKeyValuePair: function(id, attrib)
	{
		var list = "";
		$$('*[id^="+ id +"]').each(function(e){
				var id=e.readAttribute(attrib);
				var val= e.value
				if(id!=null && typeof val!='undefined')
				{
					key+= id+",";
					value+= val+",";
				}
		});
	},
	toPath: function(string){ return string.replace(/\\/g, "/");}
};