/********************
TOTAL
1: UTILS
2:PET PAGE
3:WEIGHT CLINIC PAGE
4:WEIGHT CHECKER
5:SMILEY
*********************/



/********************
UTILS
*********************/
function show_calendar(year, month) {
	$("#calendar_holder").css( {display: "block"} );
	$("#calendar_holder").load("/weight_check/calendar/" + year + "/" + month + "/");
}
function calendar_prev_month(year, month) {
	if(month == 1) {
		month = 12;
		--year;
	} else {
		--month;
	}
	show_calendar(year, month);
}
function calendar_next_month(year, month) {
	if(month == 12) {
		month = 1;
		++year;
	} else {
		++month;
	}
	show_calendar(year, month);
}
function calendar_add_start_date(year, month, day) {
	$("#calendar_holder").html("start date: " + year + "/" + month + "/" + day)
	$("input[@name='data_pet_start_month']").val( month );
	$("input[@name='data_pet_start_day']").val( day );
	var list = $("#plan_holder tbody > tr");
	date = new Date();
	date.setFullYear(year, month-1, day)
	for(var i = 0 ; i < list.length ; ++i) {
		$("#plan_holder tbody > tr:eq(" + (i + 1) + ") td.date").html(date.getFullYear() + "." + (date.getMonth() + 1) + "." + date.getDate());
		date.setDate(date.getDate() + 7);
	}
}
function is_number(x){
	var anum=/(^\d+$)|(^\d*\.\d+$)/
	if (anum.test(x))
		return true;
	else{
		return false;
	}
}
function trim(str, chars) {
    return ltrim(rtrim(str, chars), chars);
}

function ltrim(str, chars) {
    chars = chars || "\\s";
    return str.replace(new RegExp("^[" + chars + "]+", "g"), "");
}
function rtrim(str, chars) {
    chars = chars || "\\s";
    return str.replace(new RegExp("[" + chars + "]+$", "g"), "");
}
/********************
PET PAGE
*********************/
function onIconClicked(p_icon){  
	addIconComment(p_icon);
}
function addIconComment(p_icon)
{
	var comment_choice = document.getElementById("id_comment_choice");
	comment_choice.value = p_icon;
	var btn = document.getElementById("id_submit_comment");
	btn.click();
}
function addFriendComment(pet_name, friend_name)
{
	var msg_field = document.getElementById("id_message");
	msg_field.value= pet_name +" and "+ friend_name + " are now friends";
	
	var comment_choice = document.getElementById("id_comment_choice");
	comment_choice.value = "friend_added";
	var btn = document.getElementById("id_submit_comment");
	btn.click();
}
function swapImage(image)
{
	imgElement = document.getElementById("pet_image");
	imgElement.src = image;	
}
function update_pictures(pet_id) {
	$("#weight_chart_edit").load("/mypets/edit/weight_loss_plan/?t=" + (new Date()).getTime() + "&pet=" + pet_id);
}
function add_friend(pet_id, friend_id) {
	$("#pet_friends").load("/mypets/edit/pet_friends/?t=" + (new Date()).getTime() + "&pet="+pet_id+"&friend="+friend_id+"&action=add");	
}
function delete_friend(pet_id, friend_id) {
	$("#pet_friends").load("/mypets/edit/pet_friends/?t=" + (new Date()).getTime() + "&pet="+pet_id+"&friend="+friend_id+"&action=delete");
}
function result_friend_added(pet_name, friend_name) {
	addFriendComment(pet_name, friend_name);
}

/*WEIGHT LOSS PLAN*/

function update_weight_loss_plan(pet_id) {
	$("#weight_chart_edit").load("/mypets/edit/weight_loss_plan/?t=" + (new Date()).getTime() + "&pet=" + pet_id);
}

