// FCK FUNCTIONS
function try_connection() 
{
	$.get("/ax_test_connection.php",function(data)
	{
		if(data==1)
		{
			
		} 
		else 
		{
			alert('dogsandpuppies down!');
		}
	});
}
//setInterval('try_connection()',600000);
function like_biz(user_id,biz_id)
{
	$.get('/ax_add_biz_fav.php',{user_id:user_id,biz_id:biz_id},function(data)
	{
		if(data==1)
		{
			$('#fav_'+biz_id).addClass('star_on');
			$('#fav_'+biz_id).removeClass('star');	
		}
		else if(data==2)
		{
			$('#fav_'+biz_id).addClass('star');
			$('#fav_'+biz_id).removeClass('star_on');
		}
		
	});
}
function like_biz2(user_id,biz_id)
{
	$.get('/ax_add_biz_fav.php',{user_id:user_id,biz_id:biz_id},function(data)
	{
		if(data==1)
		{
			$('#like_user .star_biz').addClass('star_biz_on');
			$('#like_user .star_biz_on').removeClass('star_biz');	
		}
		else if(data==2)
		{
			$('#like_user .star_biz_on').addClass('star_biz');
			$('#like_user .star_biz').removeClass('star_biz_on');	
		}
		
	});
}
function sell_click(sell_id)
{
	var value=$('#v_'+sell_id).val();
	if(value==1)
	{
		$('#v_'+sell_id).val(0);
		$('#s_'+sell_id).removeClass('sell_chk_act');
		$('#s_'+sell_id).addClass('sell_chk');
	}
	if(value==0)
	{
		$('#v_'+sell_id).val(1);
		$('#s_'+sell_id).removeClass('sell_chk');
		$('#s_'+sell_id).addClass('sell_chk_act');
	}
}
function save_sells(biz_id,ids)
{
	var ids_active = new Array();
	var a_ids=ids.split('|');
	for(var i in a_ids)
	{
		if ($('#v_'+a_ids[i]).val()==1)
		{
			ids_active.push(a_ids[i]);
		}		
	}
	ids_active = ids_active.join('@@');
	$.get("/ax_save_sell_types.php", {biz_id: biz_id,ids:ids_active},
	function(data)
	{
	   	if(data!=0)
	   	{
	   		$('#sell_response').html(data);
	   		setTimeout("$('#sell_response').html('')",3000);
	   	}
	 });

}
function active_btn(id)
{
	$('#' + id).removeClass('btn_next');
	$('#' + id).addClass('btn_next_active');
	$('#' + id).attr('disabled','');
}
function disable_btn(id)
{
	$('#' + id).removeClass('btn_next_active');
	$('#' + id).addClass('btn_next');
	$('#' + id).attr('disabled','disabled');
}

function set_final(id)
{
	$('#' + id).parents('div:first').children('.choose_item').removeClass('choose_item_sel');
	$('.choose_item').css('background-image','');
	$('#' + id).removeClass();
	$('#' + id).addClass('choose_item');
	$('#' + id).addClass('choose_item_sel');
	$('#' + id).css('background-image','url("/style/accept.png")');
}

function set_selected(id)
{
	$('#' + id).parents('div:first').children('.choose_item').removeClass('choose_item_sel');
	$('.choose_item').css('background-image','');
	$('#' + id).removeClass();
	$('#' + id).addClass('choose_item');
	$('#' + id).addClass('choose_item_sel');
	
}
function type_choosed(type_id)
{
	$.get("/ax_ads_choose_cat.php", {type_id: type_id},
	function(data)
	{
   	if(data==0)
   	{
   		$('.choose_box_cat').css('display','none');
			set_final('type_' + type_id)
   		active_btn('choose_save');
   	}
   	else
   	{
			set_selected('type_' + type_id);
			disable_btn('choose_save');
			$('.choose_box_cat').css('display','block');
			$('.choose_box_cat').html(data);
    	}
 	});
	$('#id_type').val(type_id);
	$('#id_cat').val(0);
	$('#id_scat').val(0);
	
}

function cat_choosed(cat_id)
{
	$.get("/ax_ads_choose_scat.php", {cat_id: cat_id},
	function(data)
	{
   	if(data==0)
   	{
   		$('.choose_box_scat').css('display','none');
			set_final('cat_' + cat_id)
   		active_btn('choose_save');
   	}
   	else
   	{
   		set_selected('cat_' + cat_id);
			disable_btn('choose_save');
			$('.choose_box_scat').css('display','block');
			$('.choose_box_scat').html(data);
    	}
 	});
	$('#id_cat').val(cat_id);
	$('#id_scat').val(0);
}

function scat_choosed(scat_id)
{
	$('#id_scat').val(scat_id);
	set_final('scat_' + scat_id);
	active_btn('choose_save');	
}

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];}
}

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 toogle(element){
	$(element).toggle();
}

function show(element){
	$(element).show();
}

function hide(element){
	$(element).hide();
}

function swicth_sections_visibility(div){
	hide('#buy_sell_bar');
	hide('#community_bar');
	show('#'+div+"_bar");
}

function tellfriend(sending_message){
	var tell_name=$("#hmt_name").val();
	var tell_email=$("#hmt_email").val();
	var tell_fname=$("#hmt_fname").val();
	var tell_femail=$("#hmt_femail").val();
	var tell_text=$("#hmt_comments").val();
	
	$("#recommend_open").html("<div class='msg'><span class='sending'>"+sending_message+"</span></div>");
	
	$.get("/ax_hm_tell_friend.php", {tell_name: tell_name, tell_email: tell_email, tell_fname: tell_fname, tell_femail: tell_femail, tell_text: tell_text},
		function(data){
			$("#recommend_open").html(data);	
	});
}

function ins_tellfriend_wkprofile(wkprofile_id){
	var cm_name = $("#c_name").val();
	var cm_email = $("#c_email").val();
	var cm_fname = $("#c_fname").val();
	var cm_femail = $("#c_femail").val();
	var cm_text = $("#c_text").val();
	$.get("/ax_wkprofile_tellfriend.php", {wkprofile_id: wkprofile_id, cm_text: cm_text, cm_name: cm_name, cm_email: cm_email, cm_fname: cm_fname, cm_femail: cm_femail, type: "ins"},
		function(data){
			$("#wkprofile_tellfriend").html(data);	
	});
}

function ins_tellfriend_voucher(voucher_id){
	var cm_name = $("#tf_name").val();
	var cm_email = $("#tf_email").val();
	var cm_fname = $("#tf_fname").val();
	var cm_femail = $("#tf_femail").val();
	var cm_text = $("#tf_text").val();
	$.get("/ax_voucher_tellfriend.php", {voucher_id: voucher_id, cm_text: cm_text, cm_name: cm_name, cm_email: cm_email, cm_fname: cm_fname, cm_femail: cm_femail, type: "ins"},
		function(data){
			$("#voucher_tellfriend").html(data);	
	});
	return false;
}

