// FCK FUNCTIONS

var FCKeditorLoaded = false;
function FCKeditor_OnComplete(editorInstance) {
  FCKeditorLoaded = true;
}
function switchEditors(ID) {
  if(!FCKeditorLoaded) {
    setTimeout('switchEditors(\'' + ID + '\')', 500);
    return;
  }
  DoSwitchEditors(document.getElementById(ID));
}
function DoSwitchEditors(oNode) {
  var i;
  for (i = 0; i < oNode.childNodes.length;i++) {
    childNode = oNode.childNodes.item(i);
    editor = FCKeditorAPI.GetInstance(childNode.name);
    if (editor && editor.EditorDocument && editor.EditMode == FCK_EDITMODE_WYSIWYG) {
      editor.SwitchEditMode();
      editor.SwitchEditMode();
    }
    DoSwitchEditors(childNode);
  }
}

// SWAP IMAGES FUNCTIONS

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) { //v3.0
  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); 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];}
}


var reNumbers = /^[0-9]*$/;

function only_numbers(string){
   return reNumbers.test(string);
}

var twoWords = /^.+\s+.+$/;

function has_two_words(string){
   return twoWords.test(string);
}

var reTextNumbers = /^[a-zA-Z0-9]*$/;

function only_alphanumeric(string){
   return reTextNumbers.test(string);
}

var reEmail = /^[a-zA-Z\-\_\.0-9]+\@[a-zA-Z\-\_\.0-9]+[a-zA-Z0-9]\.[a-zA-Z]{2,4}$/;

function is_email(string){
   return reEmail.test(string);
}

function bookmark(title, url){
	document.images["bkm_img"].src = "/ax_save_bookmark.php?btitle="+title+"&burl="+url;
}

function addBookmarkMV(url, title) {
    if (window.sidebar) { // firefox
          window.sidebar.addPanel(title, url,"");
    } else if( document.all ) { //MSIE
            window.external.AddFavorite( url, title);
    } else {
           alert("Sorry, your browser doesn't support this");
    }
}

function switch_qlinks_tab(){
	if (document.getElementById("qlinks_opened").style.display != 'block'){
		document.getElementById("qlinks_opened").style.display = 'block';
		document.getElementById("qlinks_closed").style.display = 'none';
	}
	else{
		document.getElementById("qlinks_opened").style.display = 'none';
		document.getElementById("qlinks_closed").style.display = 'block';
	}
}

function switch_recommend(){
	if (document.getElementById("recommend_open").style.display == "block"){
		document.getElementById("recommend_closed").style.display = "block";
		document.getElementById("recommend_open").style.display = "none";
	}
	else{
		document.getElementById("recommend_closed").style.display = "none";
		document.getElementById("recommend_open").style.display = "block";
	}
}

function vp_tfriend(message){
	var tell_name = document.vp_tellfriend.vpt_name.value;
	var tell_email = document.vp_tellfriend.vpt_email.value;
	var tell_fname = document.vp_tellfriend.vpt_fname.value;
	var tell_femail = document.vp_tellfriend.vpt_femail.value;
	var tell_text = document.vp_tellfriend.vpt_comments.value;
	document.getElementById("recommend_open").innerHTML = '<div class="msg"><span class="sending">'+message+'</span></div>';

	tell_name = escape(tell_name);
	tell_fname = escape(tell_fname);
	tell_text = escape(tell_text);
	var params = "tell_name="+tell_name+"&tell_email="+tell_email+"&tell_fname="+tell_fname+"&tell_femail="+tell_femail+"&tell_text="+tell_text+"&type=ins";
	ajaxEngine.sendRequest('vptellFriend', {method:'post', parameters: params});

	return false;
}

function open_comment_block(type){document.getElementById(type+"_ins_comm").style.display = "block";}
function close_comment_block(type){document.getElementById(type+"_ins_comm").style.display = "none";}