function proc_weight_loss_plan(pet_id) {
	var error = false;
	var bodyframe = $("input[@name='bodyframe']:checked").val();
	var gender = $("input[@name='gender']:checked").val();
	var weight = $("input[@name='weight']").val();
	var vet_weight = $("input[@name='vet_weight']").val();
	var pet_gender = $("input[@name='pet_gender']").val();
	if(vet_weight==""){
		vet_weight = 0;
	}
	if(!bodyframe) {
		error |= true;
	}
	if( !pet_gender ) {
		if(!gender) {
			error |= true;
		}
	}
	if(weight.length == 0 || !is_number(weight)) {
		error |= true;
	}	
	if(error) {
		var msg = "";
		if( !pet_gender ) {
			msg = "Please choose valid bodyframe size, gender and current weight."
		} else {
			msg = "Please choose valid bodyframe size and current weight."
		}
		$("#weight_loss_plan_error").html(msg);
	} else {
		$("#weight_loss_plan_error").html("");
		$("#weight_loss_plan_loading").css( {display: "block"} );
		
		$("#weight_chart_edit").load( "/mypets/edit/weight_loss_plan/?t=" + (new Date()).getTime() + "&pet=" + pet_id, 
			{
				bodyframe: bodyframe, 
				gender: gender, 
				weight: weight,
				vet_weight: vet_weight,
				data_pet_start_year: $("input[@name='data_pet_start_year']").val(),
				data_pet_start_month: $("input[@name='data_pet_start_month']").val(),
				data_pet_start_day: $("input[@name='data_pet_start_day']").val()
			},
			function() {
				$("#weight_loss_plan_loading").css( {display: "none"} );
				$("#step_ideal_next").css( {display: "block"} );
				$("#pet_details").load( "/mypets/edit/details/?t=" + (new Date()).getTime() + "&pet=" + pet_id);
			} );
	}
}
function result_weight_loss_plan(pet_id) {
	$("#weight_chart_edit").html("");
	$("#mypet_weight_chart").load("/mypets/weight_chart/?t=" + (new Date()).getTime() + "&pet=" + pet_id);
}
function cancel_weight_loss_plan() {
	$("#weight_chart_edit").html("");
}
/*
* PET HI LO
*/
function update_hi_lo(pet_id) {
	$("#pet_hi_lo").load("/mypets/edit/hi_lo/?t=" + (new Date()).getTime() + "&pet=" + pet_id + "&edit=true");
}
function proc_hi_lo(pet_id) {
	//alert("prot")
	$("#pet_hi_lo").load( "/mypets/edit/hi_lo/?t=" + (new Date()).getTime() + "&pet=" + pet_id + "&edit=true", 
		{
			hi1: $("#pet_hi_lo input[@name='hi1']").val(),
			hi2: $("#pet_hi_lo input[@name='hi2']").val(),
			hi3: $("#pet_hi_lo input[@name='hi3']").val(),
			hi4: $("#pet_hi_lo input[@name='hi4']").val(),
			lo1: $("#pet_hi_lo input[@name='lo1']").val(),
			lo2: $("#pet_hi_lo input[@name='lo2']").val(),
			lo3: $("#pet_hi_lo input[@name='lo3']").val(),
			lo4: $("#pet_hi_lo input[@name='lo4']").val()
		},
		function(id) {
			$("#pet_about_loading").css( {display: "none"} );			
	 		//result_hi_lo(id)
			
		}
	);
}
function cancel_hi_lo(pet_id) {
	$("#pet_hi_lo").load("/mypets/edit/hi_lo/?t=" + (new Date()).getTime() + "&pet=" + pet_id);
}
function result_hi_lo(pet_id) {
	//alert('result_hi_lo')
	window.location.href = window.location.href;
}
/*
* PET MESSAGE
*/
function update_status_message(pet_id) {
	
	$("#pet_message").load("/mypets/edit/status_message/?t=" + (new Date()).getTime() + "&pet=" + pet_id + "&edit=true");
}
function proc_status_message(pet_id) {
	$("#pet_message").load( "/mypets/edit/status_message/?pet=" + pet_id + "&edit=true", 
		{
			status_message_dropdown:$("#pet_message select[@name='status_message_dropdown']").val(),
			status_message_text_area:$("#pet_message input[@name='status_message_text_area']").val()
		}
	);
}
function cancel_status_message(pet_id) {
	$("#pet_message").load("/mypets/edit/status_message/?t=" + (new Date()).getTime() + "&pet=" + pet_id);
}
function result_status_message(pet_id) {
	window.location.href = window.location.href;
}
/*
* PET ABOUT
*/
function update_about(pet_id) {
	$("#pet_about").load("/mypets/edit/about/?t=" + (new Date()).getTime() + "&pet=" + pet_id + "&edit=true");
}
function proc_about(pet_id) {
	$("#pet_about").load( "/mypets/edit/about/?pet=" + pet_id + "&edit=true", 
		{
			about: $("#pet_about textarea[@name='about']").val()
		}
	);
}
function cancel_about(pet_id) {
	$("#pet_about").load("/mypets/edit/about/?t=" + (new Date()).getTime() + "&pet=" + pet_id);
}
function result_pet_about(pet_id) {
	
	
	window.location.href = window.location.href;
}
/*
 * PET DETAILS
*/
function update_pet_details(pet_id) {
	$("#pet_details").load("/mypets/edit/details/?t=" + (new Date()).getTime() + "&pet=" + pet_id + "&edit=true");
}
function proc_pet_details(pet_id) {
	
	var update_weight = "";
	if( $("#pet_details input[@name='update_weight']").attr("checked") ){
		update_weight = "on";
	}
	var bodyframe = $("#pet_details input[@name='bodyframe']:checked").val();
	if( $("#pet_details input[@name='bodyframe']:checked").val() == null ){
		bodyframe = "";
	}
	
	
	if (!$("#pet_details input[@name='vet_weight']").val())
	{
		$("#pet_details input[@name='vet_weight']").val(0.00)
	}
	
	
	$("#pet_details").load( "/mypets/edit/details/?t=" + (new Date()).getTime() + "&pet=" + pet_id + "&edit=true", 
		{
			breed: $("#pet_details select[@name='breed']").val(), 
			age: $("#pet_details input[@name='age']").val(), 
			gender: $("#pet_details input[@name='gender']:checked").val(), 
			loves: $("#pet_details input[@name='loves']").val(), 
			hates: $("#pet_details input[@name='hates']").val(), 
			update_weight: update_weight,
			weight: $("#pet_details input[@name='weight']").val(), 
			vet_weight: $("#pet_details input[@name='vet_weight']").val(), 
			bodyframe: bodyframe 
		},
		function(id) {
			  result_pet_details(id)
		}
	);
}
function cancel_pet_details(pet_id) {
	$("#pet_details").load( "/mypets/edit/details/?t=" + (new Date()).getTime() + "&pet=" + pet_id);
}
function show_update_weight_form(obj) {
	if(obj.checked) {
		$("#pet_details input[@name='weight']").val( $("#pet_details input[@name='hidden_current_weight']").val() )
		$("#pet_details_weight_form").css( {display: "block"} )
	} else {
		$("#pet_details_weight_form").css( {display: "none"} )
	}
}
function result_pet_details(pet_id) {
	window.location.href = window.location.href;
}
/*
 * INVITE FRIENDS
*/
function displayInviteFriends()
{
	$("#invite_friends_link").css("display","none");
	$("#invite_friends_main").css("display", "block");
}
function proc_invite_friends(p_pet_id)
{	
	$("#invite_friends_result").html("");
	var val = trim( $("#id_invite_friends_email").val() );
	var reg = /^([A-Za-z0-9_\-\.])+\@([A-Za-z0-9_\-\.])+\.([A-Za-z]{2,4})$/;
	// cause problems in ie
	if(reg.test(val) == false) {
		$("#invite_friends_result").html("Please enter valid email.");
	} else {
	  $("#invite_friends_result").load("/mypets/invite_friends/",
		  {
			  email: $("#id_invite_friends_email").val(),
			  pet_id: p_pet_id
		  })
	}
}
function result_invite_friends(msg)
{
	if(!msg)
	{
		msg = "thank you!"
	}
	$("#invite_friends_result").html(msg);
}
/********************
WEIGHT CLINIC PAGE
*********************/
$(document).ready(function() {	
			$('#advice_boxes .box').mouseover(function(){
				$(this).find('.tip').css("display","block");
			});
			$('#advice_boxes .box').mouseout(function(){
				$(this).find('.tip').css("display","none");
			});		 
});
function showTip(p_back){
	 $("#tip").load("/tip/?back="+p_back);
}
function createNumber(p_txt){
	var txt = p_txt;
	txt =  txt.slice(0,txt.indexOf(".")) +  txt.slice(txt.indexOf(".")+1);
	var txt_ar= txt.split("");
	var imageNumber = "";
	for (i=0;i<txt_ar.length;i++){
		imageNumber+="<img src='/site-media/images/modules/state_nations_pets/"+txt_ar[i]+".jpg'/>"; 	
	}
	imageNumber+="<img src='/site-media/images/modules/state_nations_pets/0.jpg'/>" ;
	imageNumber+="<img src='/site-media/images/modules/state_nations_pets/0.jpg'/>" ;
	imageNumber+="<img src='/site-media/images/modules/state_nations_pets/0.jpg'/>" ;
	imageNumber+="<img src='/site-media/images/modules/state_nations_pets/0.jpg'/>" ;
	imageNumber+="<img src='/site-media/images/modules/state_nations_pets/0.jpg'/>" ;
    return imageNumber;
}
/********************
WEIGHT CHECKER
*********************/
function runOnLoad(f) {
    if (runOnLoad.loaded) f();    
    else runOnLoad.funcs.push(f); 
}
runOnLoad.funcs = []; 
runOnLoad.loaded = false; 
runOnLoad.run = function() {
    if (runOnLoad.loaded) return;  
    for(var i = 0; i < runOnLoad.funcs.length; i++) {
        try { runOnLoad.funcs[i](); }
        catch(e) {  }
    }
    runOnLoad.loaded = true; 
    delete runOnLoad.funcs;  
    delete runOnLoad.run;  
};
if (window.addEventListener)
    window.addEventListener("load", runOnLoad.run, false);
