
function toggle_submenu(activemenu) {
	$("#subnav > li").removeClass("selected");
	$('#'+activemenu).addClass("selected");
}

function sendform(form,php,method,div){

	$.ajax({
		beforeSend: busy,
		type: method,
		url: php,
		data: $('#'+form).serialize(),
		success: function(msg){
			$('#'+div).empty();
			$('#'+div).append(msg);
			//$(msg).appendTo('#'+div);
			done();
		}
	});

}

var busy = function(t) {
	//window.scrollTo(0, 0);
	var winh = ($(window).height()/2)-50;
	$('#loading').css({'position' : 'fixed'});
	$('#loading').css({'top' : winh});
	$('#loading').css({'display' : ''});
}

var done = function(t) {
	$('#loading').css({'display' : 'none'});
}

var show = function(name){
	$('#'+name).show('fast');
};

var hide = function(name){
	$('#'+name).hide('fast');
};

var toggle_visibility = function(name){
	//$(element).css('display')=='none'
	if($('#'+name).is(":hidden")){
		show(name);
	} else {
		hide(name);
	}
};

// OLD from inmoba
$(function(){
	$('.submitBtn').hover(
		function(){ $(this).addClass('submitBtnHover'); },// mouseover
		function(){ $(this).removeClass('submitBtnHover'); }// mouseout
	);
	$('.submitBtn_s').hover(
		function(){ $(this).addClass('submitBtn_sHover'); },
		function(){ $(this).removeClass('submitBtn_sHover'); }
	);
});


var form_changed = false;

function showhide(toshow,tohide){
	var tohide = eval("new Array('"+tohide.replace(/,/g, "','")+"')");
	var toshow = eval("new Array('"+toshow.replace(/,/g, "','")+"')");
	for (var i = 0; i < tohide.length; ++i){
		//alert(tohide[i]);
		$('#'+tohide[i]).css('display', 'none');
	}
	for (var i = 0; i < toshow.length; ++i){
		//alert(toshow[i]);
		$('#'+toshow[i]).css('display', '');
	}
}

function fit_minilist(){
	if($('#autominilist').length > 0) {
		var winh = $(window).height();
		var p = $('#autominilist');
		var position = p.position();
		var opth = (winh-position.top-50);
		$('#autominilist').css('height', opth);
	}
}

function movevalueto(from,to){

	$("#"+from+" option:selected").remove().prependTo("#"+to).removeAttr("selected");
//	$('#options_on > option').attr({selected:"selected"});
/*       $("#select1").change(function (e) {
           $("#select1 option:selected").remove().appendTo("#select2").removeAttr("selected");
           $("#select2").css({'color':'green'});
       });

       $("#select2").change(function (e) {
           $("#select2 option:selected").remove().appendTo("#select1").removeAttr("selected");
       }); */
}

function openwindow(name,file){
	$('#'+name).jOverlay({url:file, bgClickToClose : false, autoHide : false, opacity : 0.8});
}

function shclass(name) {
	$('.shclass').css('display', 'none');
	$('#'+name).show('fast');
}

function db_hiddenbox() {
	var found='db_hidden=';
	$('#content div > ul').each(function(){
		if($('#'+this.id).is(":hidden")){
			found = found+this.id+',';
		}
	});
	//alert(found);
	$.cookie('db_boxes', found, { expires: 30, path: '/'});
}

function db_hidebox(boxes) {
	$('#content div > ul').each(function(){
		if(boxes.indexOf(this.id) > 1) hide(this.id);
	});
}

function clear_desc(lang) {
	$('#f_short_description_'+lang).val('');
	$('#f_description_'+lang).val('');
	$('#f_price_description_'+lang).val('');
	$('#f_extra_description_'+lang).val('');
}

function toggle_desc_lang(name) {
	$('#all_descriptions > div').css('display', 'none');
	$('#'+name).css('display', '');
}

function toggle_divis(activemenu,hide) {
	$('#'+hide+' > div').css('display', 'none');
	$('#'+activemenu).css({'display' : ''});
}



function fill_title() {
	if($('#page_header_view').length > 0 && $('#page_header').length > 0) {
		$('#page_header_view').empty();
		var str = $('#page_header').text();
		$('#page_header_view').append(str);
//		$(str).appendTo('#page_header_view');
	}
}

