function printJS(o){
	var s = "";
	for(var i in o){
		s += " "+ i+ " = " + o[i] + "; ";
	}
	alert(s);
}

var Main = {
	is_debug: true,
	showDebug: function(msg){
		if(this.is_debug == true){
			alert(msg);
		}
	},showAlert:function(msg){
		if(this.is_debug == true){
			alert(msg);
		}
	}, _u: function(obj){ //{side:'side', cl:'cl', act:'act'} expected
	var def = {side:'index', cl:'index', act:'default'};
	var res = {};
		if(obj.hasProp('side'))
			res.side = obj.side;
		else
			res.side = def.side;
		if(obj.hasProp('cl'))
			res.cl = obj.cl;
		else res.cl = def.cl;

		if(obj.hasProp('act'))
			res.act = obj.act;
		else
			res.act = def.act;
		return '/' + res.side + '/' + res.cl + '/' + res.act;
	},login:function(){
		//console.debug($('l[email]').getValue());
		//console.debug($('l[password]').getValue());
		return false;
	}
	,dirify:function(str){
        return str.replace(/[^a-zA-Z0-9]/ig,"_") + ".html";
	},isLinkValid: function(str){
        var res = str == encodeURIComponent(str);
        return res;
	},isDateValid: function (str){
	  // gets the string and says is it correct date
      // correct is 12/3/2008 (dd/mm/yy)
      var str_arr = str.split('/');
      var res= false;
      if(str_arr.length == 3){
        res = !isNaN(str_arr[0])&& !isNaN(str_arr[1])&& !isNaN(str_arr[2]);
      }
      return res;
    },isEmpty: function (str){
        var res = str.trim() == '';
        return res;
    },
    isEmty: function(str){
      return this.isEmtpy(str);
    },isFloat:function(str){
        var reFloat = /^((\d+(\.\d*)?)|((\d*\.)?\d+))$/;
        if(reFloat.test(str.trim()))
            return str.trim();
    },redirect: function(loc){
		document.location = loc;
	},get_param: function( name )
	{
	  name = name.replace(/[\[]/,"\\\[").replace(/[\]]/,"\\\]");
	  var regexS = "[\\?&]"+name+"=([^&#]*)";
	  var regex = new RegExp( regexS );
	  var results = regex.exec( window.location.href );
	  if( results == null )
	    return "";
	  else
	    return results[1];
	},
	apply: function(o, c, defaults){
	    if(defaults){
	        Main.apply(o, defaults);
	    }
	    if(o && c && typeof c == 'object'){
	        for(var p in c){
	            o[p] = c[p];
	        }
	    }
	    return o;
	},
	_mask_remover: function(el) {
		/*mask_id = "mask_for_" + el.id;
    	if(!!$(mask_id)){
	    		document.body.removeChild($(mask_id));
    	}*/
    },
	_initLoadMask: function(){
		if(!!$("loading-content")){
			return $("loading-content");
		}else{
            pdiv = document.createElement("div");
            pdiv.setAttribute('class', 'yui-skin-sam');
            div = document.createElement('div');
			div.setAttribute('id', 'loading-content');
            pdiv = document.body.appendChild(pdiv);
			return pdiv.appendChild(div);
		}
	},_loadMask: function(el, load){
		var content = this._initLoadMask();
		content.innerHTML = "";
        if (!YAHOO.wait) {

            // Initialize the temporary Panel to display while waiting for external content to load

            YAHOO.wait = new YAHOO.widget.Panel("wait",{ width: "256px",
                                  fixedcenter: true,
                                  close: false,
                                  draggable: false,
                                  zindex:4,
                                  modal: true,
                                  visible: false
                                });

            YAHOO.wait.setHeader("Loading, please wait...");
            YAHOO.wait.setBody("<img src=\"http://us.i1.yimg.com/us.yimg.com/i/us/per/gr/gp/rel_interstitial_loading.gif\"/>");
            YAHOO.wait.render(document.body);

		}
	if(!YAHOO.util.Dom.hasClass(document.body, 'yui-skin-sam-cust'))
		YAHOO.util.Dom.addClass(document.body, 'yui-skin-sam-cust');
	YAHOO.wait.show();
	},_loadStatusMask: function(el, load, status){
		return false;
	},
	rList: [],
	onReady: function(fn, scope) {
		if (scope) {
			this.rList.push(fn.bind(scope));
		} else {
			this.rList.push(fn);
		};
	},
	_onPLoad: function() {
		for(var i=0; i<this.rList.length; i++) {
			this.rList[i]();
		}
	},
	// ----- Search Box Functionality ----------------
	request: function(url, params){
		var  sUrl ="";
		for(p in params.parameters){
			//console.debug(p);
			sUrl += p+ '=' + encodeURIComponent(params.parameters[p]) + "&";
		}

		this._loadMask(null, null);
		var AjaxObject = {
		handleSuccess:function(o){
			params.onSuccess(eval('(' + o.responseText + ')'), o.responseText);//: function()
			this.hide_load_panel();
			this.processResult(o);
		},
		hide_load_panel:function (){
			if(YAHOO.util.Dom.hasClass(document.body, 'yui-skin-sam-cust'))
				YAHOO.util.Dom.removeClass(document.body, 'yui-skin-sam-cust');
			YAHOO.wait.hide();
		},handleFailure:function(o){
			// Failure handler
			this.hide_load_panel();
		},

		processResult:function(o){
			// This member is called by handleSuccess
		},
		startRequest:function() {
		   YAHOO.util.Connect.asyncRequest('POST', url, callback, sUrl);
		}

	};

	/*
	 * Define the callback object for success and failure
	 * handlers as well as object scope.
	 */
	var callback =
	{
		success:AjaxObject.handleSuccess,
		failure:AjaxObject.handleFailure,
		scope: AjaxObject
	};

// Start the transaction.
	AjaxObject.startRequest();
	},chkMail: function (mail){
         var email_reg = /^([A-Za-z0-9_\-\.])+\@([A-Za-z0-9_\-\.])+\.([A-Za-z]{2,4})$/;
		return email_reg.test(mail);
	},checkUKTelephone :function (telephoneNumber) {

  // Convert into a string and check that we were provided with something
  var telnum = telephoneNumber + "";
  if (telnum.length == 1)  {
     telNumberErrorNo = 1;
     return false
  }
  telnum.length = telnum.length - 1;

  // Don't allow country codes to be included (assumes a leading "+")
  var exp = /^(\+)[\s]*(.*)$/;
  if (exp.test(telnum) == true) {
     telNumberErrorNo = 2;
     return false;
  }

// // Remove spaces from the telephone number to help validation
// while (telnum.indexOf(" ")!= -1)  {
//   telnum = telnum.slice (0,telnum.indexOf(" ")) + telnum.slice (telnum.indexOf(" ")+1)
// }
//
// // Remove hyphens from the telephone number to help validation
// while (telnum.indexOf("-")!= -1)  {
//   telnum = telnum.slice (0,telnum.indexOf("-")) + telnum.slice (telnum.indexOf("-")+1)
// }

  // Now check that all the characters are digits
  exp = /^([0-9]{10,11})$/;
  if (exp.test(telnum) != true) {
     telNumberErrorNo = 3;
     return false;
  }

  // Now check that the first digit is 0
  exp = /^0[0-9]{9,10}$/;
  if (exp.test(telnum) != true) {
     telNumberErrorNo = 4;
     return false;
  }

  // Disallow numbers allocated for dramas.

  // Array holds the regular expressions for the drama telephone numbers
  var tnexp = new Array ();
	tnexp.push (/^(0113|0114|0115|0116|0117|0118|0121|0131|0141|0151|0161)(4960)[0-9]{3}$/);
	tnexp.push (/^02079460[0-9]{3}$/);
	tnexp.push (/^01914980[0-9]{3}$/);
	tnexp.push (/^02890180[0-9]{3}$/);
	tnexp.push (/^02920180[0-9]{3}$/);
	tnexp.push (/^01632960[0-9]{3}$/);
	tnexp.push (/^07700900[0-9]{3}$/);
	tnexp.push (/^08081570[0-9]{3}$/);
	tnexp.push (/^09098790[0-9]{3}$/);
	tnexp.push (/^03069990[0-9]{3}$/);

	for (var i=0; i<tnexp.length; i++) {
    if ( tnexp[i].test(telnum) ) {
      telNumberErrorNo = 5;
      return false;
    }
	}
  // Finally check that the telephone number is appropriate.
  exp = (/^(01|02|03|05|071|072|073|074|075|07624|077|078|079)[0-9]+$/);
	if (exp.test(telnum) != true) {
     telNumberErrorNo = 5;
     return false;
  }

  // Array holds the numbers acceptable by oxygen
  var recycle_acceptable = new Array ();
      recycle_acceptable.push ('01');   //Geographical Numbers
      recycle_acceptable.push ('02');   //Geographical Numbers
      recycle_acceptable.push ('071');  //Mobile Services
      recycle_acceptable.push ('072');  //Mobile Services
      recycle_acceptable.push ('073');  //Mobile Services
      recycle_acceptable.push ('074');  //Mobile Services
      recycle_acceptable.push ('075');  //Mobile Services
      recycle_acceptable.push ('077');  //Mobile Services
      recycle_acceptable.push ('078');  //Mobile Services
      recycle_acceptable.push ('079');  //Mobile Services


   var in_rec_ar = false;
   for (var i = 0; i < recycle_acceptable.length; i++)
   {
      if (telnum.indexOf(recycle_acceptable[i]) === 0)
      {
        in_rec_ar = true;
        break;
      }
   }

   if (!in_rec_ar)
   {
     telNumberErrorNo = 6;
     return false;
   }

  // Telephone number seems to be valid - return the stripped telehone number
  return telnum;
},
	btn: function(){
		var m_btns = document.getElementsByClassName('m_btn');
		for(var i=0; i < m_btns.length; i++){
			m_btns[i].observe("mouseover", function(ev){
				ev.target.className = "m_btn-over";
			});
			m_btns[i].observe("mouseout", function(ev){
				ev.target.className = "m_btn";
			});
		}
		var s_btns = document.getElementsByClassName('s_btn');
		for(var i=0; i < s_btns.length; i++){
			s_btns[i].observe("mouseover", function(ev){
				ev.target.className = "s_btn-over";
			});
			s_btns[i].observe("mouseout", function(ev){
				ev.target.className = "s_btn";
			});
		}
		var l_btns = document.getElementsByClassName('l_btn');
		for(var i=0; i < l_btns.length; i++){
			l_btns[i].observe("mouseover", function(ev){
				ev.target.className = "l_btn-over";
			});
			l_btns[i].observe("mouseout", function(ev){
				ev.target.className = "l_btn";
			});
		}

	},
	chache_states: {},
	onChangeCountry: function(c_selector, state_selector_id, mask_el) {
		var country_id = c_selector.value;

		var state_selector = $(state_selector_id);
		if(country_id == -1){
			var newOpt = new Option("Any","-1");
			state_selector.add(newOpt, null);
			return false;
		}
		if (state_selector) {
			if (this.chache_states && this.chache_states[country_id]) {
				this.updateStateSelector(state_selector, this.chache_states[country_id]);
			} else {
				this.current_state_selector = state_selector;
				this.current_mask_el = mask_el ? mask_el : null;
				if (this.current_mask_el) {
					Main._loadMask(this.current_mask_el, true);
				}
				Main.request("ajax_getstates_list.php", {
					parameters: {country_id: country_id},
					onSuccess: function(json, response){
						var list = null;
						if (json && json['country_id'] > 0) {
							if (json['data']) {
								list = json['data'];
							}
							this.chache_states[json['country_id']] = list;
						}
						this.updateStateSelector(this.current_state_selector, list);
						if (this.current_mask_el) {
							Main._loadMask(this.current_mask_el, false);
						}
					},
					scope: this
				});
			}
		}
	},

	updateStateSelector: function(selector, list) {
		if (!selector) return null;
		var l = [];
		if (list) {
			for(var i in list) {
				l.push({v: i, t: list[i]});
			}
		}

		if (l.length == 0) {
			selector.disabled = true;
			return true;
		}

		while(selector.options.length > 0) {
			selector.remove(0);
		}
		for(var i=0; i<l.length; i++) {
			var newOpt = new Option(l[i].t, l[i].v);
			try {
    			selector.add(newOpt, null);
  			}
			catch(ex) {
				selector.add(newOpt); // IE only
			}
		}
		selector.selectedIndex = 0;
	}
};