else if (window.attachEvent) window.attachEvent("onload", runOnLoad.run);
else window.onload = runOnLoad.run;
function stopRKey(evt) {
  var evt = (evt) ? evt : ((event) ? event : null);
  var node = (evt.target) ? evt.target : ((evt.srcElement) ? evt.srcElement : null);
  if ((evt.keyCode == 13) && (node.type=="text"))  {return false;}
}
document.onkeypress = stopRKey; 
runOnLoad(function(){
    $("#pet_name_next").bind("click", function(e){
        proc_step1_name();
    })
});
function proc_step1_name() {
	var val = trim( $("#pet_name").val() );
	if(val.length == 0) {
		$("#step_error").html("Please enter valid name.");
		return false;
	} else {
		$("#step_error").html("");
		$("#data_pet_name").val( val );
		$("#step_content").empty();
		$("#step_content").load("/weight_check/1/age/");
		return true;
	}
}
function showPopup(){
	$("#popup").css("display","block");
}
function hidePopup(){
	$("#popup").css("display","none");
}
function weight_checker_next(step, phase, next_step, next_phase) {
	$("#data_pet_" + phase).val( $("#pet_" + phase).val() );
	alert( $("#pet_" + phase).val() );
	alert( document.getElementById("data_pet_" + phase) );
	alert( $("#data_pet_" + phase).val() );	
	$("#step_content").load("/weight_check/" + next_step + "/" + next_phase);
}
function prepopulate_from_saved(pet_name, pet_age, pet_type, pet_breed, pet_bodyframe, pet_gender, pet_weight_ideal, pet_weight_ideal_vet) {
	$("#data_pet_name").val( pet_name );
	$("#data_pet_age").val( pet_age );
	$("#data_pet_type").val( pet_type );
	$("#data_pet_breed").val( pet_breed );
	$("#data_pet_bodyframe").val( pet_bodyframe );
	$("#data_pet_gender").val( pet_gender );
	$("#data_pet_weight_ideal").val( pet_weight_ideal );
	$("#data_pet_weight_ideal_vet").val( pet_weight_ideal_vet );
	
	proc_step2_ideal_next();
}
function back_to_proc_step1_name()
{
	$("#step_content").load("/weight_check/1/name", null, 				
			function(){
				$("#pet_name").val(  $("#data_pet_name").val()  )
			}
		);	
}
function proc_step1_age() { 
	var val = trim( $("#pet_age").val() );
	if(val.length == 0 || !is_number(val)) {
		$("#step_error").html("Please enter valid age.");
	} else {
		val = Number(val);
		$("#step_error").html("");
		$("#data_pet_age").val( val );
		$("#step_content").load("/weight_check/1/type/");
	}
}
function back_to_proc_step1_age(){
	$("#step_content").load("/weight_check/1/age", null, function(){
			$("#pet_age").val(  $("#data_pet_age").val()  )
			});
}
function proc_step1_type(type) {
	$("#data_pet_type").val( type );
	$("#tab_steps").load("/weight_check/step/2");
	$("#step_content").load("/weight_check/2/slider/?type="+type);
}
function back_to_proc_step1_type(){
	$("#step_content").load("/weight_check/1/type/");
}
function proc_step2_slider(){
	$("#step_content").load("/weight_check/2/ideal/" + $("#data_pet_type").val() + "/" + $("#data_pet_name").val());
}
function back_to_proc_step2_slider(){
	var type =  $("#data_pet_type").val();
	$("#step_content").load("/weight_check/2/slider/?type="+type);	
}
function proc_step2_ideal(type_id) {
	var error = false;
	var breed = $("#id_breed_select_" + type_id).val();
	var bodyframe = $("#step_bodyframe input:checked").val();
	var gender = $("#step_gender input:checked").val();
	if(breed) {
		$("#data_pet_breed").val( breed );
	} else {
		error |= true;
	}
	if(bodyframe) {
		$("#data_pet_bodyframe").val( bodyframe );
	} else {
		error |= true;
	}
		if(gender) {
			$("#data_pet_gender").val( gender );
		} else {
			error |= true;
		}
	if(error) {
		var msg = "";
        msg = "Please choose valid breed, bodyframe size and gender."
		$("#step_error").html(msg);
	} else {
		$("#step_error").html("");
		$("#step_ideal_result_weight_test").html("");		
		$("#step_ideal_result_weight_text").html("The ideal weight is");	
		$("#vet_weight").css({ display:"block"});
		$("#id_vet_weight").val($("#data_pet_weight_ideal_vet").val());
		$("#step_ideal_result_kg").html("kg");
	   	$("#submit_info").css( {display: "none"} );
		$("#step_ideal_result_weight").html("");
		$("#step_ideal_result_loading").css( {display: "block"} );
		$("#step_ideal_result_weight").load( "/weight_check/get_ideal/", {type: $("#data_pet_type").val(), breed: breed, bodyframe: bodyframe, gender: gender},
			function() {
				$("#step_ideal_result_loading").css( {display: "none"} );
				$("#step_ideal_next").css( {display: "block"} );
				$("#data_pet_weight_ideal").val( $("#step_ideal_result_weight").text() );
			} );
	}
}
function back_to_proc_step2_ideal(){
	$("#tab_steps").load("/weight_check/step/2");
	$("#step_content").load("/weight_check/2/ideal/" + $("#data_pet_type").val() + "/" + $("#data_pet_name").val(), null,																								 
				 function(){
					 var gender = $("#data_pet_gender").val();
					 var bodyframe = $("#data_pet_bodyframe").val();
					 var breed=  $("#data_pet_breed").val(); 
					if(gender =="female"){
						$("#female").attr("checked","checked");
					}else{
						$("#male").attr("checked","checked");
					}
					//bodyframe
					if(bodyframe=="small"){
						$("#small").attr("checked","checked");
					}else if(bodyframe=="below_avg"){
						$("#below_avg").attr("checked","checked");
					}else if(bodyframe=="average"){
						$("#average").attr("checked","checked");
					}else if(bodyframe=="above_avg"){
						$("#above_avg").attr("checked","checked");
					}
					else if(bodyframe=="large"){
						$("#large").attr("checked","checked");
					}
					//breed
					$("option[@value='"+breed+"']").attr("selected","selected")
				 }																									 
	);
}
function proc_step2_ideal_save() {
	$("#step_content").load("/weight_check/send_email/");	
}
function back_to_proc_step2_ideal_save()
{

	$("#step_content").load("/weight_check/send_email/");																											
	
}
function proc_step2_email() {
	var val = trim( $("#email").val() );
	var reg = /^([A-Za-z0-9_\-\.])+\@([A-Za-z0-9_\-\.])+\.([A-Za-z]{2,4})$/;

	var data_vet_weight = trim( $("#data_pet_weight_ideal_vet").val() );
	if(data_vet_weight.length==0){
		data_vet_weight = null
	}
	// cause problems in ie
	if(reg.test(val) == false) {
		
		$("#step_error").html("Please enter valid email.");
	} else {
		$("#step_error").html("");
		$("#step_content").load("/weight_check/send_email/?email="+val+"&data_pet_name="+ $("#data_pet_name").val()+"&data_pet_age="+$("#data_pet_age").val() + "&data_pet_type="+$("#data_pet_type").val()+"&data_pet_breed=" +$("#data_pet_breed").val()+"&data_pet_bodyframe="+ $("#data_pet_bodyframe").val()+ "&data_pet_gender=" +$("#data_pet_gender").val()+ "&data_pet_weight_ideal_vet="+data_vet_weight);
	}
	
}
function proc_step2_vet_weight(p_callback)
{
	var vet_weight;
	if($("#id_vet_weight").val())
	{
		vet_weight = trim( $("#id_vet_weight").val() );
		if(vet_weight.length!=0){
			if(Number(vet_weight)){	
				if(vet_weight.indexOf(".")==-1){
					vet_weight+=".0";
				}
				$("#data_pet_weight_ideal_vet").val( vet_weight );
			}
			else{			
				$("#error_vet_weight").html("please insert  a correct value");
				return;
			}
		}
		else{
			$("#data_pet_weight_ideal_vet").val("");
		}	
	}
	else{
		$("#data_pet_weight_ideal_vet").val("");
	}
	eval(p_callback)();
}
function getIdealWeight(){
	var idealWeight;
	vet_weight =  $("#data_pet_weight_ideal_vet").val();
	if(vet_weight.length!=0){
		idealWeight = vet_weight;
	}
	else{
		idealWeight = $("#data_pet_weight_ideal").val();
	}
	return idealWeight;
}
function proc_step2_ideal_next() {
	$("#tab_steps").load("/weight_check/step/3");
	var data_vet_weight = trim( $("#data_pet_weight_ideal_vet").val() );
	if(data_vet_weight.length!=0){
		$("#step_content").load("/weight_check/3/current/" + $("#data_pet_name").val() + "/" + $("#data_pet_weight_ideal_vet").val() + "/");
	}else{
		$("#step_content").load("/weight_check/3/current/" + $("#data_pet_name").val() + "/" + $("#data_pet_weight_ideal").val() + "/");
	}
}
function back_to_proc_step2_ideal_next(){
	$("#tab_steps").load("/weight_check/step/3");
	$("#step_content").load("/weight_check/3/current/" + $("#data_pet_name").val() + "/" + $("#data_pet_weight_ideal").val() + "/", null ,
			function(){
				$("#pet_current").val($("#data_pet_weight_current").val());
			}
		);
}
function proc_step3_current() {
	var val = trim( $("#pet_current").val() );
	if(val.length == 0 || !is_number(val)) {
		$("#step_error").html("Please enter valid weight.");
	} else {
		val = Number(val);
		$("#step_error").html("");
		$("#data_pet_weight_current").val( val );
		vet_weight_val = $("#data_pet_weight_ideal_vet").val();
		if(!vet_weight_val)
		{
			vet_weight_val = "0.0";
		}
		$("#tab_steps").load("/weight_check/step/4");
			$("#step_content").load("/weight_check/4/plan/" + $("#data_pet_name").val() + "/" + $("#data_pet_weight_ideal").val() + "/"+ vet_weight_val +"/" + val + "/",{},function(){
			var page_size = 5;
			var links = '<div id="page_holder_pager">';
			pages = 0;
			var elements_array = [];
			$('div#plan_holder tr.list_items').each(function(f){
				elements_array[f] = this;
				var a = f%page_size;
				var b = (f-a)/page_size;
				if(a==0){
					links += '<a href="'+pages+'" class="js_page" />'+(pages+1)+'</a>';
					pages++;
				}
				$(this).css('display','none');		// hidden when loaded
			});
			links += '</div>';
			$('div#plan_holder table').after(links);	// append links in the end
			show_page(0,elements_array);			// show first page
			$('a.js_page').click(function(){		// add actions to the links
				var link_id = this.href;
				var tmp_url = link_id.split('/');
				for(var k=0; k<tmp_url.length;k++){
					link_id = tmp_url[k];
				}
				show_page(link_id,elements_array);	// show clicked page
				return false;
			});
			return false;
		});	
	}
}