function verify_username(){
	document.images["quoka_verify_img"].src = "/images/quoka_loading.gif";
	document.images["quoka_verify_img"].src = "/ax_verify_username.php?username="+document.form_reg.reg_username.value;
}

function verify_quoka(){
	document.images["quoka_verify_img"].src = "/images/quoka_loading.gif";
	document.images["quoka_verify_img"].src = "/ax_verify_username.php?username="+document.quoka.quoka_username.value;
}

function verify_vol(){
	document.images["vol_verify_img"].src = "/images/quoka_loading.gif";
	document.images["vol_verify_img"].src = "/ax_verify_username.php?username="+document.vol.vol_username.value;
}

function add_ctag(new_tag, tagelement) {
	curvalue = tagelement.value;
	if (curvalue == "") tagelement.value = new_tag;
	else tagelement.value = curvalue + ", " + new_tag;
}

function block_chars(obj, max){
	var total = obj.value.length;
	if (total > max){
		obj.value = obj.value.substring(0, max);
	}
}

function filter_cat(flag) {
	if((document.ads_searchf.cid.value>0) && (document.ads_searchf.cid.value<7)){
		document.ads_searchf.fid.disabled = true;
		document.ads_searchf.sfor.disabled = false;
		document.ads_searchf.fid.value = document.ads_searchf.cid.value;
	}
	else{
		document.ads_searchf.fid.disabled = false; 
		document.ads_searchf.sfor.disabled = true;
		document.ads_searchf.fid.value = 0;
	}
	if(flag==1) filterCombo();
}

function switch_payment_div(pmethod){
	if (document.getElementById("method_"+pmethod+"_opened").style.display != 'block'){
		document.getElementById("method_"+pmethod+"_opened").style.display = 'block';
		document.getElementById("method_"+pmethod+"_closed").style.display = 'none';
	}
	else{
		document.getElementById("method_"+pmethod+"_opened").style.display = 'none';
		document.getElementById("method_"+pmethod+"_closed").style.display = 'block';
	}
}

// MY_HOME FUNCTIONS

var opened_tour = "main_block";
function show_tour(tourid){
	if (tourid == 6) tourid = 1;
	document.getElementById(opened_tour).style.display = 'none';
	document.getElementById("step_block"+tourid).style.display = 'block';
	opened_tour = "step_block"+tourid;
}
function close_tour(){
	document.getElementById(opened_tour).style.display = 'none';
	document.getElementById("main_block").style.display = 'block';
	opened_tour = "main_block";
}

var opened_tab = "my_def";
function show_tab(tabname){
	document.getElementById(opened_tab).style.display = 'none';
	document.getElementById(tabname).style.display = 'block';
	opened_tab = tabname;
}
function close_tab(tabname){
	document.getElementById(tabname).style.display = 'none';
	document.getElementById("my_def").style.display = 'block';
	opened_tab = "my_def";
}

function close_voucher_teaser(){
	document.getElementById("voucher_teaser").style.display = 'none';
	document.getElementById("tops_block").style.display = 'block';
}

var old_send_html = "";
var writing_message = true;
function block_chars_mphone(){
	var total = document.mphone.mp_text.value.length;
	if (total >= 300){
	}
}
function count_chars(){
	var total = document.mphone.mp_text.value.length;
	if (total > 300){
		document.mphone.mp_text.value = document.mphone.mp_text.value.substring(0, 300);
		total = 300;
	}
	document.getElementById("chars_left").innerHTML = 300 - total;
}

function switch_promo_block(){
	document.getElementById("mphone_block_view").style.display = 'none';
	document.getElementById("mphone_block").style.display = 'none';
	document.getElementById("promo_block").style.display = 'block';
}

function switch_mphone_block(){
	if (!writing_message){
		document.getElementById("mphone_block").innerHTML = old_send_html;
		document.mphone.mp_text.value = "";
		count_chars();
		writing_message = true;
	}
	document.getElementById("promo_block").style.display = 'none';
	document.getElementById("mphone_block_view").style.display = 'none';
	document.getElementById("mphone_block").style.display = 'block';

}

