/*
  $Id: general.js,v 1.1.1.1 2005/01/15 06:43:52 Michael Sasek Exp $

  osCommerce, Open Source E-Commerce Solutions
  http://www.oscommerce.com

  Copyright (c) 2003 osCommerce

  Released under the GNU General Public License
*/

onLoadList = new Array();

function SetFocus(TargetFormName) {
  var target = 0;
  if (TargetFormName != "") {
    for (i=0; i<document.forms.length; i++) {
      if (document.forms[i].name == TargetFormName) {
        target = i;
        break;
      }
    }
  }

  var TargetForm = document.forms[target];
    
  for (i=0; i<TargetForm.length; i++) {
    if ( (TargetForm.elements[i].type != "image") && (TargetForm.elements[i].type != "hidden") && (TargetForm.elements[i].type != "reset") && (TargetForm.elements[i].type != "submit") ) {
      TargetForm.elements[i].focus();

      if ( (TargetForm.elements[i].type == "text") || (TargetForm.elements[i].type == "password") ) {
        TargetForm.elements[i].select();
      }

      break;
    }
  }
}

function RemoveFormatString(TargetElement, FormatString) {
  if (TargetElement.value == FormatString) {
    TargetElement.value = "";
  }

  TargetElement.select();
}

function CheckDateRange(from, to) {
  if (Date.parse(from.value) <= Date.parse(to.value)) {
    return true;
  } else {
    return false;
  }
}

function IsValidDate(DateToCheck, FormatString) {
  var strDateToCheck;
  var strDateToCheckArray;
  var strFormatArray;
  var strFormatString;
  var strDay;
  var strMonth;
  var strYear;
  var intday;
  var intMonth;
  var intYear;
  var intDateSeparatorIdx = -1;
  var intFormatSeparatorIdx = -1;
  var strSeparatorArray = new Array("-"," ","/",".");
  var strMonthArray = new Array("jan","feb","mar","apr","may","jun","jul","aug","sep","oct","nov","dec");
  var intDaysArray = new Array(31, 28, 31, 30, 31, 30, 31, 31, 30, 31, 30, 31);

  strDateToCheck = DateToCheck.toLowerCase();
  strFormatString = FormatString.toLowerCase();
  
  if (strDateToCheck.length != strFormatString.length) {
    return false;
  }

  for (i=0; i<strSeparatorArray.length; i++) {
    if (strFormatString.indexOf(strSeparatorArray[i]) != -1) {
      intFormatSeparatorIdx = i;
      break;
    }
  }

  for (i=0; i<strSeparatorArray.length; i++) {
    if (strDateToCheck.indexOf(strSeparatorArray[i]) != -1) {
      intDateSeparatorIdx = i;
      break;
    }
  }

  if (intDateSeparatorIdx != intFormatSeparatorIdx) {
    return false;
  }

  if (intDateSeparatorIdx != -1) {
    strFormatArray = strFormatString.split(strSeparatorArray[intFormatSeparatorIdx]);
    if (strFormatArray.length != 3) {
      return false;
    }

    strDateToCheckArray = strDateToCheck.split(strSeparatorArray[intDateSeparatorIdx]);
    if (strDateToCheckArray.length != 3) {
      return false;
    }

    for (i=0; i<strFormatArray.length; i++) {
      if (strFormatArray[i] == 'mm' || strFormatArray[i] == 'mmm') {
        strMonth = strDateToCheckArray[i];
      }

      if (strFormatArray[i] == 'dd') {
        strDay = strDateToCheckArray[i];
      }

      if (strFormatArray[i] == 'yyyy') {
        strYear = strDateToCheckArray[i];
      }
    }
  } else {
    if (FormatString.length > 7) {
      if (strFormatString.indexOf('mmm') == -1) {
        strMonth = strDateToCheck.substring(strFormatString.indexOf('mm'), 2);
      } else {
        strMonth = strDateToCheck.substring(strFormatString.indexOf('mmm'), 3);
      }

      strDay = strDateToCheck.substring(strFormatString.indexOf('dd'), 2);
      strYear = strDateToCheck.substring(strFormatString.indexOf('yyyy'), 2);
    } else {
      return false;
    }
  }

  if (strYear.length != 4) {
    return false;
  }

  intday = parseInt(strDay, 10);
  if (isNaN(intday)) {
    return false;
  }
  if (intday < 1) {
    return false;
  }

  intMonth = parseInt(strMonth, 10);
  if (isNaN(intMonth)) {
    for (i=0; i<strMonthArray.length; i++) {
      if (strMonth == strMonthArray[i]) {
        intMonth = i+1;
        break;
      }
    }
    if (isNaN(intMonth)) {
      return false;
    }
  }
  if (intMonth > 12 || intMonth < 1) {
    return false;
  }

  intYear = parseInt(strYear, 10);
  if (isNaN(intYear)) {
    return false;
  }
  if (IsLeapYear(intYear) == true) {
    intDaysArray[1] = 29;
  }

  if (intday > intDaysArray[intMonth - 1]) {
    return false;
  }
  
  return true;
}

function IsLeapYear(intYear) {
  if (intYear % 100 == 0) {
    if (intYear % 400 == 0) {
      return true;
    }
  } else {
    if ((intYear % 4) == 0) {
      return true;
    }
  }

  return false;
}

function CVVPopUpWindow(url) {
	window.open(url,'popupWindow','toolbar=no,location=no,directories=no,status=no,menubar=no,scrollbars=no,resizable=no,copyhistory=no,width=600,height=233,screenX=150,screenY=150,top=150,left=150')
}

function popupImage(url, imageHeight, imageWidth) {
	var newImageHeight = (parseInt(imageHeight) + 40);
	var yPos = ((screen.height / 2) - (parseInt(newImageHeight) / 2));
	var xPos = ((screen.width / 2) - (parseInt(imageWidth) / 2));

	imageWindow = window.open(url,'popupImages','toolbar=no,location=no,directories=no,status=yes,menubar=no,scrollbars=no,resizable=yes,copyhistory=no,width=' + imageWidth + ',height=' + newImageHeight + ',screenY=' + yPos + ',screenX=' + xPos + ',top=' + yPos + ',left=' + xPos);

	imageWindow.moveTo(xPos, yPos);
	imageWindow.resizeTo(parseInt(imageWidth), parseInt(newImageHeight));

	if (window.focus) {
		imageWindow.focus();
	}
}

function popupWindow(url, scroll) {
  window.open(url,'popupWindow','toolbar=no,location=no,directories=no,status=no,menubar=no,scrollbars=' + (scroll ? 'yes' : 'no') + ',resizable=yes,copyhistory=no,width=100,height=100,screenX=150,screenY=150,top=150,left=150')
}

var i=0;
function resize() {
  if (navigator.appName == 'Netscape') i=10;
  if (document.images[0]) {
  imgHeight = document.images[0].height+65-i;
  imgWidth = document.images[0].width+30;
  var height = screen.height;
  var width = screen.width;
  var leftpos = width / 2 - imgWidth / 2;
  var toppos = height / 2 - imgHeight / 2; 
  window.moveTo(leftpos, toppos);  
  window.resizeTo(imgWidth, imgHeight);
  }
  self.focus();
}




//functii adaugate de Dan

var offsetfrommouse=[15,25]; //image x,y offsets from cursor position in pixels. Enter 0,0 for no offset
var displayduration=0; //duration in seconds image should remain visible. 0 for always.

var defaultimageheight = 40;	// maximum image size.
var defaultimagewidth = 40;	// maximum image size.

var timer;

function gettrailobj(){
if (document.getElementById)
return document.getElementById("preview_div").style
}

function gettrailobjnostyle(){
if (document.getElementById)
return document.getElementById("preview_div")
}


function truebody(){
return (!window.opera && document.compatMode && document.compatMode!="BackCompat")? document.documentElement : document.body
}


function hidetrail(){	
	gettrailobj().display= "none";
	document.onmousemove="";
	gettrailobj().left="-500px";
	clearTimeout(timer);
}