function check_submenue(origin, reference) {
	if($('#tabs_'+reference).length == 0) {
		loadit('ajax','_tabs.php?ref='+reference,'submenu');
		toggle_submenu('main');
	}
}


function send2form(form,php,method,div){

	$.ajax({
		beforeSend: busy,
		type: method,
		url: php,
		data: $('#'+form).serialize(),
		success: function(msg){
			$('#'+div).empty();
			$('#'+div).append(msg);
			form_changed = true;
			done();
		}
	});

}

function loadit(type,address,target){
	if (type == 'blank') {
		OpenWindow = window.open(address, "newindow", "dependent=yes,width=1000,height=600,scrollbars=yes,location=no,menubar=no");
		OpenWindow.focus();
	}
	if (type == 'page') {
		window.location.href=address;
	}
	if (type == 'ajax') {
		sendform('loading',address,'get',target);
	}
}

function saveit(type,address,target){

	if (form_changed)
	{
		Check = confirm("You have not saved your last changes.\nContinue without saving?");
		if (Check) {
			if (type == 'page')
			{
				window.location.href=address;
				form_changed = false;
			}
			if (type == 'ajax')
			{
				sendform('loading',address,'get',target);
				form_changed = false;
			}
		}
	} else {
		if (type == 'page')
		{
			window.location.href=address;
		}
		if (type == 'ajax')
		{
			sendform('loading',address,'get',target);
		}
	}
}

var nextpage = function(page){
	$('#start').val(page);
	sendform('navform','list.php','post','info');
};

var prevpage = function(page){
	$('#start').val(page);
	sendform('navform','list.php','post','info');
};

var wp_paging = function(page){
	$('#start').val(page);
	sendform('navform','_results.php','post','results_content');
};

var pagination = function(page,php,fill){
	$('#start').val(page);
	sendform('navform',php,'post',fill);
};

var man_paging = function(page, process, output){
	$('#start').val(page);
	sendform('navform',process,'post',output);
};

function toggle_minilist(activemenu) {
	$("#table_minilist tbody > tr").removeClass("act_small");
	$('#'+activemenu).addClass("act_small");
}





































var show_msg = function(name){
	var div = $(name).setStyles({
		display:'block',
		opacity: 0
	});
	new Fx.Style(div, 'opacity', {duration: 2000} ).start(1);
};

var hide_msg = function(name){
/*	var div = $(name).setStyles({
		display:'block',
		opacity: 1
	});
	var sys_msg = new Fx.Style(div, 'opacity', {duration: 2000} ).start(0);
	setTimeout("$('"+name+"').setStyle('display', 'none')", 2500);*/
};



function unsaved(msg_text){
	if (form_changed){
		Check = confirm(msg_text);
		if (Check) {
			return true;
		} else {
			return false;
		}
	} else {
		return true;
	}
}


var sdone = function(t) {
	$('swait').style.display='none';
}


function fillview(name) {
	$(name+'_view').innerHTML=$(name).value;
}

function add_email(fillto,email) {
	if($('#'+fillto).val()) {
		$('#'+fillto).val($('#'+fillto).val()+','+email);
	} else {
		$('#'+fillto).val(email);
	}
}

function toggle_desc(name,lang) {
	$('f_description_'+lang).style.display='none';
	$('f_price_description_'+lang).style.display='none';
	$('f_extra_description_'+lang).style.display='none';

	$(name+lang).style.display='';
}

function toggle_classes(cname,iname) {
	$$('.'+cname).setStyle('font-weight', 'normal');
	$(iname).setStyle('font-weight', 'bold');
}

function toggle_classes_style(cname,iname,stype,svalue) {
	$$('.'+cname).setStyle('font-weight', 'normal');
	$(iname).setStyle(stype, svalue);
}

function toggle_classes_class(cname,sclass,ainame,aiclass) {
	$$('.'+cname).getProperty('id').each(function(idname) {
		$(idname).setProperty('class',sclass);
	});
	//$(ainame).setProperty('class', aiclass);
}