function switch_mphone_block_view(){
	document.getElementById("promo_block").style.display = 'none';
	document.getElementById("mphone_block").style.display = 'none';
	document.getElementById("mphone_block_view").style.display = 'block';
}

function send_mphone(message){
	old_send_html = document.getElementById("mphone_block").innerHTML;
	writing_message = false;
	var text = document.mphone.mp_text.value;
	document.getElementById("mphone_block").innerHTML = '<span class="sending">'+message+'...</span>';

	text = escape(text);
	var params = "text="+text+"&type=ins";
	ajaxEngine.sendRequest('sendMPhone', {method:'post', parameters: params});

	return false;
}

function view_mphone(mphone, message){
	document.getElementById("mphone_block_view").innerHTML = '<span class="sending">'+message+'...</span>';
	switch_mphone_block_view();
	ajaxEngine.sendRequest('viewMPhone', "id="+mphone);
	return false;
}

function rmv_content(ctname){
	document.getElementById(ctname).style.display = 'none';
	ajaxEngine.sendRequest('removeBlock', "block_key="+ctname)			
}

// PETSITES/MEMBERS FUNCTIONS

var ie=document.all;
var dom=document.getElementById;
var ns4=document.layers;
var calunits=document.layers? "" : "px";
var popon = false;

function open_popin(key,sstring_len){
	if (popon) crossobj.visibility = "hidden";
	if (!dom&&!ie&&!ns4) return;
	crossobj = (dom)? document.getElementById("pin_"+key).style : ie? document.all.pin_msg : document.pin_msg;
	scroll_top = (ie)? truebody().scrollTop : window.pageYOffset;
	crossobj.top = 300 + calunits;
	crossobj.visibility = (dom||ie)? "visible" : "show";
	popon = true;
	nkey = key.substring(sstring_len);
	MM_swapImage('ps_'+nkey, '', document.getElementById('ps_'+nkey).src, 1);
}

function close_box(key){
	MM_swapImgRestore();
	crossobj = (dom)? document.getElementById("pin_"+key).style : ie? document.all.pin_msg : document.pin_msg;
	crossobj.visibility = "hidden";
	popon = false;
}

function truebody(){
	return (document.compatMode && document.compatMode!="BackCompat")? document.documentElement : document.body;
}

function open_popin2(){
	if (!dom&&!ie&&!ns4) return;
	crossobj = (dom)? document.getElementById("award_details").style : ie? document.all.award_details : document.award_details;
	scroll_top = (ie)? truebody().scrollTop : window.pageYOffset;
	crossobj.top = 400 + calunits;
	crossobj.visibility = (dom||ie)? "visible" : "show";
}

function close_box2(){
	crossobj = (dom)? document.getElementById("award_details").style : ie? document.all.award_details : document.award_details;
	crossobj.visibility = "hidden";
}

// PETSITES FUNCTIONS

function show_awards(award_id, pet_id, message){
	document.getElementById("award_details").innerHTML = '<div style="margin:10px;"><span class="sending">'+message+'...</span></div>';
	open_popin2();
	ajaxEngine.sendRequest('awardDetails', "award_id="+award_id, "pet_id="+pet_id);
}

function ins_comment_pet(pet_id){
	var cm_text = document.ins_comm.c_text.value;
	var cm_temporary = 0;
	if(document.ins_comm.c_temporary.checked) cm_temporary=1;
	cm_text = escape(cm_text);
	var params = "pet_id="+pet_id+"&cm_text="+cm_text+"&cm_temporary="+cm_temporary+"&type=ins";
	ajaxEngine.sendRequest('insComment_pet', {method:'post', parameters: params});
	return false;
}