function showtrail(imagename,title,width,height){
	i = imagename;
	t = title;
	w = width;
	h = height;
	timer = setTimeout("show('"+i+"',t,w,h);",200);
}
function show(imagename,title,width,height){
 
    var docwidth=document.all? truebody().scrollLeft+truebody().clientWidth : pageXOffset+window.innerWidth - offsetfrommouse[0];
	var docheight=document.all? Math.min(truebody().scrollHeight, truebody().clientHeight) : Math.min(window.innerHeight);

	if( (navigator.userAgent.indexOf("Konqueror")==-1  || navigator.userAgent.indexOf("Firefox")!=-1 || (navigator.userAgent.indexOf("Opera")==-1 && navigator.appVersion.indexOf("MSIE")!=-1)) && (docwidth>650 && docheight>500)) {
		( width == 0 ) ? width = defaultimagewidth: '';
		( height == 0 ) ? height = defaultimageheight: '';
			
		width+=30;
		height+=55;
		defaultimageheight = height;
		defaultimagewidth = width;
	
		document.onmousemove=followmouse; 

		newHTML = '<table cellpadding="0" cellspacing="0" border="1" bgcolor="#b8bbc9"><tr><td style="padding-top:5px; padding-bottom:5px; padding-left:5px; padding-right:5px" width="320" height="250" valign="top">' ;
		newHTML = newHTML +	'<div class="border_preview" style="width:'+  width +'px;height:'+ height +'px"><div id="loader_container"><div id="loader"><div align="center"></div><div id="loader_bg"><div id="progress"></div></div></div></div>'	;
		
		
    	newHTML = newHTML + '<div class="preview_temp_load"><img onload="javascript:remove_loading();" src="' + imagename + '" border="0"></div>';
		newHTML = newHTML + '<div align="left">' + ' '+title + '</div>';
		newHTML = newHTML + '</div></td></tr></table>'; 
		
		//if(navigator.userAgent.indexOf("MSIE")!=-1 && navigator.userAgent.indexOf("Opera")==-1 ){
		//	newHTML = newHTML+'<iframe src="about:blank" scrolling="no" frameborder="0" width="'+width+'" height="'+height+'"></iframe>';
		//}		

		gettrailobjnostyle().innerHTML = newHTML;
		gettrailobj().display="block";
	}
}

function followmouse(e){

	var xcoord=offsetfrommouse[0];
	var ycoord=offsetfrommouse[1];

	var docwidth=document.all? truebody().scrollLeft+truebody().clientWidth : pageXOffset+window.innerWidth-15;
	var docheight=document.all? Math.min(truebody().scrollHeight, truebody().clientHeight) : Math.min(window.innerHeight);

	if (typeof e != "undefined"){
		if (docwidth - e.pageX < defaultimagewidth + 2*offsetfrommouse[0]){
			xcoord = e.pageX - xcoord - defaultimagewidth; // Move to the left side of the cursor
		} else {
			xcoord += e.pageX;
		}
		if (docheight - e.pageY < defaultimageheight + 2*offsetfrommouse[1]){
			ycoord += e.pageY - Math.max(0,(2*offsetfrommouse[1] + defaultimageheight + e.pageY - docheight - truebody().scrollTop));
		} else {
			ycoord += e.pageY;
		}

	} else if (typeof window.event != "undefined"){
		if (docwidth - event.clientX < defaultimagewidth + 2*offsetfrommouse[0]){
			xcoord = event.clientX + truebody().scrollLeft - xcoord - defaultimagewidth; // Move to the left side of the cursor
		} else {
			xcoord += truebody().scrollLeft+event.clientX
		}
		if (docheight - event.clientY < (defaultimageheight + 2*offsetfrommouse[1])){
			ycoord += event.clientY + truebody().scrollTop - Math.max(0,(2*offsetfrommouse[1] + defaultimageheight + event.clientY - docheight));
		} else {
			ycoord += truebody().scrollTop + event.clientY;
		}
	}
	gettrailobj().left=xcoord+"px";
	gettrailobj().top=ycoord+"px";

}



// ------------------------------------------------------------------------------------------------------------------------------------------------------------------------------
// Server.Class.js
// ------------------------------------------------------------------------------------------------------------------------------------------------------------------------------
/**
	Class Server
	
	Handles a AJAX comunication with the server. Interacts with the 
PHP Application class, using the "resource" protocol
*/

function Server(url) {
	// methods
	this.show = this.load = serverLoad;
	this.hide = serverHide;
	this.unhide = serverUnhide;
	this.process = serverProcess;
	
	this.onProcess = null;

	// public members
	this.loadInto = null;
	this.url = url;
	this.className = 'Server';
	this.params = '';
	this.onLoad = null;
	this.onBeforeLoad = null;
	
	this.data = null;
	
	this.post = null;
	
	this.method = 'GET';
	
	// private members
	this.__loadInto = null;
	this.__draw = serverDraw;
}

function serverLoad(extraParams, into, syncron) {
	if ( extraParams == null ) extraParams = '';
	this.__loadInto = (into != null) ? into : this.loadInto;
	
	/*
	if (! this.__loadInto ) {
		return false;
	}
	*/
	
	var async = syncron ? false : true;
	
	var url = 
			this.url
			+ this.params
			+ extraParams;
			
	//alert(url);
	
	// create a copy of this
	var _this = this;
	
	// setting the xmlDoc
	var xmlDoc;
	if ( typeof window.ActiveXObject != 'undefined' ) {
		xmlDoc = new ActiveXObject("Microsoft.XMLHTTP");
		xmlDoc.onreadystatechange = function(){_this.process()};
	}
	else {
		xmlDoc = new XMLHttpRequest();
		xmlDoc.onload = function(){_this.process()};
	}
	
	this.xmlDoc = xmlDoc;
	
	if ( this.onBeforeLoad ) {
		if ( this.onBeforeLoad() == false ) {
			return false;
		}
	}
	
	this.xmlDoc.open(this.method, url, async);
	
	if ( this.method == 'POST' ) {
		this.xmlDoc.setRequestHeader("Content-type", "application/x-www-form-urlencoded");
		this.xmlDoc.setRequestHeader("Content-length", this.post.length);
		this.xmlDoc.setRequestHeader("Connection", "close");
	}
	
	this.xmlDoc.send(this.post);
	
	//alert(url + ' ' + this.method + ': ' + this.post);
}

function serverHide() {
	if (! this.loadInto ) {
		return false;
	}
	
	this.loadInto.style.display = 'none';
}

function serverUnhide() {
	if (! this.loadInto ) {
		return false;
	}
	
	this.loadInto.style.display = '';
}

function serverProcess() {
	if ( this.xmlDoc.readyState != 4 ) return;
	
	if ( this.onLoad ) {
		this.onLoad();
	}
	else {
		this.__draw();
		
	}
}

function serverDraw() {
	if (! this.__loadInto ) {
		return false;
	}
	
	this.__loadInto.style.display = '';
	this.__loadInto.innerHTML = this.xmlDoc.responseText;
}



// ------------------------------------------------------------------------------------------------------------------------------------------------------------------------------
// Dialog.Class.js
// ------------------------------------------------------------------------------------------------------------------------------------------------------------------------------
function Dialog(elemId, drawInto, drawCallback) {
		// properties
		this.elemId = elemId;

		this.instance = ++Dialog.instances;
		
		this.timer = null;
		
		this.interval = 30; // in ms
		this.steps = 4;
		
		this.step = 0;
		this.event = null; // will be set by the callers of this.animate()
		
		this.width = null;
		this.height = null;
		this.x = null;
		this.y = null;
		
		this.left = 0;
		this.right = 0;
		this.top = 0;
		this.bottom = 0;
		
		this.visible = false;
		this.loaded = false;
		
		if ( drawInto ) {
			this.drawInto = drawInto;
		}
		else {
			this.drawInto = 'dialogs';
		}
		
		// methods
		this.setPosition = dialogSetPosition;
		this.setSize = dialogSetSize;
		
		this.load = dialogLoad;
		
		this.show = dialogShow;
		this.hide = dialogHide;
		
		this.attach = dialogAttach;
		this.setup = dialogSetup;
		
		this.startAnimation = dialogStartAnimation;
		this.stopAnimation = dialogStopAnimation;
		
		this.transition = dialogTransition;
		
		// event callbacks
		this.onTimer = dialogOnTimer;
		
		if ( drawCallback && typeof(drawCallback) == 'function' ) {
			this.draw = drawCallback;
		}
		else {
			this.draw = dialogDraw;
		}
		
		this.onBeforeLoad = dialogOnBeforeLoad;
		this.onLoad = dialogOnLoad;
		
		this.onBeforeShow = null;
		this.onShowTimer = dialogOnShowTimer;
		this.onShowStep = dialogOnShowStep;
		this.onShow = null;
		
		this.onBeforeHide = null;
		this.onHideTimer = dialogOnHideTimer;
		this.onHideStep = dialogOnHideStep;
		this.onHide = null;
		
		this.generate = dialogGenerate;
		this.redraw = dialogRedraw;
		
		// init
		this.setup(elemId);
		this.attach();
		
		this.transparency = false;
		
		// different data container
		this.data = new Array();
}

