function write_review()
{
		$('div#form_result').html('Processing...');
		xajax_add_review_form(xajax.getFormValues('review_form'));
		return false;
}
function remove_favour(id)
{
  var ok=confirm('Do you really want to remove this?');
  if (ok) xajax_remove_favour(id); 
  return false;
}
function mloadphone(value,cate)
{
	xajax_loadphone(value,cate);
	return false;
}
function review_popup()
{
	tb_show("","#TB_inline?height=490&amp;width=580&amp;inlineId=popup&amp;modal=false",true);
	return false;
}
function add_helpful(id,type)
{
	var cook = $.cookie('ws_helpful');		
		xajax_helpful(id,type,cook);		
		return false;
}
function addcookie(id)
{
	var cook = $.cookie('ws_helpful');	
	if (cook=='undefined' || cook==null) $.cookie('ws_helpful',id,1);
	else
	{
		var arr = cook.split(',');
		arr.push(id);
		$.cookie('ws_helpful',arr.join(','),1);
	}
	alert('Thanks for make a choose about this review!');	
	return false;
}
function sort_user_review(value)
{
   xajax_set_review(value);
   return false;
}
function email_popup()
{
	tb_show("","#TB_inline?height=465&amp;width=580&amp;inlineId=write_email&amp;modal=false",true);
	return false;
}
function reload(imageName,path)
{
    var randomnumber=Math.floor(Math.random()*101001); // generate a random number to add to image url to prevent caching
    var src = path+'/captcha.php?num=' + randomnumber;
    $('img[name='+imageName+']').attr('src',src);  // change image src to the same url but with the random number on the end
}
$(function(){
    $.fn.resizeImg = function(new_width,new_height) {
        this.each(function(){
            var oldwidth = this.width;                   
            var oldheight = this.height;
            if (oldwidth>oldheight) this.height=new_height;
            if (oldheight>oldwidth) this.width=new_width;
            if(oldheight==oldwidth)                    
            {                                
                this.width=new_width;
                this.height=new_height;                          
            }  
            return this;

        });
    };          
});
function tiny_init(config_real_ws)
{
    tinyMCE.init({

        mode : "exact",
        theme : "advanced",
        elements: "detail_desc,introtext",    
        plugins : "safari,spellchecker,pagebreak,style,layer,table,save,advhr,advimage,advlink,emotions,iespell,inlinepopups,insertdatetime,preview,media,searchreplace,print,contextmenu,paste,directionality,fullscreen,noneditable,visualchars,nonbreaking,xhtmlxtras,template,imagemanager",
        paste_auto_cleanup_on_paste : true,        
        // Theme options
        theme_advanced_buttons1 : "save,newdocument,|,bold,italic,underline,strikethrough,|,justifyleft,justifycenter,justifyright,justifyfull",
        theme_advanced_buttons2 : "cut,copy,paste,pastetext,pasteword,|,search,replace,|,bullist,numlist,|,outdent,indent,blockquote,|,undo,redo,|,link,unlink,anchor,image,cleanup,help,code",
        theme_advanced_buttons3 : "insertdate,inserttime,preview,|,forecolor,backcolor,|,styleselect,formatselect,fontselect,fontsizeselect",
        theme_advanced_buttons4 : "insertlayer,moveforward,movebackward,absolute,|,styleprops,spellchecker,|,visualchars,nonbreaking,template,blockquote,pagebreak,|,insertfile,insertimage",
        theme_advanced_toolbar_location : "top",
        theme_advanced_toolbar_align : "left",
        theme_advanced_statusbar_location : "bottom",
        theme_advanced_resizing : true,    
        height: "300",
        font_size_style_values : "medium",
        relative_urls : false,
        remove_script_host : false, 
        document_base_url : config_real_ws

    });
}
jQuery.fn.counter = function() {
  // setup initial counter display
  $(this).each(function() {
    var max = $(this).attr('maxlength');
    var val = $(this).attr('value');
    var cur = 0;
    if(val) // value="", or no value at all will cause an error
      cur = val.length;
    var left = max-cur;
    $(this).after("<span class='counter'>"
      + left.toString()+"</span> characters remaining");
    // Style as desired
    var c = $(this).next(".counter");
    c.css("margin-left","10px");
    c.css("padding", "0 3px 0 3px")
    c.css("border", "1px solid #ccc")
    if(left <= 10)
        c.css("background","#F4F379");
    else
        c.css("background","none");
 
    // setup counter to change with keystrokes 
    $(this).keyup(function(i) {
      var max = $(this).attr('maxlength');
      var val = $(this).attr('value');
      var cur = 0;
      if(val)
        cur = val.length;
      var left = max-cur;
      var c = $(this).next(".counter");
      c.text(left.toString());
      if(left <= 10)
          c.css("background","#F4F379");
      else
          c.css("background","none");
      return this;
    });
  });
  return this;
}
function call_login(val,add)
{
    tb_show('','#TB_inline?height=400&amp;width=495&amp;inlineId=thickload&amp;modal=false',true);
    $('#type').val(val);
    $('#add_value').val(add);
     
}



