//////////////////////////////////////////////////////////////////////////////////////
//																					//
//								BASIC CMS FUNCTIONS									//
//																					//
//////////////////////////////////////////////////////////////////////////////////////

var IsIE = !!(window.attachEvent && !window.opera);
var IsOpera = !!window.opera;
var IsMozilla = navigator.userAgent.indexOf('Gecko') > -1 && navigator.userAgent.indexOf('KHTML') == -1;
function HexString(number){if (number < 0){number = 0xFFFFFFFF + number + 1;}return number.toString(16).toUpperCase();}
function RandomID(){return Math.floor(Math.random() * (2147483647-(-2147483648)+1)) +(-2147483648);}
function __(href,w,h,r){var width=arguments.length<2?900:w;var height=arguments.length<3?600:h;var resize=arguments.length<4?'yes':r;window.open(href+(href.indexOf('?')<0?'?':'&')+'window=' + HexString(RandomID()),HexString(RandomID()),'width='+width+',height='+height+',resizable=no,scrollbars='+resize+'');}
function __InsertScripts(s) {
   var myRegExp = new RegExp('<\s*script.*?>(.*?)<\s*/script\s*>','g');
   var scripts = s.match(myRegExp);
   if (scripts) for (var i=0; i<scripts.length; i++) {
       var scripttag = window.document.createElement('script');
       var scriptcontent = scripts[i].substring(scripts[i].indexOf('>')+1,scripts[i].lastIndexOf('<'));
       try {scripttag.appendChild(window.document.createTextNode(scriptcontent));}
       catch(e) {scripttag.text = scriptcontent;} //IE
       window.document.getElementsByTagName('head')[0].appendChild(scripttag);
   }
}

function trim(str, chars) {
	return ltrim(rtrim(str, chars), chars);
}
 
function ltrim(str, chars) {
	chars = chars || "\\s";
	return str.replace(new RegExp("^[" + chars + "]+", "g"), "");
}
 
function rtrim(str, chars) {
	chars = chars || "\\s";
	return str.replace(new RegExp("[" + chars + "]+$", "g"), "");
}
function formatCurrency(strValue){
		strValue = strValue.toString().replace(/\$|\,/g,'');
		dblValue = parseFloat(strValue);
		blnSign = (dblValue == (dblValue = Math.abs(dblValue)));
		dblValue = Math.floor(dblValue*100+0.50000000001);
		intCents = dblValue%100;
		strCents = intCents.toString();
		dblValue = Math.floor(dblValue/100).toString();
		if(intCents<10)
			strCents = "0" + strCents;
		for (var i = 0; i < Math.floor((dblValue.length-(1+i))/3); i++)
			dblValue = dblValue.substring(0,dblValue.length-(4*i+3))+'.'+
			dblValue.substring(dblValue.length-(4*i+3));
		return (((blnSign)?'':'-') +  dblValue + ',' + strCents).replace('.','');
	}

var prototypeWindow;
function __Layer(href,width,height,options,caption){
	var w=820;if(width!=null)w=width;
	var h=590;if(height!=null)h=height;
	if(prototypeWindow!=null){
		if(prototypeWindow.getSize['width']!=w || prototypeWindow.getSize['height']!=h)prototypeWindow.setSize(w, h);
		prototypeWindow.setAjaxContent(href, options, true, false);
	}
	else{
		prototypeWindow = new Window({
			className: "alphacube", 
			title: (caption!=null?caption:''), 
			destroyOnClose: true, 
			recenterAuto:true,
			minimizable:false,
			maximizable:false,
			resizable:true,
			maxWidth:990,
			maxHeight:500, 
			minWidth:200,
			minHeight:150,
			width:w,
			height:h
		});
		prototypeWindow.setAjaxContent(href, options, true, true);
		prototypeWindowObserver = { 
				onDestroy: function(eventName, win) { 
					if (win == prototypeWindow) { 
						prototypeWindow = null; 
						Windows.removeObserver(this); 
					} 
				}
		} 
		Windows.addObserver(prototypeWindowObserver); 
	}
	
}


//////////////////////////////////////////////////////////////////////////////////////
//																					//
//								CONTENT MENU CUNCTION								//
//																					//
//////////////////////////////////////////////////////////////////////////////////////
var ContextMenu = Class.create({
  initialize: function(idelement, classname, iddbitem, url) {
      this.idelement = idelement;
      this.classname = classname;
      this.iddbitem = iddbitem;
      this.url=url;
      this.timer=null; 
  },
  Appear: function() {
  	if($('ContextMenuDiv'+this.idelement)==null){
      	var angor = $('ContextMenu'+this.idelement); 
  		var div = new Element('div'); 
  		div.id='ContextMenuDiv'+this.idelement;
  		div.style.position = 'absolute'; 
  		div.style.top = (angor.cumulativeOffset().top + angor.getHeight()) + 'px';
  		div.style.left = angor.cumulativeOffset().left + 'px';
  		angor.onmouseout=function(){
			if(this.timer!=null){clearTimeout(this.timer);this.timer=null;}
			this.timer=setTimeout(function(){
				if(div!=null)div.hide();
				clearTimeout(this.timer);
				this.timer=null;
			}, 500);
			
  		}.bind(this);
      	new Ajax.Request(this.url,{ 
      		method: 'POST',
      		parameters: {ClassName:this.classname,idDBItem:this.iddbitem},
      		onSuccess: function(transport) {
      			
      			if(trim(transport.responseText)!=''){
      				div.update(transport.responseText);
          			$(document.body).insert(div);
          			div.addClassName('ContextMenu');
          			var lis = div.getElementsByTagName('a'); 
          			for (var i=0; i<lis.length; i++) { 
          				lis[i].onmouseover=function() { 
          					if(this.timer!=null){clearTimeout(this.timer);this.timer=null;}
          					this.Appear.bind(this);
          				}.bind(this); 
          				lis[i].onmouseout=function() { 
    	  					this.timer=setTimeout(function(){
    							if(div!=null)div.hide();
    							clearTimeout(this.timer);
    							this.timer=null;
    						}, 100);      					
          				}.bind(this); 
          			} 
      			}
      			else{angor.src=angor.src.replace('gear16', 'geargrey16');}
      			
      		}.bind(this)
        });
  	}
  	else{$('ContextMenuDiv'+this.idelement).show();}
  	
  }
});

//////////////////////////////////////////////////////////////////////////////////////
//																					//
//										LIGHTVIEW									//
//																					//
//////////////////////////////////////////////////////////////////////////////////////



