var arr_ls_all_1 = new Array();
var arr_ls_all_2 = new Array();
var arr_ls_all_30 = new Array();
var arr_ls_all_31 = new Array();
var arr_ls_all_32 = new Array();
var arr_ls_all_4 = new Array();
var arr_ls_all_5 = new Array();
var arr_ls_all_6 = new Array();
var arr_ls_all_7 = new Array();
var arr_ls_all_8 = new Array();
var arr_ls_all_9 = new Array();

arr_ls_all_4["ru"] = "Вы не выбрали фотографию!";
arr_ls_all_4["en"] = "You have not selected a photo!";
arr_ls_all_4["de"] = "You have not selected a photo!";
arr_ls_all_4["fr"] = "You have not selected a photo!";

arr_ls_all_5["ru"] = "Вы не ввели название документа!";
arr_ls_all_5["en"] = "You do not have the title of the document!";
arr_ls_all_5["de"] = "You do not have the title of the document!";
arr_ls_all_5["fr"] = "You do not have the title of the document!";

arr_ls_all_6["ru"] = "Вы не выбрали документ!";
arr_ls_all_6["en"] = "You have not selected a document!";
arr_ls_all_6["de"] = "You have not selected a document!";
arr_ls_all_6["fr"] = "You have not selected a document!";

arr_ls_all_8["ru"] = "Вы действительно хотите удалить?";
arr_ls_all_8["en"] = "Are you sure you want to delete?";
arr_ls_all_8["de"] = "Are you sure you want to delete?";
arr_ls_all_8["fr"] = "Are you sure you want to delete?";

arr_ls_all_9["ru"] = "обязательное поле";
arr_ls_all_9["en"] = "this field is required";
arr_ls_all_9["de"] = "pflichtfeld";
arr_ls_all_9["fr"] = "champ obligatoire";

var site_lang = jQuery("body").attr("site_lang");


