var checkobj = '';
var checkquestion = '';
var checktype = 'confirm';

function surveysubmit() {
    if(submitnow==1) {
	// normalis
	document.surveyform.submit();
    }
    else if(submitnow==2) {
	// oldaltordelt lista
	var count=0;
	// odalep
	for(var x=0;x<showvpage;x++) {
	    count+=onvpage[x];
	}
	
	// eltuntet
	for(var x=0;x<onvpage[showvpage];x++) {
	    var tmp = x+count;
	    cmd='visibility(0,\'answer'+tmp+'\',\'\');';
	    //alert(cmd);
	    eval(cmd);
	}
	count+=x;
	
	// kovetkezo megjelenit
	var nextpage = showvpage+1;
	if(nextpage<maxvpage) {
	    for(var x=0;x<onvpage[nextpage];x++) {
		var tmp = x+count;
		cmd='visibility(1,\'answer'+tmp+'\',\'\');';
		//alert(cmd);
		eval(cmd);
	    }
	    showvpage=nextpage;
	}
	else {
	    document.surveyform.submit();
	}
    }
    else if(submitnow==3) {
	// matrix checkbox1
	
	cmd = 'var x = mdata_q'+checkbox1qid+'_rownr;';
	eval(cmd);
	
	if(rcount >= x || next_submit == 1) {
	    document.surveyform.submit();
	} else {
	    mshownextrow(checkbox1qid,rcount);
	}
	rcount++;
    }
    else if(submitnow==4) {
	if(document.getElementById(checkobj).value=='') {
		if (checktype == 'confirm') {
		    if(confirm(checkquestion)) {
				document.surveyform.submit();
		    }
		}
		else if (checktype == 'alert') {
			alert(checkquestion);
		}
	}
	else {
	    document.surveyform.submit();
	}
    }
    else if(submitnow==-1) {
	if(document.surveyform.elements[3].value=='') {
	    if(confirm('Egészen biztosan nem jutott eszébe mobiltelefon márka?')) {
		document.surveyform.submit();
	    }	    
	}
	else {
	    document.surveyform.submit();
	}
    }
}




function popup(w,h,page) {
    window.open(pagethis+'/index.ftx?module=popup&page='+page+'&width='+w+'&height='+h,'researchpopup','width='+w+',height='+h+',location=0,menubar=0,resizable=1,scrollbars=0,status=0,toolbar=0,directories=0');
}

function init() {

	var y = document.getElementsByTagName('a');
	for (var i=0; i<y.length; i++) {
		if (!y[i].onclick) {
		  y[i].onclick = link_onclick;
		}
	}

	var y = document.getElementsByTagName('img');
	for (var i=0; i<y.length; i++) {
		if (y[i].getAttribute('icon')) {
			if (is_ie5_5up) {
				y[i].style.filter='progid:DXImageTransform.Microsoft.AlphaImageLoader(enabled=true, sizingMethod=scale src=' + y[i].getAttribute('icon') + ')';
			}
			else {
				y[i].style.backgroundImage='url(' + y[i].getAttribute('icon') + ')';
			}
		}
		else if (y[i].getAttribute('expand')) {
			y[i].onclick = expand_category_block;
		}
	}
	
	var y = document.getElementsByTagName('div');
	for (var i=0; i<y.length; i++) {
		if ((y[i].className == 'text') && (y[i].getAttribute('submit'))) {
			y[i].onclick = submit_form;
		}
		else if ((y[i].className == 'text') && (y[i].getAttribute('location'))) {
			if (y[i].getAttribute('inactivated')) {
				y[i].style.color = '#999';
			}
			y[i].onclick = link_onclick;
		}
		else if ((y[i].className == 'text') && (y[i].getAttribute('option_id'))) {
			y[i].onclick = hide_new_item_box;
		}
		else if ((y[i].className == 'text') && (y[i].getAttribute('popup'))) {
			y[i].onclick = link_onclick;
		}
	}
}

function link_onclick() {
	
	var timer = 0;
	var location;
	var picWidth = 200;
	var picHeight = 200;
	
	if (timer) clearTimeout(timer);
	location = this.getAttribute('href');
	if (!location) location = this.getAttribute('location');
	
	if ((this.getAttribute('inactivated')) && (this.getAttribute('inactivated') != '')) {
		alert(this.getAttribute('inactivated'));
		return false;
	}
	
	if ((this.getAttribute('popup')) && (this.getAttribute('popup') != '') && (this.getAttribute('popup_size')) && (this.getAttribute('popup_size') != '')) {
		var myArray = this.getAttribute('popup_size').split('x');
		popupWindow = window.open(this.getAttribute('popup'),'','resizable=yes,width='+myArray[0]+',height='+myArray[1]+',scrollbars=no');
		return false;
	}
	
	if ((this.getAttribute('show_image_popup')) && (this.getAttribute('show_image_popup') != '')) {
		if (this.getAttribute('picWidth')) picWidth = this.getAttribute('picWidth');
		if (this.getAttribute('picHeight')) picHeight = this.getAttribute('picHeight');
		show_image_popup(this.getAttribute('show_image_popup'), picWidth, picHeight);
		return false;
	}
	
	if ((location) && (location != '')) {
//		visible('pleasewait', true, 'block');
		timer = setTimeout("document.location='" + location + "'", 0);
	}

	return false;	
}

function bgcolor(fw,obj) {
    if (document.all) window.document.all(obj).bgColor=fw;
    else document.getElementById(obj).bgColor=fw;
    return true;
}