Main.ajaxForm = function(config) {
	Main.apply(this, config);
	this.init();
};

Main.ajaxForm.prototype = {

	form: null,

	with_multiselect: false,

	multi_select_name: 'f[categories]',

	inputErrorClass: 'field-invalid',

	invalidClass: '',

	divErrorClass: 'error',

	listeners: null,

	mask_element: null,

	alert_title: "Information",

	init: function() {
		var f = $(this.form);
		if (!f) {
			Main.showDebug('FATAL - FORM element not found!!');
			return false;
		}
		if(!this.mask_element){
				this.mask_element = this.form;
		}

		f.onsubmit = this._onSubmit.bind(this);
		this.form = f;
	},
	_onSubmit: function() {
		Main._loadMask(this.mask_element, true);
		if(this.with_multiselect == false){
			Main.request(this.form.action,{
				parameters: this.form.serialize(true),
				onSuccess: function(json){
					this._onRequestComplete(json);

				},
				onFail: function(json){
					this._onRequestComplete(json);
				},
				scope: this,
				fscope: this
			})
		}else{
				var url 	= this.form.action;
				var data = this.form.serialize(true);
				var categories = null;
				data[this.multi_select_name]._each(function(item){
					if(categories == null){
						categories = item;
					}else{
						categories += ","+item;
					}
				}.bind(this));
				data[this.multi_select_name] = categories;
				Main.request(url,{
					parameters: data,
					onSuccess: function(json){
						this._onRequestComplete(json);
					},
					onFail: function(json){
						this._onRequestComplete(json);
					},
					scope: this,
					fscope: this
				})
		}
		return false;
	},
	_onRequestComplete: function(jsonObj) {
	if(YAHOO.util.Dom.hasClass(document.body, 'yui-skin-sam'))
				YAHOO.util.Dom.removeClass(document.body, 'yui-skin-sam');
		YAHOO.wait.hide();
		if (jsonObj) {
			var msg_text = null;
			if (jsonObj.messages) {
				var m = jsonObj.messages;
				if (m instanceof Array) {
					msg_text = m.join("<br />");
				} else if (jsonObj.is_error == true) {
					this._setupErrors(m);
				} else {
					this.resetErrors();
				}
			}
			if (msg_text) {
				if (jsonObj.is_error == true) {
					//Main.showAlert(msg_text, "Error",
					//	this._internalOnFail.bind(this, jsonObj)
					//);
					this._internalOnFail(jsonObj);
				} else {
					this.resetErrors();
					//Main.showAlert(msg_text, this.alert_title,
					//	this._internalOnSuccess.bind(this, jsonObj)
					//);
					this._internalOnSuccess(jsonObj);
				}
			} else {
				if (jsonObj.is_error == true) {
					this._internalOnFail(jsonObj);
				} else {
					this._internalOnSuccess(jsonObj);
				}
			}
		} else {
			var req_fail = "Request is fail. Please, try later.";
			//Main.showAlert(req_fail, "Error",
			//	this._internalOnFail.bind(this, jsonObj)
			//);
			this._internalOnFail(jsonObj);
		}

		//Main._loadMask(this.mask_element, false);
	},

	_internalOnSuccess: function(result) {
		if (!this.listeners) return false;
		var f = this.listeners['onSuccess'] ? this.listeners['onSuccess'] : null;
		if (f && typeof f == 'function') {
			if (this.listeners['scope']) {
				f.apply(this.listeners['scope'], arguments);
			} else {
				f(result);
			}
		}
	},

	_internalOnFail: function(result) {
		if (!this.listeners) return false;
		var f = this.listeners['onFail'] ? this.listeners['onFail'] : null;
		if (f && typeof f == 'function') {
			if (this.listeners['scope']) {
				f.apply(this.listeners['scope'], arguments);
			} else {
				f(result);
			}
		}
	},

	_setFieldState: function(field, is_valid, mes) {
		if (!is_valid) {
			if (!field.error_div) {
				var p = field.parentNode;
				var d = document.createElement("div");
				d.className = this.divErrorClass;
				p.appendChild(d);
				field.error_div = d;
			} else {
				field.error_div.style.display = '';
			}
			field.error_div.innerHTML = mes;
			if(!field.is_invalid){
				field.begining_class = field.className;
				field.className += " "+this.inputErrorClass+this.invalidClass;
				field.is_invalid = true;
			}
		} else if(field.is_invalid) {
				field.is_invalid = false;
				field.error_div.style.display = 'none';
				field.className = field.begining_class;
		}
	},
	_getFieldsMap: function() {
		if (!this.fieldsMap) {
			var m = this.form.elements;
			var map = {};
			for(var i=0; i<m.length; i++) {
				if (m[i].tagName == 'FIELDSET' || m[i].type == "checkbox" || m[i].type == "reset" || m[i].type == "hidden" || m[i].type == "button" || m[i].type == "submit" || m[i].type == "image" || m[i].type == "radio") {
					continue;
				}
				var data_key = this.getFieldDataKey(m[i]);
				if (data_key) {
					if (map[data_key]) {
						Main.showDebug('already_set' + data_key);
					} else {
						map[data_key] = m[i];
						var error_div_id = m[i].getAttribute("error_div_id");
						if (error_div_id) {
							var error_div = document.getElementById(error_div_id);
							if (error_div) {
								m[i].error_div = error_div;
							}
						}
						//m[i].onfocus = this._setFieldState.bind(this, m[i], true);
					}
				} else {
					Main.showDebug('Cant get ' + m[i].name + m[i].type);
				}
			}
			this.fieldsMap = map;
		}

		return this.fieldsMap;
	},

	getFieldDataKey: function(field) {
		var res = field.getAttribute("_dataIndex");
		if (!res) {
			res = field.name.replace(/(?:.*\[)(.*)(?:\])/, "$1");
		}
		return res;
	},

	resetErrors: function() {
		this._setupErrors({});
	},

	reset: function() {
		this.form.reset();
		this._setupErrors({});
	},

	_setupErrors: function(mesages){
		var m = this._getFieldsMap();
		for(var name in m) {
			if (mesages[name]) {
				this._setFieldState(m[name], false, mesages[name]);
			} else {
				this._setFieldState(m[name], true);
			}
		}
	},
	submit: function() {
		this._onSubmit();
	}
};
// *************************** Prototype  GRID **************************
/*
  		Example of use :

  	 	 var config = {
			url : "ajax_search_users.php",
			content_container: "search_users_box",
			mask_element: "mask_container",
			limit: public_num_rows,
			template: new Template('<div class="f_l userbox">' +
				'<a href="profile.php?user_id=#{user_id}"><div class="shadow"><div class="shadow_inner"><img src="#{picture}" alt="#{username}" /></div></div></a></div>')
		};
		new Main.grid(config);
 */


