function MM_swapImgRestore() { //v3.0
  var i,x,a=document.MM_sr; for(i=0;a&&i<a.length&&(x=a[i])&&x.oSrc;i++) x.src=x.oSrc;
}

function MM_preloadImages() { //v3.0
  var d=document; if(d.images){ if(!d.MM_p) d.MM_p=new Array();
    var i,j=d.MM_p.length,a=MM_preloadImages.arguments; for(i=0; i<a.length; i++)
    if (a[i].indexOf("#")!=0){ d.MM_p[j]=new Image; d.MM_p[j++].src=a[i];}}
}

function MM_findObj(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=MM_findObj(n,d.layers[i].document);
  if(!x && d.getElementById) x=d.getElementById(n); return x;
}

function MM_swapImage() { //v3.0
  var i,j=0,x,a=MM_swapImage.arguments; document.MM_sr=new Array; for(i=0;i<(a.length-2);i+=3)
   if ((x=MM_findObj(a[i]))!=null){document.MM_sr[j++]=x; if(!x.oSrc) x.oSrc=x.src; x.src=a[i+2];}
}

function confirmLink(Link, action){
  var is_confirmed = confirm(action);
    if (is_confirmed) {
        Link.href += '&is_confirmed=1';
    }
    return is_confirmed;
}

function page_wrap()
{
	if ($('#sub_menu_con').height() > $('#ajax_con').height())
	{
		def_height = $('#sub_menu').height();
		wrap_space = $('#sub_menu_con').height();
	}
	else
	{
		def_height = $('#main_con').height();
		wrap_space = $('#ajax_con').height();
	}
	
	size_diff = wrap_space - def_height;
	
	if (size_diff >= 0)
		wrap_mltp = Math.round(size_diff / 20)+1 ;
	else
		wrap_mltp = 1;
		
	$('#wrapper').height(20*wrap_mltp);
	$('#overlay').fadeOut();
	
}

// Change the background of the object to color on mouseOver.
function mOvr(src, clr, tclr, tbld) {
//   if (!src.contains(event.fromElement)) {
     	src.style.cursor = 'pointer';
		src.style.color = tclr;
     	src.bgColor = clr;
		src.style.fontWeight=tbld;
//   }
}
// Change the background of the object to image on mouseOver.
function mOvri(src, img, tclr, tbld) {
//   if (!src.contains(event.fromElement)) {
     	src.style.cursor = 'pointer';
		src.style.color = tclr;
     	src.backgroundImages = 'url(img)';
		src.style.fontWeight=tbld;
//   }
}
// Change the background of the object to color on mouseOut.
function mOut(src, clr, tclr) {
//   if (!src.contains(event.toElement)) {
     	src.style.cursor = 'default';
		src.style.fontWeight= 'normal';
     	src.bgColor = clr;
		src.style.color = tclr;
//   }
}
// Change the background of the object to image on mouseOut.
function mOuti(src, img, tclr) {
//   if (!src.contains(event.toElement)) {
     	src.style.cursor = 'default';
		src.style.fontWeight= 'normal';
     	src.backgroundImage = 'url(img)';
		src.style.color = tclr;
//   }
}
function initialize_map() {
      if (GBrowserIsCompatible()) {
        var map = new GMap2(document.getElementById("map_canvas"));
        map.setCenter(new GLatLng(42.678549,23.289653), 15);
       
    	var point = new GLatLng(42.678549,23.289653);
    	map.addOverlay(new GMarker(point));
        map.setUIToDefault();
      }
    }
function main_ajax()
{
	$('.ajax').ajaxContent(
			{  
				loader: false,
				target:'#ajax_con',
				beforeSend:function()
				{ 
					//$('#ajax_con').fadeOut(500);
				},
				success:function()
				{
					//$('#ajax_con').fadeIn(0);
					page_wrap();				
				} 
	 		});
}