jQuery(document).ready(function(){
    var ur = window.location.href;
    var loc = ur.split('/')[3];
    var loc_prefix ='';
    if (loc == 'ru' || loc == 'de' || loc == 'fr') loc_prefix = loc+'/';
    else loc_prefix = '';

//for lich edit
jQuery(".edit[@type='edit']").click(
function()
{
  if(jQuery.browser.msie) jQuery(this).parent().parent().next("tr").find('.align_left').css("display","block");
  else jQuery(this).parent().parent().next("tr").find('.align_left').css("display","table-cell");
  jQuery(this).parent().parent().attr("class", "lastRow");
  return false;
});
jQuery(".align_left > form > .close3").click(
function()
{
  jQuery(this).parent().parent().css("display","none");
  jQuery(this).parent().parent().parent().prev("tr").removeAttr("class");
});
jQuery("a[@type='editcancel']").click(
function()
{
  jQuery(this).parent().parent().parent().css("display","none");
  jQuery(this).parent().parent().parent().parent().prev("tr").removeAttr("class");
  var mod = jQuery(this).parent().find('.mod').val();
  var orig = jQuery(this).parent().find('.orig').val();
  if (mod != orig) jQuery(this).parent().find('.mod').attr("value", orig);
  return false;
});


// translator's comment
jQuery("a[@type='comment']").click(
function()
{
  if(jQuery.browser.msie) jQuery(this).parent().parent().parent().next("tr").find('.align_left').css("display","block");
  else jQuery(this).parent().parent().parent().next("tr").find('.align_left').css("display","table-cell");
  jQuery(this).parent().parent().parent().attr("class", "lastRow");
  return false;
});
jQuery(".align_left > div > .close3").click(
function()
{
  jQuery(this).parent().parent().css("display","none");
  jQuery(this).parent().parent().parent().prev("tr").removeAttr("class");
});
jQuery("a[@type='savecomment']").click(
function()
{
  jQuery('table.clubpageEmpTable').attr('style','cursor: progress');
  var url = '/'+loc_prefix+'account-projects/translator';
  var act = 'comment';
  var project_id = jQuery(this).parent().next('input').val();
  var trans_comment = jQuery(this).parent().prev('textarea').val();
  var data = { 'act':act, 'project_id': project_id, 'trans_comment': trans_comment };
  var th = jQuery(this);
  jQuery.post(url, data,
   function(){
     th.parent().parent().parent().parent().css("display","none");
     th.parent().parent().parent().parent().parent().prev("tr").removeAttr("class");
     jQuery('div.area').remove();
     jQuery('div.header').after('<div class="area"><h3>Your comment was added successfully!</h3></div>');
     jQuery('table.clubpageEmpTable').removeAttr('style');
   });
});



/*----popup окно в талице ----*/
/*
 * UPD: 2009-06-24, Alena
 * now popup window on /projects page is openned by clicking on employer name
 * previouse code (by hover) is commented in /js/jquery.index.js
 */
  jQuery('.td2div').click(
  function()
  {
          var el=jQuery(this).parent().find("div").eq(2);
          if(jQuery(el).is("div"))
          {
          jQuery(el).toggle(400);
          }
  });
/*----end popup окно в талице ----*/

/*----popup окно в талице ----*/
/*
 * UPD: 2009-06-24, Alena
 * now popup window on /projects/id/X page is openned by clicking on employer name
 * previouse code (by hover) is commented in /js/jquery.project.js
 */
jQuery('.td2').click(
function()
{
        var el=jQuery(this).parents(".projectTableBody").prev().find("div").eq(1);
        if(jQuery(el).is("div"))
        {
        jQuery(el).toggle(400);
        }
});

  jQuery('.close1').click(
  function()
  {
    jQuery(this).parent().hide(400);
  });


/*
 * UPD: 2009-07-02, Alena
 * для раскрытия комментрия переводчика на /account_projects/employer/bidded
 */
jQuery("span.showDetailProEmp").mousedown(
function()
{
        if(jQuery(this).parents(".projectTableBody").attr("class").indexOf("projectActive")==-1)
        jQuery(this).parents(".projectTableBody").addClass("projectActive");
        else
        jQuery(this).parents(".projectTableBody").removeClass("projectActive");
        return false;
});

jQuery(".openBids").livequery('click', function(){
        if(jQuery.browser.msie) jQuery(this).parent().parent().next().next().find('td.allBids').attr('style','display:block');
	else jQuery(this).parent().parent().next().next().find('td.allBids').attr('style','display:table-cell');
	jQuery(this).addClass("closeBids");
	jQuery(this).removeClass("openBids");
	jQuery(this).find('a').addClass("closeBidsA");
	jQuery(this).find('a').removeClass("openBidsA");
});

jQuery(".closeBids").livequery('click',function(){
	jQuery(this).parent().parent().next().next().find('td.allBids').attr('style','display:none');
	jQuery(this).addClass("openBids");
	jQuery(this).removeClass("closeBids");
	jQuery(this).find('a').addClass("openBidsA");
	jQuery(this).find('a').removeClass("closeBidsA");
});

jQuery(".openBidsA").livequery('click', function(){
	if(jQuery.browser.msie) jQuery(this).parent().parent().parent().next().next().find('td.allBids').attr('style','display:block');
        else jQuery(this).parent().parent().parent().next().next().find('td.allBids').attr('style','display:table-cell');
	jQuery(this).addClass("closeBidsA");
	jQuery(this).removeClass("openBidsA");
	jQuery(this).parent().addClass("closeBids");
	jQuery(this).parent().removeClass("openBids");
});

jQuery(".closeBidsA").livequery('click', function(){
	jQuery(this).parent().parent().parent().next().next().find('td.allBids').attr('style','display:none');
	jQuery(this).addClass("openBidsA");
	jQuery(this).removeClass("closeBidsA");
	jQuery(this).parent().addClass("openBids");
	jQuery(this).parent().removeClass("closeBids");
});

});


/*
 * /account/translator, удаление изображения
 */