Dialog.instances = 0;
Dialog.timers = new Array();


/* moves the dialog to a specified coordonate */
/* 
	@param int x	Defines the horizontal absolute coordonate. If positive, will alter the LEFT position. If negative, will alter the RIGHT position, setting RIGHT = abs(x)
	@param int y	Defines the vertical absolute coordonate. If positive, will alter the TOP position. If negative, will alter the BOTTOM position, setting BOTTOM = abs(y)
*/
function dialogSetPosition(x, y) {
	this.x = x;
	this.y = y;
	
	this.left = 0;
	this.right = 0;
	this.top = 0;
	this.bottom = 0;
	
	this.elem.style.left = '';
	this.elem.style.right = '';
	this.elem.style.top = '';
	this.elem.style.bottom = '';

	if ( x > 0 ) {
		this.left = x;
		this.elem.style.left = this.left + 'px';
	}
	else {
		this.right = (-x);
		this.elem.style.right = this.right + 'px';
	}
	
	if ( y > 0 ) {
		this.top = y;
		this.elem.style.top = this.top + 'px';
	}
	else {
		this.bottom = (-y);
		this.elem.style.bottom = this.bottom + 'px';
	}
}

/* resizes the dialog */
function dialogSetSize(w, h) {
	this.width = w;
	this.height = h;
}

/* loads the dialog contents from an external source via ajax */
function dialogLoad(uri) {
	if ( this.loaded == uri ) {
		return false;
	}
	
	this.uri = uri;
	
	this.server = new Server(this.uri);
	
	this.server.data = new Array();
	this.server.data['dialog'] = this;
	
	this.server.onBeforeLoad = this.onBeforeLoad;
	
	var dialog = this;
	
	this.server.onLoad = function () {
		dialog.loaded = uri;
		
		if ( dialog.onLoad ) {
			dialog.onLoad();
		}
	}
	
	this.server.load('', getObj(this.elemId + 'Content') );
}

/* attaches the dialog to the specified page object, given by id */
function dialogAttach() {
	// deattaching from an old element, if exists
	if ( this.elem ) {
		this.elem.dialog = null;
	}
	
	this.elem.dialog = this;
}

/* displays the dialog, using the specified transition efects */
function dialogShow() {
	if ( this.visible ) {
		//return false;
	}
	
	if ( this.onBeforeShow != null ) {
		if (! this.onBeforeShow() ) {
			return false;
		}
	}
	
	if ( this.debug ) alert("Show " + this.elemId);
	
	this.event = 'show';
	this.startAnimation();
	
	return true;
}

/* hides the dialog, using the specified transition efects */
function dialogHide() {
	if (! this.visible ) {
		//return false;
	}
	
	if ( this.onBeforeHide != null ) {
		if (! this.onBeforeHide() ) {
			return false;
		}
	}
	
	this.event = 'hide';
	this.startAnimation();
	
	return true;
}

/* sets up the dialog before show */
function dialogSetup() {
	if ( elem = getObj(this.elemId) ) {
		// the id is already defined, we use it
		this.elem = elem;
	}
	else {
		// generating the dialog..
		this.generate( this.draw() );
		
		// and storing it..
		this.elem = getObj(this.elemId);
	}
}

/* re-draws the dialog containing html */
function dialogRedraw() {
	this.generate( this.draw() );
}

/* animates the dialog display */
function dialogStartAnimation() {
	// stop the last timer if set
	
	if ( this.timer ) {
		this.stopAnimation();
	}
	
	var dialog = this;
	
	this.timer = setInterval(
		function() {
			dialog.step++;
			if (! dialog.onTimer() ) {
				dialog.stopAnimation();
			}
		}
		,
		this.interval
	);
	
	if ( this.debug ) alert("Timer set for " + this.event + '!');
	
	this.step = 0;
}

/* stops the animation timer */
function dialogStopAnimation() {
	if ( this.timer ) {
		clearInterval(this.timer);
		this.timer = null;
		
		if ( this.debug ) alert("Timer cleared for " + this.event + "!");
	}

	this.step = 0;
}

function dialogOnTimer() {
	if ( this.event == 'show' ) {
		return this.onShowTimer();
	}
	else if ( this.event == 'hide' ) {
		return this.onHideTimer();
	}
	else {
		return false;
	}
}

function dialogOnShowTimer(dialog) {
	if ( this.step == 1 ) {
		this.elem.style.marginLeft = 0;
		this.elem.style.marginRight = 0;
		this.elem.style.marginTop = 0;
		this.elem.style.marginBottom = 0;
		
		this.elem.className = 'dialogLoading';
	}
	
	this.onShowStep();
	
	if ( this.step == this.steps ) {
		this.elem.className = 'dialog';
		this.visible = true;
		if ( this.onShow ) {
			this.onShow();
		}
		return false;
	}
	else {
		return true;
	}
}

function dialogOnHideTimer(dialog) {
	if ( this.step == 1 ) {
		this.elem.style.marginLeft = 0;
		this.elem.style.marginRight = 0;
		this.elem.style.marginTop = 0;
		this.elem.style.marginBottom = 0;
		this.elem.className = 'dialogLoading';
	}
	
	this.onHideStep();
	
	if ( this.step == this.steps ) {
		this.elem.className = 'dialogHidden';
		this.visible = false;
		if (  this.onHide ) {
			this.onHide();
		}
		return false;
	}
	else {
		return true;
	}
}

function dialogOnShowStep() {
	this.transition( this.step / this.steps );
}

function dialogOnHideStep() {
	this.transition( (this.steps - this.step) / this.steps );
}

function dialogTransition(amountOpen) {
	var w = Math.ceil( amountOpen * this.width );
	var h = Math.ceil( amountOpen * this.height );
	var marginH = Math.ceil( (this.width - w) / 2 );
	var marginV = Math.ceil( (this.height - h) / 2 );
	
	this.elem.style.width = w + 'px';
	this.elem.style.height = h + 'px';
	
	if ( this.x > 0 ) {
		this.elem.style.marginLeft = marginH + 'px';
	}
	else {
		this.elem.style.marginRight = marginH + 'px';
	}
	
	if ( this.y > 0 ) {
		this.elem.style.marginTop = marginV + 'px';
	}
	else {
		this.elem.style.marginBottom = marginV + 'px';
	}
	
	if ( this.debug ) alert(
		  "this.transition (" + this.event + ")\nClass: " + this.elem.className + "\n" + amountOpen
		  	+ "\nTop: " + this.elem.style.top
		  	+ "\nLeft: " + this.elem.style.left
			 + "\nRight: " + this.elem.style.right
		  + "\nMargin: " + this.elem.style.marginTop + ' ' + this.elem.style.marginRight + ' ' + this.elem.style.marginBottom + ' ' + this.elem.style.marginLeft
		  );
		  
	if ( this.transparency ) {
		var opacity = Math.ceil(amountOpen * 90 );
		setOpacity(this.elem, opacity);
	}
	else {
		setOpacity(this.elem, 100);
	}
}

function dialogDraw() {
	var content = 
		''
		+ '<div class="dialogHidden" id="' + this.elemId + '">'
			// Modified by ByColor - 2010.06.26
			// Div-iditis...
			//+ '<div class="br">'
				//+ '<div class="bl">'
					//+ '<div class="tl">'
						//+ '<div class="tr">'
							+ '<a class="close" href="javascript:void(0)" onclick="hideDialog(\'' + this.elemId + '\')">'
							+ '</a>'
							+ '	<div class="content" id="' + this.elemId + 'Content">'
							+ '<br class="clearfloat" />'
							+ '	</div>'
						//+ '</div>'
					//+ '</div>'
				//+ '</div>'
			//+ '</div>'
			// End Modified by ByColor - 2010.06.26
		+ '</div>'
	;
	
	return content;
}

function dialogGenerate(content) {
	getObj(this.drawInto).innerHTML = content;
}

function dialogOnBeforeLoad() {
	var content = getObj(this.data['dialog'].elemId+'Content');
	content.innerHTML = '<div class="loading"><img src="images/loading.gif" /></div>';
}