function back_to_proc_step3_current(){
	proc_step3_current()
}
function show_page(page,elements_array){
	var page_size = 5;
	var current_page = -1;
	for(var t=0;t<elements_array.length;t++){
		var element = elements_array[t];
		var a = t%page_size;
		if(a==0){
			current_page++;
		}
		var b = (t-a)/page_size;
		if(page ==  current_page){
			element.removeAttribute('style');
            if($.browser.opera){
                element.style.cssText ='display:block';
            }if($.browser.msie){
                element.style.cssText ='display:block';
            }if($.browser.safari){
                element.style.cssText ='display:block';
            }
		}else{
			element.setAttribute('style','display:none');
			if($.browser.msie){
				element.style.cssText ='display:none';
			}
		}
	}
}
function pet_update() {
	var pet_id = $("#matching_pets").val();
	if(pet_id) {
		window.location = "/mypets/update_weight_loss_plan/?pet=" + pet_id;
	} else {
		alert("select a pet");
	}
}
/********************
SMILEY
*********************/
function Smiley(code) {
	code = ' ' + code + ' ';
	if (document.forms['post'].message.createTextRange && document.forms['post'].message.caretPos) {
		var caretPos = document.forms['post'].message.caretPos;
		caretPos.text = caretPos.text.charAt(caretPos.text.length - 1) == ' ' ? code + ' ' : code;
		document.forms['post'].message.focus();
	} else {
	document.forms['post'].message.value  += code;
	document.forms['post'].message.focus();
	}
}






