function setasHome(){
	if(document.all){
		if(document.getElementById('email_hash')!=null){
			setHome(document.getElementById('email_hash').value)
		}
		document.body.style.behavior='url(#default#homepage)';
		document.body.setHomePage('http://' + document.write(location.host) );
		stat();
	}
}

function addToFavorites(){
	if(document.all){
		if(document.getElementById('email_hash')!=null){
			setFavorites(document.getElementById('email_hash').value)
		}
		window.external.AddFavorite(location.href, document.title);
	}
}


/*** Menü ***/

function menu_mouse_over(menu_item_num) {
	document.getElementById("menu_item_left_"+menu_item_num).className  = "menu_item_h_left";
	document.getElementById("menu_item_right_"+menu_item_num).className = "menu_item_h_right";
	document.getElementById("menu_item_text_"+menu_item_num).className  = "menu_item_h_text";
}
function menu_mouse_out(menu_item_num) {
	document.getElementById("menu_item_left_"+menu_item_num).className  = "menu_item_left";
	document.getElementById("menu_item_right_"+menu_item_num).className = "menu_item_right";
	document.getElementById("menu_item_text_"+menu_item_num).className  = "menu_item_text";
}


/*** link ajánló ***/

function link_offer_send(senderForm, link_exsits) {
	categories = '';
	for ( i=0; i<senderForm.elements.length; i++ ) {
		element = senderForm.elements[i];
		if ( element.name == "categories[]" && element.checked ) {
			if ( categories.length > 0 ) {
				categories += ',';
			}
			categories += element.value;
		}
	}

	params  = 'link_email='+senderForm.email.value;
	params += '&check_code='+senderForm.check_code.value;
	params += '&link_categories='+categories
	params += '&link_name='+senderForm.name.value;
	params += '&link_url='+senderForm.url.value;
	
	if ( link_exsits > 0 ) {
		params += '&exists=1';
	} else {
		params += '&link_description='+senderForm.description.value;
		params += '&link_comment='+senderForm.comment.value;
		params += '&exists=0';
	}

	ajaxRequest('link_offer_send', params, 'link_offer_send_result');

	//document.getElementById('check_code').src = 'check_code.php?r=' + Math.floor(Math.random()*1000000);
	//document.getElementById('check_code_input').value= '';
}

function link_offer_check_cat_count(senderCheck) {
	var selected_count = 0;
	var senderForm = senderCheck.form;

	for ( i=0; i<senderForm.elements.length; i++ ) {
		element = senderForm.elements[i];
		if ( element.name == "categories[]" && element.checked ) {
			selected_count++;
			if ( selected_count > 3 ) {
				alert_lang("max_3_categories_alert");
				return false;
			}
		}
	}
	return true;
}


/*** jelentkezés szerkesztőnek ***/

function new_editor(senderForm) {
	params  = 'editor_name='+senderForm.editor_name.value;
	params += '&editor_email='+senderForm.editor_email.value;
	params += '&editor_phone='+senderForm.editor_phone.value;
	params += '&editor_suggested_theme='+senderForm.editor_suggested_theme.value;
	params += '&editor_suggested_categories='+senderForm.editor_suggested_categories.value;
	params += '&editor_description='+senderForm.editor_description.value;

	ajaxRequest('editor_send', params, 'new_editor_result');
}

function send_comment(senderForm) {
	params  = 'comment='+senderForm.comment.value;
	params += '&comment_type='+senderForm.comment_type.value;
	params += '&comment_for='+senderForm.comment_for.value;
	params += '&email='+senderForm.email.value;
	params += '&page_url='+senderForm.page_url.value;

	ajaxRequest('comment_send', params, 'comment_result');
}

function search_where_change(search_form_id, a_id, value) {
	document.getElementById('search'+search_form_id+'_where').value = value;
	for ( i=1; i<=2; i++ ) {
		a_obj = document.getElementById('search'+search_form_id+'_where_a_'+i);
		if ( i == a_id ) {
			a_obj.className = 'search_where_active';
		} else {
			a_obj.className = 'search_where';
		}
	}
}

function login(senderForm) {
	params  = 'email='+senderForm.email.value;
	params += '&password='+senderForm.password.value;
	if ( senderForm.save_login.checked ) {
		params += '&save_login=1';
	}
	try {
		params += '&return_url=' + senderForm.return_url.value;
	} catch(err) {
	}

	ajaxRequest('login_do', params, 'login_result');
}