function dialogOnLoad() {
	this.server.__draw();
}

/************************************************/

function getDialog(elemId, drawInto, drawCallback) {
	if ( ( elem = getObj(elemId) ) && elem.dialog )  {
		dialog = elem.dialog;
	}
	else {
		dialog = new Dialog(elemId, drawInto, drawCallback);
	}
	
	return dialog;
}

function showDialog(elemId, width, height, x, y, loadFromUri) {
	dialog = getDialog(elemId);
	dialog.setSize(width, height);
	
	if ( x && y ) {
		dialog.setPosition(x, y);
	}
	
	if ( loadFromUri ) {
		dialog.load(loadFromUri);
	}
	
	dialog.show();
}

function hideDialog(elemId) {
	dialog = getDialog(elemId);
	dialog.hide();
}



// ------------------------------------------------------------------------------------------------------------------------------------------------------------------------------
// slick.js
// ------------------------------------------------------------------------------------------------------------------------------------------------------------------------------
/* general functions */
	function getWidth(elemId) {
		return getObj(elemId).offsetWidth;
	}
	
	function getHeight(elemId) {
		return getObj(elemId).offsetHeight;
	}

	function erase(elemId) {
		getObj(elemId).value = '';
	}
	
	function completeIfNotNull(elemId, value) {
		if (! getObj(elemId).value ) {
			getObj(elemId).value = value;
		}
	}

	function show(elemId) {
		var elem = getObj(elemId);
		
		if ( elem ) {
			elem.className = 'visible';
		}
	}
	
	function hide(elemId) {
		var elem = getObj(elemId);
		alert(elem);
		
		if ( elem ) {
			elem.className = 'invisible';
		}
	}

	function findPosX(obj)
	{
		var curleft = 0;
		if (obj.offsetParent)
		{
			while (obj.offsetParent)
			{
				curleft += obj.offsetLeft
				obj = obj.offsetParent;
			}
		}
		else if (obj.x)
			curleft += obj.x;
		return curleft;
	}
	
	function findPosY(obj)
	{
		var curtop = 0;
		if (obj.offsetParent)
		{
			while (obj.offsetParent)
			{
				curtop += obj.offsetTop
				obj = obj.offsetParent;
			}
		}
		else if (obj.y)
			curtop += obj.y;
		return curtop;
	}
	
	
	function move(obj, x, y) {
		obj.style.position = 'absolute';
		obj.style.top = y + 'px';
		obj.style.left = x + 'px';
		obj.style.display = '';
	}
	
	function getObj(elemId) {
		return document.getElementById(elemId);
	}
	
	function clientWidth() {
		return filterResults (
			window.innerWidth ? window.innerWidth : 0,
			document.documentElement ? document.documentElement.clientWidth : 0,
			document.body ? document.body.clientWidth : 0
		);
	}
	
	function clientHeight() {
		return filterResults (
			window.innerHeight ? window.innerHeight : 0,
			document.documentElement ? ( document.documentElement.clientHeight > 100 ? document.documentElement.clientHeight : 0 ) : 0,
			document.body ? ( document.body.clientHeight > 100 ? document.body.clientHeight : 0 ) : 0
		);
	}
	
	function scrollLeft() {
		return filterResults (
			window.pageXOffset ? window.pageXOffset : 0,
			document.documentElement ? document.documentElement.scrollLeft : 0,
			document.body ? document.body.scrollLeft : 0
		);
	}
	
	function scrollTop() {
		return filterResults (
			window.pageYOffset ? window.pageYOffset : 0,
			document.documentElement ? document.documentElement.scrollTop : 0,
			document.body ? document.body.scrollTop : 0
		);
	}
	
	function filterResults(n_win, n_docel, n_body) {
		var n_result = n_win ? n_win : 0;
		if (n_docel && (!n_result || (n_result > n_docel)))
			n_result = n_docel;
		return n_body && (!n_result || (n_result > n_body)) ? n_body : n_result;
	}
	
	function urlencode(s) {
		s = escape(s);
		/*
		while ( s.indexOf('/') != -1 ) {
			s = s.replace('/', '%' + "/".charCodeAt(0)); // %47
		}
		
		while ( s.indexOf('+') != -1 ) {
			s = s.replace('+', '%' + " ".charCodeAt(0)); // $20
		}
		*/
		return s;
	}


/* change or restore an element's css class*/

	function changeClass(elem, newClass) {
		if (! elem.oldClass ) {
			elem.oldClass = elem.className;
		}
		
		elem.className = newClass;
	}
	
	function restoreClass(elem) {
		elem.className = elem.oldClass;
	}




/* transparency functions */

	var ie = (document.all) ? 1 : 0;
	var p = (ie) ? "filter" : "MozOpacity";
	
	function setOpacity(element, opacity) {
		v = (ie) ? "alpha(opacity:"+opacity+")" : opacity/100;
		element.style[p] = v;
		element.style['opacity'] = v;
	}


/* dialogs functions */
	function dialogSimpleDraw() {
		var content = 
			''
			// Modified by ByColor - 2010.06.26
			+ '<div class="dialogHidden" id="' + this.elemId + '">'
				+ '<div class="dialogContent">'
					+ '<a class="close" href="javascript:void(0)" onclick="hideDialog(\'' + this.elemId + '\')">'
					+ '</a>'
					+ '	<div class="content" id="' + this.elemId + 'Content">'
					+ '	</div>'
				+ '</div>'
				+ '<br class="clearfloat" />'
			+ '</div>'
			// End Modified by ByColor - 2010.06.26
		;
		
		return content;
	}


/* search dialog */

	function searchDialogOnLoad() {
		this.server.__draw();
		
		this.onShow();
	}
	
	function searchDialogOnShow() {
		if ( this.loaded ) {
			getObj('advancedSearchInput').value = this.data['searchText'];
		}
	}
	
	function showSearchDialog() {
		var searchText = getObj('quickSearchInput').value;
		
		dialog = getDialog('advancedSearchDialog123');
		
		//dialog.debug = true;
		
		dialog.data = new Array();
		dialog.data['searchText'] = searchText;
		
		dialog.setSize(400, 350);
		
		dialog.setPosition(-40, findPosY(getObj('advancedSearch'))-175);
		
		dialog.onLoad = searchDialogOnLoad;
		
		dialog.onShow = searchDialogOnShow;

		dialog.load('/ajax_advanced_search.php');
		
		dialog.show();
	}




// product dialog

	function productDialogOnLoad() {
		this.server.__draw();
	}
	
	function productDialogOnBeforeShow() {
		if ( Dialog.productDialogOpen && Dialog.productDialogOpen != this.elemId ) {
			//hideDialog(Dialog.productDialogOpen);
		}
		
		Dialog.productDialogOpen = this.elemId;
		
		return true;
	}
		
	function productDialogOnBeforeHide() {
		Dialog.productDialogOpen = null;
		
		return true;
	}
	
	Dialog.productDialogOpen = null;
	
	function showProductDialog(productId) {
		width = 550;
		height = 450;
		// Modified by ByColor - 2010.06.26
		height = 480;
		// End Modified by ByColor - 2010.06.26
		
		//alert( scrollLeft() + ', ' + scrollTop() );
		//alert( clientWidth() + ', ' + clientHeight() );
		
		dialog = getDialog('productDescription' + productId);
		dialog.setSize(width, height);
		
		//dialog.debug = true;
		
		dialog.onBeforeShow = productDialogOnBeforeShow;
		dialog.onBeforeHide = productDialogOnBeforeHide;
		
		dialog.setPosition(
			scrollLeft() + clientWidth()/2 - width/2,
			scrollTop() + clientHeight()/2 - width/2 + 100
		);
		
		dialog.load('/ajax_product_info.php?products_id=' + productId);
		
		dialog.onLoad = productDialogOnLoad;
		
		dialog.show();
	}
	
