function getCheckedValue(radioObj) {
	if(!radioObj)
		return "";
	var radioLength = radioObj.length;
	if(radioLength == undefined)
		if(radioObj.checked)
			return radioObj.value;
		else
			return "";
	for(var i = 0; i < radioLength; i++) {
		if(radioObj[i].checked) {
			return radioObj[i].value;
		}
	}
	return "";
}
function setCheckedValue(radioObj, newValue) {
	if(!radioObj)
		return;
	var radioLength = radioObj.length;
	if(radioLength == undefined) {
		radioObj.checked = (radioObj.value == newValue.toString());
		return;
	}
	for(var i = 0; i < radioLength; i++) {
		radioObj[i].checked = false;
		if(radioObj[i].value == newValue.toString()) {
			radioObj[i].checked = true;
		}
	}
}
function debugInfo(str){
	if(window.console){
		console.log(str);
	}
}
Element.implement(
{
	hideRN: function() 
	{
		this.setStyle('opacity', 0);
	},
	hide: function() 
	{
		this.morph({duration: 700,opacity: 0});
	},
	
	show: function() 
	{
		this.morph({duration: 700,opacity: 1});
	}
});
var TipPartnerAddress;
_EVAL_SCRIPTS=true;
var DropdownMenu = new Class({	
	initialize: function(element,level)
	{
		$A($(element).childNodes).each(function(el)
		{
			if(el.nodeName.toLowerCase() == 'li')
			{
				$A($(el).childNodes).each(function(el2)
				{
					if(el2.nodeName.toLowerCase() == 'ul')
					{
						el.addEvents({
							mouseenter: function()
						{
							el2.show();
							return false;
						},
						mouseleave: function()
						{
							el2.hide();
						}});
						new DropdownMenu(el2,level+1);
						$(el2).hideRN();
					}
				});
			}
		});
		return this;
	}
});
window.addEvent('domready', function(){

	if($('dropdownMenu'))
		new DropdownMenu($('dropdownMenu'),0);

//firebug in explorer
/*		
if (!window.console) {
  window.console = {
    timers: {},
    openwin: function() {
      window.top.debugWindow =
          window.open("",
                      "Debug",
                      "left=0,top=0,width=300,height=700,scrollbars=yes,"
                      +"status=yes,resizable=yes");
      window.top.debugWindow.opener = self;
      window.top.debugWindow.document.open();
      window.top.debugWindow.document.write('<html><head><title>debug window</title></head><body><hr /><pre>');
    },

    log: function(entry) {
      window.top.debugWindow.document.write(entry+"\n");
    },

    time: function(title) {
      window.console.timers[title] = new Date().getTime();
    },

    timeEnd: function(title) {
      var time = new Date().getTime() - window.console.timers[title];
      console.log(['<strong>', title, '</strong>: ', time, 'ms'].join(''));
    }

  }

  if (!window.top.debugWindow) { console.openwin(); }
}
*/

})