function form_ajax(name,binds,misc)
{
	$(name).ajaxContent(
			{  
				loader: false,
				target:'#ajaxContent',
				bind: binds,
				beforeSend:function()
				{ 
					$('#ajaxContent').slideUp(500);
				},
				success:function()
				{
					$('#ajaxContent').slideDown(500);
				} 
	 		})
}
function comm_ajax_load(str_invalid,str_uploading,str_done,str_failed)
{
	
	comm_form_ajax('.ajaxcomments','#item_id,#type_id,#post_text');
		
	$('#dialog').dialog({ autoOpen: false, height: 300, width: 500, show: 'slide',hide: 'slide',resizable: false,modal: true });
	
	$('.open_dialog').click(function(){
		att_count = $(this).find('.att_count');
		$('#dialog').dialog('open');
			return false;	
	});
	comm_attach('.com_attach','#files');	
	upload = new AjaxUpload('upload_button', {
										action: '?r=comments&do=attach&ready=yes&ajax=1',
										autoSubmit: true, 
										onSubmit : function(file , ext){
																			if (! (ext && /^(jpg|png|jpeg|gif)$/.test(ext)))
																			{
																				$('#output').append(str_invalid);  
																				return false;
																			}
																			else
																			{
																				$('#output').append(str_uploading+file+'...');
																				$('#files').hide();
																			}
																		},
										onComplete: function(file, response){
																				if (response != '')
																				{
																					$('#files').html(response);
																					$('#files').fadeIn(500);
																					pic++;
																					$('#output').append(str_done+'('+pic+'/5)<br/>');
																					if (pic >= 5 )
																						this.disable();
																					//$('#files a').fancyzoom();
																					$('img.fancyzoom').fancyzoom();
																					att_count.html(pic);
																					att_del_link('.del_file');
																				}
																				else
																				{
																					$('#output').append(str_failed);
																				}
	                       													}
	              					}); 		
	comm_del_ajax('.triggerlink'); 
	$('.inline-edit').inlineEdit({hover: 'hover'});
}
function comm_attach(name,target)
{
	$(name).ajaxContent(
	{  
		target:target,
		beforeSend:function()
		{ 
			$('#output').html('');
			$(target).html('');
			$(target).hide();
			upload.enable();
		},
		success:function()
		{
			pic = document.getElementById('att_count').value;
			if (pic >= 5)
				upload.disable();
			$(target).fadeIn(500);
			att_del_link('.del_file');
			$('img.fancyzoom').fancyzoom();
		}
	});
}
function att_del_link(name)
{
	if ($(name))
	{	
		$(name).ajaxContent(
		{
			loader: false,
			target: '#notarget',
			success:function()
			{
				pic--;
				att_count.html(pic);
			}
		});
		$(name).click(function () {
			$(this).parent().fadeOut(500);
			//$(this).fadeOut(500);
		 });
		$(name).hide();
		$(name).prev().mouseover(function () {});
		$(name).prev().mouseover(function () { $(name).slideUp(500);$(this).siblings(name).slideDown(500) });
		//$(name).prev().mouseout(function () { $(this).siblings('.del_file').slideUp(500) });
	}
}
function comm_form_ajax(name,binds)
{	
	$('#comcont').hide();
	var i=0;
	$(name).ajaxContent(
			{  
				loader: false,
				bind: binds,
				target: '#comcont',
				beforeSend:function()
				{ 					 
					 $('#comment').before('<div id="comdiv'+i+'"></div>');
					 $('#comdiv'+i).html('<img width="31" height="31" src="images/ajax-loader.gif">').fadeIn(500);
				},
				success:function()
				{
					$('#comdiv'+i).hide();
					$('#comdiv'+i).html($('#comcont').html());
					$('#comdiv'+i).slideDown('slow');
					comm_del_ajax('.triggerlink'); 
					$('.inline-edit').inlineEdit({hover: 'hover'});
					$('.open_dialog').click(function(){
						att_count = $(this).find('.att_count');
						$('#dialog').dialog('open');
						return false;	
					});
					comm_attach('.com_attach','#files');
					i++;
				} 
	 		})
}

function comm_del_ajax (name)
{
	$('.dellink').mouseover(function () {
     			 $(this).css("font-weight","bolder");
     			 $(this).css("background-color", "#999");
   			 });
	 $('.dellink').mouseout(function () {
		 $(this).css("font-weight","normal");
		 $(this).css("background","none");
	 });
   			 
	$(name).ajaxContent(
		{
			loader: false,
			target: '#notarget'
		})
}
function send_form(theform) {
	document.getElementById('ready').value = "yes";
	document.forms[theform].submit();
}
function send_form_mtpl(theform) {
	document.forms[theform].ready.value = "yes";
	document.forms[theform].submit();
}
function SetCookie( name, value, expires, path, domain, secure ) 
{
	// set time, it's in milliseconds
	var today = new Date();
	today.setTime( today.getTime() );
	
	/*
	if the expires variable is set, make the correct 
	expires time, the current script below will set 
	it for x number of days, to make it for hours, 
	delete * 24, for minutes, delete * 60 * 24
	*/
	if ( expires )
	{
		expires = expires * 1000 * 60 * 60 * 24;
	}
	var expires_date = new Date( today.getTime() + (expires) );
	
	document.cookie = name + "=" +escape( value ) +
			( ( expires ) ? ";expires=" + expires_date.toGMTString() : "" ) + 
			( ( path ) ? ";path=" + path : "" ) + 
			( ( domain ) ? ";domain=" + domain : "" ) +
			( ( secure ) ? ";secure" : "" );
}


function check_this(form_name, el, do_check) {
	document.forms[form_name].elements[el].checked = !document.forms[form_name].elements[el].checked;
}

function check_all(the_form, the_element, do_check) {
	var checked_field = document.forms[the_form].elements[do_check];
    var fields      = (typeof(document.forms[the_form].elements[the_element]) != 'undefined')?document.forms[the_form].elements[the_element]:document.forms[the_form].elements[the_element] ;
    var fields_cnt  = (typeof(fields.length) != 'undefined')
                  ? fields.length
                  : 0;

    if (fields_cnt) {
        for (var i = 0; i < fields_cnt; i++) {
            fields[i].checked = checked_field.checked;
        }
    } else {
        fields.checked        = checked_field.checked;;
    }

    return true;
}
function get_document_root(){
 url = document.URL
 url_arr = url.split("?");
 //url_strIE = url_arr[0];
 //url_str = url_strIE.split("#");
 return url_arr[0];
}