function registration(senderForm) {
	params  = 'name='+senderForm.name.value;
	params += '&password1='+senderForm.password1.value;
	params += '&password2='+senderForm.password2.value;
	params += '&email='+senderForm.email.value;
	if ( senderForm.pass_newsletter.checked ) {
		params += '&pass_newsletter=1';
	}
	if ( senderForm.accept_terms.checked ) {
		params += '&accept_terms=1';
	}

	ajaxRequest('registration_do', params, 'registrtation_result');
}

function forget_password(senderForm) {
	params  = 'email='+senderForm.email.value;
	ajaxRequest('forget_password_send', params, 'forget_password_result');
	senderForm.reset();
}

function emailbox_loginform_change(index) {
	users   = document.getElementById("email_box_loginform_users").value.split("|");
	passwds = document.getElementById("email_box_loginform_passwds").value.split("|");
	logins  = document.getElementById("email_box_loginform_logins").value.split("|");
	regs    = document.getElementById("email_box_loginform_regs").value.split("|");
	
	document.getElementById("email_box_loginform_users").name  = users[index];
	document.getElementById("email_box_loginform_passwd").name = passwds[index];
	document.getElementById("email_box_loginform_form").action = logins[index];
	document.getElementById("email_box_loginform_reg").href    = regs[index];
}

function imgh_in(senderImg) {
	senderImg.src = senderImg.src.substring(0,senderImg.src.length-4) + "_h.png";
}
function imgh_out(senderImg) {
	senderImg.src = senderImg.src.substring(0,senderImg.src.length-6) + ".png";
}

function change_userdata(senderForm) {
	ajaxRequestForm('control_panel_userdata_change', senderForm, 'change_userdata_result');
}

function change_user_password(senderForm) {
	params  = 'old_password='+senderForm.old_password.value;
	params += '&new_password1='+senderForm.new_password1.value;
	params += '&new_password2='+senderForm.new_password2.value;
	ajaxRequest('control_panel_change_password_do', params, 'change_user_password_result');
}

function cp_search_user(senderForm) {
	params = 'search_user='+senderForm.search_user.value;
	ajaxRequest('control_panel_userlist', params, 'control_panel_page');
}

function CreateBookmarkLink(url, title) {
	if (window.sidebar) {
		window.sidebar.addPanel(title, url,"");
	} else if( window.external ) {
		window.external.AddFavorite( url, title); }
	else if(window.opera && window.print) {
		return true; 
	}
}

function cmcl(name, style) {
	catbox_style_set_all_default();
	document.getElementById("cbt_"+name).className = "cbt"+style;
}

function catbox_style_set_all_default() {
	var objs=document.getElementsByTagName('div');
	for (var i=0; i<objs.length; i++) {
		id = getElementId(objs[i]);
		if (id.substring(0,4) == "cbt_") {
			document.getElementById(id).className = "cbt";
		}
	}
}

function getElementId(obj) {
	if (document.all) {
		return obj.getAttribute('id');
	} else {
		return obj.id;	
	}
}

function changeFontSize(num) {
	var p = document.getElementsByTagName('a');
	for( i=0; i<p.length; i++ ) {
		if (getElementId(p[i]).charAt(0) == "_" ) {
			if(p[i].style.fontSize) {
			   var s = parseInt(p[i].style.fontSize.replace("px",""));
			} else {
			   var s = 11;
			}
			s += num;
			p[i].style.fontSize = s+"px"
		}
	}
}

function alert_lang(langvar) {
	var request = createAjaxRequest();
	request.open('get', "ajax_langvar.php?langvar="+langvar);
	request.onreadystatechange = requestResult;
	request.send('');
	
	function requestResult() {
		if (request.readyState == 4) {
	    if (request.status == 200) {
	    	alert(request.responseText);
	    } else {
	      alert("Ajax hiba: " + request.statusText);
	    }
	  }
	}
}


// blinking
var blink_times   = 10;
var blink_color   = "#FCD5A2";
var blink_default = "";
function blink(divId) {
	div = document.getElementById(divId);
	if ( blink_times == 10 ) {
		blink_default = div.style.backgroundColor;
	}
  blink_times = blink_times-1;
  if ( blink_times > 0 ) {
    if ( blink_times%2==0 ) {
    	div.style.backgroundColor = blink_default;
    } else {
    	div.style.backgroundColor = blink_color;
    }
    setTimeout("blink('"+divId+"')", 60);
  } else {
    clearTimeout();
    blink_times = 10;
    div.style.backgroundColor = blink_default;
  }
}