Main.grid = function (config) {
	Main.apply(this, config);
	this.init();
}

Main.grid.prototype = {
	limit: 10, // Count records on the one page is displaying
	mask_element: null, // Default mask element applyed to general content container. If set "none" then mask does not applyed
	url: null, //REQUIRED
	params: {}, // Additional parameters for AJAX REQUEST
	pager_container: null,
	content_container: null, //REQUIRED:  ID of content container
	template: null, // Required Prototype Template. Example new Template("<img src='#{picture}' alt="#{name}" />");
	no_records: "No Records to Display.",
	init_page: 0,
	init: function(){
		if(!this.url){
			Main.showDebug("FATAL - Url undefined!");
			return false;
		}
		this.params["limit"] = this.limit;

		this.content_container = $(this.content_container);

		if(!this.content_container){
			Main.showDebug("FATAL -  Content container undefined!");
			return false;
		}
		this.pager_container = $(this.pager_container);
		if(!this.template || typeof this.template != "object"){
			Main.showDebug("FATAL -  Template for Records not defined.<br> <a class='pointer' target='_blank' href='http://prototypejs.org/api/template'>See Doc</a>");
			return false;
		}
		this._loadGrid(this.init_page);
	},
	_loadGrid: function(page){

		this._mask(true);

		this.start = page*this.limit;
		this.page = page;
		this.params["start"] = this.start;

		Main.request(this.url, {
			parameters: this.params,
			onSuccess: function(json, response){
				if(!json){
					eval("json = " + response);
				}
				var records = "";
				if(json.total > 0){
					records = this._getAllRecords(json.data);
				} else {
					records = this.no_records;
				}
				this.content_container.update(records);
				if(this.pager_container){
					this.pager_container.update(this._getPager(json));
				} else {
					if(!this._internalPagerContainer){
						this._internalPagerContainer = new Element("div", {"class": "f_r"});
					}
					this.content_container.insert(this._internalPagerContainer);
					var dd =this._getPager(json);
					this._internalPagerContainer.update(dd);
				}
				this._mask(false);
			},
			scope: this
		});
	},
	_getAllRecords: function(data){
			var content = '';
			data.each(function(item){
					content += this.template.evaluate(item);
			}.bind(this))
			content += '<div class="clear"></div>';
			return content;
	},
	_getPager: function(d){
				var content = new Element("div");
				if(d.total > this.limit){
						var count_pages = Math.round(0.4+(d.total / this.limit));
						var a = {};
						if (this.start != 0){

								a = this._createPagerLinkWithListener(0, "<< First");
								content.insert(a);

							    a = this._createPagerLinkWithListener((parseInt(this.page)-1), "< Previous");
								content.insert(a);

						}
						for(var i = 0 ; i <count_pages; i++){
							if(this.page == i){
								content.insert(new Element('span', {"class": "active pager_link"}).update((i+1)));
							}else{
							    a = this._createPagerLinkWithListener(i, (i+1));
								content.insert(a);
							}
				 		}
				 	    if(this.page < (count_pages-1)){
						    a = this._createPagerLinkWithListener((parseInt(this.page)+1), "Next >");
							content.insert(a);

						    a = this._createPagerLinkWithListener((parseInt(count_pages)-1), "Last >>");
							content.insert(a);
				 	    }
				}
			return content;
	},
	_mask: function (show){
		if(this.mask_element != "none"){
			if(!this._ismask){
				this._ismask = this.mask_element;
			}
			if(this._ismask == null){
				this.mask_element = this.content_container;
			} else {
				this.mask_element = $(this.mask_element);
			}
			if(this.mask_element){
				Main._loadMask(this.mask_element, show);
			}
		}
	},
	_createPagerLinkWithListener: function(param, name){
			var a = new Element("a", {"class": "pointer pager_link"});
			a.update(name);
			a.observe("click", this._loadGrid.bind(this, [parseInt(param)]));
			return a;
	}
}