/*function locale_prefix()
{
    var ur = window.location.href;
    var loc = ur.split('/')[3];
    var loc_prefix ='';
    if (loc == 'ru' || loc == 'de' || loc == 'fr') loc_prefix = loc+'/';
    else loc_prefix = '';
    return loc_prefix;
}
function front_delete_image(image_id, index)
{
    loc_prefix = locale_prefix();

  var image_item = jQuery("#image_item_" + image_id);
    if (confirm("Are you sure?") ) {
                image_item.remove();
                jQuery("#ajax_animation2").css('display', 'block');
                jQuery.get("/utils/delete-image-options", {type: "get", image_id: image_id}, AfterDataDel);
        }
        return false;
}

 function AfterDataDel(data)  {
        jQuery("#photo_block").html(data);
        jQuery("#ajax_animation2").css('display', 'none');
}

function front_delete_pdf(pdf_id, index)
{
  var pdf_item = jQuery("#pdf_item_" + pdf_id);
    if (confirm("Are you sure?") ) {
                pdf_item.remove();
                jQuery("#ajax_pdf_animation2").css('display', 'block');
                jQuery.get("/utils/delete-pdf-options", {type: "get", pdf_id: pdf_id}, AfterDataPdfDel);
        }
        return false;
}
function front_delete_pdf_emp(pdf_id, index)
{
  var pdf_item = jQuery("#pdf_item_" + pdf_id);
    if (confirm("Are you sure?") ) {
                pdf_item.remove();
                jQuery("#ajax_pdf_animation2").css('display', 'block');
                jQuery.get("/utils/delete-pdf-options-emp", {type: "get", pdf_id: pdf_id}, AfterDataPdfDel);
        }
    return false;
}
 function AfterDataPdfDel(data)  {
        jQuery("#ajax_pdf_animation2").css('display', 'none');
}


*/

/*
 * /account/translator, загрузка документа
 */

// Загружаем фотографию
jQuery("#upload_photo").click(function() {
    jQuery("#msg_photo").html("");
    jQuery("#msg_error_block_img").text("");

    if (jQuery("#photo_url").val() == "" && jQuery("#photo_offer").val() == "" )
    {
        jQuery("#msg_photo").html("<span class='error' style='color: red;'>" + arr_ls_all_4[ site_lang ] + "</span>");
        return false;
    }

    // Из файла
    if (jQuery("#photo_offer").val() != "" )
    {
        jQuery("#ajax_animation")
            .ajaxStart(function(){
                jQuery(this).show();
            })
            .ajaxComplete(function(){
                jQuery(this).hide();
            });

        jQuery.ajaxFileUpload
        (
            {
                url:'/utils/upload-tmp-img-options',
                secureuri:false,
                fileElementId:'photo_offer',
                dataType: 'text',
                success: function (data, status) {
                    afterUploadTmpImgData(data);
                },
                error: function (data, status, e) {
                    alert(e);
                }
            }
        )
        return false;
    }

    // Из URL
    if ( jQuery("#photo_url").val() != "" )
    {
        jQuery("#ajax_animation").css('display', 'block');
        jQuery.post("/utils/upload-photo-url", {url: jQuery("#photo_url").val()}, function(data){
            afterUploadTmpImgData(data);
            jQuery("#photo_url").val("");
        });
        return false;
    }
});

// после загрузки изображения
function afterUploadTmpImgData(response) {
	jQuery("#ajax_animation").css('display', 'none');
	jQuery("#text1").attr('value', '');

	jQuery("#photo_offer").attr("value", "");
	jQuery("#photo_name").attr("value", "");
	jQuery("#photo_url").attr("value", "");

	jQuery("div.addOfferEditPhoto").html(response);

 }
// --- //
/* --- */