function send_message_pet(pet_id, message){
	var pm_title = document.pet_msg.msg_title.value;
	var pm_text = document.pet_msg.msg_text.value;
	document.getElementById("ctt_pet_msg").innerHTML = '<span class="sending">'+message+'</span>';

	pm_title = escape(pm_title);
	pm_text = escape(pm_text);
	var params = "pet_id="+pet_id+"&pm_title="+pm_title+"&pm_text="+pm_text+"&type=ins";
	ajaxEngine.sendRequest('sendMessage_pet', {method:'post', parameters: params});

	return false;
}

function give_treat(pet_id, treat_id, message){
	document.getElementById("ctt_pet_treat").innerHTML = '<span class="sending">'+message+'</span>';
	ajaxEngine.sendRequest('giveTreat', "pet_id="+pet_id, "treat_id="+treat_id);
	return false;
}

function give_award(pet_id, award_id, message){
	document.getElementById("ctt_pet_award").innerHTML = '<span class="sending">'+message+'</span>';
	ajaxEngine.sendRequest('giveAward', "pet_id="+pet_id, "award_id="+award_id);
	return false;
}

function add_favourite(pet_id){
	ajaxEngine.sendRequest('addFavourite', "pet_id="+pet_id);
	return false;
}

function remove_favourite(pet_id){
	ajaxEngine.sendRequest('removeFavourite', "pet_id="+pet_id);
	return false;
}

function tell_friend(pet_id, message){
	var tellpet_name = document.pet_tell.tell_name.value;
	var tellpet_email = document.pet_tell.tell_email.value;
	var tellpet_text = document.pet_tell.tell_text.value;
	document.getElementById("ctt_pet_tell").innerHTML = '<span class="sending">'+message+'</span>';
	
	tellpet_name = escape(tellpet_name);
	tellpet_text = escape(tellpet_text);
	var params = "pet_id="+pet_id+"&tellpet_name="+tellpet_name+"&tellpet_email="+tellpet_email+"&tellpet_text="+tellpet_text+"&type=ins";
	ajaxEngine.sendRequest('tellFriend', {method:'post', parameters: params});

	return false;
}

function make_buddy_pet(pet_id, message){
	var petbuddy_id = document.pet_buddy.buddy_pet.value;
	var petbuddy_text = document.pet_buddy.buddy_text.value;
	document.getElementById("ctt_pet_buddy").innerHTML = '<span class="sending">'+message+'</span>';

	petbuddy_text = escape(petbuddy_text);
	var params = "pet_id="+pet_id+"&petbuddy_id="+petbuddy_id+"&petbuddy_text="+petbuddy_text+"&type=ins";
	ajaxEngine.sendRequest('makeBuddy_pet', {method:'post', parameters: params});
	
	return false;
}

function send_comment(pet_id, message){
	var cm_text = document.pet_comm.c_text.value;
	var cm_temporary = 0;
	if(document.ins_comm.c_temporary.checked) cm_temporary=1;
	cm_text = escape(cm_text);
	var params = "pet_id="+pet_id+"&cm_text="+cm_text+"&cm_temporary="+cm_temporary;
	document.getElementById("ctt_pet_comm").innerHTML = '<span class="sending">'+message+'</span>';
	ajaxEngine.sendRequest('sendComment', {method:'post', parameters: params});
	
	return false;
}

function ins_comment_photo(photo_id){
	var cm_text = document.ins_comm.c_text.value;
	var cm_temporary = 0;
	if(document.ins_comm.c_temporary.checked) cm_temporary=1;
	cm_text = escape(cm_text);
	var params = "photo_id="+photo_id+"&cm_text="+cm_text+"&cm_temporary="+cm_temporary+"&type=ins";
	ajaxEngine.sendRequest('insComment_photo', {method:'post', parameters: params});
	return false;
}

function ins_comment_diary(diary_id){
	var cm_text = document.ins_comm.c_text.value;
	var cm_temporary = 0;
	if(document.ins_comm.c_temporary.checked) cm_temporary=1;
	cm_text = escape(cm_text);
	var params = "diary_id="+diary_id+"&cm_text="+cm_text+"&cm_temporary="+cm_temporary+"&type=ins";
	ajaxEngine.sendRequest('insComment_diary', {method:'post', parameters: params});
	return false;
}

