document.write('<div style="position: absolute; right: 0px; width: 200px; height: 300px; overflow: auto;" id="_d"></div>');

function _d(o,a,c) {
	if (a)
		$('_d').innerHTML =  (c?Object.toJSON(o):o) + ((o && o.id)?(' id=' + o.id):'') + '<br>' + $('_d').innerHTML;
	else
		$('_d').innerHTML = Math.random() + ': ' + (c?Object.toJSON(o):o) + ((o && o.id)?(' id=' + o.id):'');
	return true;
	}


var gd = new Date(); 
var oldtime=gd.getTime();


function _timer(label) {
	var d = new Date(); 
	_d(label + ': ' +  (d.getTime()-oldtime) ,true);
	oldtime = d.getTime();
	}
function eyeplasticsTip(tt) {
	$('WzTtDiV').show();
	return Tip(tt, WIDTH, 200);
	}
	
function eyeplasticsTTT(tti) {
	$('WzTtDiV').show();
	var newid = 'definitiontip_' + tti.replace(/[\s]/gim,'_').toLowerCase();
	TagToTip(newid, WIDTH, 200);
	}
	
function loadFlash(img,id,w,h) {
	var flashvars = {};
	var params = {};
	params.allowscriptaccess = "always";
	params.wmode = "transparent";
	var attributes = {};
	swfobject.embedSWF(img, id, w, h, "9.0.0", '',flashvars, params, attributes);
	}



function clickForEnter(o,c) {
	if ($(o) && $(o).hasClassName(c))  
		{
		$(o).removeClassName(c);
		$(o).value='';
		return true;
		}
	else {
		return false;
		}
	}

function setTimePicker(descr, dat, onlyshow)
	{
	var tmpdate = (dat?(new Date(dat*1000)):(tmpdate = new Date()));

	tmpdate.setUTCHours(7);
	tmpdate.setUTCMinutes(0);
	tmpdate.setSeconds(0);
	$(descr + '_visible').innerHTML = tmpdate.print('%A, %e %B %Y');
	$(descr + '_hidden').value = (tmpdate.valueOf()/1000);
	if (onlyshow) return;
		Calendar.setup({
			range: [1976,2100],
			inputField    	:   descr + "_hidden",     // id of the input field
			displayArea		:	descr + "_visible",
			date			:   tmpdate,
			daFormat      	:    "%A, %e %B %Y",      // format of the input field
			ifFormat      	:    "%s",      // format of the input field
			button        	:    descr + "_button",  // trigger for the calendar (button ID)
			showsTime		:	false,  
			align       	:    "Tl",           // alignment (defaults to "Bl")
			showOthers		:	false,
			singleClick   	:    true
		});
	$(descr + "_button").style.cursor="pointer";
	$(descr + "_button").style.border = "1px solid red";
	$(descr + "_button").title="Date selector";
	$(descr + "_button").style.display="inline";
	$(descr + "_button").style.marginLeft="4pt";
	$(descr + "_button").onmouseover="this.style.background='red';";
	$(descr + "_button").onmouseout="this.style.background=''";
	}

	
function setErrorMessages(formid,setnotices,setwarnings,seterrors) {
	if (!seterrors) seterrors = $H({});
	if (!setwarnings) setwarnings = $H({});
	if (!setnotices) setnotices = $H({});
	var formisok = true;
	$(formid).select('.errormessage').each( function (errordiv) {
		var errorid = errordiv.id.replace(/_error$/,'');
		errordiv.hide();
		errordiv.removeClassName('notice');
		errordiv.removeClassName('warning');
		errordiv.removeClassName('error');
		if (seterrors.get(errorid)) {
			errordiv.innerHTML = seterrors.get(errorid);
			errordiv.addClassName('error');
			errordiv.show();
			formisok = false;
			}
		else {
			if (setwarnings.get(errorid)) {
				errordiv.innerHTML = setwarnings.get(errorid);
				errordiv.addClassName('warning');
				errordiv.show();
				}
			else {
				if (setnotices.get(errorid)) {
					errordiv.innerHTML = setnotices.get(errorid);
					errordiv.addClassName('notice');
					errordiv.show();
					}
				}
			}
		});
	$(formid).getInputs('submit').each( function (submb) {
		submb.disabled = !formisok;
		} );
	return formisok;
	}

function checkForm(formid,ajaxurl,trytopost) {
	if (!trytopost) {
		var reterrors = false;
		var retwarnings = false;
		var retnotices = false;
		if (formchecking) return;
		formchecking = $H($(formid).serialize(true));
		if (formchecking.toJSON() == formchecked ) {
			formchecking = false;
			return false;
			}
		}
	else {
		$(formid).getInputs('submit').each( function (submb) {
			submb.disabled = true;
			});
		formchecking = $H($(formid).serialize(true));
		dim(formid,true,'<h2>Saving data...</h2>');
		}
	new Ajax.Request(ajaxurl + '?json=1' + (trytopost?'&post=1':'') , {
  	method: 'POST', 
  	parameters: formchecking,
	onSuccess: function(transport) {
		formchecked = formchecking.toJSON();
		try {
			resp = $H(transport.responseText.evalJSON());
			reterrors = $H(resp.get('errors'));
			retwarnings = $H(resp.get('warnings'));
			retnotices = $H(resp.get('notices'));
			}
		catch (e) {
			reterrors = false;
			retwarnings = false;
			retnotices = false;
			}
		dim(formid,false);
		setErrorMessages(formid,retnotices,retwarnings,reterrors);
		formchecking = false;
		if (trytopost && $(formid).ajaxOptions.onSuccess) $(formid).ajaxOptions.onSuccess(resp);
		},
	onFailure:function() {
		setErrorMessages(formid,false);
		formchecking = false;
		formchecked = false;
		// alert('Failure');
		dim(formid,false);
		},
	onException: function() {
		setErrorMessages(formid,false);
		formchecking = false;
		formchecked = false;
		alert('Exception');
		dim(formid,false);
		}
	});
	return false;
}