// information dialog
	Dialog.popupOpen = null;

	function informationDialogOnLoad() {
		this.server.__draw();
	}
	
	function informationDialogOnBeforeShow() {
		if ( Dialog.popupOpen && Dialog.popupOpen != this.elemId ) {
			hideDialog(Dialog.popupOpen);
		}
		
		Dialog.popupOpen = this.elemId;
		
		return true;
	}
		
	function informationDialogOnBeforeHide() {
		if ( dialog.hideTimer ) {
			clearTimeout( dialog.hideTimer );
			dialog.hideTimer = null;
		}
		
		Dialog.popupOpen = null;
		
		return true;
	}
	
	function showInformationDialog(elemId, left, top, width, height) {
		//width = 140;
		//height = 200;
	
		window.status = elemId;
		dialog = getDialog(elemId);

		if ( dialog.hideTimer ) {
			clearTimeout( dialog.hideTimer );
			dialog.hideTimer = null;
		}
		
		if ( dialog.visible ) {
			return false;
		}
		
		dialog.setSize(width, height);
		
		//dialog.debug = true;
		
		dialog.onBeforeShow = informationDialogOnBeforeShow;
		dialog.onBeforeHide = informationDialogOnBeforeHide;
		
		dialog.setPosition(
			findPosX( getObj('customerMenu') ) + 55,
			findPosY( getObj('customerMenu') ) + 20
		);
		
		dialog.onLoad = informationDialogOnLoad;
		
		dialog.show();
	}
	
	function hideInformationDialog(name) {
		dialog = getDialog(name);
		
		if ( dialog.hideTimer ) {
			clearTimeout( dialog.hideTimer );
			dialog.hideTimer = null;
		}

		window.status = "hideDialog('" + name + "')";
	
		dialog.hideTimer = setTimeout(
			"hideDialog('" + name + "')", 
			500
		);
	}
	
	
// customer info dialog

	function customerInfoDialogOnLoad() {
		this.server.__draw();
	}
	
	function customerInfoDialogOnBeforeShow() {
		if ( Dialog.popupOpen && Dialog.popupOpen != this.elemId ) {
			hideDialog(Dialog.popupOpen);
		}
		
		Dialog.popupOpen = this.elemId;
		
		return true;
	}
		
	function customerInfoDialogOnBeforeHide() {
		if ( dialog.hideTimer ) {
			clearTimeout( dialog.hideTimer );
			dialog.hideTimer = null;
		}
		
		Dialog.popupOpen = null;
		
		return true;
	};
	
	function showCustomerInfoDialog() {
		width = 150;
		height = 130;
		
		dialog = getDialog('customerInfoDialog');
		
		if ( dialog.hideTimer ) {
			clearTimeout( dialog.hideTimer );
			dialog.hideTimer = null;
		}
		
		if ( dialog.visible ) {
			return false;
		}
		
		dialog.setSize(width, height);
		
		//dialog.debug = true;
		
		dialog.onBeforeShow = customerInfoDialogOnBeforeShow;
		dialog.onBeforeHide = customerInfoDialogOnBeforeHide;
		
		dialog.setPosition(
			findPosX( getObj('customerMenu') ) - 45,
			findPosY( getObj('customerMenu') ) + 20
		);
		
		//dialog.load('/ajax_product_info.php');
		
		//dialog.onLoad = customerInfoDialogOnLoad;
		
		dialog.show();
	}
	
	function hideCustomerInfoDialog() {
		dialog = getDialog('customerInfoDialog');
		
		if ( dialog.hideTimer ) {
			clearTimeout( dialog.hideTimer );
			dialog.hideTimer = null;
		}
	
		dialog.hideTimer = setTimeout("hideDialog('customerInfoDialog')", 500);
	}
	
	
// filter dialogs

	function filterDialogOnBeforeShow() {
		if ( Dialog.popupOpen && Dialog.popupOpen != this.elemId ) {
			hideDialog(Dialog.popupOpen);
		}
		
		Dialog.popupOpen = this.elemId;
		
		return true;
	}
	
	function filterDialogOnBeforeHide() {
		if ( dialog.hideTimer ) {
			clearTimeout( dialog.hideTimer );
			dialog.hideTimer = null;
		}
		
		Dialog.popupOpen = null;
		
		return true;
	}
	
	function filterDialogOnShow() {
		//alert(width + ' ' + height);
	}

	// temp: showFilterDialog('filterProductAuthorMenu', 'filterProductAuthorDialog', 200, 250);
	function showFilterDialog(linkToDiv, contentDiv, width, height) {
		if (! width ) {
			width = 230;
		}
		
		if (! height ) {
			height = 300;
		}
		
		dialog = getDialog(contentDiv);
		
		if ( dialog.hideTimer ) {
			clearTimeout( dialog.hideTimer );
			dialog.hideTimer = null;
		}
		
		if ( dialog.visible ) {
			return false;
		}
		
		//dialog.debug = true;
		
		if (! dialog.data['sizeInfo'] ) {
			// caching the inner content size
			dialog.data['sizeInfo'] = new Array();
			
			//this.elem.style.width = width + 'px';
			this.elem.style.height = height + 'px';
			setOpacity(this.elem, 0);
			this.elem.className = 'dialog';
			
			dialog.data['sizeInfo']['width'] = getWidth(contentDiv + 'Content');
			dialog.data['sizeInfo']['height'] = getHeight(contentDiv + 'Content');
			
			
			setOpacity(this.elem, 100);
			this.elem.className = 'dialogHidden';
			
			//alert(this.sizeInfo['width'] + ' ' + this.sizeInfo['height']);
		}
		
		width = Math.max(width, dialog.data['sizeInfo']['width']);
		height = Math.min(height, dialog.data['sizeInfo']['height']);
		
		dialog.setSize(width, height);
		
		dialog.steps = 4;
		dialog.onBeforeShow = filterDialogOnBeforeShow;
		dialog.onBeforeHide = filterDialogOnBeforeHide;
		
		dialog.data['contentDiv'] = contentDiv;
		dialog.onShow = filterDialogOnShow;
		
		// Bugfix ByColor - 2009.11.18
		// Pozitionare gresita la submeniul pentru "Afiseaza" de aici: https://comenzi.farmaciatei.ro/antihistaminice/
		stingaX = findPosX( getObj(linkToDiv) );

		if (linkToDiv == 'filterProductTypeMenu'
			|| linkToDiv == 'filterProductManufacturerMenu')
		{
			stingaX = 1;
			dialog.setPosition(
				stingaX,
				20
			);
			
			document.getElementById(linkToDiv).style.zIndex = "10000";
		} else {
			dialog.setPosition(
				stingaX,
				377
			);
		};
		// End Bugfix ByColor - 2009.11.18
		
		dialog.steps = 2;
		dialog.show();
	}
	
	function hideFilterDialog(contentDiv) {
		dialog = getDialog(contentDiv);
		
		if ( dialog.hideTimer ) {
			clearTimeout( dialog.hideTimer );
			dialog.hideTimer = null;
		}
	
		dialog.hideTimer = setTimeout("hideDialog('" + contentDiv + "')", 500);
	}
	
	/* product type popup */
	function showFilterProductTypeDialog() {
		showFilterDialog('filterProductTypeMenu', 'filterProductTypeDialog', 150, 250);
	}
	
	function hideFilterProductTypeDialog() {
		hideFilterDialog('filterProductTypeDialog');
	}
	
	/* product manufacturer popup */
	function showFilterProductManufacturerDialog() {
		showFilterDialog('filterProductManufacturerMenu', 'filterProductManufacturerDialog', 200, 250);
	}
	
	function hideFilterProductManufacturerDialog() {
		hideFilterDialog('filterProductManufacturerDialog');
	}
	
	/* product author popup */
	function showFilterProductAuthorDialog() {
		showFilterDialog('filterProductAuthorMenu', 'filterProductAuthorDialog', 200, 250);
	}
	
	function hideFilterProductAuthorDialog() {
		hideFilterDialog('filterProductAuthorDialog');
	}
	
	
/* on load */
	function setAuthorsBox() {
		if ( getObj('products_authorsBox') ) {
			var authorsBox = new Server('ajax_authors.php');
			authorsBox.load('', getObj('products_authorsBox'));
		}
	}
	
	//onLoadList.push(setAuthorsBox);
	
	function pageOnLoad() {
		for (i in onLoadList) {
			onLoadList[i]();
		}
	}
	
	