// MEMBERS FUNCTIONS

function make_buddy_member(user_id, message){
	var userbuddy_text = document.user_buddy.buddy_text.value;
	document.getElementById("ctt_user_buddy").innerHTML = '<span class="sending">'+message+'</span>';

	userbuddy_text = escape(userbuddy_text);
	var params = "user_id="+user_id+"&userbuddy_text="+userbuddy_text+"&type=ins";
	ajaxEngine.sendRequest('makeBuddy_member', {method:'post', parameters: params});

	return false;
}

function send_message_member(user_id, message){
	var pm_title = document.user_msg.c_title.value;
	var pm_text = document.user_msg.c_text.value;
	document.getElementById("ctt_user_msg").innerHTML = '<span class="sending">'+message+'</span>';

	pm_title = escape(pm_title);
	pm_text = escape(pm_text);
	var params = "user_id="+user_id+"&pm_title="+pm_title+"&pm_text="+pm_text+"&type=ins";
	ajaxEngine.sendRequest('sendMessage_member', {method:'post', parameters: params});

	return false;
}

function block_user(user_id){
	ajaxEngine.sendRequest('blockUser', "user_id="+user_id);
	return false;
}

function unblock_user(user_id){
	ajaxEngine.sendRequest('unblockUser', "user_id="+user_id);
	return false;
}

// ARTICLES FUNCTIONS

function ins_expert_article(article_id){
	var cm_bio = document.ins_exp.c_bio.value;
	var cm_name = document.ins_exp.c_name.value;
	var cm_email = document.ins_exp.c_email.value;
	cm_bio = escape(cm_bio);
	cm_name = escape(cm_name);

	var params = "article_id="+article_id+"&cm_bio="+cm_bio+"&cm_name="+cm_name+"&cm_email="+cm_email;
	ajaxEngine.sendRequest('insExpert_article', {method:'post', parameters: params});
	return false;
}

function ins_tellfriend_article(article_id){
	var cm_name = document.ins_tell.c_name.value;
	var cm_email = document.ins_tell.c_email.value;
	var cm_fname = document.ins_tell.c_fname.value;
	var cm_femail = document.ins_tell.c_femail.value;
	var cm_text = document.ins_tell.c_text.value;

	cm_name = escape(cm_name);
	cm_fname = escape(cm_fname);
	cm_text = escape(cm_text);

	var params = "article_id="+article_id+"&cm_text="+cm_text+"&cm_name="+cm_name+"&cm_email="+cm_email+"&cm_fname="+cm_fname+"&cm_femail="+cm_femail+"&type=ins";
	ajaxEngine.sendRequest('instellfriend', {method:'post', parameters: params});

	return false;
}

function ins_comment_article(article_id){
	var cm_text = document.ins_comm.c_text.value;
	var cm_temporary = 0;
	if(document.ins_comm.c_temporary.checked) cm_temporary=1;
	cm_text = escape(cm_text);
	var params = "article_id="+article_id+"&cm_text="+cm_text+"&cm_temporary="+cm_temporary+"&type=ins";
	ajaxEngine.sendRequest('insComment', {method:'post', parameters: params});
	return false;
}

// VIDEOS FUNCTIONS

function ins_fave_video(video_id){
	ajaxEngine.sendRequest('insFavourite_video', "video_id="+video_id);
	return false;
}

function ins_tellfriend_video(video_id){
	var cm_name = document.ins_tell.c_name.value;
	var cm_email = document.ins_tell.c_email.value;
	var cm_fname = document.ins_tell.c_fname.value;
	var cm_femail = document.ins_tell.c_femail.value;
	var cm_text = document.ins_tell.c_text.value;

	cm_name = escape(cm_name);
	cm_fname = escape(cm_fname);
	cm_text = escape(cm_text);
	var params = "video_id="+video_id+"&cm_text="+cm_text+"&cm_name="+cm_name+"&cm_email="+cm_email+"&cm_fname="+cm_fname+"&cm_femail="+cm_femail+"&type=ins";
	ajaxEngine.sendRequest('instellfriend_video', {method:'post', parameters: params});

	return false;
}