function fontweight(fw,obj) {
    if (document.all) window.document.all(obj).style.fontWeight=fw;
    else document.getElementById(obj).style.fontWeight=fw;
    return true;
}

function fontcolor(fc,obj) {
	var o = document.getElementById(obj);
	if (o) {
		o.style.color=fc;
	}
//    if (document.all) window.document.all(obj).style.color=fc;
  //  else document.getElementById(obj).style.color=fc;
    return true;
}


function visibility(visible,objid,vtype) {
	var o = document.getElementById(objid);
	if (o) {
		if (visible=='change') visible = o.style.display == 'none';
		if (visible) { o.style.display=vtype; }
		else { o.style.display='none'; }
	}

//    if (document.all) {
//        if (visible=='change') visible=window.document.all(obj).style.display=='none';
//        if (visible) window.document.all(obj).style.display='';
//        else window.document.all(obj).style.display='none';
//    }
//    else {
//	  if (visible=='change') visible=document.getElementById(obj).style.display=='none';
//	  if (visible) document.getElementById(obj).style.display='';
//	  else document.getElementById(obj).style.display='none';
//  }
    return true;
}

var mrun=0;

function changeInnerHtml(obj,content) {
  var obj = document.getElementById(objid);
  if (obj) {
	obj.innerHTML = content;
  }
}

var fade_current = 0;
var fade_step = 0;
var fade_timeout = 10;
var fade_limit = 0;
var fade_objid = '';

function GiveHex(Dec) {
	var Value = "";
	if(Dec == 10) Value = "A";
	else if(Dec == 11) Value = "B";
	else if(Dec == 12) Value = "C";
	else if(Dec == 13) Value = "D";
	else if(Dec == 14) Value = "E";
	else if(Dec == 15) Value = "F";
    else if(Dec<10) Value = "" + Dec;
	else Value = "0";
	return Value;																				 
}
function GreyD2H(D) {
	var a = GiveHex(Math.floor(D / 16));
	var b = GiveHex(D % 16);
	var z = a + b + a + b + a + b;
	return z;
}

function fadeIn(objid) {
    fade_current = 255;
	fade_limit = 3;
	fade_step = -10;
	fade_timeout = 30;
	fade_objid = objid;
	_fade();
}

function _fade() {
	fade_current+=fade_step;
	if ((fade_step < 0 && fade_current >= fade_limit) || (fade_step > 0 && fade_current <= fade_limit)) {
		fontcolor("#"+GreyD2H(fade_current),fade_objid);
		setTimeout('_fade()',fade_timeout);
	}
	else {
		fontcolor("#990000",fade_objid);
		fontweight("bold",fade_objid);
	}
}


var ih_active = 0;
var ih_mode = -1;
var ih_objid = '';
var ih_text = '';
var ih_counter = -1;
var ih_time = 10;
var ih_lastcmd = '';
var next_submit = 0;

function showObj(objid,text) {
  if (text != '') {
  	fadeIn(objid);
  }
  else {
  	eval(ih_lastcmd);
  }
/*
  if (text != '') {
    ih_mode = 1;
	ih_objid = objid;
	ih_text = text;
	ih_counter = 0;
	__showObj();  
  }
  else {
	ih_mode = 0;
	ih_objid = objid;
	__showObj();  
  }
*/
}

function __showObj() {
  var obj = document.getElementById(ih_objid);
  if (!obj) return false;
  
  if (ih_mode == 1) {
	if (ih_text == '#') {
	  ih_text = obj.innerHTML;
	  ih_counter = 0;
	  obj.innerHTML = '';
	}
	// beir
	if (ih_counter < ih_text.length) {
	  obj.innerHTML = ih_text.substring(0,ih_counter+2);
	  ih_counter+=2;
	  setTimeout('__showObj()',ih_time);  
	}
	else return true;
  }
  
  if (ih_mode == 0) {
	// elszed
	if (obj.innerHTML != '') {
	  ih_text = obj.innerHTML.substring(0,obj.innerHTML.length-3);
	  obj.innerHTML = ih_text;
	  setTimeout('__showObj()',ih_time);
	}
	else setTimeout(ih_lastcmd,ih_time);
  }
}

function mshownextrow(qid,rcount) {
	if (ih_active == 1) return false;
	ih_active = 1;
    var curr=0;
    var max=0;
    cmd='max=mdata_q'+qid+'_rownr;';    eval(cmd);
    cmd='curr=mdata_q'+qid+'_rowcurrent;';    eval(cmd);
	
	var objid = 'q'+qid+'a'+curr;
    var next=curr+1;

    cmd='visibility(0,\'q'+qid+'row'+curr+'\',\'\');';

    if(next>=max) {
	  // kesz
	  cmd+='visibility(1,\'q'+qid+'done\',\'\');';
	  next_submit = 1;
    }    
    else {
	  // kov
	  var xcmd='mdata_q'+qid+'_rowcurrent='+next+';';
	  eval(xcmd);

	  cmd+='visibility(1,\'q'+qid+'row'+next+'\',\'\');';
	  cmd+='visibility(1,\'q'+qid+'a'+next+'\',\'\');';
      cmd+="showObj('q"+qid+"a"+next+"','#');";

	}

	ih_lastcmd = cmd; // ez amit végrehajt amikor mutatja
	showObj(objid,'');
	ih_active = 0;
	return true;

}