String.prototype.trim = function() {
a = this.replace(/^\s+/, '');
return a.replace(/\s+$/, '');
};


// following it the Custom dropdown className
/*
	sample usage:
	window.reg_but = new customDD("country-select", "country-button");
	where
	country-select - id of select Element
	country-button - id of styled button
*/
function cDropDown(sel_id, but_id){
	var o = this;
	var c = {s_id:sel_id, b_id:but_id, dd:null};
	if(o && c && typeof c == 'object'){
         for(var p in c){
             o[p] = c[p];
         }
     }
	YAHOO.util.Event.onAvailable(this.s_id, this.initCalaback, this, this);
}

cDropDown.prototype = {
s_id:"",
b_id:"",
dd:"",
initCalaback:function(){
	el = $(this.s_id);
	var i_text = el.options[el.selectedIndex].text;
	var i_val = el.options[el.selectedIndex].value;
	this.dd  = new YAHOO.widget.Button(this.b_id, {
	                                        type: "menu",
	                                        menu: this.s_id });
		cmenu = this.dd.getMenu();
		cmenu.subscribe('click', function(oArgs, item){
			srcEl = item[1].srcElement;
		this.dd.set('value',srcEl.value);
		this.dd.set('label', srcEl.text);
		}, this, this);
		this.dd.set('value',i_val);
		this.dd.set('label', i_text);

},getValue:function (){
	return {value:this.dd.get('value'), title:this.dd.get('label')};
}
};
Object.prototype.hasProp = function(property) {
    return typeof(this[property]) !== 'undefined'
};