function ins_comment_video(video_id){
	var cm_text = document.ins_comm.c_text.value;
	var cm_temporary = 0;
	if(document.ins_comm.c_temporary.checked) cm_temporary=1;
	cm_text = escape(cm_text);
	var params = "video_id="+video_id+"&cm_text="+cm_text+"&cm_temporary="+cm_temporary+"&type=ins";
	ajaxEngine.sendRequest('insComment_video', {method:'post', parameters: params});
	return false;
}

// BREEDS FUNCTIONS

function move_next_race(array_values, array_wid, array_hei){
	var id = new Array();    
	var hei = new Array();
	var wid = new Array(); 		
	var id_img;	
	id = array_values.split(",");
	hei = array_hei.split(",");
	wid = array_wid.split(",");			
	id_img = document.getElementById("id_img").value;

	if(parseInt(id_img)+1 < id.length){
		document.images["src_breed"].src = "/img/galeria/race/"+id[parseInt(id_img)+1];
		document.images["src_breed"].width = wid[parseInt(id_img)+1];
		document.images["src_breed"].height = hei[parseInt(id_img)+1];	
		document.getElementById("id_img").value = parseInt(id_img)+1;				
	}
	
	if(parseInt(document.getElementById("id_img").value)+1 >= id.length){
		document.getElementById("id_next").style.display = 'none';
	}else{
		document.getElementById("id_next").style.display = '';
	}
	document.getElementById("id_prev").style.display = '';

}

function move_back_race(array_values, array_wid, array_hei){
	var id = new Array();  
	var hei = new Array();
	var wid = new Array();
	var id_img;	 
	id = array_values.split(",");
	hei = array_hei.split(",");
	wid = array_wid.split(",");			
	id_img = document.getElementById("id_img").value; 
	
	if(parseInt(id_img)-1 >= 0){
		document.images["src_breed"].src = "/img/galeria/race/"+id[parseInt(id_img)-1];		
		document.images["src_breed"].width = wid[parseInt(id_img)-1];
		document.images["src_breed"].height = hei[parseInt(id_img)-1];			
		document.getElementById("id_img").value = parseInt(id_img)-1;				
	}

	document.getElementById("id_next").style.display = '';

	if(document.getElementById("id_img").value == 0){
		document.getElementById("id_prev").style.display = 'none';
	}else{
		document.getElementById("id_prev").style.display = '';
	}
	
}

function open_link_block(){document.getElementById("race_link").style.display = "block";}

function ins_fave_race(race_id){
	ajaxEngine.sendRequest('insFavourite_race', "race_id="+race_id);
	return false;
}

function ins_expert_race(race_id){
	var cm_name = document.ins_exp.ce_name.value;
	var cm_email = document.ins_exp.ce_email.value;
	var cm_bio = document.ins_exp.ce_bio.value;

	cm_name = escape(cm_name);
	cm_bio = escape(cm_bio);
	var params = "race_id="+race_id+"&cm_name="+cm_name+"&cm_email="+cm_email+"&cm_bio="+cm_bio;
	ajaxEngine.sendRequest('insExpert_race', {method:'post', parameters: params});

	return false;
}

function ins_tellfriend_race(race_id){
	var cm_name = document.ins_tell.c_name.value;
	var cm_email = document.ins_tell.c_email.value;
	var cm_fname = document.ins_tell.c_fname.value;
	var cm_femail = document.ins_tell.c_femail.value;
	var cm_text = document.ins_tell.c_text.value;

	cm_name = escape(cm_name);
	cm_fname = escape(cm_fname);
	cm_text = escape(cm_text);
	var params = "race_id="+race_id+"&cm_name="+cm_name+"&cm_email="+cm_email+"&cm_fname="+cm_fname+"&cm_femail="+cm_femail+"&cm_text="+cm_text;
	ajaxEngine.sendRequest('instellfriend_race', {method:'post', parameters: params});

	return false;
}