/*
 * Загружаем документ account/translator
 */
	jQuery("#upload_doc_url").click(function() {
	    jQuery("#msg_doc").html("");
        jQuery("#msg_error_block_doc").text("");


		if ( !jQuery("#docName").val() ) {
		    jQuery("#msg_doc").html("<span class='error' style='color: red;'>Document name is required field</span>");
		    return false;
		}

		if ( jQuery("#doc_url").val() == "" && jQuery("#doc_offer").val() == "" ) {
		    jQuery("#msg_doc").html("<span class='error' style='color: red;'>file is not specified</span>");
		    return false;
		}

		if ( jQuery("#doc_offer").val() != "" ) {

		    jQuery("#ajax_animation2")
		     .ajaxStart(function(){
			     jQuery(this).show();
		     })
		     .ajaxComplete(function(){
			     jQuery(this).hide();
		     });

		    jQuery.ajaxFileUpload
		    (
			    {
				    url:'/utils/upload-tmp-pdf-options',
				    secureuri:false,
				    fileElementId:'doc_offer',
				    dataType: 'text',
				    success: function (data, status) {
					    afterUploadTmpPdfData(data);
				    },
				    error: function (data, status, e) {
					    alert(e);
				    }
			    }
		    )

		    return false;
		}

		if ( jQuery("#doc_url").val() != "" ) {
		    jQuery("#ajax_animation2").css('display', "block");
		    jQuery.post("/utils/upload-doc-url", {
			    url: jQuery("#doc_url").val(),
			    desc: jQuery("#docName").val()
			    }, function(data) {
			      afterUploadTmpPdfData(data);
		    });
		    return false;
		}
	});

/* --- */

/*
 * Загружаем документ account/employer
 */
	jQuery("#upload_doc_url_emp").click(function() {
	    jQuery("#msg_doc").html("");
        jQuery("#msg_error_block_doc").text("");


		if ( !jQuery("#docName").val() ) {
		    jQuery("#msg_doc").html("<span class='error' style='color: red;'>Document name is required field</span>");
		    return false;
		}

		if ( jQuery("#doc_url").val() == "" && jQuery("#doc_offer").val() == "" ) {
		    jQuery("#msg_doc").html("<span class='error' style='color: red;'>file is not specified</span>");
		    return false;
		}

		if ( jQuery("#doc_offer").val() != "" ) {

		    jQuery("#ajax_animation2")
		     .ajaxStart(function(){
			     jQuery(this).show();
		     })
		     .ajaxComplete(function(){
			     jQuery(this).hide();
		     });

		    jQuery.ajaxFileUpload
		    (
			    {
				    url:'/utils/upload-tmp-pdf-options-emp',
				    secureuri:false,
				    fileElementId:'doc_offer',
				    dataType: 'text',
				    success: function (data, status) {
					    afterUploadTmpPdfData(data);
				    },
				    error: function (data, status, e) {
					    alert(e);
				    }
			    }
		    )

		    return false;
		}

		if ( jQuery("#doc_url").val() != "" ) {
		    jQuery("#ajax_animation2").css('display', "block");
		    jQuery.post("/utils/upload-doc-url-emp", {
			    url: jQuery("#doc_url").val(),
			    desc: jQuery("#docName").val()
			    }, function(data) {
			      afterUploadTmpPdfData(data);
		    });
		    return false;
		}
	});
/* --- */

// после загрузки документа
 function afterUploadTmpPdfData(response) {
	jQuery("#ajax_animation2").css('display', 'none');
	jQuery("#text2").attr('value', '');

	jQuery("#docName").val("");
	jQuery("#doc_offer").val("");
	jQuery("#text_doc").val("");
	jQuery("#doc_url").val("");

	jQuery(".addOfferEditDoc").empty().append(response);
	jQuery("#docName").attr('value', '');
	return false;
 }
// --- //


/*
 * удаление временного изображения
 */
function delete_tmp_image(image_id) {
	var image_item = jQuery("#image_item_" + image_id);
    if (confirm(arr_ls_all_8[ $("body").attr("site_lang") ]) ) {
		image_item.empty();
		$("#ajax_animation").css('display', 'block');
                    $.get("/utils/delete-tmp-image-options", {type: "get", image_id: image_id}, AfterDeleteTmpImgData);
	}
	return false;
}

function AfterDeleteTmpImgData(data) {
	$("div.addOfferEditPhoto").html(data);
	$("#ajax_animation").css('display', 'none');
	$("#upload_errors").empty();
}
/* --- */

/*
 * удаление временного документа
 */