function urlEncode(str){
    //str=escape(str);
    str=str.replace(new RegExp('\\+','g'),'%2B');
    str=str.replace(new RegExp('%20','g'),'+');
    str=str.replace(new RegExp('&','g'),'%26');
    return str;
}
function htmlEncode(str){
    str=str.replace(new RegExp('\n','g'),'<br/>');
    return str;
}
function htmlDecode(str){
    str=str.replace(new RegExp('<br/>','g'),'\n');
    return str;
}
function decodeField(id,value){
	$(id).value=htmlDecode(value);
}
function callSyncServerDispatcher(obj,scrollToTop){
	callServerDispatcher(obj,scrollToTop,true)
}
function callServerDispatcher(obj, scrollToTop,sync) {
	$('AJAX_LOADING').style.display='block';
	new Fx.Morph($('AJAX_LOADING'),'top').start(0,window.getScrollTop()+10+'px')
	jsonpar=urlEncode(JSON.encode(obj));
	var ajaxRequest = new Request({
		url: 'class.AJAXServerDispatcher.php',
		method: 'post',
		async: !sync,
		data: 'json=' + jsonpar,
		onSuccess: function(response,responseXML){
//	debugInfo('response ' + response);
			input = JSON.decode(response);
//	debugInfo('input ' + input);
			$each(input, function(value, key){
//				debugInfo(value);
				switch(value.action){
				   	case 'assign':
							var id = value.id;
//							debugInfo('id '+id);
							$each(value.attributes, function(value, key){
								switch(key){
									case 'innerHTML':
										$(id).set('html',value);
										break;
									case 'value':
										$(id).value = value;
										break;
									default:
										try {
											$(id)[key] = value;
										} catch(e) {
										}
										$(id).setAttribute(key, value);
										break;
									case 'style':
										var styles = [];
										if (value.indexOf(';')) {
											styles = value.split(';');
										}
										else {
											styles.push(value);
										}
										for(var i = 0; i < styles.length; i++) {
											var r = styles[i].match(/^\s*(.+)\s*:\s*(.+)\s*$/);
											if(r) {
												$(id).style[_camelize(r[1])] = r[2];
											}
										}
										break;
								}
							});
							break;
				   	case 'clear':
							var id = value.id;
							$each(value.attributes, function(value, key){
								switch(value){
									case 'innerHTML':
										$(id).set('html','');
										break;
									case 'value':
										$(id).value = '';
										break;
									default:
										$(id).removeAttribute(value);
										break;
								}
							});
							break;
				   	case 'append':
							var id = value.id;
							$each(value.attributes, function(value, key){
								switch(key){
									case 'innerHTML':
										$(id).set('html',$(id).innerHTML+value);
										break;
									case 'value':
										$(id).value += value;
										break;
									default:
										try {
											$(id)[key] = value;
										} catch(e) {
										}
										$(id).setAttribute(key, value);
										break;
/*									case 'style':
										var styles = [];
										if (value.indexOf(';')) {
											styles = value.split(';');
										}
										else {
											styles.push(value);
										}
										for(var i = 0; i < styles.length; i++) {
											var r = styles[i].match(/^\s*(.+)\s*:\s*(.+)\s*$/);
											if(r) {
												$(id).style[_camelize(r[1])] = r[2];
											}
										}
										break;*/
								}
							});
							break;
				   	case 'script':
							eval(value.data);
							break;
				}
			});
			$('AJAX_LOADING').style.display='none';
			if (scrollToTop)
			window.scrollTo(0,0);
		}
		}).send();	
}
function _camelize(instr){
	var p = instr.split('-');
	var out = p[0];
	for(var i = 1; i < p.length; i++) {
		out += p[i].charAt(0).toUpperCase()+p[i].substring(1);
	}
	return out;
}
function showAlert(msg){
	alert(msg);
}
function goUp(){
	location.href="#";
}
function init(){
}
var RE_NUM = /^\-?\d+$/;
function cal_prs_date1 (str_date) {

	var arr_date = (str_date.indexOf('/')>0) ? str_date.split('/') : str_date.split('-');

	if (arr_date.length != 3) return cal_error ("Hibás dátum formátum: '" + str_date + "'.\nHelyes formátum: éééé-hh-nn.");
	if (!arr_date[0]) return cal_error ("Hibás dátum formátum: '" + str_date + "'.\nEbben a hónapban ilyen nap nincs.");
	if (!RE_NUM.exec(arr_date[2])) return cal_error ("Hibás nap érték: '" + arr_date[2] + "'.\nNem egész számot adott meg.");
	if (!arr_date[1]) return cal_error ("Hibás dátum formátum: '" + str_date + "'.\nIlyen hónap nincs.");
	if (!RE_NUM.exec(arr_date[1])) return cal_error ("Hibás hónap érték: '" + arr_date[1] + "'.\nNem egész számot adott meg.");
	if (!arr_date[2]) return cal_error ("Hibás dátum formátum: '" + str_date + "'.\nIlyen év nincs.");
	if (!RE_NUM.exec(arr_date[0])) return cal_error ("Hibás év érték: '" + arr_date[0] + "'.\nNem egész számot adott meg.");

	var dt_date = new Date();
	dt_date.setDate(1);

	if (arr_date[1] < 1 || arr_date[1] > 12) return cal_error ("A hónap érték hibás: '" + arr_date[1] + "'.\nMegengedett tartomány: 01-12.");
	dt_date.setMonth(arr_date[1]-1);
	 
	if (arr_date[0] < 100) arr_date[0] = Number(arr_date[0]) + (arr_date[0] < NUM_CENTYEAR ? 2000 : 1900);
	dt_date.setFullYear(arr_date[0]);

	var dt_numdays = new Date(arr_date[0], arr_date[1], 0);
	dt_date.setDate(arr_date[2]);
	if (dt_date.getMonth() != (arr_date[1]-1)) return cal_error ("Nap érték hibás: '" + arr_date[2] + "'.\nMegengedett tartomány: 01-"+dt_numdays.getDate()+".");

	return (dt_date)
}
// date generating function
function cal_gen_date1 (dt_datetime) {
	return (
		dt_datetime.getFullYear() + "-"
		+ (dt_datetime.getMonth() < 9 ? '0' : '') + (dt_datetime.getMonth() + 1) + "-"
		+ (dt_datetime.getDate() < 10 ? '0' : '') + dt_datetime.getDate()
	);
}
function storeMultiSelection(srcid,destid){
	var value="";
	for(var i=0; i<srcid.options.length; i++)
    	if (srcid.options[i].selected){
    		if(value!="") value+=";";
        	value += srcid.options[i].value;
        }
    destid.value=value;
}

/********** simpleSoft **********/
function emailKuldes(){
	if(validf.validate())
		$('emailForm').submit();
	return false;
}