function inse_link(race_id, message){
	var cm_text = document.ins_link.c_text.value;
	var cm_title = document.ins_link.c_ltitle.value;
	var cm_url = document.ins_link.c_lurl.value;
	var cm_name = document.ins_link.c_name.value;
	var cm_email = document.ins_link.c_email.value;
	document.getElementById("race_link").innerHTML = '<span class="sending">'+message+'</span>';

	cm_text = escape(cm_text);
	cm_title = escape(cm_title);
	cm_url = escape(cm_url);
	cm_name = escape(cm_name);
	
	var params = "race_id="+race_id+"&cm_text="+cm_text+"&cm_title="+cm_title+"&cm_url="+cm_url+"&cm_name="+cm_name+"&cm_email="+cm_email;
	ajaxEngine.sendRequest('inselink', {method:'post', parameters: params});

	return false;
}

function open_wiki_block(id){
	ajaxEngine.registerAjaxElement('txt_'+id+'_edit');
	document.getElementById('txt_'+id+'_view').style.display = 'none';
	document.getElementById('txt_'+id+'_edit').style.display = 'block';
	switchEditors('txt_'+id+'_edit');
}
function close_wiki_block(id){
	document.getElementById('txt_'+id+'_view').style.display = 'block';
	document.getElementById('txt_'+id+'_edit').style.display = 'none';
}
function save_wiki(text_id){
	var oEditor = FCKeditorAPI.GetInstance('wiki_'+text_id+'_txt');
	var wiki_text = oEditor.GetXHTML(true);

	wiki_text = escape(wiki_text);
	var params = "text_id="+text_id+"&wiki_text="+wiki_text;
	ajaxEngine.sendRequest('saveWiki', {method:'post', parameters: params});

	return false;
}
function new_wiki(race_id){
	var oEditor = FCKeditorAPI.GetInstance('wiki_text');
	var wiki_text = oEditor.GetXHTML(true);
	var wiki_title = document.new_wiki_text.wiki_title.value;

	wiki_title = escape(wiki_title);
	wiki_text = escape(wiki_text);
	var params = "wiki_title="+wiki_title+"&wiki_text="+wiki_text+"&wiki_race="+race_id;
	ajaxEngine.sendRequest('newWiki', {method:'post', parameters: params});

	return false;
}

function ins_comment_race(race_id){
	var cm_text = document.ins_comm.c_text.value;
	var cm_temporary = 0;
	if(document.ins_comm.c_temporary.checked) cm_temporary=1;
	cm_text = escape(cm_text);
	var params = "race_id="+race_id+"&cm_text="+cm_text+"&cm_temporary="+cm_temporary+"&type=ins";
	
	ajaxEngine.sendRequest('insComment_race', {method:'post', parameters: params});
	
	return false;
}

// COMICS FUNCTIONS

function ins_fave_comic(comic_id){
	ajaxEngine.sendRequest('insFavourite_comic', "comic_id="+comic_id);
	return false;
}

function ins_tellfriend_comic(comic_id){
	var cm_name = document.ins_tell.c_name.value;
	var cm_email = document.ins_tell.c_email.value;
	var cm_fname = document.ins_tell.c_fname.value;
	var cm_femail = document.ins_tell.c_femail.value;
	var cm_text = document.ins_tell.c_text.value;

	cm_name = escape(cm_name);
	cm_fname = escape(cm_fname);
	cm_text = escape(cm_text);
	var params = "comic_id="+comic_id+"&cm_text="+cm_text+"&cm_name="+cm_name+"&cm_email="+cm_email+"&cm_fname="+cm_fname+"&cm_femail="+cm_femail+"&type=ins";
	ajaxEngine.sendRequest('instellfriend_comic', {method:'post', parameters: params});

	return false;
}