function delete_tmp_pdf(pdf_id) {
    var pdf_item= jQuery("#pdf_item_" + pdf_id);
    if (confirm('Are you sure?')) {
		pdf_item.empty();
		jQuery("#ajax_animation2").css('display', 'block');
		
                    jQuery.get("/utils/delete-tmp-pdf-options", {type: "get", pdf_id: pdf_id}, AfterDeleteTmpPdfData);
                    if( jQuery("#userinfoAttachedPdf").find("span").length == 0 )
                    {
                        var width = parseInt(jQuery("#div_percent").attr("width")) + 15;
                        jQuery("#div_percent").css("width", width+"%");
                        jQuery("#div_percent").attr("width", width);
                        jQuery("#show_percent").text(width+"%");
                        
                        if ( width > 50 ) {
                            jQuery("#percent_content").css("color", "green");
                        } else if ( width < 49 ) {
                            jQuery("#percent_content").css("color", "red");
                        }
                    }
	}
	return false;
}

function delete_tmp_pdf_emp(pdf_id) {
    var pdf_item= jQuery("#pdf_item_" + pdf_id);
    if (confirm('Are you sure?')) {
		pdf_item.empty();
		jQuery("#ajax_animation2").css('display', 'block');
		jQuery.get("/utils/delete-tmp-pdf-options-emp", {type: "get", pdf_id: pdf_id}, AfterDeleteTmpPdfData);
	}
	return false;
}

function AfterDeleteTmpPdfData(data) {
	jQuery("div.addOfferEditDoc").html(data);
	jQuery("#ajax_animation2").css('display', 'none');
	jQuery("#upload_errors").empty();
	return false;
}

/* --- */

/*
 * удаление временного изображения
 */
function delete_tmp_image(image_id) {
	var image_item = jQuery("#image_item_" + image_id);
    if (confirm(arr_ls_all_8[ jQuery("body").attr("site_lang") ]) ) {
		image_item.empty();
		jQuery("#ajax_animation").css('display', 'block');
		jQuery.get("/utils/delete-tmp-image-options", {type: "get", image_id: image_id}, AfterDeleteTmpImgData);
                    if( jQuery("ul.clubpageImList").find("li").length == 2 )
                    {
                        var width = parseInt(jQuery("#div_percent").attr("width")) - 15;
                        jQuery("#div_percent").css("width", width+"%");
                        jQuery("#div_percent").attr("width", width);
                        jQuery("#show_percent").text(width+"%");
                        
                        if ( width > 50 ) {
                            jQuery("#percent_content").css("color", "green");
                        } else if ( width < 49 ) {
                            jQuery("#percent_content").css("color", "red");
                        }
                    }
	}
	return false;
}

function AfterDeleteTmpImgData(data) {
	jQuery("div.addOfferEditPhoto").html(data);
	jQuery("#ajax_animation").css('display', 'none');
	jQuery("#upload_errors").empty();

	/*tb_init('a.thickbox');
	//hover effect for photo number
jQuery(".numpro > span").mouseover(function() {
		if(this.className!='activ')	this.className="span_over";
	});
jQuery(".numpro > span").mouseout(function()
	{
		if(this.className!='activ')	this.className="";
	});
jQuery(".numpro > span").click(function()
	{
		if(this.className!='activ')
		{
		jQuery(this.parentNode.getElementsByTagName('span')).removeClass();
		var num=jQuery(this).text();
		this.className="activ";
		var el = jQuery(this.parentNode.parentNode).find('.visible');
		el.fadeOut(300);
		el.removeClass();

		jQuery(this.parentNode.parentNode.getElementsByTagName('a').item(num-1)).fadeIn(300);
		this.parentNode.parentNode.getElementsByTagName('a').item(num-1).className="visible";
		}
	});*/
}
/* --- */

/*
 * список городов при выборе страны в фильтре пользователей в админке
 */