/* add to wishlist */
	// wishlist dialog

	function addToWishlist(productId, noCheck) {
		var productList;
		
		if (! noCheck ) {
			var productListInput = getObj('attributes_list_' + productId);
			
			if (! productListInput ) {
				// probabil suntem intr-un listing, deschidem dialogul de informatii produs
				showProductDialog(productId);
				return;
			}
			
			productList = productListInput.value;
		}
		else {
			productList = '';
		}
		
		// daca exista lista de atribute, putem sa adaugam direct in wishlist
		
		var attributes = productList.split(',');
		
		var params = 'action=add_to_wishlist&products_id=' + productId;
		
		for (i in attributes)
		if ( parseInt('0' + attributes[i], 10) ) {
			var select = getObj('attr_' + attributes[i]);
			params += '&id[' + attributes[i] + ']=' + select.value;
		}
		
		width = 550;
		// Modified by ByColor - 2010.06.26
		height = 450;
		height = 480;
		// End Modified by ByColor - 2010.06.26
		
		dialog = getDialog('addToWishList' + productId);
		dialog.setSize(width, height);
		
		//dialog.debug = true;
		
		dialog.onBeforeShow = productDialogOnBeforeShow;
		dialog.onBeforeHide = productDialogOnBeforeHide;
		
		dialog.setPosition(
			scrollLeft() + clientWidth()/2 - width/2,
			scrollTop() + clientHeight()/2 - width/2 + 100
		);
		
		dialog.load('/ajax_wishlist.php?' + params);
		
		dialog.onLoad = productDialogOnLoad;
		
		dialog.show();
		
		//alert(params);
	}
	
	
/* add to cart */
	function confirmationDialogOnLoad() {
		this.server.__draw();
	}
	
	function confirmationDialogOnBeforeShow() {
		if ( this.hideTimer ) {
			clearTimeout(this.hideTimer);
		}
		
		return true;
	}
	
	function confirmationDialogOnShow() {
		this.hideTimer = setTimeout("hideDialog('" + this.elemId + "')", 5000);
	}
		
	function confirmationDialogOnBeforeHide() {
		//this.elem.innerHTML = '';

		if ( this.hideTimer ) {
			clearTimeout(this.hideTimer);
		}
		
		return true;
	}

	/*
	function addToCart(productId) {
		//alert('window.top.cart_content: ' + window.top.cart_content);
		if ( window.top.cart_content ) {
			window.top.cart_content.update();
		}
		
		//productId = parseInt('0'+productId, 10);
		
		productId = 0;
		
		width = 600;
		height = 130;
		
		dialog = getDialog('addToCart' + productId, 'auxDialogs', dialogSimpleDraw);

		dialog.setSize(width, height);
		
		//dialog.drawInto = 'auxDialogs';
		
		//dialog.debug = true;
		
		//dialog.draw = dialogSimpleDraw;
		//dialog.redraw();
		
		//alert( getObj('addToCart' + productId).innerHTML );
		
		dialog.transparency = true;
		dialog.onBeforeShow = confirmationDialogOnBeforeShow;
		dialog.onShow = confirmationDialogOnShow;
		dialog.onBeforeHide = confirmationDialogOnBeforeHide;
		dialog.onLoad = confirmationDialogOnLoad;
		
		var left = scrollLeft() + clientWidth()/2 - width/2;
		var top = scrollTop() + clientHeight()/2 - height/2;
		
		dialog.setPosition(left, top);
		
		dialog.load('/ajax_product_added.php?products_id=' + productId);
		
		dialog.show();
	}
	*/
	
	
	function checkTermsCheckbox()
	{
		var ret=true;
		if(!document.getElementById("confirmTerms").checked)
		{
			ret=false;
			alert('Confirmati acordul pentru timpul de livrare!');
		}
		return ret;
	}
	

	
/* print order */
	function printOrderDialogOnLoad() {
		this.server.__draw();
	}
	
	function printOrderDialogOnBeforeShow() {
		return true;
	}
	
	function printOrderDialogOnShow() {
	}
		
	function printOrderDialogOnBeforeHide() {
		//this.elem.innerHTML = '';

		return true;
	}

	function printOrder() {
		width = 600;
		height = 550;
		
		dialog = getDialog('printOrder', 'auxDialogs');

		dialog.setSize(width, height);
		
		dialog.transparency = true;
		dialog.onBeforeShow = printOrderDialogOnBeforeShow;
		dialog.onShow = printOrderDialogOnShow;
		dialog.onBeforeHide = printOrderDialogOnBeforeHide;
		dialog.onLoad = printOrderDialogOnLoad;
		
		var left = scrollLeft() + clientWidth()/2 - width/2;
		var top = scrollTop() + clientHeight()/2 - height/2;
		
		dialog.setPosition(left, top);
		
		dialog.load('/ajax_print_order.php');
		
		dialog.show();
	}
	
	
	


// random information dialog

	function infoDialogOnLoad() {
		this.server.__draw();
	}
	
	function infoDialogOnBeforeShow() {
		if ( Dialog.infoDialogOpen && Dialog.infoDialogOpen != this.elemId ) {
			//hideDialog(Dialog.productDialogOpen);
		}
		
		Dialog.infoDialogOpen = this.elemId;

		return true;
	}
		
	function infoDialogOnBeforeHide() {
		Dialog.infoDialogOpen = null;
		
		return true;
	}
	
	Dialog.infoDialogOpen = null;

	function showInfoDialog(name) {
		width = 400;
		height = 200;
		
		dialog = getDialog(name + 'Dialog', 'auxDialogs', dialogSimpleDraw);
		dialog.setSize(width, height);
		
		//dialog.debug = true;
		
		dialog.onBeforeShow = infoDialogOnBeforeShow;
		dialog.onBeforeHide = infoDialogOnBeforeHide;
		
		dialog.setPosition(
			scrollLeft() + clientWidth()/2 - width/2,
			scrollTop() + clientHeight()/2 - width/2 + 100
		);
		
		getObj(dialog.elemId + 'Content').innerHTML = getObj(name).innerHTML;
		
		dialog.show();
	}

	function showInfoBox(name, holder, width, height, top, left) {
		if (!width) 
		{
			width = 230;
		}
		
		if (!height) 
		{
			height = 300;
		}

		if (!holder) 
		{
			holder = 'auxDialogs';
		}
		
		dialog = getDialog(name + 'Dialog', holder, dialogSimpleDraw);
		dialog.setSize(width, height);
		
		dialog.onBeforeShow = infoDialogOnBeforeShow;
		dialog.onBeforeHide = infoDialogOnBeforeHide;
		
		if (!top)
		{
			top = findPosY(getObj(holder));
			alert ("name: " + name + "\n" + "holder: " + holder + "\n" + "top: " + top);
		}
		if (!left)
		{
			left = findPosX(getObj(holder));
			alert ("name: " + name + "\n" + "left: " + left);
		}
		dialog.setPosition(left, top);
		
		getObj(dialog.elemId + 'Content').innerHTML = getObj(name).innerHTML;
		
		dialog.show();
	}
	

function checkPrintOrderForm()
{
	var myreturn=true;
	x=document.getElementById('errorPrintOrderNume');
	if(document.getElementById('printOrderNume').value.length<=0)
	{
		x.style.display='';
		myreturn=false;
	}
	else
	{
			x.style.display='none';
	}
	
	x=document.getElementById('errorPrintOrderInstitutie');
	if(document.getElementById('printOrderInstitutie').value.length<=0)
	{
		x.style.display='';
		myreturn=false;
	}
	else
	{
			x.style.display='none';
	}
	
	x=document.getElementById('errorPrintOrderLocalitate');
	if(document.getElementById('printOrderLocalitate').value.length<=0)
	{
		x.style.display='';
		myreturn=false;
	}
	else
	{
			x.style.display='none';
	}
	
	x=document.getElementById('errorPrintOrderTelefon');
	if(document.getElementById('printOrderTelefon').value.length<=0)
	{
		x.style.display='';
		myreturn=false;
	}
	else
	{
			x.style.display='none';
	}
	
	return myreturn;
}



// ------------------------------------------------------------------------------------------------------------------------------------------------------------------------------
// preview.js
// ------------------------------------------------------------------------------------------------------------------------------------------------------------------------------

var offsetfrommouse=[15,25]; //image x,y offsets from cursor position in pixels. Enter 0,0 for no offset
var displayduration=0; //duration in seconds image should remain visible. 0 for always.

var defaultimageheight = 40;	// maximum image size.
var defaultimagewidth = 40;	// maximum image size.

var timer;

function gettrailobj(){
if (document.getElementById)
return document.getElementById("preview_div").style
}

function gettrailobjnostyle(){
if (document.getElementById)
return document.getElementById("preview_div")
}


function truebody(){
return (!window.opera && document.compatMode && document.compatMode!="BackCompat")? document.documentElement : document.body
}


function hidetrail(){	
	gettrailobj().display= "none";
	document.onmousemove="";
	gettrailobj().left="-500px";
	clearTimeout(timer);
}

