//var SITE_URL = 'http://86.123.98.83:84/February2011/magazine/';
var SITE_URL = 'http://www.decoratiuni4u.ro/';

function CreateBookmark() {
  title = document.title;
  url = self.location;

  if (window.sidebar) { // Mozilla Firefox Bookmark
    window.sidebar.addPanel(title, url,"");
  } else if( window.external ) { // IE Favorite
    window.external.AddFavorite( url, title);
  } else if(window.opera && window.print) { // Opera Hotlist
    return true;
  }
}

function swapImage ( src_in ) {
  var img_src = src_in.replace('/thumb/','/normal/');

  $('#big_img').fadeOut('slow');
  $('#big_img').hide();
  $('#big_img').attr('src',img_src);
  $('#big_img').fadeIn('slow')
}

function addCount ( a_id, _link ) {
  if ( a_id != "" ) {
    var ajaxres = $.ajax( {
      type: "POST",
      url: SITE_URL+"includes/ajax/ajaxAddCount.php",
      data: "a_id=" + a_id,
      async: false
    } ).responseText;

    if(typeof(ajaxres) != null) {
      if ( _link != 'not_allowed' ) {
        window.location = _link;
      }
    }
  }
}

function showMessage( _id ) {
  if ( _id != "" ) {
    var ajaxres = $.ajax( {
      type: "POST",
      url: SITE_URL+"includes/ajax/ajaxRead.php",
      data: "_id="+_id,
      async: false
    } ).responseText;

    if(typeof(ajaxres) != null) {
      $('#friendship_status').html(ajaxres);
    }
    $('#message_'+_id).toggle('slow');
  }
}

function addFriend( owner_id, session_id) {
  if ( owner_id != "" && session_id !="" ) {
    var ajaxres = $.ajax( {
      type: "POST",
      url: SITE_URL+"includes/ajax/ajaxAddFriend.php",
      data: "owner_id="+owner_id+"&session_id=" + session_id,
      async: false
    } ).responseText;

    if(typeof(ajaxres) != null) {
      $('#friendship_status').html(ajaxres);
    }
  }
}

function deleteFriend( owner_id, session_id) {
  if ( owner_id != "" && session_id !=""  ) {
    var ajaxres = $.ajax( {
      type: "POST",
      url: SITE_URL+"includes/ajax/ajaxDeleteFriend.php",
      data: "owner_id="+owner_id+"&session_id=" + session_id,
      async: false
    } ).responseText;

    if(typeof(ajaxres) != null) {
      $('#friendship_status').html(ajaxres);
    }
  }
}

function toogleArrow( id ) {
  src = $('#'+id).attr('src');
  if ( src == (SITE_URL+'images/arrow_red_right.gif') ) {
    $('#'+id).attr('src', SITE_URL+'images/arrow_red_down.gif');
  } else if ( src == (SITE_URL+'images/arrow_red_down.gif') ) {
    $('#'+id).attr('src', SITE_URL+'images/arrow_red_right.gif');
  }
}

function charCount ( _in, _out, _length ) {
  chars = $("#"+_in).val();
  leng = _length - chars.length;
  $("#"+_out).html(_length - (chars.length));
  if ( leng < 0 ) {
    $("#"+_in).val( chars.substr(0,_length) );
  }
  
}

function s_changeRating ( grade, shop_id ) {
  if ( grade != "" ) {
    var ajaxres = $.ajax( {
      type: "POST",
      url: SITE_URL+"includes/ajax/ajaxAddPoints.php",
      data: "shop_id="+shop_id+"&grade=" + grade,
      async: false
    } ).responseText;

    if(typeof(ajaxres) != null) {
      s_getPoints( shop_id );
      $('#alert_message'+shop_id).html(ajaxres);
    }
  }
}