function bind_selectors(parant_select_id, child_select_id, datasource_path, extra_option)
{

jQuery(document).ready(function(){

// при заходе на страницу
   if(jQuery('#edit_user_id').val() > 0)
   {
     var uid = jQuery('#edit_user_id').val();
     var city_tmp = jQuery('#city_tmp').val();
    var city_id = $('#city_id_fakt').val();
     jQuery('#edit_user_id').attr('value','')
     var value = jQuery("#" + parant_select_id+" option[selected]").attr('value');
     
    $("#please_wait").show();

     jQuery.post(datasource_path, {id : value, edit_user_id: uid}, function(data){
        var child_select = jQuery('#' + child_select_id);
        child_select.hide().empty();

        if(extra_option)
           data = '<option value="">' + extra_option + '</option>' + data;

        child_select.append(data).show();
        var first_one = child_select.children().get(1);
        if(first_one)
          child_select.val(jQuery(first_one).val());

        if(city_tmp != "")
            child_select.find('option:first').attr('selected','selected');
            
        if ( city_id != '' ) {
            child_select.val(city_id);
        }
        
        $("#please_wait").hide();
        
      });
    }
// --- //

 //for original selectors
 jQuery("#" + parant_select_id).change(function(){
   var value = jQuery(this).attr('value');

   jQuery.post(datasource_path, {id : value}, function(data){
      var child_select = jQuery('#' + child_select_id);
      child_select.hide().empty();

      if(extra_option)
        data = '<option value="">' + extra_option + '</option>' + data;

      child_select.append(data).show();
      var first_one = child_select.children().get(0);
      if(first_one)
        child_select.val(jQuery(first_one).val());
    });
 });
 //for fake selectors
 jQuery("#" + parant_select_id+ "_fake > span").click(function(){
   var value = jQuery(this).attr('name');

   jQuery.post(datasource_path, {id : value}, function(data){
      var child_select = jQuery('#' + child_select_id + '_fake');
      child_select.hide().empty();

      extra_option_text = '';
      if(extra_option)
        var extra_option_text = '<span name="">' + extra_option + '</span>';

      child_select.html(extra_option_text + data);
      sel_span_click();
      });
 });
});
}
/* --- */

/*
 * список городов выбранной страны начинающихся на введенную букву, /admin-user/edit
 */
function cities_list (parant_select_id, child_select_id, datasource_path, extra_option, first_symbol, country_id)
{
     jQuery.get(datasource_path, {country_id : country_id, first_symbol: first_symbol}, function(data){
        var child_select = jQuery('#' + child_select_id);
        child_select.hide().empty();

        if(extra_option)
          data = '<option value="">' + extra_option + '</option>' + data;

        child_select.append(data).show();
        var first_one = child_select.children().get(1);
        if(first_one)
          child_select.val(jQuery(first_one).val());
      });
}
/* --- */

/*
 * функция trim
 */
  function trim(str)
  {
    str = str.replace(/ /g,'');
    return str.replace(/(^\s+)|(\s+jQuery)/g, "");
  }

/*
 * nl2br
 */

function nl2br (str, is_xhtml) {
    // Converts newlines to HTML line breaks  
    // 
    // version: 911.1619
    // discuss at: http://phpjs.org/functions/nl2br    // +   original by: Kevin van Zonneveld (http://kevin.vanzonneveld.net)
    // +   improved by: Philip Peterson
    // +   improved by: Onno Marsman
    // +   improved by: Atli Þór
    // +   bugfixed by: Onno Marsman    // +      input by: Brett Zamir (http://brett-zamir.me)
    // +   bugfixed by: Kevin van Zonneveld (http://kevin.vanzonneveld.net)
    // +   improved by: Brett Zamir (http://brett-zamir.me)
    // +   improved by: Maximusya
    // *     example 1: nl2br('Kevin\nvan\nZonneveld');    // *     returns 1: 'Kevin\nvan\nZonneveld'
    // *     example 2: nl2br("\nOne\nTwo\n\nThree\n", false);
    // *     returns 2: '<br>\nOne<br>\nTwo<br>\n<br>\nThree<br>\n'
    // *     example 3: nl2br("\nOne\nTwo\n\nThree\n", true);
    // *     returns 3: '\nOne\nTwo\n\nThree\n'    var breakTag = (is_xhtml || typeof is_xhtml === 'undefined') ? '' : '<br>';

    //var breakTag = (is_xhtml || typeof is_xhtml === 'undefined') ? '' : '<br>';
    var breakTag = '<br>';

    return (str + '').replace(/([^>\r\n]?)(\r\n|\n\r|\r|\n)/g, '$1'+ breakTag +'$2');
}