function modalwindow(url,text,size) {
		MOOdalBox.open( // case matters
		url, // the link URL
		text, // the caption (link's title) - can be blank
		size // width and height of the box - can be left blank
		);
	}





function addLoadEvent(func) {
  var oldonload = window.onload;
  if (typeof window.onload != 'function') {
    window.onload = func;
  } else {
    window.onload = function() {
      if (oldonload) {
        oldonload();
      }
      func();
    }
  }
}






/**
 * Cookie plugin
 *
 * Copyright (c) 2006 Klaus Hartl (stilbuero.de)
 * Dual licensed under the MIT and GPL licenses:
 * http://www.opensource.org/licenses/mit-license.php
 * http://www.gnu.org/licenses/gpl.html
 *
 */

/**
 * Create a cookie with the given name and value and other optional parameters.
 *
 * @example $.cookie('the_cookie', 'the_value');
 * @desc Set the value of a cookie.
 * @example $.cookie('the_cookie', 'the_value', { expires: 7, path: '/', domain: 'jquery.com', secure: true });
 * @desc Create a cookie with all available options.
 * @example $.cookie('the_cookie', 'the_value');
 * @desc Create a session cookie.
 * @example $.cookie('the_cookie', null);
 * @desc Delete a cookie by passing null as value. Keep in mind that you have to use the same path and domain
 *       used when the cookie was set.
 *
 * @param String name The name of the cookie.
 * @param String value The value of the cookie.
 * @param Object options An object literal containing key/value pairs to provide optional cookie attributes.
 * @option Number|Date expires Either an integer specifying the expiration date from now on in days or a Date object.
 *                             If a negative value is specified (e.g. a date in the past), the cookie will be deleted.
 *                             If set to null or omitted, the cookie will be a session cookie and will not be retained
 *                             when the the browser exits.
 * @option String path The value of the path atribute of the cookie (default: path of page that created the cookie).
 * @option String domain The value of the domain attribute of the cookie (default: domain of page that created the cookie).
 * @option Boolean secure If true, the secure attribute of the cookie will be set and the cookie transmission will
 *                        require a secure protocol (like HTTPS).
 * @type undefined
 *
 * @name $.cookie
 * @cat Plugins/Cookie
 * @author Klaus Hartl/klaus.hartl@stilbuero.de
 */

/**
 * Get the value of a cookie with the given name.
 *
 * @example $.cookie('the_cookie');
 * @desc Get the value of a cookie.
 *
 * @param String name The name of the cookie.
 * @return The value of the cookie.
 * @type String
 *
 * @name $.cookie
 * @cat Plugins/Cookie
 * @author Klaus Hartl/klaus.hartl@stilbuero.de
 */
jQuery.cookie = function(name, value, options) {
    if (typeof value != 'undefined') { // name and value given, set cookie
        options = options || {};
        if (value === null) {
            value = '';
            options.expires = -1;
        }
        var expires = '';
        if (options.expires && (typeof options.expires == 'number' || options.expires.toUTCString)) {
            var date;
            if (typeof options.expires == 'number') {
                date = new Date();
                date.setTime(date.getTime() + (options.expires * 24 * 60 * 60 * 1000));
            } else {
                date = options.expires;
            }
            expires = '; expires=' + date.toUTCString(); // use expires attribute, max-age is not supported by IE
        }
        // CAUTION: Needed to parenthesize options.path and options.domain
        // in the following expressions, otherwise they evaluate to undefined
        // in the packed version for some reason...
        var path = options.path ? '; path=' + (options.path) : '';
        var domain = options.domain ? '; domain=' + (options.domain) : '';
        var secure = options.secure ? '; secure' : '';
        document.cookie = [name, '=', encodeURIComponent(value), expires, path, domain, secure].join('');
    } else { // only name given, get cookie
        var cookieValue = null;
        if (document.cookie && document.cookie != '') {
            var cookies = document.cookie.split(';');
            for (var i = 0; i < cookies.length; i++) {
                var cookie = jQuery.trim(cookies[i]);
                // Does this cookie string begin with the name we want?
                if (cookie.substring(0, name.length + 1) == (name + '=')) {
                    cookieValue = decodeURIComponent(cookie.substring(name.length + 1));
                    break;
                }
            }
        }
        return cookieValue;
    }
};