function s_getPoints( shop_id ) {
	if ( shop_id != "" ) {
		var ajaxres = $.ajax( {
      type: "POST",
      url: SITE_URL+"includes/ajax/ajaxGetPoints.php",
      data: "shop_id="+shop_id,
      async: false
    } ).responseText;

    if(typeof(ajaxres) != null) {
      ints = ajaxres.split('###');
      $('#rank_points'+shop_id).html(ints[0]+"/5 ( "+ints[1]+"&nbsp;voturi)");
      rate = (ints[0]*100)/5;
      $('#current_rating'+shop_id).width( (rate*125)/100 );
    }
	}
}

function a_changeRating ( grade, article_id ) {
  if ( grade != "" ) {
    var ajaxres = $.ajax( {
      type: "POST",
      url: SITE_URL+"includes/ajax/ajaxAddPoints.php",
      data: "article_id="+article_id+"&grade=" + grade,
      async: false
    } ).responseText;

    if(typeof(ajaxres) != null) {
      a_getPoints( article_id );
      $('#alert_message').html(ajaxres);
    }
  }
}

function a_getPoints( article_id ) {
	if ( article_id != "" ) {
		var ajaxres = $.ajax( {
      type: "POST",
      url: SITE_URL+"includes/ajax/ajaxGetPoints.php",
      data: "article_id="+article_id,
      async: false
    } ).responseText;

    if(typeof(ajaxres) != null) {
      ints = ajaxres.split('###');
      $('#rank_points').html(ints[0]+"/5 ( "+ints[1]+"&nbsp;voturi)");
      rate = (ints[0]*100)/5;
      $('#current_rating').width( (rate*125)/100 );
    }
	}
}

function changeRating ( grade, product_id ) {
  if ( grade != "" ) {
    var ajaxres = $.ajax( {
      type: "POST",
      url: SITE_URL+"includes/ajax/ajaxAddPoints.php",
      data: "product_id="+product_id+"&grade=" + grade,
      async: false
    } ).responseText;

    if(typeof(ajaxres) != null) {
      getPoints( product_id );
      $('#alert_message').html(ajaxres);
    }
  }
}

function getPoints( product_id ) {
	if ( product_id != "" ) {
		var ajaxres = $.ajax( {
      type: "POST",
      url: SITE_URL+"includes/ajax/ajaxGetPoints.php",
      data: "product_id="+product_id,
      async: false
    } ).responseText;

    if(typeof(ajaxres) != null) {
      ints = ajaxres.split('###');
      $('#rank_points').html(ints[0]+"/5 ( "+ints[1]+"&nbsp;voturi)");
      rate = (ints[0]*100)/5;
      $('#current_rating').width( (rate*125)/100 );
    }
	}
}

function switchView( id ) {
  $('#'+id).toggle("slow");
}

function switchForm( type ) {
	if ( type == 'shop' ) {
		$('#shop_link').hide();
		$('#user_form').hide();
		$('#user_link').show();
		$('#shop_form').show();

    $('#info_register').hide();
	} else if ( type == 'user' ) {
		$('#shop_link').show();
		$('#user_form').show();
		$('#user_link').hide();
		$('#shop_form').hide();

    $('#info_register').hide();
	}
}

function addArticleView ( article_id, _link ) {
  if ( article_id != "" ) {
    var ajaxres = $.ajax( {
      type: "POST",
      url: SITE_URL+"includes/ajax/ajaxAddArticleView.php",
      data: "article_id=" + article_id,
      async: false
    } ).responseText;

    if(typeof(ajaxres) != null) {
      window.location = _link;
    }
  }
}

function addProductView ( product_id, _link ) {
  if ( product_id != "" ) {
    var ajaxres = $.ajax( {
      type: "POST",
      url: SITE_URL+"includes/ajax/ajaxAddProductView.php",
      data: "product_id=" + product_id,
      async: false
    } ).responseText;

    if(typeof(ajaxres) != null) {
      window.location = _link;
    }
  }
}

function addShopView ( shop_id, _link ) {
  if ( shop_id != "" ) {
   var ajaxres = $.ajax( {
      type: "POST",
      url: SITE_URL+"includes/ajax/ajaxAddShopView.php",
      data: "shop_id=" + shop_id,
      async: false
    } ).responseText;

    if(typeof(ajaxres) != null) {
      window.location = _link;
    }
  }
}

  