function ajaxCheckForm(formid,ajaxurl,opt){
	var opts = Object.extend({
			timeinterval: 250,                        
			onSuccess: null
							}, arguments[2] || { });
	$(formid).ajaxOptions = opts;
	setInterval("checkForm('"+formid+"','"+ajaxurl+"')",opts.timeinterval);
	if (!$(formid).onsubmit) $(formid).onsubmit = function (event) {
		checkForm(formid,ajaxurl, true); 
		return false;
		};
	}
	
function dim(divid,dimundim,message) {
	if (!$('_dim')) return;
	$('_dim').innerHTML = message?message:'';
	if (dimundim && $(divid)) $('_dim').clonePosition(divid);
	if (dimundim) $('_dim').show();
	else $('_dim').hide();
	}
	
var Url = {
 
	// public method for url encoding
	encode : function (string) {
		return escape(this._utf8_encode(string));
	},
 
	// public method for url decoding
	decode : function (string) {
		return this._utf8_decode(unescape(string));
	},
 
	// private method for UTF-8 encoding
	_utf8_encode : function (string) {
		string = string.replace(/\r\n/g,"\n");
		var utftext = "";
 
		for (var n = 0; n < string.length; n++) {
 
			var c = string.charCodeAt(n);
 
			if (c < 128) {
				utftext += String.fromCharCode(c);
			}
			else if((c > 127) && (c < 2048)) {
				utftext += String.fromCharCode((c >> 6) | 192);
				utftext += String.fromCharCode((c & 63) | 128);
			}
			else {
				utftext += String.fromCharCode((c >> 12) | 224);
				utftext += String.fromCharCode(((c >> 6) & 63) | 128);
				utftext += String.fromCharCode((c & 63) | 128);
			}
 
		}
 
		return utftext;
	},
 
	// private method for UTF-8 decoding
	_utf8_decode : function (utftext) {
		var string = "";
		var i = 0;
		var c = c1 = c2 = 0;
 
		while ( i < utftext.length ) {
 
			c = utftext.charCodeAt(i);
 
			if (c < 128) {
				string += String.fromCharCode(c);
				i++;
			}
			else if((c > 191) && (c < 224)) {
				c2 = utftext.charCodeAt(i+1);
				string += String.fromCharCode(((c & 31) << 6) | (c2 & 63));
				i += 2;
			}
			else {
				c2 = utftext.charCodeAt(i+1);
				c3 = utftext.charCodeAt(i+2);
				string += String.fromCharCode(((c & 15) << 12) | ((c2 & 63) << 6) | (c3 & 63));
				i += 3;
			}
 
		}
 
		return string;
	}
 
}

Element.collectTextNodes1 = function(element) {
  // element = Element.cleanWhitespace(element);
  if (!$(element)) return new Array();
  return $A($(element).childNodes).collect( function(node) {
    return (node.nodeType==3 ? node : Element.collectTextNodes1(node));
  }).flatten();
}

function deletePlayer(thePlaceholder, thePlayerId, theInnerId) { 
    swfobject.removeSWF(thePlayerId);
	if($(thePlaceholder)) $(thePlaceholder).innerHTML = "<div id=" + theInnerId + "></div>"
}
 
function createPlayer(thePlaceholder, theFile, sx, sy) { 
	
 	var thePlayerId = thePlaceholder + '_player_id';
	var theInnerId = thePlaceholder + '_inner_id';
	deletePlayer(thePlaceholder, thePlayerId, theInnerId);
 
	if (sx) {var thePlaceholder_width = "" + sx;}
	else thePlaceholder_width = "" + $(thePlaceholder).getWidth();
	if (!thePlaceholder_width) thePlaceholder_width = "100";
	
	
	if (sy) {var thePlaceholder_height = "" + sy;}
	else thePlaceholder_height = "" + $(thePlaceholder).getHeight();
	if (!thePlaceholder_height) thePlaceholder_height = thePlaceholder_width;
	
	var flashvars = {
		file:theFile, 
		autostart:'true',
		repeat:"false"
	};
	swfobject.embedSWF("/img/mediaplayer.swf", theInnerId, thePlaceholder_width, thePlaceholder_height, "9.0.115", false, flashvars);
}



/* check for image validation on add my location form*/

function dim_locations(divid,dimundim,message,formaction) {

	if(formaction == 'add')
	{
	if(document.getElementById('imagemap').checked == true)
		{
			var extensions = new Array("jpg","jpeg","gif","png");
 
			var mapimage = document.location_form.mapimage.value;
						
			var image_length = document.location_form.mapimage.value.length;
			
			var pos = mapimage.lastIndexOf('.') + 1;
			
			var ext = mapimage.substring(pos, image_length);
			
			var final_ext = ext.toLowerCase();
			
			for (i = 0; i < extensions.length; i++)
			{
			if(extensions[i] == final_ext)
			{
			return true;
			}
			}
			
			alert("You must upload an image file with one of the following extensions: "+ extensions.join(', ') +".");
			return false;		
		}	

	} // only for add action 

	if (!$('_dim')) return;
	$('_dim').innerHTML = message?message:'';
	if (dimundim && $(divid)) $('_dim').clonePosition(divid);
	if (dimundim) $('_dim').show();
	else $('_dim').hide();
	}

/*  end image validation */