function send_message_front(ad_id){



Main.request(Main._u({side:'user',cl:'message', act:'getsform'}),{
	parameters:{'ad_id':ad_id},
	onSuccess: function (el, resp){

		if(!YAHOO.util.Dom.hasClass(document.body, 'yui-skin-sam'))
			YAHOO.util.Dom.addClass(document.body, 'yui-skin-sam');

		div = document.createElement('div');
		nid = 'resp-' + el.id;
		div.setAttribute('id', nid);
		document.body.appendChild(div);
		YAHOO.mess = new YAHOO.widget.Panel(nid,
                                                    {
													  width: "697px",
                                                      fixedcenter: true,
                                                      close: false,
                                                      draggable: false,
                                                      zindex:4,
                                                      modal: true,
                                                      visible: true
                                                    }
                                                );

            YAHOO.mess.setHeader("");
            YAHOO.mess.setBody(el.html);
            YAHOO.mess.render(document.body);
			$(nid).style.backgroundColor = "#FFF";
			$(nid).style.border = "1px solid #4D8C38";
			$(nid).style.padding = "5px";
			window.dialog_ad_id = el.id;
			window.dialog_user_id = el.user_id;
	}
	});
}

function send_message_front_do(){

	if(Main.isEmpty($('dialog-theme').getValue())){
		if(!confirm('Are you sure you whant send this message without subject?')){
			$('dialog-theme').focus();
			return false;
		}

	}
	if(Main.isEmpty($('dialog-body').getValue(''))){
		if(!confirm('Are you sure you whant send this message without body?')){
			$('dialog-body').focus();
			return false;
		}
	}

	hide_message_front();
	Main.request("index.php", {
					parameters: {'side':'user','cl':'message','act' :'post-message',
                    'm[ad_id]': window.dialog_ad_id,
                    'm[to_user_id]': window.dialog_user_id,
                    'm[subject]': $('dialog-theme').getValue(),
                    'm[body]': $('dialog-body').getValue()} ,
					onSuccess: function(json, response){

						alert('Message sent');
					},
					scope: this
	});

	//$('dialog-theme')
	//$('dialog-body')
}

function hide_message_front(){
	if(!YAHOO.util.Dom.hasClass(document.body, 'yui-skin-sam'))
		YAHOO.util.Dom.removeClass(document.body, 'yui-skin-sam');
	YAHOO.mess.hide();
}

/*
 * Sample for create new window
 * var win = new Window({
					html: '<img src="gallery/users/thumbs/thumb12217507282251.jpg" alt="" />',
					width: 300,
					close_btn_id: "close_btn",
					destroyOnClose: true

		});
		win.show();
		win.setTitle("Window Title");
		win.setContent('<center>Test Window</center> <input type="button" id="close_btn" value=" Close" />');
 *
 */