function showtrail(imagename,title,width,height,image_width){
	i = imagename;
	t = title;
	w = width;
	h = height;
	iw = image_width; 
	timer = setTimeout("show('"+i+"',t,w,h,iw);",200);
}
function show(imagename,title,width,height,image_width){
 
    var docwidth=document.all? truebody().scrollLeft+truebody().clientWidth : pageXOffset+window.innerWidth - offsetfrommouse[0]
	var docheight=document.all? Math.min(truebody().scrollHeight, truebody().clientHeight) : Math.min(window.innerHeight)

	if( (navigator.userAgent.indexOf("Konqueror")==-1  || navigator.userAgent.indexOf("Firefox")!=-1 || (navigator.userAgent.indexOf("Opera")==-1 && navigator.appVersion.indexOf("MSIE")!=-1)) && (docwidth>650 && docheight>500)) {
		( width == 0 ) ? width = defaultimagewidth: '';
		( height == 0 ) ? height = defaultimageheight: '';
			
		width+=30
		height+=55
		defaultimageheight = height
		defaultimagewidth = width
	
		document.onmousemove=followmouse; 
		while (title.search("_") != -1) 
		{
			title = title.replace("_"," ");
		}
		
		var our_width = image_width;

		if(our_width>400){
			pwidth = " width=400";
		}
		else{
			pwidth = " ";
		}
		
			newHTML = '<table cellpadding="0" cellspacing="0" style="border:1px solid #999" bgcolor="#f1f1f1">' ;
			newHTML = newHTML + '<tr><td style="padding-top:5px; padding-bottom:5px; padding-left:5px; padding-right:5px;" height="25" valign="top">';
			//newHTML = newHTML +	'<div class="border_preview" style="width:'+  width +'px;height:'+ height +'px"><div id="loader_container"><div id="loader"><div align="center"></div><div id="loader_bg"><div id="progress"></div></div></div></div>'	;	
			newHTML = newHTML + '<img onload="javascript:remove_loading();" src="' + imagename + pwidth +'" border="0" style="border:2px solid #999" name="imagine">';	
			newHTML = newHTML + '</td></tr><tr><td style="padding-top:5px; padding-bottom:0px; padding-left:5px; padding-right:5px" height="25" valign="top" align="center">';
			newHTML = newHTML + '<font color="#000000" size="1">' + ' <strong> '+title + '</strong></font></td></tr></table>'; 
			
			//if(navigator.userAgent.indexOf("MSIE")!=-1 && navigator.userAgent.indexOf("Opera")==-1 ){
			//	newHTML = newHTML+'<iframe src="about:blank" scrolling="no" frameborder="0" width="'+width+'" height="'+height+'"></iframe>';
			//}		

			gettrailobjnostyle().innerHTML = newHTML;
			gettrailobj().display="block";
		
	
	}
}

function followmouse(e){

	//var xcoord=offsetfrommouse[0]
	//var ycoord=offsetfrommouse[1]
	var xcoord=100;
	var ycoord=-200;



	var docwidth=document.all? truebody().scrollLeft+truebody().clientWidth : pageXOffset+window.innerWidth-15
	var docheight=document.all? Math.min(truebody().scrollHeight, truebody().clientHeight) : Math.min(window.innerHeight)

	if (typeof e != "undefined"){
		if (docwidth - e.pageX < defaultimagewidth + 2*offsetfrommouse[0]){
			xcoord = e.pageX - xcoord - defaultimagewidth; // Move to the left side of the cursor
		} else {
			xcoord += e.pageX;
		}
		if (docheight - e.pageY < defaultimageheight + 2*offsetfrommouse[1]){
			ycoord += e.pageY - Math.max(0,(2*offsetfrommouse[1] + defaultimageheight + e.pageY - docheight - truebody().scrollTop));
		} else {
			ycoord += e.pageY;
		}

	} else if (typeof window.event != "undefined"){
		if (docwidth - event.clientX < defaultimagewidth + 2*offsetfrommouse[0]){
			xcoord = event.clientX + truebody().scrollLeft - xcoord - defaultimagewidth; // Move to the left side of the cursor
		} else {
			xcoord += truebody().scrollLeft+event.clientX;
		}
		if (docheight - event.clientY < (defaultimageheight + 2*offsetfrommouse[1])){
			ycoord += event.clientY + truebody().scrollTop - Math.max(0,(2*offsetfrommouse[1] + defaultimageheight + event.clientY - docheight));
		} else {
			ycoord += truebody().scrollTop + event.clientY;
		}
	}
	gettrailobj().left=xcoord+"px";
	gettrailobj().top=ycoord+"px";

}



// ------------------------------------------------------------------------------------------------------------------------------------------------------------------------------
// behaviour.js
// ------------------------------------------------------------------------------------------------------------------------------------------------------------------------------
/*
   Behaviour v1.1 by Ben Nolan, June 2005. Based largely on the work
   of Simon Willison (see comments by Simon below).

   Description:
   	
   	Uses css selectors to apply javascript behaviours to enable
   	unobtrusive javascript in html documents.
   	
   Usage:   
   
	var myrules = {
		'b.someclass' : function(element){
			element.onclick = function(){
				alert(this.innerHTML);
			}
		},
		'#someid u' : function(element){
			element.onmouseover = function(){
				this.innerHTML = "BLAH!";
			}
		}
	};
	
	Behaviour.register(myrules);
	
	// Call Behaviour.apply() to re-apply the rules (if you
	// update the dom, etc).

   License:
   
   	This file is entirely BSD licensed.
   	
   More information:
   	
   	http://ripcord.co.nz/behaviour/
   
*/   

var Behaviour = {
	list : new Array,
	
	register : function(sheet){
		Behaviour.list.push(sheet);
	},
	
	start : function(){
		Behaviour.addLoadEvent(function(){
			Behaviour.apply();
		});
	},
	
	apply : function(){
		for (h=0;sheet=Behaviour.list[h];h++){
			for (selector in sheet){
				list = document.getElementsBySelector(selector);
				
				if (!list){
					continue;
				}

				for (i=0;element=list[i];i++){
					sheet[selector](element);
				}
			}
		}
	},
	
	addLoadEvent : function(func){
		var oldonload = window.onload;
		
		if (typeof window.onload != 'function') {
			window.onload = func;
		} else {
			window.onload = function() {
				oldonload();
				func();
			}
		}
	}
}

Behaviour.start();

/*
   The following code is Copyright (C) Simon Willison 2004.

   document.getElementsBySelector(selector)
   - returns an array of element objects from the current document
     matching the CSS selector. Selectors can contain element names, 
     class names and ids and can be nested. For example:
     
       elements = document.getElementsBySelect('div#main p a.external')
     
     Will return an array of all 'a' elements with 'external' in their 
     class attribute that are contained inside 'p' elements that are 
     contained inside the 'div' element which has id="main"

   New in version 0.4: Support for CSS2 and CSS3 attribute selectors:
   See http://www.w3.org/TR/css3-selectors/#attribute-selectors

   Version 0.4 - Simon Willison, March 25th 2003
   -- Works in Phoenix 0.5, Mozilla 1.3, Opera 7, Internet Explorer 6, Internet Explorer 5 on Windows
   -- Opera 7 fails 
*/

function getAllChildren(e) {
  // Returns all children of element. Workaround required for IE5/Windows. Ugh.
  return e.all ? e.all : e.getElementsByTagName('*');
}