function view_votes(id,type)
{
   
    if (type=='1')
    {
          xajax_load_votelist(id); 
          $('div#commentlist div.popup_vo,div#commentlist div.lb_c1').hide();
          $('div#comment_votes'+id).css('display','inline');
    }
    else 
    {
        $('div#vote_content').html('');
        $('div#comment_votes'+id).css('display','none');
    }
    return false;
}
function report(id,type)
{
     
    if (type=='1')
    {
         $('div#commentlist div.popup_vo,div#commentlist div.lb_c1').hide();
         $('div#report'+id).css('display','inline');
    }
    else  
    {
        $('div#report'+id).css('display','none');
        $('form#report_form'+id).clearForm();
    }
    return false;
}
function report_deal(id,type)
{
     
    if (type=='1')
    {
         $('div#commentlist div.popup_vo,div#commentlist div.lb_c1').hide();
         $('div#report_deal'+id).css('display','inline');
    }
    else  
    {
        $('div#report_deal'+id).css('display','none');
        $('form#report_deal_form'+id).clearForm();
    }
    return false;
}
function edit(id,type)
{
     
    if (type=='1')
    {
         $('div#commentlist div.popup_vo,div#commentlist div.lb_c1').hide();
         $('div#edit'+id).css('display','inline');
    }
    else  
    {
        $('div#edit'+id).css('display','none');
        
    }
    reload('captcha_edit'+id,config_ws);
   
    return false;
}



function reply(id,type)
{
     
    if (type=='1')
    {
         $('div#commentlist div.popup_vo,div#commentlist div.lb_c1').hide();
         $('div#reply'+id).css('display','block');
    }
    else  
    {
        $('div#reply'+id).css('display','none');
         $('form#reply_form'+id).clearForm();
    }
    reload('captcha_reply'+id,config_ws);
   
    return false;
}
function new_comment(post_id,type)
{
     
    if (type=='1')
    {
        xajax_load_new_comment(post_id);
    }
    else  
    {
       $('div#new_comment').hide().html('');
    }
    reload('captcha_newcomment',config_ws);
   
    return false;
}
function email_friend(type)
{
    if (type==1)
    {
        xajax_showbox();
    }
    else
    {
        tb_remove();
        $('div#email_friend').html('');
        
    }
    return false;
}
$.fn.clearForm = function() {
  return this.each(function() {
 var type = this.type, tag = this.tagName.toLowerCase();
 if (tag == 'form')
   return $(':input',this).clearForm();
 if (type == 'text' || type == 'password' || tag == 'textarea')
   this.value = '';
 else if (type == 'checkbox' || type == 'radio')
   this.checked = false;
 else if (tag == 'select')
   this.selectedIndex = -1;
  });
};
