	var enCsize = false;
	var over_it = false;
	
	function cResize(objN,minH,absT,absM,oldT,oldM) {
		var obj = O(objN);
		var myWidth = 0, myHeight = 0, newHeight = 0;
		  if( typeof( window.innerWidth ) == 'number' ) {
			myWidth = window.innerWidth;
			myHeight = window.innerHeight;
		  } else if(document.documentElement&&(document.documentElement.clientWidth||document.documentElement.clientHeight)) {
			myWidth = document.documentElement.clientWidth;
			myHeight = document.documentElement.clientHeight;
		  } else if( document.body && ( document.body.clientWidth || document.body.clientHeight ) ) {
			myWidth = document.body.clientWidth;
			myHeight = document.body.clientHeight;
		  }
		  if (myHeight<=minH) {
			  obj.style.top = absT;
			  obj.style.marginTop = absM;
		  } else {
			  obj.style.top = oldT;
			  obj.style.marginTop = oldM;
		  }
		  if (enCsize) { setTimeout('cResize(\''+objN+'\',\''+minH+'\',\''+absT+'\',\''+absM+'\',\''+oldT+'\',\''+oldM+'\')',150); }
	}
	
	function f_clientWidth() {
		return f_filterResults (
			window.innerWidth ? window.innerWidth : 0,
			document.documentElement ? document.documentElement.clientWidth : 0,
			document.body ? document.body.clientWidth : 0
		);
	}
	
	function f_clientHeight() {
		return f_filterResults (
			window.innerHeight ? window.innerHeight : 0,
			document.documentElement ? document.documentElement.clientHeight : 0,
			document.body ? document.body.clientHeight : 0
		);
	}
	
	function highlight(menu_id) {
		for (i=1;i!=6;i++) {
			if (('menu_'+i)!=menu_id) {
				O('menu_'+i).style.backgroundImage = 'url(/mlib/tpl/img/menu_bar_bg.jpg)';
			}
		}	
		if (O(menu_id).style.backgroundImage!='url(/mlib/tpl/img/menu_bar_bg_over.jpg)') 
		O(menu_id).style.backgroundImage = 'url(/mlib/tpl/img/menu_bar_bg_over.jpg)';
	}
	
	function unhighlight(menu_id) {
		O(menu_id).style.backgroundImage = 'url(/mlib/tpl/img/menu_bar_bg.jpg)';
	}
	
	function f_scrollLeft() {
		return f_filterResults (
			window.pageXOffset ? window.pageXOffset : 0,
			document.documentElement ? document.documentElement.scrollLeft : 0,
			document.body ? document.body.scrollLeft : 0
		);
	}
	
	function f_scrollTop() {
		return f_filterResults (
			window.pageYOffset ? window.pageYOffset : 0,
			document.documentElement ? document.documentElement.scrollTop : 0,
			document.body ? document.body.scrollTop : 0
		);
	}
	
	function f_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 O(n, d) { //v4.01
	  var p,i,x;  if(!d) d=document; if((p=n.indexOf("?"))>0&&parent.frames.length) {
		d=parent.frames[n.substring(p+1)].document; n=n.substring(0,p);}
	  if(!(x=d[n])&&d.all) x=d.all[n]; for (i=0;!x&&i<d.forms.length;i++) x=d.forms[i][n];
	  for(i=0;!x&&d.layers&&i<d.layers.length;i++) x=O(n,d.layers[i].document);
	  if(!x && d.getElementById) x=d.getElementById(n); return x;
	}

	function $m(quem){
	 return document.getElementById(quem)
	}
	function remove(quem){
	 quem.parentNode.removeChild(quem);
	}
	function addEvent(obj, evType, fn){

		if (obj.addEventListener)
			obj.addEventListener(evType, fn, true)
		if (obj.attachEvent)
			obj.attachEvent("on"+evType, fn)
	}
	function removeEvent( obj, type, fn ) {
	  if ( obj.detachEvent ) {
		obj.detachEvent( 'on'+type, fn );
	  } else {
		obj.removeEventListener( type, fn, false ); }
	} 

	function ajaxUpload(form,url_action,id_element,html_show_loading,html_error_http){

	 form = typeof(form)=="string"?$m(form):form;
	 
	 var erro="";
	 if(form==null || typeof(form)=="undefined"){ erro += "The form of 1st parameter does not exists.\n";}
	 else if(form.nodeName.toLowerCase()!="form"){ erro += "The form of 1st parameter its not a form.\n";}
	 if($m(id_element)==null){ erro += "The element of 3rd parameter does not exists.\n";}
	 if(erro.length>0) {
	  alert("Error in call ajaxUpload:\n" + erro);
	  return;
	 }
	 var d = new Date();
	 var iframe = document.createElement("iframe");
	 iframe.setAttribute("id","ajax-temp");
	 iframe.setAttribute("name","ajax-temp");
	 iframe.setAttribute("width","0");
	 iframe.setAttribute("height","0");
	 iframe.setAttribute("border","0");
	 iframe.setAttribute("style","width: 0; height: 0; border: none;");
	 var oform = form;
	 form.parentNode.appendChild(iframe);
	 window.frames['ajax-temp'].name="ajax-temp"; //ie sucks
	 
	 var carregou = function() { 
	   removeEvent( $m('ajax-temp'),"load", carregou);
	   var cross = "javascript: ";
	   cross += "window.parent.$m('" + id_element + "').innerHTML = 'Complete!'; window.parent.$m('pic_viewer').innerHTML = document.body.innerHTML; void(0); ";
	   
	   $m(id_element).innerHTML = html_error_http;
	   $m('ajax-temp').src = cross;
	   //del the iframe
	  
	   setTimeout(function(){ remove($m('ajax-temp'))}, 250);
	  }
	 addEvent( $m('ajax-temp'),"load", carregou)
	 
	 //properties of form
	 form.setAttribute("target","ajax-temp");
	 form.setAttribute("action",url_action);
	 form.setAttribute("method","post");
	 form.setAttribute("enctype","multipart/form-data");
	 form.setAttribute("encoding","multipart/form-data");
	 //submit
	 form.submit();
	 oform.reset();
	 //while loading
	 if(html_show_loading.length > 0){
	  $m(id_element).innerHTML = html_show_loading;
	 }
	 
	}
	function ajaxUpload2(form,url_action,id_element,html_show_loading,html_error_http){

	 form = typeof(form)=="string"?$m(form):form;
	 
	 var erro="";
	 if(form==null || typeof(form)=="undefined"){ erro += "The form of 1st parameter does not exists.\n";}
	 else if(form.nodeName.toLowerCase()!="form"){ erro += "The form of 1st parameter its not a form.\n";}
	 if($m(id_element)==null){ erro += "The element of 3rd parameter does not exists.\n";}
	 if(erro.length>0) {
	  alert("Error in call ajaxUpload:\n" + erro);
	  return;
	 }
	 var d = new Date();
	 var iframe = document.createElement("iframe");
	 iframe.setAttribute("id","ajax-temp");
	 iframe.setAttribute("name","ajax-temp");
	 iframe.setAttribute("width","0");
	 iframe.setAttribute("height","0");
	 iframe.setAttribute("border","0");
	 iframe.setAttribute("style","width: 0; height: 0; border: none;");
	 var oform = form;
	 form.parentNode.appendChild(iframe);
	 window.frames['ajax-temp'].name="ajax-temp"; //ie sucks
	 
	 var carregou = function() { 
	   removeEvent( $m('ajax-temp'),"load", carregou);
	   var cross = "javascript: ";
	   cross += "window.parent.$m('" + id_element + "').innerHTML = 'Complete!'; window.parent.$m('op_con').innerHTML = document.body.innerHTML; void(0); ";
	   
	   $m(id_element).innerHTML = html_error_http;
	   $m('ajax-temp').src = cross;
	   //del the iframe
	  
	   setTimeout(function(){ remove($m('ajax-temp'))}, 250);
	  }
	 addEvent( $m('ajax-temp'),"load", carregou)
	 
	 //properties of form
	 form.setAttribute("target","ajax-temp");
	 form.setAttribute("action",url_action);
	 form.setAttribute("method","post");
	 form.setAttribute("enctype","multipart/form-data");
	 form.setAttribute("encoding","multipart/form-data");
	 //submit
	 form.submit();
	 oform.previewer.backgroundColor = '';
	 oform.reset();
	 //while loading
	 if(html_show_loading.length > 0){
	  $m(id_element).innerHTML = html_show_loading;
	 }
	 
	}

	function GetXmlHttpObject()
	{
	  var xmlHttp=null;
	  try
		{
		// Firefox, Opera 8.0+, Safari
		xmlHttp=new XMLHttpRequest();
		}
	  catch (e)
		{
		// Internet Explorer
		try
		  {
		  xmlHttp=new ActiveXObject("Msxml2.XMLHTTP");
		  }
		catch (e)
		  {
		  xmlHttp=new ActiveXObject("Microsoft.XMLHTTP");
		  }
		}
	  return xmlHttp;
	}
	
	function stateChanged() { 
		if (xmlHttp.readyState==4) { 
			var w = $m("pic_viewer");
			// Return Propery XML
			// Update window with property data
			data = xmlHttp.responseText;
			w.innerHTML = data;
			
		}
	}
	
	function stateChanged2() { 
		if (xmlHttp.readyState==4) { 
			var w = $m("pic_viewer");
			
			// Return Propery XML
			// Update window with property data			
		}
	}
	function delImg(id) {
	  var d = new Date(); 
	  var url = "?cmd=add_product&delete_img="+id+"&time="+d.getTime();
	  var w = $m("pic_viewer");
	  // Display Loading Message 
	  xmlHttp = null;
	  xmlHttp=GetXmlHttpObject();
	  if (xmlHttp==null)
	  {
	  alert ("Your browser does not support AJAX!");
	  return;
	  } 
	  xmlHttp.onreadystatechange=stateChanged;
	  xmlHttp.open("GET",url,true);
	  xmlHttp.send(null);
	}
	function setColor(id,color) {
	  var d = new Date(); 
	  var url = "?cmd=add_product&setcolor="+color+"&id="+id+"&time="+d.getTime();
	  var w = $m("pic_viewer");
	  // Display Loading Message 
	  xmlHttp = null;
	  xmlHttp=GetXmlHttpObject();
	  if (xmlHttp==null)
	  {
	  alert ("Your browser does not support AJAX!");
	  return;
	  } 
	  xmlHttp.onreadystatechange=stateChanged2;
	  xmlHttp.open("GET",url,true);
	  xmlHttp.send(null);
	}
		function stateChanged3() { 
		if (xmlHttp.readyState==4) { 
			var w = $m("op_con");
			// Return Propery XML
			// Update window with property data
			data = xmlHttp.responseText;
			w.innerHTML = data;	
		}
	}
	function delOp(id) {
	  var d = new Date(); 
	  var url = "?cmd=add_product&delete_op="+id+"&time="+d.getTime();
	  // Display Loading Message 
	  xmlHttp = null;
	  xmlHttp=GetXmlHttpObject();
	  if (xmlHttp==null)
	  {
	  alert ("Your browser does not support AJAX!");
	  return;
	  } 
	  xmlHttp.onreadystatechange=stateChanged3;
	  xmlHttp.open("GET",url,true);
	  xmlHttp.send(null);
	}
	
	function setThumb(id) {
	  var d = new Date(); 
	  var url = "?cmd=add_product&set_thumb="+id+"&time="+d.getTime();
	  xmlHttp = null;
	  xmlHttp=GetXmlHttpObject();
	  if (xmlHttp==null)
	  {
	  alert ("Your browser does not support AJAX!");
	  return;
	  } 
	  xmlHttp.onreadystatechange=stateChanged2;
	  xmlHttp.open("GET",url,true);
	  xmlHttp.send(null);
	}
	
	var Drag = {
	
		obj : null,
	
		init : function(o, oRoot, minX, maxX, minY, maxY, bSwapHorzRef, bSwapVertRef, fXMapper, fYMapper)
		{
			o.onmousedown	= Drag.start;
			
			o.hmode			= bSwapHorzRef ? false : true ;
			o.vmode			= bSwapVertRef ? false : true ;
	
			o.root = oRoot && oRoot != null ? oRoot : o ;
	
			if (o.hmode  && isNaN(parseInt(o.root.style.left  ))) o.root.style.left   = "0px";
			if (o.vmode  && isNaN(parseInt(o.root.style.top   ))) o.root.style.top    = "16px";
			if (!o.hmode && isNaN(parseInt(o.root.style.right ))) o.root.style.right  = "0px";
			if (!o.vmode && isNaN(parseInt(o.root.style.bottom))) o.root.style.bottom = "0px";
	
			o.minX	= typeof minX != 'undefined' ? minX : null;
			o.minY	= typeof minY != 'undefined' ? minY : null;
			o.maxX	= typeof maxX != 'undefined' ? maxX : null;
			o.maxY	= typeof maxY != 'undefined' ? maxY : null;
	
			o.xMapper = fXMapper ? fXMapper : null;
			o.yMapper = fYMapper ? fYMapper : null;
	
			o.root.onDragStart	= new Function();
			o.root.onDragEnd	= new Function();
			o.root.onDrag		= new Function();
		},
	
		start : function(e)
		{
			var o = Drag.obj = this;
			e = Drag.fixE(e);
	
			var y = parseInt(o.vmode ? o.root.style.top  : o.root.style.bottom);
			var x = parseInt(o.hmode ? o.root.style.left : o.root.style.right );
			o.root.onDragStart(x, y);
	
			o.lastMouseX	= e.clientX;
			o.lastMouseY	= e.clientY;
	
			if (o.hmode) {
				if (o.minX != null)	o.minMouseX	= e.clientX - x + o.minX;
				if (o.maxX != null)	o.maxMouseX	= o.minMouseX + o.maxX - o.minX;
			} else {
				if (o.minX != null) o.maxMouseX = -o.minX + e.clientX + x;
				if (o.maxX != null) o.minMouseX = -o.maxX + e.clientX + x;
			}
	
			if (o.vmode) {
				if (o.minY != null)	o.minMouseY	= e.clientY - y + o.minY;
				if (o.maxY != null)	o.maxMouseY	= o.minMouseY + o.maxY - o.minY;
			} else {
				if (o.minY != null) o.maxMouseY = -o.minY + e.clientY + y;
				if (o.maxY != null) o.minMouseY = -o.maxY + e.clientY + y;
			}
	
			document.onmousemove	= Drag.drag;
			document.onmouseup		= Drag.end;
	
			return false;
		},
	
		drag : function(e)
		{
			e = Drag.fixE(e);
			var o = Drag.obj;
	
			var ey	= e.clientY;
			var ex	= e.clientX;
			var y = parseInt(o.vmode ? o.root.style.top  : o.root.style.bottom);
			var x = parseInt(o.hmode ? o.root.style.left : o.root.style.right );
			var nx, ny;
	
			if (o.minX != null) ex = o.hmode ? Math.max(ex, o.minMouseX) : Math.min(ex, o.maxMouseX);
			if (o.maxX != null) ex = o.hmode ? Math.min(ex, o.maxMouseX) : Math.max(ex, o.minMouseX);
			if (o.minY != null) ey = o.vmode ? Math.max(ey, o.minMouseY) : Math.min(ey, o.maxMouseY);
			if (o.maxY != null) ey = o.vmode ? Math.min(ey, o.maxMouseY) : Math.max(ey, o.minMouseY);
	
			nx = x + ((ex - o.lastMouseX) * (o.hmode ? 1 : -1));
			ny = y + ((ey - o.lastMouseY) * (o.vmode ? 1 : -1));
	
			if (o.xMapper)		nx = o.xMapper(y)
			else if (o.yMapper)	ny = o.yMapper(x)
	
			Drag.obj.root.style[o.hmode ? "left" : "right"] = nx + "px";
			Drag.obj.root.style[o.vmode ? "top" : "bottom"] = ny + "px";
			Drag.obj.lastMouseX	= ex;
			Drag.obj.lastMouseY	= ey;
	
			Drag.obj.root.onDrag(nx, ny);
			return false;
		},
	
		end : function()
		{
			document.onmousemove = null;
			document.onmouseup   = null;
			Drag.obj.root.onDragEnd(	parseInt(Drag.obj.root.style[Drag.obj.hmode ? "left" : "right"]), 
										parseInt(Drag.obj.root.style[Drag.obj.vmode ? "top" : "bottom"]));
			Drag.obj = null;
		},
	
		fixE : function(e)
		{
			if (typeof e == 'undefined') e = window.event;
			if (typeof e.layerX == 'undefined') e.layerX = e.offsetX;
			if (typeof e.layerY == 'undefined') e.layerY = e.offsetY;
			return e;
		}
	};