document.getElementsBySelector = function(selector) {
  // Attempt to fail gracefully in lesser browsers
  if (!document.getElementsByTagName) {
    return new Array();
  }
  // Split selector in to tokens
  var tokens = selector.split(' ');
  var currentContext = new Array(document);
  for (var i = 0; i < tokens.length; i++) {
    token = tokens[i].replace(/^\s+/,'').replace(/\s+$/,'');;
    if (token.indexOf('#') > -1) {
      // Token is an ID selector
      var bits = token.split('#');
      var tagName = bits[0];
      var id = bits[1];
      var element = document.getElementById(id);
      if (tagName && element.nodeName.toLowerCase() != tagName) {
        // tag with that ID not found, return false
        return new Array();
      }
      // Set currentContext to contain just this element
      currentContext = new Array(element);
      continue; // Skip to next token
    }
    if (token.indexOf('.') > -1) {
      // Token contains a class selector
      var bits = token.split('.');
      var tagName = bits[0];
      var className = bits[1];
      if (!tagName) {
        tagName = '*';
      }
      // Get elements matching tag, filter them for class selector
      var found = new Array;
      var foundCount = 0;
      for (var h = 0; h < currentContext.length; h++) {
        var elements;
        if (tagName == '*') {
            elements = getAllChildren(currentContext[h]);
        } else {
            elements = currentContext[h].getElementsByTagName(tagName);
        }
        for (var j = 0; j < elements.length; j++) {
          found[foundCount++] = elements[j];
        }
      }
      currentContext = new Array;
      var currentContextIndex = 0;
      for (var k = 0; k < found.length; k++) {
        if (found[k].className && found[k].className.match(new RegExp('\\b'+className+'\\b'))) {
          currentContext[currentContextIndex++] = found[k];
        }
      }
      continue; // Skip to next token
    }
    // Code to deal with attribute selectors
    if (token.match(/^(\w*)\[(\w+)([=~\|\^\$\*]?)=?"?([^\]"]*)"?\]$/)) {
      var tagName = RegExp.$1;
      var attrName = RegExp.$2;
      var attrOperator = RegExp.$3;
      var attrValue = RegExp.$4;
      if (!tagName) {
        tagName = '*';
      }
      // Grab all of the tagName elements within current context
      var found = new Array;
      var foundCount = 0;
      for (var h = 0; h < currentContext.length; h++) {
        var elements;
        if (tagName == '*') {
            elements = getAllChildren(currentContext[h]);
        } else {
            elements = currentContext[h].getElementsByTagName(tagName);
        }
        for (var j = 0; j < elements.length; j++) {
          found[foundCount++] = elements[j];
        }
      }
      currentContext = new Array;
      var currentContextIndex = 0;
      var checkFunction; // This function will be used to filter the elements
      switch (attrOperator) {
        case '=': // Equality
          checkFunction = function(e) { return (e.getAttribute(attrName) == attrValue); };
          break;
        case '~': // Match one of space seperated words 
          checkFunction = function(e) { return (e.getAttribute(attrName).match(new RegExp('\\b'+attrValue+'\\b'))); };
          break;
        case '|': // Match start with value followed by optional hyphen
          checkFunction = function(e) { return (e.getAttribute(attrName).match(new RegExp('^'+attrValue+'-?'))); };
          break;
        case '^': // Match starts with value
          checkFunction = function(e) { return (e.getAttribute(attrName).indexOf(attrValue) == 0); };
          break;
        case '$': // Match ends with value - fails with "Warning" in Opera 7
          checkFunction = function(e) { return (e.getAttribute(attrName).lastIndexOf(attrValue) == e.getAttribute(attrName).length - attrValue.length); };
          break;
        case '*': // Match ends with value
          checkFunction = function(e) { return (e.getAttribute(attrName).indexOf(attrValue) > -1); };
          break;
        default :
          // Just test for existence of attribute
          checkFunction = function(e) { return e.getAttribute(attrName); };
      }
      currentContext = new Array;
      var currentContextIndex = 0;
      for (var k = 0; k < found.length; k++) {
        if (checkFunction(found[k])) {
          currentContext[currentContextIndex++] = found[k];
        }
      }
      // alert('Attribute Selector: '+tagName+' '+attrName+' '+attrOperator+' '+attrValue);
      continue; // Skip to next token
    }
    
    if (!currentContext[0]){
    	return;
    }
    
    // If we get here, token is JUST an element (not a class or ID selector)
    tagName = token;
    var found = new Array;
    var foundCount = 0;
    for (var h = 0; h < currentContext.length; h++) {
      var elements = currentContext[h].getElementsByTagName(tagName);
      for (var j = 0; j < elements.length; j++) {
        found[foundCount++] = elements[j];
      }
    }
    currentContext = found;
  }
  return currentContext;
}

/* That revolting regular expression explained 
/^(\w+)\[(\w+)([=~\|\^\$\*]?)=?"?([^\]"]*)"?\]$/
  \---/  \---/\-------------/    \-------/
    |      |         |               |
    |      |         |           The value
    |      |    ~,|,^,$,* or =
    |   Attribute 
   Tag
*/



// ------------------------------------------------------------------------------------------------------------------------------------------------------------------------------
// rating.js
// ------------------------------------------------------------------------------------------------------------------------------------------------------------------------------
/*
Page:           rating.js
Created:        Aug 2006
Last Mod:       Mar 11 2007
Handles actions and requests for rating bars.	
--------------------------------------------------------- 
ryan masuga, masugadesign.com
ryan@masugadesign.com 
Licensed under a Creative Commons Attribution 3.0 License.
http://creativecommons.org/licenses/by/3.0/
See readme.txt for full credit details.
--------------------------------------------------------- */

var xmlhttp
	/*@cc_on @*/
	/*@if (@_jscript_version >= 5)
	  try {
	  xmlhttp=new ActiveXObject("Msxml2.XMLHTTP")
	 } catch (e) {
	  try {
	    xmlhttp=new ActiveXObject("Microsoft.XMLHTTP")
	  } catch (E) {
	   xmlhttp=false
	  }
	 }
	@else
	 xmlhttp=false
	@end @*/
	if (!xmlhttp && typeof XMLHttpRequest!='undefined') {
	 try {
	  xmlhttp = new XMLHttpRequest();
	 } catch (e) {
	  xmlhttp=false
	 }
	}
	function myXMLHttpRequest() {
	  var xmlhttplocal;
	  try {
	    xmlhttplocal= new ActiveXObject("Msxml2.XMLHTTP")
	 } catch (e) {
	  try {
	    xmlhttplocal= new ActiveXObject("Microsoft.XMLHTTP")
	  } catch (E) {
	    xmlhttplocal=false;
	  }
	 }

	if (!xmlhttplocal && typeof XMLHttpRequest!='undefined') {
	 try {
	  var xmlhttplocal = new XMLHttpRequest();
	 } catch (e) {
	  var xmlhttplocal=false;
	  alert('couldn\'t create xmlhttp object');
	 }
	}
	return(xmlhttplocal);
}

function sndReq(vote,id_num,ip_num,units) {
	var theUL = document.getElementById('unit_ul'+id_num); // the UL
	
	// switch UL with a loading div
	theUL.innerHTML = '<div class="loading"></div>';
	
    xmlhttp.open('get', 'rpc.php?j='+vote+'&q='+id_num+'&t='+ip_num+'&c='+units);
    xmlhttp.onreadystatechange = handleResponse;
    xmlhttp.send(null);	
}

function handleResponse() {
  if(xmlhttp.readyState == 4){
		if (xmlhttp.status == 200){
       	
        var response = xmlhttp.responseText;
        var update = new Array();

        if(response.indexOf('|') != -1) {
            update = response.split('|');
            changeText(update[0], update[1]);
        }
		}
    }
}

function changeText( div2show, text ) {
    // Detect Browser
    var IE = (document.all) ? 1 : 0;
    var DOM = 0; 
    if (parseInt(navigator.appVersion) >=5) {DOM=1};

    // Grab the content from the requested "div" and show it in the "container"
    if (DOM) {
        var viewer = document.getElementById(div2show);
        viewer.innerHTML = text;
    }  else if(IE) {
        document.all[div2show].innerHTML = text;
    }
}

/* =============================================================== */
var ratingAction = {
		'a.rater' : function(element){
			element.onclick = function(){

			var parameterString = this.href.replace(/.*\?(.*)/, "$1"); // onclick="sndReq('j=1&q=2&t=127.0.0.1&c=5');
			var parameterTokens = parameterString.split("&"); // onclick="sndReq('j=1,q=2,t=127.0.0.1,c=5');
			var parameterList = new Array();

			for (j = 0; j < parameterTokens.length; j++) {
				var parameterName = parameterTokens[j].replace(/(.*)=.*/, "$1"); // j
				var parameterValue = parameterTokens[j].replace(/.*=(.*)/, "$1"); // 1
				parameterList[parameterName] = parameterValue;
			}
			var theratingID = parameterList['q'];
			var theVote = parameterList['j'];
			var theuserIP = parameterList['t'];
			var theunits = parameterList['c'];
			
			//for testing	alert('sndReq('+theVote+','+theratingID+','+theuserIP+','+theunits+')'); return false;
			sndReq(theVote,theratingID,theuserIP,theunits); return false;		
			}
		}
		
	};
Behaviour.register(ratingAction);