function ins_comment_comic(comic_id){
	var cm_text = document.ins_comm.c_text.value;
	var cm_temporary = 0;
	if(document.ins_comm.c_temporary.checked) cm_temporary=1;
	cm_text = escape(cm_text);
	var params = "comic_id="+comic_id+"&cm_text="+cm_text+"&cm_temporary="+cm_temporary+"&type=ins";
	ajaxEngine.sendRequest('insComment_comic', {method:'post', parameters: params});
	return false;
}

// ADS FUNCTIONS

function switch_div_visibility(divid){
	elem = document.getElementById(divid);
	if (elem.style.display == "block"){
		elem.style.display = "none";
	} else {
		elem.style.display = "block"; 
	}
}

function open_msg_block(){document.getElementById("ad_msg").style.display = "block";}

function ins_adfav(ad_id){
	ajaxEngine.sendRequest('insFavourite', "ad_id="+ad_id);
	return false;
}

function ins_admsg(ad_id,message){
	var pm_text = document.ins_msg.c_text.value;
	pm_text = escape(pm_text);
	document.getElementById("ad_msg").innerHTML = '<span class="sending">'+message+'</span>';

	var params = "ad_id="+ad_id+"&pm_text="+pm_text;
	ajaxEngine.sendRequest('insMessage', {method:'post', parameters: params});
	return false;
}

// OTHER FUNCTIONS

function open_question_block(){document.getElementById("question").style.display = "block";}
function open_expert_block(key){document.getElementById(key+"_expert").style.display = "block";}
function open_tellfriend_block(key){document.getElementById(key+"_tellfriend").style.display = "block";}
function open_fav_block(key){document.getElementById(key).style.display = "block";}
function close_block(key){document.getElementById(key).style.display = "none";}

function ins_comment_blog(blog_id){
	var cm_text = document.ins_comm.c_text.value;
	var cm_temporary = 0;
	if(document.ins_comm.c_temporary.checked) cm_temporary=1;
	cm_text = escape(cm_text);
	var params = "blog_id="+blog_id+"&cm_text="+cm_text+"&cm_temporary="+cm_temporary+"&type=ins";
	ajaxEngine.sendRequest('insComment_blog', {method:'post', parameters: params});
	return false;
}

function ins_tellfriend_wkpet(wkpet_id){
	var cm_name = document.ins_tell.c_name.value;
	var cm_email = document.ins_tell.c_email.value;
	var cm_fname = document.ins_tell.c_fname.value;
	var cm_femail = document.ins_tell.c_femail.value;
	var cm_text = document.ins_tell.c_text.value;

	cm_name = escape(cm_name);
	cm_fname = escape(cm_fname);
	cm_text = escape(cm_text);

	var params = "wkpet_id="+wkpet_id+"&cm_text="+cm_text+"&cm_name="+cm_name+"&cm_email="+cm_email+"&cm_fname="+cm_fname+"&cm_femail="+cm_femail+"&type=ins";
	ajaxEngine.sendRequest('instellfriend_wkpet', {method:'post', parameters: params});

	return false;
}

function showpic(w,h,token_x,token_y) {
	var iw, ih; // Set inner width and height
	if (window.innerWidth == null) {
		iw = document.body.clientWidth;
		ih=document.body.clientHeight; 
	}
	else {
		iw = window.innerWidth;
		ih = window.innerHeight;
	}

	iw = document.body.clientWidth;
	ih=document.body.clientHeight; 

	var x,y;
	x=Math.round(iw / 2);
	y=Math.round(ih / 2);
	x= x-w-token_x;
	y= y-h+190;
	y=token_y;

	document.write('<div style=\"position:absolute;left:'+x+'px;top:'+y+'px;text-align:center;\">');
}