function ins_tellfriend_video(video_id){
	var cm_name = $("#c_name").val();
	var cm_email = $("#c_email").val();
	var cm_fname = $("#c_fname").val();
	var cm_femail = $("#c_femail").val();
	var cm_text = $("#c_text").val();
	$.get("/ax_video_tellfriend.php", {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"},
		function(data){
			$("#video_tellfriend").html(data);	
	});
	return false;
}

function ins_tellfriend_ad(ad_id){
	var cm_name = $("#tf_name").val();
	var cm_email = $("#tf_email").val();
	var cm_fname = $("#tf_fname").val();
	var cm_femail = $("#tf_femail").val();
	var cm_text = $("#tf_text").val();
	
	$.get("/ax_ad_tellfriend.php", {ad_id: ad_id, cm_text: cm_text, cm_name: cm_name, cm_email: cm_email, cm_fname: cm_fname, cm_femail: cm_femail, type: "ins"},
		function(data){
			$("#ad_tellfriend").html(data);	
	});

	return false;
}

function ins_tellfriend_article(ref_id){
	var cm_name = $("#c_name").val();
	var cm_email = $("#c_email").val();
	var cm_fname = $("#c_fname").val();
	var cm_femail = $("#c_femail").val();
	var cm_text = $("#c_text").val();

	$.get("/ax_article_tellfriend.php", {article_id: ref_id, cm_text: cm_text, cm_name: cm_name, cm_email: cm_email, cm_fname: cm_fname, cm_femail: cm_femail, type: "ins"},
		function(data){
			$("#article_tellfriend").html(data);	
	});
	return false;
}

function ins_tellfriend_race(ref_id){
	var cm_name = $("#c_name").val();
	var cm_email = $("#c_email").val();
	var cm_fname = $("#c_fname").val();
	var cm_femail = $("#c_femail").val();
	var cm_text = $("#c_text").val();
	
	$.get("/ax_race_tellfriend.php", {ref_id: ref_id, cm_text: cm_text, cm_name: cm_name, cm_email: cm_email, cm_fname: cm_fname, cm_femail: cm_femail, type: "ins"},
		function(data){
			$("#race_tellfriend").html(data);	
	});
	return false;
}

function tell_friend(ref_id, sending_message){
	var tellhorse_name = $("#tell_name").val();
	var tellhorse_email = $("#tell_email").val();
	var tellhorse_text = $("#tell_text").val();
	
	$("#ctt_horse_tell").html(sending_message);	
	
	$.get("/ax_horse_tell_friend.php", {profile_id: ref_id, tellhorse_name: tellhorse_name, tellhorse_email: tellhorse_email, tellhorse_text: tellhorse_text, type: 'ins'},
		function(data){
			$("#ctt_horse_tell").html(data);	
	});
	
	return false;
}

function ins_favourite(type, req_id){
	$.get("/ax_"+type+"_fav.php", {req_id: req_id},
		function(data){
			$("#"+type+"_fav").html(data);	
	});
	return false;
}

function ins_comment(type, req_id, is_logged){
	var cm_text = $("#comm_text").val();
	var cm_name = "";
	var cm_email = "";
	
	if(is_logged==null) is_logged=1;
	
	if(!is_logged){
		cm_name = $("#comm_name").val();
		cm_email = $("#comm_email").val();
	}
	$.get("/ax_"+type+"_comment.php", {req_id: req_id, cm_name: cm_name, cm_email: cm_email, cm_text: cm_text, type: "ins"},
		function(data){
			$("#"+type+"_ins_comm").html(data);	
	});
	return false;
}

function add_testimonial(sending_message){
	var cm_name = $("#c_name").val();
	var cm_email = $("#c_email").val();
	var cm_text = $("#c_msg").val();
	
	$("#testimonial").html(sending_message);	
	
	$.get("/ax_save_testimonial.php", {cm_text: cm_text, cm_name: cm_name, cm_email: cm_email},
		function(data){
			$("#testimonial").html(data);	
	});
	return false;
}

function save_search(s_url){
	var s_title = $("#search_title").val();

	$.get("/ax_save_search.php", {s_url: s_url, s_title: s_title},
		function(data){
			$("#save_search").html(data);	
	});
	return false;
}

function ins_admsg(ad_id, logged, sending_message){
	var pm_text = $("#p_text").val();
	var pm_email = $("#p_email").val();
	var pm_phone = $("#p_phone").val();
	if(logged==1) var pm_captcha = "";
	else var pm_captcha = $("#ctc_captcha").val();
	
	$("#ad_msg").html(sending_message);	
	
	$.get("/ax_ad_send_email.php", {ad_id: ad_id, pm_text: pm_text, pm_email: pm_email, pm_phone: pm_phone, pm_captcha: pm_captcha},
		function(data){
			$("#ad_msg").html(data);	
	});
	return false;
}

function ins_ads_review(id, logged){
	var cm_name = $("#c_name").val();
	var cm_email = $("#c_email").val();
	var cm_phone = $("#c_phone").val();
	var cm_text = $("#c_text").val();
	var cm_rating = $("#c_rating").val();
	if(logged==1) var cm_captcha = "";
	else var cm_captcha = $("#c_captcha").val();
	
	$.get("/ax_ads_review.php", {id: id, cm_name: cm_name, cm_email: cm_email, cm_phone: cm_phone, cm_text: cm_text, cm_rating: cm_rating, cm_captcha: cm_captcha, type: "ins"},
		function(data){
			$("#ad_ins_rev").html(data);	
	});

	return false;
}

function chp_photo(id, img_path, img_width, img_height, img_id){
	document.images["ads_photo"].src = img_path;
	document.images["ads_photo"].width = img_width;
	document.images["ads_photo"].height = img_height;
	
	var js = "popin_photo("+img_id+");";
	// create a function from the "js" string
    var newclick = new Function(js);
	
	$('#big_photo_link').attr('onclick', '').click(newclick);
	$('#big_photo_link1').attr('onclick', '').click(newclick);
	
	$.get("/ax_save_views_photo.php", {id: id});
}

function save_question(sending_message){
	var consult_sec = $("#consult_sec").val();
	var cm_text = $("#c_text").val();

	$("#question").html(sending_message);	
	
	$.get("/ax_save_question.php", {consult_id: consult_sec, cm_text: cm_text},
		function(data){
			$("#question").html(data);	
	});
	return false;
}

function clip_ad(ad_id, sending_message){
	$("#clip_ad_"+ad_id).html(sending_message);	
	
	$.get("/ax_ad_clip_list.php", {ad_id: ad_id},
		function(data){
			$("#clip_ad_"+ad_id).html(data);	
	});
	return false;
}

function show_awards(loading_message, award_id, profile_id){
	$("#award_details").html("<div style='margin:10px;'><span class='sending'>"+loading_message+"...</span></div>");
	
	open_popin2();
	
	$.get("/ax_award_details.php", {award_id: award_id, profile_id: profile_id},
		function(data){
			$("#award_details").html(data);	
	});
}

function ins_expert(race_id){
	var cm_name = $("#ce_name").val();
	var cm_email = $("#ce_email").val();
	var cm_bio = $("#ce_bio").val();
	
	$.get("/ax_race_expert.php", {race_id: race_id, cm_name: cm_name, cm_email: cm_email, cm_bio: cm_bio},
		function(data){
			$("#race_expert").html(data);	
	});

	return false;
}

function save_wiki(text_id){
	var oEditor = FCKeditorAPI.GetInstance('wiki_'+text_id+'_txt');
	var wiki_text = oEditor.GetXHTML(true);
	
	$.get("/ax_save_wiki_race.php", {text_id: text_id, wiki_text: wiki_text},
		function(data){
			$("#txt_"+text_id+"_edit").html(data);	
	});
	
	return false;
}

function new_wiki(race_id){
	var oEditor = FCKeditorAPI.GetInstance('wiki_text');
	var wiki_text = oEditor.GetXHTML(true);
	var wiki_title = $("#wiki_title").val();
	
	$.get("/ax_new_wiki_race_text.php", {wiki_title: wiki_title, wiki_text: wiki_text, wiki_race: race_id},
		function(data){
			$("#txt_0_edit").html(data);	
	});

	return false;
}

function inse_link(race_id, sending_message){
	var cm_text = $("#c_text").val();
	var cm_title = $("#c_ltitle").val();
	var cm_url = $("#c_lurl").val();
	var cm_name = $("#c_name").val();
	var cm_email = $("#c_email").val();

	$("#race_link").html(sending_message);	
	
	$.get("/ax_race_link.php", {race_id: race_id, cm_text: cm_text, cm_title: cm_title, cm_url: cm_url, cm_name: cm_name, cm_email: cm_email},
		function(data){
			$("#race_link").html(data);	
	});
	return false;
}


function send_message_horse(profile_id, sending_message){
	var pm_title = $("#msg_title").val();
	var pm_text = $("#msg_text").val();	
	
	$("#ctt_horse_msg").html(sending_message);
	
	$.get("/ax_send_pm.php", {profile_id: profile_id, pm_title: pm_title, pm_text: pm_text},
		function(data){
			$("#ctt_horse_msg").html(data);	
	});
	return false;
}

function send_message_member(user_id, sending_message){
	var pm_title = $("#c_title").val();
	var pm_text = $("#c_text").val();	
	
	$("#ctt_user_msg").html(sending_message);
	
	$.get("/ax_send_pm.php", {user_id: user_id, pm_title: pm_title, pm_text: pm_text},
		function(data){
			$("#ctt_user_msg").html(data);	
	});
	return false;
}

function give_treat(profile_id, treat_id, sending_message){
	$("#ctt_horse_treat").html(sending_message);
	
	$.get("/ax_give_treat.php", {profile_id: profile_id, treat_id: treat_id},
		function(data){
			$("#ctt_horse_treat").html(data);	
	});
	return false;
}

function give_award(profile_id, award_id, sending_message){
	$("#ctt_horse_award").html(sending_message);
	
	$.get("/ax_give_award.php", {profile_id: profile_id, award_id: award_id},
		function(data){
			$("#ctt_horse_award").html(data);	
	});
	return false;
}

function add_favourite(profile_id){
	$.get("/ax_fav_profile.php", {profile_id: profile_id},
		function(data){
			$("#ctt_horse_fav").html(data);	
	});
	return false;
}

function remove_favourite(profile_id){
	$.get("/ax_fav_profile_remove.php", {profile_id: profile_id},
		function(data){
			$("#ctt_horse_fav").html(data);	
	});
	return false;
}

function make_buddy_horse(profile_id, sending_message){
	var profilebuddy_id = $("#buddy_horse").val();
	var profilebuddy_text = $("#buddy_text").val();	
	
	$("#ctt_horse_buddy").html(sending_message);
	
	$.get("/ax_add_buddy.php", {profile_id: profile_id, profilebuddy_id: profilebuddy_id, profilebuddy_text: profilebuddy_text, type: 'ins'},
		function(data){
			$("#ctt_horse_buddy").html(data);	
	});
	return false;
}

function make_buddy_member(user_id, sending_message){
	var userbuddy_text = $("#buddy_text").val();
	
	$("#ctt_user_buddy").html(sending_message);
	
	$.get("/ax_add_user_buddy.php", {user_id: user_id, userbuddy_text: userbuddy_text, type: 'ins'},
		function(data){
			$("#ctt_user_buddy").html(data);	
	});
	return false;
}

function send_comment(profile_id, sending_message){
	var cm_text = $("#c_text").val();	
	
	$("#ctt_horse_comm").html(sending_message);
	
	$.get("/ax_profile_comment.php", {req_id: profile_id, cm_text: cm_text},
		function(data){
			$("#ctt_horse_comm").html(data);	
	});
	return false;
}

function block_user(user_id){
	$.get("/ax_block_user.php", {user_id: user_id},
		function(data){
			$("#ctt_user_block").html(data);	
	});
	return false;
}

function unblock_user(user_id){
	$.get("/ax_unblock_user.php", {user_id: user_id},
		function(data){
			$("#ctt_user_block").html(data);	
	});
	return false;
}

var step_featured_ads=1;
function more_featured_ads(p){
	step_featured_ads=step_featured_ads+p;
	
	$.get("/ax_more_featured_ads.php", {page: step_featured_ads},
		function(data){
			$(".items_featured").html(data);	
	});
	return false;
}

function more_featured_ads_b(p){
	step_featured_ads=step_featured_ads+p;
	
	$.get("/ax_more_featured_ads_b.php", {page: step_featured_ads},
		function(data){
			$(".items_featured").html(data);	
	});
	return false;
}

function offer_like(id){
	$.get("/ax_offer_like.php", {offer_id: id},
		function(data){
			if(data!='') $("#nr_likes_"+id).html(data);	
	});
	return false;
}

function like(type, id){
	$.get("/ax_like.php", {type: type, ref_id: id},
		function(data){
			if(data!='') $("#nr_likes").html(data);	
	});
	return false;
}

function get_window_dimentsions(){
	var window_dimentsions = {Width: 0, Height: 0};
	
	if( typeof( window.innerWidth ) == 'number' ) {
		//Non-IE
		myWidth = window.innerWidth;
		myHeight = window.innerHeight;
	} 
	else if( document.documentElement && ( document.documentElement.clientWidth || document.documentElement.clientHeight ) ) {
		//IE 6+ in 'standards compliant mode'
		myWidth = document.documentElement.clientWidth;
		myHeight = document.documentElement.clientHeight;
	} 
	else if( document.body && ( document.body.clientWidth || document.body.clientHeight ) ) {
		//IE 4 compatible
		myWidth = document.body.clientWidth;
		myHeight = document.body.clientHeight;
	}
	window_dimentsions.Width=myWidth;
	window_dimentsions.Height=myHeight;
	return window_dimentsions;
}

function popin_photo(photo_id, progeny){	
	var window_dimentsions = get_window_dimentsions();	
	var x, y;
	
	x=Math.round(window_dimentsions.Width / 2);
	y=Math.round(window_dimentsions.Height / 2)+$(window).scrollTop();
	
	$.getJSON("/ax_popin_photo.php", {id: photo_id, progeny: progeny},
		function(data){
			if(data.message!=''){
				$("#html_popin_photo").html(data.message);	
				$("#global_div").addClass("opac_div");	
				
				x = x-Math.round((parseInt(data.width)+40) / 2);
				y = y-Math.round((parseInt(data.height)+110) / 2);
				if(y<35) y=35;	
				
				$("#html_popin_photo").css('left', x + 'px');
				$("#html_popin_photo").css('top', y + 'px');
				show("#html_popin_photo");
			}
	});
	
	return false;
}

function close_popin_photo(){
	$("#global_div").removeClass("opac_div");	
	$("#html_popin_photo").css('display', 'none');
}

function add_dream_stable(ad_id){
	$.get("/ax_add_dream_stable.php", {ad_id: ad_id},
		function(data){
			if(data!='') $("#popin_dream_html").html(data);	
	});
	return false;
}

function remove_dream_stable(id){
	$.get("/ax_remove_dream_stable.php", {id: id},
		function(data){
			if(data=="true"){
				$("#stable_"+id).remove();	
				$("#num_horses").html((parseInt($("#num_horses").html())-1));
			}
	});
	return false;
}

function add_form_vote(entry_id){
	$.get("/ax_add_form_vote.php", {entry_id: entry_id},
		function(data){
			if(data!=''){
				$('.vote').removeClass('vote_sel');
				$("#vote_"+entry_id).addClass("vote_sel");
				$("#vote_"+entry_id).btOn();
			}
	});
	return false;
}

function show_notification(){
	setTimeout(function() {
		$.get("/ax_get_tip.php",
			function(data){
				if(data!=""){
					$("#notifications .float_left").html(data);
					$("#notifications").show();
					setTimeout(function() {
						$("#notifications").hide();
					}, 12000);
				}
		});
	}, 2000);
}

function get_ads_uploaded_photos(objid,acode){
	$.get("/ax_get_temp_uploaded_photos.php", { scode: acode },
		function(data){
			$('#'+objid).html(data);
		}

	);
}

function get_ads_uploaded_photos2(objid,temp){
	$.get("/ax_get_temp_uploaded_photos.php", { temp_id: temp },
		function(data){
			$('#'+objid).html(data);
				$('#homepage').show();

		}

	);
}
function get_trader_uploaded_photos(objid,code){
	$.get("/ax_get_trader_uploaded_photos.php", { code: code },
		function(data)
		{
			$('#'+objid).html(data);
		}

	);
}

var oldId='';

function setMainUploadedImage(id){
	$.ajax({
		type: "GET",
		url: "/ax_uploaded_image_setmain.php",
		data: "id=" + id+"&oldId=" + oldId,
		success: function(msg){
			if(msg=='success'){
				$('.mainUploadedImage').removeClass('mainUploadedImage');
				
				$("div[id^='uploadedImage']").css('background-color','#F2F2F2');
				$("div[id^='uploadedImage']").css('border','2px solid #F2F2F2');
				$("img[class^='removeUploadedImage']").hide();
				
				$('#uploadedImage'+id).css('background-color','#09C');
				$('#uploadedImage'+id).css('border','2px solid #09C');
				$('.removeUploadedImage'+id).show();
				
				oldId = id;
			}else{
				alert(msg);
			}
		}
	});
}

function setMainUploadedImage2(id, temp){
	$.ajax({
		type: "GET",
		url: "/ax_uploaded_image_setmain2.php",
		data: "id=" + id+"&temp_id=" + temp,
		success: function(msg){
			if(msg=='success'){
				$('.mainUploadedImage').removeClass('mainUploadedImage');
				
				$("div[id^='uploadedImage']").css('background-color','#F2F2F2');
				$("div[id^='uploadedImage']").css('border','2px solid #F2F2F2');
				$("img[class^='removeUploadedImage']").hide();
				
				$('#uploadedImage'+id).css('background-color','#09C');
				$('#uploadedImage'+id).css('border','2px solid #09C');
				$('.removeUploadedImage'+id).show();
				
				get_ad_temp_item(temp);
				get_ad_temp_item_hp(temp);
				
			}else{
				alert(msg);
			}
		}
	});
}
function removeUploadedImage3(id){
	$.ajax({
		type: "GET",
		url: "/ax_trader_image_remove.php",
		data: "id=" + id,
		success: function(msg){
		if(msg=='success'){
			$('#uploadedImage'+id).fadeOut(200,function(){
				$(this).remove();

				});
			}else{
				alert(msg);
			}
		}
	});
}
function removeUploadedImage(id, temp){
	$.ajax({
		type: "GET",
		url: "/ax_uploaded_image_remove.php",
		data: "id=" + id,
		success: function(msg){
		var msg_array = msg.split('|')
		var msg = msg_array[0];
		var last = msg_array[1];
					if(msg=='success'){
				$('#uploadedImage'+id).fadeOut(200,function(){
					$(this).remove();
					get_ad_temp_item(temp);
					get_ad_temp_item_hp(temp);
					if(last==1)
					{
						$('#homepage').hide();
						$('#homepage_ad_bg').hide();
						promote_sell('delete',temp);
					}
				
				});
			}else{
				alert(msg);
			}
		}
	});
}

function ads_set_main_image(id){
	$.get("/ax_ads_set_main_image.php", {id: id},
		function(msg){
			if(msg=='success'){
				$('.mainUploadedImage').removeClass('mainUploadedImage');
				
				$("div[id^='uploadedImage']").css('background-color','#F2F2F2');
				$("div[id^='uploadedImage']").css('border','2px solid #F2F2F2');
				$("img[class^='removeUploadedImage']").hide();
				
				$('#uploadedImage'+id).css('background-color','#09C');
				$('#uploadedImage'+id).css('border','2px solid #09C');
				$('.removeUploadedImage'+id).show();
				
				$('.uploaded_photo').show();
				$('#remove_img_'+id).hide();
			}else{
				alert(msg);
			}
	});
}

function ads_remove_image(id){
	$.get("/ax_ads_remove_image.php", {id: id},
		function(msg){
			if(msg=='success'){
				$('#uploadedImage'+id).fadeOut(200,function(){
					$(this).remove();
				});
			}else{
				alert(msg);
			}
	});
}

function tooltip(element, spikePosition, pointX, position, margin, bgColor, strokeColor, width, fontColor, fontSize, textAlign, spaceTop, padding, spikeLength, spikeGirth, trigger, fontWeight){

	if(bgColor==null) bgColor='#434343';
	if(strokeColor==null) strokeColor='#434343';
	if(margin==null) margin='40px';
	if(width==null) width='100px';
	if(fontSize==null) fontSize='12px';	
	if(fontColor==null) fontColor='#fff';
	if(spikePosition==null) spikePosition='0.5';
	if(pointX==null) pointX='0.18';
	if(position==null) position='top';	
	if(textAlign==null) textAlign='left';
	if(spaceTop==null) spaceTop=$(element).outerHeight();
	if(padding==null) padding=8;
	if(spikeLength==null) spikeLength=10;
	if(spikeGirth==null) spikeGirth=15;
	if(trigger==null) trigger='hover';
	if(fontWeight==null) fontWeight='bold';
	
	$(element).bt({
	  titleSelector: "sss",
	  trigger:trigger,
	  width:width,	
	  fill: bgColor,
	  spaceTop:spaceTop, 
	  strokeStyle: strokeColor, 
	  strokeWidth:1,
	  spikeLength: spikeLength, 
	  spikeGirth: spikeGirth, 
	  padding: padding, 
	  cornerRadius: 5, 
	  spikePosition:spikePosition,
	  centerPointX:pointX,
	  shadow:           true,
	  shadowOffsetX:    0,                     // shadow offset x (px)
	  shadowOffsetY:    2,                     // shadow offset y (px)
	  shadowBlur:       3,                     // shadow blur (px)
	  shadowColor:      "#aaa",
	  positions: [position],
	  cssStyles: {
	    fontFamily: '"verdana"', 
	    fontWeight:fontWeight,
	    textAlign:textAlign,
	    fontSize: fontSize,
	    color:fontColor,
		marginLeft: margin
	  }
	});
}
function up_validation(id)
{
	var array = id.split('_');
	$.get("/ax_fields_ordered.php", {id: array[1]},
			function(fields)
			{
				var field = fields.split('@@');
				for(i=0;i < field.length;i++ )
				{
					if(field[i]==array[1])
					{
						break;	
					}
					else
					{
						validation_field('field_'+ field[i]);
					}
				}
				
			});
	
}

function active_send(id)
{
	
	var ok=1;
	$.get("/ax_fields_ordered.php", {id:id},
	function(fields)
	{
				var field = fields.split('@@');
				for(i=0;i < field.length;i++ )
				{
					if($('#tr_field_' + field[i]).css('background-color')!=='rgb(255, 255, 255)' || $('#tips_field_' + field[i]).html()=="")
					{
						ok=0;	
					}
				}
				
				
				if(ok==1)
				{
		 			$('#form_send').attr('disabled','');
					$('#form_send').removeClass('btn_next');
					$('#form_send').addClass('btn_next_active');
				}
				else
				{
		 			$('#form_send').attr('disabled','disabled');
					$('#form_send').removeClass('btn_next_active');
					$('#form_send').addClass('btn_next');
				}
	});
	
}

function active_field_tip(id)
{
	$('#tr_' + id).css('background-color','#e8faff');
	$('#tip_' + id).show();
	$('#empty_' + id).hide();
	$('#error_' + id).hide();
	$('#valid_' + id).hide();
	up_validation(id);
}
function validation_field(field,n)
{
	var ok=1;
	var array = field.split('_');
	var id = array[1];
	var value = $('#' + field).val();
	if($('#' + field).attr('type')=='checkbox')
	{
		if($('#' + field).attr('checked')==true)
		{
			value=1;
		}
		else
		{
			value=0;	
		}
	}
	if(n)
	{

		var n_ok=0;
		var n_not=0;
		var b=n+1;
		var i=0;
			for (i=1; i < b ; i++)
			{
				var value=$('#field_' + id +'_'+ i).val();

					$.get("/ax_form_validation.php", {id:id,field_value:value},
					function(result)
					{
						if(result!=0)
						{
							n_not++;
						}
						else
						{
							n_ok++;
						}
							
							if(n_not > 0)
							{
								$('#tip_field_' + id).hide();
								$('#tr_field_' + id).css('background-color','#ffc1c1');	
								$('#tips_field_' + id).html(result);
							}
							else if(n_ok==n)
							{
								$('#tip_field_' + id).hide();
								$('#tr_field_' + id).css('background-color','#FFF');	
								$('#tips_field_' + id).html('<div id="valid_field_'+ id +'" class="valid_field"></div>');	
							}
							else
							{
								$('#tip_field_' + id).hide();
								$('#tr_field_' + id).css('background-color','#FFF');
								$('#tips_field_' + id).html(' ');
							}
							active_send(id);
					});

			}


		
	}
	else
	{
			$.get("/ax_form_validation.php", {id:id,field_value:value}, 
			function(result)
			{
				if(result!=0)
				{
					$('#tip_' + field).hide();
					$('#tr_' + field).css('background-color','#ffc1c1');	
					$('#tips_' + field).html(result);
				}
				else
				{
					$('#tip_' + field).hide();
					$('#tr_' + field).css('background-color','#FFF');	
					$('#tips_' + field).html('<div id="valid_field_'+ id +'" class="valid_field"></div>');
				}
				active_send(id);
			});
	 }
}
function set_values(id,value)
{
	
	if($('#' + id).val() == value)$('#' + id).val('');
	else if ($('#' + id).val() == '')$('#' + id).val(value);
}

function active_tip(id)
{
	$('#tr_' + id).css('background-color','#e8faff');
	$('#tip_' + id).show();
	$('#empty_' + id).hide();
	$('#error_' + id).hide();
	$('#valid_' + id).hide();
}

function change_list_bg(obj, tr, color){
	
	if (obj=='check_all')
	{
		var checked_status = $('#check_all').attr('checked');
		$("input[type=checkbox]").each(function()
		{
			if(this.id!='check_all')
			{
				if(checked_status==false)color="#FFF";								
				this.checked = checked_status;
				$(this).parents('.account_new').find(tr).css('background-color',color);
			}
		});		
	}
	else if(tr!=null && color!=null)
	{

		if($(obj).is(':checked')){
			$(tr).css('background-color',color);
		}else{
			$(tr).css('background-color','');
		}
		var checked_status = $(obj).attr('checked');
		if(checked_status == false && $('#check_all').attr('checked')==true )
		{
			$('#check_all').attr('checked',false);
		}
	}
}

function changeSelections(num){
	if (document.getElementById('check_all').checked){
		for (var id = 0; id <= num; id++){
			if (document.getElementById('check_'+id) != null){
				document.getElementById('check_'+id).checked = true;
			}
		}
	}
	else{
		for (var id = 0; id <= num; id++){
			if (document.getElementById('check_'+id) != null){
				document.getElementById('check_'+id).checked = false;
			}
		}
	}
	return true;
}

function type_choosed2(el_id,level)
{
	$.get("/ax_ads_choose_cat.php", {el_id: el_id,level:level},
	function(data)
	{
		newlevel=level+1;
	   	if(data==0)
	   	{
	   		$('#box_'+newlevel).css('display','none');
			set_final('choose_' + el_id);
	   		active_btn('choose_save');
	   		pos= newlevel;
			var i=true;			
			while(i==true)
			{
				$('#box_' + pos).css('display','none');
				pos = pos+1;
				if($('#box_' + pos).length == 0){break;}
			}
	   	}
	   	else
	   	{
			set_selected('choose_' + el_id);
			disable_btn('choose_save');
			$('#box_' + newlevel).css('display','block');
			$('#box_' + newlevel).html(data);
			pos= newlevel+1;
			var i=true;			
			while(i==true)
			{
				$('#box_' + pos).css('display','none');
				pos = pos+1;
				if($('#box_' + pos).length == 0){break;}
			}
    	}
    	var newwidth=0;
 		$('div [id^="box"]:visible').each(function()
 		{
 			newwidth=newwidth+$(this).outerWidth(true);
		});
		
	   	$('.choose_under').css('width',newwidth+'px');
	   	if(level > 2)$('div [id^="box"]:visible').append('<a href="#" style="display:block;height:17px;" class="scrollbar_comp"></a>');
	   	else $('.scrollbar_comp').remove();
  	 	$('.overflow_choose').scrollTo( '100%','100%',800 );
		$('#choosed_id').val(el_id);
 	
 	});
}

function update_overflow()
{
	var newwidth=0;
	$('div [id^="box"]:visible').scrollTo( '.choose_item_sel',800 );
	$('div [id^="box"]:visible').each(function()
	{
	  newwidth=newwidth+$(this).outerWidth(true);
   });
	$('.choose_under').css('width',newwidth+'px');
	if(newwidth > 790)$('div [id^="box"]:visible').append('<a href="#" style="display:block;height:17px;" class="scrollbar_comp"></a>');
	$('.overflow_choose').scrollTo('100%','100%',800);
	
}

function get_ad_temp_item(temp){
	$.get("/ax_paa_get_ad_temp_item.php", {temp_id:temp},
	function(data)
	{
		$('#upsell_preview').html(data);
	});
}
function get_ad_temp_item_hp(temp){
	$.get("/ax_paa_get_ad_temp_item_hp.php", {temp_id:temp},
	function(data)
	{
		$('#homepage_ad_upsell').html(data);
	});
}

function promote_sell(id,temp_id)
{
if(id!="delete")
{
	eval('var ' + id + '="";');
}

	if (id == 'all')
	{
		var all_class = $('#' + id).attr('class');
		if(all_class == 'float_left check_all_sell')
		{	
			$('#' + id).removeClass('check_all_sell');
			$('#' + id).addClass('check_all_sell_green');
			
			$('#promote_sells').children('div[class=sell]:visible').each(function() 
			{
				$(this).removeClass('sell');
				$(this).addClass('sell_green');
				$(this).children(':first-child').removeClass('check_sell');
				$(this).children(':first-child').addClass('check_sell_green');
			});

			$('.ad_preview').css("padding-top", "0px");
			$('.ad_preview').css("height", "316px");
			$('#select_text').html("Deselect all");
					
			all=1;
		}
		else if(all_class == 'float_left check_all_sell_green')
		{
			$('#' + id).removeClass('check_all_sell_green');
			$('#' + id).addClass('check_all_sell');
			
			$('#promote_sells').children('div[class=sell_green]:visible').each(function() 
			{
				if(!$(this).hasClass('always_sel'))
				{
					$(this).removeClass('sell_green');
					$(this).addClass('sell');
					$(this).children(':first-child').removeClass('check_sell_green');
					$(this).children(':first-child').addClass('check_sell');
				}
			});
			
			 $('.ad_preview').css("padding-top", "116px");
			 $('.ad_preview').css("height", "200px");
			 $('#select_text').html("Select all");
			
			all=2;
		}
	}
	else
	{
		var aclass=$('#' + id).attr('class');
		if(id == "delete")
		{
			id='homepage';
			homepage=2;
			$('#' + id).removeClass('sell_green');
			$('#' + id).addClass('sell');
			$('#check_' + id).removeClass('check_sell_green');
			$('#check_' + id).addClass('check_sell');	
		}
		else if(aclass=="sell")
		{
			$('#' + id).removeClass('sell');
			$('#' + id).addClass('sell_green');
			$('#check_' + id).removeClass('check_sell');
			$('#check_' + id).addClass('check_sell_green');
			eval(id + "=1;");
		}
		else if(aclass=="sell_green")
		{
			$('#' + id).removeClass('sell_green');
			$('#' + id).addClass('sell');
			$('#check_' + id).removeClass('check_sell_green');
			$('#check_' + id).addClass('check_sell');
			$('#all').removeClass('check_all_sell_green');
			$('#all').addClass('check_all_sell');
			$('#select_text').html("Select all");
			eval(id + "=2;");
		}
	}
	eval("$.get('/ax_paa_get_costs.php', {"+ id + ":"+ id +",temp_id:temp_id},function(cost){costs = cost.split('@@');$('#upsell_cost').html(costs[0]);$('#upsell_cost_vivas').html(costs[1]);$('#paa_send').attr('value',costs[2]);get_ad_temp_item(temp_id );get_ad_temp_item_hp(temp_id);});");
	
	
	
	if(id=="top_ad")
	{
		if(top_ad==1)
		{
			 $('.ad_preview').css("padding-top", "0px");
			 $('.ad_preview').css("height", "316px");
		}
		else if(top_ad==2)
		{
			 $('.ad_preview').css("padding-top", "116px");
			 $('.ad_preview').css("height", "200px");
		}
	}
	
	var homepage;
	var all;
	if(homepage==1 || all==1)
	{
		if($('#homepage').css('display')=="block")$('#homepage_ad_bg').show();
	}
	else if(homepage==2 || all==2)
	{
		if($('#homepage').css('display')=="block")$('#homepage_ad_bg').hide();
	}
		
}

function update_price(temp_id)
{
var coupon = $("#coupon").val();
	if (coupon == "")
	{
		alert('Please insert something!!');
	}
	else
	{
			$.get("/ax_paa_get_campaign.php", {coupon:coupon,temp_id:temp_id},
			function(data)
			{
				var array = data.split('@@');
				price = array[0];
				discount = array[1];
				if(price !=0)
				{
					$('#coupon_discount').html(discount)
					$('#upsell_cost').html(price);
					$('#coupon_wrapper').hide();
				}
				else
				{
					alert('Invalid Coupon!!');
				}
			});
	}	
	
}
function valid_external(id)
{
	var temp_id= $('#temp_id').val();
	var value = $('#field_' + id).val();
	var external = "";
	if (value > -1)external=1;
	else if (value == -1)external=2;
	
	$.get("/ax_paa_get_costs.php", {external_altcatid:external,temp_id:temp_id},
	function(cost)
	{
			costs = cost.split('@@');
			$('#upsell_cost').html(costs[0]);
			$('#upsell_cost_vivas').html(costs[1]);
			$('#paa_send').attr('value',costs[2]);
		get_ad_temp_item(temp_id);
		get_ad_temp_item_hp(temp_id);
	});
}

function valid_urgent(id, upsell_name)
{
	var temp_id= $('#temp_id').val();
	var value = $('#field_' + id).attr('checked');

	
	if (value == 1)val=1;
	else if (value == 0)val=2;
	
	eval("$.get('/ax_paa_get_costs.php', {"+ upsell_name + ":val,temp_id:temp_id},function(cost){costs = cost.split('@@');$('#upsell_cost').html(costs[0]);$('#upsell_cost_vivas').html(costs[1]);$('#paa_send').attr('value',costs[2]);get_ad_temp_item(temp_id);get_ad_temp_item_hp(temp_id);});");
	
	$('#tip_field_' + id).hide();$('#error_field_' + id).hide();$('#empty_field_' + id).hide();$('#tr_field_' + id).css('background-color','#FFF');$('#valid_field_' + id).show();
	
}
function valid_urgent_old(id)
{
	var temp_id= $('#temp_id').val();
	var value = $('#field_' + id).attr('checked');
	var urgent = "";
	var trusted = "";
	if(id==175){
		if (value == 1)trusted=1;
		else if (value == 0)trusted=2;
		$.get("/ax_paa_get_costs.php", {trusted:trusted,temp_id:temp_id},
		function(cost)
		{
				costs = cost.split('@@');
				$('#upsell_cost').html(costs[0]);
				$('#upsell_cost_vivas').html(costs[1]);
				$('#paa_send').attr('value',costs[2]);
			get_ad_temp_item(temp_id);
			get_ad_temp_item_hp(temp_id);
		});
		$('#tip_field_' + id).hide();$('#error_field_' + id).hide();$('#empty_field_' + id).hide();$('#tr_field_' + id).css('background-color','#FFF');$('#valid_field_' + id).show();
	}
	else{
		if (value == 1)urgent=1;
		else if (value == 0)urgent=2;
		$.get("/ax_paa_get_costs.php", {urgent:urgent,temp_id:temp_id},
		function(cost)
		{
				costs = cost.split('@@');
				$('#upsell_cost').html(costs[0]);
				$('#upsell_cost_vivas').html(costs[1]);
				$('#paa_send').attr('value',costs[2]);
			get_ad_temp_item(temp_id);
			get_ad_temp_item_hp(temp_id);
		});
		$('#tip_field_' + id).hide();$('#error_field_' + id).hide();$('#empty_field_' + id).hide();$('#tr_field_' + id).css('background-color','#FFF');$('#valid_field_' + id).show();
	}
	
	
	
}
function validation(id,method)
{
	var value2=0;
	var value3=0; 
	var strReturn="";
	var temp_id= $('#temp_id').val();
	var value = $('#field_' + id).val();
	value = urlencode(value);
	if($('#field_' + id +'_price').val()!=0)
	{
		value2 =$('#field_' + id +'_price').val();
	}
	if($('#search_field_' + id).length > 0)
	{
		if($('#field_' + id).val()==0)$('#search_field_' + id).val('');
		value3=$('#search_field_' + id).val();
	}
		if($('#field_' + id).attr('type')=='checkbox')
		{
			if($('#field_' + id).attr('checked')==true)
			{
				value=1;
			}
			else
			{
				value=0;
			}
		}
	jQuery.ajax({url:"/ax_get_validation_result.php?id="+id+"&field_value="+value+"&field_value2="+value2+"&field_value3="+value3+"&temp_id="+temp_id, success:
	function(result)
	{
		if(result == 0)
		{
			$('#tip_field_' + id).hide();$('#error_field_' + id).hide();$('#empty_field_' + id).show();$('#tr_field_' + id).css('background-color','#ffc1c1');$('#valid_field_' + id).hide();
		}
		else if(result == 1)
		{
			$('#tip_field_' + id).hide();$('#error_field_' + id).show();$('#empty_field_' + id).hide();$('#tr_field_' + id).css('background-color','#ffc1c1');$('#valid_field_' + id).hide();
		}
		else if (result == 2)
		{
			$('#tip_field_' + id).hide();$('#error_field_' + id).hide();$('#empty_field_' + id).hide();$('#tr_field_' + id).css('background-color','#FFF');$('#valid_field_' + id).show();
		}
		strReturn = result;
		if(method!=1)
		{
			get_ad_temp_item(temp_id);
			get_ad_temp_item_hp(temp_id);
		}
	},async:false});
	
return strReturn;
}
function update_chk(id,i)
{
	var strReturn="";
	var temp_id= $('#temp_id').val();
	var checked = 0;
	if($('#'+id+i).hasClass('sel'))checked=1;
	var value = $('#id' + i).val();
	value = urlencode(value);
	jQuery.ajax({url:"/ax_get_validation_result.php?id="+id+"&field_value="+value+"&checked="+checked+"&temp_id="+temp_id, success:
	function(result)
	{
		strReturn = result;
		//get_ad_temp_item(temp_id);
		//get_ad_temp_item_hp(temp_id);
	},async:false});
return strReturn;
}
function update_prog(id)
{
	var strReturn="";
	var temp_id= $('#temp_id').val();
	var value = "";
	for(i=1;i<8;i++){

		value = value + "sire"+i+":"+$('#' + id +'_sire_'+i).val()+";";
		value = value + "dam"+i+":"+$('#' + id +'_dam_'+i).val()+";";
	}
	value = urlencode(value);
	jQuery.ajax({url:"/ax_get_validation_result.php?id="+id+"&field_value="+value+"&temp_id="+temp_id, success:
	function(result)
	{
		strReturn = result;
		//get_ad_temp_item(temp_id);
		//get_ad_temp_item_hp(temp_id);
	},async:false});
return strReturn;
}
function multiple_validation(id,n,method)
{
	var strReturn="";
	var temp_id = $('#temp_id').val();
	var array = id.split('_');
	var id = array[0];
	if(n)
	{
		var n_ok=0;
		var n_not=0;
		var n_error=0;
		var n_empty=0;
		var b=n+1;
		var i=0;
			for (i=1; i < b ; i++)
			{
				var value=$('#field_' + id +'_'+ i).val();
				jQuery.ajax({url:"/ax_get_validation_result.php?id="+id+"&field_value="+value+"&temp_id="+temp_id+"&n="+i, success:
				function(result)
				{
						if(result == 0 || result == 1)
						{
							if(result==1)
							{
							  n_error++;
							}
							if(result==0)
							{
							  n_empty++;
							}
							n_not++;
						}
						else
						{
							n_ok++;
						}
						if(n_not > 0 && n_empty > 0)
						{
							strReturn = 0;
							$('#tip_field_' + id).hide();$('#empty_field_' + id).show();$('#error_field_' + id).hide();$('#tr_field_' + id).css('background-color','#ffc1c1');$('#valid_field_' + id).hide();
						}
						else if (n_not > 0 && n_error > 0)
						{
							strReturn = 0;
							$('#tip_field_' + id).hide();$('#error_field_' + id).show();$('#empty_field_' + id).hide();$('#tr_field_' + id).css('background-color','#ffc1c1');$('#valid_field_' + id).hide();							
						}
						else if(n_ok==n)
						{
							strReturn = 2;
							$('#tip_field_' + id).hide();$('#error_field_' + id).hide();$('#empty_field_' + id).hide();$('#tr_field_' + id).css('background-color','#FFF');$('#valid_field_' + id).show();
						}
						if(method!=1)
						{
							get_ad_temp_item(temp_id);
							get_ad_temp_item_hp(temp_id);
						}
				},async:false});
			}
	}
	return strReturn;
}
function valid_all_paa(paa_id,method)
{
	$('#validation_errors').hide();
	$('#validation_errors2').hide();
	$('#validation_errors_fields').html('');
	var str="";
	var mult="";
	var checkbf="";
	var progeny="";
	
	var ok=1;
		jQuery.ajax({url:"/ax_get_paa_ordered.php?id="+ paa_id, success:
		 function(fields)
		 {
		 	var array = fields.split('||');
		 	str=array[0];
		 	mult=array[1];
		 	checkbf=array[2];
		 	progeny=array[3];
		 	

		 	var field = str.split('@@');
			for(i=0;i < field.length;i++ )
			{
				
				if(validation(field[i],1)!=2)
				{
					set_up_field_error(field[i]);
					ok=0;
				}
			}
			if(mult!="")
			{
				var field2 = mult.split('@@');
				for(i=0;i < field2.length;i++ )
				{
					if(multiple_validation(field2[i],2,1)!=2)
					{
						set_up_field_error(field2[i]);
						ok=0;
					}
				}
			}
			if(checkbf!="")
			{
				var field3 = checkbf.split('@@');
				for(i=0;i < field3.length;i++ )
				{
					if(update_chk(field3[i])!=2)
					{
						set_up_field_error(field3[i]);
						ok=0;
					}
				}
			}
			if(progeny!="")
			{
				var field4 = progeny.split('@@');
				for(i=0;i < field4.length;i++ )
				{
					if(update_prog(field4[i])!=2)
					{
						set_up_field_error(field4[i]);
						ok=0;
					}
				}
			}
			
			if(ok == 1)
			{
				if(method=='send')
				{
					$('#ready').val(1);
				}
				else if(method == 'preview')
				{
					$('#preview_send').val(1);	
				}
				$('form').submit();
			}
			else
			{
				$('html, body').animate({scrollTop: '0px'}, 'slow');
				$('#validation_errors').show();
			}
			
		},async:true});

	return false;
}
function set_up_field_error(id)
{
	var error_html=$('#validation_errors_fields').html();
	$('#validation_errors_fields').html(error_html+'- '+$('#label_'+id).html()+'<br />');
}
function submit_trader_contact(trader_id)
{
	$('#contact_result').html('waiting...');
	var cname=$('#contact_name').val();
	var cemail=$('#contact_email').val();
	var cmessage=$('#contact_message').val();
	var code=$('#code').val();
	$.get("/script/captcha/post.php",{code:code},function(response)
	{
			
			if(response==1)
			{
				$('#contact_result').html('sending message...');
					$.get('/ax_send_trader_email.php',{cname:cname,cemail:cemail,cmessage:cmessage,trader_id:trader_id},function(data)
					{
				
						$('#contact_result').html(data);
						$('#contact_name').val('');
						$('#contact_email').val('');
						$('#contact_message').val('');
					
					});
			}
			else
			{
				$("#contact_result").html(response);
			}
	});

	
}
function refresh_captcha()
{
	$('#captcha').attr('src',"/get_captcha.php?rnd=" + Math.random());
}
function activate_tab(biz_id,news)
{
	$.get('/ax_activate_tab.php',{biz_id:biz_id,news:news},function(data)
	{
		if(data==1)
		{
			get_tab_form(biz_id,news);
		}
	});
}
function get_tab_form(biz_id,news)
{
	$.get('/ax_customtab_form.php',{biz_id:biz_id,news:news},function(data)
	{
		if(news==0)
		{
			$('#customtab_content').html(data);
		}
		else
		{
			$('#newstab_content').html(data);
		}
	});	
}
function save_customtab(biz_id,news)
{
	if(news==0)
	{
	var oEditor = FCKeditorAPI.GetInstance('customtab_template');
	var customtab_template = oEditor.GetXHTML(true);
	}
	var customtab_name = $('#customtab_name').val();
	customtab_name=urlencode(customtab_name);
	var customtab_active = $('#customtab_active').attr('checked');
	customtab_active=(customtab_active)?1:0;
	$.get('/ax_save_customtab.php',{cName:customtab_name,cTemplate:customtab_template,cActive:customtab_active,biz_id:biz_id,news:news},function(data)
	{
		if(data==1)get_customtab_info(biz_id,news);
	});
}
function get_customtab_info(biz_id,news)
{
	$.get('/ax_customtab_info.php',{biz_id:biz_id,news:news},function(data)
	{
		if(news==0)$('#customtab_content').html(data);
		else $('#newstab_content').html(data);
	});	
}
function add_biz_item(biz_id)
{
	
	$.get('/ax_add_biz_item.php',{biz_id:biz_id},function(data)
	{
		var datas=data.split('|');
		var result_id=datas[0];
		var message=datas[1];
		if(result_id > 0)
		{
			$('#newsitems_content').append(message + '<div class="biz_item" id="biz_item_'+result_id+'"></div>');
			edit_biz_item(biz_id,result_id);
		}
	});	
}
function edit_biz_item(biz_id,id)
{
	$.get('/ax_edit_biz_item.php',{biz_id:biz_id,id:id,del:0},function(data)
	{
			$('#biz_item_'+id).html(data);
	});	
}
function delete_biz_item(biz_id,id)
{
	$.get('/ax_edit_biz_item.php',{biz_id:biz_id,id:id,del:1},function(data)
	{
			$('#biz_item_'+id).fadeOut('slow',function(){$('#biz_item_'+id).remove();});
	});	
}
function save_biz_item(biz_id,id,save)
{
	$('#message_'+id).fadeOut();
	var oEditor = FCKeditorAPI.GetInstance('item_intro_'+id);
	var item_intro = oEditor.GetXHTML(true);
	var item_name = $('#item_name_'+id).val();
	item_name=urlencode(item_name);
	var item_active = $('#item_active_'+id).attr('checked');
	item_active=(item_active)?1:0;
	$.get('/ax_save_biz_item.php',{iName:item_name,iIntro:item_intro,iActive:item_active,biz_id:biz_id,id:id,save:save},function(data)
	{
			$('#item_image_'+id).uploadifyUpload();
			$('#biz_item_'+id).html(data);
	});	
}
function get_item_uploaded_photo(id)
{
	$.get("/ax_get_item_uploaded_photo.php", { id: id },
		function(data)
		{
			$('#item_uploaded_'+id).html(data);
		}

	);
}
function get_biz_uploaded_photo(id)
{
	$.get("/ax_get_biz_uploaded_photos.php", { id: id },
		function(data)
		{
			$('#biz_uploaded_photos').html(data);
		}

	);
}
function remove_biz_photo(id)
{
	$.get("/ax_remove_biz_photo.php", { id: id },
		function(data)
		{
			$('#biz_photo_'+id).fadeOut(function(){$('#biz_photo_'+id).remove();});
		}

	);
}
function save_biz_photos(biz_id)
{
	$.get("/ax_save_biz_photos.php", { biz_id: biz_id,save:1 },
		function(data)
		{
			$('#existing_photos').prepend($('#biz_uploaded_photos').html());
			$('#biz_uploaded_photos').children('div').each(function() 
			{
				$(this).fadeOut('slow',function(){$(this).remove();});
			});
		}

	);
}
function cancel_biz_photos(biz_id)
{
	$.get("/ax_save_biz_photos.php", { biz_id: biz_id,save:0},
		function(data)
		{
			$('#biz_uploaded_photos').children('div').each(function() 
			{
				$(this).fadeOut('slow',function(){$(this).remove();});
			});
		}

	);
}
function show_biz_photo(id)
{
	var img_biz=$('#img_biz_' + id).html();
	var src = $('#img_biz_' + id).children('img').attr('src');
	src=src.replace('small_','img_');
	$('#img_biz_' + id).append('<div id=\"preview_'+id+'\"class=\"preview_img_biz\"><img width="500" src="'+src+'"/></div>');
	$('#img_biz_' + id).mousemove(function(e)
	{
      $('#preview_'+id).css({
            	top: (e.pageY - $('#img_biz_' + id).offset().top)  + 3 + 'px',
               left: (e.pageX - $('#img_biz_' + id).offset().left) + 3 +'px'
                });
                
   });
}
var lastOpenedMain;
function showMain(id){
	if(lastOpenedMain!=id){
		showSecondChild('0');
		//selectFCLink('0');
	}
	$('#main'+id).addClass('main_hover');
	$('#amain'+id).removeClass('main');
	$('#amain'+id).addClass('main_hover');
	$('#menu_shadow'+id).show();
	$('#fc'+id).show();
	lastOpenedMain = id;
}

function hideMain(id){
	$('#amain'+id).removeClass('main_hover');
	$('#amain'+id).addClass('main');
	$('#fc'+lastOpenedMain).hide();
	$('#menu_shadow'+lastOpenedMain).hide();
}
var lastSC = '#sc0';
function showSecondChild(id){
	if(id!='-1'){
		$(lastSC).hide();
		$('#sc'+id).show();
		lastSC = '#sc'+id;
	}else{
		$(lastSC).hide();
	}
}

var lastFCLink = 'fclink0';
function selectFCLink(id){
	$(lastFCLink).addClass('first_child');
	$(lastFCLink).removeClass('first_child_hover');
	$('#fclink'+id).removeClass('first_child');
	$('#fclink'+id).addClass('first_child_hover');
	lastFCLink = '#fclink'+id;
}
function urlencode (str) {
	str = (str + '').toString();
    // Tilde should be allowed unescaped in future versions of PHP (as reflected below), but if you want to reflect current
    // PHP behavior, you would need to add ".replace(/~/g, '%7E');" to the following.
    return encodeURIComponent(str).replace(/~/g, '%7E').replace(/!/g, '%21').replace(/\'/g, '%27').replace(/\(/g, '%28').replace(/\)/g, '%29').replace(/\*/g, '%2A').replace(/%20/g, '+');
}

var map_opened_global=0;
function switch_map_visibility(show_label, hide_label, host, mapwhere, map_opened){
	if($('.iframe_map').hasClass('iframe_map_opened')){
		$('.iframe_map').removeClass('iframe_map_opened');
		$('.iframe_map').addClass('iframe_map_closed');
		$('.ads_list_map a').removeClass('opened');
		$('.ads_list_map a').addClass('closed');
		$('.ads_list_map a span').html(show_label);
	}
	else{
		$('.iframe_map').removeClass('iframe_map_closed');
		$('.iframe_map').addClass('iframe_map_opened');
		$('.ads_list_map a').removeClass('closed');
		$('.ads_list_map a').addClass('opened');
		$('.ads_list_map a span').html(hide_label);
		if(map_opened==0 && map_opened_global==0) $('.iframe_map').html("<iframe id=\"iframe_map\" src=\"http://"+host+"/ads_map_list.php?wheremap="+mapwhere+"\" width=\"665\" height=\"450\" frameborder=\"0\" scrolling=\"no\"></iframe>");
		map_opened=1;
		map_opened_global=1;
	}
}
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) id_img=-1;
	
	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;				
	}

}

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) id_img=id.length;
	
	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;				
	}	
}

function switch_usermenu_visibility(){
	toogle('.usermenu');
	if($('.usermenu_top').hasClass('usermenu_top_sel')) $('.usermenu_top').removeClass('usermenu_top_sel');
	else $('.usermenu_top').addClass('usermenu_top_sel');
}

function focus_hd_search(default_text){
	if($('#search_string').val(default_text)) $('#search_string').val('');

	$(".search_bar .in").addClass("in_focus");	
	hide($(".search_bar .tools"));
	show('#hd_other_filters');	
}

function blur_hd_search(default_text){
	if($('#search_string').val()=='') $('#search_string').val(default_text);
	/*$(".search_bar .in").removeClass("in_focus");
	hide('#hd_other_filters');	
	show($(".search_bar .tools"));*/
}

function ad_show_phone_mobile(ad_id, field){
	$.get("/ax_ad_show_phone_mobile.php", {ad_id: ad_id, field: field});
	hide('#ad_'+field+'_label');
	show('#ad_'+field+'_number');
}

